fix tank steering in standstill

This commit is contained in:
interfisch 2024-07-20 01:56:48 +02:00
parent 7734c41809
commit 4ef6e7448b
1 changed files with 22 additions and 11 deletions

View File

@ -607,27 +607,38 @@ void calculateSetSpeed(unsigned long timediff){
float steeringdifferential_speed=0.3; //Speed for turning the steering wheel by differtially driving the front wheels
static bool reverse_enabled2=true; //pohibit instant reverse driving when releasing steering wheel buttons when brake is still pressed. wait for throttle and brake to release once
if (!reverse_enabled2 && throttle_pos<=0 && brake_pos<=0){
reverse_enabled2=true;
}
if (reverse_enabled) { //backwards driving not prohibited
static bool tanksteering_prohibit_left=false;
static bool tanksteering_prohibit_right=false;
static bool prohibit_reverse=false;
if (control_buttonA && !control_buttonB) { //Right button (A) only
tanksteering_prohibit_left=true;
prohibit_reverse=true;
}else if(control_buttonB && !control_buttonA) {//Left button (B) only
tanksteering_prohibit_right=true;
prohibit_reverse=true;
}else if(!control_buttonA && !control_buttonB){ //no button pressed
tanksteering_prohibit_left=true;
tanksteering_prohibit_right=true;
if (throttle_pos<=0 && brake_pos<=0) {//levers released
tanksteering_prohibit_left=false;
tanksteering_prohibit_right=false;
prohibit_reverse=false;
}
}
if (!tanksteering_prohibit_right && tanksteering_prohibit_left && prohibit_reverse) { //Right Tanksteering
cmd_send_toMotor_FL+=brake_pos*steeringdifferential_speed;
cmd_send_toMotor_FR-=brake_pos*steeringdifferential_speed;
cmd_send_toMotor_RL+=brake_pos*steeringdifferential_speed;
cmd_send_toMotor_RR-=brake_pos*steeringdifferential_speed;
reverse_enabled2=false;
}else if(control_buttonB && !control_buttonA) { //Left button (B) only
}else if(tanksteering_prohibit_right && !tanksteering_prohibit_left && prohibit_reverse) { //Left Tanksteering
cmd_send_toMotor_FL-=brake_pos*steeringdifferential_speed;
cmd_send_toMotor_FR+=brake_pos*steeringdifferential_speed;
cmd_send_toMotor_RL-=brake_pos*steeringdifferential_speed;
cmd_send_toMotor_RR+=brake_pos*steeringdifferential_speed;
reverse_enabled2=false;
}else if(reverse_enabled2){ //no button on steering wheel pressed, drive backwards
}else if(tanksteering_prohibit_right && tanksteering_prohibit_left && !prohibit_reverse){ //no button on steering wheel pressed, drive backwards
_cmd_send_toMotor-=brake_pos*reverse_speed;
cmd_send_toMotor_FL=_cmd_send_toMotor;