1. 程式人生 > >catkin工作空間)

catkin工作空間)

ROS學習筆記一(ROS的catkin工作空間)

安裝完成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目錄,發現多了兩個資料夾build,devel:

可以看到在devel目錄下,有很多setup.*sh檔案,讀取這些檔案中的任何一個都會將當前工作空間的環境變數置於所有環境變數的最上層。如果我們開啟這些檔案會發現,最終都是要讀取setup.sh檔案,這個檔案中

[3]定義了catkin_ws空間所需要的環境變數。 

[email protected]:~/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