多雷达时间同步(软同步)(速腾)

文章介绍了如何在项目实践中对8个速腾激光雷达(RS80和RSBP)进行软件时间同步,包括使用message_filters库的ApproximateTime策略,以及提供了一个C++代码示例来展示如何订阅和同步不同激光雷达的数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于项目实践需要,有8个速腾激光雷达(4个rs80和4个rsbp)需要时间同步。

常见的时间同步方式有两种:硬件同步和软件同步,硬件同步有PPS同步和PTP同步,同时在速腾激光雷达技术手册中通常推荐使用GPS的PPS信号进行同步,可参考如下博客和照片

Hesai激光雷达使用PTP时间同步_ptp master-CSDN博客

 由于设备已经安装好,故本文采用软件同步,具体步骤如下

1、录制激光雷达bag包,并查看各自扫描频率

rqt_bag <bag_name>

 

可以很明显的看到各激光雷达的发布频率相差还是很大的

2、写代码

sync.c如下

#include "sync.h"
subscriberANDpublisher::subscriberANDpublisher()
{
    // 订阅四个激光雷达话题
    lidar1_sub.subscribe(nh, "rs80_1/rslidar_points", 1);
    lidar2_sub.subscribe(nh, "rs80_2/rslidar_points2", 1);
    lidar3_sub.subscribe(nh, "rs80_3/rslidar_points3", 1);
    lidar4_sub.subscribe(nh, "rs80_4/rslidar_points4", 1);

    // 消息过滤器,使用 ApproximateTime 进行时间同步
    sync_.reset(new message_filters::Synchronizer<syncpolicy>(syncpolicy(10), lidar1_sub, lidar2_sub, lidar3_sub, lidar4_sub));
    sync_->registerCallback(boost::bind(&subscriberANDpublisher::callback, this, _1, _2, _3, _4));

    // 发布者
    lidar1_pub = nh.advertise<sensor_msgs::PointCloud2>("rs80_1/sync", 10);
    lidar2_pub = nh.advertise<sensor_msgs::PointCloud2>("rs80_2/sync", 10);
    lidar3_pub = nh.advertise<sensor_msgs::PointCloud2>("rs80_3/sync", 10);
    lidar4_pub = nh.advertise<sensor_msgs::PointCloud2>("rs80_4/sync", 10);
}

void subscriberANDpublisher::callback(const sensor_msgs::PointCloud2ConstPtr& pc1,
                                       const sensor_msgs::PointCloud2ConstPtr& pc2,
                                       const sensor_msgs::PointCloud2ConstPtr& pc3,
                                       const sensor_msgs::PointCloud2ConstPtr& pc4) {
    ROS_INFO("Received synchronized message!");
    lidar1_pub.publish(pc1);
    lidar2_pub.publish(pc2);
    lidar3_pub.publish(pc3);
    lidar4_pub.publish(pc4);
}

 sync.h如下

#ifndef SUB_AND_PUB_H
#define SUB_AND_PUB_H

#include <ros/ros.h>
#include <message_filters/subscriber.h>
#include <message_filters/sync_policies/approximate_time.h>
#include <message_filters/synchronizer.h>
#include <sensor_msgs/PointCloud2.h>

class subscriberANDpublisher{
public:
    subscriberANDpublisher();
    void callback(const sensor_msgs::ImageConstPtr &image,
                  const sensor_msgs::PointCloud2ConstPtr &lidar1,
                  const sensor_msgs::PointCloud2ConstPtr &lidar2,
                  const sensor_msgs::PointCloud2ConstPtr &lidar3,
                  const sensor_msgs::PointCloud2ConstPtr &lidar4);

private:
    ros::NodeHandle nh;
    ros::Publisher camera_pub;
    ros::Publisher lidar1_pub;
    ros::Publisher lidar2_pub;
    ros::Publisher lidar3_pub;
    ros::Publisher lidar4_pub;
    message_filters::Subscriber<sensor_msgs::PointCloud2> lidar1_sub;
    message_filters::Subscriber<sensor_msgs::PointCloud2> lidar2_sub;
    message_filters::Subscriber<sensor_msgs::PointCloud2> lidar3_sub;
    message_filters::Subscriber<sensor_msgs::PointCloud2> lidar4_sub;
    message_filters::Subscriber<sensor_msgs::Image> camera_sub;

    typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image,
                                                            sensor_msgs::PointCloud2,
                                                            sensor_msgs::PointCloud2,
                                                            sensor_msgs::PointCloud2,
                                                            sensor_msgs::PointCloud2> syncpolicy;
    typedef message_filters::Synchronizer<syncpolicy> Sync;
    boost::shared_ptr<Sync> sync_;

};

#endif

main.c如下

#include <ros/ros.h>
#include "sync.h"

 
int main(int argc, char **argv) {
    ros::init(argc, argv, "node");
    subscriberANDpublisher sp;
    ROS_INFO("main done! ");
    ros::spin();
}

3、测试程序

下图是时间同步前的消息发布时间

下图是调试过的

成功!

### 关于Volkswagen Sagitar Radar COCO 数据集的信息 COCO (Common Objects in Context) 是一个广泛用于目标检测、分割和其他计算机视觉任务的数据集。然而,在提到特定品牌车型如大众速腾(Volkswagen Sagitar) 的雷达数据集时,需要注意的是官方的 COCO 数据集中并没有专门针对某一汽车品牌的雷达数据集合[^1]。 通常情况下,涉及车辆传感器(包括但不限于摄像头、激光雷达LiDAR以及毫米波雷达)的数据集是由研究机构或企业自行采集并可能遵循通用的标准格式来标注这些多模态感知信息。如果存在某个特别面向大众速腾或其他具体型号车辆所配备之雷达系统的定制化版本,则更可能是某些专项科研项目或是车企内部资源而非公开可用的大规模公共数据源[^2]。 对于希望获取与车载雷达有关联性的高质量图像及标签资料的研究者来说,可以考虑探索其他已知的相关开源数据库: - **nuScenes**: 提供了来自多个不同城市环境下的自动驾驶场景记录,涵盖了丰富的传感器融合实例; - **Waymo Open Dataset**: 谷歌旗下Waymo公司发布的大型自驾车行驶日志片段,内含详尽的时间同步多视角影像和点云序列; - **BDD100K**: Berkeley DeepDrive团队整理的城市道路动态视频素材库,虽然主要侧重于视觉识别却也包含了部分关于交通参与者行为模式的知识补充[^3]。 ```python import json from pycocotools.coco import COCO def load_coco_dataset(annotation_file_path): """ 加载标准COCO格式的注解文件 参数: annotation_file_path (str): JSON格式的注解文件路径 返回: coco_api: PyCOCOTools中的API对象, 可用于查询类别、图片ID等操作. """ coco = COCO(annotation_file_path) return coco annotation_file = 'path_to_your_annotations/instances_val2017.json' coco_instance = load_coco_dataset(annotation_file) print(f"加载完成 {len(coco_instance.getImgIds())} 张图片.") ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值