ROS学习笔记(八):Could not find a package configuration file provided by xxx

使用msg

1.0 rosed : rosbash 的一部分。利用它可以直接通过package名来获取到待编辑的文件而无需指定该文件的存储路径了。
Usage:$ rosed [package_name] [filename]
rosed默认的编辑器是vim,如果没有安装,也只需一条指令:$sudo apt-get install vim

2.0 消息(msg)和服务(srv)介绍:

  • 消息(msg): msg文件就是一个描述ROS中所使用消息类型的简单文本。它们会被用来生成不同语言的源代码,存放在package的msg目录下。文件实际上就是每行声明一个数据类型和变量名。示例如下:
  Header header
  string child_frame_id
  geometry_msgs/PoseWithCovariance pose
  geometry_msgs/TwistWithCovariance twist
  • 服务(srv): 一个srv文件描述一项服务。它包含两个部分:请求和响应。存放在srv目录下。 文件分为请求和响应两部分,由’—'分隔
int64 A
int64 B
---
int64 Sum
  • 在ROS中有一个特殊的数据类型:Header,它含有时间戳和坐标系信息。在msg文件的第一行经常可以看到Header header的声明.

3.0 使用 msg:
3.1 创建一个 msg:

$ cd ~/catkin_ws/src/beginner_tutorials
$ mkdir msg
$ echo "int64 num" > msg/Num.msg

3.2 检查package.xml
确保它包含一下两条语句:

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

如果没有,添加进去。 注意,在构建的时候,我们只需要"message_generation"。然而,在运行的时候,我们只需要"message_runtime"。

3.3 编辑CMakeLists.txt文件
vim编辑器:vim CMakeLists.txt 进入文件;i 输入模式;Esc 退出编辑;:wq 保存并退出;
在这里插入图片描述修改一:利用find_packag函数,增加对message_generation的依赖,这样就可以生成消息。
直接在COMPONENTS的列表里增加message_generation:

find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation)

修改二:设置运行依赖:在 CATKIN_DEPENDS 后面添加 message_runtime

catkin_package(
  ...
  CATKIN_DEPENDS message_runtime ...
  ...)

修改三:修改文件名:

# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )

改为:(去掉注释符号#,用你的.msg文件替代Message*.msg)

add_message_files(
  FILES
  Num.msg
)

修改四: 确保添加 generate_messages()

使用srv

1.0 创建一个srv

$ roscd beginner_tutorials
$ mkdir srv

这次我们不再手动创建服务,而是从其他的package中复制一个服务。 roscp是一个很实用的命令行工具,它实现了将文件从一个package复制到另外一个package的功能。

Usage:

$ roscp [package_name] [file_to_copy_path] [copy_path]

eg:

$ roscp rospy_tutorials AddTwoInts.srv srv/AddTwoInts.srv

现在认为,你已经如前边所介绍的,在CMakeLists.txt文件中增加了对message_generation的依赖。:

以下步骤,跟着官方教程就可以。

由于更改了.xml 、CmakeLists.txt中的信息,需要重新编译我们的package。由此遇到了困扰我一下午的问题:

Base path: /home/li/catkin_ws
Source space: /home/li/catkin_ws/src
Build space: /home/li/catkin_ws/build
Devel space: /home/li/catkin_ws/devel
Install space: /home/li/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/li/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/li/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/li/catkin_ws/devel;/opt/ros/melodic
-- This workspace overlays: /home/li/catkin_ws/devel;/opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.17", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/li/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.17") 
-- Using Python nosetests: /home/li/.local/bin/nosetests-2.7
-- catkin 0.7.26
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - beginner_tutorials
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'beginner_tutorials'
-- ==> add_subdirectory(beginner_tutorials)
-- Could NOT find std_msgms (missing: std_msgms_DIR)
-- Could not find the required component 'std_msgms'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
  Could not find a package configuration file provided by "std_msgms" with
  any of the following names:

    std_msgmsConfig.cmake
    std_msgms-config.cmake

  Add the installation prefix of "std_msgms" to CMAKE_PREFIX_PATH or set
  "std_msgms_DIR" to a directory containing one of the above files.  If
  "std_msgms" provides a separate development package or SDK, be sure it has
  been installed.
Call Stack (most recent call first):
  beginner_tutorials/CMakeLists.txt:10 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/li/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/li/catkin_ws/build/CMakeFiles/CMakeError.log".
Makefile:530: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1

原因其实很简单,就是把CmakeLists.txt中的std_msgs写成std_msgms,于是遇到了Could not find a package configuration file provided by "std_msgms"

查阅了很多资料,通常解决办法就算:
1.缺啥补啥

Could not find a package configuration file provided by "xxx"

只需一条命令:

sudo apt-get install ros-版本-xxx

2.找到出错的地方,在package.xml以及CMakeList.txt中改过来就可以。

猜你喜欢

转载自blog.csdn.net/qq_42910179/article/details/106901392