Skip to content

Commit 95d70b4

Browse files
committed
add out.armed, remove out.arm
1 parent ae2b56b commit 95d70b4

File tree

6 files changed

+63
-44
lines changed

6 files changed

+63
-44
lines changed

examples/01.Quadcopter/01.Quadcopter.ino

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ Connecting Hardware
1919
RC receiver: connect pin_ser0_rx to receiver TX pin
2020
ESCs: pin_out0 ... pin_out3 to the ESC inputs of motor1 ... motor4
2121
22-
Arming: Set throttle low, then flip arm switch from DISARMED to ARMED.
23-
Disarming: Flip arm switch from ARMED to DISARMED, at any throttle position. "Kill switch".
22+
Arming/disarming with dedicated switch
23+
24+
Arm: Set throttle low, then flip arm switch from DISARMED to ARMED.
25+
Disarm: Flip arm switch from ARMED to DISARMED, at any throttle position. "Kill switch".
26+
27+
Arming/disarming with sticks (when no arm switch is defined, i.e. cfg.rcl_arm_ch == 0 )
28+
29+
Arm: Pull both sticks toward you, yaw full right, and roll full left
30+
Disarm: Pull both sticks toward you, yaw full left, and roll full right
2431
2532
LED State Meaning
2633
--------- -------
@@ -282,25 +289,21 @@ void control_Rate(bool zero_integrators) {
282289
}
283290

