谷歌cartographer+EAI激光雷达F4建图实现

这几天在做谷歌cartographer算法实现,前两天实现了谷歌cartographer室内建图的实现,不过所建之图是基于谷歌提供的博物馆的数据,我们只是将数据包下载之后复现而已,并不是我们自己实验室或者周围的地图,由上一篇博客点击打开链接实现的建图我们可以看到,在没有里程计等其他传感器的协助之下,仅仅依靠激光测距仪和算法就完成了效果甚至优于其他多传感器结合的2D地图,如此优秀的开源我们当然希望能用在我们自己的机器人或者传感器上,而不是仅仅做一下仿真。于是拿实验室的EAI的激光雷达F4来进行实验室建图。网上的教程有基于rplidar,北洋雷达,hokuyo UTM-30LX实现的,但没有找到F4的相关教程。于是自己经过摸索实现了其建图。仅供大家参考,不对之处还望指正。

系统要求:Ubuntu16.04(kinetic)或者Ubuntu14.04(indigo)都行

硬件要求:EAI激光雷达F4以及与电脑相连数据线,笔记本一台。

1.激光雷达的调试

使用命令在当home目录下创建 flashgo_ws 工作空间,并将 F4 资料包内的 ROS 驱动包 flashgo 复制到 flashgo_ws/src 目录下,切换到 flashgo_ws 工作空间下并重新进行编译。

$ mkdir -p ~/flashgo_ws/src
$ cd ~/flashgo_ws
$ catkin_make_isolated --install --use-ninja 

编译时用ninja报错会好一点。也可以使用catkin_make.

编译完成后,添加 flashgo 环境变量到~/.bashrc 文件中,并使其生效。

echo "source ~/flashgo_ws/devel_isolated/setup.zsh " >> ~/.zshrc 

为 F4 的串口增加一个设备别名 /dev/flashlidar。

$ cd ~/flashgo_ws/src/flashgo/startup
$ sudo chmod +x initenv.sh
$ sudo sh initenv.sh

运行 launch 文件,打开 rviz 查看 F4 扫描结果。

$ roslaunch flashgo lidar_view.launch

rviz 显示如下图所示:

谷歌cartographer+EAI激光雷达F4建图实现_第1张图片

如上图所示则说明激光雷达调试成功,此时红色线条所示为障碍物,还不是地图。

2.安装谷歌cartographer中的三个文件夹(cartographer,cartographer_ros,ceres-solver)步骤见上一篇博客1_5步。上一篇博客链接点击打开链接

3.对cartographer_ros文件夹中的代码及参数修改,首先修改~/slam_ws/src/cartographer_ros/cartographer_ros/launch目录下的demo_revo_lds.launch  文件,修改后如下所示




  

  
    
  

  
  

其实需要修改的也就是因为这里我们只是利用了激光雷达建图,并未使用机器人本体。

4.接下来对~/slam_ws/src/cartographer_ros/cartographer_ros/configuration_files目录下的revo_lds.lua文件,修改好的文件如下所示

-- Copyright 2016 The Cartographer Authors
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

include "map_builder.lua"

options = {
  map_builder = MAP_BUILDER,
  sensor_bridge={
  horizontal_laser_min_range = 0.3,
  horizontal_laser_max_range = 8.,
  horizontal_laser_missing_echo_ray_length = 1.2,
  constant_odometry_translational_variance = 0.,
  constant_odometry_rotational_variance = 0.,
},
  map_frame = "map",
  tracking_frame = "laser_frame",
  published_frame = "laser_frame",
  odom_frame = "odom",
  provide_odom_frame = true,
  use_odometry_data = false,
  use_laser_scan = true,
  use_constant_odometry_variance = false,
  constant_odometry_translational_variance = 0.,
  constant_odometry_rotational_variance = 0.,
  use_horizontal_laser = true,
  use_horizontal_multi_echo_laser = false,
  horizontal_laser_min_range = 0.3,
  horizontal_laser_max_range = 8.,
  horizontal_laser_missing_echo_ray_length = 1.,
  num_lasers_3d = 0,
  lookup_transform_timeout_sec = 0.2,
  submap_publish_period_sec = 0.3,
  pose_publish_period_sec = 5e-3,
}

MAP_BUILDER.use_trajectory_builder_2d = true
TRAJECTORY_BUILDER_2D.use_imu_data = false
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
SPARSE_POSE_GRAPH.optimization_problem.huber_scale = 1e2

return options

其中比较关键的是开始的几个frame的设置,网上转载比较多的是如下修改方式

map_frame = "map",
  tracking_frame = "laser",
  published_frame = "laser",
  odom_frame = "odom",

这样设置的原因应该是只用了一个激光器,而不是机器人,所以用“laser”,这个“laser”也需要查看激光器在tf_tree中的名称,用实际的名称替换,否则rviz中看不到地图,因为tf有问题。之前的问题一直是tf树的问题,所以所建地图无法出来,通过查看激光雷达的在tf树中的名称如下所示

谷歌cartographer+EAI激光雷达F4建图实现_第2张图片

可以知道激光雷达的tf树名称为laser_frame,因此将tracking_frame和published_frame后的参数改成laser_frame即可。

5.运行激光雷达

6.运行cartographer中的建图命令

7.完成建图

谷歌cartographer+EAI激光雷达F4建图实现_第3张图片

由于激光雷达所放位置障碍物较多,而且在激光雷达开始扫描的过程中将激光雷达拿起,是的激光雷达位置发生了上下左右的倾斜,但已能实现建图。

你可能感兴趣的:(SLAM)