您的位置:首页 > 其它

ROS学习手记 - 1了解并安装ROS+创建ROS_Package

2015-07-03 17:55 489 查看
ROS学习手记:

开始之前:

先看了《认识ROS操作系统(2015版)》,了解了ROS的基本概念。

这里补充一点ROS的发展历程,以便了解catkin的由来,及willow garage公司与ROS的关系:

ROS was originally developed in 2007 under the name switchyard by the Stanford Artificial Intelligence Laboratory in support of the Stanford AI Robot STAIR (STanford AI Robot) [6][7] project.From 2008 until 2013, development was performed primarily at Willow
Garage, a robotics research institute/incubator. During that time, researchers at more than twenty institutions collaborated with Willow Garage engineers in a federated development model.[8][9]

In February 2013, ROS stewardship transitioned to the Open Source Robotics Foundation.[10] In August 2013, a blog posting[11] announced that Willow Garage would be absorbed by another company started by its founder, Suitable Technologies. The support responsibilities
for the PR2 created by Willow Garage were also subsequently taken over by Clearpath Robotics.[12] (https://en.wikipedia.org/wiki/Robot_Operating_System)

1. ROS 的安装,

ROS官方Tutorial里的Installing and Configuring Your ROS Environment比较繁琐。我们采用虚拟机搭载Ubuntu_for_ROS的方式。

具备了虚拟机使用经验的同学可以搜“Ubuntu for ROS”进行下载 .iso 文件在虚拟机里安装。笔者使用的是VirtualBox作为虚拟机工具。这里就不多说了。

需要注意的是,ROS有很多版本,对应Ubuntu不同的版本,别搞错了。我用的 Ubuntu12.04 + ROS_Hydro(ubuntu12.04-i386-ros-exbot-h2-140520.iso)

运行如下命令可看ROS的Package Path是否配置完毕。

>> echo $ROS_PACKAGE_PATH

2. 熟悉一下ROS的文件系统命令行

roscd, rosls, rospack 等命令的熟悉:

3. ROS Package

开始之前,ROS有这几个概念需要了解:

>>catkin - catkin is the official build system of ROS(相当于GNC Make,CMake这样的编译链接系统). The name catkin comes from the tail-shaped flower cluster found on willow trees -- a reference to Willow Garage where catkin was created.(http://wiki.ros.org/catkin/conceptual_overview)

>>Packages - ROS的基本组织单位,为了很好的定制和重用,包含库、数据集、节点、配置文件、第三方软件或任何有用的模型。Packages are the most atomic unit of build and the unit of release.

>>Metapackages -

>>Manifest

>>msg

preference: http://wiki.ros.org/Packages
>>srv

-- Create an empty catkin workspace

参考: http://wiki.ros.org/catkin/Tutorials/create_a_workspace
我装的ubuntu for ROS应该是已经source了/opt/ros/hydro/setup.bash,否则要运行:

$ source /opt/ros/hydro/setup.bash

开始来create a catkin workspace(我装的ubuntu for ROS应该是已经建立了workspace):

$ mkdir -p ~/catkin_ws/src

$ cd ~/catkin_ws/src

$ catkin_init_workspace

但是我的这个路径下已经有了文件了:

exbot@ubuntu:~/catkin_ws/src$ ls

CMakeLists.txt exbot_xi

cd ~/catkin_ws/src/exbot_xi && ls

exbotxi_bringup exbotxi_example exbotxi_rviz README.md

exbotxi_description exbotxi_nav exbotxi_teleop

看样子已经有很多包了,所以我就没搞 catkin_init_workspace

4. 创建Package

跟着这个教程一步步来:http://wiki.ros.org/ROS/Tutorials/CreatingPackage

一个catkin Package包含的东西:1. package.xml file; 2.CMakeLists.txt; 3.其他文件.

Package不共用一个文件夹,nest(嵌套)也不行。

现在我们来Create一个Package:

$ cd ~/catkin_ws/src

$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp

Created file beginner_tutorials/CMakeLists.txt

Created file beginner_tutorials/package.xml

Created folder beginner_tutorials/include/beginner_tutorials

Created folder beginner_tutorials/src

Successfully created files in /home/exbot/catkin_ws/src/beginner_tutorials. Please adjust the values in package.xml.

Catkin_create_pkg requires that you give it a package_name and optionally a list of dependencies on which that package depends.

use the catkin_create_pkg script to create a new package called 'beginner_tutorials' which depends on std_msgs, roscpp, and rospy.



== Building a catkin workspace and sourcing the setup file

Now you need to build the packages in the catkin workspace:

$ cd ~/catkin_ws

$ catkin_make #尽管devel里已经有东西了,新建了一个catkin package就要catkin_make一次

After the workspace has been built it has created a similar structure in the devel subfolder as you usually find under /opt/ros/$ROSDISTRO_NAME. 这里ROSDISTRO_NAME = hydro



-- ubuntu for ROS已有的文件结构 --

~/catkin_ws

/build



/devel

env.sh etc lib setup.bash setup.sh _setup_util.py setup.zsh share

/src

/CMakeLists.txt

/exbot_xi

/exbotxi_bringup

/exbotxi_example

/exbotxi_rviz

/exbotxi_description

/exbotxi_nav

/exbotxi_teleop

README.md

/beginner_tutorials #这个就是这回新增的

/include

/src

CMakeLists.txt

package.xml



-- add the workspace to your ROS environment

To add the workspace to your ROS environment you need to source the generated setup file:

$ . ~/catkin_ws/devel/setup.bash

这样,我们就可以通过roscd命令找到这个package: roscd beginner_tutorials

至此,我们完成了Create, Build, Add to ROS Env三个步骤。

== package dependencies

用一个工具来看dependencies: rospack depends1 package_name

结果运行以下命令时候出现问题:

$ rospack depends1 beginner_tutorials

[rospack] Error: the rosdep view is empty: call 'sudo rosdep init' and 'rosdep update'

当运行sudo rosdep init时,提示要移除一些东西,再init再update.

于是,按照csdn有个博客的提示,需要如下依次执行:

$ sudo rm -rf $HOME/.ros/rosdep

$ sudo rm -rf /etc/ros/rosdep

$ sudo rm /etc/ros/rosdep/sources.list.d/20-default.list

$ sudo apt-get install python-rosdep

$ sudo rosdep init

$ rosdep update

再rospack depends1 package_name:

$ rospack depends1 beginner_tutorials

roscpp

rospy

std_msgs

如果是rospack depends beginner_tutorials即可显示所有包含nested的depends



== Customizing Your Package 定制你的Package

要一行行解释catkin_create_pkg命令建立的所有文件。

我们先来关注beginner_tutorials/package.xml文件

开始之前我们关注一下package.xml文件的基础知识

-- package.xml 文件基础 --

The package manifest is an XML file called package.xml that must be included with any catkin-compliant package's root folder. (http://wiki.ros.org/catkin/package.xml)

Other than a required <buildtool_depends> dependency on catkin, metapackages can only have “run dependencies” on packages of which they group.

和要求的<buildtool_depends> dependency 在catkin不同,metapackages 只能have run dependencies,这些是建立在它们group的package。太难翻了!

关于dependencies,这里有一段解释:


Programs often use some of the same files as each other. Rather than putting these files into each package, a separate package can be installed to provide them for all of the programs that need them. So, to install a program which needs one
of these files, the package containing those files must also be installed. When a package depends on another in this way, it is known as a package dependency. By specifying dependencies, packages can be made smaller and simpler, and duplicates of files and
programs are mostly removed.

When you install a program, its dependencies must be installed at the same time. Usually, most of the required dependencies will already be installed, but a few extras may be needed, too. So, when you install a package, don't be surprised if several other packages
are installed too - these are just dependencies which are needed for your chosen package to function properly.
four types of dependencies are specified using the following respective tags:

<buildtool_depend>

<build_depend>

<run_depend>

<test_depend>

A more realistic example that specifies build, runtime, and test dependencies could look as follows.
<package>
  <name>foo_core</name>
  <version>1.2.4</version>
  <description>
    This package provides foo capability.
  </description>
  <maintainer email="ivana@willowgarage.com">Ivana Bildbotz</maintainer>
  <license>BSD</license>

  <url>http://ros.org/wiki/foo_core</url>
  <author>Ivana Bildbotz</author>

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>message_generation</build_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>std_msgs</build_depend>

  <run_depend>message_runtime</run_depend>
  <run_depend>roscpp</run_depend>
  <run_depend>rospy</run_depend>
  <run_depend>std_msgs</run_depend>

  <test_depend>python-mock</test_depend>
</package>


Metapackages

It is often convenient to group multiple packages as a single logical package. This can be accomplished throughmetapackages. A metapackage is a normal package with the following export tag in the package.xml: 为了方便,多个package可以group成单个的逻辑package。就用matapackage来实现。一个metapackage就是一个普通package带了下面的export
tag 在它的package.xml里,就变成了metapackage。

<export>
   <metapackage />
 </export>

Other than a required <buildtool_depends> dependency oncatkin, metapackages can only have run dependencies on packages of which they group.

不需要有catkin作为buildtool depends, Metapackage可以只有run dependencies, 这些run dependencies就是它group的那些包,包们作这个metapackage的run_dependencies即可。

另外,它的CMakeLists.txt也要有点不同,它有一个 required, boilerplate CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8.3)
project(<PACKAGE_NAME>)
find_package(catkin REQUIRED)
catkin_metapackage()

Note: replace <PACKAGE_NAME> with the name of the metapackage.

Metapackage now have CMakeLists.txt files after a discussion about installing the package.xml files:
https://groups.google.com/forum/#!msg/ros-sig-buildsystem/mn-VCkl2OHk/dUsHBBjyK30J
所以,现在尽管Metapackage的package.xml文件是被安装了,但是,有个要求是要强制满足的。这个要求就是,其他packages应该不要依赖metapackages。通过要求用户不要脱离了建议的 boilerplate CMakeLists.txt 代码来避免形成对metapackages的依赖。

Additional Tags

<url> - A URL for information on the package, typically a wiki page on ros.org.

<author> - The author(s) of the package

package.xml就是这样了

它就是关于Tags的文档,所以看看下面这篇文章即可。

http://wiki.ros.org/ROS/Tutorials/CreatingPackage
到Dependency Tags就完成了学习。最后的 package.xml 文件内容如下:

<?xml version="1.0"?>
<package>
  <name>beginner_tutorials</name>
  <version>0.1.0</version>
  <description>The beginner_tutorials package</description>

  <maintainer email="you@yourdomain.tld">Your Name</maintainer>
  <license>BSD</license>
  <url type="website">http://wiki.ros.org/beginner_tutorials</url>
  <author email="you@yourdomain.tld">Jane Doe</author>

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>

  <run_depend>roscpp</run_depend>
  <run_depend>rospy</run_depend>
  <run_depend>std_msgs</run_depend>

</package>


Now that the
package.xml, which contains meta information, has been tailored to your package, you are ready to move on in the tutorials. TheCMakeLists.txt file created bycatkin_create_pkg
will be covered in the later tutorials about building ROS code.
Now that you've made a new ROS package, let'sbuild our ROS package.

ROS Stack/ Package等各元件层级结构:

[Repository1]

[Stack1]

[Package1]

[Nodes]

[Messages]

[Services]

[Libraries]

[Tools]

[/Package1]

[Package2]

[Nodes]

[Messages]

[Services]

[Libraries]

[Tools]

[/Package2]

[/Stack1]

[Stack2]

...

[/Stack2]

[/Repository1]

我的exbot帮我建立的ubuntu for ros版本是ros_hydro版本,

在/opt/ros/hydro/bin目录下,可以看到有个rosstack命令,

$ rosstack list

可以列出本机已经安装的stacks, 我们还可以安装第三方 stacks完成想要的功能。

总结

== 管理ROS环境变量 ==

1. Check the ROS env. variables like ROS_ROOT/ROS_PACKAGE_PATH

$ export | grep ROS

-----------

declare -x ROSLISP_PACKAGE_DIRECTORIES="/home/exbot/catkin_ws/devel/share/common-lisp"

declare -x ROS_DISTRO="hydro"

declare -x ROS_ETC_DIR="/opt/ros/hydro/etc/ros"

declare -x ROS_MASTER_URI="http://localhost:11311"

declare -x ROS_PACKAGE_PATH="/home/exbot/catkin_ws/src:/opt/ros/hydro/share:/opt/ros/hydro/stacks"

declare -x ROS_ROOT="/opt/ros/hydro/share/ros"

declare -x ROS_TEST_RESULTS_DIR="/home/exbot/catkin_ws/build/test_results"

-----------

2. source the setup.sh files

# source /opt/ros/<distro>/setup.bash



== 建立ROS Workspace (catkin)==


1. create a catkin workspace

$ mkdir -p ~/catkin_ws/src

$ cd ~/catkin_ws/src

$ catkin_init_workspace

2. Make

Even though the workspace is empty (there are no packages in the 'src' folder, just a single CMakeLists.txt link) you can still "build" the workspace:

$ cd ~/catkin_ws/

$ catkin_make

3. Source

$ source devel/setup.bash

4. Check:

$ echo $ROS_PACKAGE_PATH

/home/youruser/catkin_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks



=== 创建ROS Package (catkin) ===


1. 确认你的catkin Workspace:~/catkin_ws/

2. $ cd ~/catkin_ws/src

3. 创建package

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

4. 编译catkin Workspace:

cd ~/catkin_ws

catkin_make

5. Source the generated setup file:

$ . ~/catkin_ws/devel/setup.bash

6. 工具:

rospack

roscd <package_name>

7. Customize Your Packages:

http://wiki.ros.org/ROS/Tutorials/CreatingPackage#ROS.2BAC8-Tutorials.2BAC8-catkin.2BAC8-CreatingPackage.Customizing_Your_Package
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: