Tuning Cartographer is unfortunately really difficult. The system has many parameters many of which affect each other. This tuning guide tries to explain a principled approach on concrete examples.
Cartographer provides built-in tools for SLAM evaluation that can be particularly useful for measuring the local SLAM quality.
They are stand-alone executables that ship with the core
cartographer library and are hence independent, but compatible with
Therefore, please head to the Cartographer Read the Docs Evaluation site for a conceptual overview and a guide on how to use the tools in practice.
These tools assume that you have serialized the SLAM state to a
cartographer_ros, you can invoke the
assets_writer to serialize the state - see the Exploiting the map generated by Cartographer ROS section for more information.
Example: tuning local SLAM¶
At our starting configuration, we see some slipping pretty early in the bag. The backpack passed over a ramp in the Deutsches Museum which violates the 2D assumption of a flat floor. It is visible in the laser scan data that contradicting information is passed to the SLAM. But the slipping also indicates that we trust the point cloud matching too much and disregard the other sensors quite strongly. Our aim is to improve the situation through tuning.
If we only look at this particular submap, that the error is fully contained in one submap. We also see that over time, global SLAM figures out that something weird happened and partially corrects for it. The broken submap is broken forever though.
Since the problem here is slippage inside a submap, it is a local SLAM issue. So let’s turn off global SLAM to not mess with our tuning.
POSE_GRAPH.optimize_every_n_nodes = 0
Correct size of submaps¶
The size of submaps is configured through
Looking at the individual submaps for this example they already fit the two constraints rather well, so we assume this parameter is well tuned.
In our case, the scan matcher can freely move the match forward and backwards without impacting the score.
We’d like to penalize this situation by making the scan matcher pay more for deviating from the prior that it got.
The two parameters controlling this are
The higher, the more expensive it is to move the result away from the prior, or in other words: scan matching has to generate a higher score in another position to be accepted.
For instructional purposes, let’s make deviating from the prior really expensive:
TRAJECTORY_BUILDER_2D.ceres_scan_matcher.translation_weight = 1e3
This allows the optimizer to pretty liberally overwrite the scan matcher results.
This results in poses close to the prior, but inconsistent with the depth sensor and clearly broken.
Experimenting with this value yields a better result at
Here, the scan matcher used rotation to still slightly mess up the result though.
4e2 leaves us with a reasonable result.
To make sure that we did not overtune for this particular issue, we need to run the configuration against other collected data.
In this case, the new parameters did reveal slipping, for example at the beginning of
b2-2016-04-05-14-44-52.bag, so we had to lower the
This setting is worse for the case we wanted to fix, but no longer slips.
Before checking them in, we normalize all weights, since they only have relative meaning.
The result of this tuning was PR 428.
In general, always try to tune for a platform, not a particular bag.
The default configuration and the above tuning steps are focused on quality. Only after we have achieved good quality, we can further consider special cases.
By low latency, we mean that an optimized local pose becomes available shortly after sensor input was received, usually within a second, and that global optimization has no backlog. Low latency is required for online algorithms, such as robot localization. Local SLAM, which operates in the foreground, directly affects latency. Global SLAM builds up a queue of background tasks. When global SLAM cannot keep up the queue, drift can accumulate indefinitely, so global SLAM should be tuned to work in real time.
There are many options to tune the different components for speed, and we list them ordered from the recommended, straightforward ones to the those that are more intrusive. It is recommended to only explore one option at a time, starting with the first. Configuration parameters are documented in the Cartographer documentation.
To tune global SLAM for lower latency, we reduce its computational load until is consistently keeps up with real-time input. Below this threshold, we do not reduce it further, but try to achieve the best possible quality. To reduce global SLAM latency, we can
MAP_BUILDER.num_background_threadsup to the number of cores
- for the adaptive voxel filter(s), decrease
- decrease search windows sizes,
To tune local SLAM for lower latency, we can
- for the adaptive voxel filter(s), decrease
max_range(especially if data is noisy)
Note that larger voxels will slightly increase scan matching scores as a side effect, so score thresholds should be increased accordingly.
Pure Localization in a Given Map¶
Pure localization is different from mapping. First, we expect a lower latency of both local and global SLAM. Second, global SLAM will usually find a very large number of inter constraints between the frozen trajectory that serves as a map and the current trajectory.
To tune for pure localization, we should first enable
TRAJECTORY_BUILDER.pure_localization = true and
POSE_GRAPH.optimize_every_n_nodes to receive frequent results.
With these settings, global SLAM will usually be too slow and cannot keep up.
As a next step, we strongly decrease
to compensate for the large number of constraints.
We then tune for lower latency as explained above until the system reliably works in real time.
If you run in
submaps.resolution should be matching with the resolution of the submaps in the
.pbstream you are running on.
Using different resolutions is currently untested and may not work as expected.
Odometry in Global Optimization¶
If a separate odometry source is used as an input for local SLAM (
use_odometry = true), we can also tune the global SLAM to benefit from this additional information.
There are in total four parameters that allow us to tune the individual weights of local SLAM and odometry in the optimization:
POSE_GRAPH.optimization_problem.local_slam_pose_translation_weight POSE_GRAPH.optimization_problem.local_slam_pose_rotation_weight POSE_GRAPH.optimization_problem.odometry_translation_weight POSE_GRAPH.optimization_problem.odometry_rotation_weight
We can set these weights depending on how much we trust either local SLAM or the odometry. By default, odometry is weighted into global optimization similar to local slam (scan matching) poses. However, odometry from wheel encoders often has a high uncertainty in rotation. In this case, the rotation weight can be reduced, even down to zero.
Still have a problem ?¶
If you can’t get Cartographer to work reliably on your data, you can open a GitHub issue asking for help.
Developers are keen to help, but they can only be helpful if you follow an issue template containing the result of
rosbag_validate, a link to a fork of
cartographer_ros with your config and a link to a
.bag file reproducing your problem.