Unit 2 · Big Idea 6
Two Sensors, One Decision
Student Lab · Follow the Line, Stop at the Object
Student PIN:
Overview
So far, each behavior used one sensor. Your line-follow watches the Tophat. Your touch-stop watched the button. Today the robot uses two sensors at the same time: the Tophat to stay on the line, and a new ET distance sensor to watch for an object ahead. The robot will follow the line — and the moment something appears in front of it, stop. Neither sensor could do this alone. Together, they can.
Core Insight
The smartest behavior comes from combining sensors. One answers “which way?” The other answers “stop yet?” Put together, the robot does something neither sensor could do by itself.
By the end of this activity you will be able to:
- Read an ET distance sensor with
k.analog(1)and explain what its values mean. - Map the ET’s value-to-distance relationship, and find its close-range blind spot.
- Combine two sensors in one loop — one to steer, one to decide when to stop.
- Connect multi-sensor decisions to how intelligent systems fuse many inputs.
Phase 1 — Meet the ET Sensor
Setup
Mount the ET distance sensor on the front of your robot, facing forward (looking out ahead, not down at the floor like the Tophat).
Plug it into analog 1. In code, k.analog(1) reads the ET. Your Tophat is still on k.analog(0).
The ET shines infrared light forward and measures how much bounces back off an object. The key rule:
The CLOSER the object, the HIGHER the value.
So a far-away object gives a low number, and as it gets nearer the number climbs. It’s not a neat straight line, either — the value changes faster up close than far away. That’s why you have to measure it yourself.
Watch it on the
Open the Motors and Sensors widget, then the sensor list, and find analog port 1. Move your hand toward and away from the sensor and watch the number rise as you get closer, fall as you back away.
Move an object from far to near while watching analog(1). Describe what the number did. Did it climb steadily, or faster at some distances than others?
Phase 2 — Map Value vs. Distance
Place an object squarely in front of the sensor at each distance and record the ET value (pick the middle of the bounce). This table is your map from “value” to “real distance.”
| Distance to object | ET value (analog 1) | Notes |
|---|---|---|
| 12 in | ||
| 10 in | ||
| 8 in | ||
| 6 in | ||
| 4 in |
Now Investigate the Close Range
⚠ The blind spot --- read this
The ET sensor stops behaving below about 3 inches. Get closer than that and the reading does something strange — it can drop or bounce even as the object gets nearer. The sensor has a close-range blind spot where its numbers can’t be trusted.
Carefully push the object in past 3 inches and watch what the value does. Record it — this is real data about where the sensor fails.
| Distance to object | ET value (analog 1) | Acting normal? |
|---|---|---|
| 3 in | ||
| 2 in (blind spot) | ||
| 1 in (blind spot) |
What happened to the value when you went closer than 3 inches? Why is it dangerous to trust the sensor in that range?
Phase 3 — Choose Your Stop Value
You want the robot to stop with the object close — but before it enters the untrustworthy blind spot. A safe target is around 4 inches: close enough to count as “reached the object,” but safely outside the bad zone under 3 inches.
My stop value
From your Phase 2 table, copy the ET value you measured at about 4 inches. That’s the value your loop will watch for.
Why outside the blind spot
If you set your stop value too high (too close), the robot would have to drive into the blind spot to reach it — where the reading misbehaves and the robot might never see the right number. Stopping around 4 inches keeps you in the range you can trust.
Why did you pick a stop value from around 4 inches instead of 1 or 2 inches, even though closer would “reach” the object more?
Phase 4 — Concept: Two Sensors in One Loop
Your loop will now read two sensors, each with its own job:
- Tophat (
k.analog(0)) → “Which way do I steer to stay on the line?” - ET (
k.analog(1)) → “Is there an object close enough to stop?”
Combining sensors like this is called sensor fusion — using more than one input together to make a decision neither could make alone.
The while watches the ET: keep going while the object is still far (the value is still below your stop value). Inside the loop, the same if/else steering you tuned before keeps the robot on the line.
while k.analog(1) < STOP_VALUE: # ET: still far? keep going
if k.analog(0) > MIDPOINT: # Tophat: steer on the line
...
else:
...
k.msleep(10) # tiny pause (like the touch-sensor lab)That k.msleep(10) is the same idea you used with the touch sensor: the loop checks the sensors hundreds of times a second, and a small pause keeps it from overworking the controller.
Phase 5 — Build line_follow_until_object
⚠ Test in your hands first
Hold the robot up. Pass the line under the Tophat and watch it steer. Then move your hand toward the ET and watch the wheels brake when your hand gets close. Only put it on the board once both reactions look right.
Start from your tuned line-follow. Add an ET check to the loop condition and your stop value at the top. Use your own MIDPOINT, STOP_VALUE, and the mav speeds you found best. Define line_follow_until_object above main(), as always.
#!/usr/bin/python3
# Unit 2, Big Idea 6: Two Sensors, One Decision
# Name: _______________________ Date: ___________
import os, sys
sys.path.append("/usr/lib")
import _kipr as k
MIDPOINT = ____ # your Tophat threshold (from BI4)
STOP_VALUE = ____ # your ET value at ~4 inches (from Phase 3)
FAST = ____ # your best mav fast speed (from BI5)
SLOW = ____ # your best mav slow speed (from BI5)
def main():
line_follow_until_object() # follow the line, stop at the object
def line_follow_until_object():
while k.analog(1) < STOP_VALUE: # ET: object still far? keep going
if k.analog(0) > MIDPOINT: # Tophat: on black, steer right
k.mav(0, FAST)
k.mav(1, SLOW)
else: # on white, steer left
k.mav(0, SLOW)
k.mav(1, FAST)
k.msleep(10) # tiny pause so we don't overwork the controller
k.motor(0, 0) # The object is close, so brake.
k.motor(3, 0)
k.msleep(50) # let the brake settle
main()Reminders from earlier labs
If the steering goes the wrong way, flip the two mav (from Big Idea 4). The brake-and-settle at the end is from Big Idea 2. The k.msleep(10) in the loop is from Big Idea 1.
Test Log
| Try | What you changed | Did it follow the line AND stop at the object? |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 |
- The loop condition reads the ET:
k.analog(1) < STOP_VALUE - The
if/elseinside reads the Tophat:k.analog(0) > MIDPOINT - There is an
k.msleep(10)inside the loop - Your
STOP_VALUEis a ~4 inch reading — outside the blind spot - The robot brakes after the loop
Phase 6 — Connect: The AI Literacy Bridge
Big Idea --- AI Literacy Thread
Intelligent systems combine multiple sources of information to make decisions.
Your robot just did something it never could with one sensor: it stayed on a path and watched for an obstacle, at the same time. This is called sensor fusion, and it’s how every advanced intelligent system works. A self-driving car blends cameras, radar, and GPS at once — no single one is enough. Your phone blends the touchscreen, the accelerometer, and the light sensor to decide what to show. Intelligence grows when a system stops relying on one input and starts combining many.
Read each scenario. Think it through, then write your answer.
Your robot used the Tophat AND the ET together. Describe a task that needs both — something neither sensor could accomplish alone.
You learned the ET can’t be trusted closer than ~3 inches. Why is it important for an intelligent system to know not just what its sensors say, but when not to trust them?
A self-driving car combines cameras, radar, and GPS. Why is combining several sensors safer than relying on the single “best” one?
Phase 7 — Individual Reflection
Complete this section on your own.
1. How does the ET sensor’s value relate to distance? What’s surprising about it compared to “bigger number means farther”?
2. What is the ET’s blind spot, and how did it affect the stop value you chose?
3. In your loop, what question did the Tophat answer, and what question did the ET answer? Why did you need both?
4. Complete this in 2–3 sentences: “Intelligent systems combine multiple sources of information to make decisions. This means that the more a system can sense, the better it can…”
Extension Challenges
Finished early? Try one or more of these.
Extension A — Back Off to a Safe Distance
- After stopping, what if the object is a little too close? Add a short backward move so the robot ends at a consistent distance. How does this avoid the blind spot entirely?
Extension B — Report the Distance
- Use your Phase 2 table to turn the stopping ET value back into an approximate distance, and
printit. Roughly how far away did the robot actually stop?
Extension C — Two Conditions to Keep Going
- What if you wanted the robot to also stop after a maximum number of , even if it never sees an object? How could the loop check the ET and the ? (Think about combining conditions.)
Extension D — Add a Third Sensor
- Imagine adding the touch sensor from Big Idea 1 as a backup bumper. How would three sensors together make the robot even more reliable? Sketch the idea in words.
Extension E — Automatic Data Collection
- Your ET sensor automatically collects distance data the entire time your robot runs — no one approves each individual reading. Real devices do this constantly: traffic cameras, smart doorbells, fitness trackers.
- What privacy concerns come up when a device collects data automatically instead of only when someone asks it to? Who should get to see that data, and who should decide?
Extension F — A Simple Rule-Based Decision
- Right now your robot stops using one rule: distance < . A basic rule-based decision system combines multiple pieces of evidence before acting, instead of reacting to a single reading.
- Add a second condition: only stop if the object reads close on three readings in a row, not just one (to ignore a single noisy blip). Does requiring repeated evidence reduce false stops?
When you are finished, press the button to turn in your work and save a copy.
KIPR · Botball Explorer · Unit 2 Big Idea 6 — Student Lab