工作空间 workspace :存放工程开发相关的文件夹
src:代码空间(source space)
build:编译空间(build space)
devel:开发空间(development space)
install:安装空间(install space)
按图操作创建ros工作空间:
1、mkdir -p 递归创建目录,就算上级目录不存在,也会按照目录层级自动创建目录
2、catkin_init_workspace :初始化把当前文件夹变成workspace工作空间
编译工作空间:回到根目录编译,pwd 命令查看当前目录
1、$ catkin_make 编译工作空间
2、$ catkin_make install 创建并编译install 目录
在src目录下创建功能包,并编译功能包
1、$ catkin_create_pkg test_pkg std_msgs rospy roscpp
2.同样回到根目录下
$ cd ~/catkin_ws
$ catkin_make
$ source ~/catkin_ws/devel/setup.bash(设置环境变量)
$ echo $ROS_PACKAGE_PATH(检查环境变量)
结束,注意:
同一个工作空间下,不允许存在同名功能包
不同工作空间下,允许存在同名功能包
package.xml文件
catkin_make遇到问题:
Could NOT find rospy (missing: rospy_DIR)
-- Could not find the required component 'rospy'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
Could not find a package configuration file provided by "rospy" with any of
the following names:
rospyConfig.cmake
rospy-config.cmake
Add the installation prefix of "rospy" to CMAKE_PREFIX_PATH or set
"rospy_DIR" to a directory containing one of the above files. If "rospy"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
test_pkg/CMakeLists.txt:10 (find_package)
大概意思就是缺少rospy xx 等等,按照缺啥补啥的思想,我的ros是melodic版本,我就补这个版本的rospy即可,其他版本请修改:sudo apt-get install ros - ‘版本’ - ‘xx’
sudo apt-get install ros-melodic-rospy
安装完之后再catkin_make,编译就通过了