PX4 Firmware
PX4 Autopilot Software http://px4.io
preArmCheck.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 #include "../PreFlightCheck.hpp"
35 
36 #include <ArmAuthorization.h>
37 #include <systemlib/mavlink_log.h>
39 
41  const safety_s &safety, const uint8_t arm_requirements)
42 {
43  bool prearm_ok = true;
44 
45  // USB not connected
46  if (!status_flags.circuit_breaker_engaged_usb_check && status_flags.usb_connected) {
47  mavlink_log_critical(mavlink_log_pub, "Arming denied! Flying with USB is not safe");
48 
49  prearm_ok = false;
50  }
51 
52  // battery and system power status
53  if (!status_flags.circuit_breaker_engaged_power_check) {
54 
55  // Fail transition if power is not good
56  if (!status_flags.condition_power_input_valid) {
57  mavlink_log_critical(mavlink_log_pub, "Arming denied! Connect power module");
58 
59  prearm_ok = false;
60  }
61 
62  // main battery level
63  if (!status_flags.condition_battery_healthy) {
64  if (prearm_ok) {
65  mavlink_log_critical(mavlink_log_pub, "Arming denied! Check battery");
66  }
67 
68  prearm_ok = false;
69  }
70  }
71 
72  // Arm Requirements: mission
73  if (arm_requirements & ARM_REQ_MISSION_BIT) {
74 
75  if (!status_flags.condition_auto_mission_available) {
76  if (prearm_ok) {
77  mavlink_log_critical(mavlink_log_pub, "Arming denied! No valid mission");
78  }
79 
80  prearm_ok = false;
81  }
82 
83  if (!status_flags.condition_global_position_valid) {
84  if (prearm_ok) {
85  mavlink_log_critical(mavlink_log_pub, "Arming denied! Missions require a global position");
86  }
87 
88  prearm_ok = false;
89  }
90  }
91 
92  // Arm Requirements: global position
93  if (arm_requirements & ARM_REQ_GPS_BIT) {
94 
95  if (!status_flags.condition_global_position_valid) {
96  if (prearm_ok) {
97  mavlink_log_critical(mavlink_log_pub, "Arming denied! Global position required");
98  }
99 
100  prearm_ok = false;
101  }
102  }
103 
104  // safety button
105  if (safety.safety_switch_available && !safety.safety_off) {
106  // Fail transition if we need safety switch press
107  if (prearm_ok) {
108  mavlink_log_critical(mavlink_log_pub, "Arming denied! Press safety switch first");
109  }
110 
111  prearm_ok = false;
112  }
113 
114  if (status_flags.avoidance_system_required && !status_flags.avoidance_system_valid) {
115  if (prearm_ok) {
116  mavlink_log_critical(mavlink_log_pub, "Arming denied! Avoidance system not ready");
117  }
118 
119  prearm_ok = false;
120 
121  }
122 
123  if (status_flags.condition_escs_error && (arm_requirements & ARM_REQ_ESCS_CHECK_BIT)) {
124  if (prearm_ok) {
125  mavlink_log_critical(mavlink_log_pub, "Arming denied! One or more ESCs are offline");
126  prearm_ok = false;
127  }
128  }
129 
130  // Arm Requirements: authorization
131  // check last, and only if everything else has passed
132  if ((arm_requirements & ARM_REQ_ARM_AUTH_BIT) && prearm_ok) {
133  if (arm_auth_check() != vehicle_command_ack_s::VEHICLE_RESULT_ACCEPTED) {
134  // feedback provided in arm_auth_check
135  prearm_ok = false;
136  }
137  }
138 
139 
140  return prearm_ok;
141 }
static orb_advert_t * mavlink_log_pub
static struct vehicle_status_flags_s status_flags
Definition: Commander.cpp:155
uint8_t arm_auth_check()
bool safety_switch_available
Definition: safety.h:54
static struct safety_s safety
Definition: Commander.cpp:140
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
static uint8_t arm_requirements
Definition: Commander.cpp:159
static bool preArmCheck(orb_advert_t *mavlink_log_pub, const vehicle_status_flags_s &status_flags, const safety_s &safety, const uint8_t arm_requirements)
Definition: preArmCheck.cpp:40
bool safety_off
Definition: safety.h:55