ROS中message的相关知识点

这里从官方文档做一些整理,以备后续查看。

msg的定义不用说了,这里说说msg在ros相关项目中实现的东西。

1. msg overview

ROS uses a simplified messages description language for describing the data values (aka messages) that ROS nodes publish. This description makes it easy for ROS tools to automatically generate source code for the message type in several target languages. Message descriptions are stored in .msg files in the msg/ subdirectory of a ROS package.

(这一段告诉我们msg文件的路径)

There are two parts to a .msg file: fields and constants. Fields are the data that is sent inside of the message. Constants define useful values that can be used to interpret those fields (e.g. enum-like constants for an integer value).(msg文件的格式)

Message types are referred to using package resource names. For example, the file geometry_msgs/msg/Twist.msgis commonly referred to as geometry_msgs/Twist.(注:这里很重要,大部分头文件都会以后者作为名称,而非前者)

详见:http://www.ros.org/wiki/msg

2. msg generation

Like all ROS Client Libraries, roscpp takes msg files and generates C++ source code for them. The pattern for this is:

  • package_name/msg/Foo.msg → package_name::Foo

Similarly, srv files have C++ source code generated. The pattern for this is:

  • package_name/srv/Foo.srv → package_name::Foo

Note that a limitation of roscpp is that the message and service namespaces overlap.(roscpp中的msg和srv的名字空间是重合的)

The source for the generated files are put in the msg_gen/cpp/include/package_name/  and srv_gen/cpp/include/package_name/ directories, for messages and services respectively. The header files are generated with the same name as the filename of the msg/srv.

(实际上,msg文件会最终被转为一系列的头文件,而且保持文件名称不变)

Thus, including the std_msgs/String message in your code involves:

#include <std_msgs/String.h>

and instantiating the message:

std_msgs::Stringstr;
 
(以上是一些实际的例子,以str为例,可以看见其用法)
 
 
未完待续。。。。。

 

posted @ 2013-05-22 19:04  IT屁民  阅读(2655)  评论(0编辑  收藏  举报