Skip to content

fix(simulation): clamp simulated FIFO accel/gyro samples to int16 range#27864

Draft
farhangnaderi wants to merge 1 commit into
mainfrom
claude/px4-autopilot-23469-2egb67
Draft

fix(simulation): clamp simulated FIFO accel/gyro samples to int16 range#27864
farhangnaderi wants to merge 1 commit into
mainfrom
claude/px4-autopilot-23469-2egb67

Conversation

@farhangnaderi

@farhangnaderi farhangnaderi commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #23469.

The simulated FIFO emulation in SimulatorMavlink::update_sensors() converts SI sensor values to raw counts and assigns them to the int16 sample fields of sensor_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-int16 conversion 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. Since PX4Accelerometer/PX4Gyroscope already 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.


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>
@github-actions github-actions Bot added kind:bug Something is broken or behaving incorrectly. scope:simulation SITL, Gazebo, jmavsim, lockstep, or simulated sensors. labels Jul 10, 2026
@farhangnaderi

Copy link
Copy Markdown
Contributor Author

I have not tested this. Fable did. I will test it later myself.

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

Labels

kind:bug Something is broken or behaving incorrectly. scope:simulation SITL, Gazebo, jmavsim, lockstep, or simulated sensors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Simulated gyro sensor data gets inverted at fast rates

2 participants