KIPR · Botball Explorer
Activity Sections

Discovery · Coding Project 15

Following the Line

The sensor stops being a stop sign and becomes a steering wheel.

Project
Coding Project 15
Strand
Coding
Phase
Make It Smart
Time
One class period
What You Are Doing
Steering from a reading instead of driving blind, then using the lines to reach four of the hardest scoring targets on the field.
Mission Anchor
Mission 6 · Mission 7 base · Mission 16 base · Mission 17 base — 51 points
Before You Start
Project 14 — you need a working and a robot that can find a line.
What You Need
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 Submit & Download to turn in your work and save a copy.

Try It — Where Is the Line, Exactly?

Put your robot on the field with the sensor over a black line. Open the Sensor List, then push the robot sideways by hand, slowly, across the line and off the other side. Watch the number the whole way.

Sensor sitting…Reading
Well off the line, on white
Right at the edge, half on and half off
Dead center of the line
Right at the other edge
Well off the other side, on white

Now the question that matters

Look at your first reading and your last reading — both on white, one either side of the line. Can the sensor tell them apart?

Your robot drifts off the line. Just from the number, can it work out which way it drifted?

⚠ One Sensor Cannot Stay on the Middle

Sitting on the center of the line, everything looks the same in both directions. Drift left, the reading goes up. Drift right, the reading goes up. The robot has no idea which happened, so it cannot know how to correct.

Following the middle of a line with one sensor is impossible. So you do not.

Learn It — Follow the Edge, Not the Line

Put the sensor on one edge of the line and everything becomes answerable. Now dark and light mean two different directions, which you can write using two conditions.

  • Reading is high: Drifted onto black, so steer away from the line.
  • Reading is low: Drifted onto white so teer back toward the line.

The Robot Won't Straight

It zigzags. Too dark, arc one way. Too light, arc back. Over and over, several times a second.

From a distance it looks like the robot is following the line. Up close it is constantly overcorrecting — and that is exactly what makes it work.

Two choices, checked forever

This is a while loop with an if inside it. You have had both since Projects 10 and 13 — this is the first time they work together.

// Keep going until someone stops me
while (a_button() == 0)
{
	// I see black: I drifted onto the line
	if (analog(line) > threshold)
	{
		// Arc away from it
		motor(left,  20);
		motor(right, 60);
	}
	// I see white: I drifted off the line
	else
	{
		// Arc back toward it
		motor(left,  60);
		motor(right, 20);
	}
}
motor(0, 0);
motor(3, 0);
msleep(30);
Code / partWhat it means
while (...)Keeps the whole thing repeating. Without it the robot checks once and gives up.
if / elsePicks one of two steering actions, every single time through.
no ao() insideNever stop the motors inside a line-follow loop. The robot should steer continuously, not stutter.

⚠ Never One Motor Forward and One Backward

It is tempting to make the turns sharper by reversing a wheel. Do not. In a loop that switches direction several times a second, reversing a motor over and over will burn it out.

Use two different positive speeds. A big gap between them gives a sharp turn; a small gap gives a gentle one.

That is the same rule you found in Project 5 — the further apart the two power numbers, the sharper the curve. It has been true this whole time.

Tuning it

ProblemTry this
Wanders off the line and never comes backBigger gap between the two speeds — turn harder
Zigzags so wildly it barely moves forwardSmaller gap — turn more gently
Loses the line on sharp corners onlySlow the whole thing down, or sharpen just the inside turn
Follows for a while then drives offCheck your threshold — it may be right for one part of the field and wrong for another

Following until something else happens

Line following on its own goes forever. To be useful it has to stop for a reason — a count, a bump, or a second line crossing the first.

cmpc(left);

// Follow for this far, then move on
while (gmpc(left) < 5000)
{
	if (analog(line) > threshold)
	{
		// Arc away
	}
	else
	{
		// Arc back
	}
}
motor(0, 0);
motor(3, 0);
msleep(30);

Now the line keeps you straight and the counter tells you when you have arrived. Two sensors doing two different jobs in one loop.

Do It — Steer and Deliver

Step 1 — Build the follower

Create a new project called Line Follow. Start with the two-choice loop. Put the sensor on the left edge of a line and let it run until you press a button.

TrySlow motorFast motorWhat it did
1
2
3
4

Step 2 — Switch edges

Move the robot to the other edge of the same line and run the identical program.

What happened, and why?

What single change makes it follow the right edge instead?

Step 3 — Follow a curve

Straight lines are easy. Find a line on the field that bends and follow that.

Did you have to change anything from your straight-line settings?

Step 4 — Follow, then stop for a reason

Wrap the follower in a tick count so it travels a set distance and then hands over to whatever comes next. This is the pattern every mission below uses.

Turn it into a while you are at it — follow_line(int ticks).

Step 5 — Mission 16 — Freight Shelving for 9 points

Watch Mission 16 video

Base Mission

9 points Final judged

At least one cube originating from the Spilled Cube area is the Large Green Cube.

Bonus Mission

11 points Final judged

Two or more cubes originating from the Spilled Cube area are the Large Green Cube.

Scores

  • One spilled cube is the Large Green Cube.
  • One spilled cube is the Large Green Cube while supported by a robot.
  • One spilled cube another spilled cube that is the Large Green Cube.
  • Multiple spilled cubes the Large Green Cube.

