diff --git a/docs/src/config/ini-config.adoc b/docs/src/config/ini-config.adoc index e8aabf083d6..2cb57345001 100644 --- a/docs/src/config/ini-config.adoc +++ b/docs/src/config/ini-config.adoc @@ -1204,9 +1204,10 @@ These settings are verified at startup when the trivkins kinematics modules is s The `[JOINT_N]MIN_LIMIT`/`MAX_LIMIT` settings are enforced while jogging in joint mode prior to homing. After homing, `[AXIS_L]MIN_LIMIT`/`MAX_LIMIT` coordinate limits are used as constraints for axis (coordinate letter) jogging and by the trajectory planning used for G-code moves (programs and MDI commands). -The trajectory planner works in Cartesian space (XYZABCUVW) and has no information about the motion of joints implemented by *any* kinematics module. -It is possible for joint limit violations to occur for G-code that obeys trajectory planning position limits when non identity kinematics are used. -The motion module always detects joint position limit violations and faults if they occur during the execution of G-code commands. +The trajectory planner works in Cartesian space (XYZABCUVW). +On a kinematics that is not the identity, every move of a program or an MDI command is also followed through the kinematics module ahead of motion, and a move that would take a joint past `MIN_LIMIT` or `MAX_LIMIT` anywhere along it is refused before it runs, its line failing with the joint and the limit; see the <> chapter, INI file limit settings. +A kinematics module that can only be evaluated in realtime is checked at the ends of each move. +The motion module detects a joint position limit violation during the execution of G-code commands and faults, for what cannot be seen ahead of it. See also related https://github.com/LinuxCNC/linuxcnc/issues/97[GitHub issue #97]. ==== diff --git a/docs/src/motion/kinematics-conventions.adoc b/docs/src/motion/kinematics-conventions.adoc index dd109f87527..3ce73233498 100644 --- a/docs/src/motion/kinematics-conventions.adoc +++ b/docs/src/motion/kinematics-conventions.adoc @@ -337,9 +337,11 @@ every block. It is the inverse of the tool frame: not where the tool points for these joints, but which joints point it there. It has more than one answer. A five-axis machine reaches a given tool axis two -ways, one with the secondary rotary positive and one with it negative, and -which of the two is wanted depends on the joint limits and on what the operator -asked for, shortest move or one direction of rotation only. So the module +ways, which differ in the sign of the first rotary met going from the tool to +the work: the secondary rotary of two in the head, the one carrying the other +of two in the table, the head rotary of one of each. Which of the two is wanted +depends on the joint limits and on what the operator asked for, shortest move +or one direction of rotation only. So the module reports every set of joint values that reaches the orientation and stops there. It does not apply the joint limits and it does not rank the answers, because neither is geometry: a module that picked for the caller would be picking with diff --git a/docs/src/motion/switchkins.adoc b/docs/src/motion/switchkins.adoc index c6e7aaa8f43..661870fd27d 100644 --- a/docs/src/motion/switchkins.adoc +++ b/docs/src/motion/switchkins.adoc @@ -316,6 +316,21 @@ the box is a restriction inside it. A module that declares no kinstype flags keeps the box on the world of the kinstype in force, as before. +The travel is followed along each move, not only at its end. Ahead +of motion every segment is sampled through the module, on the +kinstype and the tool offset the program is under, and a move that +would take a homed joint past its `MIN_LIMIT` or `MAX_LIMIT` anywhere +along it is refused before it is sent: a turn of a tilted head under +the tool centre point that swings the carriage past its travel and +back, with both ends of the move inside it, fails its line with the +joint, the limit and where along the move it would be passed, and +nothing of it runs. Between samples the joint is followed on the +cubic through their positions and rates, and a peak that comes near +the limit is read through the module itself; only a point the module +puts past the limit refuses a move. A module that can only be +evaluated in realtime is checked at the ends of each move; motion's +own check of the joints while they move stays behind both. + The velocity and acceleration limits, `MAX_VELOCITY` and `MAX_ACCELERATION`, bound the coordinate letter in the world of the kinstype in force. What the joints can follow is bound separately: diff --git a/include/nml_intf/canon.hh b/include/nml_intf/canon.hh index a89772c224f..cb38ceda264 100644 --- a/include/nml_intf/canon.hh +++ b/include/nml_intf/canon.hh @@ -282,6 +282,12 @@ extern void CANON_UPDATE_END_POINT(double x, double y, double z, /* Called from emctask to update the canon position during skipping through programs started with start-from-line > 0. */ +extern int CANON_MOVE_REFUSED(char *message, size_t messagesize); +/* Called from emctask after the interpreter has read or executed a line: + 1 and the reason in message where canon refused a move since the last + call, because a joint would leave its travel along it, 0 otherwise. + The refused move and every move after it are dropped until then. */ + extern void USE_LENGTH_UNITS(CANON_UNITS u); /* Use the specified units for length. Conceptually, the units must diff --git a/src/emc/motion_planning/kinslimits.cc b/src/emc/motion_planning/kinslimits.cc index 04ca010defc..31731fb22c4 100644 --- a/src/emc/motion_planning/kinslimits.cc +++ b/src/emc/motion_planning/kinslimits.cc @@ -92,11 +92,13 @@ static void usage(const char *argv0) "usage: %s --module NAME --joints N --coords LETTERS\n" " --start x,y,z,a,b,c,u,v,w --end x,y,z,a,b,c,u,v,w\n" " --vel v0,v1,... --acc a0,a1,... [--jerk j0,j1,...]\n" + " [--min m0,m1,... --max m0,m1,...]\n" " [--samples N] [--singularity COND]\n" "\n" "Prints the Jacobian and the world-space caps the joint limits imply\n" - "for a straight move from --start to --end. Requires a running HAL\n" - "instance with the kinematics module loaded.\n", argv0); + "for a straight move from --start to --end, and with --min and --max\n" + "the first place along it a joint leaves its travel. Requires a\n" + "running HAL instance with the kinematics module loaded.\n", argv0); } int main(int argc, char **argv) @@ -106,7 +108,7 @@ int main(int argc, char **argv) int num_joints = 0; int samples = 11; double singularity = 100.0; - std::vector start_v, end_v, vel_v, acc_v, jerk_v; + std::vector start_v, end_v, vel_v, acc_v, jerk_v, min_v, max_v; for (int i = 1; i < argc; i++) { const char *a = argv[i]; @@ -121,6 +123,8 @@ int main(int argc, char **argv) else if (!strcmp(a, "--vel") && next) { vel_v = parse_list(next); i++; } else if (!strcmp(a, "--acc") && next) { acc_v = parse_list(next); i++; } else if (!strcmp(a, "--jerk") && next) { jerk_v = parse_list(next); i++; } + else if (!strcmp(a, "--min") && next) { min_v = parse_list(next); i++; } + else if (!strcmp(a, "--max") && next) { max_v = parse_list(next); i++; } else { usage(argv[0]); return 1; } } @@ -275,6 +279,8 @@ int main(int argc, char **argv) for (int j = 0; j < KINEMATICS_USER_MAX_JOINTS; j++) { lim.vel[j] = j < num_joints ? vel_v[j] : SEGMENT_CAP_NONE; lim.acc[j] = j < num_joints ? acc_v[j] : SEGMENT_CAP_NONE; + lim.min[j] = j < (int)min_v.size() ? min_v[j] : -HUGE_VAL; + lim.max[j] = j < (int)max_v.size() ? max_v[j] : HUGE_VAL; } auto pose_at = [](double f, EmcPose *p, void *arg) { const EmcPose *se = (const EmcPose *)arg; @@ -285,6 +291,13 @@ int main(int argc, char **argv) if (segmentCap(ctx, &lim, target, samples, pose_at, &line, joints, &cap) == 0) { printf("canon's cap : vel %.3f (joint %d at s=%.3f), acc %.1f (joint %d), %d of %d samples unanswered\n", cap.vel, cap.vel_joint, cap.vel_at, cap.acc, cap.acc_joint, cap.unanswered, cap.samples); + if (cap.travel_joint >= 0) { + printf("travel : joint %d past its %s at s=%.3f, at %.6f\n", + cap.travel_joint, cap.travel_side > 0 ? "MAX_LIMIT" : "MIN_LIMIT", + cap.travel_at, cap.travel_pos); + } else if (!min_v.empty() || !max_v.empty()) { + printf("travel : every joint inside it\n"); + } } else { printf("canon's cap : none, no sample could be evaluated\n"); } diff --git a/src/emc/motion_planning/segment_cap.cc b/src/emc/motion_planning/segment_cap.cc index ec4cf00faf0..761669e68c3 100644 --- a/src/emc/motion_planning/segment_cap.cc +++ b/src/emc/motion_planning/segment_cap.cc @@ -1,7 +1,8 @@ /******************************************************************** * Description: segment_cap.cc * The velocity and acceleration cap a segment gets from the joint - * limits through the kinematics module's Jacobian. + * limits through the kinematics module's Jacobian, and the first + * place along it a joint would leave its travel. * * Author: LinuxCNC * License: GPL Version 2 @@ -15,6 +16,13 @@ namespace motion_planning { +/* at each sample: the joints, the rate of every joint per unit of path + parameter, the path parameter, and whether the module answered there */ +static double q[SEGMENT_CAP_MAX_SAMPLES][KINEMATICS_USER_MAX_JOINTS]; +static double g[SEGMENT_CAP_MAX_SAMPLES][KINEMATICS_USER_MAX_JOINTS]; +static double s[SEGMENT_CAP_MAX_SAMPLES]; +static bool ok[SEGMENT_CAP_MAX_SAMPLES]; + static double pose_axis(const EmcPose &p, int ax) { switch (ax) { @@ -30,22 +38,268 @@ static double pose_axis(const EmcPose &p, int ax) } } +/* The joints at fraction f of a segment sampled at K points, the inverse + seeded from what joints holds, and the rate of each there per unit of + path parameter: the module's Jacobian along the tangent, taken by a + central difference of the geometry, exact for a line and a small + fraction of a sample step for an arc. False where the module cannot + answer. */ +static bool sample_at(KinematicsUserContext *ctx, double length, int K, + SegmentPoseFn pose_at, void *arg, int njoints, + double f, double *joints, double *rate) +{ + double df = 1.0 / (8.0 * (K - 1)); + double fp = f + df > 1.0 ? 1.0 : f + df; + double fm = f - df < 0.0 ? 0.0 : f - df; + EmcPose p, pp, pm; + double t[AXIS_COUNT]; + double J[KINEMATICS_USER_MAX_JOINTS][AXIS_COUNT]; + int j, a; + + pose_at(f, &p, arg); + pose_at(fp, &pp, arg); + pose_at(fm, &pm, arg); + for (a = 0; a < AXIS_COUNT; a++) { + t[a] = (pose_axis(pp, a) - pose_axis(pm, a)) / ((fp - fm) * length); + } + if (kinematicsUserInverse(ctx, &p, joints) != 0 + || kinematicsUserJacobianAt(ctx, joints, &p, J) != 0) { + return false; + } + for (j = 0; j < njoints; j++) { + rate[j] = 0.0; + for (a = 0; a < AXIS_COUNT; a++) { rate[j] += J[j][a] * t[a]; } + } + return true; +} + +//---------------------------------------------------------------------- +// The travel. Every joint is followed from sample to sample against its +// MIN_LIMIT and MAX_LIMIT, the samples themselves and, between two, the +// cubic through their positions and rates, which is where the joint goes +// between them as long as the samples are close enough to see its turns. +// The cubic only says where to look: a joint is reported past a limit +// where the inverse puts it there, never on the cubic's word. +//---------------------------------------------------------------------- + +/* a hair past a limit is the inverse rounding, not travel */ +static const double TRAVEL_HAIR = 1e-6; +/* the share of its bulge past both ends the cubic may be out by at its + peak; a peak that close to the limit is read through the inverse */ +static const double TRAVEL_DOUBT = 0.05; +/* how deep a stretch is split at its peaks, and how many points beyond + the samples a segment may be read at in all */ +enum { TRAVEL_DEPTH = 6, TRAVEL_READS = 32 }; + +enum { WATCH_MAX = 1, WATCH_MIN = 2 }; +enum { TRAVEL_CLEAR, TRAVEL_CROSSED, TRAVEL_UNSURE }; + +/* a point the joints are known at */ +struct TravelPoint { + double s; + double q[KINEMATICS_USER_MAX_JOINTS]; + double g[KINEMATICS_USER_MAX_JOINTS]; +}; + +static void travel_load(TravelPoint *p, int k, int njoints) +{ + p->s = s[k]; + for (int j = 0; j < njoints; j++) { + p->q[j] = q[k][j]; + p->g[j] = g[k][j]; + } +} + +/* whether some joint moves between two points further than its rates at + them account for: the inverse has changed branch, or the joint swings + through more between the two than either shows */ +static bool travel_jumped(const TravelPoint &a, const TravelPoint &b, int njoints) +{ + double ds = b.s - a.s; + + for (int j = 0; j < njoints; j++) { + double moved = b.q[j] - a.q[j]; + double trapezoid = 0.5 * (a.g[j] + b.g[j]) * ds; + double rate = fmax(fabs(a.g[j]), fabs(b.g[j])) * ds; + if (fabs(moved - trapezoid) > rate + TRAVEL_HAIR) { return true; } + } + return false; +} + +/* whether a followed joint is past its travel at a point, and if so the + first one, into out */ +static bool travel_past(const TravelPoint &p, const SegmentCapLimits *lim, + const int *watch, int njoints, double length, SegmentCap *out) +{ + for (int j = 0; j < njoints; j++) { + int side = 0; + if ((watch[j] & WATCH_MAX) && p.q[j] > lim->max[j] + TRAVEL_HAIR) { side = 1; } + if ((watch[j] & WATCH_MIN) && p.q[j] < lim->min[j] - TRAVEL_HAIR) { side = -1; } + if (side) { + out->travel_joint = j; + out->travel_side = side; + out->travel_at = p.s / length; + out->travel_pos = p.q[j]; + return true; + } + } + return false; +} + +/* The peak toward one side of the cubic through two points, the joint at + qa and qb, its rates there scaled to the stretch ma and mb: where it is, + u inside (0, 1), its value, and how far it bulges past both ends. False + where the cubic has no peak inside the stretch on that side. */ +static bool travel_peak(double qa, double ma, double qb, double mb, int side, + double *u, double *peak, double *bulge) +{ + /* p(t) = qa + ma t + c2 t^2 + c3 t^3, p'(t) = 3 c3 t^2 + 2 c2 t + ma */ + double c2 = 3.0 * (qb - qa) - 2.0 * ma - mb; + double c3 = 2.0 * (qa - qb) + ma + mb; + double roots[2]; + int i, n = 0; + bool found = false; + + if (c3 == 0.0) { + if (c2 != 0.0) { roots[n++] = -ma / (2.0 * c2); } + } else { + double disc = c2 * c2 - 3.0 * c3 * ma; + if (disc >= 0.0) { + /* the pair that keeps its digits */ + double r = c2 >= 0.0 ? -(c2 + sqrt(disc)) : -(c2 - sqrt(disc)); + roots[n++] = r / (3.0 * c3); + if (r != 0.0) { roots[n++] = ma / r; } + } + } + for (i = 0; i < n; i++) { + double t = roots[i], v; + if (!(t > 0.0 && t < 1.0)) { continue; } + v = qa + t * (ma + t * (c2 + t * c3)); + if (!found || side * (v - *peak) > 0.0) { + *u = t; + *peak = v; + found = true; + } + } + if (!found) { return false; } + *bulge = side * (*peak - (side > 0 ? fmax(qa, qb) : fmin(qa, qb))); + return *bulge > 0.0; +} + +/* What lies between two points: where the cubic between them peaks past a + limit, or close enough that it may be wrong, the inverse is read at the + peak; a joint past a limit there is CROSSED, else each half is looked at + the same way. UNSURE where the module cannot answer at a peak or a + joint jumps to it. */ +static int travel_between(KinematicsUserContext *ctx, const SegmentCapLimits *lim, + double length, int K, SegmentPoseFn pose_at, void *arg, + int njoints, const int *watch, + const TravelPoint &a, const TravelPoint &b, + int *reads, SegmentCap *out) +{ + struct Stretch { + TravelPoint a, b; + int depth; + }; + /* split depth first, the half nearer the start on top */ + static Stretch stack[TRAVEL_DEPTH + 2]; + static TravelPoint m; + int n = 0, j, side; + + stack[n].a = a; + stack[n].b = b; + stack[n++].depth = 0; + while (n > 0) { + const Stretch st = stack[--n]; + double ds = st.b.s - st.a.s; + double worst = 0.0, at = -1.0; + + for (j = 0; j < njoints; j++) { + for (side = 1; side >= -1; side -= 2) { + double limit, u, peak, bulge, past; + if (!(watch[j] & (side > 0 ? WATCH_MAX : WATCH_MIN))) { continue; } + if (!travel_peak(st.a.q[j], st.a.g[j] * ds, st.b.q[j], st.b.g[j] * ds, + side, &u, &peak, &bulge)) { + continue; + } + /* how far past the limit the true peak can be */ + limit = side > 0 ? lim->max[j] : lim->min[j]; + past = side * (peak - limit) + TRAVEL_DOUBT * bulge - TRAVEL_HAIR; + if (past > worst) { + worst = past; + at = u; + } + } + } + if (at < 0.0) { continue; } + /* out of reads: what is left is let through */ + if (*reads <= 0) { return TRAVEL_CLEAR; } + (*reads)--; + m.s = st.a.s + at * ds; + for (j = 0; j < njoints; j++) { m.q[j] = st.a.q[j]; } + if (!sample_at(ctx, length, K, pose_at, arg, njoints, m.s / length, m.q, m.g) + || travel_jumped(st.a, m, njoints) || travel_jumped(m, st.b, njoints)) { + return TRAVEL_UNSURE; + } + if (travel_past(m, lim, watch, njoints, length, out)) { return TRAVEL_CROSSED; } + if (st.depth < TRAVEL_DEPTH) { + stack[n].a = m; + stack[n].b = st.b; + stack[n++].depth = st.depth + 1; + stack[n].a = st.a; + stack[n].b = m; + stack[n++].depth = st.depth + 1; + } + } + return TRAVEL_CLEAR; +} + +/* the first place along the sampled segment a joint leaves its travel */ +static void travel(KinematicsUserContext *ctx, const SegmentCapLimits *lim, + double length, int K, SegmentPoseFn pose_at, void *arg, + int njoints, SegmentCap *out) +{ + static int watch[KINEMATICS_USER_MAX_JOINTS]; + static TravelPoint a, b; + int k, j, any = 0, reads = TRAVEL_READS; + + if (!ok[0]) { return; } + /* a side of the travel the joint starts past is not followed: the move + may be the one bringing it back */ + for (j = 0; j < njoints; j++) { + watch[j] = 0; + if (std::isfinite(lim->max[j]) && q[0][j] <= lim->max[j] + TRAVEL_HAIR) { watch[j] |= WATCH_MAX; } + if (std::isfinite(lim->min[j]) && q[0][j] >= lim->min[j] - TRAVEL_HAIR) { watch[j] |= WATCH_MIN; } + any |= watch[j]; + } + if (!any) { return; } + travel_load(&a, 0, njoints); + for (k = 1; k < K; k++) { + if (!ok[k]) { return; } + travel_load(&b, k, njoints); + if (travel_jumped(a, b, njoints)) { return; } + if (travel_between(ctx, lim, length, K, pose_at, arg, njoints, watch, + a, b, &reads, out) != TRAVEL_CLEAR) { + return; + } + if (travel_past(b, lim, watch, njoints, length, out)) { return; } + a = b; + } +} + int segmentCap(KinematicsUserContext *ctx, const SegmentCapLimits *lim, double length, int samples, SegmentPoseFn pose_at, void *arg, double *joints, SegmentCap *out) { const double tiny = 1e-12; - /* the rate of every joint per unit of path parameter at each sample, - the most that rate changes per unit of parameter on either side of - it, and the most it can bulge past the samples on either side */ - static double g[SEGMENT_CAP_MAX_SAMPLES][KINEMATICS_USER_MAX_JOINTS]; + /* the most the rate of every joint changes per unit of parameter on + either side of a sample, and the most it can bulge past the samples + on either side */ static double h[SEGMENT_CAP_MAX_SAMPLES][KINEMATICS_USER_MAX_JOINTS]; static double bulge[SEGMENT_CAP_MAX_SAMPLES][KINEMATICS_USER_MAX_JOINTS]; - static double s[SEGMENT_CAP_MAX_SAMPLES]; - static bool ok[SEGMENT_CAP_MAX_SAMPLES]; int K = samples < 2 ? 2 : samples; int njoints; - int k, j, a, prev, answered = 0; + int k, j, prev, answered = 0; out->vel = SEGMENT_CAP_NONE; out->acc = SEGMENT_CAP_NONE; @@ -54,6 +308,10 @@ int segmentCap(KinematicsUserContext *ctx, const SegmentCapLimits *lim, out->vel_at = 0.0; out->samples = 0; out->unanswered = 0; + out->travel_joint = -1; + out->travel_side = 0; + out->travel_at = 0.0; + out->travel_pos = 0.0; if (!ctx || !lim || !pose_at || !joints || length <= 0.0) { return -1; } if (K > SEGMENT_CAP_MAX_SAMPLES) { K = SEGMENT_CAP_MAX_SAMPLES; } njoints = lim->joints; @@ -62,38 +320,21 @@ int segmentCap(KinematicsUserContext *ctx, const SegmentCapLimits *lim, for (k = 0; k < K; k++) { double f = (double)k / (double)(K - 1); - /* the tangent by a central difference of the geometry, exact for - a line and a small fraction of a sample step for an arc */ - double df = 1.0 / (8.0 * (K - 1)); - double fp = f + df > 1.0 ? 1.0 : f + df; - double fm = f - df < 0.0 ? 0.0 : f - df; - EmcPose p, pp, pm; - double t[AXIS_COUNT]; - double J[KINEMATICS_USER_MAX_JOINTS][AXIS_COUNT]; s[k] = f * length; - ok[k] = false; - pose_at(f, &p, arg); - pose_at(fp, &pp, arg); - pose_at(fm, &pm, arg); - for (a = 0; a < AXIS_COUNT; a++) { - t[a] = (pose_axis(pp, a) - pose_axis(pm, a)) / ((fp - fm) * length); - } /* the joints at the sample, seeded from the sample before so the whole segment stays on one solution branch, then the Jacobian on that branch */ - if (kinematicsUserInverse(ctx, &p, joints) != 0 - || kinematicsUserJacobianAt(ctx, joints, &p, J) != 0) { + ok[k] = sample_at(ctx, length, K, pose_at, arg, njoints, f, joints, g[k]); + if (!ok[k]) { out->unanswered++; continue; } for (j = 0; j < njoints; j++) { - g[k][j] = 0.0; + q[k][j] = joints[j]; h[k][j] = 0.0; bulge[k][j] = 0.0; - for (a = 0; a < AXIS_COUNT; a++) { g[k][j] += J[j][a] * t[a]; } } - ok[k] = true; answered++; } if (!answered) { return -1; } @@ -169,6 +410,9 @@ int segmentCap(KinematicsUserContext *ctx, const SegmentCapLimits *lim, } } } + + /* and the travel, on the same samples */ + travel(ctx, lim, length, K, pose_at, arg, njoints, out); return 0; } // segmentCap() diff --git a/src/emc/motion_planning/segment_cap.hh b/src/emc/motion_planning/segment_cap.hh index 80826bcb900..76407abd991 100644 --- a/src/emc/motion_planning/segment_cap.hh +++ b/src/emc/motion_planning/segment_cap.hh @@ -19,11 +19,15 @@ namespace motion_planning { /* The joint limits the cap is read against, in the units motion commands - the joints in: [JOINT_n] MAX_VELOCITY and MAX_ACCELERATION. */ + the joints in: [JOINT_n] MAX_VELOCITY and MAX_ACCELERATION, and the + travel between MIN_LIMIT and MAX_LIMIT, -HUGE_VAL and HUGE_VAL for a + joint whose travel is not to be followed. */ struct SegmentCapLimits { int joints; double vel[KINEMATICS_USER_MAX_JOINTS]; double acc[KINEMATICS_USER_MAX_JOINTS]; + double min[KINEMATICS_USER_MAX_JOINTS]; + double max[KINEMATICS_USER_MAX_JOINTS]; }; /* No joint binds. */ @@ -42,6 +46,10 @@ struct SegmentCap { double vel_at; /* the fraction of the segment the velocity cap is read at */ int samples; /* points the segment was sampled at */ int unanswered; /* of them, the ones the module could not invert or differentiate */ + int travel_joint; /* the first joint found leaving its travel along the segment, -1 for none */ + int travel_side; /* 1 past its MAX_LIMIT, -1 past its MIN_LIMIT */ + double travel_at; /* the fraction of the segment it is found at */ + double travel_pos; /* where the joint is there */ }; /* The pose at a fraction of the segment, 0 the start and 1 the end, in @@ -61,11 +69,24 @@ typedef void (*SegmentPoseFn)(double fraction, EmcPose *pose, void *arg); aside: at most half the joint's budget goes to it, and the velocity is lowered where it would take more. + The joints are followed against their travel along the same samples: a + sample past a limit, or, between two samples, the peak of the cubic + through their positions and rates, read again through the inverse at + the peak and found past the limit there, is reported, the first one + along the segment. Where the cubic puts a peak near the limit without + the inverse confirming it, the stretch is split at the peak and each + half looked at the same way, a bounded number of times. Only a point + the inverse itself puts past a limit is reported, and not on a side of + the travel the joint starts the segment past, nor beyond a sample the + module cannot invert or a joint moving between two points further than + its rates allow, as where the inverse changes branch: past those the + segment is not known well enough to be refused. + length is the segment's extent in the path parameter, in the units the caps come back in. joints seeds the inverse at the start and comes back holding the joints at the end, so the next segment starts on the same solution branch. Returns 0, or -1 where no sample could be evaluated, - the caps then NONE. */ + the caps then NONE and no joint found leaving its travel. */ int segmentCap(KinematicsUserContext *ctx, const SegmentCapLimits *lim, double length, int samples, SegmentPoseFn pose_at, void *arg, double *joints, SegmentCap *out); diff --git a/src/emc/task/emccanon.cc b/src/emc/task/emccanon.cc index ec11bca6d00..7df4ac115cb 100644 --- a/src/emc/task/emccanon.cc +++ b/src/emc/task/emccanon.cc @@ -868,6 +868,15 @@ static double getStraightJerk(double x, double y, double z, // motion runs, loaded through the non-RT loader in kinematics_userspace/ // the first time a segment asks. A module that runs only in realtime, // and a kinematics type that is the identity, cap nothing. +// +// The same samples follow every joint against its travel. Motion checks +// the joints at the end of a move only, so a tilted head turning under +// the tool centre point can swing a carriage past its limit in the middle +// of a move whose ends are both inside; motion then stops on the soft +// limit partway through it, with the joint past the limit. Here such a +// move is refused before it is sent: it is dropped, every move after it +// is dropped too, since one sent after it would start from where the +// dropped one began, and task fails the line with the reason. //---------------------------------------------------------------------- // The HAL component the module is loaded on, canon's and the @@ -973,6 +982,22 @@ int GET_EXTERNAL_HAL_VALUE(const char *name, double *value) } } +// where a joint would leave its travel along a segment, joint -1 for nowhere +struct KinsTravel { + int joint; + int side; // 1 past MAX_LIMIT, -1 past MIN_LIMIT + double limit; // the limit, as motion held it + double pos; // where the joint would be + double at; // the fraction of the segment it is found at +}; + +// the first move refused, until task takes it +static struct { + bool pending; + int line; // of the move dropped for it, -1 until then + KinsTravel travel; +} refusal = { false, -1, { -1, 0, 0.0, 0.0, 0.0 } }; + static struct { KinematicsUserContext *ctx; bool tried; // loading was attempted, once @@ -988,8 +1013,9 @@ static struct { EmcPose start, end; bool capped; double vel, acc; + KinsTravel travel; } memo; -} kins = { NULL, false, -1, {}, false, false, {}, { false, {}, {}, false, 0.0, 0.0 } }; +} kins = { NULL, false, -1, {}, false, false, {}, { false, {}, {}, false, 0.0, 0.0, { -1, 0, 0.0, 0.0, 0.0 } } }; // the machine's own module, once static bool kins_load(void) @@ -1104,15 +1130,30 @@ static int kins_samples(const EmcPose *start, const EmcPose *end, double sweep_d return n > SEGMENT_CAP_MAX_SAMPLES ? SEGMENT_CAP_MAX_SAMPLES : n; } +// the travel motion holds the joints to now, MIN_LIMIT and MAX_LIMIT or +// what the ini.N pins have made of them since, on the joints that are +// homed: the position of one that is not means nothing to its limits +static void kins_travel_limits(void) +{ + for (int j = 0; j < kins.limits.joints; j++) { + bool homed = emcStatus->motion.joint[j].homed; + kins.limits.min[j] = homed ? emcStatus->motion.joint[j].minPositionLimit : -HUGE_VAL; + kins.limits.max[j] = homed ? emcStatus->motion.joint[j].maxPositionLimit : HUGE_VAL; + } +} + // what the joints allow along a segment, in the machine's units per second -// of the path parameter canon plans it with; false where nothing binds +// of the path parameter canon plans it with, false where nothing binds, +// and where along it a joint would leave its travel static bool kins_cap(KinematicsUserContext *ctx, const EmcPose *start, const EmcPose *end, double length, int samples, motion_planning::SegmentPoseFn pose_at, void *arg, - double *vel, double *acc) + double *vel, double *acc, KinsTravel *travel) { motion_planning::SegmentCap cap; + travel->joint = -1; kins_seed(ctx, start); + kins_travel_limits(); if (motion_planning::segmentCap(ctx, &kins.limits, length, samples, pose_at, arg, kins.joints, &cap) != 0) { CANON_ERROR(fmt::format("the kinematics cannot reach the move to X{:.3f} Y{:.3f} Z{:.3f} A{:.3f} B{:.3f} C{:.3f}, the joints are not checked along it", end->tran.x, end->tran.y, end->tran.z, end->a, end->b, end->c)); @@ -1129,10 +1170,19 @@ static bool kins_cap(KinematicsUserContext *ctx, const EmcPose *start, const Emc CANON_ERROR(fmt::format("joint {} cannot follow the move to X{:.3f} Y{:.3f} Z{:.3f} A{:.3f} B{:.3f} C{:.3f} near {:.0f}% of its length: the kinematics is singular there and the move crawls", cap.vel_joint, end->tran.x, end->tran.y, end->tran.z, end->a, end->b, end->c, 100.0 * cap.vel_at)); } + if (cap.travel_joint >= 0) { + travel->joint = cap.travel_joint; + travel->side = cap.travel_side; + travel->limit = cap.travel_side > 0 ? kins.limits.max[cap.travel_joint] + : kins.limits.min[cap.travel_joint]; + travel->pos = cap.travel_pos; + travel->at = cap.travel_at; + } if (kins.debug) { - fprintf(stderr, "canon kins: to X%.3f Y%.3f Z%.3f A%.3f B%.3f C%.3f length %.3f in %d samples: vel %.3f (joint %d at %.2f) acc %.3f (joint %d), %d unanswered; seed", + fprintf(stderr, "canon kins: to X%.3f Y%.3f Z%.3f A%.3f B%.3f C%.3f length %.3f in %d samples: vel %.3f (joint %d at %.2f) acc %.3f (joint %d), %d unanswered, travel left by joint %d at %.2f; seed", end->tran.x, end->tran.y, end->tran.z, end->a, end->b, end->c, length, cap.samples, - cap.vel, cap.vel_joint, cap.vel_at, cap.acc, cap.acc_joint, cap.unanswered); + cap.vel, cap.vel_joint, cap.vel_at, cap.acc, cap.acc_joint, cap.unanswered, + cap.travel_joint, cap.travel_at); for (int j = 0; j < kins.limits.joints; j++) { fprintf(stderr, " %.3f", kins.joints[j]); } fprintf(stderr, "\n"); } @@ -1141,6 +1191,16 @@ static bool kins_cap(KinematicsUserContext *ctx, const EmcPose *start, const Emc return cap.vel_joint >= 0 || cap.acc_joint >= 0; } +// a segment a joint would leave its travel along refuses the move, the +// first one only: the moves after it are dropped with it +static void kins_refuse(const KinsTravel *travel) +{ + if (travel->joint < 0 || refusal.pending) { return; } + refusal.pending = true; + refusal.line = -1; + refusal.travel = *travel; +} + struct KinsLine { EmcPose start, end; }; @@ -1176,6 +1236,7 @@ static bool kins_straight_cap(double x, double y, double z, line.start = to_ext_pose(canon.endPoint); line.end = to_ext_pose(x, y, z, a, b, c, u, v, w); if (kins.memo.valid && kins_same(&kins.memo.start, &line.start) && kins_same(&kins.memo.end, &line.end)) { + kins_refuse(&kins.memo.travel); *vel = kins.memo.vel; *acc = kins.memo.acc; return kins.memo.capped; @@ -1194,7 +1255,9 @@ static bool kins_straight_cap(double x, double y, double z, kins.memo.end = line.end; kins.memo.capped = kins_cap(ctx, &line.start, &line.end, length, kins_samples(&line.start, &line.end, 0.0), - kins_line_pose, &line, &kins.memo.vel, &kins.memo.acc); + kins_line_pose, &line, &kins.memo.vel, &kins.memo.acc, + &kins.memo.travel); + kins_refuse(&kins.memo.travel); *vel = kins.memo.vel; *acc = kins.memo.acc; return kins.memo.capped; @@ -1228,6 +1291,8 @@ static bool kins_arc_cap(const PM_CARTESIAN ¢er, const PM_CARTESIAN &normal, { KinematicsUserContext *ctx = kins_here(); KinsArc arc; + KinsTravel travel; + bool capped; if (!ctx || length <= 0.0) { return false; } arc.start = to_ext_pose(canon.endPoint); @@ -1242,9 +1307,42 @@ static bool kins_arc_cap(const PM_CARTESIAN ¢er, const PM_CARTESIAN &normal, return false; } } - return kins_cap(ctx, &arc.start, &arc.end, TO_EXT_LEN(length), - kins_samples(&arc.start, &arc.end, fabs(full_angle) * 180.0 / M_PI), - kins_arc_pose, &arc, vel, acc); + capped = kins_cap(ctx, &arc.start, &arc.end, TO_EXT_LEN(length), + kins_samples(&arc.start, &arc.end, fabs(full_angle) * 180.0 / M_PI), + kins_arc_pose, &arc, vel, acc, &travel); + kins_refuse(&travel); + return capped; +} + +// whether a move about to be sent is dropped: the one refused, or one +// after it, which would start from where the refused one began, until +// task has taken the refusal +static bool kins_dropped(int line_number) +{ + if (!refusal.pending) { return false; } + if (refusal.line < 0) { refusal.line = line_number; } + return true; +} + +int CANON_MOVE_REFUSED(char *message, size_t messagesize) +{ + const KinsTravel &t = refusal.travel; + const char *limit = t.side > 0 ? "MAX_LIMIT" : "MIN_LIMIT"; + char move[32] = "the move"; + + if (!refusal.pending) { return 0; } + if (refusal.line > 0) { snprintf(move, sizeof(move), "the move on line %d", refusal.line); } + if (t.at > 1.0 - 1e-9) { + snprintf(message, messagesize, "%s would end with joint %d past its limit, at %.4f against %s %.4f", + move, t.joint, t.pos, limit, t.limit); + } else { + snprintf(message, messagesize, "%s would take joint %d past its limit, to %.4f against %s %.4f, %.0f%% of the way along", + move, t.joint, t.pos, limit, t.limit, 100.0 * t.at); + } + refusal.pending = false; + // the move may be asked for again, under other limits by then + kins.memo.valid = false; + return 1; } /** @@ -1385,6 +1483,10 @@ static void flush_segments(void) { #endif VelData linedata = getStraightVelocity(x, y, z, a, b, c, u, v, w); + if (kins_dropped(line_no)) { + drop_segments(); + return; + } double jerk = getStraightJerk(x, y, z, a, b, c, u, v, w); double vel = linedata.vel; @@ -1518,6 +1620,7 @@ void FINISH() { void ON_RESET() { drop_segments(); + refusal.pending = false; } void SELECT_KINS_TYPE(int switchkins_type) @@ -1586,6 +1689,7 @@ static void joint_move(int line_number, const double *joints, int have_joints, auto msg = std::make_unique(); flush_segments(); + if (kins_dropped(line_number)) { return; } from_prog(x,y,z,a,b,c,u,v,w); rotate_and_offset_pos(x,y,z,a,b,c,u,v,w); @@ -1677,6 +1781,7 @@ void STRAIGHT_TRAVERSE(int line_number, VelData veldata = getStraightVelocity(x, y, z, a, b, c, u, v, w); AccelData accdata = getStraightAcceleration(x, y, z, a, b, c, u, v, w); double jerk = getStraightJerk(x, y, z, a, b, c, u, v, w); + if (kins_dropped(line_number)) { return; } vel = veldata.vel; acc = accdata.acc; @@ -1723,6 +1828,10 @@ void RIGID_TAP(int line_number, double x, double y, double z, double scale) from_prog(x,y,z,unused,unused,unused,unused,unused,unused); rotate_and_offset_pos(x,y,z,unused,unused,unused,unused,unused,unused); + // the segments before it first, so that the tap is read from where it + // starts + flush_segments(); + VelData veldata = getStraightVelocity(x, y, z, canon.endPoint.a, canon.endPoint.b, canon.endPoint.c, canon.endPoint.u, canon.endPoint.v, canon.endPoint.w); @@ -1746,7 +1855,7 @@ void RIGID_TAP(int line_number, double x, double y, double z, double scale) rigidTapMsg->ini_maxjerk = toExtVel(jerk); rigidTapMsg->acc = toExtAcc(acc); rigidTapMsg->scale = scale; - flush_segments(); + if (kins_dropped(line_number)) { return; } if(ini_maxvel && acc) { interp_list.set_line_number(line_number); @@ -1796,6 +1905,7 @@ void STRAIGHT_PROBE(int line_number, AccelData accdata = getStraightAcceleration(x, y, z, a, b, c, u, v, w); acc = accdata.acc; + if (kins_dropped(line_number)) { return; } probeMsg->vel = toExtVel(vel); probeMsg->ini_maxvel = toExtVel(ini_maxvel); @@ -3280,6 +3390,7 @@ void ARC_FEED(int line_number, a_max = std::min(a_max, FROM_EXT_LEN(kacc)); } } + if (kins_dropped(line_number)) { return; } // Limit velocity by maximum double vel = std::min(canon.linearFeedRate, v_max); @@ -3584,6 +3695,7 @@ void CHANGE_TOOL() double jerk = getStraightJerk(x, y, z, a, b, c, u, v, w); vel = veldata.vel; acc = accdata.acc; + if (kins_dropped(_tag.fields[GM_FIELD_LINE_NUMBER])) { return; } auto linearMoveMsg = std::make_unique(); linearMoveMsg->feed_mode = canon.feed_mode; @@ -3958,6 +4070,7 @@ void INIT_CANON() double units; chained_points.clear(); + refusal.pending = false; // initialize locals to original values canon.xy_rotation = 0.0; diff --git a/src/emc/task/emctaskmain.cc b/src/emc/task/emctaskmain.cc index 23c6f7119c5..f610a866845 100644 --- a/src/emc/task/emctaskmain.cc +++ b/src/emc/task/emctaskmain.cc @@ -545,6 +545,27 @@ static int checkInterpList(NML_INTERP_LIST * il, EMC_STAT * /*stat*/) return 0; } + +// whether the line the interpreter has just executed is one stepped over +// on the way to the line a run starts from, its output thrown away +static bool stepping_over(void) +{ + return programStartLine != 0 && emcTaskPlanLevel() == 0 + && (programStartLine < 0 || emcTaskPlanLine() <= programStartLine); +} + +// A move canon refused, because a joint would leave its travel along it, +// fails the line like an interpreter error: canon has dropped it and every +// move after it. On a line stepped over the refusal goes with the rest of +// its output, its moves read from wherever the machine stands. +static int canon_refusal(int retval, bool stepped_over) +{ + char text[LINELEN]; + + if (!CANON_MOVE_REFUSED(text, sizeof(text)) || stepped_over) { return retval; } + emcOperatorError("%s", text); + return INTERP_ERROR; +} extern int emcTaskMopup(); void readahead_reading(void) @@ -573,6 +594,7 @@ void readahead_reading(void) } } else { readRetval = emcTaskPlanRead(); + readRetval = canon_refusal(readRetval, stepping_over()); /*! \todo MGS FIXME This if() actually evaluates to if (readRetval != INTERP_OK)... *** Need to look at all calls to things that return INTERP_xxx values! *** @@ -598,6 +620,7 @@ void readahead_reading(void) command); // and execute it execRetval = emcTaskPlanExecute(NULL); + execRetval = canon_refusal(execRetval, stepping_over()); // line number may need update after // returns from subprograms in external // files @@ -635,10 +658,7 @@ void readahead_reading(void) // throw the results away if we're supposed to // read // through it - if ( programStartLine != 0 && - emcTaskPlanLevel() == 0 && - ( programStartLine < 0 || - emcTaskPlanLine() <= programStartLine )) { + if (stepping_over()) { // we're stepping over lines, so check them // for // limits, etc. and clear then out @@ -2403,6 +2423,7 @@ static int emcTaskIssueCommand(NMLmsg * cmd) } execRetval = emcTaskPlanExecute(command, 0); + execRetval = canon_refusal(execRetval, false); level = emcTaskPlanLevel(); diff --git a/tests/kins-limits/travel/README b/tests/kins-limits/travel/README new file mode 100644 index 00000000000..61cf454cb3e --- /dev/null +++ b/tests/kins-limits/travel/README @@ -0,0 +1,16 @@ +A move whose joints leave their travel between its ends is refused before +it is sent, not stopped on the soft limit partway through it. + +5axiskins with a 400 mm pivot, the head laid over to B90 by a joint move, +the tool tip held while C turns, so that the carriage swings round the tip +at the pivot length plus the tool length; C-90 puts it at Y+ that radius, +against joint 1's MAX_LIMIT of 400. A tool length of 0.05 makes the swing +from C-5 to C-175 peak 0.05 past the travel at C-90, between two samples +1.2 inside it: the move is refused, asked again it is refused again, and +moves inside the travel still go, turning the other way among them; a +move ending past the travel is refused for its end. At -0.05 the same +swing peaks 0.05 inside and runs; at 100 the samples themselves are past. +With the head upright an arc whose ends are inside the travel and whose +top is past it is refused, the same arc the other way round runs. A +program fails on the line of the swing with no joint past its limit, and +run from the line after it, which only steps over the swing, it runs. diff --git a/tests/kins-limits/travel/checkresult b/tests/kins-limits/travel/checkresult new file mode 100755 index 00000000000..9d48d3f180e --- /dev/null +++ b/tests/kins-limits/travel/checkresult @@ -0,0 +1,3 @@ +#!/bin/sh +# the test script counts its own failures +grep -q "^Exiting with 0 errors" "$1" diff --git a/tests/kins-limits/travel/sim.hal b/tests/kins-limits/travel/sim.hal new file mode 100644 index 00000000000..e92c60eb526 --- /dev/null +++ b/tests/kins-limits/travel/sim.hal @@ -0,0 +1,16 @@ +loadrt [KINS]KINEMATICS +loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS + +addf motion-command-handler servo-thread +addf motion-controller servo-thread + +net J0 joint.0.motor-pos-cmd => joint.0.motor-pos-fb +net J1 joint.1.motor-pos-cmd => joint.1.motor-pos-fb +net J2 joint.2.motor-pos-cmd => joint.2.motor-pos-fb +net J3 joint.3.motor-pos-cmd => joint.3.motor-pos-fb +net J4 joint.4.motor-pos-cmd => joint.4.motor-pos-fb +net J5 joint.5.motor-pos-cmd => joint.5.motor-pos-fb + +net estop-loop iocontrol.0.user-enable-out iocontrol.0.emc-enable-in +net tool-prep-loop iocontrol.0.tool-prepare iocontrol.0.tool-prepared +net tool-change-loop iocontrol.0.tool-change iocontrol.0.tool-changed diff --git a/tests/kins-limits/travel/test-ui.py b/tests/kins-limits/travel/test-ui.py new file mode 100755 index 00000000000..07c5b067779 --- /dev/null +++ b/tests/kins-limits/travel/test-ui.py @@ -0,0 +1,196 @@ +#!/usr/bin/env python3 +# A move whose joints leave their travel between its ends is refused before +# it is sent: see README. +import linuxcnc +import linuxcnc_util +import os +import sys +import time + +JOINTS = 6 +PROGRAM = os.path.abspath("travel.ngc") +# the line of travel.ngc that swings the carriage past its Y travel +SWING_LINE = 6 + +c = linuxcnc.command() +s = linuxcnc.stat() +e = linuxcnc.error_channel() + +errors = 0 +# the furthest joint 1 was seen, every time the machine is polled +y_peak = -1e99 + +def error(what): + global errors + errors += 1 + print("*** ERROR %s" % what) + +def joints(): + global y_peak + s.poll() + y_peak = max(y_peak, s.joint_position[1]) + return [s.joint_position[i] for i in range(JOINTS)] + +def drain(): + said = [] + while True: + m = e.poll() + if not m: + return said + said.append(m) + +def complaints(said): + return [m for m in said if m[0] in (linuxcnc.NML_ERROR, linuxcnc.OPERATOR_ERROR)] + +def settled(): + deadline = time.time() + 60 + last = None + while time.time() < deadline: + now = joints() + if s.inpos and not s.queue and now == last: + return now + last = now + time.sleep(0.01) + error("timed out waiting for the move") + return last + +def mdi(cmd): + c.mdi(cmd) + c.wait_complete(60) + return settled() + +def back_to_mdi(): + c.mode(linuxcnc.MODE_MDI) + c.wait_complete(30) + +def accepted(cmd, joint, where): + drain() + now = mdi(cmd) + said = complaints(drain()) + if said: + error("%s was refused: %s" % (cmd, said[0][1].strip())) + elif abs(now[joint] - where) > 1e-3: + error("%s left joint %d at %.4f, not %.4f" % (cmd, joint, now[joint], where)) + else: + print("accepted as expected: %-28s joint %d at %.4f" % (cmd, joint, now[joint])) + back_to_mdi() + +def refused(cmd, *needles): + drain() + before = joints() + c.mdi(cmd) + c.wait_complete(30) + settled() + said = complaints(drain()) + if not said: + error("%s was accepted" % cmd) + elif not all(n in said[0][1] for n in needles): + error("%s said %r, not %r" % (cmd, said[0][1].strip(), needles)) + else: + print("refused as expected: %s" % said[0][1].strip()) + if max(abs(a - b) for a, b in zip(joints(), before)) > 1e-6: + error("%s moved the joints" % cmd) + back_to_mdi() + +def run(start_line): + drain() + c.mode(linuxcnc.MODE_AUTO) + c.wait_complete(30) + c.program_open(PROGRAM) + c.wait_complete(30) + c.auto(linuxcnc.AUTO_RUN, start_line) + c.wait_complete(30) + deadline = time.time() + 60 + while time.time() < deadline: + joints() + if s.interp_state == linuxcnc.INTERP_IDLE and not s.queue and s.inpos: + break + time.sleep(0.01) + else: + error("the program did not finish") + now = settled() + said = complaints(drain()) + back_to_mdi() + return now, said + +c.state(linuxcnc.STATE_ESTOP_RESET) +c.state(linuxcnc.STATE_ON) +c.wait_complete(30) +linuxcnc_util.LinuxCNC(command=c, status=s).home_all(timeout=60) +back_to_mdi() +drain() + +# the tool centre point kinematics, the head laid over by a joint move; the +# carriage at X-400 puts the tip at X0. A turn of C holding the tip swings +# the carriage round it at the pivot length plus the tool length, C-90 +# putting it at Y+ that radius, against joint 1's MAX_LIMIT of 400 +mdi("G12.1 P0") +mdi("G53.7 G0 J0=-400 J1=0 J2=0 J3=90 J4=0 J5=0") + +# a radius of 400.05: the swing from C-5 to C-175 peaks at C-90 between two +# samples, which are 1.2 inside the travel; the peak is 0.05 past it +mdi("G43.1 Z0.05") +accepted("G0 C-5", 4, -5) +refused("G0 C-175", "joint 1", "MAX_LIMIT", "50%") +# asked again, it is refused again, and a move inside the travel still goes +refused("G0 C-175", "joint 1", "MAX_LIMIT") +accepted("G0 C-60", 4, -60) +accepted("G0 C-5", 4, -5) +# turning the other way, C through +90, runs the carriage through +# Y-400.05, inside the travel +accepted("G0 C175", 4, 175) +accepted("G0 C-5", 4, -5) +# a move that ends past the travel is refused for its end +refused("G0 C-90", "joint 1", "end with", "MAX_LIMIT") + +# a radius of 399.95: the same swing peaks 0.05 inside the travel +mdi("G43.1 Z-0.05") +accepted("G0 C-175", 4, -175) +accepted("G0 C-5", 4, -5) + +# a radius of 500: the samples themselves are past the travel +mdi("G43.1 Z100") +refused("G0 C-175", "joint 1", "MAX_LIMIT") +mdi("G49") + +# an arc with the head upright, its ends inside the travel and its top +# 54.4 past it; the other way round it runs below +mdi("G53.7 G0 J0=0 J1=0 J2=0 J3=0 J4=0 J5=0") +accepted("G0 X-100 Y380", 1, 380) +refused("G2 X100 Y380 I100 J-30 F30000", "joint 1", "MAX_LIMIT") +accepted("G3 X100 Y380 I100 J-30 F30000", 1, 380) +accepted("G0 X0 Y0", 1, 0) + +# a program: the line that swings past the travel fails, the moves before +# it may have run, and no joint has passed its limit +mdi("G53.7 G0 J0=-400 J1=0 J2=0 J3=90 J4=0 J5=0") +y_peak = -1e99 +now, said = run(0) +if not said: + error("the program ran through line %d" % SWING_LINE) +elif "line %d" % SWING_LINE not in said[0][1] or "joint 1" not in said[0][1]: + error("the program said %r" % said[0][1].strip()) +else: + print("refused as expected: %s" % said[0][1].strip()) +if any("soft limit" in m[1] for m in said): + error("a joint ran onto its soft limit") +if y_peak > 400 + 1e-6: + error("joint 1 reached %.4f, past its MAX_LIMIT" % y_peak) + +# run from the line after the swing: the line is only stepped over, its +# moves are thrown away, and the program runs +mdi("G49") +mdi("G53.7 G0 J0=-400 J1=0 J2=0 J3=90 J4=0 J5=0") +now, said = run(SWING_LINE + 1) +if said: + error("run from line %d said %r" % (SWING_LINE + 1, said[0][1].strip())) +elif abs(now[4] + 5) > 1e-3: + error("run from line %d left C at %.4f, not -5" % (SWING_LINE + 1, now[4])) +else: + print("ran from line %d as expected, C at %.4f" % (SWING_LINE + 1, now[4])) + +mdi("G49") +mdi("G53.7 G0 J0=0 J1=0 J2=0 J3=0 J4=0 J5=0") +print("joint 1 peaked at %.4f since the program started" % y_peak) +print("Exiting with %d errors" % errors) +sys.exit(1 if errors else 0) diff --git a/tests/kins-limits/travel/test.ini b/tests/kins-limits/travel/test.ini new file mode 100644 index 00000000000..50349e5995f --- /dev/null +++ b/tests/kins-limits/travel/test.ini @@ -0,0 +1,136 @@ +[EMC] +VERSION = 1.1 +DEBUG = 0 + +[DISPLAY] +DISPLAY = ./test-ui.py + +[RS274NGC] +RS274NGC_STARTUP_CODE = G17 G21 G40 G49 G54 G64 P0.001 G80 G90 G92.1 G94 G97 G98 +PARAMETER_FILE = sim.var + +[KINS] +# switchkins-type 0 is 5axiskins, the tool centre point; 1 is identity +KINEMATICS = 5axiskins coordinates=xyzbcw +JOINTS = 6 + +[HAL] +HALFILE = sim.hal +# laid over to B90, the head swings the carriage round the tip at the +# pivot length plus the tool's +HALCMD = setp 5axiskins.pivot-length 400 + +[TRAJ] +# the rates are high so the moves are short: the test checks only which +# moves are refused and where the others end +COORDINATES = XYZBCW +LINEAR_UNITS = mm +ANGULAR_UNITS = deg +DEFAULT_LINEAR_VELOCITY = 8000 +MAX_LINEAR_VELOCITY = 13840 +MAX_LINEAR_ACCELERATION = 1280000 +DEFAULT_LINEAR_ACCELERATION = 1280000 +MAX_ANGULAR_VELOCITY = 14400 + +[EMCMOT] +EMCMOT = motmod +SERVO_PERIOD = 1000000 +COMM_TIMEOUT = 4 + +[TASK] +TASK = milltask +CYCLE_TIME = 0.001 + +[EMCIO] +TOOL_TABLE = tool.tbl + +[AXIS_X] +MIN_LIMIT = -2000 +MAX_LIMIT = 2000 +MAX_VELOCITY = 8000 +MAX_ACCELERATION = 1280000 + +[AXIS_Y] +MIN_LIMIT = -2000 +MAX_LIMIT = 2000 +MAX_VELOCITY = 8000 +MAX_ACCELERATION = 1280000 + +[AXIS_Z] +MIN_LIMIT = -2000 +MAX_LIMIT = 2000 +MAX_VELOCITY = 8000 +MAX_ACCELERATION = 1280000 + +[AXIS_B] +MIN_LIMIT = -120 +MAX_LIMIT = 120 +MAX_VELOCITY = 2400 +MAX_ACCELERATION = 320000 + +[AXIS_C] +MIN_LIMIT = -36000 +MAX_LIMIT = 36000 +MAX_VELOCITY = 2400 +MAX_ACCELERATION = 320000 + +[AXIS_W] +MIN_LIMIT = -100 +MAX_LIMIT = 500 +MAX_VELOCITY = 8000 +MAX_ACCELERATION = 1280000 + +[JOINT_0] +TYPE = LINEAR +MIN_LIMIT = -1000 +MAX_LIMIT = 1000 +MAX_VELOCITY = 8000 +MAX_ACCELERATION = 1280000 +HOME_SEARCH_VEL = 0 +HOME_SEQUENCE = 0 + +[JOINT_1] +TYPE = LINEAR +# the travel the swings are measured against +MIN_LIMIT = -1000 +MAX_LIMIT = 400 +MAX_VELOCITY = 8000 +MAX_ACCELERATION = 1280000 +HOME_SEARCH_VEL = 0 +HOME_SEQUENCE = 0 + +[JOINT_2] +TYPE = LINEAR +MIN_LIMIT = -1000 +MAX_LIMIT = 1000 +MAX_VELOCITY = 8000 +MAX_ACCELERATION = 1280000 +HOME_SEARCH_VEL = 0 +HOME_SEQUENCE = 0 + +[JOINT_3] +TYPE = ANGULAR +MIN_LIMIT = -120 +MAX_LIMIT = 120 +MAX_VELOCITY = 2400 +MAX_ACCELERATION = 320000 +HOME_SEARCH_VEL = 0 +HOME_SEQUENCE = 0 + +[JOINT_4] +TYPE = ANGULAR +MIN_LIMIT = -36000 +MAX_LIMIT = 36000 +MAX_VELOCITY = 2400 +MAX_ACCELERATION = 320000 +HOME_SEARCH_VEL = 0 +HOME_SEQUENCE = 0 + +[JOINT_5] +TYPE = LINEAR +MIN_LIMIT = -100 +MAX_LIMIT = 500 +MAX_VELOCITY = 8000 +MAX_ACCELERATION = 1280000 +HOME_SEARCH_VEL = 0 +HOME_SEQUENCE = 0 diff --git a/tests/kins-limits/travel/test.sh b/tests/kins-limits/travel/test.sh new file mode 100755 index 00000000000..765cf14fed6 --- /dev/null +++ b/tests/kins-limits/travel/test.sh @@ -0,0 +1,4 @@ +#!/bin/bash -e +# a failed run leaves the var file behind, and it carries offsets +rm -f sim.var sim.var.bak +linuxcnc -r test.ini diff --git a/tests/kins-limits/travel/tool.tbl b/tests/kins-limits/travel/tool.tbl new file mode 100644 index 00000000000..80153f2ca05 --- /dev/null +++ b/tests/kins-limits/travel/tool.tbl @@ -0,0 +1 @@ +T1 P1 Z0 ; diff --git a/tests/kins-limits/travel/travel.ngc b/tests/kins-limits/travel/travel.ngc new file mode 100644 index 00000000000..23b2a4b9949 --- /dev/null +++ b/tests/kins-limits/travel/travel.ngc @@ -0,0 +1,8 @@ +(the head laid over to B90, the tip held while C turns) +G21 G90 G94 +G12.1 P0 +G43.1 Z0.05 +G0 C-5 +G0 C-175 +G0 C-5 +M2