学习链接:http://wiki.ros.org/message_filters

message_filters

  • A message filter is defined as something which a message arrives into and may or may not be spit back out of at a later point in time.
  • time synchronizer ---------------------the same timestamp.

Filter Pattern

  • Outputs are connected through the registerCallback() method

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.

Connections

  • Input

No input connections

  • Output

C++: void callback(const boost::shared_ptr&) Python: callback(msg)

Example (C++)

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

相当于

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

Time Synchronizer

  • 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.

  • TimeSynchronizer filter通过header 中包含的时间戳来同步 incoming channels,并以单个回调函数的形式输出,该回调函数需要相同数量的通道。C++的实现最多可以同步9个通道。

Connections

Input

C++: Up to 9 separate filters, each of which is of the form void callback(const boost::shared_ptr&). 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&, …, const boost::shared_ptr&). The number of parameters is determined by the number of template arguments the class was created with. Python: callback(msg0… msgN). The number of parameters is determined by the number of template arguments the class was created with.

Example (C++)

#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;
}

Cache

Stores a time history of messages.

Given a stream of messages, the most recent N messages are cached in a ring buffer, from which time intervals of the cache can then be retrieved by the client. The timestamp of a message is determined from its header field.
If the message type doesn’t contain a header, see below for workaround.
The Cache immediately passes messages through to its output connections.

Connections

Input

C++: void callback(const boost::shared_ptr&) Python: callback(msg)

Output

C++: void callback(const boost::shared_ptr&) Python: callback(msg)

In C++:

message_filters::Subscriber<std_msgs::String> sub(nh, "my_topic", 1);
message_filters::Cache<std_msgs::String> cache(sub, 100);
cache.registerCallback(myCallback);

In this example, the Cache stores the last 100 messages received on my_topic, and myCallback is called on the addition of every new message. The user can then make calls like cache.getInterval(start, end) to extract part of the cache.

If the message type does not contain a header field that is normally used to determine its timestamp, and the Cache is contructed with allow_headerless=True, the current ROS time is used as the timestamp of the message. This is currently only available in Python.

Policy-Based Synchronizer [ROS 1.1+]

The Synchronizer 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.

The Synchronizer filter is templated on a policy that determines how to synchronize the channels. There are currently two policies: ExactTime and ApproximateTime.

Connections

Input

C++: Up to 9 separate filters, each of which is of the form void callback(const boost::shared_ptr&). 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&, …, const boost::shared_ptr&). The number of parameters is determined by the number of template arguments the class was created with. Python: callback(msg0… msgN). The number of parameters is determined by the number of template arguments the class was created with.

ExactTime Policy

  • The message_filters::sync_policies::ExactTime policy requires messages to have exactly the same timestamp in order to match.
  • message_filters::sync_policies::ExactTime 要求message的时间戳必须相同
  • 所有channels的具有相同时间戳的message都接收到
  • Example (C++)
#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<MySyncPolicy> sync(MySyncPolicy(10), image_sub, info_sub);sync.registerCallback(boost::bind(&callback, _1, _2));ros::spin();return 0;
}

ApproximateTime Policy

  • The message_filters::sync_policies::ApproximateTime policy uses an adaptive algorithm to match messages based on their timestamp.
    If not all messages have a header field from which the timestamp could be determined, see below for a workaround.

  • C++ Header: message_filters/sync_policies/approximate_time.h

  • Example (C++)

#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;
}

If some messages are of a type that doesn’t contain the header field, ApproximateTimeSynchronizer refuses by default adding such messages. However, its Python version can be constructed with allow_headerless=True, which uses current ROS time in place of any missing header.stamp field:

import message_filters
from std_msgs.msg import Int32, Float32def callback(mode, penalty):# The callback processing the pairs of numbers that arrived at approximately the same timemode_sub = message_filters.Subscriber('mode', Int32)
penalty_sub = message_filters.Subscriber('penalty', Float32)ts = message_filters.ApproximateTimeSynchronizer([mode_sub, penalty_sub], 10, 0.1, allow_headerless=True)
ts.registerCallback(callback)
rospy.spin()

message_filters::sync::ApproximateTime 重点关注

  • 它能匹配具有不同时间戳的messages
  • 我们把一组messages的size表示这组最早最晚时间戳的差值
  • 它允许在某个epsilon时间差进行匹配, 与 ExactTime 不同
  • 它满足这些特性:
  1. 参数,不用指定epsilon时间差。可以提一些可选参数。
  2. messages 只能被使用一次,两个组中不能共享message. 一些message可能被丢弃
  3. 集合不交叉,都是一整段时间
  4. 集合是连续的,集合之间没有空余的message
  5. Sets are of minimal size among the sets contiguous to the previous published set. (没理解)
  6. 输出只取决于时间戳,而不是message到达的时间
  • 可选择的参数
    (剩下的详情见原网页吧,我暂时用不到了)请点击链接

