Skip to content

Feature/workspace limits richard - #47

Open
richardnguyen165 wants to merge 21 commits into
mainfrom
feature/workspace-limits-richard
Open

richardnguyen165 wants to merge 21 commits into
mainfrom
feature/workspace-limits-richard

Conversation

@richardnguyen165

@richardnguyen165 richardnguyen165 commented Oct 17, 2026 •

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features
    • Added a configurable keep-in boundary for the tool tip, with default bounds around the home pose.
    • Tool movement is constrained at the boundary across Cartesian, joint, and insertion controls. If the tool starts outside the box, movement back toward it remains possible.
    • The boundary is displayed in RViz and changes color when it blocks movement. Teleoperation status and diagnostics also identify keep-in limits.

yassinsolim and others added 13 commits September 26, 2026 13:06
The arm is a base yaw, three parallel pitch joints and a roll through the
tool tip, so kinematics.py solves any tip position and tool tilt in closed
form from the URDF. The new Cartesian group (Y) moves the tip along straight
lines in base_link with the tilt fixed; LB keeps only the strongest axis.
At a joint speed limit or the workspace edge the whole step shrinks, so the
tip stops on the line, and the roll turns against the yaw to keep the tool's
heading.

Each drive now gets the next setpoint one period ahead and the speed that
reaches it in exactly one period, measured from its encoder, so all drives
arrive together. acc is 255 because a gentle drive ramp adds the same rpm/s
to every drive and the one with the largest change falls behind. In
simulation a sideways cut at 30:1 gearing stays within 7-17 um of the line,
compared with up to 186 um with the old 1.5x speed rule. At the 1:1
placeholder gearing it stays within about 0.13 mm, one encoder count at the
tip.
D-pad left/right changes the tool pitch while the tip stays in place, so
the shoulder, elbow and wrist move around a fixed point. The tilt uses the
same closed-form step as straight moves, so a joint limit stops it with the
tip still in place. It runs at up to 30 deg/s, scaled by the speed level.
- Start is refused while a tilt button or A is held, like the sticks.
- Homing clears the Cartesian rates, so releasing A can't resume the last move.
- Cartesian roll ramps with the acceleration limit and scales with the accepted step.
- The drives' setpoint one period ahead stays within the URDF joint limits, which the
  drive node now reads from robot_description.
- If one drive would pass max_rpm, every drive slows by the same factor, so they still
  arrive together.
- The roll compensation is documented as stopping the tool spinning about its own axis;
  that keeps a blade's heading only when the tool points straight down.
- The Cartesian launch test is registered where it won't conflict with #22.
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 86fdab06-6993-4816-9e0e-7865eeb27c6d

No actionable comments were generated in the recent review.

Walkthrough

Teleoperation now applies a configured tool-tip keep-in box to joint, Cartesian, and incision motion. The Xbox node displays the box and reports when it blocks motion.

Changes: Keep-in Tool-tip Constraint

Layer / File(s) Summary
Define bounds and constrain kinematic jogs
waybionic_teleop/config/xbox_teleop.yaml, waybionic_teleop/waybionic_teleop/kinematics.py, waybionic_teleop/test/test_kinematics.py
The configuration defines the box bounds. Kinematic jogs check candidate tool-tip positions against those bounds and report keep_in when the box blocks a step. Tests cover box boundaries, return movement, diagonal cuts, and tilt and roll at a boundary.
Load bounds and enforce them in teleop
waybionic_teleop/waybionic_teleop/teleop.py, waybionic_teleop/test/test_teleop.py, waybionic_teleop/test/test_incision.py, waybionic_teleop/test/test_collision.py
Teleop loads and validates the bounds, checks that the home tool tip is inside the box, and constrains joint, Cartesian, and incision motion. Tests cover bounds, blocking, target lookahead, and collision behavior.
Display box and blocked state
waybionic_teleop/waybionic_teleop/xbox_teleop_node.py, waybionic_teleop/test/test_xbox_teleop_node.py
The Xbox node publishes a box marker in the base frame. The marker changes color when keep_in blocks motion. A test checks the stop state, summary, and diagnostic message.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant XboxTeleop
  participant ArmTeleop
  participant ArmKinematics
  XboxTeleop->>ArmTeleop: Send motion input
  ArmTeleop->>ArmKinematics: Solve jog with keep_in bounds
  ArmKinematics-->>ArmTeleop: Return targets and blocker
  ArmTeleop-->>XboxTeleop: Report keep_in stop state
