Base Mission
7 points Final judgedOne Orange Pom is a basket.
Discovery · Coding Project 17
The last loop — and the last thirty-eight points on the field.
Student PIN:
Back in Project 9 you moved a in three big jumps and were asked what it would take to move it in thirty small ones. Here is the answer you were promised.
#include <kipr/wombat.h>
int main ()
{
int arm = 0;
int position = 200;
enable_servos();
while (position < 1800)
{
position = position + 10;
set_servo_position(arm, position);
msleep(5);
}
disable_servos();
return 0;
}Read it with a partner before you run it, and answer these from the code alone.
| Question | My answer |
|---|---|
| What kind of loop is this? | |
Where does position start? | |
| What makes it stop? | |
| How much does it change each time round? | |
| So how many times does the loop run? |
How is this different from set_servo_position(arm, 1800); on its own?
A Smooth Arm Is a Careful Arm
An arm that snaps to a position throws whatever it is holding. An arm that creeps there sets things down gently — which matters for every final-position mission you have.
Look at that loop again. The three things that control the counting are in three different places:
A does exactly the same job, but it puts the start, the stop, and the step together where you can see all three at once.
for (position = 200; position < 1800; position++)
↑ ↑ ↑
start stop step| Code / part | What it means |
|---|---|
position = 200 | Where the counting begins. Runs once, before anything else. |
position < 1800 | Checked before every trip through the block. The moment it is false, the loop ends. |
position++ | Runs at the end of every trip. ++ means add one — the shorthand you met in Project 9. |
Two inside the parentheses, and none after the closing one. Same rule as while and if — the braces finish the .
while
int position = 200;
while (position < 1800)
{
set_servo_position(arm, position);
msleep(5);
position++;
}Three pieces in three places. Forget the last one and it never ends.
for
int position;
for (position = 200; position < 1800; position++)
{
set_servo_position(arm, position);
msleep(5);
}All three in one place. Hard to forget the step when it is right there.
Use while when… | Use for when… |
|---|---|
| You do not know how many times — it depends on a . | You know the count before you start. Four corners. Two poms. |
| There is more than one way out of the loop. | You are counting up or down by a steady amount. |
| Nothing needs to change by a set step each time. | You want the whole plan readable on one line. |
Look Back at Every Loop You Have Written
Drive until bump. Drive until 4000 . Follow until you see black. Every one of them was a while, and every one had to be — the robot could not know in advance how many times round it would go.
Now think about “put two poms in the basket.” You know it is two. That is what for is for.
The counter does not have to control anything. It can just count how many times you have gone round.
int count;
for (count = 0; count < 4; count++)
{
drive_forward(4000);
turn_right();
}That is a square. Four sides, four corners, four lines of code — and to make it a pentagon you change one number.
⚠ Starting at 0 Means Stopping Before the Count
count = 0; count < 4 gives you 0, 1, 2, 3 — that is four trips, not three, and not five.
Counting from zero again, same as the motor back in Project 3. Write out the numbers if you are not sure.
Take the while version from Try It and rewrite it as a for loop. The arm should move identically.
position++ to position = position + 40. What happened to the movement?The square, for the last time. Use a for loop and your library .
| Version | Lines in main | Change it to a pentagon by… |
|---|---|---|
| Project 11 — ticks, written out | ||
| Project 12 — functions | ||
| Now — a for loop |
Mission 11 One Orange Pom is a basket. Two or more Orange Poms are the same basket.Hazard Disposal
Watch Mission 11 video
Base Mission
7 points
Final judgedBonus Mission
7 points
Final judgedScores
Does Not Score
Two Ways, Both Fine
Call your function twice, or wrap it in a two-iteration for loop. Try both and see which reads better to you.
The loop wins the moment the number might change — and at a tournament it always might.
The second pom is somewhere different, so your function needs an or a short drive between trips. Same problem you solved for Mission 15 in Project 12.
A Cube On a Cube Still Counts
Read the scoring examples: one cube another cube that is the Large Green Cube scores. So the second cube can go on the pile rather than beside it — whichever your claw does more reliably.
⚠ Final Position --- Both Have to Survive
Delivering the second cube is where the first one gets knocked off. Approach the same way each trip, and back straight away rather than turning while you are still close.
Did the second delivery ever knock the first one off? What fixed it?
Mission 7 One Blue Pom and one Orange Pom are the same PVC enclosure. A second PVC enclosure contains at least one Blue Pom and at least one Orange Pom, each the enclosure. The Base and Bonus must use different enclosures.Hazard Containment
Watch Mission 7 video
Base Mission
11 points
Final judgedBonus Mission
9 points
Final judgedScores
Does Not Score
Anything you wrapped in a loop that worked — deliver_poms(int howMany), smooth_arm(int from, int to) — belongs in your library file. Add it, save, and note it in your block.
| Run | M11 | M16 | M17 | M7 | Points |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 |
| Mission part | Scored? | Points |
|---|---|---|
| Mission 11 — Bonus (two orange poms, same basket) | 7 | |
| Mission 16 — Bonus (two spilled cubes on the green) | 11 | |
| Mission 17 — Bonus (two unstraight cubes on the brown) | 11 | |
| Mission 7 — Bonus (a second enclosure) | 9 | |
| My total this project | 38 |
| The robot needs to… | while or for? |
|---|---|
| Drive until it touches a wall | |
| Put three cubes on a | |
| Follow a line until it has gone 5000 ticks | |
| Lower the arm in small steps from 200 to 1800 | |
| Wait for someone to press a button |
| The loop | Runs how many times? |
|---|---|
for (i = 0; i < 5; i++) | |
for (i = 1; i <= 5; i++) | |
for (i = 0; i < 10; i = i + 2) | |
for (i = 10; i > 0; i--) |
Add up what you scored across the whole strand. The right-hand column is what was available.
| Project | I scored | Available |
|---|---|---|
| 4 — Out and Back | 4 | |
| 6 — Bulldoze Run | 16 | |
| 7 — Your Robot’s Arm | 7 | |
| 8 — Arm and Claw Together | 37 | |
| 9 — Names for Your Numbers | 20 | |
| 10 — Feeling for Things | 13 | |
| 11 — Counting Wheel Ticks | 40 | |
| 12 — Teaching Your Robot New Moves | 18 | |
| 13 — Deciding What to Do | 22 | |
| 14 — Seeing Light and Dark | 35 | |
| 15 — Following the Line | 51 | |
| 17 — Repeating Without Retyping | 38 | |
| Total | 301 |
301 Is the Whole Game
Add up every base, bonus, and advanced bonus across all eighteen Stack Attack missions and the number is 301.
There is nothing on that field you have not been taught how to reach.
You have written four kinds of loop condition now — a switch, a tick count, a brightness, and a plain count. Which was hardest to get right, and why that one?
In Project 1 you ran a program somebody else wrote and did not understand a line of it. Go back and read that program now. What does it say to you?
Your robot does exactly what it is told, every time, and has no idea what any of it means. After seventeen projects, does it seem intelligent to you? Say what makes you answer that way.
Seventeen projects ago your robot could not be switched on. It now drives measured distances, turns to an angle, grabs and stacks and places, feels for walls, counts its own wheels, reads light and dark, follows a line, checks its own work, and decides what to do when something goes wrong.
All of it built from about a dozen commands and four ideas: do this, do it if, do it while, do it again.
Take your library with you. Next season the field will be different and most of what is in that file will still work.
KIPR · Botball Explorer — Discovery Projects · © KISS Institute for Practical Robotics 1997–2026
When you are finished, press the button to turn in your work and save a copy.
KIPR · Botball Explorer · Discovery