ros多传感器融合

2023-05-16

转:http://www.rosclub.cn/post-1030.html
最近实验室老师在做一个多传感器数据采集实验,涉及到了消息同步。所以就学习了ROS官网下的消息同步工具message_filters。 http://wiki.ros.org/message_filters 消息同步有两种方式,暂且称之为松同步与紧同步,紧同步是精确的同步,松同步是粗略的同步。我使用的是C++下的松同步我的代码如下:#include <message_filters/subscriber.h> #include <message_filters/synchronizer.h> #include <message_filters/sync_policies/approximate_tim

最近实验室老师在做一个多传感器数据采集实验,涉及到了消息同步。所以就学习了ROS官网下的消息同步工具message_filters。
http://wiki.ros.org/message_filters
消息同步有两种方式,暂且称之为松同步与紧同步,紧同步是精确的同步,松同步是粗略的同步。我使用的是C++下的松同步我的代码如下:

#include <message_filters/subscriber.h>
#include <message_filters/synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/PointCloud2.h>
#include <sensor_msgs/LaserScan.h>
#include "image_transport/image_transport.h"
#include "sensor_msgs/CompressedImage.h"
#include "ros/ros.h"
#include "sensor_msgs/Imu.h"
#include "nav_msgs/Odometry.h"
#include "sensor_msgs/CameraInfo.h"
#include "rosbag/bag.h"
#include "ctime"
#include "time.h"
/*
ros::Publisher Velodyne_pub;
ros::Publisher Hokuyo_pub;
ros::Publisher Ominivision_pub;
ros::Publisher Kinect2color_pub;
ros::Publisher Kinect2depth_pub;
ros::Publisher Imu_pub;
ros::Publisher Odom_pub;
ros::Publisher Kinect2camera_info_pub;*/
rosbag::Bag bag_record;
using namespace std;
string int2string(int value)
{
    stringstream ss;
    ss<<value;
    return ss.str();
}
 
void callback(const sensor_msgs:: PointCloud2ConstPtr& point_cloud2,
              const sensor_msgs::LaserScan::ConstPtr& laser_scan,
              const sensor_msgs::CompressedImageConstPtr& ominivision_msg,
              const sensor_msgs::CompressedImageConstPtr& kinect2color_msg,
              const sensor_msgs::CompressedImageConstPtr&kinect2depth_msg,
              const sensor_msgs::ImuConstPtr& imu_msg,
              const nav_msgs::OdometryConstPtr& odom_msg)
{
    ROS_INFO("Enter Publish");
 
    bag_record.write("message_filter/velodyne_points",point_cloud2->header.stamp.now(),*point_cloud2);
    bag_record.write("message_filter/scan",laser_scan->header.stamp.now(),*laser_scan);
    bag_record.write("message_filter/camera/compressed",ominivision_msg->header.stamp.now(),*ominivision_msg);
    bag_record.write("message_filter/kinect2/qhd/image_color_rect/compressed",laser_scan->header.stamp.now(),*kinect2color_msg);
    bag_record.write("message_filter/kinect2/qhd/image_depth_rect/compressed",laser_scan->header.stamp.now(),*kinect2depth_msg);
    bag_record.write("message_filter/imu/data",imu_msg->header.stamp.now(),*imu_msg);
    bag_record.write("message_filter/odom",odom_msg->header.stamp.now(),*odom_msg);
 
}
int main(int argc, char** argv)
{
  ros::init(argc, argv, "message_filter_node");
  ros::Time::init();
  ros::NodeHandle nh;
  ROS_INFO("start message filter");
  time_t t=std::time(0);
  struct tm * now = std::localtime( & t );
  string file_name;
  //the name of bag file is better to be determined by the system time
  file_name=int2string(now->tm_year + 1900)+
          '-'+int2string(now->tm_mon + 1)+
          '-'+int2string(now->tm_mday)+
          '-'+int2string(now->tm_hour)+
          '-'+int2string(now->tm_min)+
          '-'+int2string(now->tm_sec)+
            ".bag";
  bag_record.open(file_name,rosbag::bagmode::Write);
  message_filters::Subscriber<sensor_msgs::PointCloud2> Velodyne_sub(nh, "/velodyne_points", 1);//订阅16线激光雷达Topic
  message_filters::Subscriber<sensor_msgs::LaserScan> Hokuyo_sub(nh,"/scan" , 1);//订阅平面激光雷达Topic
  message_filters::Subscriber<sensor_msgs::CompressedImage> ominivision_sub(nh,"/camera/image_raw/compressed" , 1);//订阅全向视觉Topic
  message_filters::Subscriber<sensor_msgs::CompressedImage> kinect2color_sub(nh,"/kinect2/qhd/image_color_rect/compressed" , 1);//订阅Kinect的Topic
  message_filters::Subscriber<sensor_msgs::CompressedImage> kinect2depth_sub(nh,"/kinect2/qhd/image_depth_rect/compressed" , 1);//订阅Kinect的Topic
  message_filters::Subscriber<sensor_msgs::Imu> imu_sub(nh,"/imu/data" , 1);//订阅imu的Topic
  message_filters::Subscriber<nav_msgs::Odometry> odom_sub(nh,"/odom" , 1);//订阅里程计的Topic
 
  typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::PointCloud2,
          sensor_msgs::LaserScan,
          sensor_msgs::CompressedImage,
          sensor_msgs::CompressedImage,
          sensor_msgs::CompressedImage,
          sensor_msgs::Imu,
          nav_msgs::Odometry> MySyncPolicy;
  // ApproximateTime takes a queue size as its constructor argument, hence MySyncPolicy(10)
  message_filters::Synchronizer<MySyncPolicy> sync(MySyncPolicy(20),
                                                   Velodyne_sub,
                                                   Hokuyo_sub,
                                                   ominivision_sub,
                                                   kinect2color_sub,
                                                   kinect2depth_sub,
                                                   imu_sub,
                                                   odom_sub);
  sync.registerCallback(boost::bind(&callback, _1, _2, _3, _4, _5, _6, _7));
  ros::spin();
  bag_record.close();
  return 0;
}

