mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-30 12:30:34 +08:00
Commander: start pulling arming related parts into separate folder
* PreFlightCheck: remove unused reportFailures flag * Commander: pull all pre flight checks together on the PreFlightCheck class * PreFlightCheck: separate checks into their own files
This commit is contained in:
committed by
Daniel Agar
parent
08a27492b4
commit
1a79f75f94
@@ -46,11 +46,9 @@
|
||||
#include <systemlib/mavlink_log.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
|
||||
|
||||
#include "Arming/PreFlightCheck/PreFlightCheck.hpp"
|
||||
#include "state_machine_helper.h"
|
||||
#include "commander_helper.h"
|
||||
#include "PreflightCheck.h"
|
||||
#include "arm_auth.h"
|
||||
|
||||
static constexpr const char reason_no_rc[] = "no RC";
|
||||
static constexpr const char reason_no_offboard[] = "no offboard";
|
||||
@@ -132,13 +130,13 @@ transition_result_t arming_state_transition(vehicle_status_s *status, const safe
|
||||
*/
|
||||
bool preflight_check_ret = true;
|
||||
|
||||
const bool checkGNSS = (arm_requirements & ARM_REQ_GPS_BIT);
|
||||
const bool checkGNSS = (arm_requirements & PreFlightCheck::ARM_REQ_GPS_BIT);
|
||||
|
||||
/* only perform the pre-arm check if we have to */
|
||||
if (fRunPreArmChecks && (new_arming_state == vehicle_status_s::ARMING_STATE_ARMED)
|
||||
&& !hil_enabled) {
|
||||
|
||||
preflight_check_ret = Preflight::preflightCheck(mavlink_log_pub, *status, *status_flags, checkGNSS, true, true,
|
||||
preflight_check_ret = PreFlightCheck::preflightCheck(mavlink_log_pub, *status, *status_flags, checkGNSS, true, true,
|
||||
time_since_boot);
|
||||
|
||||
if (preflight_check_ret) {
|
||||
@@ -157,7 +155,8 @@ transition_result_t arming_state_transition(vehicle_status_s *status, const safe
|
||||
|
||||
if ((last_preflight_check == 0) || (hrt_elapsed_time(&last_preflight_check) > 1000 * 1000)) {
|
||||
|
||||
status_flags->condition_system_sensors_initialized = Preflight::preflightCheck(mavlink_log_pub, *status, *status_flags,
|
||||
status_flags->condition_system_sensors_initialized = PreFlightCheck::preflightCheck(mavlink_log_pub, *status,
|
||||
*status_flags,
|
||||
checkGNSS, false, false, time_since_boot);
|
||||
|
||||
last_preflight_check = hrt_absolute_time();
|
||||
@@ -179,7 +178,7 @@ transition_result_t arming_state_transition(vehicle_status_s *status, const safe
|
||||
|
||||
if (fRunPreArmChecks && preflight_check_ret) {
|
||||
// only bother running prearm if preflight was successful
|
||||
prearm_check_ret = prearm_check(mavlink_log_pub, *status_flags, safety, arm_requirements);
|
||||
prearm_check_ret = PreFlightCheck::preArmCheck(mavlink_log_pub, *status_flags, safety, arm_requirements);
|
||||
}
|
||||
|
||||
if (!preflight_check_ret || !prearm_check_ret) {
|
||||
@@ -1009,115 +1008,8 @@ void reset_offboard_loss_globals(actuator_armed_s *armed, const bool old_failsaf
|
||||
}
|
||||
}
|
||||
|
||||
bool prearm_check(orb_advert_t *mavlink_log_pub, const vehicle_status_flags_s &status_flags, const safety_s &safety,
|
||||
const uint8_t arm_requirements)
|
||||
{
|
||||
bool reportFailures = true;
|
||||
bool prearm_ok = true;
|
||||
|
||||
|
||||
// USB not connected
|
||||
if (!status_flags.circuit_breaker_engaged_usb_check && status_flags.usb_connected) {
|
||||
if (reportFailures) {
|
||||
mavlink_log_critical(mavlink_log_pub, "Arming denied! Flying with USB is not safe");
|
||||
}
|
||||
|
||||
prearm_ok = false;
|
||||
}
|
||||
|
||||
// battery and system power status
|
||||
if (!status_flags.circuit_breaker_engaged_power_check) {
|
||||
|
||||
// Fail transition if power is not good
|
||||
if (!status_flags.condition_power_input_valid) {
|
||||
if (reportFailures) {
|
||||
mavlink_log_critical(mavlink_log_pub, "Arming denied! Connect power module");
|
||||
}
|
||||
|
||||
prearm_ok = false;
|
||||
}
|
||||
|
||||
// main battery level
|
||||
if (!status_flags.condition_battery_healthy) {
|
||||
if (prearm_ok && reportFailures) {
|
||||
mavlink_log_critical(mavlink_log_pub, "Arming denied! Check battery");
|
||||
}
|
||||
|
||||
prearm_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Arm Requirements: mission
|
||||
if (arm_requirements & ARM_REQ_MISSION_BIT) {
|
||||
|
||||
if (!status_flags.condition_auto_mission_available) {
|
||||
if (prearm_ok && reportFailures) {
|
||||
mavlink_log_critical(mavlink_log_pub, "Arming denied! No valid mission");
|
||||
}
|
||||
|
||||
prearm_ok = false;
|
||||
}
|
||||
|
||||
if (!status_flags.condition_global_position_valid) {
|
||||
if (prearm_ok && reportFailures) {
|
||||
mavlink_log_critical(mavlink_log_pub, "Arming denied! Missions require a global position");
|
||||
}
|
||||
|
||||
prearm_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Arm Requirements: global position
|
||||
if (arm_requirements & ARM_REQ_GPS_BIT) {
|
||||
|
||||
if (!status_flags.condition_global_position_valid) {
|
||||
if (prearm_ok && reportFailures) {
|
||||
mavlink_log_critical(mavlink_log_pub, "Arming denied! Global position required");
|
||||
}
|
||||
|
||||
prearm_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
// safety button
|
||||
if (safety.safety_switch_available && !safety.safety_off) {
|
||||
// Fail transition if we need safety switch press
|
||||
if (prearm_ok && reportFailures) {
|
||||
mavlink_log_critical(mavlink_log_pub, "Arming denied! Press safety switch first");
|
||||
}
|
||||
|
||||
prearm_ok = false;
|
||||
}
|
||||
|
||||
if (status_flags.avoidance_system_required && !status_flags.avoidance_system_valid) {
|
||||
if (prearm_ok && reportFailures) {
|
||||
mavlink_log_critical(mavlink_log_pub, "Arming denied! Avoidance system not ready");
|
||||
}
|
||||
|
||||
prearm_ok = false;
|
||||
|
||||
}
|
||||
|
||||
if (status_flags.condition_escs_error && (arm_requirements & ARM_REQ_ESCS_CHECK_BIT)) {
|
||||
if (prearm_ok && reportFailures) {
|
||||
mavlink_log_critical(mavlink_log_pub, "Arming denied! One or more ESCs are offline");
|
||||
prearm_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Arm Requirements: authorization
|
||||
// check last, and only if everything else has passed
|
||||
if ((arm_requirements & ARM_REQ_ARM_AUTH_BIT) && prearm_ok) {
|
||||
if (arm_auth_check() != vehicle_command_ack_s::VEHICLE_RESULT_ACCEPTED) {
|
||||
// feedback provided in arm_auth_check
|
||||
prearm_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return prearm_ok;
|
||||
}
|
||||
|
||||
|
||||
void battery_failsafe(orb_advert_t *mavlink_log_pub, const vehicle_status_s &status,
|
||||
const vehicle_status_flags_s &status_flags, commander_state_s *internal_state, const uint8_t battery_warning,
|
||||
|
||||
Reference in New Issue
Block a user