feat(autopilot-manager): set system time from FC GNSS time when NTP is not synced#107
Merged
Conversation
…s not synced Consume SYSTEM_TIME from the autopilot and step the local clock via clock_settime when the FC time is valid, the kernel reports no NTP sync, and the clocks disagree by more than 2 s. The stream is requested at 1 Hz and re-requested after 30 s of silence. The systemd units grant CAP_SYS_TIME, and the message loop's timers move to time.monotonic() so the service's own clock steps cannot stall or misfire them.
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.
Summary
Set the local system clock from the flight controller's GNSS-derived UTC time (SYSTEM_TIME) when the clock has no NTP sync.
Problem
A Jetson/Pi with no network has no NTP source and no battery-backed RTC, so its clock is wrong from boot until the network appears. An FC with GNSS already knows UTC and streams it in SYSTEM_TIME, but nothing consumed it — time sync only worked in the companion→FC direction.
Solution
autopilot-manager requests SYSTEM_TIME at 1 Hz (re-requested after 30 s of silence, since PX4 mutes the stream while its clock is unset and a reboot drops the configured interval) and steps the clock via clock_settime when the FC time is valid, the kernel reports no NTP sync, and the clocks disagree by more than 2 s (absorbs transport latency). The two directions cannot fight: FC→local runs only while unsynced, and clock_settime does not raise the kernel NTP-synced flag that gates the existing local→FC push. The systemd units grant AmbientCapabilities=CAP_SYS_TIME, and the message loop's interval timers and heartbeat staleness checks move to time.monotonic() so the service's own clock steps cannot stall or misfire them.