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

请添加图片描述

二、时间同步需要的服务

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
-EE2E延迟测量机制 (默认配置)
-PP2P延迟测量机制
-2IEEE 802.3协议
-4UDP/IPv4协议(默认配置)
-6UDP/IPv6协议
-H硬件时间戳(默认配置)
-S软件时间戳
-LLegacy硬件时间戳
-f指定配置文件,若没有指定,则使用默认配置。
-i指定网口(PTP port),可以多次使用指定多个网口,但该选项或配置文件中至少要指定一个。
-p指定PHC (PTP Hardware Clock) device,例如/dev/ptp0,该选项已经不推荐使用,适用于v3.5之前的内核,因为v3.5之前的内核不支持通过网口找到PHC device。
-sslaveOnly模式
-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秒经过的总秒数

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