6、Lidar mapping

Gmapping:http://wiki.ros.org/gmapping/

hector_slam:http://wiki.ros.org/hector_slam

hector_slam/Tutorials:http://wiki.ros.org/hector_slam/Tutorials/SettingUpForYourRobot

hector_mapping:http://wiki.ros.org/hector_mapping

karto:http://wiki.ros.org/slam_karto

Cartographer:https://google-cartographer.readthedocs.io/en/latest/

Cartographer ROS:https://google-cartographer-ros.readthedocs.io/en/latest/

rrt_exploration:http://wiki.ros.org/rrt_exploration

rrt_exploration/Tutorials:http://wiki.ros.org/rrt_exploration/Tutorials

map_server:https://wiki.ros.org/map_server

6.1、Instructions

6.1.1、Mapping

Note: When building a map, the slower the speed of the car, the better the effect (especially the rotation speed). If the speed is too fast, the effect will be poor.

Start command (note: the navigation effect of depth mapping alone is not good, so it is not recommended).

Mapping

6.1.2、Usage

Run following command, then you can control robot movement by keyboard

Or you can control robot by handle, no need run any code. The command for mapping or navigation includes the start command for the handle control.

We need to make sure that the robot walks all over the area to be mapped. As shown below, the map should be closed.

image-20210919142650310

There may be some scattered points during the mapping process. If the mapping environment is well closed, relatively regular, and the movement speed is slower, the scattering phenomenon will be much smaller.

6.1.3、Save map

There are different ways of saving maps in several mapping algorithms.

The map is saved to this path: ~/transbot_ws/src/transbot_nav/maps/,a pgm picture file and a yaml file.

map.yaml

Parameter analysis:

6.1.4、View info

View tf tree

View node

6.1.5、2D mapping by depth mapping alone

Start the driver reference【6.1.1】# Astra + Transbot; the command for starting the map is the same as【6.1.1】.

The function package depthimage_to_laserscan is mainly used to convert the depth image into lidar data. Its mapping function is the same as that of lidar.

Note: The scanning range of the depth camera is not 360°.

image-20210919142650310

6.2、Mapping algorithm

6.2.1、gmapping

1)Introduction

Advantages: Gmapping can construct indoor maps in real time, and the amount of calculation required to construct small scene maps is small and the accuracy is high.

Disadvantages: Not suitable for building large scene maps.

