From 38cbe28e0f229d39fd2c9892a3ecbfded3c2a8bc Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Fri, 1 Aug 2014 21:10:26 +0100 Subject: [PATCH] Apply accz pt1 element fixes. See: f7132b9d33211a55b8bd2c92f14da59f35b715a4 b1f58bc01fcf1632b3c3947a5ed0e807c2763a30 5832e2f67fcd2ee93044b300fda37a420c595813 a5961aeda657225fa843a115a94229313db4b2db --- src/main/flight/imu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/flight/imu.c b/src/main/flight/imu.c index 3c8671fc18..20ea3250f5 100755 --- a/src/main/flight/imu.c +++ b/src/main/flight/imu.c @@ -214,10 +214,14 @@ static const float fc_acc = 0.5f / (M_PI * F_CUT_ACCZ); void acc_calc(uint32_t deltaT) { static int32_t accZoffset = 0; - static float accz_smooth; + static float accz_smooth = 0; + float dT; fp_angles_t rpy; t_fp_vector accel_ned; + // deltaT is measured in us ticks + dT = (float)deltaT * 1e-6f; + // the accel values have to be rotated into the earth frame rpy.angles.roll = -(float)anglerad[AI_ROLL]; rpy.angles.pitch = -(float)anglerad[AI_PITCH]; @@ -238,7 +242,7 @@ void acc_calc(uint32_t deltaT) } else accel_ned.V.Z -= acc_1G; - accz_smooth = accz_smooth + (deltaT / (fc_acc + deltaT)) * (accel_ned.V.Z - accz_smooth); // low pass filter + accz_smooth = accz_smooth + (dT / (fc_acc + dT)) * (accel_ned.V.Z - accz_smooth); // low pass filter // apply Deadband to reduce integration drift and vibration influence accSum[X] += applyDeadband(lrintf(accel_ned.V.X), accDeadband->xy);