Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Rover/AP_Arming_Rover.cpp
9572 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 (should_skip_all_checks()) {
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 (should_skip_all_checks()) {
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
}
130
131
/*
132
arm motors
133
*/
134
bool AP_Arming_Rover::arm(AP_Arming::Method method, const bool do_arming_checks)
135
{
136
if (!AP_Arming::arm(method, do_arming_checks)) {
137
AP_Notify::events.arming_failed = true;
138
return false;
139
}
140
141
// Set the SmartRTL home location. If activated, SmartRTL will ultimately try to land at this point
142
rover.g2.smart_rtl.set_home(true);
143
144
// initialize simple mode heading
145
rover.mode_simple.init_heading();
146
147
// save home heading for use in sail vehicles
148
rover.g2.windvane.record_home_heading();
149
150
#if HAL_LOGGING_ENABLED
151
// Tell logger it can start logging
152
AP::logger().set_vehicle_armed(true);
153
#endif
154
155
update_soft_armed();
156
157
send_arm_disarm_statustext("Throttle armed");
158
159
return true;
160
}
161
162
/*
163
disarm motors
164
*/
165
bool AP_Arming_Rover::disarm(const AP_Arming::Method method, bool do_disarm_checks)
166
{
167
if (method == AP_Arming::Method::RUDDER) {
168
if (rover.g2.motors.active()) {
169
// can't emit a message here as full-rudder while driving
170
// is not uncommon
171
return false;
172
}
173
}
174
175
if (!AP_Arming::disarm(method, do_disarm_checks)) {
176
return false;
177
}
178
if (rover.control_mode != &rover.mode_auto) {
179
// reset the mission on disarm if we are not in auto
180
rover.mode_auto.mission.reset();
181
}
182
183
#if HAL_LOGGING_ENABLED
184
// Tell logger it can stop logging
185
AP::logger().set_vehicle_armed(false);
186
#endif
187
188
update_soft_armed();
189
190
send_arm_disarm_statustext("Throttle disarmed");
191
192
return true;
193
}
194
195
#if AP_OAPATHPLANNER_ENABLED
196
// check object avoidance has initialised correctly
197
bool AP_Arming_Rover::oa_check(bool report)
198
{
199
char failure_msg[50] = {};
200
if (rover.g2.oa.pre_arm_check(failure_msg, ARRAY_SIZE(failure_msg))) {
201
return true;
202
}
203
204
check_failed(report, "%s", failure_msg);
205
return false;
206
}
207
#endif // AP_OAPATHPLANNER_ENABLED
208
209
// perform parameter checks
210
bool AP_Arming_Rover::parameter_checks(bool report)
211
{
212
// success if parameter checks are disabled
213
if (!check_enabled(Check::PARAMETERS)) {
214
return true;
215
}
216
217
// check waypoint speed is positive
218
if (!is_positive(rover.g2.wp_nav.get_default_speed())) {
219
check_failed(Check::PARAMETERS, report, "WP_SPEED too low");
220
return false;
221
}
222
223
return true;
224
}
225
226
// check if arming allowed from this mode
227
bool AP_Arming_Rover::mode_checks(bool report)
228
{
229
//display failure if arming in this mode is not allowed
230
if (!rover.control_mode->allows_arming()) {
231
check_failed(report, "Mode not armable");
232
return false;
233
}
234
return true;
235
}
236
237
// check motors are ready
238
bool AP_Arming_Rover::motor_checks(bool report)
239
{
240
bool ret = rover.g2.motors.pre_arm_check(report);
241
242
#if HAL_TORQEEDO_ENABLED
243
char failure_msg[50] = {};
244
AP_Torqeedo *torqeedo = AP_Torqeedo::get_singleton();
245
if (torqeedo != nullptr) {
246
if (!torqeedo->pre_arm_checks(failure_msg, ARRAY_SIZE(failure_msg))) {
247
check_failed(report, "Torqeedo: %s", failure_msg);
248
ret = false;
249
}
250
}
251
#endif
252
253
return ret;
254
}
255
256