在这里详述 roschina/教程/安装与配置ROS环境。

(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Install and configure your ROS environment

Description: This tutorials walks you through installing ROS and setting up your ROS environment on your computer.

Tutorial Level: BEGINNER

Next Tutorial: Navigating the ROS Filesystem

安装 ROS

在阅读下面内容前,请先安装好ROS最新版软件包,安装指南请参照ROS installation instructions

Note: 如果您使用类似'apt'的包管理器安装ROS, 这些ROS包就没有写权限,并且也不能被您的用户权限修改. 当您需要使用ROS包的源程序或者创建新的ROS包时,您需要工作在您有权限读写的目录下,例如home文件夹。

管理您的ROS环境

当安装ROS时,您会被提示'source'一些setup.*sh文件,或者添加这个'sourcing'到您的shell启动脚本中,需要这样是因为ROS依赖shell环境变量。这使得针对不同版本的ROS或针对不同的套包更容易开发。

如果您有任何finding或者使用ROS包的问题,请确认您的ROS环境已经正确设置了。 一个好的方法是确认 environment variablesROS_ROOT相似,并且ROS_PACKAGE_PATH已经被设置好了:

$ printenv | grep ROS

如果环境变量没有设置,您可能需要'source'一些setup.*sh文件.

环境变量设置文件已经被创建好了,但是可能在不同的地方.

  • 在使用包管理器安装ROS包的时候已经提供了setup.*sh文件
  • rosbuild workspaces 使用rosws工具提供了setup.*sh 文件.

  • Setup.*sh 文件在buildinginstalling catkin 包的时候被创建.

Note: 通过本教程您将会看到rosbuildcatkin两种参考。这是两种组织和build您的ROS代码的方法。通常来说,rosbuild 容易使用而且简单,而catkin使用的是更加标准的CMake编译所以更复杂一些,但它更加灵活一些,尤其是对想要集成外部代码库或发布自己的软件的人来说更加如此。详细的分解请看catkin or rosbuild.

如果您在Ubuntu上使用apt来安装ROS,您会有一个setup.*sh文件在'/opt/ros/<distro>/'目录里,并且您可以向下面一样source它们:

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

可以使用您自己的ROS版本的缩写代替<distro>

比如您使用ROS Kinetic,应该是这样的:

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

您每次打开新的shell运行ROS命令的时候都需要运行这个命令,除非您把这行添加到您的 .bashrc 这样的处理可以允许您在同一个计算机上安装和切换各种不同版本的ROS(比如indigo和kinetic).

在别的操作系统上,您可以在安装的地方发现这些setup.*sh文件.

创建 ROS Workspace

These instructions are for ROS Groovy and later. For ROS Fuerte and earlier, select rosbuild.

Let's create and build a catkin workspace:

$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/
$ catkin_make

The catkin_make command is a convenience tool for working with catkin workspaces. Running it the first time in your workspace, it will create a CMakeLists.txt link in your 'src' folder.

Python 3 users in ROS Melodic and earlier: note, if you are building ROS from source to achieve Python 3 compatibility, and have setup your system appropriately (ie: have the Python 3 versions of all the required ROS Python packages installed, such as catkin) the first catkin_make command in a clean catkin workspace must be:

$ catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3

This will configure catkin_make with Python 3. You may then proceed to use just catkin_make for subsequent builds.

Additionally, if you look in your current directory you should now have a 'build' and 'devel' folder. Inside the 'devel' folder you can see that there are now several setup.*sh files. Sourcing any of these files will overlay this workspace on top of your environment. To understand more about this see the general catkin documentation: catkin. Before continuing source your new setup.*sh file:

$ source devel/setup.bash

To make sure your workspace is properly overlayed by the setup script, make sure ROS_PACKAGE_PATH environment variable includes the directory you're in.

$ echo $ROS_PACKAGE_PATH
/home/youruser/catkin_ws/src:/opt/ros/kinetic/share

When working with ROS source code, it is often useful to do so in a "workspace". For the following ROS tutorials you will need an area for working on tutorials and creating new ROS stacks and packages.

rosws is a tool that provides a uniform interface to various version control systems such as SVN, Git and Mercurial and for managing all packages installed in a ROS overlay. An extensive tutorial on rosws can be found here.

Creating a new workspace

The following command creates a new workspace in ~/fuerte_workspace which extends the set of packages installed in /opt/ros/fuerte:

rosws init ~/fuerte_workspace /opt/ros/fuerte

Note: rosws is part of the rosinstall package, which is not installed by default. The following command downloads it using the Ubuntu package manager:

sudo apt-get install python-rosinstall

Creating a sandbox directory for new packages

New packages need to be put in a path that is in the variable ROS_PACKAGE_PATH. All directories that are managed by rosws, i.e. that have been added using rosws are automatically added to the ROS_PACKAGE_PATH when the file setup.bash of the corresponding workspace is sourced. Although new packages should always be put in repositories that have been installed using rosws, it can be very convenient to have a sandbox directory where for instance packages created during the tutorials can be put without requiring any additional rosws commands. For that we create a new directory sandbox and add it to the hidden .rosinstall file with rosws:

mkdir ~/fuerte_workspace/sandbox
rosws set ~/fuerte_workspace/sandbox

Every time the entries in the workspace change, it is necessary to re-source ~/fuerte_workspace/setup.bash to make sure that the updated ROS_PACKAGE_PATH is used.

source ~/fuerte_workspace/setup.bash

It is very common to replace the line source /opt/ros/fuerte/setup.bash to source the setup.bash in ~/fuerte_workspace or whichever workspace you use most often.

A more complete ROS Workspace tutorial can be found here.

Confirmation

To confirm that your package path has been set, echo the ROS_PACKAGE_PATH variable.

$ echo $ROS_PACKAGE_PATH

You should see something similar to:

/home/your_user_name/fuerte_workspace/sandbox:/opt/ros/fuerte/share:/opt/ros/fuerte/stacks

现在环境已经安装设置好了,接下来看ROS文件系统教程.

Note: 上面部分是翻译官方教程,下面为之前老版本2012年的教程,感谢之前作者LuZhiShen的教程,留做纪念,上面做完没问题可以不用看下面的部分了。 2016.10.5 translate by xy1zzz

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~万恶的分界线 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

old version 创建 ROS Workspace

首先需要一个工作区域来创建新的ROS stacks 和 packages。先在home目录中创建一个 ros_workspace 目录。

mkdir ~/ros_workspace

(注:以下部分为electric配置方式,fuerte的配置方式见此小节之后注释)

然后新建一个 bash 脚本来配置ROS工作环境。该脚本名称为 setup.sh

 #!/bin/sh
 source /opt/ros/electric/setup.bash
 export ROS_ROOT=/opt/ros/electric/ros
 export PATH=$ROS_ROOT/bin:$PATH
 export PYTHONPATH=$ROS_ROOT/core/roslib/src:$PYTHONPATH
 export ROS_PACKAGE_PATH=~/ros_workspace:/opt/ros/electric/stacks:$ROS_PACKAGE_PATH

这个setup.sh脚本添加 'ros_workspace' 目录到环境变量ROS_PACKAGE_PATH中。现在执行这个脚本 setup.sh:

. setup.sh

并确认数据包路径已经被设置到环境变量中.

echo $ROS_PACKAGE_PATH

命令执行结果类似如下:

  • /home/user/ros_workspace:/opt/ros/electric/stacks

将setup.sh文件放到你的宿主目录中,并在文件.bashrc中添加如下一行,以确保下次登录自动执行

source  ~/setup.sh

(注:以上部分是electric的配置方式,fuerte的配置方式见下,到下一注释处结束此小节)

每当一个新的界面(shell)启动时,自动设置ROS workspace很方便:

echo "export ROS_PACKAGE_PATH=~/ros_workspace:$ROS_PACKAGE_PATH" >> ~/.bashrc
echo "export ROS_WORKSPACE=~/ros_workspace" >> ~/.bashrc
. ~/.bashrc

为了确认你的package路径设置正确,回显 ROS_PACKAGE_PATH 变量:

echo $ROS_PACKAGE_PATH

你应该能看到类似的结果:

/home/user/ros_workspace:/opt/ros/fuerte/share:/opt/ros/fuerte/stacks

(注:以上部分是fuerte的配置方式,至此两种配置方式的不同之处结束)

Wiki: roschina/教程/安装与配置ROS环境 (last edited 2016-10-04 18:38:09 by xy1zzz)