Skip to content

Commit 8b1b8ec

Browse files
Merge pull request #11356 from sensei-hacker/fix/imu-gps3dspeed-on-new-data
imu: compute GPS 3D speed only on new GPS data
2 parents 41d168f + 66c87bf commit 8b1b8ec

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/main/flight/imu.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ STATIC_FASTRAM pt1Filter_t HeadVecEFFilterY;
113113
STATIC_FASTRAM pt1Filter_t HeadVecEFFilterZ;
114114
FASTRAM fpVector3_t HeadVecEFFiltered = {.v = {0.0f, 0.0f, 0.0f}};
115115

116-
STATIC_FASTRAM float GPS3DspeedFiltered=0.0f;
117-
STATIC_FASTRAM pt1Filter_t GPS3DspeedFilter;
118116

119117
FASTRAM bool gpsHeadingInitialized;
120118

@@ -210,8 +208,6 @@ void imuInit(void)
210208
pt1FilterReset(&HeadVecEFFilterX, 0);
211209
pt1FilterReset(&HeadVecEFFilterY, 0);
212210
pt1FilterReset(&HeadVecEFFilterZ, 0);
213-
// Initialize 3d speed filter
214-
pt1FilterReset(&GPS3DspeedFilter, 0);
215211
}
216212

217213
void imuSetMagneticDeclination(float declinationDeg)
@@ -667,9 +663,6 @@ static void imuCalculateFilters(float dT)
667663
HeadVecEFFiltered.y = pt1FilterApply4(&HeadVecEFFilterY, rMat[1][0], IMU_ROTATION_LPF, dT);
668664
HeadVecEFFiltered.z = pt1FilterApply4(&HeadVecEFFilterZ, rMat[2][0], IMU_ROTATION_LPF, dT);
669665

670-
//anti aliasing
671-
float GPS3Dspeed = calc_length_pythagorean_3D(gpsSol.velNED[X],gpsSol.velNED[Y],gpsSol.velNED[Z]);
672-
GPS3DspeedFiltered = pt1FilterApply4(&GPS3DspeedFilter, GPS3Dspeed, IMU_ROTATION_LPF, dT);
673666
}
674667

675668
static void imuCalculateGPSacceleration(fpVector3_t *vEstAccelEF,fpVector3_t *vEstcentrifugalAccelBF, float *acc_ignore_slope_multipiler)
@@ -705,6 +698,14 @@ static void imuCalculateTurnRateacceleration(fpVector3_t *vEstcentrifugalAccelBF
705698
float currentspeed = 0;
706699
if (isGPSTrustworthy()){
707700
//first speed choice is gps
701+
static bool lastGPSHeartbeat;
702+
static pt1Filter_t GPS3DspeedFilter;
703+
static float GPS3DspeedFiltered = 0.0f;
704+
if (gpsSol.flags.gpsHeartbeat != lastGPSHeartbeat) {
705+
lastGPSHeartbeat = gpsSol.flags.gpsHeartbeat;
706+
float GPS3Dspeed = calc_length_pythagorean_3D(gpsSol.velNED[X], gpsSol.velNED[Y], gpsSol.velNED[Z]);
707+
GPS3DspeedFiltered = pt1FilterApply4(&GPS3DspeedFilter, GPS3Dspeed, IMU_ROTATION_LPF, dT);
708+
}
708709
currentspeed = GPS3DspeedFiltered;
709710
*acc_ignore_slope_multipiler = 4.0f;
710711
}

0 commit comments

Comments
 (0)