Hello everybody, I would like to collect some ideas on using the Precision Time Protocol (IEEE 1588v2) on mobile robots. Ten years ago, most robots had only one computer and maybe a camera. Nowadays, there can be multiple computers, SBCs or Jetsons on a single robot, together with GigE cameras, lidars, IMUs and other equipment that benefits from having synchronized time.
We have started with PTP on our robots quite recently and we still haven’t found an ideal solution. So I’m reaching out to the community to collect ideas. I’ll describe my view of how the time sync should work. Please, comment on it if you do something differently! This topic is not exactly ROS-specific, but I guess a lot of people who are working with ROS are facing the same kind of problems.
From my point of view, each mobile robot should behave as an isolated time island which synchronizes its island time via NTP with either the Internet (if possible) or with some other central unit running itself as an isolated time island (NTP does not like this, but can be persuaded). It can also use GPS time if available. The idea for using NTP “to the outside” is simple - PTP usually requires wired connections to work well, while most mobile robots are connected wirelessly. So it is not possible to use PTP to sync with the outer world. I think getting to the 10-100 ms precision offered by NTP is enough here.
However, “inside” the robot, all time should be ideally synchronized very precisely (at microsecond level) to be able to fuse various sensor measurements. At the same time, the network architecture on mobile robots tends to be mostly static, which makes it very similar to what Automotive profile defines (Automotive profile is a PTP profile that discards the Best Master Clock Algorithm and allows selecting the master clock manually; it also adds configuration that allows faster convergence of the time sync). I would usually want one of the computers to be the NTP client synced with outer world, and this computer should always act as PTP master to the rest of the robot. All other computers and sensors should be set to be PTP slaves.
So, that was the theory. Practically, we see several problems.
- PTP Delay mechanism. PTP defines peer-to-peer (P2P) and end-to-end (E2E) delay mechanisms. P2P is probably better, but as the name suggests (peer-to-peer), there can only be 2 PTP endpoints on each network time segment. This is quite a limitation which either tells you can only have 2 synced devices on the whole robot, or you have to buy expensive boundary clock or P2P transparent clock switches (or you have to have multiple network cards in the computers). E2E delay mechanism, on the other hand, can serve any number of endpoints on one segment, but it is not used by the Automotive profile (gPTP and Automotive only count with P2P). Some devices and libraries tend to only provide whatever is published as an official PTP profile, so getting them to work with “Automotive on E2E” is not possible. E2E is usually supported by the default PTP profile, but that has the BMCA selection enabled, which is not suitable on the mobile robot (you don’t want your clocks desynced by a rougue device claiming itself a master just because there was a network hiccup).
- Switches. As said above, P2P between more than 2 devices requires a boundary clock switch. And even with E2E, it is better if the switch has at least the transparent clock functionality, which greatly decreases the time needed for synchronization. But it seems almost nobody makes small PTP-enabled switches. Mobile robots usually can’t carry rack-mount beasts. We’ve only found BotBlox who are making high-performance minature switches. GigaBlox Rugged (unavailable due to chip shortage until '23; 4 gigabit ports, roughly $300 if chip prices go back to normal) should work as E2E transparent clock (but the firmware still has to be fixed for this to really work). GigaStax Rugged (first experimental batch in May '22; 5 gigabit ports, roughly $400) should work as P2P and E2E transparent clock and can also be configured as boundary clock. These are the only 1588-aware switches of reasonable size and price we have found. It also seems to me that there are two types of transparent clocks - those only filling the correction field in passing packets, and those that can act as P2P peers. So not all TC switches are compatible with the P2P protocol.
-
Network cards. Not all network cards support packet timestamping. Figuring out which card supports software or hardware timestamping is almost impossible (maybe by examining linux kernel, but even then - most NIC manufacturers do not tell you which NIC chip they used). It would be really useful to have an online database of
ethtool -T
which you can search when you’re looking for the right network card. But I haven’t found such. -
When is sync ready? Last problem (but a smaller one) is how to tell all devices are in sync and operation of the robot can begin. The PTP protocol does not define this kind of important aspect. The official way is “look at the master offset on slaves and decide whether its average and std are in an acceptable range”. But even then, the PTP clients such as linuxptp cannot do this for you automatically. The best thing I found so far is running
pmc
in a loop, querying the client (or the whole network) and manually analyzing the received offsets. I haven’t found a ROS node that could do this for me and e.g. publish a diagnostics message.
When doing the research, I sketched this table that helps me reason about the various official PTP profiles:
Profile | BMCA | Delay mech. | Layer |
---|---|---|---|
Default | Yes | P2P/E2E | L2/L3 |
gPTP (802.1AS) | Yes | P2P | L2 |
Automotive | No | P2P | L2 |
Autosar | No | P2P | L2 |
LXI | Yes | P2P | L3 |
IEC 62439-3 L2P2P | Yes | P2P | L2 |
IEC 62439-3 L3E2E | Yes | E2E | L3 |
Power Profile | Yes | P2P | L2 |
GigE Vision | Yes | P2P/E2E | ? |
My ideal | No | E2E | L2 |
I have also seen some newer mentions of unicast PTP, but we haven’t experimented with that too much and it also seems that support in sensors is not yet there (Basler ace2 cameras seem to be among the first ones).
This reading was quite useful to me when doing my research: