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 p2
Drive at what you can see
Checkpoints · 0 of 2 (waiting for Run)
- Turn toward the crate you can see (waiting for Run)
- Pull up to it without hitting it (waiting for Run)
A picture with two axes, and a blank one
Same camera, more of it. Instead of one row of floor you now get a grid: 20 cells across, 8 rows deep, reaching about 100px ahead of you and 90px either side. It arrives as one flat tuple in row major order, which is the convention nearly every image format in the world uses: the first 20 values are the nearest row, the next 20 are the row behind that, and so on. Cell r * n + i is column i of row r.
There is one crate out there and no flag to steer at. Press Run and watch the patch: it is completely blank. The crate is real, but it is further away than the camera can reach, and a blank picture is not a malfunction. It is the honest answer to the question you asked. Your find_line handled that case by returning 0.0, which quietly meant “dead ahead”. Here that lie would be expensive, so find_blob returns None instead, and the caller creeps forward until there is something to see.
Average the bright cells into a place
Use the second coordinate to stop
▸API reference
- robot.sensors.camera()
- The same camera as the last lesson, but now a 2D patch: a flat tuple of 20 x 8 brightness values, row major, nearest row first. 0.0 is bare floor and 1.0 is crate. It reaches about 100px ahead, so it reads all zeros until something is close enough to see.
- find_blob(image, n, half_width=90.0, spacing=14.0)
- Yours to write. Return (sideways, ahead) in px for the bright region, or None when the patch is empty. Row r is 2 + r * spacing px ahead; column i is half_width - 2 * half_width * i / (n - 1) px to the side. This is the piece that gets saved into your library.
- seek_crate(kp=1.2, base=22, stop_at=50.0)
- Called every tick. Already wired: creep forward while find_blob returns None, steer proportionally to the sideways offset once it does not, and stop once the crate is within stop_at px. Returns a (left, right) tuple clamped to ±100.
space pause · r reset · ctrl/cmd+enter run