Repository navigation
feat(iwr6843): phone-assisted TI radar tilt calibration - #298
Merged
Merged
Conversation
A phone can now measure the IWR6843 mount tilt with its accelerometer and send it over BLE (`iwr6843_orientation_calibration`) or HTTP (`POST /api/calibration/iwr6843/orientation`; `GET` reads the current tilt). Both call one server function. The Pi recomputes tilt and roll from the gravity vector and rejects inconsistent, unstable, out-of-range or unlevel measurements. When the enclosure LIS3DH is enabled it waits for a stable reading and subtracts the calibrated enclosure pitch, failing safe with 409 if the sensor is unstable. The tilt is applied immediately, broadcast on Socket.IO, logged as a config change with source `ios_companion`, and saved atomically to ~/.config/openflight/iwr6843_phone_orientation.json. At startup the TI tilt resolves as `--iwr6843-tilt-deg` > saved phone calibration > calibration JSON, recorded as `tilt_source` in the runtime config. An unreadable saved file is ignored with a warning. This is the first BLE command that writes persisted configuration; the BLE security docs now say so explicitly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
16 of 17 tasks
On startup the saved phone tilt was applied, but the record itself was dropped, so GET /api/calibration/iwr6843/orientation returned "calibration": null until the phone recalibrated. Carry the record into the runtime config and calibration meta when it supplies the tilt; a --iwr6843-tilt override still reports null because the record is unused. Co-Authored-By: Claude Opus 5.5 <[email protected]>
btripp
marked this pull request as ready for review
October 12, 2026 17:56
…ibration # Conflicts: # docs/ios-ble.md # src/openflight/server.py
jewbetcha
approved these changes
Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reviewing this PR
src/openflight/phone_orientation.py(new, 178 lines): payload validation, gravity recomputation and atomic save/load.src/openflight/server.py(+143/-2): the/api/calibration/iwr6843/orientationroute andapply_iwr6843_orientation_calibration, one new entry indispatch_phone_control_command, and_resolve_iwr_mount_tiltused byinit_iwr6843.docs/ios-ble.md→ Security and scope and in the dispatcher docstring. If you'd rather keep BLE strictly read-and-select, the change is to drop one line from thehandlersdict (and the loopback test) and leave HTTP only.What does this PR do?
Adds phone-assisted tilt calibration for the TI IWR6843 radar.
mount_tilt_deg/roll_deg,sample_count, tilt/roll standard deviations,measured_at, and an optionaldevice_model. It goes over BLE asiwr6843_orientation_calibrationor over HTTP asPOST /api/calibration/iwr6843/orientation.GETon that route returns the current configured tilt, the azimuth offset, and the last phone calibration applied in this process. Both transports call the same server function.400if:409.409and changes nothing.Calibrationis replaced, not mutated)iwr6843_orientation_calibratedios_companion~/.config/openflight/iwr6843_phone_orientation.json--iwr6843-tilt-degfirst, then the saved phone calibration, then the calibration JSON. The source is recorded astilt_sourcein the IWR6843 runtime config. A corrupt saved file is ignored with a warning.docs/ios-ble.md: new "Calibrate TI radar tilt with the phone" section, a row in the commands table, and updated Security and scope.docs/iwr6843/mounting.md,docs/build/inclinometer.mdanddocs/how-it-works/positioning.md.Why was this required?
This is follow-up 3 from #285. Measuring the TI antenna-face tilt means holding a separate inclinometer against the board and typing the number into
--iwr6843-tilt-deg. A wrong tilt doesn't raise an error. It quietly produces plausible but wrong launch angles. The phone's accelerometer is accurate enough for this and is already in the user's hand, so the companion app can measure, check stability and roll, and apply the tilt in one step.This only covers pitch. It deliberately does not touch
--iwr6843-azimuth-offset-deg: an accelerometer can't give yaw relative to the target line.Automated tests
tests/test_phone_orientation_calibration.py(new, 9 test functions, one parametrized):409without the TI radartilt_source == "ios_companion", with the originalCalibrationleft untouchedGETstill reports the saved calibration record, and reportsnullwhen--iwr6843-tilt-degoverrides ittests/test_ble_loopback.py:test_calibration_without_iwr6843_returns_the_409_error. The real BLE dispatch path returnsok:falsewithTI IWR6843 radar is not enabled.tests/test_server.py: the twoinit_iwr6843tests inTestIWR6843ShotIntegrationnow pointPHONE_ORIENTATION_CALIBRATION_PATHat a missing file intmp_path. Without that, a real saved calibration on the dev machine would change their results.uv run python scripts/ble/generate_goldens.py --checkpasses.Manual (human) testing
uv run pytest -q: 1817 passed, 10 skipped (after merging currentmain).uv run ruff check src/openflight/: all checks passed.uv run ruff format --checkon every touched Python file: already formatted.uv run pylint src/openflight/ --fail-under=9: 9.60/10, with no messages on added lines.uv run openflight-server --mock --host 127.0.0.1 --web-port 8766, then:GET /api/calibration/iwr6843/orientation→409 {"error":"TI IWR6843 radar is not enabled"}POSTwith a JSON body →409 {"error":"TI IWR6843 radar is not enabled"}IWR6843CaptureMonitor(serial/GPIO; does nothing),tx_order_from_config→"normal", andCalibration.load→ identity with a 10.4° tilt. The calibration file path pointed at a temp dir.main()rejects--iwr6843with--mock, so a small launcher calledinit_iwr6843(...)with the same argumentsmain()uses, then ranserver.main()with--mock.init_iwr6843, tilt resolution,IWR6843Runtime, the Flask route, validation, atomic save/load, the session logger and the Socket.IO emit, all exercised over real HTTP and Socket.IO.GETbefore calibrating →200, tilt 10.4,calibration: null.POSTwith a valid 12.25° measurement →200 applied. The file was written, a followingGETreturned the record, the log showedApplied iOS phone calibration … configured TI tilt 12.250deg, and the session log recorded aconfig_changefromios_companion.400with the expected messages (10 samples, stddev 0.9°, roll 4°, gravity/angle mismatch, non-object body). The saved file was unchanged (same sha256).tilt_source: ios_companion, andGETreturns the saved record.tilt_source: command_line,calibration: null, and the saved file untouched.iwr6843_orientation_calibratedSocket.IO event per successfulPOST, with a payload equal to the response; none for rejected ones.Checklist
uv run pytest tests/ -v)uv run pylint src/openflight/ --fail-under=9)uv run ruff check src/openflight/)cd ui && npm run build) — no UI changes; not runcd ui && npm run lint) — no UI changes; not run🤖 Generated with Claude Code