ROS创建工作空间和功能包

创建工作空间和功能包

ROS中的工作空间是存放工程开发相关文件的文件夹。主要包括四个文件夹:

  • src 代码空间(功能包的代码、配置文件和其他的一些文件)
  • build 编译空间 (编译过程中产生的文件)
  • devel 开发空间 (编译生成的可执行文件、库)
  • install 安装空间 (使用install指令安装成功的指定位置)

创建工作空间

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

使用以上的命令来创建工作空间。可以看到~/catkin_ws/src 文件夹下变成了以下的情况:
ROS创建工作空间和功能包_第1张图片

编译

$ catkin_make
Base path: /home/devil/catkin_ws
Source space: /home/devil/catkin_ws/src
Build space: /home/devil/catkin_ws/build
Devel space: /home/devil/catkin_ws/devel
Install space: /home/devil/catkin_ws/install
####
#### Running command: "cmake /home/devil/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/devil/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/devil/catkin_ws/install -G Unix Makefiles" in "/home/devil/catkin_ws/build"
####
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- 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/devil/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/devil/catkin_ws/devel;/opt/ros/melodic
-- This workspace overlays: /home/devil/catkin_ws/devel;/opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.17", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/devil/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.17") 
-- Looking for pthread.h
-- Looking for 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  
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.29
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- Configuring done
-- Generating done
-- Build files have been written to: /home/devil/catkin_ws/build
####
#### Running command: "make -j12 -l12" in "/home/devil/catkin_ws/build"
####

编译使用ros指定的编译工具来编译工程文件,但是注意一定要在工作空间的根目录下面来执行这个命令。
我们来看一下现在工作空间的情况:

$ ls
build  devel  src

可以看到里面包含三个文件夹,对比上面的标准不难发现,少了一个install文件夹。这时候需要使用以下命令

$ catkin_make install
Base path: /home/devil/catkin_ws
Source space: /home/devil/catkin_ws/src
Build space: /home/devil/catkin_ws/build
Devel space: /home/devil/catkin_ws/devel
Install space: /home/devil/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/devil/catkin_ws/build"
####
####
#### Running command: "make install -j12 -l12" in "/home/devil/catkin_ws/build"
####
Install the project...
-- Install configuration: ""
-- Installing: /home/devil/catkin_ws/install/_setup_util.py
-- Installing: /home/devil/catkin_ws/install/env.sh
-- Installing: /home/devil/catkin_ws/install/setup.bash
-- Installing: /home/devil/catkin_ws/install/local_setup.bash
-- Installing: /home/devil/catkin_ws/install/setup.sh
-- Installing: /home/devil/catkin_ws/install/local_setup.sh
-- Installing: /home/devil/catkin_ws/install/setup.zsh
-- Installing: /home/devil/catkin_ws/install/local_setup.zsh
-- Installing: /home/devil/catkin_ws/install/.rosinstall

在查看就会发现出现了install文件夹。

创建功能包

不能直接把代码放进文件夹里面进行编译,要想创建功能包需要使用以下的命令:

$ catkin_create_pkg test_pkg std_msgs rospy roscpp
Created file test_pkg/package.xml
Created file test_pkg/CMakeLists.txt
Created folder test_pkg/include/test_pkg
Created folder test_pkg/src
Successfully created files in /home/devil/catkin_ws/src/test_pkg. Please adjust the values in package.xml.

catkin_create_pkg是创建功能包的命令,test_pkg是我们创建功能包的名字,后面的三个是创建功能包的依赖。其中std_msgs是标准的消息文件。然后查看src文件夹:

$ tree 
.
├── CMakeLists.txt
├── include
│   └── test_pkg
├── package.xml
└── src

3 directories, 2 files

可以看到test_pkg下面有include src CMakeLists.txt package.xml 四个文件(夹)。
当你创建完之后就可以按照上面的步骤字再次编译一次,当然你编译的肯定是一个空功能包,但是无所谓嘛。

$ catkin_make
Base path: /home/devil/catkin_ws
Source space: /home/devil/catkin_ws/src
Build space: /home/devil/catkin_ws/build
Devel space: /home/devil/catkin_ws/devel
Install space: /home/devil/catkin_ws/install
####
#### Running command: "cmake /home/devil/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/devil/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/devil/catkin_ws/install -G Unix Makefiles" in "/home/devil/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/devil/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/devil/catkin_ws/devel;/opt/ros/melodic
-- This workspace overlays: /home/devil/catkin_ws/devel;/opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.17", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/devil/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.17") 
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.29
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - test_pkg
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'test_pkg'
-- ==> add_subdirectory(test_pkg)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/devil/catkin_ws/build
####
#### Running command: "make -j12 -l12" in "/home/devil/catkin_ws/build"
####

可以看到中间有一部分出现了我们创建的功能包。

package.xml简介



  test_pkg  //功能包的名称
  0.0.0    //功能包的版本号
  The test_pkg package   //叙述

  
  
  
  devil


  
  
  
  TODO      //开源许可证


  
  
  
  


  
  
  
  


  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  catkin   ///以下是功能包的依赖信息
  roscpp
  rospy
  std_msgs
  roscpp
  rospy
  std_msgs
  roscpp
  rospy
  std_msgs


  
  
    

  

你可能感兴趣的:(ROS,linux,ubuntu)