Coding Project 13 — Deciding What to Do
KIPR · Botball Explorer
Activity Sections

Introductory · EV3 Coding Project 13

Deciding What to Do

Until now your robot has followed orders. Today it starts choosing.

Project
Coding Project 13
Strand
Coding
Phase
Make It Smart
Time
One class period
What You Are Doing
Writing code that asks a question once and picks a path based on the answer — then using it to build two stacks that have to come out different.
Mission Anchor
Mission 3 — Mixed Freight (advanced bonus) — 13 points
What You Need
Before You Start
Projects 10 and 12 — you need wait until and your own My Blocks.
Before you start: type your PIN in the box at the top of the page. Your teacher gave you this number. When you finish, press Download to save a local copy of your answers. This does not turn in your work automatically; give the downloaded file to your teacher.

Try It — Sabotage Your Own Robot

Load your Project 12 program — the blue pom run. Before you press start, move the first pom about four inches to one side. Now run it and watch closely.

QuestionWhat happened
Did the claw close on anything?
What did the robot do next?
Did it drive to the basket anyway?
Did it open the claw at the end?

⚠ Your Robot Has No Idea Anything Went Wrong

It drove to a spot, closed a claw on empty air, carried nothing across the field, and carefully placed nothing in the basket. Then it backed away pleased with itself.

Every program you have built does this. They all assume everything goes right.

Something goes slightly wrong in a real match — a cube got bumped, your robot drifted an inch. How much of your run is ruined?

You do this all day

You never follow a plan blindly. You check things and pick. Fill in what you would do:

If this is true……I do this. Otherwise I do this.
It is raining outside
The milk smells bad
My bag feels lighter than it should

That last one is exactly what your robot needs — a way to notice that it is carrying nothing.

Learn It — Ask Once, Then Choose

The orange Control shelf has one more pair of jaws: the if-then block. It asks a hexagon question once, and only runs what is in its jaws when the answer is true.

The hexagon is written exactly the way your wait until and repeat until hexagons are — same shapes, same comparisons, same not.

The one difference that matters

Code / partWhat it means
wait until / repeat untilKeeps asking. Checks, runs, checks again… until the answer changes. The robot stays there.
if — asks onceChecks once. Runs the jaws once if true, skips them if false. Either way the robot moves on immediately.

Same Hexagons, Completely Different Job

Until = “keep doing this until something changes.” If = “look at this once, then decide what happens next.”

Swap one for the other by accident and your robot either freezes in place or blows straight past a check it needed to make.

Three shapes

Code / partWhat it means
two separate ifsif (shoes are on) — go for a walk. if (I am hungry) — eat a snack. Two questions about different things. Both can be true, both false. They do not affect each other.
if / elseif (shoes are on) — go for a walk. else — watch TV. The if-then-else block has two mouths, and exactly one of them runs, always. Else has no hexagon — it means “every other possibility.”
a chain of choicesNeed three paths? Put a second if-then-else inside the else mouth of the first. Checked top to bottom — the first true one runs, and everything below is skipped even if it is also true.

How does a robot know it grabbed nothing?

Here is the check that fixes your sabotaged run — and it costs no extra sensor at all.

Think about what “closed” means. Your claw closed number is where the claw stops because the cube is in the way. Close the claw on empty air and nothing stops it — it swings past that number.

For that trick to work, the close itself has to change. A run-for block always swings the exact degrees you asked for — cube or no cube, it lands on the same count, and the count tells you nothing. So the grab check uses a timed squeeze instead: switch the claw motor on toward closed, give it a second, switch it off. A cube stops the squeeze early. Empty air lets it swing right on past.

The claw motor’s own degree count, which the brick has been keeping since Project 3, just became a sensor. It starts at 0 at claw-open — that is the Start Pose Rule earning its keep. Whether your empty claw ends up at a bigger or smaller number than your grip point depends on which way your claw closes — check yours by hand and flip the hexagon if needed.

Do It — Choose a Path

Step 1 — Your first decision

New project called Decisions. Build: if (1 is pressed?) then — play beep for 0.2 seconds. Run it twice — once holding the sensor pressed, once not.

What happened each time — and how fast did the program end when you were not pressing?

Step 2 — Swap if for wait-until and watch what breaks

Replace the if with wait until (1 is pressed?), beep after it. Run it without pressing.

What is the robot doing now, and how is it different from the if version? Use the words “once” and “keeps”.

Swap it back.

Step 3 — Pick a side with a press

Now a real two-way choice. Build: at the start of a program, wait 3 seconds — your window to press or not — then:

