IEEE1588(the Precision Time Protocol 简称为 PTP )全称是“网络测量和控制系统的精密时钟同步协议标准”,可以使用ubuntu中的网卡作为时间的master也可以外接一个精准的时钟,来实现传感器的时间同步。
Ouster官方参考链接
激光雷达与系统PTP时间同步
+-------------------------------------+
| Ubuntu 18.04 System |
| * 2x Intel i210 Ethernet Interfaces |
| * Linux PTP service |
| |
| eno1 eno2 |
+-------+---------------------+-------+
| |
+-------+-------+ +--------+------+
| Trimble GM100 | | + +
| GPS -> PTP | | Ouster OS1 | |
| grandmaster | | | |
| (optional) | | | |
+---------------+ +---------------- |
+--------------- +
本篇博客主要介绍单独使用一个NUC连接Ouster OS1-128激光雷达来实现PTP时间同步。
安装linuxptp,chrony,ethtool等工具
sudo apt update
sudo apt install linuxptp chrony ethtool
# 查看网络接口
ifconfig
# 查看是否有PTP功能
sudo ethtool -T YOUR_INTERFACE
出现类似如下结果,则证明支持PTP功能(PTP Hardware Clock: 0)
Time stamping parameters for eno1:
Capabilities:
hardware-transmit (SOF_TIMESTAMPING_TX_HARDWARE)
software-transmit (SOF_TIMESTAMPING_TX_SOFTWARE)
hardware-receive (SOF_TIMESTAMPING_RX_HARDWARE)
software-receive (SOF_TIMESTAMPING_RX_SOFTWARE)
software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
hardware-raw-clock (SOF_TIMESTAMPING_RAW_HARDWARE)
PTP Hardware Clock: 0
Hardware Transmit Timestamp Modes:
off (HWTSTAMP_TX_OFF)
on (HWTSTAMP_TX_ON)
Hardware Receive Filter Modes:
none (HWTSTAMP_FILTER_NONE)
all (HWTSTAMP_FILTER_ALL)
出现下述结果,则证明不支持:(PTP Hardware Clock: none)
Time stamping parameters for enxf8e43bb4ab3d:
Capabilities:
software-transmit (SOF_TIMESTAMPING_TX_SOFTWARE)
software-receive (SOF_TIMESTAMPING_RX_SOFTWARE)
software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
PTP Hardware Clock: none
Hardware Transmit Timestamp Modes: none
Hardware Receive Filter Modes: none
若支持PTP功能,则继续下述操作,否则需要外接一个外部的钟。
clockClass 128
boundary_clock_jbod 1
[YOUR_INTERFACE] <- (这个放到文档中的最后,如我的为[enp86s0])
sudo mkdir -p /etc/systemd/system/ptp4l.service.d
sudo touch /etc/systemd/system/ptp4l.service.d/override.conf
sudo gedit /etc/systemd/system/ptp4l.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/sbin/ptp4l -f /etc/linuxptp/ptp4l.conf
sudo mkdir -p /etc/systemd/system/phc2sys.service.d
sudo touch /etc/systemd/system/phc2sys.service.d/override.conf
sudo gedit /etc/systemd/system/phc2sys.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/sbin/phc2sys -w -s CLOCK_REALTIME -c YOUR_INTERFACE(你的以太网接口名字)
修改此 /etc/systemd/system/phc2shm.service文件中的内容:
[Unit]
Description=Synchronize PTP hardware clock (PHC) to NTP SHM
Documentation=man:phc2sys
After=ntpdate.service
Requires=ptp4l.service
After=ptp4l.service
[Service]
Type=simple
ExecStart=/usr/sbin/phc2sys -s YOUR_INTERFACE -E ntpshm -w
[Install]
WantedBy=multi-user.target
注:YOUR_INTERFACE为你的以太网接口名字
sudo systemctl daemon-reload
sudo systemctl restart ptp4l
sudo systemctl restart phc2sys
sudo systemctl restart phc2shm
修改ouster驱动中的Launch文件中内容timestamp_mode (string) - Method used to timestamp measurements [TIME_FROM_INTERNAL_OSC, TIME_FROM_SYNC_PULSE_IN, TIME_FROM_PTP_1588]为TIME_FROM_PTP_1588。
source devel/setup.bash
roslaunch ouster_ros ouster_XXX.launch
Ouster_IMU: 1769 1683895566.722931
Ouster_Lidar: 177 1683895566.733269
Ouster_IMU: 1770 1683895566.737509
Ouster_IMU: 1771 1683895566.742845
Ouster_IMU: 1772 1683895566.752959
Ouster_IMU: 1773 1683895566.763221
Ouster_IMU: 1774 1683895566.772937
Ouster_IMU: 1775 1683895566.783624
注:需要读者自己写一个小程序