Ros Learning (11)--msg SRV

Source: Internet
Author: User

I. MSG and SRV INTRODUCTION

1. Definition

Message (msg): The msg file is a simple text that describes the type of message used in Ros. They will be used to generate source code in different languages.

Service (SRV): An SRV file describes a service. It consists of two parts: request and response.  

2. Storage location

msg files are stored in the package's msg directory, and theSRV files are stored in the SRV directory.

3. Msg Essence

An msg file is actually a data type and variable name that each row declares. You can use the following data types:

PS: There is a special type header: contains timestamp and coordinate system information

In the first line of the msg file, you can often see the header header 's declaration .

4. SRV file structure

Int64 Aint64 B---Int64 Sum

The srv file is divided into two parts, request and response, separated by '---'

Second, MSG

1. Create a MSG

(1) Create msg file

" Int64 num " > Msg/num.msg

(2) Modify the package.xml to ensure that the msg file is converted into C + +,python and other language source code

<build_depend>message_generation</build_depend> <run_depend>message_runtime</run_depend >

Add these two lines in package.xml

(3) Modify CMakeLists.txt

A, modify Find_package

Find_package (catkin REQUIRED components   roscpp   rospy   std_msgs   message_generation)

b, modify the Catkin_package

Catkin_package (...  Catkin_depends message_runtime  ... ...)

C, modify the Add_message_files (remember to uncomment)

Add_message_files (  files  num.msg)

D. After manually adding the . msg file, we want to make sure that CMake knows when to reconfigure our project. (uncomment)

Generate_messages (  DEPENDENCIES  std_msgs)

2. Use Rosmsg to determine if Ros can identify messages

(1) Syntax:

ROSMSG show [Message type]

(2) Demo:

Rosmsg Show Beginner_tutorials/num

(3) If you are not sure which package, you can omit the package name

Rosmsg Show Num

Third, SRV

1. Create an SRV

(1) Create an SRV folder first

ROSCD Beginner_tutorialsmkdir SRV

(2) Creating an SRV file using replication

A, grammar

ROSCP [Package_name] [File_to_copy_path] [Copy_path]

B. Examples

ROSCP rospy_tutorials addtwoints.srv Srv/addtwoints.srv

(3) Modify the package.xml file as MSG and join the two dependencies

<build_depend>message_generation</build_depend><run_depend>message_runtime</run_depend >

(4) Modify the Find_package in CMakeLists.txt

Find_package (catkin REQUIRED components  roscpp  rospy std_msgs  message_generation)

(5) Modify the Add_service_files in CMakeLists.txt (remove comments)

Add_service_files (  files  addtwoints.srv)

2. Use Rossrv to ensure that Ros can identify services

(1) Syntax:

Rossrv Show <service type>

(2) Demo:

Rossrv Show Beginner_tutorials/addtwoints

(3) The package name can be omitted

Rossrv Show Addtwoints

Iv. MSG and SRV compilation

1, modify the CMakelists.txt

Generate_messages (  DEPENDENCIES  std_msgs)

Remember to remove the comment

2, to compile

Catkin_make Install

3, all in msg path < Span style= "Font-size:medium" >.msg files are converted to ros The source code of the supported languages.

generated c++ header files will be placed in < Span style= "Font-size:medium" >~/catkin_ws/devel/include/beginner_ tutorials/.

python scripting language will be ~/catkin_ws/devel/lib/python2.7/dist-packages/beginner_tutorials/msg directory.

< Span style= "Font-family:liberation Serif, Serif" > lisp file will appear in ~/catkin_ws/devel/share/ common-lisp/ros/beginner_tutorials/msg/ Path under

Ros Learning (11)--msg SRV

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.