fix(imu_orientation): use correct gyro axis per bias#9
Open
mvanhorn wants to merge 1 commit into
Open
Conversation
Lines 90-91 of `gyro_bias` adjustment read `gyro.x` for both the Y and Z axes, so the running per-axis bias estimate for Y and Z was driven by the X-axis gyro reading instead of its own axis. Result: Y and Z bias diverge from the actual sensor bias, and downstream `gyro.y -= gyro_bias.y` / `gyro.z -= gyro_bias.z` corrections drift instead of converge. Read `gyro.y` for the Y bias update and `gyro.z` for the Z update, so each axis's complementary-filter bias estimator uses its own measurement, matching the X-axis line and the gyro-bias bookkeeping that follows on lines 93-95. Fixes malloch#7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #7.
imu_orientation.cpplines 90-91 updategyro_bias.yandgyro_bias.zusinggyro.xfor both, instead ofgyro.yandgyro.zrespectively. Result: the per-axis bias estimate for Y and Z is driven by X-axis sensor input, so the corrections applied a few lines later (gyro.y -= gyro_bias.y,gyro.z -= gyro_bias.z) drift instead of converging to the actual per-axis bias. Reading the correct axis per line fixes it.Why this matters
The complementary filter pattern is "running average of axis input -> bias estimate -> subtract from raw axis." Lines 89-91 implement that pattern for each of the three axes, but a copy-paste duplicated
gyro.xacross all three. The X-axis line is correct; Y and Z are bugged.Downstream consumers reading the resulting orientation get a Y/Z gyro bias that tracks X-axis motion. Any device whose X axis sees a different angular-velocity profile from Y/Z (any real-world IMU placement) ends up with growing orientation drift on Y and Z that does not converge.
Changes
imu_orientation.cpp:90-gyro.x->gyro.yfor the Y-axis bias update.imu_orientation.cpp:91-gyro.x->gyro.zfor the Z-axis bias update.No public API change. The two-line correction makes the existing bias-removal block (
gyro.x -= gyro_bias.x/.y/.zat lines 93-95) actually correct per axis.How to test
This repo is header + cpp, no test suite. Compilation is unaffected (only two operand swaps in identical-shape expressions). The Y/Z bias correctness is verifiable in a runtime test: feed a stream of (omega_x = 0, omega_y = const, omega_z = const) to
IMU_Orientation::update()over many iterations. Before this PR,gyro_bias.yandgyro_bias.zdecay toward zero (tracking the zero X input). After this PR, they converge to the actual Y/Z bias.Fixes #7
AI-assisted.