Skip to content

CodeAIR's sensors read as its flight firmware reports them - #170

Merged
david-firia merged 2 commits into
mainfrom
codeair-sensors
Dec 3, 2026
Merged

david-firia merged 2 commits into
mainfrom
codeair-sensors

Conversation

@david-firia

@david-firia david-firia commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

A simulated CodeAIR's sensors now report what CodeAIR's own flight firmware reports (read from its source, codeair-stm32-ref), so FLY mission code compares against the same numbers it would see on the drone. World only: no page changes.

What changes

  • Rates: front and up rangers read every 100 ms, down every 25 ms, flow every 10 ms, the barometer at 50 Hz, each held between reads, so a fast loop sees the same reading again as on the drone.
  • Gyroscope raw counts (GYRO): 16.384 a degree a second, x and y with the drone's sign (its IMU sits turned half round and raw counts are logged before alignment), with a small fixed bias.
  • Flow (FLOW): deltaX follows forward motion, deltaY leftward motion with its sign turned (the simulator had them swapped), plus the pitch and roll rates' share; motion.motion is the register's 176.
  • Magnetometer: reads 0, as on CodeAIR (none works). pm.*: 3.7 V, level 10, never changing, as on CodeAIR (only the main board measures the battery).
  • Barometer: baro.asl from the pressure by the firmware's formula (1015.7 hPa reference), with noise and a slow wander.
  • Accelerometer: gravity turned into the body plus the frame's acceleration (tilted, it reads the tilt). stabilizer.pitch equals stateEstimate.pitch (one variable on the drone); the quaternion is filled in.
  • Battery: a LiPo on the firmware's voltage table; sags about 0.3 V in a hover and runs down as it flies (power.battery_voltage()), for FLY's battery check.
  • Motor test: set_param('motorPowerSet.enable', 1) with m1 to m4 spins CodeAIR's motors 1 to 4 (front left, front right, rear left, rear right, as motors.c maps them and the Attitude lessons use them), heard and seen; it never flies.

Calibration numbers that are estimates (battery capacity, hover current, the out-of-range ranger value) are listed in sim/DESIGN.md under Calibration, to check on a drone.

Tests: five new headless tests in tests/sim.mjs (floor readings against the firmware, flow and gyro signs in flight, ranger rates, the motor test, the battery). node tests/sim.mjs passes on both MicroPython builds. The browser test (tests/sim-ui.mjs) is left to CI: on the shared host it stopped before CodeAIR at a CodeBot stepping check, from load there rather than this change. Also here: the crtp module keeps one log packet, the newest, as the device's C module does (it kept two).

Screenshot: a CodeAIR on the floor, motor test on, printing its sensors.

CodeAIR sensors on the floor

Design: the botblocks page "CodeAIR sensors in the simulator: design". Next: holding the drone and a ranger card (world), then the handles on the page.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SS5gJ3p1XJhQBNJ3wv9z2z

Read from codeair-stm32-ref: each ranger, the flow sensor and the barometer
read at their own rates and hold between reads; the gyroscope's raw counts
are 16.384 a degree a second with x and y turned (the IMU sits half round)
and carry a small bias; flow's deltaX follows forward motion and deltaY
leftward motion with its sign turned, with the pitch and roll rates' share;
the magnetometer reads 0 and the power manager's pm.* keep their starting
values, as on CodeAIR; baro.asl comes from the pressure by the firmware's
formula; stabilizer.pitch is stateEstimate.pitch; the accelerometer reads
gravity turned into the body; the quaternion and motion.std are filled in.

The battery is a LiPo cell on the firmware's voltage table that sags with
the current and runs down as it flies. The motor test (motorPowerSet) spins
CodeAIR's motors 1 to 4 at the powers set, heard and seen, and never flies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SS5gJ3p1XJhQBNJ3wv9z2z
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 3660dfc):

https://firialabs-open-editor--pr170-codeair-sensors-lxq2rkyt.web.app

(expires Thu, 10 Dec 2026 15:18:37 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 81259a1fec315ca1af3747d225d9c7424890be3e

@david-firia
david-firia merged commit 1f76c92 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