Skip to content

Commit

Permalink
[bugfix] Fix: RC really lost procedure only active when launch has be…
Browse files Browse the repository at this point in the history
…en pressed. When not launched, the RC_LOST_MODE is not set and throttle is kept from the last manual input. Solves #2286
  • Loading branch information
dewagter committed Oct 8, 2018
1 parent 00f5745 commit 7bf43f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 9 additions & 5 deletions sw/airborne/firmwares/fixedwing/autopilot_static.c
Expand Up @@ -114,17 +114,21 @@ void autopilot_static_on_rc_frame(void)
uint8_t mode_changed = false;
copy_from_to_fbw();

/* really_lost is true if we lost RC in MANUAL or AUTO1 */
uint8_t really_lost = bit_is_set(imcu_get_status(), STATUS_RADIO_REALLY_LOST) &&
/* rc_lost_while_in_use is true if we lost RC in MANUAL or AUTO1 */
uint8_t rc_lost_while_in_use = bit_is_set(imcu_get_status(), STATUS_RADIO_REALLY_LOST) &&
(autopilot_get_mode() == AP_MODE_AUTO1 || autopilot_get_mode() == AP_MODE_MANUAL);

/* RC_LOST_MODE defaults to AP_MODE_HOME, but it can also be set to NAV_MODE_NAV or MANUAL when the RC receiver is well configured to send failsafe commands */
if (rc_lost_while_in_use) { // Always: no exceptions!
mode_changed = autopilot_set_mode(RC_LOST_MODE);
}

/* If in-flight, with good GPS but too far, then activate HOME mode
* In MANUAL with good RC, FBW will allow to override. */
if (autopilot_get_mode() != AP_MODE_HOME && autopilot_get_mode() != AP_MODE_GPS_OUT_OF_ORDER && autopilot.launch) {
if (too_far_from_home || datalink_lost() || higher_than_max_altitude()) {
mode_changed = autopilot_set_mode(AP_MODE_HOME);
}
if (really_lost) {
mode_changed = autopilot_set_mode(RC_LOST_MODE);
}
}
if (bit_is_set(imcu_get_status(), AVERAGED_CHANNELS_SENT)) {
bool pprz_mode_changed = pprz_mode_update();
Expand Down
7 changes: 6 additions & 1 deletion sw/airborne/firmwares/fixedwing/nav.c
Expand Up @@ -424,7 +424,12 @@ void nav_home(void)
NavCircleWaypoint(WP_HOME, FAILSAFE_HOME_RADIUS);
/** Nominal speed */
nav_pitch = 0.;
v_ctl_mode = V_CTL_MODE_AUTO_ALT;
if (autopilot_in_flight() && autopilot.launch) {
v_ctl_mode = V_CTL_MODE_AUTO_ALT;
} else {
v_ctl_mode = V_CTL_MODE_AUTO_THROTTLE;
v_ctl_throttle_setpoint = 0;
}
nav_altitude = ground_alt + HOME_MODE_HEIGHT;
compute_dist2_to_home();
dist2_to_wp = dist2_to_home;
Expand Down

0 comments on commit 7bf43f6

Please sign in to comment.