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 插入稳定

相关推荐
liiiuzy4 天前
基于move_base的机器狗定位与导航
ros
Mr.Winter`6 天前
运动规划实战案例 | 基于采样的MPC控制(MPPI)算法(附ROS C++/Python仿真)
c++·人工智能·机器人·自动驾驶·ros·路径规划·具身智能
滴啦嘟啦哒8 天前
【机械臂】【基本驱动】三、对于夹取物体bug的最新解决
深度学习·bug·ros
滴啦嘟啦哒10 天前
【机械臂】【基本驱动】二、在gazebo中实现机械臂运动学逆解及物体夹取
深度学习·ros
Sereinc.Y10 天前
【移动机器人运动规划(ROS)】03_ROS话题-服务-动作
c++·动态规划·ros·slam
花花少年11 天前
快速体验ROS通信之服务(Service)机制
ros·service机制
疯狂的doctor14 天前
conda和ros2 humble共存,rclpy引入失败
conda·ros
程序员龙一17 天前
百度Apollo Cyber RT底层原理解析
自动驾驶·ros·apollo·cyber rt
再遇当年17 天前
ubuntu22.04安装中文输入法且与ros2与clion不冲突
ubuntu·ros·输入法·中文输入法·fcitx5
明月满西楼18 天前
在Ubuntu 20.04实现ROS1 Noetic 与 ROS2 Foxy 多版本共存及切换
ubuntu·ros·noetic·foxy