-
Notifications
You must be signed in to change notification settings - Fork 2
Time Synchronisation
Even though ROS has roscore
(the central server for ROS nodes), ROS does not automatically synchronise time between nodes, or between machines. In the best case this is not noticeable, in the worst case it can lead to messages becoming extremely out of sync or not working at all. The solution to this is to manually ensure time is synchronised to within a fraction of a second (ideally to less than the highest rate message passing between machines).
Time synchronisation is complex but a simple solution which will work in the majority of cases is installing chrony.
To install chrony on Ubuntu or Debian, simply run sudo apt install chrony
.
You may wish to play around with the settings, particularly in environments where synchronisation with outside time servers may be patchy or may not exist at all. In this case designating one of the machines, probably the router or machine running roscore
, a local time server will also work to keep things, if not accurate, then at least in sync with each other.
To make a machine a local server add the following lines (with neccesary adjustments) to /etc/chrony/chrony.conf
(or /etc/chrony.conf
depending on distro):
local stratum 10
allow 192.168.0.0/16
The line local stratum 10
specifies that when running from the local clock this server's stratum (roughly distance from real time source) is 10 which by convention makes it pretty much a last resort.
The line allow 192.168.0.0/16
opens the time server to all computers with an IP in the 192.168.0.0/16
range.
Using chrony, with access to the internet, you should get accuracies on the Pi-puck of within 0.00005
of a second (usually better). This corresponds to a rate of 10 kilohertz so should be adequate for ROS.
While chrony is great at synchronisation, it by default uses time stretching to synchronise. Time stretching is great if you're close to the correct time already, but not so good if you're already off (such as when a Raspberry Pi starts up). Again we should still only be out by 0.005 maximum, is this a problem? Yes, it is as it turns out. ROS's TF (transform) package is very sensitive to time differences.
To fix this we can make chrony step the clock, e.g. skip time, to get us back in sync. This should not be done while ROS is running (or while anything important is running for that matter) but should bring synchronisation to within 0.000001 of a second (if that). Time stretching will then happily keep it very close to that value.
To force a time step use chronyc -a makestep
(you'll need sudo for this).
General
Considerations
Nodes
Examples