Skip to content

Commit

Permalink
AC_AutoTune: Convert the IF statement to a SWITCH statement
Browse files Browse the repository at this point in the history
  • Loading branch information
muramura committed May 14, 2024
1 parent 5c50da7 commit 2bd2bf7
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions libraries/AC_AutoTune/AC_AutoTune_Multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,9 @@ void AC_AutoTune_Multi::updating_angle_p_up(float &tune_p, float tune_p_max, flo
#if HAL_LOGGING_ENABLED
void AC_AutoTune_Multi::Log_AutoTune()
{
if ((tune_type == SP_DOWN) || (tune_type == SP_UP)) {
switch (tune_type) {
case SP_DOWN:
case SP_UP:
switch (axis) {
case ROLL:
Log_Write_AutoTune(axis, tune_type, target_angle, test_angle_min, test_angle_max, tune_roll_rp, tune_roll_rd, tune_roll_sp, test_accel_max);
Expand All @@ -1038,7 +1040,9 @@ void AC_AutoTune_Multi::Log_AutoTune()
Log_Write_AutoTune(axis, tune_type, target_angle, test_angle_min, test_angle_max, tune_yaw_rp, tune_yaw_rd, tune_yaw_sp, test_accel_max);
break;
}
} else {
break;

default:
switch (axis) {
case ROLL:
Log_Write_AutoTune(axis, tune_type, target_rate, test_rate_min, test_rate_max, tune_roll_rp, tune_roll_rd, tune_roll_sp, test_accel_max);
Expand All @@ -1053,6 +1057,7 @@ void AC_AutoTune_Multi::Log_AutoTune()
Log_Write_AutoTune(axis, tune_type, target_rate, test_rate_min, test_rate_max, tune_yaw_rp, tune_yaw_rd, tune_yaw_sp, test_accel_max);
break;
}
break;
}

}
Expand Down Expand Up @@ -1165,7 +1170,9 @@ void AC_AutoTune_Multi::twitch_test_run(AxisType test_axis, const float dir_sign
// hold current attitude
attitude_control->input_rate_bf_roll_pitch_yaw(0.0f, 0.0f, 0.0f);

if ((tune_type == SP_DOWN) || (tune_type == SP_UP)) {
switch (tune_type) {
case SP_DOWN:
case SP_UP:
// step angle targets on first iteration
if (twitch_first_iter) {
twitch_first_iter = false;
Expand All @@ -1186,7 +1193,9 @@ void AC_AutoTune_Multi::twitch_test_run(AxisType test_axis, const float dir_sign
break;
}
}
} else {
break;

default:
// Testing rate P and D gains so will set body-frame rate targets.
// Rate controller will use existing body-frame rates and convert to motor outputs
// for all axes except the one we override here.
Expand All @@ -1205,6 +1214,7 @@ void AC_AutoTune_Multi::twitch_test_run(AxisType test_axis, const float dir_sign
attitude_control->rate_bf_yaw_target(dir_sign * target_rate + start_rate);
break;
}
break;
}

// capture this iteration's rotation rate and lean angle
Expand Down

0 comments on commit 2bd2bf7

Please sign in to comment.