新建消息和服务
首先注意,之前新建的beginner_tutorialspackage是在src文件夹下面的。而且每次要调用这个package之前要添加路径(再新的terminal中调用这个package的时候要添加路径)
cd ~/catkin_ws/src/beginner_tutorials
mkdir msg
echo "int64 num" msg/Num.msg
查看package.xml, 确保它包含一下两条语句:
<build_depend>message_generation</build_depend>
<run_depend>message_runtime</run_depend>
再CMakeLists.txt文件中,利用find_packag函数,增加对message_generation的依赖,添加下面的语句:
# Do not just add this line to your CMakeLists.txt, modify the existing line
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation)
同时保证设置了运行依赖message_runtime
catkin_package(
CATKIN_DEPENDS roscpp rospy std_msgs message_runtime
)
注意,这个地方,ROS官网的初级教程了写的是改成:
catkin_package(
...
CATKIN_DEPENDS message_runtime ...
...)
很容易让人误解成直接改成上面这段语句,但是实际上,message_runtime ...后面的...代表的是其他的包,也就是说,在原有的包上添加message_runtime 就可以了