From a10b8132e85fb556f9bc1b5391fcac85a976c09b Mon Sep 17 00:00:00 2001 From: Ash-Pera Date: Fri, 20 Nov 2026 17:16:03 -0700 Subject: [PATCH] kinematics: keep puma, scara and three21 joints within a half turn 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 --- src/emc/kinematics/pumakins.c | 45 +++--- src/emc/kinematics/scarakins.c | 9 ++ src/emc/kinematics/three21kins.c | 37 +++-- tests/kins-unwrap/pumakins/checkresult | 1 + tests/kins-unwrap/pumakins/skip | 1 + tests/kins-unwrap/pumakins/test.sh | 1 + tests/kins-unwrap/pumakins/walks | 11 ++ tests/kins-unwrap/scarakins/checkresult | 1 + tests/kins-unwrap/scarakins/skip | 1 + tests/kins-unwrap/scarakins/test.sh | 1 + tests/kins-unwrap/scarakins/walks | 3 + tests/kins-unwrap/shared-checkresult | 7 + .../skip => kins-unwrap/shared-skip} | 0 tests/kins-unwrap/shared-test.sh | 20 +++ tests/kins-unwrap/three21kins/checkresult | 1 + tests/kins-unwrap/three21kins/skip | 1 + tests/kins-unwrap/three21kins/test.sh | 1 + tests/kins-unwrap/three21kins/walks | 5 + tests/kins-unwrap/walkcheck.c | 124 +++++++++++++++++ tests/pumakins-unwrap/checkresult | 2 - tests/pumakins-unwrap/test.sh | 5 - tests/pumakins-unwrap/unwrapcheck.c | 130 ------------------ tests/pumakins-unwrap/unwrapcheck.hal | 2 - 23 files changed, 224 insertions(+), 185 deletions(-) create mode 120000 tests/kins-unwrap/pumakins/checkresult create mode 120000 tests/kins-unwrap/pumakins/skip create mode 120000 tests/kins-unwrap/pumakins/test.sh create mode 100644 tests/kins-unwrap/pumakins/walks create mode 120000 tests/kins-unwrap/scarakins/checkresult create mode 120000 tests/kins-unwrap/scarakins/skip create mode 120000 tests/kins-unwrap/scarakins/test.sh create mode 100644 tests/kins-unwrap/scarakins/walks create mode 100755 tests/kins-unwrap/shared-checkresult rename tests/{pumakins-unwrap/skip => kins-unwrap/shared-skip} (100%) create mode 100755 tests/kins-unwrap/shared-test.sh create mode 120000 tests/kins-unwrap/three21kins/checkresult create mode 120000 tests/kins-unwrap/three21kins/skip create mode 120000 tests/kins-unwrap/three21kins/test.sh create mode 100644 tests/kins-unwrap/three21kins/walks create mode 100644 tests/kins-unwrap/walkcheck.c delete mode 100755 tests/pumakins-unwrap/checkresult delete mode 100755 tests/pumakins-unwrap/test.sh delete mode 100644 tests/pumakins-unwrap/unwrapcheck.c delete mode 100644 tests/pumakins-unwrap/unwrapcheck.hal diff --git a/src/emc/kinematics/pumakins.c b/src/emc/kinematics/pumakins.c index 1b14dab8520..4b7fb124b64 100644 --- a/src/emc/kinematics/pumakins.c +++ b/src/emc/kinematics/pumakins.c @@ -35,14 +35,10 @@ static const kins_param_desc puma_params[] = { }; enum { P_A2, P_A3, P_D3, P_D4, P_D6 }; -/* the difference of two angles, brought into (-pi, pi] so that a joint a - whole turn from the formula still matches it */ -static double angleDiff(double a, double b) +/* angle, in degrees, moved by whole turns to within a half turn of near */ +static double nearestTurn(double angle, double near) { - double d = a - b; - while (d > PM_PI) { d -= 2*PM_PI; } - while (d <= -PM_PI) { d += 2*PM_PI; } - return d; + return angle - 360.0*round((angle - near)/360.0); } /* The flange orientation for a joint set: the ISO 9787 mechanical interface @@ -170,16 +166,18 @@ static int puma_forward(const kins_params *p, kins_scratch *s, *iflags = 0; /* Set shoulder-up flag if necessary */ - if (fabs(angleDiff(joint[0]*PM_PI/180, atan2(hom.tran.y, hom.tran.x) - - atan2(PUMA_D3, -sqrt(sumSq)))) < FLAG_FUZZ) + if (fabs(nearestTurn((atan2(hom.tran.y, hom.tran.x) - + atan2(PUMA_D3, -sqrt(sumSq)))*180.0/PM_PI, joint[0]) - joint[0]) < + FLAG_FUZZ*180.0/PM_PI) { *iflags |= PUMA_SHOULDER_RIGHT; } /* Set elbow down flag if necessary */ - if (fabs(angleDiff(joint[2]*PM_PI/180, atan2(PUMA_A3, PUMA_D4) - + if (fabs(nearestTurn((atan2(PUMA_A3, PUMA_D4) - atan2(k, -sqrt(PUMA_A3 * PUMA_A3 + - PUMA_D4 * PUMA_D4 - k * k)))) < FLAG_FUZZ) + PUMA_D4 * PUMA_D4 - k * k)))*180.0/PM_PI, joint[2]) - joint[2]) < + FLAG_FUZZ*180.0/PM_PI) { *iflags |= PUMA_ELBOW_DOWN; } @@ -195,7 +193,8 @@ static int puma_forward(const kins_params *p, kins_scratch *s, /* if not singular set wrist flip flag if necessary */ else{ - if (! (fabs(angleDiff(joint[3]*PM_PI/180, atan2(t1, t2))) < FLAG_FUZZ)) + if (! (fabs(nearestTurn(atan2(t1, t2)*180.0/PM_PI, joint[3]) - joint[3]) < + FLAG_FUZZ*180.0/PM_PI)) { *iflags |= PUMA_WRIST_FLIP; } @@ -402,21 +401,13 @@ static int puma_inverse(const kins_params *p, kins_scratch *s, from a difference of two, so a joint crossing +-180 would jump a whole turn in one call, and th1, th2 and th3 can be a turn off anywhere. Bring each back within a half turn of the joint passed - in. */ - th1 = joint[0]*PM_PI/180 + angleDiff(th1, joint[0]*PM_PI/180); - th2 = joint[1]*PM_PI/180 + angleDiff(th2, joint[1]*PM_PI/180); - th3 = joint[2]*PM_PI/180 + angleDiff(th3, joint[2]*PM_PI/180); - th4 = joint[3]*PM_PI/180 + angleDiff(th4, joint[3]*PM_PI/180); - th5 = joint[4]*PM_PI/180 + angleDiff(th5, joint[4]*PM_PI/180); - th6 = joint[5]*PM_PI/180 + angleDiff(th6, joint[5]*PM_PI/180); - - /* copy out */ - joint[0] = th1*180/PM_PI; - joint[1] = th2*180/PM_PI; - joint[2] = th3*180/PM_PI; - joint[3] = th4*180/PM_PI; - joint[4] = th5*180/PM_PI; - joint[5] = th6*180/PM_PI; + in, in degrees as it is copied out. */ + joint[0] = nearestTurn(th1*180.0/PM_PI, joint[0]); + joint[1] = nearestTurn(th2*180.0/PM_PI, joint[1]); + joint[2] = nearestTurn(th3*180.0/PM_PI, joint[2]); + joint[3] = nearestTurn(th4*180.0/PM_PI, joint[3]); + joint[4] = nearestTurn(th5*180.0/PM_PI, joint[4]); + joint[5] = nearestTurn(th6*180.0/PM_PI, joint[5]); return 0; } diff --git a/src/emc/kinematics/scarakins.c b/src/emc/kinematics/scarakins.c index a3340a968c5..d0e5b556d21 100644 --- a/src/emc/kinematics/scarakins.c +++ b/src/emc/kinematics/scarakins.c @@ -77,6 +77,12 @@ static const kins_param_desc scara_params[] = { }; enum { P_D1, P_D2, P_D3, P_D4, P_D5, P_D6 }; +/* angle, in degrees, moved by whole turns to within a half turn of near */ +static double nearestTurn(double angle, double near) +{ + return angle - 360.0*round((angle - near)/360.0); +} + /* joint[0], joint[1] and joint[3] are in degrees and joint[2] is in length units */ static int scara_forward(const kins_params *p, kins_scratch *s, const double * joint, @@ -184,6 +190,9 @@ static int scara_inverse(const kins_params *p, kins_scratch *s, q0 = q0 * (180 / PM_PI); q1 = q1 * (180 / PM_PI); + /* keep q0 within a half turn of the joint passed in, as pumakins does */ + q0 = nearestTurn(q0, joint[0]); + joint[0] = q0; joint[1] = q1; joint[2] = D1 + D3 - D5 - z; diff --git a/src/emc/kinematics/three21kins.c b/src/emc/kinematics/three21kins.c index a22ed430338..6be4f66f13d 100644 --- a/src/emc/kinematics/three21kins.c +++ b/src/emc/kinematics/three21kins.c @@ -41,14 +41,10 @@ static const kins_param_desc three21_params[] = { }; enum { P_A1, P_A2, P_A3, P_D1, P_D2, P_D3, P_D4, P_D6 }; -/* the difference of two angles, brought into (-pi, pi] so that a joint a - whole turn from the formula still matches it */ -static double angleDiff(double a, double b) +/* angle, in degrees, moved by whole turns to within a half turn of near */ +static double nearestTurn(double angle, double near) { - double d = a - b; - while (d > PM_PI) { d -= 2*PM_PI; } - while (d <= -PM_PI) { d += 2*PM_PI; } - return d; + return angle - 360.0*round((angle - near)/360.0); } static int three21_forward(const kins_params *p, kins_scratch *s, @@ -153,8 +149,9 @@ static int three21_forward(const kins_params *p, kins_scratch *s, *iflags = 0; /* set shoulder flag */ - if (fabs(angleDiff(joint[0]*PM_PI/180, atan2(hom.tran.y, hom.tran.x) - - atan2(d23, -sqrt(sumSq)))) < FLAG_FUZZ) + if (fabs(nearestTurn((atan2(hom.tran.y, hom.tran.x) - + atan2(d23, -sqrt(sumSq)))*180.0/PM_PI, joint[0]) - joint[0]) < + FLAG_FUZZ*180.0/PM_PI) { *iflags |= THREE21_SHOULDER_RIGHT; } @@ -164,8 +161,9 @@ static int three21_forward(const kins_params *p, kins_scratch *s, if (discr < 0.0) { discr = 0.0; } - if (fabs(angleDiff(joint[2]*PM_PI/180, atan2(a3, d4) - - atan2(k, -sqrt(discr)))) < FLAG_FUZZ) + if (fabs(nearestTurn((atan2(a3, d4) - + atan2(k, -sqrt(discr)))*180.0/PM_PI, joint[2]) - joint[2]) < + FLAG_FUZZ*180.0/PM_PI) { *iflags |= THREE21_ELBOW_DOWN; } @@ -179,7 +177,8 @@ static int three21_forward(const kins_params *p, kins_scratch *s, } else { - if (! (fabs(angleDiff(joint[3]*PM_PI/180, atan2(t1, t2))) < FLAG_FUZZ)) + if (! (fabs(nearestTurn(atan2(t1, t2)*180.0/PM_PI, joint[3]) - joint[3]) < + FLAG_FUZZ*180.0/PM_PI)) { *iflags |= THREE21_WRIST_FLIP; } @@ -370,13 +369,13 @@ static int three21_inverse(const kins_params *p, kins_scratch *s, th6 = th6 + PM_PI; } - /* copy out */ - joint[0] = th1*180/PM_PI; - joint[1] = th2*180/PM_PI; - joint[2] = th3*180/PM_PI; - joint[3] = th4*180/PM_PI; - joint[4] = th5*180/PM_PI; - joint[5] = th6*180/PM_PI; + /* copy out in degrees, each joint the turn nearest the one passed in */ + joint[0] = nearestTurn(th1*180.0/PM_PI, joint[0]); + joint[1] = nearestTurn(th2*180.0/PM_PI, joint[1]); + joint[2] = nearestTurn(th3*180.0/PM_PI, joint[2]); + joint[3] = nearestTurn(th4*180.0/PM_PI, joint[3]); + joint[4] = nearestTurn(th5*180.0/PM_PI, joint[4]); + joint[5] = nearestTurn(th6*180.0/PM_PI, joint[5]); return 0; } diff --git a/tests/kins-unwrap/pumakins/checkresult b/tests/kins-unwrap/pumakins/checkresult new file mode 120000 index 00000000000..c4fbef14529 --- /dev/null +++ b/tests/kins-unwrap/pumakins/checkresult @@ -0,0 +1 @@ +../shared-checkresult \ No newline at end of file diff --git a/tests/kins-unwrap/pumakins/skip b/tests/kins-unwrap/pumakins/skip new file mode 120000 index 00000000000..27cf8a6dbbe --- /dev/null +++ b/tests/kins-unwrap/pumakins/skip @@ -0,0 +1 @@ +../shared-skip \ No newline at end of file diff --git a/tests/kins-unwrap/pumakins/test.sh b/tests/kins-unwrap/pumakins/test.sh new file mode 120000 index 00000000000..0b01664e62e --- /dev/null +++ b/tests/kins-unwrap/pumakins/test.sh @@ -0,0 +1 @@ +../shared-test.sh \ No newline at end of file diff --git a/tests/kins-unwrap/pumakins/walks b/tests/kins-unwrap/pumakins/walks new file mode 100644 index 00000000000..2d8a217eb5c --- /dev/null +++ b/tests/kins-unwrap/pumakins/walks @@ -0,0 +1,11 @@ +# The walks pumakins-unwrap took for #4585 and #4708. The wrist pitch, +# joint 5, is left out: at +-180 the wrist is folded back on itself, a +# singularity where joints 4 and 6 are not determined. +# joints 4 and 6 together from 150 and 140 +pumakins start=20,-20,100,150,35,140 mask=40 +# the waist, joint 1, from 150 +pumakins start=150,-20,100,30,35,40 mask=1 +# the shoulder, joint 2, from 150 +pumakins start=20,150,100,30,35,40 mask=2 +# the elbow, joint 3, from 150 +pumakins start=20,-20,150,30,35,40 mask=4 diff --git a/tests/kins-unwrap/scarakins/checkresult b/tests/kins-unwrap/scarakins/checkresult new file mode 120000 index 00000000000..c4fbef14529 --- /dev/null +++ b/tests/kins-unwrap/scarakins/checkresult @@ -0,0 +1 @@ +../shared-checkresult \ No newline at end of file diff --git a/tests/kins-unwrap/scarakins/skip b/tests/kins-unwrap/scarakins/skip new file mode 120000 index 00000000000..27cf8a6dbbe --- /dev/null +++ b/tests/kins-unwrap/scarakins/skip @@ -0,0 +1 @@ +../shared-skip \ No newline at end of file diff --git a/tests/kins-unwrap/scarakins/test.sh b/tests/kins-unwrap/scarakins/test.sh new file mode 120000 index 00000000000..0b01664e62e --- /dev/null +++ b/tests/kins-unwrap/scarakins/test.sh @@ -0,0 +1 @@ +../shared-test.sh \ No newline at end of file diff --git a/tests/kins-unwrap/scarakins/walks b/tests/kins-unwrap/scarakins/walks new file mode 100644 index 00000000000..d5f3ec4fe0f --- /dev/null +++ b/tests/kins-unwrap/scarakins/walks @@ -0,0 +1,3 @@ +# joint 0 across 180 with the elbow bent each way +scarakins start=150,30,0,0,0,0 mask=1 +scarakins start=150,-30,0,0,0,0 mask=1 diff --git a/tests/kins-unwrap/shared-checkresult b/tests/kins-unwrap/shared-checkresult new file mode 100755 index 00000000000..30519ac3a21 --- /dev/null +++ b/tests/kins-unwrap/shared-checkresult @@ -0,0 +1,7 @@ +#!/bin/sh +# every walk in walks ran and held +n=$(grep -cv '^[[:space:]]*\(#\|$\)' "$(dirname "$1")/walks") +[ "$n" -ge 1 ] \ + && [ "$(grep -c '^=== ' "$1")" = "$n" ] \ + && [ "$(grep -c 'joints continuous' "$1")" = "$n" ] \ + && ! grep -q "FAIL" "$1" diff --git a/tests/pumakins-unwrap/skip b/tests/kins-unwrap/shared-skip similarity index 100% rename from tests/pumakins-unwrap/skip rename to tests/kins-unwrap/shared-skip diff --git a/tests/kins-unwrap/shared-test.sh b/tests/kins-unwrap/shared-test.sh new file mode 100755 index 00000000000..7d066e78039 --- /dev/null +++ b/tests/kins-unwrap/shared-test.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Walk kinematics joints across +-180 the way motion calls them. Each +# line of walks is a module and the walkcheck arguments for one walk. +# One directory per module, so runtests -j runs them side by side. +set -e + +[ -r walks ] || { echo "Error: file 'walks' does not exist"; exit 1; } + +halcompile --install ../walkcheck.c >/dev/null + +# every walk runs, so one failure does not hide the next +status=0 +while read -r kins args; do + case "$kins" in ''|'#'*) continue ;; esac + printf 'loadrt %s\nloadrt walkcheck %s\n' "$kins" "$args" > walk.hal + echo "=== $kins $args" + halrun -f walk.hal < /dev/null || status=1 +done < walks +rm -f walk.hal +exit $status diff --git a/tests/kins-unwrap/three21kins/checkresult b/tests/kins-unwrap/three21kins/checkresult new file mode 120000 index 00000000000..c4fbef14529 --- /dev/null +++ b/tests/kins-unwrap/three21kins/checkresult @@ -0,0 +1 @@ +../shared-checkresult \ No newline at end of file diff --git a/tests/kins-unwrap/three21kins/skip b/tests/kins-unwrap/three21kins/skip new file mode 120000 index 00000000000..27cf8a6dbbe --- /dev/null +++ b/tests/kins-unwrap/three21kins/skip @@ -0,0 +1 @@ +../shared-skip \ No newline at end of file diff --git a/tests/kins-unwrap/three21kins/test.sh b/tests/kins-unwrap/three21kins/test.sh new file mode 120000 index 00000000000..0b01664e62e --- /dev/null +++ b/tests/kins-unwrap/three21kins/test.sh @@ -0,0 +1 @@ +../shared-test.sh \ No newline at end of file diff --git a/tests/kins-unwrap/three21kins/walks b/tests/kins-unwrap/three21kins/walks new file mode 100644 index 00000000000..8bb37a0b924 --- /dev/null +++ b/tests/kins-unwrap/three21kins/walks @@ -0,0 +1,5 @@ +# pumakins' walks: three21kins carries its solver +three21kins start=20,-20,100,150,35,140 mask=40 +three21kins start=150,-20,100,30,35,40 mask=1 +three21kins start=20,150,100,30,35,40 mask=2 +three21kins start=20,-20,150,30,35,40 mask=4 diff --git a/tests/kins-unwrap/walkcheck.c b/tests/kins-unwrap/walkcheck.c new file mode 100644 index 00000000000..603b66ac0e3 --- /dev/null +++ b/tests/kins-unwrap/walkcheck.c @@ -0,0 +1,124 @@ +/* Check that a kinematics module keeps its joints continuous (#4585). + * + * Loaded after the module under test, so kinematicsForward() and + * kinematicsInverse() resolve to it. A failed check fails the load, and + * a failed load fails the test. + * + * An inverse that takes its joints from atan2(), or from a difference of + * two, lands in (-180, 180] or (-360, 360], so a joint crossing a half + * turn comes back a whole turn away in one call. Walk the joints in mask + * 60 degrees up from start, across +-180, and back down, as motion does: + * take the pose of each step from the forward and hand the inverse the + * joints of the step before. The inverse has to return the joints that + * made the pose, not ones a turn away. + * + * Author: LinuxCNC + * License: GPL Version 2 + * System: Linux + * + * Copyright (c) 2026 All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("kinematics joint unwrap checker"); + +static int start[6]; +RTAPI_MP_ARRAY_INT(start, 6, "joints to start the walk from"); + +static int mask = 1; +RTAPI_MP_INT(mask, "joints to walk, bit 0 for joint 0"); + +/* degrees the inverse may drift from the joints that made the pose; the + round trip is exact, this only covers floating point noise */ +#define TOL 1e-6 +#define STEP 2.5 + +static int comp_id = -1; +static int failures; +static int poses; + +static void step(double *prev, const double *j) +{ + EmcPose world; + double out[6]; + KINEMATICS_FORWARD_FLAGS ff = 0; + KINEMATICS_INVERSE_FLAGS inf = 0; + double worst = 0.0; + int i; + + poses++; + if (kinematicsForward(j, &world, &ff, &inf)) { + rtapi_print_msg(RTAPI_MSG_ERR, "walkcheck: FAIL forward at %g %g %g %g %g %g\n", + j[0], j[1], j[2], j[3], j[4], j[5]); + failures++; + return; + } + memcpy(out, prev, sizeof(out)); + if (kinematicsInverse(&world, out, &inf, &ff)) { + rtapi_print_msg(RTAPI_MSG_ERR, "walkcheck: FAIL inverse at %g %g %g %g %g %g\n", + j[0], j[1], j[2], j[3], j[4], j[5]); + failures++; + return; + } + for (i = 0; i < 6; i++) { + if (fabs(out[i] - j[i]) > worst) { worst = fabs(out[i] - j[i]); } + } + if (worst > TOL) { + rtapi_print_msg(RTAPI_MSG_ERR, + "walkcheck: FAIL at %g %g %g %g %g %g: got %g %g %g %g %g %g," + " worst joint error %g\n", + j[0], j[1], j[2], j[3], j[4], j[5], + out[0], out[1], out[2], out[3], out[4], out[5], worst); + failures++; + } + memcpy(prev, out, sizeof(out)); +} + +static void walk_to(double *j, double *prev, int n) +{ + int i; + + for (i = 0; i < 6; i++) { + if (mask & (1 << i)) { j[i] = start[i] + n * STEP; } + } + step(prev, j); +} + +int rtapi_app_main(void) +{ + double j[6], prev[6]; + int i, n; + + if (mask <= 0 || mask >= (1 << 6)) { + rtapi_print_msg(RTAPI_MSG_ERR, "walkcheck: mask %d must pick from joints 0 to 5\n", mask); + return -EINVAL; + } + + comp_id = hal_init("walkcheck"); + if (comp_id < 0) { return comp_id; } + + for (i = 0; i < 6; i++) { j[i] = prev[i] = start[i]; } + for (n = 0; n <= 24; n++) { walk_to(j, prev, n); } + for (n = 24; n >= 0; n--) { walk_to(j, prev, n); } + + if (failures) { + rtapi_print_msg(RTAPI_MSG_ERR, "walkcheck: %d of %d pose(s) failed\n", + failures, poses); + hal_exit(comp_id); + return -ERANGE; + } + rtapi_print("walkcheck: joints continuous over %d pose(s)\n", poses); + hal_ready(comp_id); + return 0; +} + +void rtapi_app_exit(void) { hal_exit(comp_id); } diff --git a/tests/pumakins-unwrap/checkresult b/tests/pumakins-unwrap/checkresult deleted file mode 100755 index a5c05ae9144..00000000000 --- a/tests/pumakins-unwrap/checkresult +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -grep -q "joints continuous" "$1" && ! grep -q "FAIL" "$1" diff --git a/tests/pumakins-unwrap/test.sh b/tests/pumakins-unwrap/test.sh deleted file mode 100755 index 4410e5c47d0..00000000000 --- a/tests/pumakins-unwrap/test.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -halcompile --install unwrapcheck.c >/dev/null -halrun -f unwrapcheck.hal diff --git a/tests/pumakins-unwrap/unwrapcheck.c b/tests/pumakins-unwrap/unwrapcheck.c deleted file mode 100644 index 4f003ff0301..00000000000 --- a/tests/pumakins-unwrap/unwrapcheck.c +++ /dev/null @@ -1,130 +0,0 @@ -/* Check that pumakins keeps its joints continuous (issue #4585). - * - * Loaded after pumakins, so kinematicsForward() and kinematicsInverse() - * resolve to it. A failed check fails the load, and a failed load fails - * the test. - * - * The inverse took its joints from atan2(), or from a difference of two, - * which lands in (-180, 180] or (-360, 360], so a joint crossing a half - * turn came back a whole turn away in one call. Walk each joint through - * +-180 in each direction, as motion does: take the pose of each step from - * the forward and hand the inverse the joints of the step before. The - * inverse has to return the joints that made the pose, not ones a turn - * away. The wrist pitch, joint 5, is left out: at +-180 the wrist is - * folded back on itself, a singularity where joints 4 and 6 are not - * determined. - * - * Author: LinuxCNC - * License: GPL Version 2 - * System: Linux - * - * Copyright (c) 2026 All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -MODULE_LICENSE("GPL"); -MODULE_DESCRIPTION("pumakins joint unwrap checker"); - -/* degrees the inverse may drift from the joints that made the pose; the - round trip is exact, this only covers floating point noise */ -#define TOL 1e-6 -#define STEP 2.5 - -static int comp_id = -1; -static int failures; -static int poses; - -static void step(double *prev, const double *j) -{ - EmcPose world; - double out[6]; - KINEMATICS_FORWARD_FLAGS ff = 0; - KINEMATICS_INVERSE_FLAGS inf = 0; - double worst = 0; - int i; - - poses++; - if (kinematicsForward(j, &world, &ff, &inf)) { - rtapi_print_msg(RTAPI_MSG_ERR, "unwrapcheck: FAIL forward at %g %g %g %g %g %g\n", - j[0], j[1], j[2], j[3], j[4], j[5]); - failures++; - return; - } - memcpy(out, prev, sizeof(out)); - if (kinematicsInverse(&world, out, &inf, &ff)) { - rtapi_print_msg(RTAPI_MSG_ERR, "unwrapcheck: FAIL inverse at %g %g %g %g %g %g\n", - j[0], j[1], j[2], j[3], j[4], j[5]); - failures++; - return; - } - for (i = 0; i < 6; i++) { - if (fabs(out[i] - j[i]) > worst) { worst = fabs(out[i] - j[i]); } - } - if (worst > TOL) { - rtapi_print_msg(RTAPI_MSG_ERR, - "unwrapcheck: FAIL at %g %g %g %g %g %g: got %g %g %g %g %g %g," - " worst joint error %g\n", - j[0], j[1], j[2], j[3], j[4], j[5], - out[0], out[1], out[2], out[3], out[4], out[5], worst); - failures++; - } - memcpy(prev, out, sizeof(out)); -} - -/* Walk the joints in mask by 60 degrees from the start, past +180, and - back down again, the others held. */ -static void walk(const double *start, unsigned mask) -{ - double j[6], prev[6]; - int n, i; - - memcpy(j, start, sizeof(j)); - memcpy(prev, j, sizeof(prev)); - for (n = 0; n <= 24; n++) { - for (i = 0; i < 6; i++) { - if (mask & (1u << i)) { j[i] = start[i] + n * STEP; } - } - step(prev, j); - } - for (n = 24; n >= 0; n--) { - for (i = 0; i < 6; i++) { - if (mask & (1u << i)) { j[i] = start[i] + n * STEP; } - } - step(prev, j); - } -} - -int rtapi_app_main(void) -{ - comp_id = hal_init("unwrapcheck"); - if (comp_id < 0) { return comp_id; } - - /* joints 4 and 6 together from 150 and 140 */ - walk((const double[6]){ 20.0, -20.0, 100.0, 150.0, 35.0, 140.0 }, 0x28); - /* the waist, joint 1, from 150 */ - walk((const double[6]){ 150.0, -20.0, 100.0, 30.0, 35.0, 40.0 }, 0x01); - /* the shoulder, joint 2, from 150 */ - walk((const double[6]){ 20.0, 150.0, 100.0, 30.0, 35.0, 40.0 }, 0x02); - /* the elbow, joint 3, from 150 */ - walk((const double[6]){ 20.0, -20.0, 150.0, 30.0, 35.0, 40.0 }, 0x04); - - if (failures) { - rtapi_print_msg(RTAPI_MSG_ERR, "unwrapcheck: %d of %d pose(s) failed\n", - failures, poses); - hal_exit(comp_id); - return -ERANGE; - } - rtapi_print("unwrapcheck: joints continuous over %d pose(s)\n", poses); - hal_ready(comp_id); - return 0; -} - -void rtapi_app_exit(void) { hal_exit(comp_id); } diff --git a/tests/pumakins-unwrap/unwrapcheck.hal b/tests/pumakins-unwrap/unwrapcheck.hal deleted file mode 100644 index 76a3ff2d3ba..00000000000 --- a/tests/pumakins-unwrap/unwrapcheck.hal +++ /dev/null @@ -1,2 +0,0 @@ -loadrt pumakins -loadrt unwrapcheck