Official documentation: Cartographer – Cartographer documentation
1. Dependency installation (Ubuntu20.04)
Link: https://pan.baidu.com/s/1vBfm2Xxf9Z7iQwZvJmYJGw Extraction code: mm8q
./auto-carto-build.sh
One-click installation using script~
2. Pull source code
The source code used here is based on the source code annotated by teacher Li Xiang~
Source code path:https://github.com/xiangli0608/cartographer_detailed_comments_ws
mkdir carto_ws cd carto_ws git clone https://github.com/xiangli0608/cartographer_detailed_comments_ws.git
Compile:
cd cartographer_detailed_comments_ws ./catkin_make.sh
4 packages were compiled:
- cartographer
- cartographer_ros
- cartographer_ros
- cartographer_ros_msgs
- cartographer_rviz
Set environment path:
sudo vim ~/.bashrc # Put (absolute path) at the end source /home/robot/Documents/learn_repo/carto_ws/cartographer_detailed_comments_ws/install_isolated/setup.bash
Tips: (Click G in vim to jump to the last line)
Note: This project file can only be compiled using the catkin_make.sh script file, not catkin_make directly
When there is no need to modify the cartographer source code, you can directly put cartographer_ros in the workspace and compile catkin_make (because the cartographer source code has been installed in the system as an installation library)
3. Run (2D mapping)
Create a new bagfiles file in the home directory (you can also modify the bag path information in the launch file later)
cd ~ mkdir bagfiles
Put the downloaded data set bag file into this folder!
The path to the dataset here can be modified:
# Check whether the system environment is effective rospack profile
Run: (2D mapping)
roslaunch cartographer_ros lx_rs16_2d_outdoor.launch
The above map construction uses Submaps for viewing, or map for viewing:
Check who posted the map topic:
rostopic info /map
4. Save the map (2D map)
Save map: (Method 1)
rosrun map_server map_saver -f map
(Method 2:) Use the script file finish_slam_2d.sh in the project
./finish_slam_2d.sh
We can see that it is saved in the home directory and a folder is created. This path can actually modify the script file.
5. Run (pure positioning mode)
roslaunch cartographer_ros lx_rs16_2d_outdoor_localization.launch
Pure positioning mode Compared with the mapping just now, it is actually loading the created map and then running the bag to build the map
And we can find that the map actually changes slightly, which is not good for navigation, so we can load the established map through map_server and use map Just publish the topic
6. Run (3D mapping)
roslaunch cartographer_ros lx_rs16_3d.launch
7. Save the map (3D map)
./finish_slam_3d.sh
Generate pbstream files
7. Use asset to generate a 2D raster map in ros format
roslaunch cartographer_ros assets_writer_2d.launch
Read urdf files, bag packages, and pbstream files, and finally generate a map.pgm
8. Use asset to generate a 3D raster map in ros format
roslaunch cartographer_ros assets_writer_3d.launch
A b3_1.pcd file was generated
pcl_viewer b3_1.pcd
Installation:
sudo apt install pcl-tools
Press 4 to assign colors to point clouds at different heights
9. Use landmark
roslaunch cartographer_ros landmark_mir_100.launch
10. Configuration lua file
- tracking_frame
- If there is an imu link, set it to imu_link
- If not, set it to base_link
- published_frame
- The bottom coordinate system of tf released by cartographer, the top coordinate system of the tf tree in the bag
- provide_odom_frame
- Is an odometer provided?
- If there is an odometer coordinate system in the bag, this is false.
- If not, decide whether to provide an odometer coordinate system as needed (purely for mapping, it doesn’t matter whether there is odom or not)
-
use_pose_extrapolator
-
set to false
-
-
use_odometry
-
Whether to use the sensor data of the odometer. If it is true, the odom coordinate system must exist in the tf tree.
-
-
num_laser_scans/num_point_clouds
-
Whether to use single-line radar or multi-line radar, if one is used, it will be 1, if not, it will be 0. It can be 1 at the same time, but cannot be 0 at the same time (multiple single-line radars or multiple multi-line radars can be used)
-
-
TRAJECTORY_BUILDER_2D.use_imu_data
-
Whether to use IMU. If IMU is used, tracking_frame must be set to imu_link
-
-
TRAJECTORY_BUILDER_2D.min_z
-
The minimum z range of the point cloud
-
Single-line point cloud cannot be set to a value greater than 0 (or not set)
-
For multi-line point clouds, this value must be greater than 0
-
lua file:
-- 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, -- configuration information of map_builder.lua trajectory_builder = TRAJECTORY_BUILDER, -- configuration information of trajectory_builder.lua map_frame = "map", -- the name of the map coordinate system tracking_frame = "imu_link", -- Convert all sensor data to this coordinate system published_frame = "odom", -- tf: map -> odom odom_frame = "odom", -- the coordinate system name of the odometer provide_odom_frame = false, -- Whether to provide odom's tf, if true, the tf tree is map->odom->footprint publish_frame_projected_to_2d = false, -- Whether to project the coordinate system onto the plane use_pose_extrapolator = false, use_odometry = false, -- Whether to use odometry, if required, you must have odom tf use_nav_sat = false, -- whether to use gps /fix use_landmarks = false, -- whether to use landmarks num_laser_scans = 0, -- whether to use single-line laser data num_multi_echo_laser_scans = 0, -- whether to use multi_echo_laser_scans data multi-echo radar num_subdivisions_per_laser_scan = 1, -- 1 frame of data is divided into several times for processing, usually 1 num_point_clouds = 1, -- whether to use point cloud data lookup_transform_timeout_sec = 0.2, -- timeout when looking for tf submap_publish_period_sec = 0.3, -- the time interval for publishing data pose_publish_period_sec = 5e-3, trajectory_publish_period_sec = 30e-3, rangefinder_sampling_ratio = 1., -- Sampling frequency of sensor data 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.use_imu_data = true TRAJECTORY_BUILDER_2D.min_z = 0.1 -- the minimum value of the z-axis of the radar data, below which the value is filtered out return options
The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. CS entry skill treeLinux introductionFirst introduction to Linux 37641 people are learning the system