ROS

ROS_Study: Creatomg a ROS msg and srv(Only msg)

우기빌리 2023. 11. 22. 20:28

msg:

1. simple text files that describe the fields of a ROS message

2. msg 파일들은 패키지의 msg 폴더 안에 저장된다.

3. 각 줄에 field typefield name이 적힌 간단한 텍스트 파일

field type 예시:

  • int8, int16, int32, int64 (plus uint*)
  • float32, float64
  • string
  • time, duration
  • other msg files
  • variable-length array[] and fixed-length array[C]

msg 사용법:

1. msg 만들기

 1) 패키지 안에 새로운 msg 만들기

*edit 프로그램(visual code 등)에서 폴더에다 생성하는게 쉬움

$ roscd beginner_tutorials
$ mkdir msg
$ echo "int64 num" > msg/Num.msg

 

 2) package.xml을 열어서 다음 두 줄을 추가

  <build_depend>message_generation</build_depend>
  <exec_depend>message_runtime</exec_depend>

* build time에서는 message_generation이

 runtime에서는 message_runtime이 필요

 

 3) CMakeLists.txt 를 아래와 같이 수정

# Do not just add this to your CMakeLists.txt, modify the existing text to add message_generation before the closing parenthesis
find_package(catkin REQUIRED COMPONENTS
   roscpp
   rospy
   std_msgs
   message_generation
)
catkin_package(
  ...
  CATKIN_DEPENDS message_runtime ...
  ...)
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )

change it to

add_message_files(
  FILES
  Num.msg
)
generate_messages(
  DEPENDENCIES
  std_msgs
)

 

2. rosmsg 사용하기

1) 패키지 이름을 알고 있을 경우

$ rosmsg show [message type]

$ rosmsg show beginner_tutorials/Num

->
int64 num

*

beginner_tutorials: msg가 정의되어있는 패키지

Num: 생성한 msg의 이름

 

2) 패키지 이름을 모를 경우

$ rosmsg show Num

->
[beginner_tutorials/Num]:
int64 num