一、Cartographer簡介
Cartographer是google開源的通用2D和3D定位與地圖同步構建的SLAM工具,並提供ROS接口。官網地址:https://github.com/googlecartographer
二、安裝方法
1、安裝全部依賴項
sudo apt-get update sudo apt-get install -y \ cmake \ g++ \ git \ google-mock \ libboost-all-dev \ libeigen3-dev \ libgflags-dev \ libgoogle-glog-dev \ liblua5.2-dev \ libprotobuf-dev \ libsuitesparse-dev \ libwebp-dev \ ninja-build \ protobuf-compiler \ python-sphinx \ ros-kinetic-tf2-eigen \ libatlas-base-dev \ libsuitesparse-dev \ liblapack-dev
2、安裝ceres solver,下載安裝在主目錄下,由於googlesource.com需要FQ,這里使用hitcm(張明明)的github地址
# Build and install Ceres. # git clone https://ceres-solver.googlesource.com/ceres-solver # cd ceres-solver git clone https://github.com/hitcm/ceres-solver-1.11.0.git cd ceres-solver-1.11.0 mkdir build cd build cmake .. -G Ninja ninja ninja test sudo ninja install
3、安裝cartographer,下載安裝在主目錄下,這里同樣使用的是hitcm(張明明)的github地址
# Build and install Cartographer. git clone https://github.com/hitcm/cartographer.git cd cartographer mkdir build cd build cmake .. -G Ninja ninja ninja test sudo ninja install
4、安裝cartographer_ros,這里使用的是hitcm(張明明)的github地址,由於google官方的教程需要FQ下載一些文件,因此容易失敗,經驗證hitcm(張明明)對原文件進行了少許修改后可以成功安裝,在他的修改中核心代碼不變,只修改了編譯文件。
# Install wstool and rosdep. sudo apt-get update sudo apt-get install -y python-wstool python-rosdep ninja-build # Create a new workspace in 'catkin_ws'. mkdir catkin_ws cd catkin_ws wstool init src # 下載到catkin_ws下面的src文件夾下面 cd src git clone https://github.com/hitcm/cartographer_ros.git # 然后到catkin_ws下面運行catkin_make安裝 (會失敗,所以根據提示改變命令) cd cd catkin_ws catkin_make source ./devel/setup.zsh
5、改變命令進行編譯
catkin_make_isolated --install --use-ninja
6、修改cartographer_ros--cartographer_ros--launch--demo_revo_lds.launch
<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_ros--cartographer_ros--configuration_files--revo_lds.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", published_frame = "laser", odom_frame = "odom", provide_odom_frame = true, use_odometry_data = false, use_constant_odometry_variance = true, constant_odometry_translational_variance = 1e-2, constant_odometry_rotational_variance = 1e-1, use_horizontal_laser = true, use_horizontal_multi_echo_laser = false, horizontal_laser_min_range = 0.1, horizontal_laser_max_range = 30., horizontal_laser_missing_echo_ray_length = 5., 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
修改完以上2個文件重新編譯一下,命令行輸入
catkin_make_isolated --install --use-ninja
7、運行
最后命令行中運行rplidar的Node和launch文件
roslaunch rplidar_ros rplidar.launch
roslaunch cartographer_ros demo_revo_lds.launch