Programming Assignment: Robot Maze Runner
Programming a more serious ROS application


Write a python script to control a robot running a maze from a starting point to an ending point. For our purposes the ending point is when you stop the script, or pick up the robot. In other words for the moment your robot does not need to detect the end of the maze itself.

You should write and test your code first on the simulator. You can choose STDR, Gazebo or The ConstructSim. They are all three legitimate simuators, each with it’s pros and cons. This command will give you a pretty nice “built-in” maze using Gazebo, but remember that Gazebo doesn’t work well in VMs at all. It usually crashes :)

$ roslaunch turtlebot3_gazebo turtlebot3_stage_4.launch 

Remember it’s worth trying to work in the simulator first. If your code works well in the simulator, you know that your algorithm and logic are right. However, even though it works perfect in the simulator, it might encounter unexpected problems in the real world. The physical robot will behave a lot differently than the simulated one. Take that into account.

The wall-following algorithm can be the basis of the solution, but it is not the only one. And even if you use that, going around corners or handling dead ends will need special attention. But you are encouraged to try different algorithms. You can find tons of algorithms online. Feel free to use any of them. You can invent your own algorithm as well.

The Maze

Each team can create their own maze as long as it is simuilarly complex as the one in this diagram. Remember: the lidar on our robots has particular limitations: The specs say that minimum distance is 120 mm (12 cm, about 5 inches) and max is 3.5 M, which is about 3.5M which is a little over 11 feet. So factoring in the size of the robot, the narrowest passage that we should ask it to navigate is 12 + 12 + 20 = 44cm = 1.5 feet.

Maze! There is a maze already set up next to the lab for you to practice on. You can change it if you want, but it doesnt need to be too complex.


This is a pair programming assignment. Students should self select into teams of two students. It’s fine to talk to everyone else, as well as google for ideas. Just as long as the code is written and fully understood by both members of the team. You will submit one solution for each team (see below.)

What to submit

The submission to Latte:

  1. The source code, including a readme explaining what it is, how to run it and any other reflections
  2. A video of the real robot running the maze successfully. THis can be totally rough, unedited, with crazy laughing in the background. We just want to see that it worked.

Background Info

From previous semesters here are some practical tips:

  • Wall following is tricky because depending on how you do it, it might oscilate back and forth. Read up about PID below, it has some good but advanced ideas.
  • Note that as you are following a wall, you need to notice when the wall suddenly disappears and at that point you have to turn to keep following it.
  • Conversely the robot might be in the middle where all walls are far and as far from it, in which case you have to just drive until you get to the wall and then start following it
  • Feel free to google for wall following robot and be inspired by what you read. Just don’t copy the code, please.
  • Here are some solutions that might be helpful, but please do not limit to these.
Right hand Rule - For this assignment, you can choose either one from Right-Hand Rule (which means you will turn to the rightmost route whenever possible) and Left-hand Rule (which means you will turn left whenever possible). Here are some examples for what you should expect when using Right-hand Rule:

Working with LaserScan data

Here is a great video which provides almost everything you need to understand to manipulate the LaserScan data: Reading Laserscan Data The most important field that you need to understand is the “ranges”. You can access the reading of a specific angle by using “range[index]”, and access a subarray by using “range[index0:index1]”

An infinite LIDAR value in STDR is inf (infinity), while that on the actual Turtlebot3 is 0. A 0 reading from Turltebot3 can refer to either infinity or actual 0 (obstacle is right next to Turtlebot3). Check the valid ranges and also remember that the Lidar’s range is not infinite!

PID Control

PID is a well known technique for smoothing out control, to avoid oscilation. Applying PID control to your algorithm will make it more robust and perform more consistently. PID control is a smoothing function which helps you better follow the wall without too much fluctuation. It will make the robot turn at a higher speed when you are too away from the designated route (too far or too close to the wall), and turn at a slower speed when you are close to it.

Here are some great links. You will be amazed at how well this works.