详解常用的ROS内置消息类型

本文介绍了ROS的消息类型,包括内置的标准消息类型std_msgs,它是基础类型,还包含特殊的Head类型用于记录数据信息。此外,还介绍了ros常用数据类型集合comm_msg,重点阐述了其中最常用的几何消息类型geometry_msgs,如点、速度、位姿等的定义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

std_msgs 

      该类型是ROS内置的标准消息类型,是最基础的消息类型

 

(1)对于单类型,下表是其与C++和python的对应关系:


Primitive TypeSerializationC++Python2 / Python3
boolunsigned 8-bit intuint8_tbool                                        
int8signed 8-bit intint8_tint                                                    
uint8unsigned 8-bit intuint8_tint
int16signed 16-bit intint16_tint
uint16unsigned 16-bit intuint16_tint
int32signed 32-bit intint32_tint
uint32unsigned 32-bit intuint32_tint
int64signed 64-bit intint64_tlong int
uint64unsigned 64-bit intuint64_tlong int
float3232-bit IEEE floatfloatfloat
float6464-bit IEEE floatdoublefloat
stringascii stringstd::stringstr bytes
timesecs/nsecs unsigned 32-bit intsros::Timerospy.Time
durationsecs/nsecs signed 32-bit intsros::Durationrospy.Duration

 

(2)对于数组类型,其对应关系如下:


Primitive TypeSerializationC++Python2 / Python3
fixed-lengthno extra serializationboost::array<T, length>/std::vectortuple
variable-lengthuint32 length prefixstd::vectortuple
uint8[]see aboveas abovestr bytes
bool[]see abovestd::vector<uint8_t>list of bool

 

(3)Head

 

std_msg中还包含一个特殊消息类型 :Head,表示包头,它是一个结构体,内置三个类型:


uint32  seq                       # 表示数据流的 sequenceID

time  stamp                     # 表示时间戳

string  frame_id              # 表示当前帧数据的帧头(帧序号)


Head类型常用于记录每帧数据的时间和序列信息,用于记录历史数据的情形。

 

以上消息类型是其他各种类型的基础,其他各种消息类型的嵌套定义归根结底都依赖以上几种类型。

 

comm_msg

 

     该类型是ros常用数据类型的集合,包括以下几种:actionlib_msgs、diagnostic_msgs、geometry_msgs、nav_msgs、sensor_msgs, 下面是几种最常用的类型的介绍:

 

2.1 geometry_msgs

    是最常用的几何消息类型,定义了描述机器人状态的各种类型,比如点、速度、加速度、位姿等。

 

2.1.1 Vector3、Vector3Stamped

 

   (1) geometry_msgs/Vector3.msg

       表示自由空间的三维向量,是一个结构体,内置三个类型:


 float64 x

 float64 y

 float64 z


注意:该类型仅用于表示方向,tf2中只能应用于(rotation)旋转,不能应用于变换(transtion),若想用于变换,需要用到geometry_msgs/Point类型。

 

   (2) geometry_msgs/Vector3Stamped.msg

       表示带有时间戳和参考坐标系的三维向量


std_msgs/Header header
geometry_msgs/Vector3 vector


 

2.1.2 Quaternion、QuaternionStamped
 

 (1) geometry_msgs/Quaternion.msg

        用四元数表示自由空间中的旋转:


float64 x
float64 y
float64 z
float64 w


 

   (2) geometry_msgs/QuaternionStamped.msg

         表示带有参考坐标系和时间戳的旋转:


std_msgs/Header header
geometry_msgs/Quaternion quaternion


 

 

2.1.3 Transform、TransformStamped


(1)   geometry_msgs/Transform.msg

       表示自由空间的两个坐标系之间的变换关系,包括旋转和平移。旋转用四元数表示,平移用平移向量表示:


geometry_msgs/Vector3 translation
geometry_msgs/Quaternion rotation


 

(2)  geometry_msgs/TransformStamped.msg

       表示从Head里面的坐标系到子坐标系的变换:


