This project comprehensively compares different SLAM (Simultaneous Localization and Mapping) techniques using ROS2 and TurtleBot3 in a simulated Gazebo environment. The SLAM algorithms compared in this project are Cartographer and RTAB-Map. The goal is to evaluate their performance using different LIDAR resolutions and determine the most effective SLAM solution for different scenarios.
- Operating System: Ensure you are running Ubuntu 22.04.
- ROS Installation: Install ROS Humble Desktop Full. You can follow the instructions here.
-
Operating System: Ensure you are running Ubuntu 20.04.
-
Docker: Install Docker on your system. Follow the instructions here.
-
NVIDIA GPU Support: If you have an NVIDIA GPU, install NVIDIA Docker support. Follow the instructions here.
NOTE: For a detailed guide on setting up NVIDIA GPU support for running GUI applications in Docker containers, refer to this medium article.
-
Install Dependencies: Install the required ROS and Python packages:
sudo apt-get update && \ apt-get install -y \ ros-humble-joint-state-publisher \ ros-humble-tf-transformations \ ros-humble-gazebo-ros \ ros-humble-gazebo-ros-pkgs \ ros-humble-cartographer \ ros-humble-cartographer-ros \ ros-humble-rtabmap \ ros-humble-rtabmap-ros \ ros-humble-navigation2 \ ros-humble-nav2-bringup \ ros-humble-ament-cmake \ python3-pip pip3 install \ transforms3d \ opencv-python \ opencv-contrib-python
-
Source ROS Environment: Add ROS environment setup to your bash configuration:
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc echo "source /usr/share/gazebo/setup.sh" >> ~/.bashrc
-
Create ROS Workspace: Create a ROS workspace, clone the repository, and build the packages:
mkdir -p ~/clutterbot/src cd ~/clutterbot/src git clone https://github.com/Tanishq30052002/ros2-slam-comparison.git cd ~/clutterbot colcon build --symlink-install
-
Source the workspace setup:
echo "source ~/clutterbot/install/setup.bash" >> ~/.bashrc
-
Clone Repository: Clone the repository containing Docker setup:
cd ~ git clone https://github.com/Tanishq30052002/ros2-slam-comparison.git
-
Build Docker Image: Build the Docker image from the cloned repository:
cd ~/ros2-slam-comparison docker build -t clutterbot:base .
-
Start Docker Container: Start the docker container
cd ~/ros2-slam-comparison docker compose up
NOTE To enable X11 forwarding, run the following command once every time the machine restarts:
xhost + local:docker
Enter Docker Container: To enter the Docker container:
docker exec -it clutterbot bash
NOTE: If using docker, then you must need to be inside the docker container for running any of th efollowing commands
To initialize the simulation environment, execute the following commands based on your desired LiDAR configuration:
- Gazebo
- LiDAR with Angular Resolution: 0.9
LIDAR_RESOLUTION=0.9 ros2 launch turtlebot3_burger turtlebot3_aws_small_house_gazebo.launch.py
- LiDAR with Angular Resolution: 0.9
LIDAR_RESOLUTION=2.5 ros2 launch turtlebot3_burger turtlebot3_aws_small_house_gazebo.launch.py
- LiDAR with Angular Resolution: 0.9
- RViz
- To open RViz for sensor analysis, utilize:
ros2 launch turtlebot3_burger rviz2.launch.py
- To open RViz for sensor analysis, utilize:
Commence one of the following SLAM algorithms for map generation:
- Cartographer SLAM
ros2 launch turtlebot3_cartographer cartographer.launch.py
- RTAB-Map SLAM
ros2 launch turtlebot3_rtab rtab.launch.py
Navigate the robot throughout the entire environment to create the map using the Teleop Twist Keyboard:
ros2 run teleop_twist_keyboard teleop_twist_keyboard
To save the map, follow these steps:
-
Change Directory: Move to the specific map directory based on the SLAM algorithm used and LiDAR resolution:
cd ~/clutterbot/src/turtlebot3_burger_navigation2/maps/{slam_name}_lidar{resValue}res
Replace {slam_name} with the name of the SLAM algorithm (cart or rtab) and {resValue} with the resolution value of the LiDAR (0-9 or 2-5).
-
Run Map Saver: Execute the following command to save the map:
ros2 run nav2_map_server map_saver_cli -f map
After saving the map, you can initiate navigation by following these steps:
-
Change Directory: Navigate to the directory where the map is saved:
cd ~/clutterbot/src/turtlebot3_burger_navigation2/maps/{slam_name}_lidar{resValue}res
Replace {slam_name} with the name of the SLAM algorithm (cart or rtab) and {resValue} with the resolution value of the LiDAR (0-9 or 2-5).
-
Launch Navigation: Launch the navigation system by executing:
ros2 launch turtlebot3_burger_navigation2 navigation2.launch.py map:=map.yaml
NOTE: Ensure that the map file name matches with the one saved in the previous step (map.yaml). Adjust the path and filenames as necessary based on your setup.
Commence one of the following command for map generation with RTab Map in noisy enviroment:
ros2 launch turtlebot3_rtab rtab_with_noise.launch.py
Demonstration video showcasing the implementation of Cartographer SLAM and navigation techniques tailored for lidar with a 0.9-degree angular resolution.
- Comparative Observations:
- % Compute Usage: In our comparative analysis between RTAB Map and Cartographer SLAM, I observed differences in compute usage. RTAB Map generally exhibited higher compute usage due to its feature-based mapping approach, which involves extensive loop closure detection and graph optimization processes. Conversely, Cartographer SLAM, with its grid-based mapping technique, showed relatively lower compute usage, as it primarily focuses on real-time localization and mapping without extensive graph optimizations.
- Variations in Mapping Output with Varying Input Velocity: We noticed variations in the mapping output of both RTAB Map and Cartographer SLAM when subjected to varying input velocities. RTAB Map showed robustness in maintaining map consistency at different velocities, thanks to its efficient loop closure detection and pose graph optimization. However, Cartographer SLAM demonstrated slightly better performance at higher velocities, likely due to its grid-based mapping approach, which can handle rapid motion more effectively.
-
Differences Observed with Lidar Configurations: Running RTAB Map and Cartographer SLAM with different lidar configurations revealed significant differences in mapping performance. With a low-resolution lidar, RTAB Map struggled to capture fine details and small features in the environment, resulting in less detailed maps compared to Cartographer SLAM. Conversely, Cartographer SLAM demonstrated better resilience to low-resolution lidar inputs, producing more coherent maps with fewer artifacts.
-
Loop Closure/Global Correction Step: During our tests, both RTAB Map and Cartographer SLAM demonstrated loop closure and global correction steps. However, the frequency and reliability of these steps varied between the two SLAM packages. RTAB Map exhibited more frequent and robust loop closures, facilitated by its feature-based mapping approach and sophisticated loop closure detection algorithms. In contrast, while Cartographer SLAM also performed loop closures, it tended to miss some in larger environments with sparse features. Adjusting loop closure parameters and increasing feature extraction sensitivity could enhance the visibility of these steps in the simulation for both SLAM packages.
-
Recommendation for the Better Package: Based on my observations, I recommend RTAB Map as the preferred SLAM package for its overall performance and robustness in various scenarios. RTAB Map SLAM also took overall less time to generate the map as compared to Cartographer SLAM. Additionally, RTAB Map's ability to handle varying input velocities and lidar configurations makes it a versatile choice for 2D-SLAM applications.
Below are the findings derived from the evaluation of various SLAM algorithms across different lidar angular resolutions:
-
Cartographer
-
Lidar Resolution: 0.9
-
Lidar Resolution: 2.5
-
-
Rtab Map
-
Lidar Resolution: 0.9
-
Lidar Resolution: 2.5
-
-
Imperfect Map Formation: The map generated does not form perfectly due to environmental noise.
-
Increased Iterations: More iterations are required to achieve a satisfactory map.
-
False Obstacle Detection: The system not only detects actual obstacles but also incorrectly identifies adjacent areas as obstacles.
-
Extended Mapping Time: The overall time required to create the final map is significantly longer.
-
Speed Adjustment Benefits: Operating at a slower speed proves to be beneficial for accurate mapping.