资讯详情

激光、摄像头、IMU等传感器数据同步方法(message_filters)

本文介绍了一种软同步法,即算法同步法,如果要进行硬件同步,请参阅论文:VersaVIS—An Open Versatile Multi-Camera Visual-Inertial Sensor Suite(似乎有源码)。

message_filters有两种同步策略,一种是时间戳完全对齐的策略(ExactTime Policy),另一种是时间戳相似的策略(ApproximateTime Policy)。

下面是C 如果要使用同步策略框架代码(根据自己的需要更改),可以同步多个传感器数据。python代码,可以查阅ros官网。

:创建ros注意加包message_filters,类似于roscpp、sensor_msgs等

ExactTime Policy

message_filters :: sync_policies :: ExactTime战略要求新闻有完全相同的时间戳来匹配。 只有在所有具有相同确切时间戳的指定通道上收到消息时,才会调用回调。

#include <message_filters/subscriber.h> #include <message_filters/synchronizer.h> #include <message_filters/sync_policies/exact_time.h> #include <sensor_msgs/Image.h> #include <sensor_msgs/CameraInfo.h>  using namespace sensor_msgs; using namespace message_filters;  void callback(const ImageConstPtr& image, const CameraInfoConstPtr& cam_info) { 
           // Solve all of perception here... }  int main(int argc, char** argv) { 
           ros::init(argc, argv, "vision_node");    ros::NodeHandle nh;   message_filters::Subscriber<Image> image_sub(nh, "image", 1);///同步接收数据   message_filters::Subscriber<CameraInfo> info_sub(nh, "camera_info", 1);    typedef sync_policies::ExactTime<Image, CameraInfo> MySyncPolicy;   // ExactTime takes a queue size as its constructor argument, hence MySyncPolicy(10)   Synchronizer<MySyncPolcy> sync(MySyncPolicy(10), image_sub, info_sub);
  sync.registerCallback(boost::bind(&callback, _1, _2));

  ros::spin();

  return 0;
}

ApproximateTime Policy

message_filters :: sync_policies :: ApproximateTime策略使用自适应算法来匹配基于其时间戳的消息。

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

using namespace sensor_msgs;
using namespace message_filters;

void callback(const ImageConstPtr& image1, const ImageConstPtr& image2)
{ 
        
  // Solve all of perception here...
}

int main(int argc, char** argv)
{ 
        
  ros::init(argc, argv, "vision_node");

  ros::NodeHandle nh;
  message_filters::Subscriber<Image> image1_sub(nh, "image1", 1);
  message_filters::Subscriber<Image> image2_sub(nh, "image2", 1);

  typedef sync_policies::ApproximateTime<Image, Image> MySyncPolicy;
  // ApproximateTime takes a queue size as its constructor argument, hence MySyncPolicy(10)
  Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), image1_sub, image2_sub);
  sync.registerCallback(boost::bind(&callback, _1, _2));

  ros::spin();

  return 0;
}

参考:

http://wiki.ros.org/message_filters https://www.cnblogs.com/qiuheng/p/9254557.html

标签: exact传感器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

 锐单商城 - 一站式电子元器件采购平台  

 深圳锐单电子有限公司