Skip to content

Commit 11bc4aa

Browse files
committed
Plane: move rudder-arming arm checks into Plane's AP_Arming
1 parent 1c57eed commit 11bc4aa

File tree

2 files changed

+57
-40
lines changed

2 files changed

+57
-40
lines changed

ArduPlane/AP_Arming.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,30 @@ bool AP_Arming_Plane::ins_checks(bool display_failure)
136136

137137
bool AP_Arming_Plane::arm_checks(AP_Arming::Method method)
138138
{
139+
if (method == AP_Arming::Method::RUDDER) {
140+
const AP_Arming::RudderArming arming_rudder = get_rudder_arming_type();
141+
142+
if (arming_rudder == AP_Arming::RudderArming::IS_DISABLED) {
143+
//parameter disallows rudder arming/disabling
144+
check_failed(true, "Rudder arming disabled");
145+
return false;
146+
}
147+
148+
// if throttle is not down, then pilot cannot rudder arm/disarm
149+
if (plane.get_throttle_input() != 0){
150+
check_failed(true, "Non-zero throttle");
151+
return;
152+
}
153+
154+
// if not in a manual throttle mode and not in CRUISE or FBWB
155+
// modes then disallow rudder arming/disarming
156+
if (plane.auto_throttle_mode &&
157+
(plane.control_mode != &mode_cruise && plane.control_mode != &mode_fbwb)) {
158+
check_failed(true, "Mode not rudder-armable");
159+
return;
160+
}
161+
}
162+
139163
//are arming checks disabled?
140164
if (checks_to_perform == 0) {
141165
return true;
@@ -205,6 +229,17 @@ bool AP_Arming_Plane::arm(const AP_Arming::Method method, const bool do_arming_c
205229
*/
206230
bool AP_Arming_Plane::disarm(const AP_Arming::Method method)
207231
{
232+
if (method == AP_Arming::Method::RUDDER) {
233+
// don't allow rudder-disarming in flight:
234+
if (is_flying()) {
235+
return false;
236+
}
237+
// option must be enabled:
238+
if (get_rudder_arming_type() != AP_Arming::RudderArming::ARMDISARM) {
239+
return false;
240+
}
241+
}
242+
208243
if (!AP_Arming::disarm(method)) {
209244
return false;
210245
}

ArduPlane/radio.cpp

+22-40
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,6 @@ void Plane::init_rc_out_aux()
119119
*/
120120
void Plane::rudder_arm_disarm_check()
121121
{
122-
AP_Arming::RudderArming arming_rudder = arming.get_rudder_arming_type();
123-
124-
if (arming_rudder == AP_Arming::RudderArming::IS_DISABLED) {
125-
//parameter disallows rudder arming/disabling
126-
return;
127-
}
128-
129-
// if throttle is not down, then pilot cannot rudder arm/disarm
130-
if (get_throttle_input() != 0){
131-
rudder_arm_timer = 0;
132-
return;
133-
}
134-
135-
// if not in a manual throttle mode and not in CRUISE or FBWB
136-
// modes then disallow rudder arming/disarming
137-
if (auto_throttle_mode &&
138-
(control_mode != &mode_cruise && control_mode != &mode_fbwb)) {
139-
rudder_arm_timer = 0;
140-
return;
141-
}
142-
143122
if (!arming.is_armed()) {
144123
// when not armed, full right rudder starts arming counter
145124
if (channel_rudder->get_control_in() > 4000) {
@@ -160,26 +139,29 @@ void Plane::rudder_arm_disarm_check()
160139
// not at full right rudder
161140
rudder_arm_timer = 0;
162141
}
163-
} else if ((arming_rudder == AP_Arming::RudderArming::ARMDISARM) && !is_flying()) {
164-
// when armed and not flying, full left rudder starts disarming counter
165-
if (channel_rudder->get_control_in() < -4000) {
166-
uint32_t now = millis();
167-
168-
if (rudder_arm_timer == 0 ||
169-
now - rudder_arm_timer < 3000) {
170-
if (rudder_arm_timer == 0) {
171-
rudder_arm_timer = now;
172-
}
173-
} else {
174-
//time to disarm!
175-
arming.disarm(AP_Arming::Method::RUDDER);
176-
rudder_arm_timer = 0;
177-
}
178-
} else {
179-
// not at full left rudder
180-
rudder_arm_timer = 0;
181-
}
142+
return;
182143
}
144+
145+
// full left rudder starts disarming counter
146+
if (channel_rudder->get_control_in() >= -4000) {
147+
// not at full left rudder
148+
rudder_arm_timer = 0;
149+
return;
150+
}
151+
const uint32_t now = millis();
152+
153+
if (rudder_arm_timer == 0) {
154+
// start counter:
155+
rudder_arm_timer = now;
156+
}
157+
if (now - rudder_arm_timer < 3000) {
158+
// not yet time to disarm
159+
return;
160+
}
161+
162+
//time to disarm!
163+
arming.disarm(AP_Arming::Method::RUDDER);
164+
rudder_arm_timer = 0;
183165
}
184166

185167
void Plane::read_radio()

0 commit comments

Comments
 (0)