安装完成ROS indigo之后,需要查看环境变量是否设置正确,并通过创建一个简单的实例来验证ROS能否正常运行。

1 查看环境变量

在ROS的安装过程中,我们执行了如下命令:(此命令就是向当前用户添加ROS的环境变量)

echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
source ~/.bashrc

确认环境变量添加成功:printenv | grep ROS,结果如下,即说明环境变量设置成功:

ROS_ROOT=/opt/ros/indigo/share/ros
ROS_PACKAGE_PATH=/opt/ros/indigo/share:/opt/ros/indigo/stacks
ROS_MASTER_URI=http://localhost:11311
ROSLISP_PACKAGE_DIRECTORIES=
ROS_DISTRO=indigo
ROS_ETC_DIR=/opt/ros/indigo/etc/ros

2 创建ROS工作空间

我这里用的是ROS indigo,同样适用于ROS groovy及其以后的版本。
[1]创建并初始化一个catkin工作空间

$ mkdir -p ~/catkin_ws2/src
$ cd ~/catkin_ws2/src
$ catkin_init_workspace

catkin_init_workspace命令把当前目录初始化为一个ROS工作空间。

可通过来ls -l查看一下初始化之后的工作空间的内容。发现:catkin_ws目录下仅仅有一个刚才创建的src目录,src目录下只有一个指向一个cmake文件的符号连接文件。尽管现在catkin_ws目录是空的,但是我们仍可以

[2]编译该工作空间。

$ cd ~/catkin_ws2
$ catkin_make

终端结果:

Base path: /home/wj/catkin_ws2
Source space: /home/wj/catkin_ws2/src
Build space: /home/wj/catkin_ws2/build
Devel space: /home/wj/catkin_ws2/devel
Install space: /home/wj/catkin_ws2/install
####
#### Running command: "cmake /home/wj/catkin_ws2/src -DCATKIN_DEVEL_PREFIX=/home/wj/catkin_ws2/devel -DCMAKE_INSTALL_PREFIX=/home/wj/catkin_ws2/install -G Unix Makefiles" in "/home/wj/catkin_ws2/build"
####
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CATKIN_DEVEL_PREFIX: /home/wj/catkin_ws2/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/indigo
-- This workspace overlays: /opt/ros/indigo
-- Found PythonInterp: /usr/bin/python (found version "2.7.6") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/wj/catkin_ws2/build/test_results
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.18
-- BUILD_SHARED_LIBS is on
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wj/catkin_ws2/build
####
#### Running command: "make -j4 -l4" in "/home/wj/catkin_ws2/build"
####

【catkin_make命令是catkin工作空间非常有力的一个工具。】

此时再查看catkin_ws目录,发现多了两个文件夹builddevel

可以看到在devel目录下,有很多setup.*sh文件,读取这些文件中的任何一个都会将当前工作空间的环境变量置于所有环境变量的最上层。如果我们打开这些文件会发现,最终都是要读取setup.sh文件,这个文件中

[3]定义了catkin_ws空间所需要的环境变量。

wj@wj-Inspiron-5437:~/catkin_ws2$ source devel/setup.sh   //读取setup.sh文件

[4]确认已经加载catkin工作空间环境变量:echo $ROS_PACKAGE_PATH
结果:/home/wj/catkin_ws2/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks
这时ROS的环境变量已经创建好了。

3 总结

初始化ROS的catkin工作空间:catkin_init_workspace
编译ROS的catkin工作空间:catkin_make
读取当前catkin工作空间的环境变量:source devel/setup.sh
验证ROS工作空间的环境变量加载成功:echo $ROS_PACKAGE_PATH

 

posted on 2017-03-08 16:32  Jessica&jie  阅读(18088)  评论(0编辑  收藏  举报