message_filters学习笔记相关推荐

  1. ROS学习笔记之——机器人航向角的求解

    最近在做项目的时候,需要测量移动机器人的航向角,为此写下本博文,来作为学习笔记.本博文的主要内容来自于网上的各种资料,并附上参考链接. 目录 四元数 欧拉角 轴角 四元数(Quaternion)的定义 ...

  2. PyTorch 学习笔记(六):PyTorch hook 和关于 PyTorch backward 过程的理解 call

    您的位置 首页 PyTorch 学习笔记系列 PyTorch 学习笔记(六):PyTorch hook 和关于 PyTorch backward 过程的理解 发布: 2017年8月4日 7,195阅读 ...

  3. 容器云原生DevOps学习笔记——第三期:从零搭建CI/CD系统标准化交付流程

    暑期实习期间,所在的技术中台-效能研发团队规划设计并结合公司开源协同实现符合DevOps理念的研发工具平台,实现研发过程自动化.标准化: 实习期间对DevOps的理解一直懵懵懂懂,最近观看了阿里专家带 ...

  4. 容器云原生DevOps学习笔记——第二期:如何快速高质量的应用容器化迁移

    暑期实习期间,所在的技术中台-效能研发团队规划设计并结合公司开源协同实现符合DevOps理念的研发工具平台,实现研发过程自动化.标准化: 实习期间对DevOps的理解一直懵懵懂懂,最近观看了阿里专家带 ...

  5. 2020年Yann Lecun深度学习笔记(下)

    2020年Yann Lecun深度学习笔记(下)

  6. 2020年Yann Lecun深度学习笔记(上)

    2020年Yann Lecun深度学习笔记(上)

  7. 知识图谱学习笔记(1)

    知识图谱学习笔记第一部分,包含RDF介绍,以及Jena RDF API使用 知识图谱的基石:RDF RDF(Resource Description Framework),即资源描述框架,其本质是一个 ...

  8. 计算机基础知识第十讲,计算机文化基础(第十讲)学习笔记

    计算机文化基础(第十讲)学习笔记 采样和量化PictureElement Pixel(像素)(链接: 采样的实质就是要用多少点(这个点我们叫像素)来描述一张图像,比如,一幅420x570的图像,就表示 ...

  9. Go 学习推荐 —(Go by example 中文版、Go 构建 Web 应用、Go 学习笔记、Golang常见错误、Go 语言四十二章经、Go 语言高级编程)

    Go by example 中文版 Go 构建 Web 应用 Go 学习笔记:无痕 Go 标准库中文文档 Golang开发新手常犯的50个错误 50 Shades of Go: Traps, Gotc ...

  10. MongoDB学习笔记(入门)

    MongoDB学习笔记(入门) 一.文档的注意事项: 1.  键值对是有序的,如:{ "name" : "stephen", "genda" ...

最新文章

  1. GIT之git及git服务搭建
  2. 20、30、40岁年轻人,2020年的建议 转载
  3. Spring Cloud(二) 配置Eureka Client
  4. 同级选择器_基础选择器
  5. oracle linux 双机,oracleforlinux双机热备实战完全手册
  6. VBA之EXCEL删除和设置单元格行高等
  7. Win10如何屏蔽删除电脑右下角的广告
  8. 计算机网络链接的主要目标 主要功能,计算机网络课程教案‌.doc
  9. 资源放送丨《Oracle存储过程性能分析案例》PPT视频
  10. SpringBoot使用外置的Servlet容器
  11. 虚拟机如何配置网络ip地址_木杉入门Elasticsearch(2):虚拟机IP地址配置
  12. 随想录(elf文件)
  13. 宝可梦推出「电子鸡」新游戏 训练师赶紧将可爱伊布带回家!
  14. 【python笔记】选择结构:if语句详解
  15. 【Java程序设计】图形用户界面(一)
  16. CICD详解(六)——SVN+Jenkins项目控制实战
  17. python的menu_Python Tkinter Menu使用教程 | 學步園
  18. 游戏服务器架构通识 BigWorlds丨skynet
  19. 自己封装特定的Windows系统镜像
  20. 八大古都大排名(权威版)

热门文章

  1. 富爸爸穷爸爸第二章的思考
  2. 小程序之botton默认带边框的问题
  3. 深度学习之学习(3-4)YOLOV4
  4. 程序开发心理学第四篇
  5. 荆棘鸟(The Thorn bird)
  6. 【市场调查与预测】廊坊师范学院大学生洗发水使用情况调查(课程论文)
  7. MBR10200FAC-ASEMI肖特基二极管MBR10200FAC
  8. 中国大学mooc java_中国大学mooc2020年Java程序设计答案大全
  9. 生前个个说恩深,死后人人欲扇魂。画虎画皮难画骨,知人知面不知心。
  10. 高科技还是“智商税”?你怎么选