Loading

Suggested reviewers: yassinsolim

Merge Risk: Minimal · previous review 1aead

No actionable keep-in constraint issue remains; the change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 28.30% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 53 functions across 8 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title identifies workspace limits, which matches the main keep-in box changes. It includes unnecessary text such as "Feature" and "richard," but remains sufficiently related and understandable.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 28.30% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 53 functions across 8 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches

🧪 Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

ℹ️ Recent review info

⚙️ Run configuration

  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3b57764f-f1a6-4efc-bb91-e4cca26b0938
📥 Commits

Reviewing files that changed from the base of the PR and between b80d6c2 and 1aead0c.

📒 Files selected for processing: 9

  • waybionic_teleop/config/xbox_teleop.yaml
  • waybionic_teleop/test/test_collision.py
  • waybionic_teleop/test/test_incision.py
  • waybionic_teleop/test/test_kinematics.py
  • waybionic_teleop/test/test_teleop.py
  • waybionic_teleop/test/test_xbox_teleop_node.py
  • waybionic_teleop/waybionic_teleop/kinematics.py
  • waybionic_teleop/waybionic_teleop/teleop.py
  • waybionic_teleop/waybionic_teleop/xbox_teleop_node.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Richard's October 17 commit keeps the tip in the box during the base and upper groups and homing, and draws the box in RViz. Merged with main's teleop, the box check also keeps the published lookahead inside, and it skips the incision group, which keeps the tool on its axis and checks the box itself. The collision tests for the joint groups put the box out of reach so the table check still stops them.
@yassinsolim

Copy link
Copy Markdown
Member

@richardnguyen165 #47 and #48 both conflicted because your October 17 commit was on your branch but the update wasn't, so I finished task 1 for you:

  • I merged your commit into update/workspace-limits-richard and resolved the conflicts in teleop.py and xbox_teleop_node.py. Main's rumble and stop reasons are kept, and your box marker is drawn next to the incision marker.
  • keep_inside now runs in the base and upper groups and during homing. It skips the incision group, which keeps the tool on its axis and checks the box itself. It also keeps the published one-period lookahead inside the box, not just the target. There's a new test for that: test_a_joint_group_stops_the_tip_and_the_next_setpoint_at_the_keep_in_floor.
  • The collision tests for the joint groups now use a box out of the arm's reach, so the table check is still what stops them.
  • The full suite passes (1042 tests).

Your branch now points at that merge (1aead0c), so #48 is merged and #47 no longer conflicts. Pull before you change anything:

git checkout feature/workspace-limits-richard
git pull

Before #47 is ready for review, tasks 2 to 5 from the October 17 list are still open:

  1. Check the box against the arm's real reach, joint limits and home position with the Mechanical Team.
  2. Add tests for the joint movements where the tip starts outside more than one side of the box.
  3. Test the box together with the collision checks, including moves that approach both at once.
  4. Fill in the PR description with what the PR does, the test results and the remaining limitations.

If a merge conflicts again, ask a lead before opening a PR.

@richardnguyen165

Copy link
Copy Markdown
Author

The test results are all passing. The added tests involve tools that, if they go out of bounds, cannot move further but can move back along the axis, preventing them from exceeding the boundaries. Cannot run code as it keeps crashing.

@yassinsolim yassinsolim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Richard. The two-face tests are good: moves out through either face are refused, moves back in through both recover, and the third-face case stops on the wall. I applied this PR on top of current main and ran the full suite: 1279 tests, 0 failures. The CI failures here aren't from your change (a flaky Cartesian launch test, an xmllint schema download and a diagnostics test timeout on the runner), so you don't need to chase them.

