Time synchronization using PTP(ptp4l) & chrony in distributed system of robot - githeim/windheim_archive GitHub Wiki

Time synchronization using PTP(ptp4l) & chrony

Introducing how to use PTP(Precision Time Protocol) & chrony in distributed systems like robot system. Here I will introduce a method to synchronize the time between two systems within the robot system.

Here we assume two separate systems. One operates as a master and the other operates as a slave. The slave synchronizes to the master's time.

install ptp4l & chrony

Install the following on both master and slave systems.

sudo apt install -y linuxptp chrony ethtool 

Master side

start ptp4l

$ sudo ptp4l -i eno1 -m

start chrony daemon

before starting chrony daemon, edit /etc/chrony/chrony.conf

Add the following script

refclock PHC /dev/ptp0
allow                 
rtcsync               

start the chrony daemon

$ sudo systemctl restart chrony.service

Slave side

start ptp4l & phc2sys

$ sudo ptp4l -i eno1 -s -m 

$ sudo phc2sys -a -r -m 

start chrony daemon

before starting chrony daemon, edit /etc/chrony/chrony.conf

Add the following script

server 192.168.0.100 minpoll -4 maxpoll -4 xleave extfield F323 filter 5
hwtimestamp * minpoll -4
driftfile /var/lib/chrony/drift
makestep 0.1 3
rtcsync

192.168.0.100 is the ip of the master system.

then restart the chrony daemon

$ sudo systemctl restart chrony.service