In this activity, we will be programming a robot to navigate a maze.
A maze is a network of passages designed as a puzzle through which your robot has to navigate to the end. Since you are new at this, we encourage you to use a simple maze, where there is one path to the exit (or target square) and no loops. In other words, every possible branch dead-ends somewhere. There is a good article on mazes in Wikipedia, and if you do an Internet search on "robot mazes" you will find a lot of pictures and video.
Your robot will start in a defined location, and is done when it reaches the target. There are a few simple strategies, and ways to program maze-following robots. You are a pretty good programmer by now , so we will discuss how we solved the problem and give you some strategy ideas, but you will write your own program.
"Algorithm" is a term used in math, engineering and programming, and simply means the steps or rules to solve a problem. Since people have been solving mazes for at least 2,500 years, there is a lot of information available on maze-solving algorithms. We want to build a perfect maze, one without loops, so that you can use the "follow the wall" algorithm. Your robot can simply follow either the right or left wall of the maze, and eventually get to the target spot. Since your robots have the distance sensor on the left side, following the left wall might make the most sense.
Following the wall is pretty simple:
Before you start programming, write out your algorithm for your teacher. Be sure you can explain everything that can happen before you start writing your program.
If you are going to follow the left-hand wall, here are some things to think about:
Try it! https://www.robotmesh.com/create/306410
Things we will need:
Try it! https://www.robotmesh.com/create/306433
The next problem to solve is coming up with a way for the robot to reliably follow the wall. This can be achieved by placing the Ultrasonic Range Finder on the left side of the robot facing the wall and using the following algorithm:
Try it! https://www.robotmesh.com/studio/307100
Finally, we'll write code that instructs the robot to go left if the ultrasonic range finder detects an opening (i.e. the absence of a wall)
Try it! https://www.robotmesh.com/create/305930
The program in the link above combines the three strategies of turning right if a corner is detected, following a wall, and exploring all available openings on the left-side of the robot.
This solution adds a few additional features such as a timer to see if the robot can complete its run in two minutes and uses the LED lamps mounted to the front to signal when the robot is about to make a turn.
Run your robot through the maze. Did it get stuck anywhere? Were you able to "fix" your program so that it finished successfully? How long did the run take? Does your robot always do exactly the same path, or is it slightly different.