Before it can merge:

  1. Merge main. Git will report 18 conflicts, but none of them are real: main hasn't changed any of your files since #34, and you haven't changed any of the others. So keep yours for your four files and main's for the rest. CI runs the full suite when you push, so you don't need Docker for this.

    git fetch origin
    git checkout feature/workspace-limits-richard
    git pull
    git merge origin/main
    mine="waybionic_teleop/config/xbox_teleop.yaml waybionic_teleop/test/test_teleop.py
      waybionic_teleop/waybionic_teleop/teleop.py waybionic_teleop/waybionic_teleop/xbox_teleop_node.py"
    git checkout --ours -- $mine
    git add -- $mine
    git diff --name-only --diff-filter=U | xargs git checkout --theirs --
    git add -A
    git commit --no-edit
    git push
  2. Test the box and the collision check together. Add a move that heads for both at once, for example the tool going down toward a table set just above or just below the box floor. Check that the arm stops at whichever comes first and that blocked names it.

  3. Fill in the PR description: what it does, the test results, and what's still provisional, such as the box size until it's checked against the arm's reach.

richard.nguyen1 added 2 commits October 24, 2026 10:48
…its-richard

# Conflicts:
#	BuildInstructions.md
#	waybionic_bringup/CMakeLists.txt
#	waybionic_bringup/launch/ground_station.launch.py
#	waybionic_bringup/scripts/camera_follower.py
#	waybionic_teleop/config/arm_drives.yaml
#	waybionic_teleop/config/xbox_teleop.yaml
#	waybionic_teleop/setup.py
#	waybionic_teleop/test/test_gamepad.py
#	waybionic_teleop/test/test_mks_can.py
#	waybionic_teleop/test/test_sim_drives.py
#	waybionic_teleop/test/test_teleop.py
#	waybionic_teleop/waybionic_teleop/gamepad.py
#	waybionic_teleop/waybionic_teleop/joy_udp_receiver.py
#	waybionic_teleop/waybionic_teleop/mks_can.py
#	waybionic_teleop/waybionic_teleop/sim_arm_drives_node.py
#	waybionic_teleop/waybionic_teleop/teleop.py
#	waybionic_teleop/waybionic_teleop/xbox_teleop_node.py
#	waybionic_teleop/waybionic_teleop/xinput_bridge.py
@richardnguyen165

Copy link
Copy Markdown
Author

Actual Reach: 0.49m,
Joint Limits: J1(No Limit), J2(180), J3(270)
Diff (Yaw/Z: No Limit, Roll/X: 180)
Home Position: fully upright

@richardnguyen165

Copy link
Copy Markdown
Author

What this does

Adds a keep-in box for the tool tip. Teleop stops the tip at the box walls in every control mode.

  • Config: keep_in_min_mm / keep_in_max_mm in xbox_teleop.yaml, as [x, y, z] in base_frame. The default is [-550, -550, 50] to [550, 550, 800]. config_from_parameters rejects a box that is empty, has a value missing or has a non-finite value. ArmTeleop refuses to start if the box doesn't contain the home tool tip.
  • Cartesian and incision moves (ArmKinematics.jog): when a step would leave the box, the whole step shrinks, so the tip stays on its line and stops on the wall. blocked then names keep_in and not the reach or a joint. The Cartesian lookahead (command_targets) is held inside the box as well.
  • Joint groups and homing (ArmTeleop.keep_inside): the joint change for the step is scaled down by bisection, so the arm keeps its direction and the tip stops on the wall.
  • Starting outside the box: the tip can move back in, but it can never move further out through any face. That holds when it is outside two faces at once.
  • Feedback: RViz draws the box as a grey wireframe that turns red while it blocks a move. The node label shows STOPPED-keep_in and the teleop.state diagnostic reads At limit: keep_in.
  • With the table check: the box and ArmCollision both apply on every step. Whichever one the arm reaches first stops it, and that one is named in blocked.

Tests

  • CI on 24af71b: build-and-test, build-and-test-arm64 and can-drives-vcan all pass.
  • Locally: python3 -m pytest test in waybionic_teleop gives 817 passed, 0 failed.
  • New coverage:
    • test_kinematics.py: a cut stops at the box, including diagonal cuts, which stay on their line. Tilting and rolling at the wall keep the tip still. Outside one face or two, the tip may only move back in (6 cases).
    • test_teleop.py: the tip and the next setpoint stop at the floor in the Cartesian group and in a joint group. Outside two faces, joint moves out through either face are refused and a move back in through both recovers. A recovery that would leave a third face stops on that face. Bad boxes, and a box without the home pose, are rejected.
    • test_incision.py: an insertion stops at the floor on the tool axis and can back out. Box and table together: one insertion heads for both, with the table 2 mm above the floor and then 2 mm below it. In each case the arm stops at whichever comes first, blocked names only that one (tool_link: table or keep_in), and pushing on does not move it.
    • test_collision.py: the existing table tests now use a box that is out of the way or floored at the table, so the table check is still the thing they test.
    • test_xbox_teleop_node.py: a keep-in stop is named on the label and in the diagnostics.

