Skip to content

Commit

Permalink
commander: safety button disarm require land detector
Browse files Browse the repository at this point in the history
 - landed, maybe_landed, or ground_contact required before the safety
button is able to disarm
 - this reduces the risk of a faulty safety button triggering in regular
flight
  • Loading branch information
dagar authored and LorenzMeier committed Jan 21, 2020
1 parent 4f868fc commit cf195b0
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/modules/commander/Commander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,13 +1429,25 @@ Commander::run()
const bool previous_safety_off = _safety.safety_off;

if (_safety_sub.copy(&_safety)) {
// disarm if safety is now on and still armed
if (armed.armed && _safety.safety_switch_available && !_safety.safety_off) {

/* disarm if safety is now on and still armed */
if (armed.armed && (status.hil_state == vehicle_status_s::HIL_STATE_OFF)
&& _safety.safety_switch_available && !_safety.safety_off) {
bool safety_disarm_allowed = (status.hil_state == vehicle_status_s::HIL_STATE_OFF);

if (TRANSITION_CHANGED == arm_disarm(false, true, &mavlink_log_pub, "Safety button")) {
_status_changed = true;
// if land detector is available then prevent disarming via safety button if not landed
if (hrt_elapsed_time(&_land_detector.timestamp) < 1_s) {

bool maybe_landing = (_land_detector.landed || _land_detector.maybe_landed);

if (!maybe_landing) {
safety_disarm_allowed = false;
}
}

if (safety_disarm_allowed) {
if (TRANSITION_CHANGED == arm_disarm(false, true, &mavlink_log_pub, "Safety button")) {
_status_changed = true;
}
}
}

Expand Down

0 comments on commit cf195b0

Please sign in to comment.