2)Topics and services
Subscribe to topicsTypeDescription
tftf/tfMessageUsed for conversion between lidar coordinate system, base coordinate system and odometer coordinate system
scansensor_msgs/LaserScanLidar scan data
TopicTypeDescription
map_metadatanav_msgs/MapMetaDataPublish map Meta data
mapnav_msgs/OccupancyGridPublish map raster data
~entropystd_msgs/Float64Release the estimation of robot pose distribution entropy
ServiceTypeDescription
dynamic_mapnav_msgs/GetMapGet map data
3)Configuration parameter
ParameterTypeDefaults valueDescription
~throttle_scansint1Process 1 out of every this many scans (set it to a higher number to skip more scans)
~base_framestring"base_link"The frame attached to the mobile base.
~map_framestring"map"The frame attached to the map.
~odom_framestring"odom"The frame attached to the odometry system.
~map_update_intervalfloat5.0How long (in seconds) between updates to the map. Lowering this number updates the occupancy grid more often, at the expense of greater computational load.
~maxUrangefloat80.0The maximum usable range of the laser. A beam is cropped to this value.
~sigmafloat0.05The sigma used by the greedy endpoint matching
~kernelSizeint1The kernel in which to look for a correspondence
~lstepfloat0.05The optimization step in translation
~astepfloat0.05The optimization step in rotation
~iterationsint5The number of iterations of the scanmatcher
~lsigmafloat0.075The sigma of a beam used for likelihood computation
~ogainfloat3.0Gain to be used while evaluating the likelihood, for smoothing the resampling effects
~lskipint0Number of beams to skip in each scan.
~minimumScorefloat0Minimum score for considering the outcome of the scan matching good. Can avoid jumping pose estimates in large open spaces when using laser scanners with limited range (e.g. 5m). Scores go up to 600+, try 50 for example when experiencing jumping estimate issues.
~srrfloat0.1Odometry error in translation as a function of translation (rho/rho)
~srtfloat0.2Odometry error in translation as a function of rotation (rho/theta)
~strfloat0.1Odometry error in rotation as a function of translation (theta/rho)
~sttfloat0.2Odometry error in rotation as a function of rotation (theta/theta)
~linearUpdatefloat1.0Process a scan each time the robot translates this far
~angularUpdatefloat0.5Process a scan each time the robot rotates this far
~temporalUpdatefloat-1.0Process a scan if the last scan processed is older than the update time in seconds. A value less than zero will turn time based updates off.
~resampleThresholdfloat0.5The Neff based resampling threshold
~particlesint30Number of particles in the filter
~xminfloat-100.0Initial minimum size of the map in x direction
~yminfloat-100.0Initial minimum size of the map in y direction
~xmaxfloat100.0Initial maximum size of the map in x direction
~ymaxfloat100.0Initial maximum size of the map in y direction
~deltafloat0.05Resolution of the map (in metres per occupancy grid block)
~llsamplerangefloat0.01Translational sampling range for the likelihood
~llsamplestepfloat0.01Translational sampling step for the likelihood
~lasamplerangefloat0.005Angular sampling range for the likelihood
~lasamplestepfloat0.005Angular sampling step for the likelihood
~transform_publish_periodfloat0.05How long (in seconds) between transform publications.
~occ_threhfloat0.25Threshold on gmapping's occupancy values
~maxRange(float)float-Threshold on gmapping's occupancy values
4)TF Transforms
Required tf Transforms TFDescription
laser-->base_linksually a fixed value, broadcast periodically by a robot_state_publisher, or a tf static_transform_publisher.
base_link-->odomusually provided by the odometry system (e.g., the driver for the mobile base)
Provided tf TransformsDescription
map-->odomthe current estimate of the robot's pose within the map frame

6.2.2、hector

1)Introduction

Features: hector_slam does not need to subscribe to the odometer/odom message, uses the Gauss Newton method, and directly uses the lidar to estimate the odometer information. However, when the robot speed is faster, it will cause deviations in the mapping effect, and the requirements for sensors are high.

When building maps, adjust the rotation speed of the trolley as low as possible.

There is no way to use the odom coordinate system, which is taken from the Wiki.

image-20210916154657969

