1.1 Create message msg
First create the msg folder in the node beginner_tutorials directory to store msg
$ cd ~/catkin_ws/src/beginner_tutorials $ mkdir msg $ echo "int64 num" > msg/Num.msg
1.2 Add dependencies in the
package.xml file
In the tutorial http://wiki.ros.org/cn/ROS/Tutorials/CreatingMsgAndSrv, it is said that these two sentences should be added, but in reality, there are two compilation errors.
<build_depend>message_generation</build_depend> <run_depend>message_runtime</run_depend>
The error is as follows:
Finally, remove these two sentences and compile OK. In addition, I saw others on the Internet changing these two sentences to:
It also compiles.
<build_depend> message_generation </build_depend> <exec_depend> message_runtime </exec_depend> or <build_export_depend>message_generation</build_export_depend> <exec_depend>message_runtime</exec_depend>
1.3 Modify the CMakeLists.txt file
Add dependency on message_generation in
find_packag function
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation)
Add to
add_message_files( FILES Num.msg )
generate_messages( DEPENDENCIES std_msgs )
As shown
1.4 Compile
Return to the catkin_ws directory to compile
catkin_make
1.5 Check whether msg is generated
rosmsg show beginner_tutorials/Num
2.1 Create service srv
Similarly, create the srv folder
in the node beginner_tutorials directory to store the srv file
2.2 Modify the CMakeLists.txt file
Add dependency on message_generation in
find_packag function,
common to msg and srv
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation)
Add to
2.3 Compile and view
catkin_make rossrv show beginner_tutorials/AddTwoInts