用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/MIUAV/vibe-coding-ros2 --skill multi-sensor-timesync命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | multi-sensor-timesync |
| description | 多传感器时间同步技能 - 硬件同步、软同步、NTP、ROS2 时间同步 |
| argument-hint | 时间同步 OR hardware sync OR NTP OR timesync |
| user-invocable | true |
多传感器时间同步方案
当需要以下帮助时使用此技能:
# 硬件同步配置 (激光雷达 + 相机)
hardware_config:
lidar:
model: Velodyne VLP-16
mode: phase_lock # 相位锁定
sync_frequency: 10 # Hz
phase_offset: 0.0 # 秒
camera:
model:_basalt
trigger_mode: hardware_external
trigger_delay: 0.002 # 2ms 硬件延迟
gps_imu:
model: XSens MTi
sync_mode: time_ins
import rclpy
from rclpy.node import Node
from message_filters import Subscriber, ApproximateTimeSynchronizer
from sensor_msgs.msg import Image, PointCloud2, Imu
from geometry_msgs.msg import PoseWithCovarianceStamped
class MultiSensorSyncNode(Node):
def __init__(self):
super().__init__('multi_sensor_sync')
# 创建同步订阅
self.image_sub = Subscriber(self, Image, '/camera/image_raw')
self.lidar_sub = Subscriber(self, PointCloud2, '/lidar/points')
self.imu_sub = Subscriber(self, Imu, '/imu/data')
self.gps_sub = Subscriber(self, PoseWithCovarianceStamped, '/gps/pose')
# 时间同步器
self.sync = ApproximateTimeSynchronizer(
[self.image_sub, self.lidar_sub, self.imu_sub],
queue_size=20,
slop=0.05 # 50ms 容差
)
self.sync.registerCallback(self.sync_callback)
def sync_callback(self, image, lidar, imu):
stamp = image.header.stamp
.process_data(image, lidar, imu)
import numpy as np
class TimeSynchronizer:
"""软件时间同步"""
def __init__(self, buffer_size=10):
self.buffer_size = buffer_size
self.timestamps = {
'camera': [],
'lidar': [],
'imu': []
}
self.offsets = {
'lidar_camera': 0.0,
'imu_camera': 0.0
}
def add_timestamp(self, sensor, stamp):
"""添加时间戳"""
self.timestamps[sensor].append(stamp)
if len(self.timestamps[sensor]) > self.buffer_size:
self.timestamps[sensor].pop(0)
# 估计偏移
self.estimate_offset()
def estimate_offset(self):
"""估计传感器间时间偏移"""
# 互相关估计
for s1, s2 in [('lidar', 'camera'), ('imu', 'camera')]:
if len(self.timestamps[s1]) > 5 (.timestamps[s2]) > :
offset = .compute_offset(
.timestamps[s1],
.timestamps[s2])
.offsets[] = offset
():
diffs = []
t1 times1:
closest = (times2, key= t2: (t2 - t1))
diffs.append(t1 - closest)
np.median(diffs)
():
sensor == :
stamp - .offsets[]
sensor == :
stamp - .offsets[]
stamp
# 配置 PTP (Precision Time Protocol)
# 交换机需要支持 PTP
# 查看网卡是否支持 PTP
ethtool -T eth0
# 启用 PTP
sudo ptp4l -i eth0 -m &