第七弹 ROS创建工作空间与功能包

1. 工作空间(workspace)

工作空间,相当于c++编程或者32单片机开发里创建的项目,是一个存放开发相关文件的文件夹。

该空间里有四个文件夹,分别是“src(代码空间)”、"build(编译空间)"、"devel(开发空间)"、"install(安装空间)"。

  • 创建工作空间

mkdir  catkin_ws

cd   catkin_ws/

mkdir src

cd  src/

catkin_init_workspace

  (小科普:刚开始看到catkin的时候也很蒙,感觉是个完全跟ROS风马牛不相及的东西,怎么取了这么个名字?catkin这个名字准确翻译过来叫做“葇荑花序”,是无限花序的一种,花轴上着生许多无柄或短柄的单性花( 雌花或雄花) ,有花被或花被缺。它与ROS有什么关系呢?因为ROS早期的创始实验室叫做Willow Garage,而柳树(Willow)的花就属于catkin这种花序。)

  • 编译空间

尽管没有代码,仍然是可以编译的。

catkin_make

wood@wood:~/catkin_ws$ catkin_make
Base path: /home/wood/catkin_ws
Source space: /home/wood/catkin_ws/src
Build space: /home/wood/catkin_ws/build
Devel space: /home/wood/catkin_ws/devel
Install space: /home/wood/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/wood/catkin_ws/build"
####
####
#### Running command: "make -j2 -l2" in "/home/wood/catkin_ws/build"
####
  • 安装空间

catkin_make  install

wood@wood:~/catkin_ws$ catkin_make install
Base path: /home/wood/catkin_ws
Source space: /home/wood/catkin_ws/src
Build space: /home/wood/catkin_ws/build
Devel space: /home/wood/catkin_ws/devel
Install space: /home/wood/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/wood/catkin_ws/build"
####
####
#### Running command: "make install -j2 -l2" in "/home/wood/catkin_ws/build"
####
Install the project...
-- Install configuration: ""
-- Installing: /home/wood/catkin_ws/install/_setup_util.py
-- Installing: /home/wood/catkin_ws/install/env.sh
-- Installing: /home/wood/catkin_ws/install/setup.bash

2.    功能包

  • 创建功能包

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

例如: catkin_create_pkg   test_pkg   roscpp    rospy    std_msgs

wood@wood:~/catkin_ws/src$ catkin_create_pkg test_pkg roscpp rospy std_msgs
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/wood/catkin_ws/src/test_pkg. Please adjust the values in package.xml.

  •  编译功能包

catkin_make   

wood@wood:~/catkin_ws$ catkin_make
Base path: /home/wood/catkin_ws
Source space: /home/wood/catkin_ws/src
Build space: /home/wood/catkin_ws/build
Devel space: /home/wood/catkin_ws/devel
Install space: /home/wood/catkin_ws/install
####
#### Running command: "cmake /home/wood/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/wood/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/wood/catkin_ws/install -G Unix Makefiles" in "/home/wood/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/wood/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/melodic
-- This workspace overlays: /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/wood/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/wood/catkin_ws/build
####
#### Running command: "make -j2 -l2" in "/home/wood/catkin_ws/build"
####
  •  运行功能包的某个程序

需要先设置一个环境变量。(非常重要)

source devel/setup.bash
让系统能够找到工作空间。

echo $ROS_PACKAGE_PATH

wood@wood:~/catkin_ws$ source devel/setup.bash
wood@wood:~/catkin_ws$ 
wood@wood:~/catkin_ws$ 
wood@wood:~/catkin_ws$ echo $ROS_PACKAGE_PATH
/home/wood/catkin_ws/src:/opt/ros/melodic/share
wood@wood:~/catkin_ws$ 
wood@wood:~/catkin_ws$ 

在同一工作空间下,不允许存在同名功能包。

不同工作空间下,允许同名功能包。

简单点,就是一副扑克里只有一张大王,但是每副扑克都可以有大王。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是刃小木啦~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值