Skip to content

TurtleBot3 – SLAM (Simultaneous Localization and Mapping)

Overview

SLAM (Simultaneous Localization and Mapping) is a technique that allows the TurtleBot3 to build a map of an unknown environment while simultaneously estimating its position within that map. This is a core capability for mobile robotics and is essential for autonomous navigation.

TurtleBot3 uses the Cartographer SLAM method by default in ROS 2 Humble, enabling high-quality 2D mapping in indoor environments using its onboard LiDAR sensor and optional IMU.


Getting Started

Prerequisites

  • SLAM must be run from the Remote PC.
  • Launch the robot.launch.py Bringup node on the TurtleBot3 SBC before starting SLAM.

Launch SLAM Node

# On the TurtleBot3 SBC
$ ssh ubuntu@{IP_ADDRESS_OF_RASPBERRY_PI}
$ export TURTLEBOT3_MODEL=burger
$ ros2 launch turtlebot3_bringup robot.launch.py

# On the Remote PC
$ export TURTLEBOT3_MODEL=burger
$ ros2 launch turtlebot3_cartographer cartographer.launch.py

Teleoperation for Mapping

Once SLAM is running, use teleoperation to manually explore the environment and collect mapping data:

$ export TURTLEBOT3_MODEL=burger
$ ros2 run turtlebot3_teleop teleop_keyboard

Use the keyboard to slowly and thoroughly explore the space, avoiding sudden movements. The goal is to allow the robot to scan all corners and spaces to build a complete occupancy map.


Saving the Map

After building a satisfactory map, you can save it using:

$ ros2 run nav2_map_server map_saver_cli -f ~/map

This command generates a map.pgm and map.yaml in your home directory. The .pgm file is the occupancy grid, while the .yaml defines map metadata.


SLAM Configuration Parameters

TurtleBot3’s SLAM behavior is controlled via the turtlebot3_lds_2d.lua configuration file. Key parameters include:

  • MAP_BUILDER.use_trajectory_builder_2d: Enables 2D mapping mode.
  • TRAJECTORY_BUILDER_2D.min_range: Minimum LiDAR sensing range.
  • TRAJECTORY_BUILDER_2D.max_range: Maximum LiDAR sensing range.
  • TRAJECTORY_BUILDER_2D.use_imu_data: Toggle IMU usage.
  • TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching: Enhances local scan accuracy.
  • POSE_GRAPH.optimize_every_n_nodes: Controls global SLAM optimization frequency.
  • POSE_GRAPH.constraint_builder.min_score: Match score threshold for constraints.
  • POSE_GRAPH.constraint_builder.global_localization_min_score: Global localization trust threshold.

Use these parameters to tune SLAM performance for accuracy and responsiveness in different operating environments.


Output Map Format

The output is a 2D Occupancy Grid Map (OGM): - White: Free space - Black: Obstacles - Gray: Unknown space

Maps can be visualized in RViz in real time and reused for navigation missions using Navigation2.


Summary

TurtleBot3's SLAM capabilities allow it to operate autonomously in unknown environments by constructing real-time maps and self-localizing within them. With tools for parameter tuning, visualization, and map saving, it provides a complete SLAM development and training platform suitable for indoor exploration and autonomous robotics research.