Skip to content

Commit

Permalink
Add failsafe to prevent arming without prior zero throttle
Browse files Browse the repository at this point in the history
  • Loading branch information
okalachev committed Jan 24, 2025
1 parent 7d2d54a commit 15fbe34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions flix/failsafe.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2024 Oleg Kalachev <okalachev@gmail.com>
// Repository: https://github.com/okalachev/flix

// Fail-safe for RC loss
// Fail-safe functions

#define RC_LOSS_TIMEOUT 0.2
#define DESCEND_TIME 3.0 // time to descend from full throttle to zero
Expand All @@ -10,13 +10,28 @@ extern double controlsTime;
extern int rollChannel, pitchChannel, throttleChannel, yawChannel;

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) {
descend();
}
}

// Smooth descend on RC lost
void descend() {
// Smooth descend on RC lost
mode = STAB;
controls[rollChannel] = 0;
controls[pitchChannel] = 0;
Expand Down
2 changes: 2 additions & 0 deletions gazebo/flix.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ void sendMessage(const void *msg);
void receiveMavlink();
void handleMavlink(const void *_msg);
void failsafe();
void armingFailsafe();
void rcLossFailsafe();
void descend();
inline Quaternion FLU2FRD(const Quaternion &q);

Expand Down

0 comments on commit 15fbe34

Please sign in to comment.