Hold the sensor during the wait → robot turns right. Do not → it turns left. One program, two behaviours, chosen at run time.

Step 4 — Did I actually grab it?

Open your grab block from Project 12. Swap its claw-close for the timed squeeze from Learn It, then add the empty-claw check right after it: if the claw count is past claw closed by more than about 10, show the sad face and stop; else, carry on.

Test it honestly: run with a cube in place, then run with the cube moved away.

Your robot just told you something went wrong instead of carrying air across the field. What should it do about it — try again, skip to the next mission, or stop? Who decides?

Step 5 — A three-way choice

Build a chain: press within the first 3 seconds → the full run; press and hold → just the grab test; no press → a beep and stop. Use an if-then-else with a second if-then-else inside the else mouth.

Why does the order of the questions in your chain matter? What would go wrong if you asked them the other way round?

Step 6 — Mission 3 Advanced — two opposite stacks13 pts

Mission 3

Mixed Freight

Watch Mission 3 video

Base Mission

7 points Live judged

Create one stack consisting of a Green Cube a Yellow Cube, or a Yellow Cube a Green Cube.

Bonus Mission

9 points Live judged

Create a second stack consisting of a Green Cube and a Yellow Cube.

Advanced Bonus

13 points Live judged

Create two stacks such that one contains a Green Cube a Yellow Cube, and one contains a Yellow Cube a Green Cube (opposite color arrangements).

Scores

  • Green on Yellow or Yellow on Green — both satisfy the Base Mission.
  • Two valid mixed-color stacks satisfy the Bonus Mission.
  • Two stacks with opposite color arrangements satisfy the Advanced Bonus.

Does Not Score

  • Green on Green or Yellow on Yellow — same-color stacks do not score.
  • A single three-cube stack does not count as two scoring stacks.
  • Any cube used in one stack may not be reused for another stack.

Going for Advanced Gets You the Bonus Too

Two opposite stacks are two stacks. Score the Advanced Bonus and the 9-point Bonus comes with it — 22 points from this one run.

Scores

  • Two stacks with opposite colour arrangements.
  • The stacks do not need to be next to each other.
  • The shape of the stack does not matter — only the ON TOP OF relationships.

Does Not Score

  • Green on Green, or Yellow on Yellow.
  • A single three-cube stack counted as two stacks.
  • Reusing a cube from the first stack in the second.

⚠ Four Cubes, Four Jobs

Each cube may contribute to only one scoring stack. You need two greens and two yellows, and every one of them has a specific place to be. Get the second stack’s colours the wrong way round and you drop from 22 points to 9.

Where the decisions go. This run has four grabs and four placements in a row. If grab two fails and the robot does not notice, everything after it is wasted. Put a check after each grab — the pattern from step 4 — so a miss costs you one cube instead of the whole mission.

Plan it out. Which cube goes where, and in what order?

StepCubeGoes whereCheck after?
1
2
3
4

Step 7 — Run it five times

RunTwo stacks?Opposite arrangement?Did a check catch a miss?Points
1
2
3
4
5

Score It — Checkpoint

My score

Mission partScored?Points
Mission 3 — Bonus (a second mixed stack)9
Mission 3 — Advanced (opposite arrangements)13
My total this project22

if or until?

Which tool fits each job — an if, a wait until, or a repeat until?

The robot should…Tool
Keep driving until the sensor is pressed
Check once whether the claw is empty, then choose
Do nothing until the match-start tap
Steer left or right depending on what it sees, over and over

Spot the bug

The stackWhat goes wrong
An if (pressed?) used to wait for the match-start tap
A wait until (pressed?) where a quick one-time check was meant
In a chain, the catch-all question placed first

Can you do it again?

Think about it

In Try It your robot carried nothing across the field and placed it carefully in a basket. Would you call that a mistake by the robot, or a mistake by the programmer?

A robot that checks its own work looks smarter than one that does not. Is it actually smarter, or is it something else?

Every decision you made today came from a switch — pressed or not pressed. What kinds of choices could your robot make if it could tell how much of something there is, instead of just yes or no?

Next

Everything your robot senses right now is on or off. The field is not like that — a black line and a white mat are not two states of a switch, they are two brightnesses.

In Project 14 — Seeing Light and Dark, your robot gets a sensor that answers with a number instead of a yes.

Download saves a local copy of your answers. It does not turn in your work automatically; give the downloaded file to your teacher.

KIPR · Botball Explorer — Introductory Projects · © KISS Institute for Practical Robotics 1997–2026