Click & Whirr needs a wider screen
Open it on a laptop or desktop (1280px or wider recommended). The Learn · Code · Watch workspace needs the room to breathe.
Lesson p1
The camera under the line
Checkpoints · 0 of 2 (waiting for Run)
- Reach the end of the line (waiting for Run)
- Reach it smoothly (low wobble) (waiting for Run)
The number was always a picture
Every lesson since 02 has opened with the same quiet gift: line_offset, a single number telling you exactly how far off the line you are sitting, and in which direction. You tuned a gain against it. You damped it. You never once asked where it came from.
It came from here. Press Run and look at the new panel in the upper half of the simulator, just under the OFF-CENTER gauge. That is a strip of floor just ahead of the robot, sampled left to right: pale where the mat is bare, dark where the line is. Watch it slide as the robot drives. When the robot sits square on the line the dark patch is centered; when it drifts right, the dark patch slides left. There was never a number in that strip. There was only ever brightness.
The robot is not steering yet, because find_line currently claims the line is always dead ahead, so it cruises straight off the first curve. Your job for the rest of this lesson is to turn that strip back into the number you have been trusting all along.
Turn the row back into an offset
Drive lesson 02 on your own reading
▸API reference
- robot.sensors.camera()
- A tuple of brightness readings across a strip of floor ahead of the robot, left to right. 0.0 is bare floor, 1.0 is the middle of the line, and edge cells land in between. Same sensor lag as line_offset: you are looking at where the floor was a moment ago.
- find_line(camera, threshold=0.5, half_width=36.0)
- Yours to write. Turn the row of brightness values into one signed offset in px, positive when the line is off to your left. This is the piece that gets saved into your library.
- follow_camera(kp=2.4, base=26)
- Called every tick. Already wired: it reads the camera, calls your find_line, and steers proportionally. Returns a (left, right) tuple clamped to ±100. kp and base are defaults on the signature, the same pair you tuned in lesson 02b.
space pause · r reset · ctrl/cmd+enter run