当前位置:   article > 正文

ROS消息过滤器 ( message_filters)_message filter 的原理

message filter 的原理

参考地址:http://wiki.ros.org/message_filters

1.概述

message_filter是roscpp和rospy的一个应用库,他集中了一些滤波算法中常用的一些消息。当一个消息到来,在之后的一个时间点,该消息可能被返回或者不返回,将这样的一个过程或者容器理解为消息滤波器。

一个典型的例子就是时间同步器,他从多个数据源采集不同类型的数据,只有每个消息源的消息具体有相同的时间戳时候,他才将信息发布出去。

时间同步装置的一个例子:输入不同类型(type)的多个数据(source),但是仅当接收到的每个数据(source)有相同的时间戳(timestamp),才会有输出(output)。

2. 滤波模式

所有的消息滤波器服从相同的模式,用于连接输入和输出。输入通过滤波器的构造器或者connectInput()的方法连接。输出通过registerCallback()方法连接。

需要注意的是,每个滤波器各自定义输入输出的类型,所以并不是所有的滤波器可以直接互联。

例如:给了两个filters FooFilter 和 BarFilter,其中FooFilter的output和BarFilter的输入数据一致。连接foo和bar的C++例子如下

  1. FooFilter foo;
  2. BarFilter bar(foo);
或者:

  1. FooFilter foo;
  2. BarFilter bar;
  3. bar.connectInput(foo);

2.1 registerCallback()

你可以采用registerCallback()方法,注册多个回调函数。他们将按照注册顺序进行函数的回调。

3 订阅器Subscriber

The  Subscriber  filter is simply a wrapper around a ROS subscription that provides a source for other filters. The Subscriber  filter cannot connect to another filter's output, instead it uses a ROS topic as its input.

3.1 连接

输入:没有输入连接

输出:void callback(const boost::shared_ptr<M const>&)

例子:

  1. message_filters::Subscriber<std_msgs::UInt32> sub(nh, "my_topic", 1);
  2. sub.registerCallback(myCallback);


is the equivalent of:

ros::Subscriber sub = nh.subscribe("my_topic", 1, myCallback);

4. 时间一致器

The TimeSynchronizer filter synchronizes incoming channels by the timestamps contained in their headers, and outputs them in the form of a single callback that takes the same number of channels. The C++ implementation can synchronize up to 9 channels.

Connections

Input

  • C++: Up to 9 separate filters, each of which is of the form void callback(const boost::shared_ptr<M const>&). The number of filters supported is determined by the number of template arguments the class was created with.

    Python: N separate filters, each of which has signature callback(msg).

Output

  • C++: For message types M0..M8,void callback(const boost::shared_ptr<M0 const>&, ..., const boost::shared_ptr<M8 const>&). The number of parameters is determined by the number of template arguments the class was created with.

    Pythoncallback(msg0.. msgN). The number of parameters is determined by the number of template arguments the class was created with.

Example (C++)

Suppose you are writing a ROS node that needs to process data from two time synchronized topics. Your program will probably look something like this:

  1. #include <message_filters/subscriber.h>
  2. #include <message_filters/time_synchronizer.h>
  3. #include <sensor_msgs/Image.h>
  4. #include <sensor_msgs/CameraInfo.h>
  5. using namespace sensor_msgs;
  6. using namespace message_filters;
  7. void callback(const ImageConstPtr& image, const CameraInfoConstPtr& cam_info)
  8. {
  9. // Solve all of perception here...
  10. }
  11. int main(int argc, char** argv)
  12. {
  13. ros::init(argc, argv, "vision_node");
  14. ros::NodeHandle nh;
  15. message_filters::Subscriber<Image> image_sub(nh, "image", 1);
  16. message_filters::Subscriber<CameraInfo> info_sub(nh, "camera_info", 1);
  17. TimeSynchronizer<Image, CameraInfo> sync(image_sub, info_sub, 10);
  18. sync.registerCallback(boost::bind(&callback, _1, _2));
  19. ros::spin();
  20. return 0;
  21. }


(Note: In this particular case you could use the CameraSubscriber class from image_transport, which essentially wraps the filtering code above.)

参考:http://blog.csdn.net/fana8010/article/details/23880067. 十分感谢

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/813953
推荐阅读
相关标签
  

闽ICP备14008679号