2)Topics and services
Topic subscriptionTypeDescription
scansensor_msgs/LaserScanThe laser scan used by the SLAM system.
syscommandstd_msgs/StringSystem command. If the string equals "reset" the map and robot pose are reset to their inital state.
Published TopicsTypeDescription
map_metadatanav_msgs/MapMetaDataGet the map data from this topic
mapnav_msgs/OccupancyGridGet the map data from this topic
slam_out_posegeometry_msgs/PoseStampedThe estimated robot pose without covariance
poseupdategeometry_msgs
/PoseWithCovarianceStamped
The estimated robot pose with an gaussian estimate of uncertainty
ServicesTypeDescription
dynamic_mapnav_msgs/GetMapCall this service to get the map data.
reset_mapstd_srvs/TriggerCall this service to reset the map, and hector will start a whole new map from scratch. Notice that this doesn't restart the robot's pose, and it will restart from the last recorded pose.
pause_mappingstd_srvs/SetBoolCall this service to stop/start processing laser scans.
restart_mapping_with_new_posehector_mapping/ResetMappingCall this service to reset the map, the robot's pose, and resume mapping (if paused)
3)Parameters
ParametersTypeDefaults valueDescription
~base_frameString"base_link"The name of the base frame of the robot. This is the frame used for localization and for transformation of laser scan data.
~map_frameString"map"The name of the map frame.
~odom_framestring"odom"The name of the odom frame.
~map_resolutionDouble0.025(m)The map resolution [m]. This is the length of a grid cell edge.
~map_sizeInt1024The size of the map.
~map_start_xdouble0.5Location of the origin [0.0, 1.0] of the /map frame on the x axis relative to the grid map. 0.5 is in the middle.
~map_start_ydouble0.5Location of the origin [0.0, 1.0] of the /map frame on the y axis relative to the grid map. 0.5 is in the middle.
~map_update_distance_threshdouble0.4(m)Threshold for performing map updates [m]. The platform has to travel this far in meters or experience an angular change as described by the map_update_angle_thresh parameter since the last update before a map update happens.
~map_update_angle_threshdouble0.9(rad)Threshold for performing map updates [rad]. The platform has to experience an angular change as described by this parameter of travel as far as specified by the map_update_distance_thresh parameter since the last update before a map update happens.
~map_pub_perioddouble2.0The map publish period [s].
~map_multi_res_levelsint3The number of map multi-resolution grid levels.
~update_factor_freedouble0.4The map update modifier for updates of free cells in the range [0.0, 1.0].
~update_factor_occupieddouble0.9The map update modifier for updates of occupied cells in the range [0.0, 1.0].
~laser_min_distdouble0.4(m)The minimum distance [m] for laser scan endpoints to be used by the system.
~laser_max_distdouble30.0(m)The maximum distance [m] for laser scan endpoints to be used by the system
~laser_z_min_valuedouble-1.0(m)The minimum height [m] relative to the laser scanner frame for laser scan endpoints to be used by the system.
~laser_z_max_valuedouble1.0(m)The maximum height [m] relative to the laser scanner frame for laser scan endpoints to be used by the system.
~pub_map_odom_transformbooltrueDetermine if the map->odom transform should be published by the system.
~output_timingboolfalseOutput timing information for processing of every laser scan via ROS_INFO.
~scan_subscrible_queue_sizeint5The queue size of the scan subscriber.
~pub_map_scanmatch_transformbooltrueDetermines if the scanmatcher to map transform should be published to tf.
~tf_map_scanmatch_transform_frame_nameString"scanmatcher_frame"The frame name when publishing the scanmatcher to map transform as described in the preceding parameter.
4)TF Transforms
Required tf TransformsDescription
laser-->base_linkusually a fixed value, broadcast periodically by a robot_state_publisher, or a tf static_transform_publisher.
Provided tf TransformsDescription
map-->odomthe current estimate of the robot's pose within the map frame (only provided if parameter "pub_map_odom_transform" is true).

6.2.3、karto

1)Introduction

Karto is a 2D laser SLAM solution, which is based on a sparse graph optimization method with closed loop detection. Karto uses the spa (karto_slam) or g2o (nav2d) optimization library, and the front-end and back-end uses a single-threaded process. It uses odom to predict the initial position.

