Turtlebot3建图和导航仿真调试
Turtlebot3环境搭建
以Ubuntu16.04为平台,
在工作空间catkin_ws的src文件夹下安装turtlebot3和turtlebot3_simulation包:
$ git clone -b kinetic-devel https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
$ git clone -b kinetic-devel https://github.com/ROBOTIS-GIT/turtlebot3.git
$ git clone -b kinetic-devel https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
安装完成后编译:
$ cd ~/catkin_ws && catkin_make
测试:
设置环境变量:
$ source ~/catkin_ws/devel/setup.bash
添加模型声明(TURTLEBOT3_MODEL有三种:burger,waffle,waffle_pi):
$ export TURTLEBOT3_MODEL=waffle
启动gazebo仿真:
$ roslaunch turtlebot3_gazebo turtlebot3_world.launch
此时可能会出现小车“一飞冲天,开始蹦迪”的现象,下载模型文件(在/catkin_ws/src/turtlebot3_simulations/turtlebot3_gazebo路径下新建models文件夹,将模型文件放到里面)后现象消除:
网盘链接:https://pan.baidu.com/s/1QY9fLEaI_64pvC3NAz5Xlg
提取码:hfg2
gazebo打开后关闭再打开可能会出现异常关闭的问题:
通过关闭硬件加速解决:
$ export SVGA_VGPU10=0
SLAM环境搭建
turtlebot3包内包含slam算法gmapping,其他算法cartographer、hector、karto等需要额外下载。
gmapping算法包可能不完整,通过安装指令来补全:
$ sudo apt-get install ros-kinetic-gmapping
下载安装hector和karto:
安装hector:
$ sudo apt-get install ros-kinetic-hector-mapping
安装karto:
$ sudo apt-get install ros-kinetic-slam-karto
下载安装cartographer:
安装wstool和rosdep:
$ sudo apt-get install -y python-wstool python-rosdep ninja-build
创建工作空间:
$ mkdir cartographer_ws
$ cd cartographer_ws
$ wstool init src
获取源码:
$ wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_turtlebot/master/cartographer_turtlebot.rosinstall
$ wstool update -t src
安装依赖:
$ rosdep update
$ src/cartographer/scripts/install_proto3.sh
$ rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
编译安装:
$ catkin_make_isolated --install --use-ninja -j1
$ source install_isolated/setup.bash
添加到.bashrc:
$ echo "source ~/cartographer_ws/install_isolated/setup.bash" >> ~/.bashrc
仿真调试
Step1:打开终端,启动gazebo仿真世界模型;
$ source ~/catkin_ws/devel/setup.bash
$ export TURTLEBOT3_MODEL=waffle
$ export SVGA_VGPU10=0
$ roslaunch turtlebot3_gazebo turtlebot3_house.launch
Step2:新建终端,启动键盘控制节点;
$ source ~/catkin_ws/devel/setup.bash
$ export TURTLEBOT3_MODEL=waffle
$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
Step3:新建终端,启动rviz进行slam建图;
$ source ~/catkin_ws/devel/setup.bash
$ export TURTLEBOT3_MODEL=waffle
$ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=gmapping
或者:$ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=hector
或者:$ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=karto
或者:
$ source ~/catkin_ws/install_isolated/setup.bash
$ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=cartographer configuration_basename:=turtlebot3_lds_2d_gazebo.lua
Step4:通过键盘控制小车移动,扫描整个地图;
Step5:新建终端,保存地图;
$ rosrun map_server map_saver -f /map
cartographer创建的地图格式与gmapping、hector_slam等生成的地图格式不同,不能使用map_saver节点保存地图。需要使用以下命令保存地图:
(1)请求/finish_trajectory服务,完成轨迹,不再接收数据:
$ rosservice call /finish_trajectory 0
(2)请求/write_state服务,保存当前状态,其中路径可以根据需要自行更改:
$ rosservice call /write_state "{filename: '${HOME}/map.pbstream'}"
(3)运行cartographer_pbstream_to_ros_map节点,将保存的.pbstream文件转为.pgm和.yaml文件:
$ rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=${HOME}/map -pbstream_filename =${HOME}/map.pbstream -resolution=0.05
Step6:关闭slam,打开保存的地图并启动navigation导航;
$ roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=$HOME/map.yaml
这里使用 source ~/catkin_ws/devel/setup.bash 设置环境变量可能会有问题:
调整环境变量以解决问题:
$ source ~/catkin_ws/install_isolated/setup.bash
Step7:通过rviz中的2D Pose Estimate调整小车的初始位姿使其雷达点云与地图重合;
Step8:通过rviz中的2D Nav Goal设置目标位姿,小车会自动规划路径移动到目标点,gazebo中的小车会按照规划的路径进行移动,当在地图中添加障碍时小车会进行自主避障。