forked from ArduPilot/ardupilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAP_Arming.cpp
123 lines (111 loc) · 3.95 KB
/
AP_Arming.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "AP_Arming.h"
#include "Rover.h"
enum HomeState AP_Arming_Rover::home_status() const
{
return rover.home_is_set;
}
// perform pre_arm_rc_checks checks
bool AP_Arming_Rover::pre_arm_rc_checks(const bool display_failure)
{
// set rc-checks to success if RC checks are disabled
if ((checks_to_perform != ARMING_CHECK_ALL) && !(checks_to_perform & ARMING_CHECK_RC)) {
return true;
}
const RC_Channel *channels[] = {
rover.channel_steer,
rover.channel_throttle,
};
const char *channel_names[] = {"Steer", "Throttle"};
for (uint8_t i= 0 ; i < ARRAY_SIZE(channels); i++) {
const RC_Channel *channel = channels[i];
const char *channel_name = channel_names[i];
// check if radio has been calibrated
if (!channel->min_max_configured()) {
if (display_failure) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: RC %s not configured", channel_name);
}
return false;
}
if (channel->get_radio_min() > 1300) {
if (display_failure) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: %s radio min too high", channel_name);
}
return false;
}
if (channel->get_radio_max() < 1700) {
if (display_failure) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: %s radio max too low", channel_name);
}
return false;
}
if (channel->get_radio_trim() < channel->get_radio_min()) {
if (display_failure) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: %s radio trim below min", channel_name);
}
return false;
}
if (channel->get_radio_trim() > channel->get_radio_max()) {
if (display_failure) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: %s radio trim above max", channel_name);
}
return false;
}
}
return true;
}
// performs pre_arm gps related checks and returns true if passed
bool AP_Arming_Rover::gps_checks(bool display_failure)
{
if (!rover.control_mode->requires_position() && !rover.control_mode->requires_velocity()) {
// we don't care!
return true;
}
// call parent gps checks
return AP_Arming::gps_checks(display_failure);
}
bool AP_Arming_Rover::pre_arm_checks(bool report)
{
return (AP_Arming::pre_arm_checks(report)
& rover.g2.motors.pre_arm_check(report)
& fence_checks(report)
& proximity_check(report));
}
bool AP_Arming_Rover::fence_checks(bool report)
{
// check fence is initialised
const char *fail_msg = nullptr;
if (!_fence.pre_arm_check(fail_msg)) {
if (report && fail_msg != nullptr) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: Fence : %s", fail_msg);
}
return false;
}
return true;
}
// check nothing is too close to vehicle
bool AP_Arming_Rover::proximity_check(bool report)
{
// return true immediately if no sensor present
if (rover.g2.proximity.get_status() == AP_Proximity::Proximity_NotConnected) {
return true;
}
// return false if proximity sensor unhealthy
if (rover.g2.proximity.get_status() < AP_Proximity::Proximity_Good) {
if (report) {
gcs().send_text(MAV_SEVERITY_CRITICAL,"PreArm: check proximity sensor");
}
return false;
}
// get closest object if we might use it for avoidance
float angle_deg, distance;
if (rover.g2.avoid.proximity_avoidance_enabled() && rover.g2.proximity.get_closest_object(angle_deg, distance)) {
// display error if something is within 60cm
if (distance <= 0.6f) {
if (report) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "PreArm: Proximity %d deg, %4.2fm", static_cast<int32_t>(angle_deg), static_cast<double>(distance));
}
return false;
}
}
return true;
}