diff --git a/flix/parameters.ino b/flix/parameters.ino index 469a1ba..e58abed 100644 --- a/flix/parameters.ino +++ b/flix/parameters.ino @@ -10,6 +10,7 @@ extern float channelZero[16]; extern float channelMax[16]; extern float rollChannel, pitchChannel, throttleChannel, yawChannel, armedChannel, modeChannel; extern int wifiMode, udpLocalPort, udpRemotePort; +extern float rcLossTimeout, descendTime; Preferences storage; @@ -91,6 +92,9 @@ Parameter parameters[] = { {"MAV_SYS_ID", &mavlinkSysId}, {"MAV_RATE_SLOW", &telemetrySlow.rate}, {"MAV_RATE_FAST", &telemetryFast.rate}, + // safety + {"SF_RC_LOSS_TIME", &rcLossTimeout}, + {"SF_DESCEND_TIME", &descendTime}, }; void setupParameters() { diff --git a/flix/rc.ino b/flix/rc.ino index 0095d55..f046e5b 100644 --- a/flix/rc.ino +++ b/flix/rc.ino @@ -14,7 +14,7 @@ float channelMax[16]; // calibration max values float controlRoll, controlPitch, controlYaw, controlThrottle; // pilot's inputs, range [-1, 1] 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): float rollChannel = NAN, pitchChannel = NAN, throttleChannel = NAN, yawChannel = NAN, modeChannel = NAN; diff --git a/flix/safety.ino b/flix/safety.ino index 35ece02..1d67010 100644 --- a/flix/safety.ino +++ b/flix/safety.ino @@ -3,12 +3,12 @@ // Fail-safe functions -#define RC_LOSS_TIMEOUT 1 -#define DESCEND_TIME 10 - extern float controlTime; extern float controlRoll, controlPitch, controlThrottle, controlYaw; +float rcLossTimeout = 1; +float descendTime = 10; + void failsafe() { rcLossFailsafe(); autoFailsafe(); @@ -16,9 +16,8 @@ void failsafe() { // RC loss failsafe void rcLossFailsafe() { - if (controlTime == 0) return; // no RC at all if (!armed) return; - if (t - controlTime > RC_LOSS_TIMEOUT) { + if (t - controlTime > rcLossTimeout) { descend(); } } @@ -27,7 +26,7 @@ void rcLossFailsafe() { void descend() { mode = AUTO; attitudeTarget = Quaternion(); - thrustTarget -= dt / DESCEND_TIME; + thrustTarget -= dt / descendTime; if (thrustTarget < 0) { thrustTarget = 0; armed = false;