Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Rover/AP_Arming_Rover.cpp
4183 views
1
#include "AP_Arming_Rover.h"
2
#include "Rover.h"
3
4
// perform pre_arm_rc_checks checks
5
bool AP_Arming_Rover::rc_calibration_checks(const bool display_failure)
6
{
7
// set rc-checks to success if RC checks are disabled
8
if (!check_enabled(Check::RC)) {
9
return true;
10
}
11
12
const RC_Channel *channels[] = {
13
rover.channel_steer,
14
rover.channel_throttle
15
};
16
const char *channel_names[] = {"Steer", "Throttle"};
17
18
for (uint8_t i= 0 ; i < ARRAY_SIZE(channels); i++) {
19
const RC_Channel *channel = channels[i];
20
const char *channel_name = channel_names[i];
21
// check if radio has been calibrated
22
if (channel->get_radio_min() > RC_Channel::RC_CALIB_MIN_LIMIT_PWM) {
23
check_failed(Check::RC, display_failure, "%s radio min too high", channel_name);
24
return false;
25
}
26
if (channel->get_radio_max() < RC_Channel::RC_CALIB_MAX_LIMIT_PWM) {
27
check_failed(Check::RC, display_failure, "%s radio max too low", channel_name);
28
return false;
29
}
30
}
31
return AP_Arming::rc_calibration_checks(display_failure);
32
}
33
34
// performs pre_arm gps related checks and returns true if passed
35
bool AP_Arming_Rover::gps_checks(bool display_failure)
36
{
37
if (!require_location &&
38
!rover.control_mode->requires_position() &&
39
!rover.control_mode->requires_velocity()) {
40
// we don't care!
41
return true;
42
}
43
44
// call parent gps checks
45
if (!AP_Arming::gps_checks(display_failure)) {
46
return false;
47
}
48
49
const AP_AHRS &ahrs = AP::ahrs();
50
51
// always check if inertial nav has started and is ready
52
char failure_msg[50] = {};
53
if (!ahrs.pre_arm_check(true, failure_msg, sizeof(failure_msg))) {
54
check_failed(display_failure, "AHRS: %s", failure_msg);
55
return false;
56
}
57
58
// check for ekf failsafe
59
if (rover.failsafe.ekf) {
60
check_failed(display_failure, "EKF failsafe");
61
return false;
62
}
63
64
// ensure position estimate is ok
65
if (!rover.ekf_position_ok()) {
66
// vehicle level position estimate checks
67
check_failed(display_failure, "Need Position Estimate");
68
return false;
69
}
70
71
return true;
72
}
73
74
bool AP_Arming_Rover::pre_arm_checks(bool report)
75
{
76
if (armed) {
77
// if we are already armed then skip the checks
78
return true;
79
}
80
81
if (!hal.scheduler->is_system_initialized()) {
82
check_failed(report, "System not initialised");
83
return false;
84
}
85
86
//are arming checks disabled?
87
if (checks_to_perform == 0) {
88
return mandatory_checks(report);
89
}
90
91
if (rover.g2.sailboat.sail_enabled() && !rover.g2.windvane.enabled()) {
92
check_failed(report, "Sailing enabled with no WindVane");
93
return false;
94
}
95
96
#pragma clang diagnostic push
97
#pragma clang diagnostic ignored "-Wbitwise-instead-of-logical"
98
return (AP_Arming::pre_arm_checks(report)
99
& motor_checks(report)
100
#if AP_OAPATHPLANNER_ENABLED
101
& oa_check(report)
102
#endif
103
& parameter_checks(report)
104
& mode_checks(report));
105
#pragma clang diagnostic pop
106
}
107
108
bool AP_Arming_Rover::arm_checks(AP_Arming::Method method)
109
{
110
if (method == AP_Arming::Method::RUDDER) {
111
// check if arming/disarming allowed from this mode
112
if (!rover.control_mode->allows_arming_from_transmitter()) {
113
check_failed(true, "Mode not rudder-armable");
114
return false;
115
}
116
}
117
118
//are arming checks disabled?
119
if (checks_to_perform == 0) {
120
return true;
121
}
122
return AP_Arming::arm_checks(method);
123
}
124
125
void AP_Arming_Rover::update_soft_armed()
126
{
127
hal.util->set_soft_armed(is_armed() &&
128
hal.util->safety_switch_state() != AP_HAL::Util::SAFETY_DISARMED);
129
#if HAL_LOGGING_ENABLED
130
AP::logger().set_vehicle_armed(hal.util->get_soft_armed());
131
#endif
132
}
133
134
/*
135
arm motors
136
*/
137
bool AP_Arming_Rover::arm(AP_Arming::Method method, const bool do_arming_checks)
138
{
139
if (!AP_Arming::arm(method, do_arming_checks)) {
140
AP_Notify::events.arming_failed = true;
141
return false;
142
}
143
144
// Set the SmartRTL home location. If activated, SmartRTL will ultimately try to land at this point
145
rover.g2.smart_rtl.set_home(true);
146
147
// initialize simple mode heading
148
rover.mode_simple.init_heading();
149
150
// save home heading for use in sail vehicles
151
rover.g2.windvane.record_home_heading();
152
153
update_soft_armed();
154
155
send_arm_disarm_statustext("Throttle armed");
156
157
return true;
158
}
159
160
/*
161
disarm motors
162
*/
163
bool AP_Arming_Rover::disarm(const AP_Arming::Method method, bool do_disarm_checks)
164
{
165
if (method == AP_Arming::Method::RUDDER) {
166
if (rover.g2.motors.active()) {
167
// can't emit a message here as full-rudder while driving
168
// is not uncommon
169
return false;
170
}
171
}
172
173
if (!AP_Arming::disarm(method, do_disarm_checks)) {
174
return false;
175
}
176
if (rover.control_mode != &rover.mode_auto) {
177
// reset the mission on disarm if we are not in auto
178
rover.mode_auto.mission.reset();
179
}
180
181
update_soft_armed();
182
183
send_arm_disarm_statustext("Throttle disarmed");
184
185
return true;
186
}
187
188
#if AP_OAPATHPLANNER_ENABLED
189
// check object avoidance has initialised correctly
190
bool AP_Arming_Rover::oa_check(bool report)
191
{
192
char failure_msg[50] = {};
193
if (rover.g2.oa.pre_arm_check(failure_msg, ARRAY_SIZE(failure_msg))) {
194
return true;
195
}
196
197
check_failed(report, "%s", failure_msg);
198
return false;
199
}
200
#endif // AP_OAPATHPLANNER_ENABLED
201
202
// perform parameter checks
203
bool AP_Arming_Rover::parameter_checks(bool report)
204
{
205
// success if parameter checks are disabled
206
if (!check_enabled(Check::PARAMETERS)) {
207
return true;
208
}
209
210
// check waypoint speed is positive
211
if (!is_positive(rover.g2.wp_nav.get_default_speed())) {
212
check_failed(Check::PARAMETERS, report, "WP_SPEED too low");
213
return false;
214
}
215
216
return true;
217
}
218
219
// check if arming allowed from this mode
220
bool AP_Arming_Rover::mode_checks(bool report)
221
{
222
//display failure if arming in this mode is not allowed
223
if (!rover.control_mode->allows_arming()) {
224
check_failed(report, "Mode not armable");
225
return false;
226
}
227
return true;
228
}
229
230
// check motors are ready
231
bool AP_Arming_Rover::motor_checks(bool report)
232
{
233
bool ret = rover.g2.motors.pre_arm_check(report);
234
235
#if HAL_TORQEEDO_ENABLED
236
char failure_msg[50] = {};
237
AP_Torqeedo *torqeedo = AP_Torqeedo::get_singleton();
238
if (torqeedo != nullptr) {
239
if (!torqeedo->pre_arm_checks(failure_msg, ARRAY_SIZE(failure_msg))) {
240
check_failed(report, "Torqeedo: %s", failure_msg);
241
ret = false;
242
}
243
}
244
#endif
245
246
return ret;
247
}
248
249