Skip to content

Use 64-bit microsecond timestamps for MAVLink HIL messages#17

Open
Blandingo wants to merge 1 commit into
PX4:masterfrom
Blandingo:fix-64-bit-hil-timestamps
Open

Use 64-bit microsecond timestamps for MAVLink HIL messages#17
Blandingo wants to merge 1 commit into
PX4:masterfrom
Blandingo:fix-64-bit-hil-timestamps

Conversation

@Blandingo

Copy link
Copy Markdown

Problem

MavlinkInterface::SendSensorMessages takes the simulation time as a signed 32-bit int, and SensorData::Gps::time_utc_usec is also an int. The MAVLink HIL_SENSOR and HIL_GPS time_usec fields are 64-bit, so the value wraps at 2^31 microseconds — roughly 35 minutes 47 seconds of simulation time. After the wrap, PX4 sees non-monotonic/stale sensor timestamps and long-endurance SITL sessions degrade or fall over.

Fix

  • Carry the timestamp as uint64_t end to end (SendSensorMessages, SensorData::Gps::time_utc_usec), matching the MAVLink field width.
  • Clamp the JSBSim sim-time-to-microseconds conversion in sensor_gps_plugin so a non-finite or negative sim time cannot produce a bogus timestamp.

Validation

We have been carrying this as a local patch on top of f37ec25 for long-endurance fixed-wing SITL runs (JSBSim + PX4 v1.16/v1.17 lockstep); with it applied, sessions run well past the 36-minute mark with healthy estimator state, and our smoke/metrics gates pass against both PX4 v1.16.2 and v1.17.0.

SendSensorMessages takes the simulation time as a signed 32-bit int, so
HIL_SENSOR and HIL_GPS time_usec wrap after 2^31 microseconds, roughly
35 minutes 47 seconds of simulation time. After the wrap PX4 rejects the
stale-looking sensor data and long-endurance SITL sessions fall over.

Carry the timestamp as uint64_t end to end, matching the width of the
MAVLink time_usec fields, and clamp the JSBSim sim-time conversion so a
non-finite or negative sim time cannot produce a bogus timestamp.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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