[关闭]
@ferstar 2015-08-03T23:25:24.000000Z 字数 1753 阅读 2107

创建ros软件包

ROS


1. 最简单的包看起来是这样子的

  1. my_package/
  2. CMakeLists.txt
  3. package.xml

2. 典型工作目录下的结构

  1. workspace_folder/ -- 工作目录
  2. src/ -- 源码目录
  3. CMakeLists.txt -- 顶层CMake file, catkin自动生成
  4. package_1/
  5. CMakeLists.txt -- CMakeLists.txt file for package_1
  6. package.xml -- Package manifest for package_1
  7. ...
  8. package_n/
  9. CMakeLists.txt -- CMakeLists.txt file for package_n
  10. package.xml -- Package manifest for package_n

3. 用catkin工具新建一个软件包

$ cd ~/catkin_ws/src
然后新建一个beginner_tutorials的软件包,依赖于std_msgs, roscpp, and rospy
$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
输出

  1. Created file beginner_tutorials/CMakeLists.txt
  2. Created file beginner_tutorials/package.xml
  3. Created folder beginner_tutorials/include/beginner_tutorials
  4. Created folder beginner_tutorials/src
  5. Successfully created files in /home/ferstar/catkin_ws/src/beginner_tutorials. Please adjust the values in package.xml.

3.1 所以,新建软件包的规则是 包名+依赖

catkin_create_pkg <package_name> [depend1] [depend2] [depend3]

4 编译工作空间并导出到环境变量

$ cd ~/catkin_ws
$ catkin_make
输出

Base path: /home/ferstar/catkin_ws
Source space: /home/ferstar/catkin_ws/src
Build space: /home/ferstar/catkin_ws/build
Devel space: /home/ferstar/catkin_ws/devel
Install space: /home/ferstar/catkin_ws/install
......

导出软件包路径到环境变量
$ . ~/catkin_ws/devel/setup.zsh
输出

5. 软件包依赖

5.1 列出初始依赖

rospack depends1 beginner_tutorials
输出
std_msgs
rospy
roscpp

所有依赖关系都存储在package.xml文件中

$ roscd beginner_tutorials
$ cat package.xml

...
catkin
roscpp
rospy
std_msgs
...

tab补全时如果发现如下权限不够的提示:
error while crawling /home/ferstar: boost::filesystem::status: Permission denied: "/home/ferstar/.gvfs
直接干掉这个目录
sudo umount ~/.gvfs
sudo rm -rf .gvfs

输出

5.2 关联依赖

顾名思义,就是依赖的包还有依赖。。。囧rz
比如rospack depends1 rospy
输出

genpy
roscpp
rosgraph
rosgraph_msgs
roslib
std_msgs

这个略烦,好在ros有自己的办法列出所有依赖关系
rospack depends beginner_tutorials
输出同wiki

6. 自定义软件包

6.1 自定义package.xml

默认catkin_create_pkg工具已经自动建立该文件,照猫画虎即可,可以修改的信息有,描述,标签,许可,依赖等等

6.2 自定义CMakeLists.txt

也是自动生成,用以指导编译程序如何编译安装软件包

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注