2)Topics and Services
Subscribed TopicsTypeDescription
scansensor_msgs/LaserScanTransforms necessary to relate frames for laser, base, and odometry
tftf/tfMessage Laser scans to create the map from
Published TopicsTypeDescription
map_metadatanav_msgs/MapMetaDataGet the metadata of the map data (resolution, width, height, ...)
mapnav_msgs/OccupancyGridGet the map data from this topic, which is latched, and updated periodically
visualization_marker_arrayvisualisation_msgs / MarkerArrayGet the pose graph from this topic, which is updated periodically
Published TopicsTypeDescription
dynamic_mapnav_msgs/GetMapCall this service to get the map data
3)Parameters
ParametersTypeDefaults valueDescription
~base_framestring"base_link"The frame attached to the mobile base.
~map_framestring"map"The frame attached to the map.
~odom_framestring"odom"The frame attached to the odometry system.
~throttle_scansint1Process 1 out of every this many scans (set it to a higher number to skip more scans)
~map_update_intervalfloat5.0How long (in seconds) between updates to the map. Lowering this number updates the occupancy grid more often, at the expense of greater computational load.
~resolutionfloat0.05Resolution of the map (in metres per occupancy grid block)
~deltafloat0.05Resolution of the map (in metres per occupancy grid block). Same as resolution. Defined for compatibility with the parameter names of gmapping.
~transform_publish_periodfloat0.05How long (in seconds) between transform publications. To disable broadcasting transforms, set to 0.
use_scan_matchingbooltrueWhen set to true, the mapper will use a scan matching algorithm. In most real-world situations this should be set to true so that the mapper algorithm can correct for noise and errors in odometry and scan data. In some simulator environments where the simulated scan and odometry data are very accurate, the scan matching algorithm can produce worse results. In those cases set this to false to improve results.
use_scan_barycenterbooltrueUse the barycenter of scan endpoints to define distances between scans.
minimum_travel_distancedouble0.2Sets the minimum travel between scans.
minimum_travel_headingdoubledeg2rad(10)=0.087266461Sets the minimum heading change between scans
scan_buffer_sizeint70Sets the length of the scan chain stored for scan matching. scan_buffer_size should be set to approximately scan_buffer_maximum_scan_distance / minimum_travel_distance.
scan_buffer_maximum_scan_distancedouble20.0Sets the maximum distance between the first and last scans in the scan chain stored for matching.
link_match_minimum_response_finedouble0.8Scans are linked only if the correlation response value is greater than this value.
link_scan_minimum_distancedouble10.0Sets the maximum distance between linked scans. Scans that are farther apart will not be linked regardless of the correlation response value.
loop_search_maximum_distancedouble4.0Scans less than this distance from the current position will be considered for a match in loop closure.
do_loop_closingbooltrueEnable/disable loop closure.
loop_match_minimum_chain_sizeint10When the loop closure detection finds a candidate it must be part of a large set of linked scans
loop_match_maximum_variance_coarsedoublemath::Square(0.4)=0.16The co-variance values for a possible loop closure have to be less than this value to consider a viable solution. This applies to the coarse search.
loop_match_minimum_response_coarsedouble0.8If response is larger than this, then initiate loop closure search at the coarse resolution.
loop_match_minimum_response_finedouble0.8If response is larger than this, then initiate loop closure search at the fine resolution.
ParametersTypeDefaults valueDescription
correlation_search_space_dimensiondouble0.3Sets the size of the search grid used by the matcher.
correlation_search_space_resolutiondouble0.01 Sets the resolution (size of a grid cell) of the correlation grid.
correlation_search_space_smear_deviationdouble0.03 The point readings are smeared by this value in X and Y to create a smoother response.
ParametersTypeDefaults valueDescription
loop_search_space_dimensiondouble8.0The size of the search grid used by the matcher.
loop_search_space_resolutiondouble0.05The resolution (size of a grid cell) of the correlation grid.
loop_search_space_smear_deviationdouble0.03The point readings are smeared by this value in X and Y to create a smoother response.
ParametersTypeDefaults valueDescription
distance_variance_penaltydoublesqrt(0.3)=0.09(<1.0)Variance of penalty for deviating from odometry when scan-matching. The penalty is a multiplier (less than 1.0) is a function of the delta of the scan position being tested and the odometric pose.
angle_variance_penaltydoublesqrt(deg2rad(20))=0.17453292See distance_variance_penalty.
fine_search_angle_offsetdoubledeg2rad(0.2)=0.0017453292The range of angles to search during a fine search.
coarse_search_angle_offsetdoubledeg2rad(20)=0.17453292The range of angles to search during a coarse search.
coarse_angle_resolutiondoubledeg2rad(2)=0.017453292Resolution of angles to search during a coarse search.
minimum_angle_penaltydouble0.9Minimum value of the angle penalty multiplier so scores do not become too small.
minimum_distance_penaltydouble0.5Minimum value of the distance penalty multiplier so scores do not become too small.
use_response_expansionboolfalseWhether to increase the search space if no good matches are initially found
4)TF Transforms
Required tf TransformsDescription
laser-->base_linkusually a fixed value, broadcast periodically by a robot_state_publisher, or a tf static_transform_publisher.
base_link-->odomusually provided by the odometry system (e.g., the driver for the mobile base)
Provided tf TransformsTFDescription
map-->odomthe current estimate of the robot's pose within the map frame

6.2.4、cartographer

1)Introduction

Cartographer is a 2D and 3D SLAM (simultaneous localization and mapping) library supported by a ROS system open sourced by Google. A graph-building algorithm based on graph optimization (multi-threaded back-end optimization, problem optimization built by cere). Data from multiple sensors (for example, LIDAR, IMU, and camera) can be combined to calculate the position of the sensor simultaneously and map the environment around the sensor.

2)Code structure

