Base Mission
9 points Live judgedA Small Red Cube is the Large Red Cube.
Discovery · Coding Project 9
Your comments become real code. Change a number once, and the whole program changes with it.
Student PIN:
Open your Project 8 program — the big one with all four missions in it. Scroll through it slowly.
| How many times does this appear as a bare number? | Count |
|---|---|
| My arm’s servo | |
| My arm’s “up” position | |
| My arm’s “down” position | |
| My claw’s “open” position | |
| My claw’s “closed on a cube” position |
⚠ Your Teammate Rebuilt the Claw Last Night
It grips better now. But the closed position is different — it is 200 lower than it was.
Find every place that number appears in your program and change it. Time yourself.
| Question | Answer |
|---|---|
| How long did it take? | |
| How many places did you have to edit? | |
| Are you certain you got them all? |
That last question is the real problem. If you missed one, what would happen — and how would you find out?
This Gets Worse, Not Better
Your program is going to keep growing. By the time you are running a full match, that number could be in twenty places. There is a fix, it takes one line, and you are about to learn it.
A is a name that holds a value. You set it once at the top of your program, then use the name everywhere instead of the number.
Here is the whole idea in one line:
int arm = 0;| Code / part | What it means |
|---|---|
int | Short for — a whole number. Ports and servo positions are always whole numbers. |
arm | The name. Pick something simple and descriptive. |
= 0 | The value it holds. |
; | A , same as any other . |
Where Variables Go
Inside the — after the opening { of main, above everything else. Not outside the braces, and not scattered through the middle of your program.
You have been writing your positions as since Project 7, in the name = number format. There was a reason for that. Turning a comment into a variable takes three changes:
int at the front.Before — comments
int main ()
{
// arm = 0
// up = 230
// down = 1234
...
}After — variables
int main ()
{
int arm = 0;
int up = 230;
int down = 1234;
...
}Before
set_servo_position(0, 1234);
msleep(500);
set_servo_position(0, 230);
motor(0, 50);
motor(3, 50);After
set_servo_position(arm, down);
msleep(500);
set_servo_position(arm, up);
motor(left, 50);
motor(right, 50);Read both versions out loud. One is a list of numbers. The other tells you what the robot is doing.
Short names are fine if they are obvious. If they are not obvious, explain them:
// L is my left wheel
int L = 0;
// R is my right wheel
int R = 3;A name nobody can decode is barely better than a bare number.
A Yellow Banner Is Not an Error
If you declare a variable and never use it, you will get Compilation Succeeded with Warnings — a yellow banner instead of a green one. The program still runs.
But warnings exist for a reason. A variable you declared and never used usually means you forgot to swap out one of the bare numbers.
Most of your variables hold one value forever — a port is always the same port. But a variable is called a variable because it can vary.
int position = 250;
// Now 260
position = position + 10;
// Back to 250
position = position - 10;Adding or subtracting one is so common it has its own shorthand:
| Code / part | What it means |
|---|---|
position++; | Exactly the same as position = position + 1; |
position--; | Exactly the same as position = position - 1; |
You will meet the real use for these in Project 10, once you have a loop to put them in.
Open your Wave program from Project 7. Turn the three position comments into variables, then replace the numbers in the set_servo_position() lines with the names.
. Run. It should behave exactly as before.
Add a variable you do not use anywhere:
int notused = 999;Compile and look at the banner colour.
Delete the line. Get your green banner back.
This is the real job. Declare all your variables at the top, then work down the program replacing bare numbers with names.
| Variable | My value | Done? |
|---|---|---|
| left | ||
| right | ||
| arm | ||
| claw | ||
| up | ||
| horizontal | ||
| down | ||
| open | ||
| closed |
Convert One Mission Section at a Time
Same rule as building it in the first place. Convert one section, compile, run it, then move on. Converting all four at once and finding it broken tells you nothing about where.
Same problem as Try It. Your claw’s closed position drops by 200. Change it.
| Question | Answer |
|---|---|
| How long did it take this time? | |
| How many places did you edit? |
Compare those two numbers with the ones you wrote in Try It.
Small experiment. Add this to a test program and watch the arm.
int arm = 0;
int position = 250;
set_servo_position(arm, position);
enable_servos();
msleep(500);
// Change the variable
position = position + 300;
set_servo_position(arm, position);
msleep(500);
// Change it again
position = position + 300;
set_servo_position(arm, position);
msleep(500);
disable_servos();The arm moved in three hops instead of one jump. What would you have to do to make it move in thirty small hops?
Hold that thought. Project 10 gives you the tool that makes it one line instead of thirty.
Mission 5 A Small Red Cube is the Large Red Cube. Both Small Red Cubes are the Large Red Cube.Top Shelf Delivery
Watch Mission 5 video
Base Mission
9 points
Live judgedBonus Mission
11 points
Live judgedScores
Does Not Score
Live Judged Is On Your Side Here
Robot support is permitted, and the cubes do not have to stay up there. Once the judge has seen it, it counts — even if it falls a second later.
⚠ Check What Mission 2 Did to These Cubes
In Project 6 you pushed the Large Red Cube, its , and both Small Red Cubes off the black line. Those are the same cubes you need here. Where they ended up decides how hard this is — so plan the two missions together, not separately.
Where do your red cubes end up after your Mission 2 push? Does that help or hurt you here?
The bonus needs both cubes up there at the same time. Why does that make the second one harder than the first?
| Run | First cube on top? | Both at once? | Points |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 |
| Mission part | Scored? | Points |
|---|---|---|
| Mission 5 — Base (one small red cube on top) | 9 | |
| Mission 5 — Bonus (both small red cubes on top) | 11 | |
| My total | 20 |
Turn each comment into a proper variable declaration.
| Comment | Variable |
|---|---|
// claw = 3 | |
// open = 1246 | |
// left = 0 |
Given int arm = 0; and int down = 1234; — what does each line do?
| Line | What it does |
|---|---|
set_servo_position(arm, down); | |
down = down - 50; | |
arm++; |
Nothing your robot does changed in this project — it drives, grabs, and stacks exactly as it did before. So what actually got better?
Variables fixed the problem of one number appearing in many places. But your program still has the six-step grab sequence typed out four separate times. Would variables fix that too? Why or why not?
Your teammate opens your program for the first time. Which version would they be able to work on — the one from Project 8, or this one? What does that tell you about who you are really writing code for?
Your robot still cannot tell when it has arrived anywhere. It drives for a length of time and hopes.
In Project 10 — Feeling for Things, it gets its first sense: a switch that knows when it has touched something — and the loop that keeps checking.
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