Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global: Change the IF statement to a SWITCH statement #27043

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions Rover/mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,17 @@ void Mode::get_pilot_desired_steering_and_throttle(float &steering_out, float &t

// check for special case of input and output throttle being in opposite directions
float throttle_out_limited = g2.motors.get_slew_limited_throttle(throttle_out, rover.G_Dt);
if ((is_negative(throttle_out) != is_negative(throttle_out_limited)) &&
((g.pilot_steer_type == PILOT_STEER_TYPE_DEFAULT) ||
(g.pilot_steer_type == PILOT_STEER_TYPE_DIR_REVERSED_WHEN_REVERSING))) {
steering_out *= -1;
if (is_negative(throttle_out) != is_negative(throttle_out_limited)) {
switch (g.pilot_steer_type) {
case PILOT_STEER_TYPE_DEFAULT:
case PILOT_STEER_TYPE_DIR_REVERSED_WHEN_REVERSING:
steering_out *= -1;
break;
default:
break;
}
}

throttle_out = throttle_out_limited;
}

Expand All @@ -137,11 +143,17 @@ void Mode::get_pilot_desired_steering_and_speed(float &steering_out, float &spee
speed_out = desired_throttle * 0.01f * calc_speed_max(g.speed_cruise, g.throttle_cruise * 0.01f);
// check for special case of input and output throttle being in opposite directions
float speed_out_limited = g2.attitude_control.get_desired_speed_accel_limited(speed_out, rover.G_Dt);
if ((is_negative(speed_out) != is_negative(speed_out_limited)) &&
((g.pilot_steer_type == PILOT_STEER_TYPE_DEFAULT) ||
(g.pilot_steer_type == PILOT_STEER_TYPE_DIR_REVERSED_WHEN_REVERSING))) {
steering_out *= -1;
if (is_negative(speed_out) != is_negative(speed_out_limited)) {
switch (g.pilot_steer_type) {
case PILOT_STEER_TYPE_DEFAULT:
case PILOT_STEER_TYPE_DIR_REVERSED_WHEN_REVERSING:
steering_out *= -1;
break;
default:
break;
}
}

speed_out = speed_out_limited;
}

Expand Down
18 changes: 14 additions & 4 deletions libraries/AP_Param/AP_Param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2205,23 +2205,33 @@ void AP_Param::set_float(float value, enum ap_var_type var_type)
float rounding_addition = 0.01f;

// handle variables with standard type IDs
if (var_type == AP_PARAM_FLOAT) {
switch (var_type) {
case AP_PARAM_FLOAT:
((AP_Float *)this)->set(value);
} else if (var_type == AP_PARAM_INT32) {
break;
case AP_PARAM_INT32: {
if (value < 0) rounding_addition = -rounding_addition;
float v = value+rounding_addition;
v = constrain_float(v, INT32_MIN, INT32_MAX);
((AP_Int32 *)this)->set(v);
} else if (var_type == AP_PARAM_INT16) {
break;
}
case AP_PARAM_INT16: {
if (value < 0) rounding_addition = -rounding_addition;
float v = value+rounding_addition;
v = constrain_float(v, INT16_MIN, INT16_MAX);
((AP_Int16 *)this)->set(v);
} else if (var_type == AP_PARAM_INT8) {
break;
}
case AP_PARAM_INT8: {
if (value < 0) rounding_addition = -rounding_addition;
float v = value+rounding_addition;
v = constrain_float(v, INT8_MIN, INT8_MAX);
((AP_Int8 *)this)->set(v);
break;
}
default:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this default. Also, if we change var_class to be an enum class then we'll NEED to remove the default.

break;
}
}

Expand Down
Loading