Does Not Score

  • A spilled cube touching only the side of the Large Green Cube.
  • A spilled cube not originating from the Spilled Cube area.
  • Only one spilled cube the Large Green Cube for the Bonus Mission.

⚠ The Large Green Cube, Not a Small One

The target is the large palletized Green Cube field element — not the small green cubes you have been stacking since Project 8. Make sure your team is aiming at the right thing.

Robot support is permitted, but this is final position scored — so the cube has to still be up there at the end, which means letting go cleanly.

Step 6 — Mission 17 — Freight Racking for 9 points

Mission 17

Freight Racking

Watch Mission 17 video

Base Mission

9 points Final judged

At least one cube originating from the Unstraight Cube area is the Large Brown Cube.

Bonus Mission

11 points Final judged

Two or more cubes originating from the Unstraight Cube area are the Large Brown Cube.

Scores

  • One Unstraight Cube is the Large Brown Cube.
  • One Unstraight Cube another that is the Large Brown Cube.
  • Multiple Unstraight Cubes the Large Brown Cube.

Does Not Score

  • An Unstraight Cube touching only the side of the Large Brown Cube.
  • A cube not originating from the Unstraight Cube area.
  • Only one Unstraight Cube the Large Brown Cube for the Bonus Mission.

Same Job, Different Address

This is Mission 16 with two words changed. If you wrote Mission 16 as a function with , this one costs you almost nothing — which is the reward for the work you did in Project 12.

⚠ Watch Your Cube Budget

The Unstraight Cubes are the same three you stacked for Mission 13 back in Project 10. A cube can only be in one place at the end of the match. Decide now which missions you are actually going for.

Step 7 — Mission 7 — Hazard Containment for 11 points

Watch Mission 7 video

Base Mission

11 points Final judged

One Blue Pom and one Orange Pom are the same PVC enclosure.

Bonus Mission

9 points Final judged

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.

Scores

  • One Blue Pom and one Orange Pom are the same PVC enclosure.
  • Multiple Blue Poms and one Orange Pom are the same PVC enclosure.
  • Two different enclosures each containing at least one Blue and one Orange Pom.

Does Not Score

  • A Blue Pom in one enclosure and an Orange Pom in a different enclosure.
  • Only one pom type in any enclosure.
  • The same enclosure used to satisfy both Base and Bonus Missions.
Two colours, one enclosure. Poms roll, so the second delivery is the one that knocks the first one out — go slowly and back straight away.

Step 8 — Mission 6 — Pallet Builder · 22 pts

Watch Mission 6 video

Base Mission

15 points Live judged

Place all four Green and Yellow Cubes onto a single pallet. A cube is on the pallet if touching the upper surface or another cube that is on the pallet.

Bonus Mission

7 points Final judged

The pallet is a starting box and is not touching any black line.

Scores

  • All four cubes touching the pallet.
  • A four-cube vertical stack on the pallet.
  • Any arrangement where all four cubes are part of a single palletized load.
  • The pallet a starting box, not touching the black line.

Does Not Score

  • Three cubes on the pallet and one cube elsewhere.
  • The pallet is touching the black line.
  • The pallet is not a starting box.

The Arrangement Does Not Matter

Four cubes flat on the , a four-high tower, or anything in between — all of it scores, as long as every cube is part of one palletized load. Pick whatever your claw finds easiest.

Better still: the cubes are not required to stay on the pallet after the base is scored. It is live judged, so once the judge has seen four cubes on the pallet, you can go on and move the pallet without worrying about a cube rolling off.

⚠ Not Any Black Line

The bonus is stricter than it looks. The pallet must be the starting box and not any black line. Push it in too far or not far enough and you get nothing.

These are the same four green and yellow cubes you used for Mission 3 in Projects 8 and 13. What is your plan — Mission 3’s stacks or Mission 6’s pallet?

Step 9 — Run it five times

RunM16M17M7M6 baseM6 bonusPoints
1
2
3
4
5

Score It — Checkpoint

My score

Mission partScored?Points
Mission 16 — Base (spilled cube on the Large Green Cube)9
Mission 17 — Base (unstraight cube on the Large Brown Cube)9
Mission 7 — Base (blue + orange in one enclosure)11
Mission 6 — Base (four cubes on one pallet)15
Mission 6 — Bonus (pallet in a starting box)7
My total51

My line-following settings

SettingValue
Threshold I use for following
Slow motor power
Fast motor power
Which edge I follow (left or right)

Can you do it again?

Think about it

Your line follower checks and steers several times a second and never drives perfectly straight. Would a person following a line with their eyes shut, feeling for the edge with a foot, do anything different?

A second sensor, mounted a few inches away from the first, would let the robot see both edges at once. What could it do then that it cannot do now?

Missions 16 and 17 want two or more cubes for the bonus, and Mission 7 wants a second enclosure. Look at how you wrote these runs. What would it take to do each one a second time?

Next

You have written every skill this game needs. What you have not done is tidy up — your functions live in one long file, and half your missions have a bonus that just means “now do that again.”

In Project 16 — Building Your Toolbox, your functions move into a you can carry between projects.

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