Make failsafe configurable using parameters

SF_RC_LOSS_TIME - time without rc to activate failsafe.
SD_DESCEND_TIME - total time to decrease the throttle to zero.
Make controlTime nan on the start to simplify the logic.
This commit is contained in:
Oleg Kalachev
2026-01-22 23:57:52 +03:00
parent 0abb18c616
commit 6d01cd2e79
3 changed files with 10 additions and 7 deletions

View File

@@ -10,6 +10,7 @@ extern float channelZero[16];
extern float channelMax[16]; extern float channelMax[16];
extern float rollChannel, pitchChannel, throttleChannel, yawChannel, armedChannel, modeChannel; extern float rollChannel, pitchChannel, throttleChannel, yawChannel, armedChannel, modeChannel;
extern int wifiMode, udpLocalPort, udpRemotePort; extern int wifiMode, udpLocalPort, udpRemotePort;
extern float rcLossTimeout, descendTime;
Preferences storage; Preferences storage;
@@ -91,6 +92,9 @@ Parameter parameters[] = {
{"MAV_SYS_ID", &mavlinkSysId}, {"MAV_SYS_ID", &mavlinkSysId},
{"MAV_RATE_SLOW", &telemetrySlow.rate}, {"MAV_RATE_SLOW", &telemetrySlow.rate},
{"MAV_RATE_FAST", &telemetryFast.rate}, {"MAV_RATE_FAST", &telemetryFast.rate},
// safety
{"SF_RC_LOSS_TIME", &rcLossTimeout},
{"SF_DESCEND_TIME", &descendTime},
}; };
void setupParameters() { void setupParameters() {

View File

@@ -14,7 +14,7 @@ float channelMax[16]; // calibration max values
float controlRoll, controlPitch, controlYaw, controlThrottle; // pilot's inputs, range [-1, 1] float controlRoll, controlPitch, controlYaw, controlThrottle; // pilot's inputs, range [-1, 1]
float controlMode = NAN; float controlMode = NAN;
float controlTime; // time of the last controls update (0 when no RC) float controlTime = NAN; // time of the last controls update
// Channels mapping (nan means not assigned): // Channels mapping (nan means not assigned):
float rollChannel = NAN, pitchChannel = NAN, throttleChannel = NAN, yawChannel = NAN, modeChannel = NAN; float rollChannel = NAN, pitchChannel = NAN, throttleChannel = NAN, yawChannel = NAN, modeChannel = NAN;

View File

@@ -3,12 +3,12 @@
// Fail-safe functions // Fail-safe functions
#define RC_LOSS_TIMEOUT 1
#define DESCEND_TIME 10
extern float controlTime; extern float controlTime;
extern float controlRoll, controlPitch, controlThrottle, controlYaw; extern float controlRoll, controlPitch, controlThrottle, controlYaw;
float rcLossTimeout = 1;
float descendTime = 10;
void failsafe() { void failsafe() {
rcLossFailsafe(); rcLossFailsafe();
autoFailsafe(); autoFailsafe();
@@ -16,9 +16,8 @@ void failsafe() {
// RC loss failsafe // RC loss failsafe
void rcLossFailsafe() { void rcLossFailsafe() {
if (controlTime == 0) return; // no RC at all
if (!armed) return; if (!armed) return;
if (t - controlTime > RC_LOSS_TIMEOUT) { if (t - controlTime > rcLossTimeout) {
descend(); descend();
} }
} }
@@ -27,7 +26,7 @@ void rcLossFailsafe() {
void descend() { void descend() {
mode = AUTO; mode = AUTO;
attitudeTarget = Quaternion(); attitudeTarget = Quaternion();
thrustTarget -= dt / DESCEND_TIME; thrustTarget -= dt / descendTime;
if (thrustTarget < 0) { if (thrustTarget < 0) {
thrustTarget = 0; thrustTarget = 0;
armed = false; armed = false;