All projects

Michigan Tech · Robot Operating Systems

Autonomous Maze Solver (ROS 2)

A TurtleBot 3 that drives itself through a 5×5 maze using LiDAR and IMU feedback, written as a ROS 2 node with a teammate.

The TurtleBot 3 driving the maze.

Try it

  1. Before the run, every cell got a number (0-24) and a list of which sides are open. Tick "Show the map data" to see it.
  2. A search over that map finds the shortest way from the start cell to the end cell.
  3. The route becomes the only two things the robot does: drive forward some cells, or turn 90°.
  4. On the robot, the LiDAR measures each forward move and keeps it centered, and the IMU times each turn.

Moves

    Sensors

    LiDAR ahead
    -
    LiDAR 30° left / right
    -
    IMU heading
    -

    Our real run: from cell 20 facing north to cell 24. On the robot this route was hard-coded (the planner wasn't connected yet); its last "forward 2" stopped after one cell, when the wall check (0.25 m) kicked in.

    Problem

    Get a TurtleBot 3 from a start cell to an end cell in a 5×5 maze on its own, using only its onboard sensors and ROS 2. Built with Raymond Nelson for Robot Operating Systems.

    Approach

    Every move is built from two primitives:

    • Driving forward takes a LiDAR reading of the wall ahead, then drives until that distance has closed by one cell (0.42 m), or until the robot is within 0.25 m of a wall. While driving, LiDAR beams 30° left and right of center watch the side walls, and the robot steers away from any wall that gets too close, which keeps it centered.
    • Turning computes a target heading 90° from the current IMU yaw, then rotates in place until it is within 1° of that heading.

    How it came together

    • Sensing had to keep running while the robot moved. In ROS 2, rclpy.spin() blocks forever, but the navigation code also needs to loop while driving. The fix was multithreading: the node spins in a background thread, so LiDAR and IMU callbacks keep updating while the main thread runs the motion primitives.
    • LiDAR doubles as a steering correction. Watching the side walls while driving keeps the robot centered in each corridor, which made runs more consistent than distance-driving alone.

    Key decisions

    • Pivot from a planner to a set route. Our first plan, inspired by A*, would search the maze grid for the shortest route and hand the robot a list of moves. Between hardware limits and the deadline, connecting the planner to reliable motion was too hard to debug in time, so we drove a predetermined route instead. The planner (a depth-first search with backtracking) still runs in the code, but its output doesn’t drive the robot yet.

    What went wrong

    Relying on odometry and the IMU meant errors added up over a run. Some runs felt like a coin toss. Putting everything in one Python script also made it harder to test pieces separately.

    What I’d do differently

    • Reconnect the path planner to the motion functions, now that ROS communication is solid.
    • Fuse LiDAR and odometry to cut down on dead-reckoning error.
    • Split the code into separate ROS nodes for sensing, planning, and acting, with launch files.