联合标定三维雷达和IMU,第一步要先对齐两种传感信息的时间戳。

ros官网提供了message_filters用于对齐多种传感信息的时间戳。

http://wiki.ros.org/message_filters#Time_Synchronizer

注意,对齐传感信息时间戳有两种方式,一种是时间戳完全对齐 ExactTime Policy ,另一种是时间戳相近

ApproximateTime Policy ,前者更为严格。

msg_syn.h

#ifndef CLIMBING_ROBOT_GT_MAP_
#define CLIMBING_ROBOT_GT_MAP_ #include <string> #include <ros/ros.h>
#include <rosbag/bag.h>
#include <sensor_msgs/PointCloud2.h>
#include <geometry_msgs/PoseStamped.h> #include <message_filters/subscriber.h>
#include <message_filters/synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h> namespace climbing_robot
{ class MsgSynchronizer{
public:
MsgSynchronizer(ros::NodeHandle node);
~MsgSynchronizer(){}; void callback(const sensor_msgs::PointCloud2::ConstPtr& ori_pointcloud, const geometry_msgs::PoseStamped::ConstPtr& ori_pose); inline void CloseBag()
{
msg_syn_bag.close();
} private:
// ros::Publisher pubVelodyne;
// ros::Publisher pubImu;
std::string syn_bag_path;
rosbag::Bag msg_syn_bag;
}; }//namespace climbing_robot #endif// CLIMBING_ROBOT_GT_MAP_

msg_syn.cpp

#include "msg_syn.h"

#include <iostream>

namespace climbing_robot
{ MsgSynchronizer::MsgSynchronizer(ros::NodeHandle node)
{
// pubVelodyne = nh.advertise<sensor_msgs::PointCloud2>("/Syn/imu/data", 1); message_filters::Subscriber<geometry_msgs::PoseStamped> pose_sub(node, "/vrpn_client_node/RigidBody/pose", );
message_filters::Subscriber<sensor_msgs::PointCloud2> velodyne_sub(node, "/velodyne_points", ); typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::PointCloud2, geometry_msgs::PoseStamped> approximate_policy;
message_filters::Synchronizer<approximate_policy> sync(approximate_policy(), velodyne_sub, pose_sub);
sync.registerCallback(boost::bind(&MsgSynchronizer::callback, this, _1, _2)); node.getParam("msg_syn_bag_path", syn_bag_path);
msg_syn_bag.open(syn_bag_path, rosbag::bagmode::Write); ros::spin();
} void MsgSynchronizer::callback(const sensor_msgs::PointCloud2::ConstPtr& ori_pointcloud, const geometry_msgs::PoseStamped::ConstPtr& ori_pose)
{
ROS_INFO("pointcloud stamp value is: %f", ori_pointcloud->header.stamp.toSec());
ROS_INFO("pose stamp value is: %f", ori_pose->header.stamp.toSec()); // ros::Time timestamp = ori_pointcloud.header.stamp;
msg_syn_bag.write("/velodyne_points", ori_pointcloud->header.stamp, *ori_pointcloud);
msg_syn_bag.write("/vrpn_client_node/RigidBody/pose", ori_pointcloud->header.stamp, *ori_pose); // pubVelodyne.publish(syn_pointcloud);
} }//namespace climbing_robot

main.cpp

#include "msg_syn.h"

int main(int argc, char** argv)
{
ros::init(argc, argv, "msg_synchronizer");
ros::NodeHandle node("~");
ROS_INFO("\033[1;32m---->\033[0m Sync msgs node Started."); climbing_robot::MsgSynchronizer synchronizer(node); // ros::spin(); synchronizer.CloseBag(); return ;
}

非常注意2点:

A

sync.registerCallback(boost::bind(&mySynchronizer::callback, this, _1, _2));

由于callback函数是类内函数,所以要使用类内成员函数的写法;

加上this关键字;

参考:https://blog.csdn.net/Felaim/article/details/78212738#commentBox

B

ros::spin();  要放在订阅函数之后。如果放在主函数中,由于作用域的原因,会出现无法订阅/topic的错误。

参考:https://www.cnblogs.com/liu-fa/p/5925381.html

