自动驾驶:时钟同步
·
一、自动驾驶时间同步简介

二、时间同步需要的服务
1、PTP
ptp4l -i mgbe3_0 -f /etc/automotive-slave.cfg &
phc2sys -s mgbe3_0 -O 0 -S 1 &
##命令这里的mgbe3_0可以换成mgbe2_0或者mgbe3_0.34
1.1 ptp4l
ptp4l是一个Linux上PTP协议(IEEE 1588)的实现,支持普通时钟,边界时钟和透明时钟
参数设置:
| 配置选项 | 描述 |
|---|---|
| -A | 自动选择延迟测量机制,运行时使用E2E,但接收到peer delay request报文后自动切换到P2P |
| -E | E2E延迟测量机制 (默认配置) |
| -P | P2P延迟测量机制 |
| -2 | IEEE 802.3协议 |
| -4 | UDP/IPv4协议(默认配置) |
| -6 | UDP/IPv6协议 |
| -H | 硬件时间戳(默认配置) |
| -S | 软件时间戳 |
| -L | Legacy硬件时间戳 |
| -f | 指定配置文件,若没有指定,则使用默认配置。 |
| -i | 指定网口(PTP port),可以多次使用指定多个网口,但该选项或配置文件中至少要指定一个。 |
| -p | 指定PHC (PTP Hardware Clock) device,例如/dev/ptp0,该选项已经不推荐使用,适用于v3.5之前的内核,因为v3.5之前的内核不支持通过网口找到PHC device。 |
| -s | slaveOnly模式 |
| -l | 打印级别 0~7(默认6,LOG_INFO) |
| -m | 将信息打印到标准输出 |
| -q | 不将信息发送到系统logger |
| -v | 显示版本号 |
| -h | 显示help信息 |
配置文件:
配置文件按段划分,空行和#开头的行会被忽略
有三种段类型:
- [global]段,用来配置program选项,clock选项,默认port选项
- port段使用被配置的网口的名字,如[eth0]段,其配置的选项会覆盖[global]段中默认port选项。port段可以为空内容,作用只是指定网口,这样命令行中不必使用-i选项
- [unicast_master_table]段,配置单播table,后面会有介绍。
配置文件内容示例:
#
# Automotive Profile example configuration for slaves containing those
# attributes which differ from the defaults. See the file, default.cfg, for
# the complete list of available options.
#
[global]
#
# Options carried over from gPTP.
#
gmCapable 1
priority1 254
priority2 254
logSyncInterval -3
syncReceiptTimeout 3
neighborPropDelayThresh 800000
min_neighbor_prop_delay -20000000
assume_two_step 1
path_trace_enabled 1
follow_up_info 1
transportSpecific 0x1
ptp_dst_mac 01:80:C2:00:00:0E
network_transport L2
delay_mechanism P2P
tx_timestamp_timeout 1000
step_threshold 1.0
#
# Automotive Profile specific options
#
BMCA noop
slaveOnly 1
inhibit_announce 1
asCapable true
ignore_source_id 1
# Required to quickly correct Time Jumps in master
#operLogSyncInterval 0
#operLogPdelayReqInterval 2
msg_interval_request 0
#servo_offset_threshold 30
#servo_num_offset_values 10
三、UTC转换UNIX时间戳(timestamp)
UNIX时间戳: Unix系统内记录的时间是一个时间戳,所谓时间戳,就是当前时间距离1970年1月1日0时0分0秒经过的总秒数
更多推荐
所有评论(0)