Skip to content

Commit f8f9533

Browse files
committed
AC_Autotune: Fix gain load problem when mode set to FAILED
1 parent 2565aa5 commit f8f9533

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

libraries/AC_AutoTune/AC_AutoTune.cpp

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ void AC_AutoTune::send_step_string()
185185
case TESTING:
186186
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "AutoTune: Testing");
187187
return;
188+
case COMPLETE:
189+
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "AutoTune: Complete");
190+
break;
188191
}
189192
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "AutoTune: unknown step");
190193
}
@@ -387,11 +390,6 @@ void AC_AutoTune::control_attitude()
387390
step = TESTING;
388391
step_start_time_ms = now;
389392
step_time_limit_ms = get_testing_step_timeout_ms();
390-
// set gains to their to-be-tested values
391-
load_gains(GAIN_TEST);
392-
} else {
393-
// when waiting for level we use the intra-test gains
394-
load_gains(GAIN_INTRA_TEST);
395393
}
396394

397395
// Initialize test-specific variables
@@ -419,9 +417,6 @@ void AC_AutoTune::control_attitude()
419417

420418
case TESTING: {
421419
// Run the twitching step
422-
load_gains(GAIN_TEST);
423-
424-
// run the test
425420
test_run(axis, direction_sign);
426421

427422
// Check for failure causing reverse response
@@ -569,9 +564,7 @@ void AC_AutoTune::control_attitude()
569564
update_gcs(AUTOTUNE_MESSAGE_SUCCESS);
570565
LOGGER_WRITE_EVENT(LogEvent::AUTOTUNE_SUCCESS);
571566
AP_Notify::events.autotune_complete = true;
572-
573-
// Return to original gains for landing
574-
load_gains(GainType::GAIN_ORIGINAL);
567+
step = COMPLETE;
575568
} else {
576569
AP_Notify::events.autotune_next_axis = true;
577570
reset_update_gain_variables();
@@ -586,16 +579,39 @@ void AC_AutoTune::control_attitude()
586579
attitude_control->input_euler_angle_roll_pitch_yaw_cd(0.0f, 0.0f, ahrs_view->yaw_sensor, false);
587580
}
588581

589-
// set gains to their intra-test values (which are very close to the original gains)
590-
load_gains(GAIN_INTRA_TEST);
591-
592582
// reset testing step
593583
step = WAITING_FOR_LEVEL;
594584
positive_direction = twitch_reverse_direction();
595585
step_start_time_ms = now;
596586
level_start_time_ms = now;
597587
step_time_limit_ms = AUTOTUNE_REQUIRED_LEVEL_TIME_MS;
598588
break;
589+
590+
case COMPLETE:
591+
// we don't need to do anything
592+
break;
593+
}
594+
595+
// Load the appropriate gains
596+
switch (step) {
597+
case WAITING_FOR_LEVEL:
598+
// when waiting for level we use the intra-test gains
599+
load_gains(GAIN_INTRA_TEST);
600+
break;
601+
case TESTING:
602+
// set gains to their to-be-tested values
603+
load_gains(GAIN_TEST);
604+
break;
605+
case UPDATE_GAINS:
606+
FALLTHROUGH;
607+
case ABORT:
608+
// set gains to their intra-test values (which are very close to the original gains)
609+
load_gains(GAIN_INTRA_TEST);
610+
break;
611+
case COMPLETE:
612+
// Return to original gains for landing
613+
load_gains(GainType::GAIN_ORIGINAL);
614+
break;
599615
}
600616
}
601617

libraries/AC_AutoTune/AC_AutoTune.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ class AC_AutoTune
208208
WAITING_FOR_LEVEL = 0, // autotune is waiting for vehicle to return to level before beginning the next twitch
209209
TESTING = 1, // autotune has begun a test and is watching the resulting vehicle movement
210210
UPDATE_GAINS = 2, // autotune has completed a test and is updating the gains based on the results
211-
ABORT = 3 // load normal gains and return to WAITING_FOR_LEVEL
211+
ABORT = 3, // load normal gains and return to WAITING_FOR_LEVEL
212+
COMPLETE = 4 // load original gains
212213
};
213214

214215
// mini steps performed while in Tuning mode, Testing step

0 commit comments

Comments
 (0)