std_msgs/Header header
string child_frame_id                               #子坐标系
geometry_msgs/Transform transform


 

2.1.4 Point、Point32、PointStamped

 

(1) geometry_msgs/Point.msg

    表示自由空间中的点:


 float64 x

 float64 y

 float64 z


 

(2)geometry_msgs/Point32.msg

        为了在发送点云时减少数据量,ros提供了压缩版的point32:


float32 x
float32 y
float32 z


 

(3)geometry_msgs/PointStamped.msg

        带有参考坐标系和时间戳的point:


std_msgs/Header header
geometry_msgs/Point point


 

2.1.5 Pose、Pose2D、PoseArray、PoseStamped、PoseWithCovariance、PoseWithCovarianceStamp

        

   (1)  geometry_msgs/Pose.msg

         位姿,即位置和姿态,用point表示位置,用四元数表示姿态:


geometry_msgs/Point position
geometry_msgs/Quaternion orientation


 

   (2) geometry_msgs/Pose2D.msg

         表示二维平面上面的一个点(表示2D流形上的位置和方向):


float64 x
float64 y
float64 theta


  (3)  geometry_msgs/PoseArray.msg

         表示全局坐标系下的一组轨迹点:


std_msgs/Header header                         #head里面保存了参考系
geometry_msgs/Pose[] poses


 

 (4) geometry_msgs/PoseStamped.msg

       表示带有时间戳和参考系的位姿:


std_msgs/Header header
geometry_msgs/Pose pose


 

 (5) geometry_msgs/PoseWithCovariance.msg
         表示带有协方差矩阵的位姿估计,协方差矩阵表示其不确定度,用6*6的矩阵表示协方差,对应表示绕xyz三轴的不确定度


geometry_msgs/Pose pose
float64[36] covariance


   

 (6) geometry_msgs/PoseWithCovariance.msg

         表示带有时间戳和坐标系的位姿估计


geometry_msgs/Pose pose
float64[36] covariance


 

2.1.6 Twist、TwistStamped、TwistWithCovariance、TwistWithCovarianceStamped


(1)   geometry_msgs/Twist.msg

        表示自由空间的一组速度,包括线速度和角速度


geometry_msgs/Vector3 linear
geometry_msgs/Vector3 angular


 

(2)  geometry_msgs/TwistStamped.msg

       表示带有时间戳和参考坐标系的速度


std_msgs/Header header
geometry_msgs/Twist twist


 

(3)  geometry_msgs/TwistWithCovariance.msg

       表示带有协方差表示不确定度的速度估计


geometry_msgs/Twist twist
float64[36] covariance


 

(4)  geometry_msgs/TwistWithCovarianceStamped.msg

      表示带有时间戳和参考坐标系的速度估计


std_msgs/Header header
geometry_msgs/TwistWithCovariance twist


 

2.1.7 Accel、AccelStamped、AccelWithCovariance、AccelWithCovarianceStamped


(1)   geometry_msgs/Accel.msg

        表示自由空间的一组加速度,包括线加速度和角加速度


geometry_msgs/Vector3 linear
geometry_msgs/Vector3 angular


 

(2)  geometry_msgs/AccelStamped.msg

       表示带有时间戳和参考坐标系的加速度


std_msgs/Header header
geometry_msgs/Accel accel


 

(3)  geometry_msgs/AccelWithCovariance.msg

       表示带有协方差表示不确定度的加速度估计


geometry_msgs/Accel accel
float64[36] covariance


 

(4)  geometry_msgs/AccelWithCovarianceStamped.msg

      表示带有时间戳和参考坐标系的加速度估计


std_msgs/Header header
geometry_msgs/AccelWithCovariance accel


 

2.1.8 Polygon、PolygonStamped


(1)   geometry_msgs/Accel.msg

        表示自由空间的一块区域,用首位相连的一组点表示


geometry_msgs/Point32[] points


 

(2)  geometry_msgs/AccelStamped.msg

      表示带有参考坐标系和时间戳的自由空间的一块区域


std_msgs/Header header
geometry_msgs/Polygon polygon


 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值