Skip to content

Commit 4937fa3

Browse files
authored
Merge pull request #6737 from harry1453/require-prearm-reset
Add "prearm was reset" flag to prevent rearming without resetting prearm & add prearm timeout
2 parents 5aabf80 + 99a8084 commit 4937fa3

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

docs/Settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@
441441
| pitot_scale | | |
442442
| platform_type | "MULTIROTOR" | Defines UAV platform type. Allowed values: "MULTIROTOR", "AIRPLANE", "HELICOPTER", "TRICOPTER", "ROVER", "BOAT". Currently only MULTIROTOR, AIRPLANE and TRICOPTER types are implemented |
443443
| pos_hold_deadband | 20 | Stick deadband in [r/c points], applied after r/c deadband and expo |
444+
| prearm_timeout | 10000 | Duration (ms) for which Prearm being activated is valid. after this, Prearm needs to be reset. 0 means Prearm does not timeout. |
444445
| rangefinder_hardware | NONE | Selection of rangefinder hardware. |
445446
| rangefinder_median_filter | OFF | 3-point median filtering for rangefinder readouts |
446447
| rate_accel_limit_roll_pitch | 0 | Limits acceleration of ROLL/PITCH rotation speed that can be requested by stick input. In degrees-per-second-squared. Small and powerful UAV flies great with high acceleration limit ( > 5000 dps^2 and even > 10000 dps^2). Big and heavy multirotors will benefit from low acceleration limit (~ 360 dps^2). When set correctly, it greatly improves stopping performance. Value of 0 disables limiting. |

src/main/fc/fc_core.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ static uint32_t gyroSyncFailureCount;
133133
static disarmReason_t lastDisarmReason = DISARM_NONE;
134134
static emergencyArmingState_t emergencyArming;
135135

136+
static bool prearmWasReset = false; // Prearm must be reset (RC Mode not active) before arming is possible
137+
static timeMs_t prearmActivationTime = 0;
138+
136139
bool isCalibrating(void)
137140
{
138141
#ifdef USE_BARO
@@ -299,8 +302,14 @@ static void updateArmingStatus(void)
299302

300303
if (isModeActivationConditionPresent(BOXPREARM)) {
301304
if (IS_RC_MODE_ACTIVE(BOXPREARM)) {
302-
DISABLE_ARMING_FLAG(ARMING_DISABLED_NO_PREARM);
305+
if (prearmWasReset && (armingConfig()->prearmTimeoutMs == 0 || millis() - prearmActivationTime < armingConfig()->prearmTimeoutMs)) {
306+
DISABLE_ARMING_FLAG(ARMING_DISABLED_NO_PREARM);
307+
} else {
308+
ENABLE_ARMING_FLAG(ARMING_DISABLED_NO_PREARM);
309+
}
303310
} else {
311+
prearmWasReset = true;
312+
prearmActivationTime = millis();
304313
ENABLE_ARMING_FLAG(ARMING_DISABLED_NO_PREARM);
305314
}
306315
} else {
@@ -412,6 +421,8 @@ void disarm(disarmReason_t disarmReason)
412421
programmingPidReset();
413422
#endif
414423
beeper(BEEPER_DISARMING); // emit disarm tone
424+
425+
prearmWasReset = false;
415426
}
416427
}
417428

src/main/fc/rc_controls.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@
6464
#define AIRMODE_DEADBAND 25
6565
#define MIN_RC_TICK_INTERVAL_MS 20
6666
#define DEFAULT_RC_SWITCH_DISARM_DELAY_MS 250 // Wait at least 250ms before disarming via switch
67+
#define DEFAULT_PREARM_TIMEOUT 10000 // Prearm is invalidated after 10 seconds
6768

6869
stickPositions_e rcStickPositions;
6970

7071
FASTRAM int16_t rcCommand[4]; // interval [1000;2000] for THROTTLE and [-500;+500] for ROLL/PITCH/YAW
7172

72-
PG_REGISTER_WITH_RESET_TEMPLATE(rcControlsConfig_t, rcControlsConfig, PG_RC_CONTROLS_CONFIG, 1);
73+
PG_REGISTER_WITH_RESET_TEMPLATE(rcControlsConfig_t, rcControlsConfig, PG_RC_CONTROLS_CONFIG, 2);
7374

7475
PG_RESET_TEMPLATE(rcControlsConfig_t, rcControlsConfig,
7576
.deadband = 5,
@@ -87,6 +88,7 @@ PG_RESET_TEMPLATE(armingConfig_t, armingConfig,
8788
.fixed_wing_auto_arm = 0,
8889
.disarm_kill_switch = 1,
8990
.switchDisarmDelayMs = DEFAULT_RC_SWITCH_DISARM_DELAY_MS,
91+
.prearmTimeoutMs = DEFAULT_PREARM_TIMEOUT,
9092
);
9193

9294
bool areSticksInApModePosition(uint16_t ap_mode)

src/main/fc/rc_controls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ typedef struct armingConfig_s {
9797
uint8_t fixed_wing_auto_arm; // Auto-arm fixed wing aircraft on throttle up and never disarm
9898
uint8_t disarm_kill_switch; // allow disarm via AUX switch regardless of throttle value
9999
uint16_t switchDisarmDelayMs; // additional delay between ARM box going off and actual disarm
100+
uint16_t prearmTimeoutMs; // duration for which Prearm being activated is valid. after this, Prearm needs to be reset. 0 means Prearm does not timeout.
100101
} armingConfig_t;
101102

102103
PG_DECLARE(armingConfig_t, armingConfig);

src/main/fc/settings.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,12 @@ groups:
13311331
field: switchDisarmDelayMs
13321332
min: 0
13331333
max: 1000
1334+
- name: prearm_timeout
1335+
description: "Duration (ms) for which Prearm being activated is valid. after this, Prearm needs to be reset. 0 means Prearm does not timeout."
1336+
default_value: "10000"
1337+
field: prearmTimeoutMs
1338+
min: 0
1339+
max: 10000
13341340

13351341
- name: PG_GENERAL_SETTINGS
13361342
headers: ["config/general_settings.h"]

0 commit comments

Comments
 (0)