상세 컨텐츠

본문 제목

ROS Message 의 이해

Coding/Robot Operating System

by 세미531 2021. 6. 4. 17:33

본문

728x90

ros 를 사용하다보면 데이터를 주고 받으면서 msg 라고 보이는 message 파일을 보게 될 것이다.

 

전에 서로 통신을 하는 토픽(Topic)에 대해 알아봤는데 간단히 말하면 topic은 데이터이고 msg는 그 데이터 안에서 표현되고 있는 데이터의 자료형에 대한 설명을 담은 파일이라고 이해하면 된다. 

 

예를 들어 거북이 튜토리얼을 진행할 때 /turtle1/cmd_vel 이라는 topic이 geometry_msgs/Twist 라는 메세지를 사용한다고 하자. 그러면 터미널 창에 msg를 보여주는 rosmsg show geometry_msgs/Twist 를 입력하면 결과는

geometry_msgs/Vector3 Linear
float64 x
float64 y
float64 z
geometry_msgs/Vector3 angular
float64 x
float64 y
float64 z

이렇게 표시될 것이다. float이 실수를 의미하는 것이고 x, y, z 가 실수로 나타난다는 의미이다.

만약 거북이 튜토리얼에서 자신이 거북이 조종을 해보자 한다면 

rostopic pud -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[4.0,1.1,5.3]''[0.0,1.0,3.3]'

이렇게 작성해주면 된다. 이 코드의 의미는 topic에 한번만 실행되도록 publish를 해주고 msg형식이 Linear 과 angular 두가지 였으므로 '[4.0,1.1,5.3]''[0.0,1.0,3.3]' 이렇게 원하는 실수값들을 작성해주면 된다.

 

 

 

개인적으로 많이 보는 msg파일들을 보자면 먼저 

sensor_msgs/PointCloud.msg

# This message holds a collection of 3d points, plus optional additional
# information about each point.

# Time of sensor data acquisition, coordinate frame ID.
Header header

# Array of 3d points. Each Point32 should be interpreted as a 3d point
# in the frame given in the header.
geometry_msgs/Point32[] points

# Each channel should have the same number of elements as points array,
# and the data in each channel should correspond 1:1 with each point.
# Channel names in common practice are listed in ChannelFloat32.msg.
ChannelFloat32[] channels

std_msgs/Header.msg

# Standard metadata for higher-level stamped data types.
# This is generally used to communicate timestamped data 
# in a particular coordinate frame.
# 
# sequence ID: consecutively increasing ID 
uint32 seq
#Two-integer timestamp that is expressed as:
# * stamp.sec: seconds (stamp_secs) since epoch (in Python the variable is called 'secs')
# * stamp.nsec: nanoseconds since stamp_secs (in Python the variable is called 'nsecs')
# time-handling sugar is provided by the client library
time stamp
#Frame this data is associated with
string frame_id

geometry_msgs/Point32.msg

# This contains the position of a point in free space(with 32 bits of precision).
# It is recommeded to use Point wherever possible instead of Point32.  
# 
# This recommendation is to promote interoperability.  
#
# This message is designed to take up less space when sending
# lots of points at once, as in the case of a PointCloud.  

float32 x
float32 y
float32 z

sensor_msgs/ChannelFloat32.msg

# This message is used by the PointCloud message to hold optional data
# associated with each point in the cloud. The length of the values
# array should be the same as the length of the points array in the
# PointCloud, and each value should be associated with the corresponding
# point.

# Channel names in existing practice include:
#   "u", "v" - row and column (respectively) in the left stereo image.
#              This is opposite to usual conventions but remains for
#              historical reasons. The newer PointCloud2 message has no
#              such problem.
#   "rgb" - For point clouds produced by color stereo cameras. uint8
#           (R,G,B) values packed into the least significant 24 bits,
#           in order.
#   "intensity" - laser or pixel intensity.
#   "distance"

# The channel name should give semantics of the channel (e.g.
# "intensity" instead of "value").
string name

# The values array should be 1-1 with the elements of the associated
# PointCloud.
float32[] values

 

 

 

728x90

관련글 더보기

댓글 영역