The source code of cartographer mainly includes three parts: cartographer、cartographer_ros and ceres-solver 。

_images/high_level_system_overview.png

The package cartographer_ros runs in the ROS system. It can receive various sensor data in the form of ROS messages, and publish it in the form of messages after processing, which is convenient for debugging and visualization.

3)Parameters

lua file

ParametersDescription
map_frameMap coordinate system
tracking_frameConvert all sensor data to this coordinate system
published_frameThe map points to coordinate system the
odom_frameIf true, the tf tree is map->odom->footprint; if false, the tf tree is map->footprint
provide_odom_frameIf true, the local, non-loop-closed, continuous pose will be published as odom_frame in map_frame
publish_frame_projected_to_2dIf enabled, the published pose will restrict 2D poses
use_odometryWhether to use the odometer, if you use it, you must have odom tf
use_nav_satWhether to use gps
use_landmarksWhether to use landmark
num_laser_scansWhether to use single-line laser data
num_multi_echo_laser_scansWhether to use multi_echo_laser_scans data
num_subdivisions_per_laser_scan1 frame of data is divided into several processings, in generally it is 1
num_point_cloudsWhether to use point cloud data
lookup_transform_timeout_secFind the timeout of tf
submap_publish_period_secTime interval for publishing submap (seconds)
pose_publish_period_secThe time interval for posting pose, when the value is 5e-3, it is 200HZ
trajectory_publish_period_secThe time interval for publishing trajectory markers (trajectory nodes), the value is 30e-3 to 30ms
rangefinder_sampling_ratioFixed sampling frequency of lidar messages
odometry_sampling_ratioFixed sampling frequency of odometer messages
fixed_frame_pose_sampling_ratioFixed sampling frequency of fixed coordinate system messages
imu_sampling_ratioFixed sampling frequency of IMU messages
landmarks_sampling_ratioFixed sampling frequency for road sign messages

6.3、rrt_exploration

6.3.1、Introduction

RRT exploration is a search algorithm based on the RRT path planning algorithm.

RRT algorithm is as follows:

image-20210916210746859

There are 3 types of nodes: nodes used to detect boundary points occupying the grid map, nodes used to filter detected points, and nodes used to assign points to robots.

6.3.2、global_rrt_frontier_detector

1)Introduction

The global_rrt_frontier_detector node uses the occupancy grid and finds boundary points (that is, exploration targets) in it. It publishes the detected points so that the filter nodes can process them. In a multi-robot configuration, only one instance of this node is run.

2)Topics and Services
Subscribed TopicsTypeDescription
mapnav_msgs/OccupancyGridThe topic name is defined by the ~map_Topic parameter. It is the name of the topic that the node receives.
clicked_pointgeometry_msgs/PointStampedThe area to be detected by the global_rrt_frontier_detector node. This topic is where the node receives the five points that define the area. The first four points are the four points that define the square area to be explored, and the last point is the starting point of the tree. After the announcement of these five points, the RRT will begin to detect border points.
Published TopicsTypeDescription
detected_pointsgeometry_msgs/PointStampedPost the topic of the detected boundary point.
shapesvisualization_msgs/MarkerPublish RRT hypothetical line type to view with Rviz.
3)Parameters
ParametersTypeDefaults valueDescription
~map_topicstring"/robot_1/map"The node receives the map topic mapping name
~etafloat5.0This parameter controls the growth rate of RRT used to detect boundary points, in meters.

6.3.3、local_rrt_frontier_detector

1)Introduction

This node is similar to global_rrt_frontier_detector. However, it works differently, because every time a boundary point is detected, the tree here is constantly reset. This node will run along the global boundary detector node, which is responsible for quickly detecting boundary points located near the robot.

2)Topics and Services
Subscribed TopicsTypeDescription
mapnav_msgs/OccupancyGridThe name of the map topic subscribed by this node.
clicked_pointgeometry_msgs/PointStampedSimilar to the global_rrt_frontier_detector node
Published TopicsTypeDescription
detected_pointsgeometry_msgs/PointStampedPost the topic of the detected boundary point.
shapesvisualization_msgs/MarkerPublish RRT hypothetical line type to view with Rviz.
3)Parameters
ParametersTypeDefaults valueDescription
~/robot_1/base_linkstring"/robot_1/base_link"Connect to the frame of the robot. Each time the RRT tree is reset, it will start from the current robot position obtained in this coordinate system.
~map_topicstring"/robot_1/map"The node receives the map topic mapping name
~etafloat5.0This parameter controls the growth rate of RRT used to detect boundary points, in meters.