这个框架直接拿出来就能用,同步过后的message会自动进入callback函数,之前把它封装成类结果一直跑不通,因为其中有些句柄当作了局部变量,这一点需要注意。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ros多传感器融合 的相关文章

  • 该不该放弃嵌入式,单片机这条路?

    本文几乎浓缩了我从业10几年的精华 xff0c 内容 涵盖我转行 打工 创业的经历 建议从头到尾不要错过一字一句 xff0c 因为字里行间的经验之谈 xff0c 或许能成为你人生重要转折点 全文 3700 多字 xff0c 写了 6 个多小
  • 集成学习(Ensemble Learning)

    集成学习Ensemble Learning Ensemble LearningDefinitionCommon types of ensemblesBootstrap aggregating Bagging BoostingStacking
  • 入住CSDN第一天

    对CSDN的个人看法 缺点 其实我对CSDN不感冒 xff0c 因为多年来一直在 简述 上面编写自己的博客 xff0c hexo 搭建个人博客 我对哪些必须扫码注册登录才能看复制 xff0c 必须花钱充钱才能下载资源的平台表示不喜欢 CSD
  • 前端技术文档

    前端技术大纲 首先声明需要CSS xff0c html xff0c xff08 js xff09 技术可不不用太深但是必须会一点 1 vue vueCDNvue Clivue routervue loadervue api 所有方法vue
  • 英雄手游版教程

    Android教程 百度搜索 ourplay 翻墙注册 Google 或者 拳头 或者 facebook 账号启动游戏 IOS教程 下载加速器个人推荐 迅雷 因为其他的都要收费搜索下载英雄联盟启动游戏
  • vue component

    component Vue component 39 todoItem 39 template 96 lt p gt 这是一个代办项 lt p gt 96 lt div gt lt todo ttem gt lt div gt 当vue实例
  • vue监听对象的用法

    watch监听对象 data return obj name 34 JackMe 34 watch 39 obj 39 handler newValue oldValue console log newValue name oldValue
  • VSCODE无法使用cnpm

    这里写自定义目录标题 简单暴力 简单暴力 1 xff0c 右击VSCode图标 xff0c 选择以管理员身份运行 xff1b 2 xff0c 在终端中执行get ExecutionPolicy xff0c 显示Restricted xff0
  • Win10环境下不同版本WinGW切换

    因需要 xff0c 安装了不同版本的WinGW gcc xff0c 实际使用中遇到一些问题 xff0c 解决过程记录如下 xff1a 在使用BusMaster时需要4 8 1版本 xff0c 原本系统默认9 2 0 xff0c busmas
  • 【无标题】

    这里写自定义目录标题 欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题 xff0c 有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中 居左 居右SmartyP
  • expo优势

    优点一 xff1a 一条命令生成apk或者ipa文件 xff0c 方便发布到应用商店 优点二 xff1a 代码publish xff0c 应用内热更新 优点三 xff1a 比react native多出不少实用原生组件 xff0c 比如一些
  • C++一些常见问题

    关于赋值的疑问 1 编译器为每个类默认重载了赋值操作符 xff1b 2 默认的赋值操作符仅完成了浅拷贝 xff1b 3 当需要进行深拷贝时必须重载赋值操作符 xff1b 4 赋值操作符与拷贝构造函数有相同的存在意义 实例分析 xff1a s
  • 树莓派学习(二):更换镜像源以及安装虚拟环境miniforge3

    树莓派学习 xff08 二 xff09 xff1a 更换镜像源以及安装pytorch 步骤一 xff1a 更换镜像源步骤二 xff1a 下载前的准备2 1 原来numpy库的卸载 步骤三 xff1a 安装miniforge3 步骤一 xff
  • 3.1 python版MapReduce基础实战

    输入文件在你每次点击评测的时候 xff0c 平台会为你创建 xff0c 无需你自己创建 xff0c 只需要启动HDFS xff0c 编写python代码即可 第1关 xff1a 成绩统计 mapper py usr bin python3
  • 怎么获取li里面的内容

    获取li的内容 span class token tag span class token tag span class token punctuation lt span ul span span class token punctuat
  • 偏移量的概念

    span class token selector span span class token punctuation span span class token property padding span span class token
  • js中的二级联动

    省份市级城市联动 span class token doctype lt DOCTYPE html gt span span class token tag span class token tag span class token pun
  • 页面跳转的几种方法

    location对象 href assgin跳转到另一个页面可以返回到原来的页面 location span class token punctuation span href span class token operator 61 sp
  • 学习JS基础部分一

    数据类型 分支结构 循环结构 数据类型 简单数据类默认值Number0BooleanfalseString Undefinedundefinednullnull 复杂数据类型默认值Array Object 分支结构 分支语句说明if 条件
  • 来,带你见识一下CT三维重建

    文 xff1a 北京协和医院放射科孙昊 来源 xff1a 从医开始 xff0c 协和八的奇妙临床笔记 相信各位同学在临床工作中 xff0c 已经接触到很多CT三维重建的图像了 xff0c 那么CT三维重建到底是个啥东东 xff1f 这个问题

随机推荐