@@ -185,6 +185,9 @@ void AC_AutoTune::send_step_string()
185
185
case TESTING:
186
186
GCS_SEND_TEXT (MAV_SEVERITY_INFO, " AutoTune: Testing" );
187
187
return ;
188
+ case COMPLETE:
189
+ GCS_SEND_TEXT (MAV_SEVERITY_INFO, " AutoTune: Complete" );
190
+ break ;
188
191
}
189
192
GCS_SEND_TEXT (MAV_SEVERITY_INFO, " AutoTune: unknown step" );
190
193
}
@@ -387,11 +390,6 @@ void AC_AutoTune::control_attitude()
387
390
step = TESTING;
388
391
step_start_time_ms = now;
389
392
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);
395
393
}
396
394
397
395
// Initialize test-specific variables
@@ -419,9 +417,6 @@ void AC_AutoTune::control_attitude()
419
417
420
418
case TESTING: {
421
419
// Run the twitching step
422
- load_gains (GAIN_TEST);
423
-
424
- // run the test
425
420
test_run (axis, direction_sign);
426
421
427
422
// Check for failure causing reverse response
@@ -569,9 +564,7 @@ void AC_AutoTune::control_attitude()
569
564
update_gcs (AUTOTUNE_MESSAGE_SUCCESS);
570
565
LOGGER_WRITE_EVENT (LogEvent::AUTOTUNE_SUCCESS);
571
566
AP_Notify::events.autotune_complete = true ;
572
-
573
- // Return to original gains for landing
574
- load_gains (GainType::GAIN_ORIGINAL);
567
+ step = COMPLETE;
575
568
} else {
576
569
AP_Notify::events.autotune_next_axis = true ;
577
570
reset_update_gain_variables ();
@@ -586,16 +579,39 @@ void AC_AutoTune::control_attitude()
586
579
attitude_control->input_euler_angle_roll_pitch_yaw_cd (0 .0f , 0 .0f , ahrs_view->yaw_sensor , false );
587
580
}
588
581
589
- // set gains to their intra-test values (which are very close to the original gains)
590
- load_gains (GAIN_INTRA_TEST);
591
-
592
582
// reset testing step
593
583
step = WAITING_FOR_LEVEL;
594
584
positive_direction = twitch_reverse_direction ();
595
585
step_start_time_ms = now;
596
586
level_start_time_ms = now;
597
587
step_time_limit_ms = AUTOTUNE_REQUIRED_LEVEL_TIME_MS;
598
588
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 ;
599
615
}
600
616
}
601
617
0 commit comments