本篇文章旨在快速让读者实现运行LOAM系列3D激光SLAM算法并实时构建3d点云地图与2d栅格地图。废话不多说,直接开始~
首先说明我们要用到的3D点云地图转2D栅格地图的工具是octomap,附上高博教程链接octomap。
接下来就开始了:
第一步:安装octomap:
#安装octomap
sudo apt-get install ros-melodic-octomap-ros
sudo apt-get install ros-melodic-octomap-server
#安装octomap在rviz中的插件
sudo apt-get install ros-melodic-octomap-rviz-plugins
第二步:进入octomap安装目录,写个octomap_server节点的launch文件:
#进入octomap_server的launch文件夹
cd /opt/ros/melodic/share/octomap_server/launch
#创建launch文件
sudo touch octomap_server.launch
#给launch文件加可写权限
sudo chmod a+w octomap_server.launch
在octomap_server.launch文件中写入:
<launch>
<node pkg="octomap_server" type="octomap_server_node" name="octomap_server">
<!--resolution in meters per pixel-->
<param name="resulution" value="0.1" />
<!--name of the fixed frame,needs to be "/map" for SLAM-->
<param name="frame_id" type="string" value="/camera_init" />
<!--max range/depth resolution of the kinect meters-->
<param name="sensor_model/max_range" value="50.0" />
<param name="latch" value="true" />
<!--max/min height for occupancy map, should be in meters-->
<param name="pointcloud_max_z" value="1.6" />
<param name="pointcloud_min_z" value="0.8" />
<param name="graound_filter_angle" value="3.14" />
<!--topic from where pointcloud2 messages are subscribed-->
<remap from="cloud_in" to="laser_cloud_map" />
</node>
</launch>
第三步:启动octomap_server,启动SLAM算法:
#启动octomap_server节点
roslaunch octomap_server octomap_server.launch
#以aloam为例,启动aloam
roslaunch aloam_velodyne aloam_velodyne_VLP_16.launch
#启动rosbag或者实时建图均可
rosbag play xxxx.bag
启动rviz后,点击“add”,分别添加"Map"、"OccupancyGrid"与"OccupancyMap",并把其话题名依次改为"/projected_map"、"octomap_full"与"octomap_binary"就可以看到建图过程了。
最后就是保存地图了
rosrun map_server map_saver map:=/projected_map
之后就可以在主目录下看到所建的2d栅格地图啦 !