Box vs. the real arm

Real arm URDF / teleop now Box now
Reach 0.49 m 0.545 m, shoulder axis to tool tip x, y ±550 mm
J1 (base yaw) no limit ±180° n/a
J2 (shoulder) 180° ±90° n/a
J3 (elbow) 270° ±90° (180°) n/a
Differential, yaw about Z no limit joint_5 ±90° n/a
Differential, roll about X 180° joint_4 ±90° n/a
Home fully upright all joints 0 = upright, tip at (0, 33, 759) mm z max 800 mm, so home is inside

The box was sized from the URDF reach (545 mm), so x and y reach about 55–60 mm past what the real arm can reach. That is safe, since it never blocks a reachable pose, but it isn't a real limit yet. Home matches: both are fully upright, and the home tip is inside the box.

Still provisional

  • Box size. The x/y limits (±550) come from the URDF reach, not the real 0.49 m. The z limits (floor 50 mm, ceiling 800 mm) were chosen to clear the base and contain home. None of the limits come from a measured workspace yet. Shrinking x/y to about ±490 mm would match the reach, if 0.49 m is measured from the same axis as the URDF value.
  • Reach mismatch. The URDF links give 0.545 m, but the arm reaches 0.49 m. Until the URDF is corrected, the upright home tip on the real arm may also sit lower than 759 mm.
  • Joint limits. The URDF and the test LIMITS are narrower than the hardware: J1 and the differential yaw are ±180° and ±90° where the hardware has no limit, and J3 is ±90° against a real 270°. Narrower is safe, but it hides part of the workspace. These belong in the URDF, not in this PR.
  • Differential axis naming. I've taken the "Roll/X 180°" axis to be joint_4 (pitch about y in the URDF) and "Yaw/Z no limit" to be joint_5 (roll about the tool axis). This needs confirming.

yassinsolim and others added 2 commits November 14, 2026 04:42
Runs the ground station's own drive, teleop, diagnostics and RViz nodes on the
bench arm through the UNO R4 WiFi + MCP2515 carrier's SLCAN link, and fixes the
CI flakes that were failing main.

- Stop CI failing on shutdown races and float timing
- Bring up the real arm through the MCP2515 carrier
- Load vcan without linux-modules-extra on new runner kernels
- Record why gravity compensation needs torque-controlled drives
- Keep arrival order when a frame rolls over during a buffer read
- Stop a failing frame log from interrupting drive control
- Fix the bench-tool edge cases found in review of the carrier bring-up

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…its-richard

Merging changes from main into branch.
…the base yaw. Pushing the stick right now turns the arm right instead of left.
@richardnguyen165

Copy link
Copy Markdown
Author

Keep the tool tip inside a configurable workspace box (keep-in limits)

Scope

Adds a keep-in box: an axis-aligned box in base_link that the tool tip may not leave.
It applies in every teleop mode and works alongside the existing table/base collision check.

In scope

  • keep_in_min_mm / keep_in_max_mm parameters in xbox_teleop.yaml, validated at startup
    (three finite values per corner, min < max, and the box must contain the home tool tip).
  • Joint groups and homing (ArmTeleop.keep_inside): a step that would take the tip out of
    the box is shortened as a whole, so the arm keeps its direction and stops on the wall. The
    next-period setpoint sent to the drives is also kept inside.
  • Cartesian and incision groups (ArmKinematics.jog(..., keep_in)): the straight-line solve
    stops the tip at the box walls and reports keep_in as the blocker.
  • Recovery from outside: a tip that starts outside (e.g. after the box is tightened) may move
    back in, but never further out on any face. A move that recovers on two faces while leaving
    through a third stops on the third.
  • Feedback: the box is drawn in RViz (grey, red while it is stopping a move) and the stop is
    named in the status label and diagnostics.

Out of scope

  • Real workspace dimensions (see Provisional bounds).
  • Changes to the collision model, joint limits or drive code.

