Skip to content

feat(autopilot-manager): set system time from FC GNSS time when NTP is not synced#107

Merged
dakejahl merged 1 commit into
mainfrom
feat/fc-gnss-time-sync
Jul 23, 2026
Merged

feat(autopilot-manager): set system time from FC GNSS time when NTP is not synced#107
dakejahl merged 1 commit into
mainfrom
feat/fc-gnss-time-sync

Conversation

@dakejahl

Copy link
Copy Markdown
Contributor

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.

…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.
@dakejahl
dakejahl merged commit b629587 into main Jul 23, 2026
1 check passed
@dakejahl
dakejahl deleted the feat/fc-gnss-time-sync branch July 23, 2026 16:38
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