Improve rc failsafe logic

Don't trigger failsafe if there's no RC at all
Use AUTO mode for descending, instead of STAB
Increase RC loss timeout and descend time
This commit is contained in:
Oleg Kalachev
2025-10-12 21:20:46 +03:00
parent 06ec5f3160
commit 7bee3d1751

View File

@@ -3,8 +3,8 @@
// Fail-safe functions // Fail-safe functions
#define RC_LOSS_TIMEOUT 0.5 #define RC_LOSS_TIMEOUT 1
#define DESCEND_TIME 3.0 // time to descend from full throttle to zero #define DESCEND_TIME 10
extern double controlTime; extern double controlTime;
extern float controlRoll, controlPitch, controlThrottle, controlYaw; extern float controlRoll, controlPitch, controlThrottle, controlYaw;
@@ -16,7 +16,7 @@ void failsafe() {
// RC loss failsafe // RC loss failsafe
void rcLossFailsafe() { void rcLossFailsafe() {
if (mode == AUTO) return; if (controlTime == 0) return; // no RC at all
if (!armed) return; if (!armed) return;
if (t - controlTime > RC_LOSS_TIMEOUT) { if (t - controlTime > RC_LOSS_TIMEOUT) {
descend(); descend();
@@ -25,14 +25,12 @@ void rcLossFailsafe() {
// Smooth descend on RC lost // Smooth descend on RC lost
void descend() { void descend() {
mode = STAB; mode = AUTO;
controlRoll = 0; attitudeTarget = Quaternion();
controlPitch = 0; thrustTarget -= dt / DESCEND_TIME;
controlYaw = 0; if (thrustTarget < 0) {
controlThrottle -= dt / DESCEND_TIME; thrustTarget = 0;
if (controlThrottle < 0) {
armed = false; armed = false;
controlThrottle = 0;
} }
} }