- 根据需要创建功能包
- 一类引用ros库函数的
- 一类是自己定义的消息类型
库函数中有的可以直接在创建功能包的时候添加依赖,也可以在CMakeLists.txt中手动添加
cpp
catkin_create_pkg crepes roscpp rospy std_msgs nav_msgs sensor_msgs geometry_msgs
创建文件夹msg:
对应文件目录:
cpp
pf@fNUC12WSKi7:~/CLionProjects/crepes3w/src$ tree -L 2
.
├── CMakeLists.txt -> /opt/ros/noetic/share/catkin/cmake/toplevel.cmake
└── crepes
├── CMakeLists.txt
├── include
├── msg
├── package.xml
└── src
4 directories, 3 files
核心要点:
- (1) 另外对于定义的消息类型,ros空间只会在包的下面找msg文件夹,也即不能自己随便创建msgs 或者xxxmsgs文件夹都是不可行的;
- (2) 如果找不到需要依赖,在CMakeLists.txt配置正确的情况下,一定是自己编辑或者copy时出现了问题,只要认真检查就可以解决;
- (3) 如果对应的消息定义在msg下,且有相互引用的情况,直接引用即可,无需加msg/这种路径识别。
对于(1)会报错如下:
cpp
==> add_subdirectory(crepes)
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
CMake Error at /opt/ros/noetic/share/genmsg/cmake/genmsg-extras.cmake:94 (message):
add_message_files() directory not found:
/home/pf/CLionProjects/crepes3w/src/crepes/msg
Call Stack (most recent call first):
crepes/CMakeLists.txt:57 (add_message_files)
对于(2)和(3)会报错如下:
cpp
Could not find messages which
'/home/pf/,,,/msg/frame.msg' depends on. Did
you forget to specify generate_messages(DEPENDENCIES ...)?
Cannot locate message [cloud_xyz]: unknown package [xre] on search path...