Robot Time and NTP : The Network Time Protocol (NTP) is run on the robot to keep the robot's system time accurate and synchronized.
Contents
Introduction
By default, your robot will automatically use NTP to synchronize its system clock when connected to the internet. Large offsets are corrected at boot, while small inaccuracies are handled gradually during run-time.
To correct your robot's time, reboot your robot while having it connected to the internet.
You can check the time on the robot with the ntpdate
tool:
$ ntpdate -q <robot_address>
server 192.168.0.1, stratum 2, offset -0.000680, delay 0.03934
5 Oct 18:32:31 ntpdate[7238]: adjust time server 192.168.52.242 offset -0.000680 sec
This will tell you the difference between your computer's time (the time on the left) and the robot's system clock.
If you cannot connect your Sawyer to the internet or need to set a custom configuration, see the Configuration Section.
Overview
Sawyer's on-board time is kept accurate using Chrony time service. The default configuration will set the robot's time once during startup each time the robot boots, and then will maintain a running NTP server that will gradually slew the time to keep the robot's system time in sync. The default time servers are received from pool.ntp.org, but these can be configured by either providing the NTP Servers
field of the Configuration Menu in the FSM from your DHCP host.
NTP on Sawyer
NTP runs automatically on Sawyer in two parts:
- The
ntp-client
script runs on boot to correct large time offsets. - The
ntpd
service then runs an NTP timeserver to gradually keep the time accurate for small time differences.
The final important piece is the ntp.conf
configuration used for both these services. This determines which reference time servers the robot should use to synchronize against.
Default settings should work for most people to keep Sawyer's time accurate. Users can query the status of the robot's NTP timeserver using various NTP tools including: ntpdate, and ntpq.
For the advanced users, the above NTP services can be configured using DHCP.
Timezone
NTP will sync your robot's time to "real-world" time, but you still need to set the robot's timezone. The robot's timezone can be set using the Field-Service-Menu. This does not affect the time kept by NTP as that will be based on UTC, however it will affect the offset used for the displayed system time.
How to Use NTP
How to Check Robot Time
You can use the ntpdate tool for a simple reference check against the robot, or use the ntpq tool to check the status of the NTP timeserver and Sawyer's synchronization, among other details. Make sure you have installed the ntp tools:
$ sudo apt-get install ntp
Query the status of the NTP server on the robot:
$ ntpq -p <robot_address>
remote refid st t when poll reach delay offset jitter
==============================================================================
*server2.shellva 128.59.39.48 2 u 1712 1024 376 10.225 1.013 3.852
*173.44.32.10 96.237.191.14 2 u 42 1024 217 52.744 -7.044 10.286
kona.skafari.co 209.51.161.238 2 u 1694 1024 376 8.558 -1.378 16.680
*sisdb01.muskego 50.18.44.198 3 u 358 1024 377 35.632 -3.661 7.991
This lists the known synchronization references (and their "refid" references) of the robot’s ntp server. These are the servers and peer timeservers that the robot’s NTP daemon/server is trying to sync against. The first character in a row indicates the current Selection status (‘*’ means active). See ‘Select Field’: http://www.eecis.udel.edu/~mills/ntp/html/decode.html#peer
Compare Reference Time
You can compare the robot's time to your system's time using the -q ntpdate command:
$ ntpdate -q <robot_ip>
How to Fix Robot Time
Robot time is fixed by connecting the robot to timeservers. This must happen at boot for large offsets. Smaller inaccuracies (~17min) are handled regularly during run-time.
Default Operation
By default the NTP services are configured to get four servers from the NTP Pool Project. On boot, if the robot can reach these servers -- i.e. if the robot can connect to the internet -- the ntp-client
corrects the robot's time, setting it to the reference time from the servers in one big jump. After this the robot's ntpd
timeserver will continue to synchronize against these servers.
Setting the Time on Boot
In order to set large offsets, the boot-time ntp-client
need to be able to connect to the configured NTP servers. If using the default settings, this just means the robot can reach the internet. If your robot cannot connect to the internet, or you wish to use different servers during boot time, you can provide those servers using the NTP Servers
field of the Configuration Menu in the FSM. Once the robot has accurate time, it will save that time to the hardware clock on shutdown.
Configuration
DHCP
Using DHCP to provide the ntp-servers
option is the standard way to provide NTP configuration information on a network. Your local network may already be configured to provide this information.
From DHCP Options and BOOTP Vendor Extensions:
8.3. Network Time Protocol Servers Option
This option specifies a list of IP addresses indicating NTP [18]
servers available to the client. Servers SHOULD be listed in order
of preference.
-- http://www.ietf.org/rfc/rfc2132.txt
Running Locally with DHCP
If you need to correct the time locally (without being on a network), you can setup your own DHCP server on a local machine with a tool such as isc-dhcp-server
. Make sure to run an NTP server on your own machine and provide the address of your machine as the address in the NTP Servers
field in the Configuration Menu of the FSM.
If your dev machine is not connected to other authentic time servers, you will need to fudge
your own local time as a valid source of authentication. By default, NTP does not sync against stratum 16 servers (which is what a disconnected server is). "Stratum" indicates the number of hops you are away from a 'true' time source (stratum 1), such as a GPS based device.
# editing your workstation's /etc/ntp.conf
# remove or comment out your workstation's references to other NTP servers or NTP pools
# add backup fake local server
server 127.127.1.0 iburst # use local clock of sdk workstation as the server, burst synchronize
fudge 127.127.1.0 stratum 10 # "fake" sdk workstation as a stratum 10 NTP server (rather than the default and invalid stratum 16)
# set permissions to use your computer as an NTP server
restrict -4 default kod notrap nomodify nopeer limited # remove the default "noquery" options to allow others on the LAN to see the NTP server
restrict -6 default kod notrap nomodify nopeer limited # ditto
# optionally broadcast your IP address to the network
broadcast <your>.<ip>.<address>.<here>
Resources
- ntpq - standard NTP query program:
http://www.eecis.udel.edu/~mills/ntp/html/ntpq.html
- ntpd - Network Time Protocol (NTP) daemon:
http://www.eecis.udel.edu/~mills/ntp/html/ntpd.html
- Command Index - (all the commands available in the ntp.conf configuration file and the ntpdc(/future ntpq versions) tools:
http://www.eecis.udel.edu/~mills/ntp/html/comdex.html