Plane: allow control_mode enum to be in arbitrary order

never use control_mode >= BLAH. This requires the order to be important which greatly increases chance for unexpected behavior
Closes https://github.com/ArduPilot/ardupilot/issues/4656
This commit is contained in:
Tom Pittenger 2018-01-02 20:45:25 -08:00 committed by Tom Pittenger
parent 404e395880
commit 39a200b83f
4 changed files with 17 additions and 2 deletions

View File

@ -561,6 +561,9 @@ private:
// with STICK_MIXING=0 // with STICK_MIXING=0
bool auto_navigation_mode:1; bool auto_navigation_mode:1;
// this allows certain flight modes to mix RC input with throttle depending on airspeed_nudge_cm
bool throttle_allows_nudging:1;
// this controls throttle suppression in auto modes // this controls throttle suppression in auto modes
bool throttle_suppressed; bool throttle_suppressed;

View File

@ -135,7 +135,7 @@ void Plane::calc_airspeed_errors()
} }
// Bump up the target airspeed based on throttle nudging // Bump up the target airspeed based on throttle nudging
if (control_mode >= AUTO && airspeed_nudge_cm > 0) { if (throttle_allows_nudging && airspeed_nudge_cm > 0) {
target_airspeed_cm += airspeed_nudge_cm; target_airspeed_cm += airspeed_nudge_cm;
} }

View File

@ -581,7 +581,7 @@ void Plane::set_servos(void)
// setup flap outputs // setup flap outputs
set_servos_flaps(); set_servos_flaps();
if (control_mode >= FLY_BY_WIRE_B || if (auto_throttle_mode ||
quadplane.in_assisted_flight() || quadplane.in_assisted_flight() ||
quadplane.in_vtol_mode()) { quadplane.in_vtol_mode()) {
/* only do throttle slew limiting in modes where throttle /* only do throttle slew limiting in modes where throttle

View File

@ -327,6 +327,7 @@ void Plane::set_mode(enum FlightMode mode, mode_reason_t reason)
switch(control_mode) switch(control_mode)
{ {
case INITIALISING: case INITIALISING:
throttle_allows_nudging = true;
auto_throttle_mode = true; auto_throttle_mode = true;
auto_navigation_mode = false; auto_navigation_mode = false;
break; break;
@ -335,17 +336,20 @@ void Plane::set_mode(enum FlightMode mode, mode_reason_t reason)
case STABILIZE: case STABILIZE:
case TRAINING: case TRAINING:
case FLY_BY_WIRE_A: case FLY_BY_WIRE_A:
throttle_allows_nudging = false;
auto_throttle_mode = false; auto_throttle_mode = false;
auto_navigation_mode = false; auto_navigation_mode = false;
break; break;
case AUTOTUNE: case AUTOTUNE:
throttle_allows_nudging = false;
auto_throttle_mode = false; auto_throttle_mode = false;
auto_navigation_mode = false; auto_navigation_mode = false;
autotune_start(); autotune_start();
break; break;
case ACRO: case ACRO:
throttle_allows_nudging = false;
auto_throttle_mode = false; auto_throttle_mode = false;
auto_navigation_mode = false; auto_navigation_mode = false;
acro_state.locked_roll = false; acro_state.locked_roll = false;
@ -353,6 +357,7 @@ void Plane::set_mode(enum FlightMode mode, mode_reason_t reason)
break; break;
case CRUISE: case CRUISE:
throttle_allows_nudging = false;
auto_throttle_mode = true; auto_throttle_mode = true;
auto_navigation_mode = false; auto_navigation_mode = false;
cruise_state.locked_heading = false; cruise_state.locked_heading = false;
@ -365,6 +370,7 @@ void Plane::set_mode(enum FlightMode mode, mode_reason_t reason)
break; break;
case FLY_BY_WIRE_B: case FLY_BY_WIRE_B:
throttle_allows_nudging = false;
auto_throttle_mode = true; auto_throttle_mode = true;
auto_navigation_mode = false; auto_navigation_mode = false;
@ -376,12 +382,14 @@ void Plane::set_mode(enum FlightMode mode, mode_reason_t reason)
case CIRCLE: case CIRCLE:
// the altitude to circle at is taken from the current altitude // the altitude to circle at is taken from the current altitude
throttle_allows_nudging = false;
auto_throttle_mode = true; auto_throttle_mode = true;
auto_navigation_mode = true; auto_navigation_mode = true;
next_WP_loc.alt = current_loc.alt; next_WP_loc.alt = current_loc.alt;
break; break;
case AUTO: case AUTO:
throttle_allows_nudging = true;
auto_throttle_mode = true; auto_throttle_mode = true;
auto_navigation_mode = true; auto_navigation_mode = true;
if (quadplane.available() && quadplane.enable == 2) { if (quadplane.available() && quadplane.enable == 2) {
@ -397,6 +405,7 @@ void Plane::set_mode(enum FlightMode mode, mode_reason_t reason)
break; break;
case RTL: case RTL:
throttle_allows_nudging = true;
auto_throttle_mode = true; auto_throttle_mode = true;
auto_navigation_mode = true; auto_navigation_mode = true;
prev_WP_loc = current_loc; prev_WP_loc = current_loc;
@ -404,6 +413,7 @@ void Plane::set_mode(enum FlightMode mode, mode_reason_t reason)
break; break;
case LOITER: case LOITER:
throttle_allows_nudging = true;
auto_throttle_mode = true; auto_throttle_mode = true;
auto_navigation_mode = true; auto_navigation_mode = true;
do_loiter_at_location(); do_loiter_at_location();
@ -418,6 +428,7 @@ void Plane::set_mode(enum FlightMode mode, mode_reason_t reason)
case AVOID_ADSB: case AVOID_ADSB:
case GUIDED: case GUIDED:
throttle_allows_nudging = true;
auto_throttle_mode = true; auto_throttle_mode = true;
auto_navigation_mode = true; auto_navigation_mode = true;
guided_throttle_passthru = false; guided_throttle_passthru = false;
@ -434,6 +445,7 @@ void Plane::set_mode(enum FlightMode mode, mode_reason_t reason)
case QLOITER: case QLOITER:
case QLAND: case QLAND:
case QRTL: case QRTL:
throttle_allows_nudging = true;
auto_navigation_mode = false; auto_navigation_mode = false;
if (!quadplane.init_mode()) { if (!quadplane.init_mode()) {
control_mode = previous_mode; control_mode = previous_mode;