Skip to content

fix: read fresh status before motion and gate the grasp handover - #62

Merged
cao-xiao-hao merged 3 commits into
mainfrom
fix/stale-status-and-true-stop
Nov 19, 2026
Merged

cao-xiao-hao merged 3 commits into
mainfrom
fix/stale-status-and-true-stop

Conversation

@cao-xiao-hao

Copy link
Copy Markdown
Contributor

Summary

Ports the stale-state and true-stop hand-over fixes from the Python SDK (nexform-tech/litegrip-python#86) to the C++ CAN controller and action engine.

Changes

  • MotorController::poll() drains every queued status frame, bounded at kMaxDrainFrames, and lets the newest one define the state. Reading one frame per call left older answers queued, and the age was stamped when a frame was read, so an old position looked fresh.
  • poll_until() decides on the target's rx_count, not on the motor returned by the drain, so another registered motor's frame cannot hide the update.
  • CanTransport now implements the CanIo interface, so a queue-backed test transport can drive the controller.
  • MotionEngine::fresh_state() requests a status frame (0xCC) before every motion, the final reach check and every hold slice, and refuses with CommError when no frame answers.
  • A force-carrying approach's hand-over also requires the window's average speed to be under the new MotionConfig::stall_speed_mm_s (2 mm/s); the field is validated at construction.
  • A mid-hold CommError drops the torque and returns ok = false with cycles = 0, instead of leaving the last torque on the bus.
  • An abort = true release reads the cached position: a zero-gain frame needs no fresh pose, and an E-stop must not wait for a status answer.
  • Both READMEs document the gate.

Testing

cmake --build build -j then ctest --test-dir build:

100% tests passed out of 15

Total Test time (real) =   3.30 sec

npx --yes markdownlint-cli2@0.23.3 README.md: 0 issues.

New coverage: test_can_poll_drain (newest frame wins, foreign frames do not stop the drain, multi-motor poll_until, bounded drain) and eight test_motion cases (slow creep is not handed over, creep without contact never enters the hold, idle-bus refresh, stale-cache refusal, final-reach refresh, mid-hold CommError, abort without a fresh frame, config validation).

Issues

Refs nexform-tech/litegrip-python#86

Checklist

  • The title follows Conventional Commits and matches the commit subject.
  • The body is written in English.
  • Tests were run and the result is stated above.
  • Human-facing documents are paired with .zh-CN.md and open with the language switcher.
  • No secrets, credentials, or private URLs are included.
  • Closes is used only when the pull request fully resolves the issue.

The motor answers every control frame with a status frame. Reading one
frame per call left the rest queued, and the age was stamped when a frame
was read, so an old position looked fresh. On 2026-11-18 a ramp after a
force hold started from the hold's first pose (78 mm) while the jaws were
at 26 mm: the first frame demanded ~0.7 rad of error and the drive left at
23 rad/s out of a 20 mm/s move.

poll() now drains the queue (bounded at kMaxDrainFrames) and lets the
newest frame define the state. poll_until() checks the target's rx_count
instead of the motor returned by the drain, so another registered motor's
frame cannot hide the update.

CanTransport now implements the CanIo interface so a queue-backed fake can
drive the controller in tests.
fresh_state() requests a status frame (0xCC) before every motion and
refuses to plan when no frame answers. A cached snapshot -- even one
younger than kStaleAfterS -- is not enough: at 20 mm/s, half a second of
silence is 10 mm of unknown. The final reach check and every hold slice
use it too.

The force-approach handover also requires the window's average speed to
be below MotionConfig::stall_speed_mm_s (2 mm/s). A force-budgeted
approach that crawls (~8 mm/s on this bench) is not contact; handing it to
the torque-only hold accelerates the jaws across the free stroke.

A mid-hold CommError now drops the torque and returns ok=false instead of
leaving the last torque on the bus, and an abort=True release reads the
cached position -- a zero-gain frame needs no fresh pose and an E-stop
must not wait for a status answer.
Add the force-approach speed floor to both READMEs: the grasp row, the
slow-creep failure combination, and the MotionConfig table.
@cao-xiao-hao
cao-xiao-hao merged commit abafde9 into main Nov 19, 2026
1 check passed
@cao-xiao-hao
cao-xiao-hao deleted the fix/stale-status-and-true-stop branch November 19, 2026 06:01
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.1.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions Bot added the released Shipped in a release label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant