The Line-Follower That Drives Straight Off the Corner
At a middle school robotics club, two teams build line-following robots for a 6 m course. The course has a 90-degree corner and a 3 cm gap in the tape where the line crosses a white expansion joint. Each robot has two reflectance sensors, left and right, spaced 2.5 cm apart, reading 0–1023. The control loop runs every 50 ms. The current algorithm is: if both sensors read above 600 (white), drive both motors forward; if left reads below 600 (black), turn left; if right reads below 600, turn right; if both read black, stop. On straight sections the robot averages 0.45 m/s. At the corner, the inside sensor sees white first, the robot pivots, then both sensors see white for two loop cycles; it drives straight off the course. The team wants to add a 'memory' variable but cannot agree whether to remember the last black sensor or count white cycles. They have one afternoon before the district showcase and a spare color sensor but no extra motor driver.
1. Identify the specific flaw in the current rule set and explain why the robot loses the line at the corner, using the sensor spacing, loop time, and speed.
Read the worked answer
The flaw is that the all-white state is treated as 'go straight' even though all-white is ambiguous: it can mean the robot is centered on the line, crossing a gap, or sitting between two segments at a sharp corner. At 0.45 m/s, one 50 ms loop covers 0.45 × 0.05 = 0.0225 m, or 2.25 cm. Two cycles cover 4.5 cm. The sensors are only 2.5 cm apart. At a 90-degree corner, the tape can fall between the sensors: the inside sensor leaves black first, the robot pivots, and then both sensors are over white for about two cycles. The controller has no history to tell it that it was just turning, so it chooses 'straight' and leaves the course. The 3 cm gap also produces an all-white condition, but the robot crosses 3 cm in 3 / 45 = 0.067 s, about 1.3 cycles, so the gap and the corner can look similar for one or two cycles. The issue is state ambiguity, not a dead sensor.
2. Compare two fixes: remembering the last-seen side versus counting consecutive all-white cycles. Which would you recommend for the corner and for the 3 cm gap, and why?
Read the worked answer
Remembering the last-seen side helps at the corner: if the last non-white pattern was left-black, the robot should keep turning left through a short all-white interval instead of straightening immediately. But it can hurt at the gap, because the last non-white pattern before a true gap may be both-black or one side, and continuing to turn can spin the robot off the line. Counting all-white cycles helps at the gap: after both sensors see black and then white, the robot can go straight for up to two cycles and reacquire the tape. But counting alone hurts at the corner if it straightens after two white cycles.
The better fix is a small state machine that stores both the last non-white pattern and a white-cycle counter. If all-white and the last pattern was left or right, continue turning that direction for up to two cycles, then stop. If all-white and the last pattern was both-black, drive straight for up to two cycles, because that matches a gap. If all-white persists beyond three cycles, stop as a fail-safe. This uses the corner's directional history and the gap's both-black history. The spare color sensor is not needed; adding it would require mounting and calibration time the team does not have.
3. The team has one afternoon. Propose a minimal test plan to validate the chosen fix without damaging the robot or missing the showcase.
Read the worked answer
Test one change at a time. First mark the corner and both edges of the 3 cm gap with removable tape so observers can score success consistently. Add serial logging of left sensor, right sensor, last pattern, white counter, and chosen action every loop. Run three trials at a reduced speed of 0.30 m/s to see the state transitions clearly, then three trials at 0.45 m/s. Between trials, inspect for loose wires and confirm the fail-safe stop works. Record whether the robot completes the corner, crosses the gap, and finishes the 6 m course, plus elapsed time. Do not change the motor driver or add the color sensor during this window. Timebox debugging to 20 minutes per failure; if the hybrid logic is not reliable by then, reduce the showcase speed and keep a human spotter. This plan validates the logic with evidence, preserves the robot, and leaves time to practice the presentation.