fix: honour flip in DHLink.A() when the joint ET is not last (#563) - #619
Open
youdie006 wants to merge 1 commit into
Open
fix: honour flip in DHLink.A() when the joint ET is not last (#563)#619youdie006 wants to merge 1 commit into
youdie006 wants to merge 1 commit into
Conversation
DHLink.A() decided whether to negate the joint variable by checking self.ets[-1].isflip. For a link with a nonzero a, d or alpha, _to_ets() places the joint ET before the constant ETs, so self.ets[-1] is a constant ET whose isflip is always False. As a result flip=True was silently ignored for such links and q was not negated, so DHRobot.fkine disagreed with the link's own ETS. For example RevoluteDH(a=1.0, flip=True).A(0.5).A[1, 0] returned +sin(0.5) instead of -sin(0.5). Check self.isflip (the joint ET's flip, via Link.isflip -> self.v.isflip) instead of the last ET. When the joint ET is last (a = d = alpha = 0) the two are equal, so previously-correct links are unaffected. Fixes petercorke#563.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #563.
Problem
DHLink.A()decided whether to negate the joint variable by checkingself.ets[-1].isflip. For a link with a nonzeroa,doralpha,_to_ets()places the joint ET (Rz(flip=flip)) before the constant ETs (tz(d)/tx(a)/Rx(alpha)), soself.ets[-1]is a constant ET whoseisflipis alwaysFalse. As a resultflip=Truewas silently ignored for such links andqwas not negated, soDHRobot.fkinedisagreed with the link's own ETS.A control link with
a = 0(where the joint ET is last) already behaved correctly, which pinpoints the cause.Fix
Check
self.isflip(the joint ET's flip, viaLink.isflip->self.v.isflip) instead of the last ET. When the joint ET is last (a = d = alpha = 0) the two are equal, so previously-correct links are unaffected. One line inDHLink.A().Testing
test_flip_with_nonzero_aintests/test_DHRobot.py: assertsRevoluteDH(a=1.0, flip=True).A(q).Aequals the link's ownets.eval([q])and thatA[1, 0] == sin(-q).+0.479vs desired-0.479) and passes with the fix. Isolated the change against the fulltests/test_DHRobot.py: baseline had 2 failures (this new test + the pre-existingtest_payloaddrift), and after the one-line fix onlytest_payloadremains -- exactly this test flips fail -> pass, no other test changes. Sanity-checked thata=0flip stays correct and non-flip links are unchanged.Thanks to @yucchengyi for the report and the precise root-cause diagnosis.
This change was prepared with AI assistance and reviewed by me before submission.