ROS通信架构(二)
ROS的通信方式有以下四种:
Topic 主题
Service 服务
Parameter Service 参数服务器
Actionlib 动作库
Topic:
topic常用于传输实时性、周期性的消息,是一种点(node)对点的单向通信方式。
1.public节点和subscriber节点到master进行注册
2.public发布topic
3.subscriber在master指挥下订阅改topic
4.public和subscriber建立单向通信
subscriber接受到消息会立刻执行回调函数Callback(前定义好了一个处理函数,当有消息来就会触发这个处理函数,函数会对消息进行处理,类似于单片机中的中断)。topic通信属于异步通信,
publisher每发布一个消息之后就会执行下一个动作,不关心消息之后会如何被处理,subscriber只管接受topic,不关心是由谁发送,publisher和subscriber不存在协同工作,为异步通信。
topic可以同时有多个subscribers,也可以同时有多个publishers(/rosout、/tf等)。
示例:
摄像头画面的发布、处理、显示:摄像头拍摄程序是一个node(记作node1),当node1运行启动之后,它作为一个Publisher就开始发布topic,叫做/camera_rgb,是rgb颜色信息,node2是图像处理程序,它订阅了/camera_rgb这个topic,经过master的介绍,node2就能建立和摄像头节点(node1)的连接。node3与node2相同。
操作命令:
命令 | 作用 |
---|---|
rostopic list | 列出当前所有的topic |
rostopic info topic_name | 显示某个topic的属性信息 |
rostopic echo topic_name | 显示某个topic的内容 |
rostopic pub topic_name | 向某个topic发布内容 |
rostopic bw topic_name | 查看某个topic的带宽 |
rostopic hz topic_name | 查看某个topic的频率 |
rostopic find topic_type | 查找某个类型的topic |
rostopic type topic_name | 查看某个topic的类型(msg) |
可以查看命令
rostopic help 或者 rostopic command -h
message
topic的数据格式就是Message(Message按照定义解释就是topic内容的数据类型),也称之为topic的格式标准。
基本的msg包括bool、int8、int16、int32、int64(以及uint)、float、float64、string、time、duration
header、可变长数组array[]、固定长数组array[c]
存放在package/mesage下,如:
std_msg/Header header
uint32 seq
time stamp
string frame_id
uint32 height
uint32 width
string encoding
uint8 is_bigendian
uint32 step
uint8[] data
rosmsg命令 | 作用 |
---|---|
rosmsg list | 列出系统上所有的msg |
rosmsg show msg_name | 显示某个msg的内容 |
常见message
常用的message包括 std_msgs ,nav_msgs ,geometry_msgs等
Vector3.msg
#文件位置:geometry_msgs/Vector3.msg
float64 x
float64 y
float64 z
Accel.msg
#定义加速度项(线性加速度和角加速度)
#文件位置:geometry_msgs/Accel.msg
Vector3 linear
Vector3 angular
Hearder.msg
#定义数据的参考时间和参考坐标系
#文件位置:std_msgs/Header.msg
uint32 seq #数据ID
time stamp #数据时间戳
string frame_id #数据的参考坐标系
Echos.msg
#定义超声传感器
#文件位置:自定义msg文件
Hearder hearder
uint16 front_left
uint16 front_center
uint16 front_right
uint16 rear_left
uint16 rear_center
uint16 rear_right
Quarternion.msg
#空间中旋转的四元数
#文件位置:geometry_msgs/Quaternion.msg
float64 x
float64 y
float64 z
float64 w
Imu.msg
#包含了从惯性元件中得到的数据,加速度为m/^2,角速度为rad/s
#如果所有的测量协方差已知,则需要全部填充进来;如果只知道方差,则只填充协方差矩阵的对角数据
#文件位置:sensor_msgs/Imu.msg
Header header
Quaternion orientation
float64[9] orientation_covariance
Vector3 angular_velocity
float64[9] angular_velocity_covariance
Vector3 linear_acceleration
float64[] linear_acceleration_covariance
LaserScan.msg
#平面内的激光测距扫描数据(仅适配激光测距)
#若声呐等测距,需要创建不同类型的消息
#文件位置:sensor_msgs/LaserScan.msg
Header header #时间戳为收到第一束激光的时间
float32 angle_min #扫描最小角度(单位为rad)
float32 angle_max #扫描最大角度(单位为rad)
float32 angle_increment #两次测量之间的角度增量(单位为rad)
float32 time_increment #两次测量之间的时间增量(单位为s)
float32 scan_time #两次扫描之间的时间间隔(单位为s)
float32 range_min #距离最小值(m)
float32 range_max #距离最大值(m)
float32[] ranges #测距数据(m,如果数据不在最小数据和最大数据之间,则抛弃)
float32[] intensities #强度,具体单位由测量设备确定,如果仪器没有强度测量,则数组为空即可
Point.msg
#空间中点的位置
#文件位置:geometry_msgs/Point.msg
float64 x
float64 y
float64 z
Pose.msg
#定义自由空间中的位姿信息(位置和指向)
#文件位置:geometry_msgs/Pose.msg
Point position
Quaternion orientation
PoseStamped.msg
#定义有时空基准的位姿
#文件位置:geometry_msgs/PoseStamped.msg
Header header
Pose pose
PoseWithCovariance.msg
#表示空间中含有不确定性的位姿信息
#文件位置:geometry_msgs/PoseWithCovariance.msg
float64[36] covariance
Pose pose
Power.msg
#表示电源状态,是否开启
#文件位置:自定义msg文件
Header header
bool power
######################
bool ON=1
bool OFF=0
Twist.msg
#定义空间中物体运动的线速度和角速度
#文件位置:geometry_msgs/Twist.msg
Vector3 linear
Vector3 angular
TwistWithCovariance.msg
#不确定的速度量,协方差矩阵按行分别表示:沿x方向速度的不确定性,沿y方向速度的不确定性,沿z方向速度的不确定性
#绕x转动角速度的不确定性,绕y轴转动的角速度的不确定性,绕z轴转动的角速度的不确定性
#文件位置:geometry_msgs/TwistWithCovariance.msg
Twist twist
flaot64[36] covariance #分别表示[x; y; z; Rx; Ry; Rz]
Odometry,msg
#描述了自由空间中位置和速度的估计值
#文件位置:nav_msgs/Odometry.msg
Header header
string child_fram_id
PoseWithCovariance pose
TwistWithCovariance twist