Use 64-bit microsecond timestamps for MAVLink HIL messages#17
Open
Blandingo wants to merge 1 commit into
Open
Conversation
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>
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.
Problem
MavlinkInterface::SendSensorMessagestakes the simulation time as a signed 32-bitint, andSensorData::Gps::time_utc_usecis also anint. The MAVLinkHIL_SENSORandHIL_GPStime_usecfields 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
uint64_tend to end (SendSensorMessages,SensorData::Gps::time_utc_usec), matching the MAVLink field width.sensor_gps_pluginso 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
f37ec25for 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.