ROS创建工作空间以及功能包

1.工作空间
工作空间(workspace)是一个存放工程开发相关文件的文件夹
src:代码空间(SOurce Space)
build:编译空间(Build Space)
devel:开发空间(Development Space)
install:安装空间(Install Space)
在这里插入图片描述2.创建工作空间
创建工作空间

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

编译工作空间

cd ~/catkin_ws/
catkin_make

设置环境变量

source devel/setup.bash

检查环境变量

echo $ROS_PACKAGE_PATRH

在终端中进行设置:

~/Downloads/ROS$ mkdir catkin_ws
~/Downloads/ROS$ cd catkin_ws/
~/Downloads/ROS/catkin_ws$ mkdir src
~/Downloads/ROS/catkin_ws$ cd src
~/Downloads/ROS/catkin_ws/src$ catkin_init_workspace 
Creating symlink "/home/wyh/Downloads/ROS/catkin_ws/src/CMakeLists.txt" pointing to "/opt/ros/kinetic/share/catkin/cmake/toplevel.cmake"
~/Downloads/ROS/catkin_ws/src$ cd ..
~/Downloads/ROS/catkin_ws$ catkin_make
Base path: /home/wyh/Downloads/ROS/catkin_ws
Source space: /home/wyh/Downloads/ROS/catkin_ws/src
Build space: /home/wyh/Downloads/ROS/catkin_ws/build
Devel space: /home/wyh/Downloads/ROS/catkin_ws/devel
Install space: /home/wyh/Downloads/ROS/catkin_ws/install
####
####Running command: "cmake /home/wyh/Downloads/ROS/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/wyh/Downloads/ROS/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/wyh/Downloads/ROS/catkin_ws/install -G Unix Makefiles" in "/home/wyh/Downloads/ROS/catkin_ws/build"
####
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 8.4.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/wyh/Downloads/ROS/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/kinetic
-- This workspace overlays: /opt/ros/kinetic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.12", 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/wyh/Downloads/ROS/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/gmock': gtests will be built
-- Found gmock sources under '/usr/src/gmock': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.12") 
-- 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.20
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wyh/Downloads/ROS/catkin_ws/build
####
####Running command: "make -j8 -l8" in "/home/wyh/Downloads/ROS/catkin_ws/build"
####
wyh@wyh-ThinkPad-E490:~/Downloads/ROS/catkin_ws$ catkin_make install
Base path: /home/wyh/Downloads/ROS/catkin_ws
Source space: /home/wyh/Downloads/ROS/catkin_ws/src
Build space: /home/wyh/Downloads/ROS/catkin_ws/build
Devel space: /home/wyh/Downloads/ROS/catkin_ws/devel
Install space: /home/wyh/Downloads/ROS/catkin_ws/install
####
####Running command: "make cmake_check_build_system" in "/home/wyh/Downloads/ROS/catkin_ws/build"
####
####
####Running command: "make install -j8 -l8" in "/home/wyh/Downloads/ROS/catkin_ws/build"
####
Install the project...
-- Install configuration: ""
-- Installing: /home/wyh/Downloads/ROS/catkin_ws/install/_setup_util.py
-- Installing: /home/wyh/Downloads/ROS/catkin_ws/install/env.sh
-- Installing: /home/wyh/Downloads/ROS/catkin_ws/install/setup.bash
-- Installing: /home/wyh/Downloads/ROS/catkin_ws/install/local_setup.bash
-- Installing: /home/wyh/Downloads/ROS/catkin_ws/install/setup.sh
-- Installing: /home/wyh/Downloads/ROS/catkin_ws/install/local_setup.sh
-- Installing: /home/wyh/Downloads/ROS/catkin_ws/install/setup.zsh
-- Installing: /home/wyh/Downloads/ROS/catkin_ws/install/local_setup.zsh
-- Installing: /home/wyh/Downloads/ROS/catkin_ws/install/.rosinstall

其中catkin_make install作用是产生install空间
创建完成后文件夹如下图所示:
在这里插入图片描述
src存放源码,install存放最终编译形成的可执行文件,devel存放开发过程中的可执行文件
build存放中间位二进制文件,基本用不到
3.创建功能包
同一个工作空间下,不允许存在同名功能包
不同工作空间下,
指令模式:

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

后面的依赖是指在运行时需要依赖ROS中的哪些功能包
创建功能包

cd ~/catkin_ws/src
catkin_create_pkg test_pkg std_msgs rospy roscpp

在这里插入图片描述
在这里插入图片描述这里的src放置功能包的代码文件,比如cpp文件等都可以放在这里面
include是放置头文件,比如cpp的头文件
编译功能包

cd ~/catkin_ws
catkin_make
source ~/catkin_ws/devel/setup.bash

最终的文件结构:
在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

yhwang-hub

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

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

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

打赏作者

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

抵扣说明:

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

余额充值