From 34b48badb918efc63daf4ef6bb0fb3e1ffb3d817 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Sun, 19 Nov 2017 04:24:40 +0000 Subject: [PATCH] Scaled PID deltaT calculations from us to seconds --- src/main/flight/pid.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/flight/pid.c b/src/main/flight/pid.c index 1aeae117da..b2279e36d9 100644 --- a/src/main/flight/pid.c +++ b/src/main/flight/pid.c @@ -410,11 +410,11 @@ void pidController(const pidProfile_t *pidProfile, const rollAndPitchTrims_t *an const float tpaFactor = getThrottlePIDAttenuation(); const float motorMixRange = getMotorMixRange(); static timeUs_t crashDetectedAtUs; - static timeUs_t previousTime; + static timeUs_t previousTimeUs; - // calculate actual deltaT - const float deltaT = currentTimeUs - previousTime; - previousTime = currentTimeUs; + // calculate actual deltaT in seconds + const float deltaT = (currentTimeUs - previousTimeUs) * 0.000001f; + previousTimeUs = currentTimeUs; // Dynamic ki component to gradually scale back integration when above windup point const float dynKi = MIN((1.0f - motorMixRange) * ITermWindupPointInv, 1.0f);