12 - Turtlebot 1
Robotics I
Poznan University of Technology, Institute of Robotics and Machine Intelligence
Laboratory 12 - Turtlebot 1
Goals
By the end of this lab you will:
- Explain the difference between SLAM (Simultaneous
Localization and Mapping) and AMCL (Adaptive Monte‑Carlo
Localization).
- Launch Cartographer‑based SLAM on a simulated
TurtleBot 3 and build a 2‑D occupancy‑grid map.
- Save the map as a set of YAML/PGM files.
- Localise the robot on the saved map with AMCL
(Navigation2) and command autonomous navigation
goals.
- Analyse how selected AMCL parameters influence localisation accuracy and CPU load.
Note: All commands are meant to be run inside the Docker container created below.
Preparation
- Pull the ROS 2 Jazzy image
docker pull osrf/ros:jazzy-desktop
- Run the container (replace
CONTAINER_NAME
with your student ID):
IMAGE_NAME="osrf/ros:jazzy-desktop"
CONTAINER_NAME="" # student ID number
xhost +local:root
XAUTH=/tmp/.docker.xauth
if [ ! -f $XAUTH ]
then
xauth_list=$(xauth nlist :0 | sed -e 's/^..../ffff/')
if [ ! -z "$xauth_list" ]
then
echo $xauth_list | xauth -f $XAUTH nmerge -
else
touch $XAUTH
fi
chmod a+r $XAUTH
fi
docker stop $CONTAINER_NAME || true && docker rm $CONTAINER_NAME || true
docker run -it \
--env="DISPLAY=$DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
--env="ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST" \
--env="ROS_LOCALHOST_ONLY=1" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
--env="XAUTHORITY=$XAUTH" \
--volume="$XAUTH:$XAUTH" \
--privileged \
--network=host \
--shm-size=1024m \
--name="$CONTAINER_NAME" \
$IMAGE_NAME \
bash
- Install the missing packages
apt update
apt install -y git python3-pip python3-vcstool \
\
ros-jazzy-cartographer ros-jazzy-cartographer-ros ros-jazzy-navigation2 ros-jazzy-nav2-bringup
In the meantime, read the overview of SLAM and AMCL below. You can also check out the TurtleBot 3 documentation.
- Create a workspace and clone TurtleBot 3 sources
source /opt/ros/jazzy/setup.bash
mkdir -p ~/ros2_ws/src && cd ~/ros2_ws/src
git clone -b jazzy https://github.com/ROBOTIS-GIT/turtlebot3.git
git clone -b jazzy https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
git clone -b jazzy https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
cd ~/ros2_ws
rosdep install -yi --from-paths src
colcon build --symlink-install
echo "source ~/ros2_ws/install/setup.bash" >> ~/.bashrc
- Quality‑of‑life environment variables
echo 'export TURTLEBOT3_MODEL=burger' >> ~/.bashrc
echo 'export GAZEBO_MODEL_PATH=$HOME/.gazebo/models:$HOME/ros2_ws/src/turtlebot3_simulations/turtlebot3_gazebo/models' >> ~/.bashrc
source ~/.bashrc
SLAM & AMCL Overview
What is SLAM?
SLAM (Simultaneous Localization and Mapping) is the process of building a map of an unknown environment while estimating the robot’s pose within that map. Both tasks support each other and must be solved together.
Courtesy of
MathWorks.
What is AMCL?
AMCL (Adaptive Monte‑Carlo Localization) is a probabilistic 2‑D localisation method that tracks robot pose on a known map using a particle filter. The algorithm adapts the number of particles to balance accuracy and CPU load.
Particles (arrows) maintained by AMCL. Courtesy of
CMuQ
Robotics.
Task 1 – Run SLAM and Build a Map
- Launch Gazebo
export TURTLEBOT3_MODEL=burger
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
- Start Cartographer SLAM
export TURTLEBOT3_MODEL=burger
ros2 launch turtlebot3_cartographer cartographer.launch.py use_sim_time:=True
- Drive the robot (new terminal)
export TURTLEBOT3_MODEL=burger
ros2 run turtlebot3_teleop teleop_keyboard
Use W
, A
, S
, D
,
X
to cover the entire world while observing the map grow in
rviz2.
Task 2 – Save the Map
mkdir -p ~/maps
ros2 run nav2_map_server map_saver_cli -f ~/maps/turtlebot3_world_map
Files turtlebot3_world_map.yaml
and
turtlebot3_world_map.pgm
are created in
~/maps
.
Task 3 – Localise with AMCL & Navigate
- Restart (or keep) the simulator
export TURTLEBOT3_MODEL=burger
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
- Launch Navigation 2 (AMCL)
export TURTLEBOT3_MODEL=burger
ros2 launch turtlebot3_navigation2 navigation2.launch.py \
\
use_sim_time:=True map:=/root/maps/turtlebot3_world_map.yaml
Initial pose
In rviz2, select 2D Pose Estimate, click near the robot and drag in its forward direction. This sets the initial pose of the robot on the map.Send a navigation goal
Select Navigation Goal, click‑and‑drag on the map. The planner computes a path and drives the robot autonomously. Drive the robot to a few different locations to test the navigation.
Final Assignment (submit on eKursy)
- Repeat Tasks 1–3 in the
turtlebot3_house
world:
export TURTLEBOT3_MODEL=burger
ros2 launch turtlebot3_gazebo turtlebot3_house.launch.py
- Parameter study – open
~/ros2_ws/src/turtlebot3/turtlebot3_navigation2/param/burger.yaml
, modify and explain how each parameter influences AMCL (accuracy, convergence speed, CPU usage):
beam_skip_distance
(whendo_beamskip: true
)
laser_max_range
,laser_min_range
max_beams
max_particles
resample_interval
update_min_a
,update_min_d
- Upload
- Map of
turtlebot3_house
(copy pgm file to the host and convert it to PNG usingconvert
command from ImageMagick or take a sccreenshot of the loaded map in rviz2) - Your parameter explanations (
.txt
).