8.1-roscomm详解

ROS 通信框架部分

TOC

参考

Wiki Page

前言

  • ROS,其实从本质上讲就是一个消息通信中间件,其最基础的功能就是在ros_common这个包中实现的,如消息,服务,控制台,roslaunch等等,在这里重点学习几个平时没有用到,但也非常重要的模块

记录

message_filters

基本概念

  • 集中处理多个消息来源的模块,或者说是进行消息同步的模块
    • 一个例子是time synchronizer,其将多个输入消息进行“过滤”(例如消息a,b),只输出消息a的timestamp下的b消息,即对消息b中的“无用”消息进行了“过滤”

基本代码

// 构造
FooFilter foo;
BarFilter bar(foo);//Bar的输入连接着foo的输出
bar.connectInput(foo);//等价
bar.registerCallback(myCallback);//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.
    • 使用一个回调函数同时处理多个消息,可以按照时间戳将不符合要求的消息丢弃,最多支持9通道,因为c++模板参数最多支持9个
#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;
}
  • 时间同步器现在还支持时间相近的时间戳的消息聚合处理,见后面的Policy-Based Synchronizer

Time Sequencer

  • The TimeSequencer filter guarantees that messages will be called in temporal order according to their header's timestamp. The TimeSequencer is constructed with a specific delay which specifies how long to queue up messages before passing them through. A callback for a message is never invoked until the messages' time stamp is out of date by at least delay. However, for all messages which are out of date by at least the delay, their callback are invoked and guaranteed to be in temporal order. If a message arrives from a time prior to a message which has already had its callback invoked, it is thrown away.
    • 简单讲,使得消息的回调函数调用能够按照固定时间间隔和按先后顺序执行,如果出现顺序混乱,则将此消息丢弃

Cache

  • 可以存储时间上最近的N个消息

Policy-Based Synchronizer

  • 基于某种策略的消息同步
    • 有两种同步:ExactTime和ApproximateTime

Chain

  • 可以将Filter连成一个链
    • 输出与下一个输入相连

ros_bag

  • 记录和重新播放消息数据的工具包,生成一个*.bag文件,此文件可以用Matlab进行解析,也可以在ROS系统中进行重新播放。
    • 详细情况见我的另外一篇播客

ros_graph

  • 进行画图的命令行工具包,在终端显示数据等
  • 使用python命令更好,包括:rostopic, rosnode, rosservice, rosparam

XmlRpc++

  • 是XML-RPC机制的C++实现,XmlRpc是远程过程调用的一种方式,不过更加简单一些,其使用XML作为数据交换格式,使用HTTP协议进行通信。
  • 所有IO都是非阻塞式的,所以网络状态不佳也不会拖慢服务端
原文地址:https://www.cnblogs.com/lizhensheng/p/11117683.html