Tested evidence

All tests run in simulation against the URDF kinematics; nothing here was measured on the
powered arm.

Platform Run Result
x86_64 Local, 41 targeted workspace/table/multi-face cases 41 passed, 0 failed
x86_64 CI build-and-test, full suite 1470 tests, 0 failures, 11 skipped —
ARM64 CI build-and-test-arm64, full suite 1470 tests, 0 failures, 11 skipped —

The 11 skips are CAN/firmware tests that need vcan or a C++ compiler; none are keep-in cases.

Targeted command (from waybionic_teleop/):

python3 -m pytest -v test/test_teleop.py test/test_incision.py test/test_collision.py \
  test/test_kinematics.py -k "keep_in or box or face or table or floor or outside"

What the tests cover:

  • The tip and the next setpoint stop at the floor, in joint and Cartesian groups.
  • Outside two faces: a move out through either face is refused; a move back in through both
    recovers, never getting further out on any face during the move.
  • Third face: a move that recovers x and z while yawing into the y wall stops exactly on the
    wall (±0.001 mm), with keep_in as the blocker.
  • Floor vs table: an insertion stops at whichever of the box floor and the table comes first,
    and only that one is reported (table_first and floor_first).
  • Invalid boxes (empty, NaN, wrong length, home outside) are rejected.

Fix after merging main: #55 reversed the base yaw stick, so the third-face test's
left_x=+1 yawed the arm away from the y wall and never engaged the guard (tip ended at
y = 5.3 mm, blocked == []). The test passes on the pre-merge commit and fails after the merge,
so the implementation was correct and the test input was stale. e3f2253 corrects the stick
direction. No assertion was changed. With the y wall deliberately removed from the guard, the
corrected test fails (tip reaches y = 52 mm), so it does detect a broken guard.

Provisional bounds

Parameter Value Basis
keep_in_min_mm [-550, -550, 50] x/y: the arm's full reach; z: tip 50 mm above the base
keep_in_max_mm [550, 550, 800] x/y: the arm's full reach; z: above the highest reachable tip
table_height 0.0 m table level with the bottom of the base
collision_clearance 0.01 m margin kept between any collision box and the table/base

These defaults are deliberately loose: they stop gross excursions, not task-specific ones.
They must be replaced once the real workspace is defined.

Unresolved mechanical assumptions

  • Arm geometry: the box is checked against the tool-tip position computed from the URDF
    (generated from CAD by scripts/cad/build_arm_description.py, whose joint limits are marked
    provisional). Link lengths, joint zero offsets and backlash on the real arm are not verified.
    An error there moves the real tip relative to the box by the same amount.
  • Tool tip: tool_link and its collision box are placeholders until Biomedical provides
    the end effector. A real tool's length moves the tip and changes where the box stops it.
  • Mounting: the box is in base_link, so it assumes the base is fixed and level and the
    table is at table_height. None of this has been measured on the bench.
  • Only the tip is bounded: the elbow, wrist and other links can still leave the box;
    only the table/base collision check protects them.
  • Missing kinematics silently disables the box: if the URDF has no usable chain to
    tool_frame, the node logs "Cartesian group unavailable" and still runs the joint groups,
    but with no keep-in check. A broken collision model, by contrast, disables teleop entirely.
    <Fixed in this PR / tracked in #___ — choose one before review>
  • Not checked on hardware:

Reviewer checklist

  • Agree the provisional bounds are safe to merge as defaults.
  • Decide how to handle the missing-kinematics bypass (fix here or follow-up).
  • Confirm build-and-test and build-and-test-arm64 are required checks on main.

@richardnguyen165

Copy link
Copy Markdown
Author

@Gkong5020 @ovilikaris-dotcom Requesting re-review.

@yassinsolim

Copy link
Copy Markdown
Member

Heads-up, Richard: I rewrote the history of main today to remove a Co-authored-by trailer from my commits (388f391 is now 750e8c7). The files are identical, but your branch still contains the old commit, so this PR's Files changed tab now lists 63 files instead of your 9.

To fix it, run:

git fetch origin
git merge origin/main
git push

The merge should be clean because the contents match. Until you have done that, please do not land this PR with a merge commit (a squash merge is fine), or the old commit comes back into main.

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.

2 participants