Skip to content

RSDK-14475: pin orientation vector longitude at both poles, not just the north - #188

Open
Vignesh P (vpandiarajan20) wants to merge 5 commits into
mainfrom
fix-ov-south-pole-longitude
Open

RSDK-14475: pin orientation vector longitude at both poles, not just the north#188
Vignesh P (vpandiarajan20) wants to merge 5 commits into
mainfrom
fix-ov-south-pole-longitude

Conversation

@vpandiarajan20

@vpandiarajan20 Vignesh P (vpandiarajan20) commented Aug 27, 2026

Copy link
Copy Markdown
Member

The bug

utils.rs:135 guards on the signed value instead of the magnitude:

val if 1.0 - val > ANGLE_ACCEPTANCE => self.o_vector.y.atan2(self.o_vector.x),

At o_z = -1 that is 1.0 - (-1.0) = 2.0, which clears ANGLE_ACCEPTANCE (1e-4) and takes the non-pole branch. So the guard only ever fires near o_z = +1, and vectors pointing nearly straight down keep a longitude that should have been discarded.

rdk — which is what encodes these vectors — guards on the magnitude and pins at both poles: orientationVector.go:134, with defaultAngleEpsilon = 1e-4. Its doc comment states the rule in prose: 1 - abs(OZ) > OrientationVectorPoleRadius.

Most likely an oversight rather than a convention, because the reverse conversion in this same file already uses the magnitude: utils.rs:183. The two directions currently disagree about where the south pole band is.

Effect

Both build Rz(lon)·Ry(lat)·Rz(theta). rdk uses lon = 0 in the band, this crate used lon = atan2(o_y, o_x), so the rotations differ by exactly the vector's azimuth, up to 180°. Measured: 45.0000° off at azimuth 45°, 90.0000° off at azimuth 90°.

Fix

One guard expression, valval.abs(). ANGLE_ACCEPTANCE unchanged, surrounding math unchanged, reverse conversion untouched.

Tests

Three added to the existing inline module. Expected quaternions are hardcoded literals computed independently of the code under test.

  • south poleo_z = -0.99999 at azimuth 45° and 90°; both must give the one pinned rotation. Fails on main (0.15224 vs 0.0).
  • north pole — same at o_z = +0.99999. Already correct; guards against fixing one pole and breaking the other.
  • round trip — quaternion → orientation vector → quaternion near the south pole. Closes now that both directions pin in the same band; the residual is the intrinsic pinning bound and shrinks with the gap (0.196° at 1e-5, 1.96e-3° at 1e-9), where the pre-fix error stayed at 45° regardless.

./etc/test.sh: 14 passed on main, 17 passed on this branch. No pre-existing test asserted the old behaviour.

to_quaternion guarded the pole case on 1.0 - o_z rather than
1.0 - o_z.abs(), so the guard could only ever fire near o_z = +1. At the
south pole 1.0 - (-1.0) = 2.0, which clears ANGLE_ACCEPTANCE and takes
the ordinary non-pole branch instead of pinning the longitude.

rdk pins at both poles (spatialmath/orientationVector.go:134), and the
reverse conversion in this same file already uses .abs() at line 186, so
the two directions were inconsistent with each other near o_z = -1.
@CLAassistant

CLAassistant commented Aug 27, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@vpandiarajan20
Vignesh P (vpandiarajan20) marked this pull request as draft August 27, 2026 20:43
Comments only; no code or test logic changed. Drops comments that
restated the following line and moves the rationale to the PR
description.
Cross-repo line numbers drift. Name the Go function instead.
Comments should describe the code as it exists; the rationale for the fix
lives in the PR description.
@vpandiarajan20
Vignesh P (vpandiarajan20) marked this pull request as ready for review August 31, 2026 16:55
@vpandiarajan20 Vignesh P (vpandiarajan20) changed the title fix(spatialmath): pin orientation vector longitude at both poles, not just the north RSDK-14475: fix(spatialmath): pin orientation vector longitude at both poles, not just the north Aug 31, 2026
@vpandiarajan20 Vignesh P (vpandiarajan20) changed the title RSDK-14475: fix(spatialmath): pin orientation vector longitude at both poles, not just the north RSDK-14475: pin orientation vector longitude at both poles, not just the north Aug 31, 2026
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