Difference between revisions of "Time and NTP"

Jump to: navigation , search
Line 92: Line 92:
   of preference.<br />
   of preference.<br />
-- http://www.ietf.org/rfc/rfc2132.txt
==== Running Locally with DHCP ====
==== Running Locally with DHCP ====

Revision as of 16:17, 28 February 2018

Robot Time and NTP

The Network Time Protocol (NTP) is run on the robot to keep the robot's system time accurate.


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, stratum 2, offset -0.000680, delay 0.03934
    5 Oct 18:32:31 ntpdate[7238]: adjust time server 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.


Sawyer's on-board time is kept accurate using the standard NTP 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 option from your DHCP host, or using the ntpdc tool to configure the running NTP server.

Note: NTP was first enabled in version 0.6.2 of the RSDK. Make sure you are running rsdk-0.6.2 or above to use these services.

NTP on Sawyer

NTP runs automatically on Sawyer in two parts:

  1. The ntp-client script runs on boot to correct large time offsets.
  2. 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, ntpq, and ntpdc.

For the advanced users, the above NTP services can be configured using DHCP or the run-time ntpdc client.


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.html 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     2 u 1712 1024  376   10.225    1.013   3.852
*    2 u   42 1024  217   52.744   -7.044  10.286
     kona.skafari.co   2 u 1694 1024  376    8.558   -1.378  16.680
*sisdb01.muskego     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 at pool.ntp.org. 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 option in your DHCP servers configuration.

Once the robot has accurate time, it will save that time to the hardware clock on shutdown.



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.


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 option.

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.

= Add backup fake local server =
server             # local clock
fudge stratum 12  # increase stratum


  • ntpq - standard NTP query program:
  • ntpd - Network Time Protocol (NTP) daemon:
  • Command Index - (all the commands available in the ntp.conf configuration file and the ntpdc(/future ntpq versions) tools: