Network Time Protocol (NTP)

Heard this from a Computerphile video, used for time Synchronization.

Wow, this is actually fascinating. First really used this at Enlighted.

In the case ROS, syncing to an NTP server helps reduce jitter between clocks on devices.

ROS 2Ā is dependent upon synchronized clocks between nodes to have all data in the same reference time. When the CreateĀ® 3 is publishing on topics, it is publishing its data with the timestamp of its system clock, which synchronizes with an NTP server.

Resources

If the CreateĀ® 3ā€™s Wi-Fi is connected to a network with internet connection, it will sync to a global time NTP server. The CreateĀ® 3 NTP config is also set to listen for servers on USB IP address 192.168.186.1 and 192.168.186.3. If the compute board is connected over USB to the CreateĀ® 3 with the compute board assigned one of these IP addresses on its USB interface, NTP on the compute board can keep the clocks between the compute board and CreateĀ® 3 in sync, even without an internet connection. If there is an internet connection on both compute board and CreateĀ® 3, configuring the NTP server on the compute board to serve the CreateĀ® 3 can still add value by reducing jitter between clocks. If your CreateĀ® 3 and compute board have an internet connection, this is not required, but is still recommended.

I donā€™t think if ROS comes out of the box like this, but this is super important to set up.

  • I guess ROS uses the system clock, so it is up to the OS to set up proper timing

Step-by-step

Taken from https://iroboteducation.github.io/create3_docs/setup/compute-ntp/

  1. On your Compute Board, install chrony NTP server package
sudo apt install chrony
  1. Edit the config file
sudo vi /etc/chrony/chrony.conf
  1. Add the following lines after theĀ pool #.ubuntu.pool.ntp.org iburst maxsources #Ā block

    server 192.168.186.2 presend 0 minpoll 0 maxpoll 0 iburst  prefer trust
    # Enable serving time to ntp clients on 192.168.186.0 subnet.
    allow 192.168.186.0/24
    
  2. Optionally add the following lines immediately afterward if your SBC will not have a connection to a reference clock (i.e., the Internet)

    # Serve time even if not synchronized to a time source
    local stratum 10
    
  3. Restart chrony

sudo service chrony restart
  1. Verify compute NTP server is talking to the CreateĀ® 3
sudo chronyc clients
  1. Confirm 192.168.182.2 shows non 0 number in NTP column

    Hostname                      NTP   Drop Int IntL Last     Cmd   Drop Int  Last
    ===============================================================================
    192.168.186.2                  51      0   5   -    32       0      0   -     -
    localhost                       0      0   -   -     -      31      0   7     4
    
  2. Note that if there is a large jump in the time, the CreateĀ® 3 may not accept it until its next reboot. This can be verified by checking the CreateĀ® 3 robotā€™s log for a line like

user.notice ntpd: ntpd: reply from 192.168.186.3: delay ### is too high, ignoring

If this happens, simply restart the robot (not just the application) via the webserver over the USB network connection.

time.google.com

Combine with ESP32 https://randomnerdtutorials.com/esp32-date-time-ntp-client-server-arduino/