ROS2 多机时间同步(Chrony配置简明指南)

适用场景:

主机运行 ROS2 Humble(发布 /scan 等),板子运行 ROS2 Foxy(发布 /tf 等),两边通过 ROS_DOMAIN_ID 跨平台通讯。需要保证系统时间对齐,避免 TF 插值失败、建图抖动等问题。


一、主机端配置(NTP服务端)

1. 安装 chrony

bash 复制代码
sudo apt install chrony

2. 修改配置文件

bash 复制代码
sudo nano /etc/chrony/chrony.conf

将原有 pool 替换为:

conf 复制代码
server ntp.aliyun.com iburst
server ntp1.aliyun.com iburst
local stratum 10
allow 192.168.0.0/16
bindaddress 0.0.0.0

确保这几项存在。

3. 重启并启用开机自启

bash 复制代码
sudo systemctl restart chrony
sudo systemctl enable chrony

4. 验证状态

bash 复制代码
chronyc tracking

确认输出中包含:

text 复制代码
Leap status     : Normal

二、板载设备配置(NTP客户端)

1. 安装 chrony

bash 复制代码
sudo apt install chrony

2. 修改配置文件

bash 复制代码
sudo nano /etc/chrony/chrony.conf

添加如下行(仅保留一条 server):

conf 复制代码
server 192.168.x.x iburst   # 改为你的主机 IP
makestep 1 3

3. 重启服务并启用开机自启

bash 复制代码
sudo systemctl restart chrony
sudo systemctl enable chrony

4. 验证同步结果

bash 复制代码
chronyc tracking

确认 Leap status 为 Normal,且时间偏差在 0.1 秒以内。


三、建图抖动消除建议

在 Cartographer 的 .lua 文件中添加:

lua 复制代码
lookup_transform_timeout_sec = 0.5

确保 .yamluse_sim_time: false,并开启 EKF 的 publish_tf: true


四、测试通过表现

  • ros2 launch 无任何 extrapolation 报错
  • rviz2 地图无抖动
  • /tf 和 /scan 时间戳一致
  • cartographer_node 日志正常,submap 插入稳定

相关推荐
别让别人觉得你做不到2 天前
Ros工作空间
ros
吃水果不削皮7 天前
VINS-FUSION:跑通手机录制数据
ros·vio
Mr.Winter`10 天前
无人船 | 图解基于LQR控制的路径跟踪算法(以全驱动无人艇WAMV为例)
人工智能·算法·机器人·ros·ros2·运动规划·无人船
Stuomasi_xiaoxin14 天前
如何Ubuntu 22.04.5 LTS 64 位 操作系统部署运行SLAM3! 详细流程
linux·运维·ubuntu·ros·slam3
Mr.Winter`15 天前
无人船 | 图解基于PID控制的路径跟踪算法(以欠驱动无人艇Otter为例)
人工智能·算法·机器人·自动驾驶·ros·ros2·无人船
MocapLeader17 天前
新型多机器人协作运输系统,轻松应对复杂路面
机器人·ros·强化学习·多机器人协同·协同搬运
Mr.Winter`17 天前
无人船 | 图解基于PID控制的路径跟踪算法(以全驱动无人艇WAMV为例)
人工智能·机器人·ros·ros2·路径规划·无人船
sanzk22 天前
Ubuntu18.04 ROS Melodic安装
ros
kyle~25 天前
ROS2---std_msgs基础消息包
开发语言·python·机器人·ros·机器人操作系统
hillstream31 个月前
ROS2学习笔记1-起步的程序
ros·ros2