284291
void out_KillSwitchAndFailsafe() {
285-
static bool rcin_arm_prev = true; //initial value is true: forces out.armed false on startup even if arm switch is ON
286-
287-
//Change to ARMED when throttle is zero and radio armed switch was flipped from disamed to armed position
288-
if (!out.armed && rcl.throttle == 0 && rcl.arm && !rcin_arm_prev) {
292+
//Change to ARMED when rcl is armed (by switch or stick command)
293+
if (!out.armed && rcl.armed) {
289294
out.armed = true;
290295
Serial.println("OUT: ARMED");
291296
}
292297

293-
//Change to DISARMED when radio armed switch is in disarmed position, or if radio lost connection
294-
if (out.armed && (!rcl.arm || !rcl.connected())) {
298+
//Change to DISARMED when rcl is disarmed, or if radio lost connection
299+
if (out.armed && (!rcl.armed || !rcl.connected())) {
295300
out.armed = false;
296-
if(!rcl.arm) {
301+
if(!rcl.armed) {
297302
Serial.println("OUT: DISARMED");
298303
}else{
299304
Serial.println("OUT: DISARMED due to lost radio connection");
300305
}
301306
}
302-
303-
rcin_arm_prev = rcl.arm;
304307
}
305308

306309
void out_Mixer() {

examples/02.QuadcopterAdvanced/02.QuadcopterAdvanced.ino

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ Connecting Hardware
2121
RC receiver: connect pin_ser0_rx to receiver TX pin, and pin_ser0_tx to receiver RX pin
2222
ESCs: pin_out0 ... pin_out3 to the ESC inputs of motor1 ... motor4
2323
24-
Arming: Set throttle low, then flip arm switch from DISARMED to ARMED.
25-
Disarming: Flip arm switch from ARMED to DISARMED, at any throttle position. "Kill switch".
24+
Arming/disarming with dedicated switch
25+
26+
Arm: Set throttle low, then flip arm switch from DISARMED to ARMED.
27+
Disarm: Flip arm switch from ARMED to DISARMED, at any throttle position. "Kill switch".
28+
29+
Arming/disarming with sticks (when no arm switch is defined, i.e. cfg.rcl_arm_ch == 0 )
30+
31+
Arm: Pull both sticks toward you, yaw full right, and roll full left
32+
Disarm: Pull both sticks toward you, yaw full left, and roll full right
2633
2734
LED State Meaning
2835
--------- -------
@@ -318,28 +325,24 @@ void control_Rate(bool zero_integrators) {
318325
}
319326

320327
void out_KillSwitchAndFailsafe() {
321-
static bool rcin_arm_prev = true; //initial value is true: forces out.armed false on startup even if arm switch is ON
322-
323-
//Change to ARMED when throttle is zero and radio armed switch was flipped from disamed to armed position
324-
if (!out.armed && rcl.throttle == 0 && rcl.arm && !rcin_arm_prev) {
328+
//Change to ARMED when rcl is armed (by switch or stick command)
329+
if (!out.armed && rcl.armed) {
325330
out.armed = true;
326331
Serial.println("OUT: ARMED");
327332
bbx.start(); //start blackbox logging
328333
}
329334

330-
//Change to DISARMED when radio armed switch is in disarmed position, or if radio lost connection
331-
if (out.armed && (!rcl.arm || !rcl.connected())) {
335+
//Change to DISARMED when rcl is disarmed, or if radio lost connection
336+
if (out.armed && (!rcl.armed || !rcl.connected())) {
332337
out.armed = false;
333-
if(!rcl.arm) {
338+
if(!rcl.armed) {
334339
Serial.println("OUT: DISARMED");
335340
bbx.stop(); //stop blackbox logging
336341
}else{
337342
Serial.println("OUT: DISARMED due to lost radio connection");
338343
//keep on logging to document the crash...
339344
}
340345
}
341-
342-
rcin_arm_prev = rcl.arm;
343346
}
344347

345348
void out_Mixer() {

examples/03.Plane/03.Plane.ino

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,15 @@ control surfaces react quickly, but don't oscillate, on changes in attitude.
5050
5151
See http://madflight.com for detailed description
5252
53-
Arming: Set throttle low, then flip arm switch from DISARMED to ARMED.
54-
Disarming: Flip arm switch from ARMED to DISARMED, at any throttle position. "Kill switch".
53+
Arming/disarming with dedicated switch
54+
55+
Arm: Set throttle low, then flip arm switch from DISARMED to ARMED.
56+
Disarm: Flip arm switch from ARMED to DISARMED, at any throttle position. "Kill switch".
57+
58+
Arming/disarming with sticks (when no arm switch is defined, i.e. cfg.rcl_arm_ch == 0 )
59+
60+
Arm: Pull both sticks toward you, yaw full right, and roll full left
61+
Disarm: Pull both sticks toward you, yaw full left, and roll full right
5562
5663
LED State Meaning
5764
--------- -------
@@ -308,28 +315,24 @@ Regular RC control, no stabilization. All RC inputs are passed through to the se
308315
}
309316

310317
void out_KillSwitchAndFailsafe() {
311-
static bool rcin_arm_prev = true; //initial value is true: forces out.armed false on startup even if arm switch is ON
312-
313-
//Change to ARMED when throttle is zero and radio armed switch was flipped from disamed to armed position
314-
if (!out.armed && rcl.throttle == 0 && rcl.arm && !rcin_arm_prev) {
318+
//Change to ARMED when rcl is armed (by switch or stick command)
319+
if (!out.armed && rcl.armed) {
315320
out.armed = true;
316321
Serial.println("OUT: ARMED");
317322
bbx.start(); //start blackbox logging
318323
}
319324

320-
//Change to DISARMED when radio armed switch is in disarmed position, or if radio lost connection
321-
if (out.armed && (!rcl.arm || !rcl.connected())) {
325+
//Change to DISARMED when rcl is disarmed, or if radio lost connection
326+
if (out.armed && (!rcl.armed || !rcl.connected())) {
322327
out.armed = false;
323-
if(!rcl.arm) {
328+
if(!rcl.armed) {
324329
Serial.println("OUT: DISARMED");
325330
bbx.stop(); //stop blackbox logging
326331
}else{
327332
Serial.println("OUT: DISARMED due to lost radio connection");
328333
//keep on logging to document the crash...
329334
}
330335
}
331-
332-
rcin_arm_prev = rcl.arm;
333336
}
334337

335338
void out_Mixer() {

src/madflight/cli/cli_cpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void cli_print_rcl_RadioScaled() {
8888
Serial.printf("roll:%+.2f\t", rcl.roll);
8989
Serial.printf("pitch:%+.2f\t", rcl.pitch);
9090
Serial.printf("yaw:%+.2f\t", rcl.yaw);
91-
Serial.printf("arm:%d\t", rcl.arm);
91+
Serial.printf("armed:%d\t", rcl.armed);
9292
Serial.printf("flightmode:%d\t", rcl.flightmode);
9393
}
9494

src/madflight/rcl/rcl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Rcl {
6767
float pitch = 0; //pitch stick value -1.0 (pitch up/stick back) to 1.0 (pitch down/stick forward)
6868
float yaw = 0; //yaw stick value -1.0 (left) to 1.0 (right)
6969
float vspeed = 0; //vertical speed stick value -1.0 (descent/stick back) to 1.0 (ascent/stick forward)
70-
bool arm = false; //arm switch state
70+
bool armed = false; //armed state (triggered by arm switch or stick commands)
7171
uint8_t flightmode = 0; //flightmode 0 to 5
7272

7373
private:
@@ -88,6 +88,7 @@ class Rcl {
8888
} st[6];
8989

9090
uint16_t st_flt_spacing;
91+
bool _arm_sw_prev = true; //default to true, to require arm switch first off, then on to enter armed state!
9192
};
9293

9394
extern Rcl rcl;

src/madflight/rcl/rcl_cpp.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ int Rcl::setup() {
6464
pitch = 0;
6565
yaw = 0;
6666
vspeed = 0;
67-
arm = false;
67+
armed = false;
68+
_arm_sw_prev = true; //default to true, to require arm switch first off, then on to enter armed state!
6869

6970
//create gizmo
7071
delete gizmo;
@@ -167,18 +168,26 @@ bool Rcl::update() { //returns true if channel pwm data was updated
167168
pitch = -st[PIT].inv * _ChannelNormalize(pwm[st[PIT].ch], st[PIT].min, st[PIT].mid, st[PIT].max, cfg.rcl_deadband); // output: -1 (pitch down, st back) to 1 (pitch up, st forward)
168169
yaw = st[YAW].inv * _ChannelNormalize(pwm[st[YAW].ch], st[YAW].min, st[YAW].mid, st[YAW].max, cfg.rcl_deadband); // output: -1 (yaw left, st left) to 1 (yaw right, st right)
169170

170-
//arm switch
171+
//armed state
171172
if(st[ARM].ch < RCL_MAX_CH) {
172-
//get arm switch state
173-
arm = (st[ARM].min <= pwm[st[ARM].ch] && pwm[st[ARM].ch] < st[ARM].max);
173+
//use arm switch
174+
bool arm_sw = (st[ARM].min <= pwm[st[ARM].ch] && pwm[st[ARM].ch] < st[ARM].max); //get arm switch state
175+
if(throttle == 0 && arm_sw && !_arm_sw_prev) {
176+
//Arm: Throttle is zero and radio armed switch was flipped from disarmed to armed position
177+
armed = true;
178+
}else if (!arm_sw) {
179+
//Disarm: As soon as arm switch is in disarmed position. "Kill switch"
180+
armed = false;
181+
}
182+
_arm_sw_prev = arm_sw;
174183
}else{
175-
//no arm switch - use stick commands
184+
//use stick commands (no arm switch defined)
176185
if(throttle == 0.0 && pitch > 0.9 && yaw > 0.9 && roll < -0.9) {
177-
//sticks pulled & toward eachother
178-
arm = true;
186+
//Arm: Pull both sticks toward you, yaw full right, and roll full left
187+
armed = true;
179188
}else if(throttle == 0.0 && pitch > 0.9 && yaw < -0.9 && roll > 0.9) {
180-
//sticks pulled & away from eachother
181-
arm = false;
189+
//Disarm: Pull both sticks toward you, yaw full left, and roll full right
190+
armed = false;
182191
}
183192
}
184193

0 commit comments

Comments
 (0)