Skip to content

CodeAIR simulator: camera.take() returns a real picture, for pipe.image and the vision lessons - #176

Merged
david-firia merged 3 commits into
mainfrom
codeair-camera-capture
Dec 3, 2026
Merged

david-firia merged 3 commits into
mainfrom
codeair-camera-capture

Conversation

@david-firia

Copy link
Copy Markdown
Contributor

camera.take() on the simulated CodeAIR now returns a picture of what is under the drone, the way the device's does. CodeSpace's camera lessons (Recon, Line Patrol, Target Lock) now run in the simulator.

A frame, drawn when asked for. take() asks the page for a frame of the drone where it is at that simulated moment; the worker sends the drone's pose. The page draws it with the same camera as the live view (PR 171), off screen at twice the size, toned as the screen is. It averages that down and packs it as the camera's bytes, then sends them back. Nothing is drawn unless a program asks.

Bytes as on the device. The frame is a read-only displayio.Bitmap. It is RGB565 with each pixel's high byte first in memory, so frame[x, y] reads byte-swapped, as the lessons teach. Grey frames are 8-bit, after camera.reconfigure(pixel_format=GRAYSCALE). Any FrameSize works, its field of view cut from the sensor's 4:3. img_utils.get_bitmap_bytes returns those bytes, so pipe.image(camera.take()) sends the record the device sends; it shows in the data panel once PR 172 lands.

Time. A frame costs 25 ms of simulated time, an estimate of what take() costs on the device, however long the page takes to draw it. While Python waits for the page, its own steps are not charged (engine.held, a small change to the shared engine.js).

Realism never touches the world. A frame is drawn at the Medium look whatever the realism setting, so a program reads the same picture on every machine.

Headless, or no page. In Node, or when the page cannot answer within 1.5 s, a frame is the floor map through the same lens, in grey. That keeps it deterministic, and tests can check the picture's orientation against tape laid on the floor.

What the lessons use, added:

  • camera.frame_available as a property, plus sensor_name, width, height and reconfigure.
  • displayio.Bitmap(w, h, value_count) to draw into.
  • img_utils.detect_color_blob: the device's C, step for step, in JavaScript (bridge/codeair-camera.js), charged as C would cost.
  • img_utils.save_bitmap_file: a 24-bit BMP. Paths on /sd/ say no card is there, as the device does without one.

Not simulated: Search Party's neural network (tflite_detect).

Tests.

  • tests/sim.mjs:
    • a frame's size, bytes (0xce 0x79 for the floor's grey) and read-only flag, and its 25 ms cost;
    • the picture's top is ahead and its left is the drone's left (tape on the floor at known rows and columns);
    • detect_color_blob on a red patch, matching the C, debug bitmap included.
  • tests/sim-ui.mjs: in the browser, a colour and a grey frame drawn by the page, 25 ms each.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 52ae554):

https://firialabs-open-editor--pr176-codeair-camera-captu-l7kgjck9.web.app

(expires Thu, 10 Dec 2026 16:45:49 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 81259a1fec315ca1af3747d225d9c7424890be3e

@david-firia
david-firia merged commit ac496b5 into main Dec 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant