Skip to content

Comments

imu: compute GPS 3D speed only on new GPS data#11356

Open
sensei-hacker wants to merge 1 commit intoiNavFlight:maintenance-9.xfrom
sensei-hacker:fix/imu-gps3dspeed-on-new-data
Open

imu: compute GPS 3D speed only on new GPS data#11356
sensei-hacker wants to merge 1 commit intoiNavFlight:maintenance-9.xfrom
sensei-hacker:fix/imu-gps3dspeed-on-new-data

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Feb 22, 2026

Summary

  • Moves GPS 3D speed filter computation inside a gpsHeartbeat check so it only runs when fresh GPS data arrives (~10 Hz), rather than every IMU cycle (~1000 Hz). Reduces the CPU impact by 99%.
  • Converts module-level filter/state variables to function-local statics to reduce scope

Motivation

The GPS 3D speed filter was previously called every IMU update cycle regardless of whether new GPS data was available. Since GPS data arrives at ~10 Hz, the filter was being invoked ~100× more often than necessary with no benefit.

Files Changed

  • src/main/flight/imu.c — gate GPS 3D speed update on gpsHeartbeat, convert state to local statics

GPS3DspeedFiltered was computed every PID cycle (1 kHz) from
gpsSol.velNED[], which only changes when the GPS task delivers a new
fix (~10 Hz). Move the sqrt and pt1 filter update into
imuCalculateTurnRateacceleration(), gate them on gpsHeartbeat change,
and make the filter state a static local. The variable is only
consumed in that function (fixed-wing + GPS-trustworthy path), so the
module-level FASTRAM variables and the imuInit() reset are also removed.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@sensei-hacker
Copy link
Member Author

sensei-hacker commented Feb 22, 2026

Mr. Oven,
I have just made three PRs that touch the areas of code that you are the expert in.
I would appreciate your thoughts on them. This one, and #11357 and #11358

@breadoven

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant