Skip to content

Fixed sensor.accelerometer gravity sign for consider_gravity = True case - #1175

Merged
Gui-FernandesBR merged 3 commits into
RocketPy-Team:developfrom
vapsik:develop-gravity_fix
Sep 9, 2026
Merged

Fixed sensor.accelerometer gravity sign for consider_gravity = True case#1175
Gui-FernandesBR merged 3 commits into
RocketPy-Team:developfrom
vapsik:develop-gravity_fix

Conversation

@vapsik

@vapsik vapsik commented Aug 16, 2026

Copy link
Copy Markdown

Issue

In the case of consider_gravity = True the current sensor.accelerometer sensor accounts for gravity vector incorrectly — $$a_{ \text{inertial} } = a_{\text{ENU}} + g$$ but since the gravity vector has components $g = (0,0,-9.8)$ in ENU frame then it must be $$a_{ \text{inertial} } = a_{\text{ENU}} - g$$.

A simple example showcasing the current implementation being incorrect is with a stationary state (1) and airless free-falling rocket (2) - both with ENU-aligned accelerometers: 1) during stationary phase where $a_{\text{ENU}} = 0$ the consider_gravity = True accelerometer reading shows $a_{ \text{inertial} } = (0,0,-9.8)$ where as real IMU would show $a_{ \text{inertial} } = (0,0,+9.8)$ as normal force upward from the ground must negate the effect of gravity for achieving the stationary state. 2) as a rocket goes into (airless) free fall real IMU would show inertial acceleration of 0 (weightless) but with current implementation in free fall or near apogee before parachute opening the consider_gravity = True accelerometer shows total acceleration of nearly 19.6 showcasing the wrong gravity sign usage.

Changes

In accelerometer.py changed inertial_acceleration = Vector(u_dot[3:6]) + gravity into inertial_acceleration = Vector(u_dot[3:6]) - gravity.

Test file showcasing the bugs (made with Claude)

repro_gravity_bug.py

@vapsik
vapsik requested a review from a team as a code owner August 16, 2026 10:28
@Gui-FernandesBR

Copy link
Copy Markdown
Member

@vapsik tests not passing on CI... Could you take a look pleasE?

Gui-FernandesBR and others added 2 commits September 8, 2026 22:40
The one test that failed with the sign fix, test_noisy_rotated_accelerometer,
recomputes the expression it is checking: it built its expected value with
`Vector(U_DOT[3:6]) + Vector([0, 0, -GRAVITY])`, the same term being
corrected in Accelerometer.measure. So it never evidenced either sign, it
mirrored whichever one the implementation held, and it failed here only
because the two copies had drifted apart. Its line is updated to match, with
a note on what the quantity is.

Mirroring it again would leave the convention untested, so this also adds
test_accelerometer_at_rest_reads_gravity_upward, which states the physics
instead of the formula: an accelerometer senses the support force holding it
up, so at rest it reads +g along its up axis, and zero with consider_gravity
off. It is exact rather than bounded, since every noise, bias and drift
default is zero. Reverting the fix in measure() fails it.

The consider_gravity docs said only that gravity was "considered", which is
what let the sign go either way; they now say the sensor reports proper
acceleration and what it reads at rest.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Running the unit suite from the repository root writes flight_calisto_robust.rpy
and the three monte_carlo_test.* logs there, and none of them are ignored, so
they were picked up by the previous commit. They are outputs, not sources.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.13%. Comparing base (7e785a6) to head (012fd5d).
⚠️ Report is 6 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1175      +/-   ##
===========================================
+ Coverage    89.96%   91.13%   +1.16%     
===========================================
  Files          131      131              
  Lines        17527    17560      +33     
===========================================
+ Hits         15769    16003     +234     
+ Misses        1758     1557     -201     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Gui-FernandesBR
Gui-FernandesBR merged commit 7f2ad3f into RocketPy-Team:develop Sep 9, 2026
9 checks passed
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.

2 participants