Ambassador Programming Robots Badge Activity
Create A Program To Guide A Robot Through A Maze
Write a computer program that tells a robot what to do!
Time needed: 60 minutes
- Robot Maze 1
- Robot Maze 2
- Robot Maze 1 Solution for your reference
- Robot Maze 2 Solution for your reference
- Chess piece, checker, or other robot stand-in
- Pen or pencil
A computer program is a type of algorithm—a set of step-by-step instructions. The list of steps for telling the robot how to complete the task is an algorithm. Recipes and driving directions are algorithms, too!
Computer programs are written in code, a language that can be understood by machines. Programs use commands to tell a machine what to do. A command is one step in a program.
You’ve been challenged to write programs a robot can follow to navigate two different mazes!
Part 1: Navigate a robot through a paper maze. (15 minutes)
First, write a program that will tell a robot how to solve the maze on the Robot Maze 1 handout.
The maze consists of a thick black line on a large sheet of white paper. The robot you’re writing this program for is designed to be follow a black line. Use regular language—you don't need to write commands in code yet.
To check if a program runs correctly, use the robot stand-in, moving it through the maze according to the program.
How did it go?
- If the robot makes it to the end of the maze, your program works!
- If the robot doesn’t make it through the maze, debug the program by going over each step. If the robot makes a wrong turn, figure out why and revise the code to avoid the error. Then, test the code again until the robot solves the maze.
If you need help, check out Robot Maze 1 Solution for one sample program that a robot could follow to navigate the maze.
Want more challenge? Try this!
Pull out a map of your favorite hiking trail! Then, write a program a robot could follow to travel it.
Part 2: Write a program to navigate a robot through any simple maze. (45 minutes)
When programming with a computer language, it’s important to get the syntax exactly right. Syntax is the set of rules used by a language. It includes spelling, spacing, symbols, and punctuation.
To plan a program without worrying about syntax, programmers sometime use pseudocode. ("Pseudo" means fake.) Pseudocode uses commands in regular human language. It can then be translated into any kind of computer language. The only rule for pseudocode is that it should be easy to understand.
Next, write a computer program in pseudocode that tells a robot how to solve any simple maze. Read pages 1 and 2 of the Robot Maze 2 handout to learn about programming using conditionals, loops, and functions.
Then, translate the “Left Hand on Wall” method (on page 3 of the handout and below) into pseudocode. This program is often used for maze-solving robots. The rule is based on the idea that if you’re walking through a maze and always keep the same hand on the wall, eventually you’ll end up at the exit.
Here is what the rule says:
- Always turn left if you can.
- When you can't turn left, go straight.
- When you can't turn left or go straight, turn right.
- When you can't turn left, go straight, or turn right, turn around because you must be at a dead end.
Write the rule in pseudocode on page 3 of the Robot Maze 2 handout.
Then, on page 4 of the handout, write a program using loops and conditional statements that can take a robot from the beginning to the end of any simple maze. The robot may take wrong turns, so it won't be as efficient as when you just gave it "driving directions" in part 1.
When the program is finished, test your program with the maze on page 5 of the handout, the same way you tested your program in part 1. Use the robot stand-in to move through the maze.
If the robot gets stuck before it reaches the end, debug the program by going over each step to find the error. Keep iterating, or repeating the process of testing and debugging, until the program works and the robot solves the maze!
Want a challenge? Try this!
Robots can run more than one program at the same time. For example, while the maze-solving program is running, the robot could also be running code that tells it to follow a line.
So, write pseudocode with conditional statements, loops, and functions to create a program that makes a robot follow the turns of a line.
To help, here's how line-following robots work:
- A line-following robot usually has two light sensors, one on each side, that control the wheels on that side
- The light sensors can detect the difference between the dark line and the white paper.
- As long as the light sensor detects light (the white paper), the wheel it controls will keep turning. So as long as the black line is centered under the robot, the sensors on the sides will detect white paper. With both wheels turning at the same speed, the robot will move forward.
- When the light sensor detects dark (the black line) on one side, the wheel on that side stops. Meanwhile, the other wheel, which is still over the white paper, keeps going. This causes the robot to pivot around in the direction of the black line.
- When the robot has turned enough so that the black line is centered beneath it, the second wheel begins to turn again and the robot moves forward.
- When both sensors detect dark (the black box at the end of the maze), both wheels stop turning and the robot stops moving.
And that’s it! You’ve now completed two steps of the Ambassador Programming Robots badge! If you had fun doing this, you might want to learn more about robots and design your own with the rest of the Ambassador Robotics badges.
Troop Leaders: The instructions for all badge steps are available free of charge in your Girl Scout Volunteer Toolkit.
Girl Scouts at Home activities have been adapted from existing Girl Scout programming and optimized for use at home during a period of social distancing.
Adapted from steps 4 and 5 of the Ambassador Programming Robots badge. Contact your troop leader or your local Girl Scout council to become a Girl Scout member and learn all the requirements needed to earn the badge .