Skip to content

pumakins: keep every joint within a half turn of the previous value - #4708

Merged
grandixximo merged 1 commit into
LinuxCNC:masterfrom
grandixximo:pumakins-base-unwrap
Oct 31, 2026
Merged

grandixximo merged 1 commit into
LinuxCNC:masterfrom
grandixximo:pumakins-base-unwrap

Conversation

@grandixximo

@grandixximo grandixximo commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #4586 (issue #4585), which unwrapped the wrist, joints 4 and 6. The arm joints have the same problem, and worse.

Joint 1 is atan2(py, px) less another atan2, joint 3 a difference of two, and joint 2 the difference of joint 3 from a third. So each can come back a whole turn away from the joint that made the pose, not only when it crosses +-180. Motion takes that as a whole turn of the joint in one servo cycle.

On the puma sim: jog the waist to 169 in joint mode and switch to world mode. On master, joint 0 becomes -191, past the -170 soft limit, and every world move after that is refused. With this change it stays at 169 and world jogs work. Below about 167 nothing shows with the arm reaching forward, because the D3 offset moves the wrap point; with the arm leaning back, the waist is a turn off anywhere.

The change

Every joint now goes through the same angleDiff() step as the wrist, onto the value within a half turn of the joint passed in. That includes the wrist pitch, joint 5, so there is one rule for all six.

Test

tests/pumakins-unwrap now walks the waist, the shoulder and the elbow through +-180 in each direction as well as the wrist: the pose of each step from the forward, and the inverse handed the joints of the step before. On master 120 of the 200 poses fail, all on joints 1, 2 and 3. The wrist pitch is left out, since at +-180 the wrist is folded back on itself and joints 4 and 6 are not determined.

f5311b8 unwrapped the wrist, joints 4 and 6, which came straight from atan2() and jumped a whole turn when they crossed +-180. The arm joints were left as they were. Joint 1 is atan2(py, px) less another atan2, joint 3 a difference of two, and joint 2 the difference of joint 3 from a third, so each can come back a turn away from the joint that made the pose, not only at the boundary: the waist at 150 degrees returned -210. Motion takes that as a whole turn of the joint in one servo cycle. On the puma sim, with the waist jogged to 169 in joint mode, switching to world mode set joint 0 to -191, past the -170 soft limit, and every world move after it was refused.

Every joint now goes through the same angleDiff() step as the wrist, onto the value within a half turn of the joint passed in. The wrist pitch, joint 5, as well, for one rule; at +-180 the wrist is folded back on itself and the test leaves it out.

tests/pumakins-unwrap walks the waist, the shoulder and the elbow through +-180 each way as well as the wrist, the pose of each step from the forward and the inverse handed the joints of the step before. Without the change 120 of the 200 poses fail, on joints 1, 2 and 3.
@grandixximo
grandixximo marked this pull request as ready for review October 27, 2026 03:31
@grandixximo
grandixximo merged commit ab27a7f into LinuxCNC:master Oct 31, 2026
17 checks passed
@grandixximo
grandixximo deleted the pumakins-base-unwrap branch October 31, 2026 12:23
Ash-Pera added a commit to Ash-Pera/linuxcnc that referenced this pull request Nov 17, 2026
The inverse took joint 0 as the difference of two atan2() results,
which lands anywhere in (-360, 360), and ignored the joint motion hands
in.  Wherever the bearing of the end effector crossed +-180 with the
elbow bent, or joint 0 itself was past a half turn, the inverse
returned joint 0 a whole turn away and joint 3 a whole turn the other
way, which motion takes as a step.  The scara sims allow joint 0
+-360, so they reach it.

Bring joint 0 back within a half turn of the joint passed in, as
pumakins does since LinuxCNC#4708.  Joint 1 comes from acos() and needs
nothing; joint 3 follows from the pose's C and the two.

Motion also seeds the inverse with the end of the queue when it plans
a joint-interpolated move, so such a move now turns joint 0 the short
way, as pumakins' moves have since LinuxCNC#4708.  Near a joint 0 limit the
short way can cross the limit where the old answer did not.

Found by tests/kins-roundtrip, which round-trips joints drawn over the
sim's joint 0 range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ash-Pera added a commit to Ash-Pera/linuxcnc that referenced this pull request Nov 17, 2026
three21kins carries pumakins' solver and took every joint straight from
atan2(), or a difference of two, without regard to the joints motion
hands in.  With the shoulder flag set the base could come back one or
two turns off, and the wrist roll and twist came back a whole turn off
past +-180, so motion saw a step of a turn or more in one cycle.

Bring each joint back within a half turn of the joint passed in, the
change pumakins took in LinuxCNC#4708.  As there, a joint-interpolated move,
whose end motion finds by seeding the inverse with the end of the
queue, now turns each joint the short way, which near a limit can
cross it where the old answer did not.

Found by tests/kins-roundtrip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ash-Pera added a commit to Ash-Pera/linuxcnc that referenced this pull request Nov 19, 2026
The inverse took joint 0 as the difference of two atan2() results,
which lands anywhere in (-360, 360), and ignored the joint motion hands
in.  Wherever the bearing of the end effector crossed +-180 with the
elbow bent, or joint 0 itself was past a half turn, the inverse
returned joint 0 a whole turn away and joint 3 a whole turn the other
way, which motion takes as a step.  The scara sims allow joint 0
+-360, so they reach it.

Bring joint 0 back within a half turn of the joint passed in, as
pumakins does since LinuxCNC#4708.  Joint 1 comes from acos() and needs
nothing; joint 3 follows from the pose's C and the two.

