Ubuntu 16.04 ROS Kinetic安装Cartographer 及使用RPLIDAR A2建图测试

Ubuntu 16.04 ROS Kinetic安装Cartographer 及使用RPLIDAR A2建图测试

Cartographer可以在ROS和非ROS环境下安装,在ROS下使用比较方便、安装也比较简单,个人推荐在ROS下安装是一个不错的选择。方法来自于官网,本人亲测Ubuntu 16.04 + ROS Kinetic完美运行。

准备工作

先安装Ubuntu 16.04 + ROS Kinetic ,Ubuntu安装这里不在赘述,网上资料比较齐全,ROS Kinetic 安装可参考官网教程
假如是新手的话,建议花一点时间适应英文网站学习,并且建议安装的时候结合官网的安装教程来装,虽然网上有很多中文教程但是不一定是最新的,如果完全按照教程中间会报错,到时候会比较烦人,所以按照官网教程看似比较麻烦,实则是一种事半功倍的方法。
下面是笔者结合官网总结出来的学习教程,供大家参考,Cartographer官网链接

1.下载需要的包

执行下面命令安装必要的包

sudo apt-get update 
sudo apt-get install -y python-wstool python-rosdep ninja-build

2.新建一个工作空间

安装完成过后,执行下面的命令为cartographer新建一个工作空间,也何以使用自己已有的工作空间。

mkdir cartographer_ws
cd cartographer_ws
wstool init src
wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_ros/master/cartographer_ros.rosinstall
wstool update -t src

注意:在执行步骤4的时候,实际上是下载三个功能,包分别为:cartographer、cartographer_ros、ceres-solver,国内的话第三个包 ceres-solver的网址会招到拦截所以会下载失败,此时的解决办法为,从github网址下载ceres-solver 后,将其放入到工作空间,参考网址:https://github.com/BlueWhaleRobot/ceres-solver,然后接着运行第5步即可。

3.安装依赖的ROS包

上面的步骤无误后,接下来安装依赖的ROS包(proto3 ),在执行步骤2的时候之前在安装ROS的时候执行过,这个命令在执行的时候会报错,忽略即可,其它命令执行的时候不会报错。

src/cartographer/scripts/install_proto3.sh
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y

4.安装编译

上面没问题过后开始编译安装,这里的编译和平时的catkin_make不太一样。

catkin_make_isolated --install --use-ninja

由于编译的内容比较大,首次编译会比较慢,耐心等待即可,根据电脑配置的不同时间长短不同,本次测试所用的工控机首次编译大概需要15分钟左右。
编译完成过后把环境变量写进.bashrc方便以后运行

echo "source ~/cartographer_ws/devel_isolated/setup.bash" >> ~/.bashrc
source ~/.bashrc

5.激光雷达RPLIDAR A2 驱动安装

本教程测试使用的是目前比较流行的思岚A2激光雷达,激光雷达的使用都差不多,假如使用不同品牌型号的,思路应该类似。

(1).首先下载并安装雷达驱动,打开终端输入以下命令:

cd ~/cartographer_ws/src
git clone https://github.com/robopeak/rplidar_ros.git
cd ..
catkin_make_isolated --install --use-ninja

(2).运行雷达测试驱动,没有报错的情况下雷达会转起来

roslaunch rplidar_ros rplidar.launch

雷达转起来后,命令窗口如下所示
Ubuntu 16.04 ROS Kinetic安装Cartographer 及使用RPLIDAR A2建图测试_第1张图片

6.激光雷达PLIDAR A2 使用Cartographer建图测试

1.修改revo_lds.lua文件
在以上步骤都正确完成后,修改cartographer下的文件
文件路径:cartographer_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"
include "trajectory_builder.lua"

options = {
     
  map_builder = MAP_BUILDER,
  trajectory_builder = TRAJECTORY_BUILDER,
  map_frame = "map",
  tracking_frame = "horizontal_laser_link",
  published_frame = "horizontal_laser_link",
  odom_frame = "odom",
  provide_odom_frame = true,
  publish_frame_projected_to_2d = false,
  use_pose_extrapolator = true,
  use_odometry = false,
  use_nav_sat = false,
  use_landmarks = false,
  num_laser_scans = 1,
  num_multi_echo_laser_scans = 0,
  num_subdivisions_per_laser_scan = 1,
  num_point_clouds = 0,
  lookup_transform_timeout_sec = 0.2,
  submap_publish_period_sec = 0.3,
  pose_publish_period_sec = 5e-3,
  trajectory_publish_period_sec = 30e-3,
  rangefinder_sampling_ratio = 1.,
  odometry_sampling_ratio = 1.,
  fixed_frame_pose_sampling_ratio = 1.,
  imu_sampling_ratio = 1.,
  landmarks_sampling_ratio = 1.,
}

MAP_BUILDER.use_trajectory_builder_2d = true

TRAJECTORY_BUILDER_2D.submaps.num_range_data = 35
TRAJECTORY_BUILDER_2D.min_range = 0.3
TRAJECTORY_BUILDER_2D.max_range = 8.
TRAJECTORY_BUILDER_2D.missing_data_ray_length = 1.
TRAJECTORY_BUILDER_2D.use_imu_data = false
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.linear_search_window = 0.1
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.translation_delta_cost_weight = 10.
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.rotation_delta_cost_weight = 1e-1

POSE_GRAPH.optimization_problem.huber_scale = 1e2
POSE_GRAPH.optimize_every_n_nodes = 35
POSE_GRAPH.constraint_builder.min_score = 0.65

return options

这里网上的很多教程测试不通过,其实只需要修改以下两句:

tracking_frame = "horizontal_laser_link",
published_frame = "horizontal_laser_link",

里面的"horizontal_laser_link",改成自己激光雷达的frame_id,我的是laser,一般都是laser,其余的不要动。
2.修改demo_revo_lds.launch文件
定位到文件路径:cartographer_ws/src/cartographer_ros/cartographer_ros/launch/demo_revo_lds.launch文件。打开demo_revo_lds.launch并修改代码如下:

<!--
  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.
-->

<launch>
  <param name="/use_sim_time" value="true" />

  <node name="cartographer_node" pkg="cartographer_ros"
      type="cartographer_node" args="
          -configuration_directory $(find cartographer_ros)/configuration_files
          -configuration_basename revo_lds.lua"
      output="screen">
    <remap from="scan" to="scan" />
  </node>

  <node name="rviz" pkg="rviz" type="rviz" required="true"
      args="-d $(find cartographer_ros)/configuration_files/demo_2d.rviz" />" 
</launch>

修改完之后,回到cartographer_ws 目录下再次编译

catkin_make_isolated --install –use-ninja

3. 启动测试
(1)首先运行激光雷达节点launch文件

roslaunch rplidar_ros rplidar.launch

(2)运行cartographer框架

roslaunch cartographer_ros demo_revo_lds.launch

运行正常将打开rviz,并且显示正常,如下Ubuntu 16.04 ROS Kinetic安装Cartographer 及使用RPLIDAR A2建图测试_第2张图片
在整个Cartographer 安装过程中,笔者也尝试过很多教程和方法,其中遇到过很多报错,本教程亲测好使,当前日期为2019年12月,总结供大家参考,当然也可能会出现问题,这些报错和系统版本、ROS版本等可能有关系,节报错信息在网上查找,纠错也是学习的过程。

你可能感兴趣的:(Ubuntu/ROS,RPLIDAR,A2)