-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
Autotune: Add switch to test gains after tune is complete #27754
Changes from all commits
6aefd1c
83e4dea
40cac3b
18c5e1b
caaf27e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,51 @@ void AC_AutoTune::stop() | |
// we expect the caller will change the flight mode back to the flight mode indicated by the flight mode switch | ||
} | ||
|
||
// Autotune aux function trigger | ||
void AC_AutoTune::do_aux_function(const RC_Channel::AuxSwitchPos ch_flag) | ||
{ | ||
if (mode != TuneMode::SUCCESS) { | ||
if (ch_flag == RC_Channel::AuxSwitchPos::HIGH) { | ||
gcs().send_text(MAV_SEVERITY_NOTICE,"AutoTune: must be complete to test gains"); | ||
} | ||
return; | ||
} | ||
|
||
switch(ch_flag) { | ||
case RC_Channel::AuxSwitchPos::LOW: | ||
// load original gains | ||
load_gains(GainType::GAIN_ORIGINAL); | ||
update_gcs(AUTOTUNE_MESSAGE_TESTING_END); | ||
break; | ||
case RC_Channel::AuxSwitchPos::MIDDLE: | ||
// Middle position is unused for now | ||
break; | ||
case RC_Channel::AuxSwitchPos::HIGH: | ||
// Load tuned gains | ||
load_gains(GainType::GAIN_TUNED); | ||
update_gcs(AUTOTUNE_MESSAGE_TESTING); | ||
break; | ||
} | ||
|
||
have_pilot_testing_command = true; | ||
} | ||
|
||
// Possibly save gains, called on disarm | ||
void AC_AutoTune::disarmed(const bool in_autotune_mode) | ||
{ | ||
// True if pilot is testing tuned gains | ||
const bool testing_tuned = have_pilot_testing_command && (loaded_gains == GainType::GAIN_TUNED); | ||
|
||
// True if in autotune mode and no pilot testing commands have been received | ||
const bool tune_complete_no_testing = !have_pilot_testing_command && in_autotune_mode; | ||
|
||
if (tune_complete_no_testing || testing_tuned) { | ||
save_tuning_gains(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you intend to save_tuning_gains() if switch is in lower position so we currently have the old gains loaded? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you have used the switch to test the gains and you have the switch in the "original gains" position then it should not save the tuned gains. If you have not used the switch to test the gains and are in AutoTune mode then it will save the gains. The is should be the same as the current behaviour. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm open to better suggestions but I could not think of anything else while preserving the current behaviour, we can't make it a requirement that everyone must setup the new switch to run autotune. Now we can send aux functions from the gcs we can't really check if the user has setup a switch until they first trigger it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about reverse the switch?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how that is less confusing, the pattern (there are one or two exceptions) for functions is that high is to take some action. In this case the action is the thing we have added namely the ability to test gains in any mode. Original gains and discarding in other modes is the existing behavior, it would be abit odd to require the user to flip a switch to high for that. Don't forget that aux functions are edge triggered, it does not matter where the switch is until autotune has completed, only changes after that (and before you disarm) will do anything. |
||
} else { | ||
reset(); | ||
} | ||
} | ||
|
||
// initialise position controller | ||
bool AC_AutoTune::init_position_controller(void) | ||
{ | ||
|
@@ -524,6 +569,9 @@ void AC_AutoTune::control_attitude() | |
update_gcs(AUTOTUNE_MESSAGE_SUCCESS); | ||
LOGGER_WRITE_EVENT(LogEvent::AUTOTUNE_SUCCESS); | ||
AP_Notify::events.autotune_complete = true; | ||
|
||
// Return to original gains for landing | ||
load_gains(GainType::GAIN_ORIGINAL); | ||
} else { | ||
AP_Notify::events.autotune_next_axis = true; | ||
reset_update_gain_variables(); | ||
|
@@ -590,7 +638,12 @@ void AC_AutoTune::backup_gains_and_initialise() | |
*/ | ||
void AC_AutoTune::load_gains(enum GainType gain_type) | ||
{ | ||
// todo: add previous setting so gains are not loaded on each loop. | ||
if (loaded_gains == gain_type) { | ||
// Loaded gains are already of correct type | ||
return; | ||
} | ||
loaded_gains = gain_type; | ||
|
||
switch (gain_type) { | ||
case GAIN_ORIGINAL: | ||
load_orig_gains(); | ||
|
@@ -624,15 +677,17 @@ void AC_AutoTune::update_gcs(uint8_t message_id) const | |
GCS_SEND_TEXT(MAV_SEVERITY_NOTICE,"AutoTune: Failed"); | ||
break; | ||
case AUTOTUNE_MESSAGE_TESTING: | ||
GCS_SEND_TEXT(MAV_SEVERITY_NOTICE,"AutoTune: Pilot Testing"); | ||
break; | ||
case AUTOTUNE_MESSAGE_SAVED_GAINS: | ||
GCS_SEND_TEXT(MAV_SEVERITY_NOTICE,"AutoTune: Saved gains for %s%s%s%s", | ||
GCS_SEND_TEXT(MAV_SEVERITY_NOTICE,"AutoTune: %s gains for %s%s%s%s", | ||
(message_id == AUTOTUNE_MESSAGE_SAVED_GAINS) ? "Saved" : "Pilot Testing", | ||
(axes_completed&AUTOTUNE_AXIS_BITMASK_ROLL)?"Roll ":"", | ||
(axes_completed&AUTOTUNE_AXIS_BITMASK_PITCH)?"Pitch ":"", | ||
(axes_completed&AUTOTUNE_AXIS_BITMASK_YAW)?"Yaw(E)":"", | ||
(axes_completed&AUTOTUNE_AXIS_BITMASK_YAW_D)?"Yaw(D)":""); | ||
break; | ||
case AUTOTUNE_MESSAGE_TESTING_END: | ||
GCS_SEND_TEXT(MAV_SEVERITY_NOTICE,"AutoTune: original gains restored"); | ||
break; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where we could change to mode AutoTune if the tune has not been completed.
********* For Discussion *********