Cartographer is a system that provides simultaneous localisation and mapping (SLAM) in 2D and 3D across multiple platforms and sensor configurations. Nowadays there are still many users who utilise this tool to create SLAM maps.
Here are my steps to run Cartographer to create a SLAM map on a recorded rosbag file.
- Installing Cartographer ROS
I am using a computer running Ubuntu 20.04 OS with ROS Noetic installed.
I ran the following commands to install the Cartographer ROS.
sudo apt-get update
sudo apt-get install -y python3-wstool python3-rosdep ninja-build stow
mkdir Cartographer
cd Cartographer
wstool init src
wstool merge -t src https://raw.githubusercontent.com/cartographer-project/cartographer_ros/master/cartographer_ros.rosinstall
wstool update -t src
sudo rosdep init
rosdep update
When I was running this command, I ran into an error.
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
By commenting out this line in the package.xml file, I was able to run the rosdep install command successfully. ( I think it was not a good approach to eliminate the error by commenting out or deleting a line of code in the original xml file.)
Cartographer uses the abseil-cpp library that needs to be manually installed using this command:
src/cartographer/scripts/install_abseil.sh
and then
catkin_make_isolated --install --use-ninja
This builds Cartographer from the latest HEAD of the master branch.
- Validating the recorded bag file
When we want to run cartographer_ros, we need to source your ROS environment by running*source install_isolated/setup.bash*
first.
Cartographer ROS provides a tool named*cartographer_rosbag_validate*
to automatically analyse data present in your bag. It is generally a good idea to run this tool before trying to tune Cartographer for incorrectPreformatted text
data. It can detect a variety of mistakes commonly found in bags. For instance, if asensor_msgs/Imu
topic is detected, the tool will make sure that the gravity vector has not been removed from the IMU measurements because the gravity norm is used by Cartographer to determine the direction of the ground.
The following command can be used to validate the recorded bag file:
cartographer_rosbag_validate -bag_filename my_bag.bag
- Creating configuration file and launch file
The default .lua configuration file cannot be used directly for os lidar. Considering that ouster scans 3D points cloud data from the environment, I copied the backpack_3d.lua file, renamed it myTest_3d.lua and made some modifications to it.
I copied the offline_backpack_3d.launch file, renamed it offline_myTest_3d.launch and made some modifications to it.
- Running Cartographer ROS to create a SLAM map
Now I have made all the preparations for creating a SLAM on my recorded bag file.
Source the environment first by running the command. If you had run this command before validating the bag file, then this step is not needed.
source install_isolated/setup.bash
Run roslaunch command by specifying the launch file created for this test and the bag file recorded before.