Time and NTP - RethinkRobotics/sdk-docs GitHub Wiki

Robot Time and NTP

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

===

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
    15 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 Baxter to the internet or need to set a custom configuration, see the Configuration Section.

Overview

Baxter'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 Baxter

NTP runs automatically on Baxter 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 synchornize against.

Default settings should work for most people to keep Baxter'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.

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 Baxter'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 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 four 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.

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 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 127.127.1.1             # local clock
fudge  127.127.1.1 stratum 12  # increase stratum

ntpdc Tool

The ntpdc tool is a program that can be run on the dev machine to query and configure the robot's NTP timeserver. Configuration changes made at run-time using this tool are only currently saved for that boot.

Configuring the NTP Server at Run-Time

Use the ntpdc tool to configure the NTP server at run-time. The easiest method is to use the interactive mode.

  1. Get the NTP Authentication Key information from the Rethink FTP - RSDK Resources folder. Your POC (Point-of-Contact) should have access to this service.
  2. In a terminal on your computer, drop into interactive mode:
    $ ntpdc -i <robot_address>  
  3. Authenticate your ntpdc session. Using the authentication file above:
    # Use the keyid number found at the start of the line
    ntpdc> keyid #<number>
    # Use the MD5 password found in the middle of the line
    ntpdc> passwd
    MD5 Password: #<Copy-&-Paste middle value of key in keys file here>

Now add a reference to your prefered time server.

  1. Add a server using the addserver command; use the prefer option to prioritize it:
    ntpdc> addserver ntp0.rethink.cxm prefer  
List Status with ntpdc

You can also use the ntpdc tool to list the current status of the robot's NTP synchronization.

  1. From inside an interactive session, use the peers command:
    ntpdc> peers
         remote           local      st poll reach  delay   offset    disp
    =======================================================================
    *kona.skafari.co 192.168.52.242   2 1024  373 0.00854  0.000148 0.15186
    =server2.shellva 192.168.52.242   2 1024  372 0.01021  0.001264 0.15143
    =sisdb01.muskego 192.168.52.242   3 1024  377 0.03574 -0.003096 0.13756
    =173.44.32.10    192.168.52.242   2 1024   77 0.05266 -0.003718 0.27809
    This is the same as using the ntpq -p <robot> command.
Unconfigure Servers

If you want to remove the default servers from the current configuration, you can remove the peers by reference.

  1. Drop into interactive mode as shown above.
  2. Authenticate as shown above.
  3. List peers (for finding their reference names):
    ntpdc> listpeers
    client    kona.skafari.com
    client    blah.servers.net
    client    server2.shellvatore.us
    client    173.44.32.10
  4. Unconfigure each peer/server by address (right side of above):
    ntpdc> unconfig <peer_address>

Resources

Troubleshooting

⚠️ **GitHub.com Fallback** ⚠️