Skip to content

Gimbal: the tilt negation is untested; make it a pure function with a test - #168

Merged
nofuturekid merged 5 commits into
rebuildfrom
fix/153-test-tilt-sign
Nov 13, 2026
Merged

nofuturekid merged 5 commits into
rebuildfrom
fix/153-test-tilt-sign

Conversation

@nofuturekid

Copy link
Copy Markdown
Collaborator

Fixes #153

What changed

  • The tilt negation of Camera::gimbal (-t + 0.0) is now the private pure function tilt_to_pitch (user tilt, positive up, in; wire pitch, positive down, out) in crates/obsbot-device/src/models/tiny2lite/camera.rs. gimbal calls it. Nothing else in gimbal changed; the tracking-mode command it sends first stays as it is.
  • New test module gimbal_tilt_tests (4 tests): tilt 20 gives -20 (and the reverse), 0 and -0.0 give +0.0 (checked by bits), None stays None, and tilt_to_pitch(Some(30.0)) / Some(0.0) build the two pose frames of capture 18 byte for byte (0x6444, seq 28 and 33).
  • No CHANGELOG line (test and internal refactor only).

Verification (no camera, no device opened)

  • cargo fmt --check, cargo clippy --all-targets --locked -j 3 -- -D warnings, cargo test --locked --workspace -j 3: clean; 122 + 1 + 25 + 2 tests pass (118 before + the 4 new in the library). tests/byte_guard.rs and tests/cli_surface.rs and their fixtures are unchanged and pass, so no sent byte and no output changed.
  • Mutation by hand, test module run each time, code restored afterwards:
    • delete the - in tilt_to_pitch: tilt_up_is_sent_as_the_negated_pitch and the_converted_tilt_builds_the_captured_pose_frames FAIL.
    • delete the + 0.0: a_tilt_of_zero_is_sent_as_positive_zero and the_converted_tilt_builds_the_captured_pose_frames FAIL.
  • Not covered by design: that gimbal calls tilt_to_pitch at all. That needs a camera (the call is followed by I/O); the byte guard does not exercise gimbal either. The minus itself now lives in the tested function, so the cargo-mutants mutant "delete - in Camera::gimbal" no longer exists as such; the equivalent "delete - in tilt_to_pitch" is caught.
  • Note for the split (Groundwork: split camera.rs #162): tilt_to_pitch sits next to tilt_to_pitch_range in models/tiny2lite/camera.rs, test module gimbal_tilt_tests at the end of the file before angle_conversion_tests.

🤖 Generated with Claude Code

Camera::answer read the device directly, so no test reached its arms. The poll is now
poll_answer, which takes the selector-2 read as a closure and the gap as an argument;
Camera::answer passes the device read and the same 50 ms gap, so what is sent and read
on the camera is unchanged. Tests script the replies: a rejected answer returns
Error::Rejected(command, code) at the first read, an empty answer returns an empty list,
a stale answer runs through all 20 reads to NoAnswer, and failed reads are polled again
until a value arrives.

Fixes #151

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@nofuturekid nofuturekid added the enhancement New feature or request label Nov 13, 2026
@nofuturekid nofuturekid self-assigned this Nov 13, 2026
nofuturekid and others added 4 commits November 13, 2026 13:24
The test module already gets XU_SIZE through use super::*.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
full_status_with reads the device directly, so no test reached the arm that turns a rejected
or unanswered tracking query (0x0104) into tracking: None. Tests now run it on a scripted
Device (compiled in tests only, answering xu_get, xu_set, get_ctrl and ctrl_range from a
table): a rejected tracking query returns Ok with tracking None and the other fields filled,
an answered one fills tracking, and a failed write still fails the whole read. No status code
and no byte sent to the camera changed.

Fixes #152

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Do not claim how a camera treats an unknown query; the comment now says
what the test double does (type 0x89, code -1) and why.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Camera::gimbal sent the tilt negated inline; no test covered it, so
deleting the minus would have left every test green and made
`gimbal --tilt 20` move the camera down.

The negation (with the + 0.0 that keeps -0.0 off the wire) is now
tilt_to_pitch, which gimbal calls. The bytes sent for any input are
unchanged (byte guard and command-line guard pass unchanged).

Tests: positive tilt up gives the negated value, 0 stays +0.0, None
stays None, and the converted value builds the two pose frames of
capture 18 byte for byte.

Fixes #153

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@nofuturekid
nofuturekid force-pushed the fix/153-test-tilt-sign branch from 65160c1 to d2d1358 Compare November 13, 2026 12:29
@nofuturekid
nofuturekid merged commit d2d1358 into rebuild Nov 13, 2026
6 checks passed
@nofuturekid
nofuturekid deleted the fix/153-test-tilt-sign branch November 13, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant