FixTheRobot Explore Robotics / Systems Engineering / Engineering Guides / Module 07

Engineering Guides · Module 07

PPS and PTP setup

PTP measures offset using four timestamps and assumes the path delay is the same both ways. PPS provides the once-per-second edge that anchors a clock to GNSS time.

  • Intermediate
  • Module 07: Sensor Time Synchronization & Latency Engineering
  • Written for ROS 2 Jazzy where ROS 2 is used
  • Sources checked 2026-11-06

Assumptions: Numbers in the examples are illustrative and the code is executed by the site’s tests. Facts taken from a cited source are marked; other statements are general engineering knowledge and must be confirmed on the datasheet of the part you use.

1. Engineering problem

Sensors on a network or on separate boards each have their own clock. Synchronising them to a common time requires a reference (PPS from a GNSS receiver or a PTP grandmaster) and software that disciplines each clock to it.

2. When is this needed?

  • Setting up multi-sensor fusion with network sensors (LiDAR, cameras, an IMU box).
  • When sensor timestamps drift relative to each other.
  • Before specifying switches and NICs for a robot network.

3. Selection and design decisions

In a PTP exchange the leader sends a Sync message at time t1, the follower receives it at t2, sends a delay request at t3 and the leader receives it at t4. With a symmetric path the follower’s offset is ((t2 − t1) − (t4 − t3)) / 2 and the path delay is ((t2 − t1) + (t4 − t3)) / 2. Asymmetric paths put an error of half the asymmetry into the offset. The tools: ptp4l (linuxptp) runs the PTP protocol and can use hardware timestamping where the NIC supports it; phc2sys (also linuxptp) synchronises the system clock to a PTP hardware clock; chrony can take a PPS device as a reference clock.

Overview
PieceRoleCheck
GNSS receiver with PPS outputProvides the once-per-second edge and time of dayPPS wired to a GPIO or serial control line the kernel exposes as /dev/pps0
chrony with PPS refclockDisciplines the host clock to PPSchronyc sources shows the PPS source selected
PTP grandmasterTime source on the networkClock quality and priority settings
ptp4lRuns PTP on each NICHardware timestamping supported (ethtool -T)
phc2sysCopies the NIC clock to the system clockOffset reported small and stable
SwitchMust handle PTP correctly (boundary or transparent clock) for best accuracyVendor documentation

4. Advantages and disadvantages

  • Hardware timestamping gives much better accuracy than software timestamping and needs NIC support.
  • PPS is simple and needs a GNSS signal; indoors use a PTP grandmaster.
  • One grandmaster is a single point of failure for time.

5. Requirements and constraints

  • NICs and switches in the path support the chosen PTP mode.
  • Path asymmetry is understood and minimised.
  • Time source quality is monitored.

6. Architecture

GNSS ──PPS──▶ grandmaster ──PTP──▶ switch ──PTP──▶ LiDAR / camera / IMU box
                         └─▶ host NIC (ptp4l) ─▶ phc2sys ─▶ system clock (chrony)

7. Implementation

  1. Choose the reference (GNSS PPS or PTP grandmaster) and confirm all sensors support it.
  2. Configure ptp4l on the host NIC and check hardware timestamping with ethtool -T.
  3. Run phc2sys to align the system clock and watch its reported offsets.
  4. If using PPS, configure the chrony PPS refclock and check chronyc sources.
  5. Verify by comparing stamps of one physical event across sensors.
def ptp(t1, t2, t3, t4):
    # t1: master sends Sync; t2: slave receives; t3: slave sends Delay_Req; t4: master receives
    offset = ((t2 - t1) - (t4 - t3)) / 2
    delay = ((t2 - t1) + (t4 - t3)) / 2
    return offset, delay
o, d = ptp(100.000000, 100.000150, 100.001000, 100.001050)
print(f"slave offset {o * 1e6:.1f} us, one-way path delay {d * 1e6:.1f} us")
o, d = ptp(100.000000, 100.000130, 100.001000, 100.001130)
print(f"symmetric path: offset {o * 1e6:.1f} us, delay {d * 1e6:.1f} us")

Printed (checked by the site’s tests):

slave offset 50.0 us, one-way path delay 100.0 us
symmetric path: offset 0.0 us, delay 130.0 us

Reading it: in the first exchange the forward leg takes 150 µs and the return leg 50 µs, so the formula reports a 50 µs offset and a 100 µs mean delay, but the “offset” is really the path asymmetry: the true offset may be zero. In the symmetric case (130 µs both ways) it correctly reports zero offset and 130 µs delay. That is why path asymmetry limits PTP accuracy. The timestamps are illustrative; the commands in the steps are not executed by the site’s tests.

8. Real examples

  • Mobile robot with an Ethernet LiDAR: LiDAR synchronised by PTP to a grandmaster on the robot, host clock disciplined via phc2sys.

9. Failure scenarios

  • A switch that does not support PTP adds variable delay and ruins accuracy.
  • Software timestamping used on a NIC without hardware support.
  • PPS wired but chrony not configured with the refclock.

10. Troubleshooting

  1. Check that all devices agree on the clock source and domain.
  2. Check hardware timestamping with ethtool.
  3. Look at the offset trend: a slow drift means the clock servo is not locked.

11. Validation

  • The example prints the lines shown (executed by the site tests).
  • Reported offsets stay below the requirement over a long run.
  • An event stamped by two sensors agrees within the requirement.

12. Engineering checklist

13. Further references

Related on FixTheRobot