ROS消息过滤器 ( message_filters)

参考地址: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++例子如下

FooFilter foo;
BarFilter bar(foo);
或者:

FooFilter foo;
BarFilter bar;
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>&)

例子:

message_filters::Subscriber<std_msgs::UInt32> sub(nh, "my_topic", 1);
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:

#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.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);
  TimeSynchronizer<Image, CameraInfo> sync(image_sub, info_sub, 10);
  sync.registerCallback(boost::bind(&callback, _1, _2));

  ros::spin();

  return 0;
}


(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. 十分感谢

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值