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.