1.检测环境变量
运行printenv | grep ROS命令,有如下返回值则表示环境变量配置正确:
ROS_ROOT=/opt/ros/kinetic/share/ros
ROS_PACKAGE_PATH=/opt/ros/kinetic/share
ROS_MASTER_URI=http://localhost:11311
ROSLISP_PACKAGE_DIRECTORIES=
ROS_DISTRO=kinetic
ROS_ETC_DIR=/opt/ros/kinetic/etc/ros
如无,需执行source /opt/ros/kinetic/setup.bash命令设置当前Terminal的ROS环境变量。
2.创建ROS Workspace
mkdir -p ~/ros/catkin_ws/src
cd ~/ros/catkin_ws/src
catkin_init_workspace
当执行完最后一条命令时有如下提示:
Creating symlink "/home/guochongxin/ros/catkin_ws/src/CMakeLists.txt"pointing to "/opt/ros/kinetic/share/catkin/cmake/toplevel.cmake"
即在src目录下创建一个CMakeLists.txt文件,该文件是个链接文件,链接到toplevel.cmake文件。
尽管只有CMakeLists.txt文件,接下来还是可以使用如下命令编译工作空间:
cd ~/ros/catkin_ws
catkin_make
执行完命令后,会创建build和devel两目录,与src同级,接下来使用如下命令完成配置:
source devel/setup.bash
此时执行如下命令确认环境变量:
echo $ROS_PACKAGE_PATH
我这边的值如下:
/home/guochongxin/ros/catkin_ws/src:/opt/ros/kinetic/share
参考网址:ROS/Tutorials/InstallingandConfiguringROSEnvironment - ROS Wiki