1. 概述
Simple Message是ROS-Industrial的一部分,定义了用于与工业机器人控制器通信的简单消息连接协议。另外还包括处理连接受限系统的处理器和管理器类。
2. 协议(Protocol)
简单消息(simple_message)协议定义了ROS的驱动层和机器人控制器之间socket通讯的信息结构。
协议格式:
- 前缀(PREFIX) (并不计算在消息之内):
(长度1个字节)
值为 int LENGTH (HEADER + DATA),即整个消息的字节长度。 - 信息头(HEADER):
(长度3个字节)
int MSG_TYPE 标识消息类型(标准的或机器人特定的值,可以参考官方指定的消息标识符)
int COMM_TYPE 可识别的通信类型
int REPLY CODE 应答代码 (仅在服务应答中有效) - 数据体(DATA):
可变长度的字节数据数组,数据由消息类型和通信类型确定
3. HEADER解析
HEADER定义头文件<simple_message.h>在simple_message\include\simple_message路径文件夹下。源码下载地址参照ROS-I使用总结第三节。
3.1 MSG_TYPE
主要用来识别该消息的数据类型,以便分类处理。为了对MSG_TYPE进行统一的规范,官方已分配好了一部分的MSG_TYPE。当然,也可以增加自己定义的消息类型。
namespace StandardMsgTypes
{
enum StandardMsgType
{
INVALID = 0,
PING = 1,
//TODO: Keeping these message type for the time being. Refactoring
// the messages should remove the need for this message.
JOINT_POSITION = 10,
JOINT = 10,
READ_INPUT = 20,
WRITE_OUTPUT = 21,
JOINT_TRAJ_PT = 11, //Joint trajectory point message (typically for streaming)
JOINT_TRAJ = 12, //Joint trajectory message (typically for trajectory downloading)
STATUS = 13, //Robot status message (for reporting the robot state)
JOINT_TRAJ_PT_FULL = 14, // Joint trajectory point message (all message fields)
JOINT_FEEDBACK = 15, // Feedback of joint pos/vel/accel
// Begin vendor specific message types (only define the beginning enum value,
// specific enum values should be defined locally, within in the range reserved
// here. Each vendor can reserve up 100 types
SWRI_MSG_BEGIN = 1000,
UR_MSG_BEGIN = 1100,
ADEPT_MSG_BEGIN = 1200,
ABB_MSG_BEGIN = 1300,
FANUC_MSG_BEGIN = 1400,
MOTOMAN_MSG_BEGIN = 2000
};
}
typedef StandardMsgTypes::StandardMsgType StandardMsgType;
3.2 COMM_TYPE
定义消息发布在ROS的消息类型,分为话题和服务两种。
namespace CommTypes
{
enum CommType
{
INVALID = 0,
TOPIC = 1,
SERVICE_REQUEST = 2,
SERVICE_REPLY = 3
};
}
typedef CommTypes::CommType CommType;
3.3 REPLY CODE
ROS中收到服务类型的消息时必须应答,此处定义应答时消息处理结果。当COMM_TYPE不是SERVICE_REPLY 时,ReplyTypes可定义为INVALID 。
namespace ReplyTypes
{
enum ReplyType
{
INVALID = 0,
SUCCESS = 1,
FAILURE = 2
};
}
typedef ReplyTypes::ReplyType ReplyType;
4. simple_message解析
由上可见,simple_message包含HEAD+DATA信息,simple_message类是对HEAD+DATA信息的处理。