Copter: always store previous control mode

also minor spacing fixup
This commit is contained in:
Randy Mackay 2019-11-29 10:42:36 +09:00
parent f768e80458
commit b482d147df

View File

@ -202,9 +202,8 @@ bool Copter::set_mode(Mode::Number mode, ModeReason reason)
#if FRAME_CONFIG == HELI_FRAME
// do not allow helis to enter a non-manual throttle mode if the
// rotor runup is not complete
if (!ignore_checks &&
!new_flightmode->has_manual_throttle() &&
(motors->get_spool_state() == AP_Motors::SpoolState::SPOOLING_UP || motors->get_spool_state() == AP_Motors::SpoolState::SPOOLING_DOWN)) {
if (!ignore_checks && !new_flightmode->has_manual_throttle() &&
(motors->get_spool_state() == AP_Motors::SpoolState::SPOOLING_UP || motors->get_spool_state() == AP_Motors::SpoolState::SPOOLING_DOWN)) {
#if MODE_AUTOROTATE_ENABLED == ENABLED
//if the mode being exited is the autorotation mode allow mode change despite rotor not being at
//full speed. This will reduce altitude loss on bail-outs back to non-manual throttle modes
@ -219,12 +218,6 @@ bool Copter::set_mode(Mode::Number mode, ModeReason reason)
return false;
}
}
#if MODE_AUTOROTATE_ENABLED == ENABLED
// If changing to autorotate flight mode from a non-manual throttle mode, store the previous flight mode
// to exit back to it when interlock is re-engaged
prev_control_mode = control_mode;
#endif
#endif
#if FRAME_CONFIG != HELI_FRAME
@ -266,6 +259,9 @@ bool Copter::set_mode(Mode::Number mode, ModeReason reason)
// perform any cleanup required by previous flight mode
exit_mode(flightmode, new_flightmode);
// store previous flight mode (only used by tradeheli's autorotation)
prev_control_mode = control_mode;
// update flight mode
flightmode = new_flightmode;
control_mode = mode;