适用场景:
主机运行 ROS2 Humble(发布 /scan 等),板子运行 ROS2 Foxy(发布 /tf 等),两边通过 ROS_DOMAIN_ID 跨平台通讯。需要保证系统时间对齐,避免 TF 插值失败、建图抖动等问题。
一、主机端配置(NTP服务端)
1. 安装 chrony
sudo apt install chrony
2. 修改配置文件
sudo nano /etc/chrony/chrony.conf
将原有 pool
替换为:
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. 重启并启用开机自启
sudo systemctl restart chrony
sudo systemctl enable chrony
4. 验证状态
chronyc tracking
确认输出中包含:
Leap status : Normal
二、板载设备配置(NTP客户端)
1. 安装 chrony
sudo apt install chrony
2. 修改配置文件
sudo nano /etc/chrony/chrony.conf
添加如下行(仅保留一条 server):
server 192.168.x.x iburst # 改为你的主机 IP
makestep 1 3
3. 重启服务并启用开机自启
sudo systemctl restart chrony
sudo systemctl enable chrony
4. 验证同步结果
chronyc tracking
确认 Leap status 为 Normal,且时间偏差在 0.1 秒以内。
三、建图抖动消除建议
在 Cartographer 的 .lua
文件中添加:
lookup_transform_timeout_sec = 0.5
确保 .yaml
中 use_sim_time: false
,并开启 EKF 的 publish_tf: true
。
四、测试通过表现
- ros2 launch 无任何 extrapolation 报错
- rviz2 地图无抖动
- /tf 和 /scan 时间戳一致
- cartographer_node 日志正常,submap 插入稳定