Motion also seeds the inverse with the joints at the end of the queue
when it checks a queued move's endpoint against the joint limits and
when it finds where a joint-interpolated move ends.  There joint 0 now
lands within a half turn of that seed, as pumakins' has since LinuxCNC#4708, so
a joint-interpolated move turns it the short way, and near a joint 0
limit an endpoint can fall on the other side of the limit, and be
refused, where the old answer did not, or the reverse.

Found by tests/kins-roundtrip, which round-trips joints drawn over the
sim's joint 0 range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ash-Pera added a commit to Ash-Pera/linuxcnc that referenced this pull request Nov 19, 2026
three21kins carries pumakins' solver and took every joint straight from
atan2(), or a difference of two, without regard to the joints motion
hands in.  With the shoulder flag set the base could come back one or
two turns off, and the wrist roll and twist came back a whole turn off
past +-180, so motion saw a step of a turn or more in one cycle.

Bring each joint back within a half turn of the joint passed in, the
change pumakins took in LinuxCNC#4708.  As there, where motion seeds the
inverse with the end of the queue, checking a queued move's endpoint
against the joint limits and finding where a joint-interpolated move
ends, each joint now lands within a half turn of the seed: such a move
turns it the short way, and near a limit an endpoint can fall on the
other side of it where the old answer did not, or the reverse.

Found by tests/kins-roundtrip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ash-Pera added a commit to Ash-Pera/linuxcnc that referenced this pull request Nov 19, 2026
The inverse took joint 0 as the difference of two atan2() results,
which lands anywhere in (-360, 360), and ignored the joint motion hands
in.  Wherever the bearing of the end effector crossed +-180 with the
elbow bent, or joint 0 itself was past a half turn, the inverse
returned joint 0 a whole turn away and joint 3 a whole turn the other
way, which motion takes as a step.  The scara sims allow joint 0
+-360, so they reach it.

Bring joint 0 back within a half turn of the joint passed in, as
pumakins does since LinuxCNC#4708.  Joint 1 comes from acos() and needs
nothing; joint 3 follows from the pose's C and the two.

Motion also seeds the inverse with the joints at the end of the queue
when it checks a queued move's endpoint against the joint limits and
when it finds where a joint-interpolated move ends.  There joint 0 now
lands within a half turn of that seed, as pumakins' has since LinuxCNC#4708, so
a joint-interpolated move turns it the short way, and near a joint 0
limit an endpoint can fall on the other side of the limit, and be
refused, where the old answer did not, or the reverse.

Found by tests/kins-roundtrip, which round-trips joints drawn over the
sim's joint 0 range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ash-Pera added a commit to Ash-Pera/linuxcnc that referenced this pull request Nov 19, 2026
three21kins carries pumakins' solver and took every joint straight from
atan2(), or a difference of two, without regard to the joints motion
hands in.  With the shoulder flag set the base could come back one or
two turns off, and the wrist roll and twist came back a whole turn off
past +-180, so motion saw a step of a turn or more in one cycle.

Bring each joint back within a half turn of the joint passed in, the
change pumakins took in LinuxCNC#4708.  As there, where motion seeds the
inverse with the end of the queue, checking a queued move's endpoint
against the joint limits and finding where a joint-interpolated move
ends, each joint now lands within a half turn of the seed: such a move
turns it the short way, and near a limit an endpoint can fall on the
other side of it where the old answer did not, or the reverse.

Found by tests/kins-roundtrip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
grandixximo pushed a commit that referenced this pull request Nov 21, 2026
Motion hands the inverse the joints of the cycle before and takes a
joint a whole turn away from them as a step.  #4708 kept pumakins'
joints within a half turn of those by taking each to radians,
unwrapping there, and taking it back to degrees; scarakins and
three21kins did nothing of the kind.

Add a static nearestTurn() to each module, which moves an angle in
degrees by whole turns to within a half turn of the joint passed in,
and apply it as the joints are copied out:

- pumakins: in place of the round trip through radians.  The answers
  are the same, but for rounding and the pick at exactly half a turn,
  where either is right.
- scarakins: to joint 0, which came from the difference of two atan2()
  results and landed anywhere in (-360, 360).  Wherever the bearing
  crossed +-180 with the elbow bent, or joint 0 was past a half turn,
  joint 0 came back a turn away and joint 3 a turn the other way.
  Joint 1 comes from acos() and needs nothing.
- three21kins: to every joint.  It carries pumakins' solver; with the
  shoulder flag set the base could come back one or two turns off, and
  the wrist roll and twist a turn off past +-180.

pumakins and three21kins also set their branch flags by comparing a
joint with the angle the inverse's formula gives, through a radian
angleDiff() that wrapped with while loops.  They compare with
nearestTurn() instead, in degrees, and angleDiff() is gone.  The flags
are unchanged.

As with pumakins since #4708, motion's endpoint checks and
joint-interpolated moves now get the joint closest to the one queued
before, so near a limit a move the old answer accepted can be refused,
or the reverse.

tests/pumakins-unwrap becomes tests/kins-unwrap, one component and one
script with a directory per module, so runtests -j runs them side by
side.  Each walks the joints across +-180 the way motion calls the
kinematics and requires the joints that made each pose back: pumakins'
four walks unchanged, scarakins joint 0 with the elbow bent each way,
three21kins pumakins' walks.  Without the unwrap every walk fails, at
14 to 50 of its 50 poses; with it all hold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant