Program a Robot Friend
You have learned so much about how robots think, sense, follow programs, and make choices. Now it is YOUR turn to be the programmer. In this lesson you are going to write a complete, step-by-step program for a pretend robot. Your program will use everything you have learned — steps in order, if-then rules, and the Sense-Think-Act loop. Get ready to think like an engineer!
Meet Your Robot: Helpful Hank
Helpful Hank is a friendly household robot. He has these parts and abilities: Sensors: a camera that can see nearby objects, a distance sensor on the front, and a touch sensor on each hand. Movement: he can roll forward, backward, left, and right. Hands: he has two simple grippers that can pick up and put down small objects. Speaker: he can say short phrases out loud. Your job is to program Hank to carry out a helpful task around the house. Before you start writing the program, you need to plan it carefully.
A robot only does exactly what you tell it. If you forget a step, the robot will not fill in the gap — it will get stuck or do the wrong thing. Think through EVERY step, no matter how obvious it seems to you.
Here is an example program to show you the format. This program tells Hank to deliver a book from the table to the bookshelf: Step 1: Roll forward until the table is detected within 30 centimeters. Step 2: Stop. Step 3: Look with camera. Confirm the book is on the table. Step 4: Extend right gripper. Grip the book. Step 5: Check touch sensor: if book is firmly held, go to Step 6. If not, try gripping again. Step 6: Roll backward 50 centimeters. Step 7: Turn right 90 degrees. Step 8: Roll forward until the bookshelf is detected within 20 centimeters. Step 9: Stop. Step 10: Place the book on the shelf. Open gripper. Step 11: Say 'Book delivered!' out loud. Step 12: Roll back to starting position. Notice: the program uses exact measurements, if-then checks (Step 5), and a complete sequence from start to finish.
Write Hank's Program
- Now it is your turn! You are going to write a complete program for Helpful Hank.
- Choose ONE of these tasks for Hank to do:
- Option A: Bring a cup of water from the kitchen counter to the living room coffee table.
- Option B: Collect three toys from the floor and put them in the toy box.
- Option C: Find and bring a lost sock from the laundry basket to the dresser.
- Follow these steps to write your program:
- 1. PLAN IT FIRST — Before writing any steps, answer these questions on paper:
- What is Hank's starting position?
- What sensors will he use to find the object?
- How will he know he has picked it up successfully?
- What if something is in the way? (Write an if-then rule for it!)
- How will he know when the task is done?
- 2. WRITE THE STEPS — Number each step. Be specific with directions, distances, and actions. Include at least one if-then rule.
- 3. TEST YOUR PROGRAM — Ask a friend or family member to be Hank. Read your program out loud, step by step. They must follow ONLY what you say — no guessing or filling in blanks.
- 4. DEBUG — Did Hank complete the task? If not, find the step that was missing or too vague. Fix it and test again.
- 5. SHARE — Read your final, fixed program to someone and explain why you included your if-then rule. What situation does it handle?
- Remember: the best programs are clear, complete, and specific. A robot can only be as good as the program it runs!
Debugging — fixing problems in your program — is one of the most important skills a programmer has. Nearly every program has at least one bug when it is first written. When your program did not work perfectly the first time, that was completely normal! Real engineers expect to find bugs. They run tests, find problems, fix them, and test again. That cycle — write, test, debug, fix, test again — is how all great programs are made. You just experienced the full programming process: planning, writing, testing, and debugging. Welcome to the world of robotics engineering!
Every professional robotics engineer started exactly where you are — writing simple programs, testing them, finding bugs, and fixing them. The programs get bigger and more complex, but the process is the same. You have already done the most important steps!
You wrote a program for Hank, but when you tested it, he stopped halfway through. What should you do?
Your program says 'go to the bookshelf.' Hank does not move. Why?