Syncing time on Upkie and your computer #422
ubgk
started this conversation in
Tips and tricks
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Time synchronisation
Some use cases may require (sub-)millisecond level of time synchronisation between your computer and Upkie.
For instance, you may be interested in collecting Motion Capture data or recording a video of the robot performing a certain task, and compare it against the robots proprioceptive logs. In such a scenario, you would typically need to align the timestamps on your robot logs, and the external ones, which is a tedious process.
Unless you are lucky enough to have a GPS clock in hand, it is most likely that your computer uses Network Time Protocol to update its time periodically, as its internal hardware clock (e.g., the RTC module on your motherboard) can gain or lose up to a few seconds a day.
Chrony
We can use the same protocol to synchronise the clock between Upkie and our computers. chrony is an implementation of NTP that can act both as a server and a client. It is available on most major package managers (e.g.,
apt
,dnf
orbrew
):Setting up the server
You can set up your computer or the onboard Raspberry Pi to act as the NTP server, to do so, you need to edit your chrony configuration file. This will typically be in
/etc/chrony.conf
or/etc/chrony/chrony.conf
Add the following lines to your configuration:
and restart the daemon:
Setting up the client
We can use
chrony
on the client to fetch the time from the server, although other NTP clients should work too.You can see and edit the NTP servers (or server pools) in your config file:
You can use
chronyc
to list all the sources and update your time:$ sudo chronyc sources MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* 192.168.2.100 10 6 377 59 +49ms[ +168ms] +/- 6470us
and
The
1/2
argument will tellchronyc
that we want at least 1 good measurement for a maximum of 2 attempts, and can be configured to reflect your needs. Another important point is, whenchrony
detects the system is out-of-sync with the server, it will adjust time gradually (rather than making a jump). You can add a directive in your config file to disable this:Nota Bene:
Every time you make changes to the config file, you will need to restart the service:
Beta Was this translation helpful? Give feedback.
All reactions