6.3.4、frontier_opencv_detector

1)Introduction

This node is another boundary detector, but it is not based on RRT.

2)Topics and Services
Subscribed TopicsTypeDescription
mapnav_msgs/OccupancyGridThe name of the map topic subscribed by this node.
Published TopicsTypeDescription
detected_pointsgeometry_msgs/PointStampedPost the topic of the detected boundary point.
shapesvisualization_msgs/MarkerPublish RRT hypothetical line type to view with Rviz.
3)Parameters
ParametersTypeDefaults valueDescription
~map_topicstring"/robot_1/map"The node receives the map topic mapping name

6.3.5、filter

1)Introduction

The node node receives the detected boundary points from all detectors, filters these points, and passes them to the distribution node to command the robot. Filtering includes deleting old points and invalid points, as well as deleting redundant points.

2)Topics and Services
Subscribed TopicsTypeDescription
mapnav_msgs/OccupancyGridThe topic name is defined by the ~map_Topic parameter. It is the name of the topic that the node receives.
robot_x/move_base_node
/global_costmap/costmap
nav_msgs/OccupancyGridx is the number of the robot. This node subscribes to the topics of all cost maps of all robots, so costmap is needed.
detected_pointsgeometry_msgs/PointStampedThe name of the topic defined by ~goals_topic. It is the topic of the filter node receiving boundary detection points.
Published TopicsTypeDescription
frontiersvisualization_msgs/MarkerThe filter node only publishes the topics of the filtered boundary points.
centroidsvisualization_msgs/MarkerThe filter node publishes the topic of the received boundary point.
filtered_pointsMsgLink(msg/type)All filtered points are sent to the assigner node of this topic as a point array.
3)Parameters
ParametersTypeDefaults valueDescription
~map_topicstring"/robot_1/map"The node receives the map topic mapping name
~costmap_clearing_thresholdfloat70.0Cost map cleanup threshold
~info_radiusfloat1.0The information radius used to calculate the information gain of the boundary point.
~goals_topicstring/detected_pointsDefine the subject of the node receiving the detection boundary point
~n_robotsfloat1.0Number of robots
~namespacestring Namespaces
~namespace_init_countfloat1.0Namespace index
~ratefloat100.0Node cycle rate (in Hz).

6.3.6、Assigner

1)Introduction

The node receives the target detection target, that is, the filtering boundary point issued by the filtering node, and commands the robot accordingly. The evaluator node commands the robot through move_base_node. This is why the navigation is started on the robot.

2)Topics and Services
Subscribed TopicsTypeDescription
mapnav_msgs/OccupancyGridThe topic name is defined by the ~map_Topic parameter. It is the name of the topic that the node receives.
frontiers_topicnav_msgs/OccupancyGridThe topic name is defined by the ~frontiers_topic parameter
3)Parameters
ParametersTypeDefaults valueDescription
~map_topicstring"/robot_1/map"The node receives the map topic mapping name
~info_radiusfloat1.0The information radius used to calculate the information gain of the boundary point.
~info_multiplierfloat3.0The unit is meters. .
~hysteresis_radiusfloat3.0The unit is meters. This parameter defines the hysteresis radius.
~hysteresis_gainfloat2.0The unit is meters. This parameter defines the hysteresis gain.
~frontiers_topicstring/filtered_pointsThe node receives the topic of the boundary point.
~n_robotsfloat1.0Number of robots
~namespacestring Namespaces
~namespace_init_countfloat1.0Starting the index of the robot name.
~delay_after_assignementfloat0.5The unit is seconds. It defines the amount of delay after each robot allocation.
~global_framestring"/map"Used in the global coordinate system. In a single robot, it is the same as the "map_topic" parameter. In the case of multiple robots, the coordinate system name corresponds to the global coordinate system name.