<ROS> message_filters 对齐多种传感器数据的时间戳的更多相关文章

  1. [ROS]一些传感器数据读取融合问题的思考

    思考问题: 1. 如何实现传感器数据的融合,或者说时间同步? 比如里程计读数和雷达数据融合? void SlamGMapping::startLiveSlam() { entropy_publishe ...

  2. 【AllJoyn专题】基于AllJoyn和Yeelink的传感器数据上传与指令下行的研究

    接触高通物联网框架AllJoyn不太久,但确是被深深地吸引了.在我看来,促进我深入学习的原因有三点:一.AllJoyn开源,对开源的软硬件总会有种莫名的喜爱,虽然或许不会都深入下去:二.顺应潮流,物联 ...

  3. python多种格式数据加载、处理与存储

    多种格式数据加载.处理与存储 实际的场景中,我们会在不同的地方遇到各种不同的数据格式(比如大家熟悉的csv与txt,比如网页HTML格式,比如XML格式),我们来一起看看python如何和这些格式的数 ...

  4. 基于uFUN开发板的心率计(一)DMA方式获取传感器数据

    前言 从3月8号收到板子,到今天算起来,uFUN到手也有两周的时间了,最近利用下班后的时间,做了个心率计,从单片机程序到上位机开发,到现在为止完成的差不多了,实现很简单,uFUN开发板外加一个Puls ...

  5. 云中树莓派(2):将传感器数据上传到 AWS IoT 并利用Kibana进行展示

    云中树莓派(1):环境准备 云中树莓派(2):将传感器数据上传到AWS IoT 并利用Kibana进行展示 1. 传感器安装及配置 1.1 DHT22 安装 DHT22 是一款温度与湿度传感器,它有3 ...

  6. C#关于时间(获取特定格式的时间及多种方式获取当前时间戳)以及10位和13位时间戳转为特定格式

    C#关于时间(获取特定格式的时间及多种方式获取当前时间戳)以及10位和13位时间戳转为特定格式 置顶 2018年03月06日 19:16:51 黎筱曦 阅读数:19098 标签: C#时间 更多 个人 ...

  7. STC15系列通用-STC15F2K60S2/STCW4K32S4读取DHT11温湿度传感器数据串口输出代码实例工程免费下载

    //为了方便大家调试,另附程序工程共大家下载,下载地址:https://www.90pan.com/b1908750 ​ //************************** //程序说明:stc ...

  8. [转]ROS中使用message_filters进行多传感器消息同步

    转:http://www.rosclub.cn/post-1030.html 最近实验室老师在做一个多传感器数据采集实验,涉及到了消息同步.所以就学习了ROS官网下的消息同步工具message_fil ...

  9. ros学习笔记 - 深度传感器转换成激光数据(hector_slam)

    前提条件:1,确保读者已经安装了kinect或者其他深度摄像头的驱动,如果未安装,可以直接在网盘下载:http://pan.baidu.com/s/1hqHB10w 提取密码:wrmn 利用深度相机仿 ...

随机推荐

  1. 18-09-09 Linux 系统如何获取外部的数据例如 软件的2中方式

    方式一 利用U盘  手动挂载/卸载 U盘==========================================1, cat /proc/partitions查看U盘插入前后, 多出的 s ...

  2. vue启动报错

    在安装依赖后,启动时报错 修复方法:将项目node_modules文件夹删除掉,重新cnpm install即可

  3. DELL H730P写策略write-through和write-back配置说明

    write-through 数据在写入存储的同时,要写入缓存,这种方式安全但是会牺牲写性能,因为只有等数据完全落入硬盘后,才算是一次io完成,这个过程会造成cpu的iowait. write-back ...

  4. css-改变input原始样式

    1.改变input的提示字位置 input::-webkit-input-placeholder { /* placeholder颜色 */ color: #aab2bd; /* placeholde ...

  5. IDEA 编译时 报 “常量字符串过长” 解决办法

    从eclipse 工具转到 IDEA 工具的时候,出现了一些问题,在这里记录一下,以便之后使用到,废话不多说. 在编译项目时,出现错误为:"常量字符串过长" ,我当时想这个问题需要 ...

  6. WEB学习笔记4-前端代码基本命名规法和格式规范

    1.HTML命名规范及格式规范 标签名和属性应该都小写,虽然HTML代码不区分大小写:属性值应该用双引号闭合. <IMG src=demo.jpg alt='test'/>(N) < ...

  7. react native 键盘弹起时必须点击两次才能成功

    在scrollview或者flatlist上设置一个参数,即可解决 keyboardShouldPersistTaps="handled"

  8. Day1-浅谈接口测试

    1.接口测试的定义:从数据库里面取数据,插入数据,把前段和后端联系起来: 2.接口测试的必要性: 1)前端未开发好,但是接口已开发 2)页面上测不了的,可以通过接口来测试 3.接口测试需要注意: 1) ...

  9. 改变highCharts的X轴和Y轴的数据刻度

    xAxis:{ tickPixelInterval:10 //自行调整X轴刻度的间距}, yAxis:{ lineWidth:1, //Y轴默认不显示Y轴线,添加一个轴线的宽度就可以显示出来 tick ...

  10. Layer弹出层销毁问题

    Layer弹出层销毁问题 最近开发时有个问题记录一下 点击按钮显示相应的图表信息,当时自己点感觉没问题,谁知到测试手里多次点击就会有后续打开的窗口无法渲染问题,看了半天才发现是调用layer.clos ...