mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-07-27 08:58:09 +08:00
commander: enable arming on boot
This commit is contained in:
@@ -1870,6 +1870,7 @@ void Commander::run()
|
||||
#endif // BOARD_HAS_POWER_CONTROL
|
||||
|
||||
_boot_timestamp = hrt_absolute_time();
|
||||
_arm_on_boot_requested = _param_com_arm_on_boot.get();
|
||||
|
||||
arm_auth_init(&_mavlink_log_pub, &_vehicle_status.system_id);
|
||||
|
||||
@@ -1949,6 +1950,20 @@ void Commander::run()
|
||||
|
||||
perf_end(_preflight_check_perf);
|
||||
checkAndInformReadyForTakeoff();
|
||||
|
||||
// Arm automatically on boot once preflight checks pass
|
||||
// _arm_on_boot_done prevents re-arming after disarming
|
||||
const bool should_arm_on_boot = _arm_on_boot_requested
|
||||
&& !_arm_on_boot_done
|
||||
&& !isArmed()
|
||||
&& hrt_elapsed_time(&_boot_timestamp) > 5_s
|
||||
&& pre_flight_checks_pass;
|
||||
|
||||
if (should_arm_on_boot) {
|
||||
if (arm(arm_disarm_reason_t::mission_start, false) != TRANSITION_DENIED) {
|
||||
_arm_on_boot_done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handle commands last, as the system needs to be updated to handle them
|
||||
|
||||
Reference in New Issue
Block a user