Skip to content

fix(robot): the line of sight of vision_collision_damper is oriented correctly for parallel and antiparallel vectors - #845

Merged
petercorke merged 1 commit into
mainfrom
fix/vision-collision-orientation
Oct 19, 2026
Merged

petercorke merged 1 commit into
mainfrom
fix/vision-collision-orientation

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Fixes #843.

The line of sight of Robot.vision_collision_damper was oriented with arccos of the dot product and the cross product of the two vectors. For a camera directly above or below the target the vectors are parallel or antiparallel, the cross product is zero, and the rotation is about no axis. Today that gives the identity, which is wrong for the antiparallel case (a camera below the target draws the line of sight the wrong way), and once SpatialMath rejects a zero axis (rai-opensource/spatialmath-python#267) it would be a ValueError. arccos also gives nan when the dot product is 1.0000000000000002.

The orientation is now SE3(SO3.RotatedVector(a, b)), in a small module-level function, _rotation_between_vectors, so it can be tested. SO3.RotatedVector is in the released SpatialMath 1.1.18, so no change to the pin.

Tests: tests/test_vision_collision_orientation.py (20 cases: parallel, parallel to rounding, antiparallel, generic and random vectors, a camera above and below a target, and no warnings). Each checks that the rotation is proper and takes the direction of a to that of b. With the old computation in place, 10 of them fail.

Checked against both SpatialMath behaviours, running the function from this branch in two throwaway virtual environments:

Also 500 random pairs, with no failures in either. The test suite here runs against the #267 behaviour, since the SpatialMath checkout in this environment is on that branch. No change to behaviour other than for these degenerate cases.

Written with Claude Code.

🤖 Generated with Claude Code

…t orientation for parallel and antiparallel vectors

The orientation was computed from arccos and a cross product, which for parallel or
antiparallel vectors is a rotation about a zero axis.  That is the identity today, wrongly
for antiparallel vectors, and a ValueError once SpatialMath rejects a zero axis.  Use
SO3.RotatedVector, which is in the released SpatialMath, and test the helper.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@petercorke
petercorke enabled auto-merge (squash) October 19, 2026 04:54
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 high

Alerts:
⚠ 2 issues (≤ 0 issues of at least minor severity)

Results:
2 new issues

Category Results
Security 2 high

View in Codacy

🟢 Metrics 11 complexity · 0 duplication

Metric Results
Complexity 11
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit 82974b1 into main Oct 19, 2026
22 of 23 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 19, 2026
@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (f0e22c0) to head (8557525).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/roboticstoolbox/robot/Robot.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #845   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files        146     146           
  Lines      16836   16838    +2     
=====================================
- Misses     16836   16838    +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

tech-debt: vision_collision_damper breaks when SMTB angvec2r rejects a zero axis (parallel/antiparallel vectors)

1 participant