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

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