fix(simulation): clamp simulated FIFO accel/gyro samples to int16 range#27864
Draft
farhangnaderi wants to merge 1 commit into
Draft
fix(simulation): clamp simulated FIFO accel/gyro samples to int16 range#27864farhangnaderi wants to merge 1 commit into
farhangnaderi wants to merge 1 commit into
Conversation
The simulated FIFO emulation for accel 0 and gyro 0 converts SI values to raw counts and assigns them to int16 FIFO fields. Beyond the emulated full-scale range (16 g / 2000 deg/s) the conversion overflows and wraps, so e.g. a 50 rad/s spin is reported as roughly -20 rad/s. Constrain the counts to the int16 range so out-of-range values saturate at full scale and are reported as clipping by the sensor driver, which matches real IMU behavior. Fixes #23469 Signed-off-by: Claude <noreply@anthropic.com>
Contributor
Author
|
I have not tested this. Fable did. I will test it later myself. |
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.
Fixes #23469.
The simulated FIFO emulation in
SimulatorMavlink::update_sensors()converts SI sensor values to raw counts and assigns them to theint16sample fields ofsensor_accel_fifo/sensor_gyro_fifo. Beyond the emulated full-scale range (16 g for accel 0, 2000 °/s ≈ 34.9 rad/s for gyro 0) the float-to-int16conversion overflows and wraps, so a fast-spinning vehicle (e.g. the monocopter at ~50 rad/s) sees its gyro data flip sign instead of saturating — the "inverted gyro at fast rates" reported in the issue.This change constrains the raw counts to
[INT16_MIN, INT16_MAX]before the assignment, for both the accel and gyro FIFO paths, so out-of-range values saturate at full scale. SincePX4Accelerometer/PX4Gyroscopealready flag FIFO samples at the int16 rails as clipped, the saturation is now correctly reported as clipping to downstream consumers (EKF2, vibration metrics), matching real IMU behavior and the expected behavior described in the issue.Tested by building
px4_sitl_default; the change is limited to the SITL MAVLink simulator sensor path and does not affect hardware targets.