mirror of
https://github.com/okalachev/flix.git
synced 2025-07-29 04:19:00 +00:00
Add failsafe to prevent arming without prior zero throttle
This commit is contained in:
parent
7d2d54a94d
commit
15fbe34d19
@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2024 Oleg Kalachev <okalachev@gmail.com>
|
// Copyright (c) 2024 Oleg Kalachev <okalachev@gmail.com>
|
||||||
// Repository: https://github.com/okalachev/flix
|
// Repository: https://github.com/okalachev/flix
|
||||||
|
|
||||||
// Fail-safe for RC loss
|
// Fail-safe functions
|
||||||
|
|
||||||
#define RC_LOSS_TIMEOUT 0.2
|
#define RC_LOSS_TIMEOUT 0.2
|
||||||
#define DESCEND_TIME 3.0 // time to descend from full throttle to zero
|
#define DESCEND_TIME 3.0 // time to descend from full throttle to zero
|
||||||
@ -10,13 +10,28 @@ extern double controlsTime;
|
|||||||
extern int rollChannel, pitchChannel, throttleChannel, yawChannel;
|
extern int rollChannel, pitchChannel, throttleChannel, yawChannel;
|
||||||
|
|
||||||
void failsafe() {
|
void failsafe() {
|
||||||
|
armingFailsafe();
|
||||||
|
rcLossFailsafe();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent arming without zero throttle input
|
||||||
|
void armingFailsafe() {
|
||||||
|
static double zeroThrottleTime;
|
||||||
|
static double armingTime;
|
||||||
|
if (!armed) armingTime = t; // stores the last time when the drone was disarmed, therefore contains arming time
|
||||||
|
if (controlsTime > 0 && controls[throttleChannel] < 0.05) zeroThrottleTime = controlsTime;
|
||||||
|
if (armingTime - zeroThrottleTime > 0.1) armed = false; // prevent arming if there was no zero throttle for 0.1 sec
|
||||||
|
}
|
||||||
|
|
||||||
|
// RC loss failsafe
|
||||||
|
void rcLossFailsafe() {
|
||||||
if (t - controlsTime > RC_LOSS_TIMEOUT) {
|
if (t - controlsTime > RC_LOSS_TIMEOUT) {
|
||||||
descend();
|
descend();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Smooth descend on RC lost
|
||||||
void descend() {
|
void descend() {
|
||||||
// Smooth descend on RC lost
|
|
||||||
mode = STAB;
|
mode = STAB;
|
||||||
controls[rollChannel] = 0;
|
controls[rollChannel] = 0;
|
||||||
controls[pitchChannel] = 0;
|
controls[pitchChannel] = 0;
|
||||||
|
@ -44,6 +44,8 @@ void sendMessage(const void *msg);
|
|||||||
void receiveMavlink();
|
void receiveMavlink();
|
||||||
void handleMavlink(const void *_msg);
|
void handleMavlink(const void *_msg);
|
||||||
void failsafe();
|
void failsafe();
|
||||||
|
void armingFailsafe();
|
||||||
|
void rcLossFailsafe();
|
||||||
void descend();
|
void descend();
|
||||||
inline Quaternion FLU2FRD(const Quaternion &q);
|
inline Quaternion FLU2FRD(const Quaternion &q);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user