ROS2

Advanced

ROS2 SLAM and Navigation: MentorPi M1 Maps a Maze and Solves It

MentorPi M1 robot SLAM in a maze
Build This
Build time

Estimated cost

What You'll Need
  • Hiwonder MentorPi M1 robot (Raspberry Pi 5)
  • TOF lidar sensor
  • Encoder and IMU sensors

Watch It In Action

This demo runs the complete ROS 2 navigation pipeline on a Hiwonder MentorPi M1 in a maze: real-time map building first, then autonomous navigation to one goal and to a chain of goals.

Mapping the maze with SLAM

SLAM stands for simultaneous localization and mapping. The robot collects point cloud data with its TOF lidar, and SLAM Toolbox in ROS 2 processes it. In RViz, you can watch it build a 2D occupancy grid map in real time.

The algorithm does three main jobs: it preprocesses the raw data, matches the current observation against the map, and merges new data to update the map. The robot keeps estimating its own pose while it builds the map of its surroundings. Each laser scan adds new information about the maze walls and corridors, and particle filters hold several guesses about the robot's position and pick the most likely one.

I drive the robot with keyboard teleop during this stage, then save the map once the maze is covered.

Single-goal navigation with Nav2

After launching navigation, I set the robot's starting position with 2D Pose Estimate, then set a target with the 2D Nav Goal tool in RViz. The planner server calculates a global path from the robot to the goal, shown as a green line on the map.

The controller server then follows that plan using the DWA local planner. It generates velocity commands while avoiding obstacles and tracking the global path, using encoder and IMU data for odometry.

The costmap has three layers:

  • The static map from SLAM
  • An obstacle layer from current sensor readings
  • An inflation layer that adds safety margins around obstacles

Together they keep the route collision-free.

Multi-point navigation

For multi-point navigation, I set a sequence of waypoints. Nav2's behavior tree coordinates the goals and the robot goes to each one in order. At each stop it uses AMCL, Adaptive Monte Carlo Localization, to check its position against the map, which corrects any drift in the odometry.

Recovery behaviors handle the moments when the robot gets stuck: clearing the costmaps, rotating in place and backing up. The behavior tree triggers these automatically when needed. You can see AMCL's particle cloud tighten around the robot's real position as the mission runs.

What this shows

  • SLAM Toolbox for mapping
  • Nav2 for path planning and control
  • AMCL for localization

It also covers the core ROS 2 ideas: publishers and subscribers for sensor data, action servers for navigation goals, transform trees for coordinate frames, and parameter servers for configuration. This is the base for more advanced ROS 2 robots.