ROS Tutorial 记录 - 3 ROS文件系统工具,使用workspace,创建和编译package

1. ROS文件系统

1.1 预备工作

安装 ros-tutorials程序包

$ sudo apt-get install ros-<distro>-ros-tutorials

1.2 概念

  • Packages: 软件包,是ROS应用程序代码的组织单元,每个软件包都可以包含程序库、可执行文件、脚本或者其它手动创建的东西。

  • Manifest (package.xml): 清单,是对于'软件包'相关信息的描述,用于定义软件包相关元信息之间的依赖关系,这些信息包括版本、维护者和许可协议等。

1.3 文件系统工具

1.3.1  rospack

rospack允许你获取软件包的有关信息。在本教程中,我们只涉及到rospack中find参数选项,该选项可以返回软件包的路径信息。

# rospack find [包名称]

例如:

$ rospack find roscpp

1.3.2 roscd

roscd是rosbash命令集中的一部分

用法:

# roscd [本地包名称[/子目录]]

它允许你直接切换(cd)工作目录到某个软件包或者软件包集当中。

用法:

# roscd [本地包名称[/子目录]]

示例:

$ roscd roscpp

就像ROS中的其它工具一样,roscd只能切换到那些路径已经包含在ROS_PACKAGE_PATH环境变量中的软件包,要查看ROS_PACKAGE_PATH中包含的路径可以输入:

$ echo $ROS_PACKAGE_PATH

你的ROS_PACKAGE_PATH环境变量应该包含那些保存有ROS软件包的路径,并且每个路径之间用冒号分隔开来。

跟其他路径环境变量类似,你可以在ROS_PACKAGE_PATH中添加更多其它路径,每条路径使用冒号':'分隔。

使用roscd也可以切换到一个软件包或软件包集的子目录中。

1.3.3 roscd log

使用roscd log可以切换到ROS保存日记文件的目录下。如果你没有执行过任何ROS程序,系统会报错说该目录不存在。

1.3.4  rosls

用法:

# rosls [本地包名称[/子目录]]

1.3.5 自动完成输入(一些ROS工具支持TAB 自动完成输入的功能。)

回顾:

一些ROS工具支持TAB 自动完成输入的功能。

1.3.5 

回顾

你也许已经注意到了ROS命令工具的的命名方式:

  • rospack = ros + pack(age)
  • roscd = ros + cd
  • rosls = ros + ls

2. 使用workspace

http://wiki.ros.org/catkin/Tutorials/using_a_workspace

2.1 在工作空间中编译(暂时只学习使用catkin_make方式)

$ cd ~/catkin_ws/src/beginner_tutorials/src

# Add/Edit source files

$ cd ~/catkin_ws/src/beginner_tutorials

# Update CMakeFiles.txt to reflect any changes to your sources

$ cd ~/catkin_ws

$ catkin_make -DCMAKE_BUILD_TYPE=Release

Note: You might want to select a different CMake build type (e.g. RelWithDebInfo or Debug, see http://cmake.org/cmake/help/v2.8.12/cmake.html#variable:CMAKE_BUILD_TYPE).

This will build any packages in the source space (~/catkin_ws/src) to the build space (~/catkin_ws/build). 

Any source files, python libraries, scripts or any other static files will remain in the source space. However, any generated files such as libraries, executables, or generated code will be placed in the devel space. Also in the devel space there will be setup.*shfiles generated, which when sourced will prefix your environment with this devel space.

If you want you can pass any arguments you would normally pass to make to catkin_make

$ cd ~/catkin_ws
$ catkin_make install

This will be equivalent to calling 'cd ~/catkin_ws/build && make install'.Now there should be an install space(~/catkin_ws/install), which contains its own setup.*sh files. Sourcing one of these setup.*sh files will overlay this install space onto your environment.

Note you should use either the install space or the devel space, not both at the same time.

开发调试用devel,部署用install?

If you have a previously compiled workspace and you add a new package inside it, you can tell catkin to add this new package to the already-compiled binaries by adding this parameter:

$ catkin_make --force-cmake

If you want to see the command lines used to run the compiler and linker, run catkin_make with this option:

$ catkin_make -DCMAKE_VERBOSE_MAKEFILE=ON

访问链接 http://wiki.ros.org/catkin/Tutorials/workspace_overlaying  ->Overlaying with catkin workspaces  目前不深入

3.  创建程序包

3.1 包组成

一个简单的工作空间也许看起来像这样:

workspace_folder/        -- WORKSPACE
  src/                   -- SOURCE SPACE
    CMakeLists.txt       -- 'Toplevel' CMake file, provided by catkin
    package_1/
      CMakeLists.txt     -- CMakeLists.txt file for package_1
      package.xml        -- Package manifest for package_1
    ...
    package_n/
      CMakeLists.txt     -- CMakeLists.txt file for package_n
      package.xml        -- Package manifest for package_n

3.2 开始创建

$ cd ~/catkin_ws/src

现在使用catkin_create_pkg命令来创建一个名为'beginner_tutorials'的新程序包,这个程序包依赖于std_msgs、roscpp和rospy:

$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
# catkin_create_pkg <package_name> [depend1] [depend2] [depend3]

3.3 包依赖关系

3.3.1 查看1级依赖

$rospack depends1 beginner_tutorials 

3.3.2 间接依赖

$rospack depends1 rospy

使用rospack可以递归检测出所有的依赖包。

$ rospack depends beginner_tutorials

3.4 自定义程序包

3.4.1 自定义 package.xml

3.4.1.1 描述标签

 <description>The beginner_tutorials package</description>

3.4.1.2 维护者标签

<maintainer email="user@todo.todo">user</maintainer>

3.4.1.3 许可标签

  <!--   BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
  <license>TODO</license>

3.4.1.4 依赖项标签

分为build_depend、buildtool_depend、run_depend、test_depend。 build_export_depend 是什么?

3.4.2 自定义 CMakeLists.txt

参考http://wiki.ros.org/catkin/CMakeLists.txt

4. 编译package

使用 catkin_make

catkin_make 是一个命令行工具,它简化了catkin的标准工作流程。你可以认为catkin_make是在CMake标准工作流程中依次调用了cmake 和 make。

使用方法:

# 在catkin工作空间下
$ catkin_make [make_targets] [-DCMAKE_VARIABLES=...]

CMake标准工作流程主要可以分为以下几个步骤:

# 在一个CMake项目里
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make install  # (可选)

使用catkin_make编译,多个catkin项目可以放在工作空间中一起编译,工作流程如下:

# In a catkin workspace
$ catkin_make
$ catkin_make install  # (可选)

上述命令会编译src文件夹下的所有catkin工程。如果你的源代码不在默认工作空间中(~/catkin_ws/src),比如说存放在了my_src中,那么你可以这样来使用catkin_make:

# In a catkin workspace
$ catkin_make --source my_src
$ catkin_make install --source my_src  # (optionally)

catkin_make首先输出它所使用到的每个空间所在的路径。其中build 目录是build space的默认所在位置,同时cmake 和 make也是在这里被调用来配置并编译你的程序包。devel 目录是devel space的默认所在位置, 同时也是在你安装程序包之前存放可执行文件和库文件的地方。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值