二维激光SLAM是无人机进行二维运动规划和建图的前提,同时也是SLAM中较为简单的定位算法,其功能是构建二维栅格地图,一般用于机器人/无人机在封闭环境下的定位和导航。XTDrone环境搭建见链接,不再赘述。
HectorSLAM安装
ros自带有HectorSLAM代码包,直接安装即可(笔者的运行环境为ros-noetic)
sudo apt install ros-noetic-hector-slam*
sudo apt install ros-noetic-map-server
安装好后复制相关文件
roscd hector_slam_launch
sudo cp ~/XTDrone/sensing/slam/laser_slam/hector_slam/hector_slam_xtdrone.launch launch/
sudo cp ~/XTDrone/sensing/slam/laser_slam/hector_slam/mapping_xtdrone.rviz rviz_cfg/mapping_xtdrone.rviz
roscd hector_imu_attitude_to_tf/
sudo cp ~/XTDrone/sensing/slam/laser_slam/hector_slam/hector_imu_xtdrone.launch launch/
roscd hector_mapping/
sudo cp ~/XTDrone/sensing/slam/laser_slam/hector_slam/hector_mapping_xtdrone.launch launch/
HectorSLAM使用
将indoor3.launch中的sdf模型设为iris_2d_lidar(若已经设好则不用改动)
启动仿真环境
roslaunch px4 indoor3.launch
启动HectorSLAM
roslaunch hector_slam_launch hector_slam_xtdrone.launch
启动通讯脚本
cd ~/XTDrone/communication/
python multirotor_communication.py iris 0
将HectorSLAM输出的2D位姿和高度值(由1D激光测距仪获得),转换为mavros话题
cd ~/XTDrone/sensing/slam/laser_slam/script/
python laser_transfer.py iris 0 hector
启动键盘控制脚本,用键盘控制无人机绕着地图飞一圈回来
cd ~/XTDrone/control/keyboard/
python multirotor_keyboard_control.py iris 1 vel
最后保存地图,后续可用于二维运动规划
rosrun map_server map_saver -f ~/XTDrone/motion_planning/2d/map/indoor3