diff --git a/configs/sim/axis/vismach/5axis/bridgemill/g532-fused-orient-move.ngc b/configs/sim/axis/vismach/5axis/bridgemill/g532-fused-orient-move.ngc index bd193299758..3439a71fae7 100644 --- a/configs/sim/axis/vismach/5axis/bridgemill/g532-fused-orient-move.ngc +++ b/configs/sim/axis/vismach/5axis/bridgemill/g532-fused-orient-move.ngc @@ -36,7 +36,7 @@ o210 else o210 endif g68.2 p1 j[90-#] k# ; plane Z is the sphere radius at b, c g53.2 ; solve the orientation, stay put - g0 x0 y0 z[#+#] b#<_orient_b> c#<_orient_c> ; one TCP turn and travel + g0 x0 y0 z[#+#] b#<_orient_rot2> c#<_orient_rot1> ; one TCP turn and travel, C orients first g1 z[#+#] g0 z[#+#] # = [#+1] diff --git a/docs/src/gcode/g-code.adoc b/docs/src/gcode/g-code.adoc index 7469bbc6c2a..7e8b66821ad 100644 --- a/docs/src/gcode/g-code.adoc +++ b/docs/src/gcode/g-code.adoc @@ -1858,7 +1858,10 @@ The H word, the offset itself and the parameters it lands in are 'G43''s. Which kinematics is the working one is declared by the module (KINSTYPE_PRIMARY, see the <> chapter), the number is not the answer; a module that -declares none rejects 'G43.4' at read time. +declares none rejects 'G43.4' at read time. A module with one working +kinematics per tool head declares each one primary: 'G43.4' stays on the +one selected with 'G12.1' and, from any other kinematics, switches to the +lowest numbered. The switch is a queue synchronisation point like '<>': when 'G43.4' or 'G49' changes the @@ -1927,8 +1930,10 @@ a rotary swings the long way round only where the short way runs out of travel. rotary, the tool vertical on a mill, one joint no longer matters to the direction and it stays where it is. -The pose the interpreter finds goes into the move as ordinary rotary -words, in program coordinates, so the rotary offsets of the coordinate +The pose the interpreter finds goes into the move as ordinary words of +the two axes the kinematics type orients the tool with, the ones +'#<_kins_orient_1>' and '#<_kins_orient_2>' name (A B C for a type that +orients with three angles, a robot's wrist), in program coordinates, so the rotary offsets of the coordinate system apply, and the move interpolates like any other move with rotary words: the rotaries turn together with the linear axes between the poses of consecutive lines. The vector itself is not interpolated @@ -1942,7 +1947,8 @@ offset and undoes the kinematics switch, as after 'G43.4'. It is an error if: -* 'I J K' are given together with a rotary word on the same line, +* 'I J K' are given together with a word of an orienting axis on the same line, +* the kinematics type orients the tool with an axis that is not rotary, * the vector is zero, * the kinematics selected is the identity one, or the module supplies no tool frame or cannot be evaluated by the interpreter, @@ -2055,10 +2061,14 @@ differ in what happens then: * 'G53.3' moves the rotaries and takes the tool to 'X Y Z', given in the plane, in one point-to-point move. A word left out keeps the present value. * 'G53.2' moves nothing. It only publishes the solved pose on the named - parameters '#<_orient_x>', '#<_orient_y>', '#<_orient_z>', '#<_orient_a>', - '#<_orient_b>' and '#<_orient_c>', and on the numbered parameters - '#5071' to '#5079' ('X Y Z A B C U V W'), in program units in the plane, - and sets '#<_orient_valid>' and '#5080' to 1. The program can then reach + parameters '#<_orient_x>', '#<_orient_y>', '#<_orient_z>', + '#<_orient_rot1>', '#<_orient_rot2>' and '#<_orient_rot3>', and on the + numbered parameters '#5071' to '#5076' in the same order, in program + units in the plane, and sets '#<_orient_valid>' and '#5080' to 1. The + rotaries come in the order the kinematics orients the tool with, the + axes '#<_kins_orient_1>' to '#<_kins_orient_3>' name, so a program reads + the angles the same way whatever letters the machine gives them; + '#<_orient_rot3>' is 0 on a machine that orients with two rotaries. The program can then reach the pose with a move of its own making, for instance a single 'G0' that names 'X Y Z' and the rotary words together, so the turn and the travel are one Cartesian move under the TCP kinematics. This is what Heidenhain diff --git a/docs/src/gcode/overview.adoc b/docs/src/gcode/overview.adoc index e202811a5f6..f2bfecf17b2 100644 --- a/docs/src/gcode/overview.adoc +++ b/docs/src/gcode/overview.adoc @@ -305,9 +305,11 @@ example '##2' means the value of the parameter whose index is the which the G38 took place. Volatile. * '5070' - <> probe result: 1 if success, 0 if probe failed to close. Used with G38.3 and G38.5. Volatile. -* '5071-5079' - Pose last solved by <> for X, Y, Z, A, - B, C, U, V & W, in program units in the tilted work plane. Same values - as `#<_orient_x>` and kin. Read-only, volatile. +* '5071-5076' - Pose last solved by <> for X, Y, Z + and the first, second and third orienting rotary, in program units in + the tilted work plane. Same values as `#<_orient_x>` and kin. Read-only, + volatile. +* '5077-5079' - Written 0 by 'G53.2'. Read-only, volatile. * '5080' - 'G53.2' result: 1 once a 'G53.2' has solved a pose, 0 before. Same as `#<_orient_valid>`. Read-only, volatile. * '5081-5089' - Tool length offset currently applied to motion for X, Y, @@ -513,11 +515,32 @@ can be added easily without changes to the source code. 'P' number of the last 'G12.1', or 0 after 'G13.1' or when no kinematics has been selected. See <>. +* '#<_kins_orient_1>', '#<_kins_orient_2>', '#<_kins_orient_3>' - The + axes the kinematics type in force orients the tool with, as axis numbers, + 0 for X to 8 for W: the first rotation, the one whose axis stays put, then + the second. A head and a table give the table first. The type's module + declares the letters, or they are those its joint map gives the joints + that turn. '#<_kins_orient_3>' is -1 on those. A type with three + rotaries, a table and a two axis head say, gives all three, the tables + first; a robot arm, whose joints all turn the tool, reads 3, 4 and 5, the + A B C of its pose. All three are -1 where the type orients otherwise, the identity + type among them, or the interpreter cannot evaluate the kinematics. An axis + named here must be 'ANGULAR' in the INI file; the interpreter refuses a + module whose type orients with a 'LINEAR' axis when it first loads it. + +* '#<_kins_orient_1_head>', '#<_kins_orient_2_head>', + '#<_kins_orient_3_head>' - 1 where that axis turns the head, 0 where it + turns the table, -1 as above. + * '#<_orient_valid>', '#<_orient_x>', '#<_orient_y>', '#<_orient_z>', - '#<_orient_a>', '#<_orient_b>', '#<_orient_c>' - The pose 'G53.2' last - solved, in program units in the tilted work plane. '#<_orient_valid>' is - 1 once a 'G53.2' has run; reading the others before that is an error. The - same values are on the numbered parameters '#5071' to '#5080'. See + '#<_orient_rot1>', '#<_orient_rot2>', '#<_orient_rot3>' - The pose 'G53.2' + last solved, in program units in the tilted work plane: X Y Z, then the + angles of the axes '#<_kins_orient_1>' to '#<_kins_orient_3>' name, in + that order, 0 for a third the machine does not have. This is how Fanuc + and Siemens number the rotaries of a five axis machine, first and second, + whatever their letters. '#<_orient_valid>' is 1 once a 'G53.2' has run; + reading the others before that is an error. The same values are on the + numbered parameters '#5071' to '#5076' and '#5080'. See <>. * '#<_plane>' - returns the value designating the current plane: diff --git a/docs/src/motion/kinematics-conventions.adoc b/docs/src/motion/kinematics-conventions.adoc index 8f99f221407..dd109f87527 100644 --- a/docs/src/motion/kinematics-conventions.adoc +++ b/docs/src/motion/kinematics-conventions.adoc @@ -565,12 +565,22 @@ the optional work and tool frames with the native rotation that relates the tool frame to the convention, and the optional Jacobian. A type whose forward iterates from the pose it is handed says so, and the shared code seeds it with the last answer after a switch. A type also says what it IS: `identity` marks -the no-transform type, joints are axes; `primary` the working transform -`G43.4` and `G43.5` switch to; `machine` the machine frame type `G13.1` and +the no-transform type, joints are axes; `primary` a working transform +`G43.4` and `G43.5` switch to, which a module with one per tool head sets +on each, `G12.1` choosing the head; `machine` the machine frame type `G13.1` and `G49` cancel to and `G53.5` moves in, which a module leaves unset when its identity type is that frame and sets on its working transform when that reports the flange with no tool, as the robot modules do (see the Switchable -Kinematics chapter). A module with +Kinematics chapter). A type may also name the axis letters that orient +the tool, first rotation then second, in `orient`: "AC" for instance, or three +letters, tables first, for a type with three rotaries. Left out, they are the +letters the joint map gives the joints that turn the frames, which is right +for a module whose forward puts each joint in its own letter; a module that +writes an orienting joint into another letter declares them. A robot arm, all +of whose joints turn the tool, orients with the A B C of its pose. `G43.5` +writes its solution into these letters, the interpreter reads them back as +`#<_kins_orient_1>` to `#<_kins_orient_3>`, and `G53.2` publishes the angles +it solves in the same order as `#<_orient_rot1>` to `#<_orient_rot3>`. A module with several types has one geometry table and one ops table per type, registered with `switchkinsRegisterOps()`; a module with one type describes itself in a `kins_module` and links `kins_single.c`. diff --git a/docs/src/motion/switchkins.adoc b/docs/src/motion/switchkins.adoc index f12c25b527b..0a28ae9db0c 100644 --- a/docs/src/motion/switchkins.adoc +++ b/docs/src/motion/switchkins.adoc @@ -631,7 +631,11 @@ are not in the conventional order still gets working spellings. With `MACHINE_MOVES_IN_MACHINE_FRAME` set in the `[RS274NGC]` section of the INI file, 'G53', 'G28' and 'G30' move in the machine frame kinstype's world too whenever another kinstype is in force; the five axis sims set -it. The +it. A +machine with two tool heads, a saw blade and a waterjet say, declares +one primary kinstype per head and selects the head with 'G12.1 P-': +'G43.4' stays on the kinstype in force when it is primary, and from any +other switches to the lowest numbered primary. The machine frame kinstype is the machine with the tool left out, XYZ the pivot or the flange in machine coordinates and the rotary letters the orientation as that kinstype reports it; on a machine whose slides line @@ -650,8 +654,8 @@ composite Y on a mill-turn, declares its machine frame kinstype separately and keeps KINSTYPE_IDENTITY for a kinstype whose joints really are the axes, since motion and the planner skip the maths on that flag alone. At most one -kinstype may be declared identity, at most one primary and at most one -machine frame, and declaring a kinstype the module does not provide +kinstype may be declared identity and at most one machine frame, any +number primary, and declaring a kinstype the module does not provide fails the module load. A module that declares nothing keeps working exactly as before for 'G12.1 P-' and 'G49', but 'G13.1' and 'G43.4' are an error, since the numbers of the identity and primary kinematics diff --git a/include/kinematics_user.h b/include/kinematics_user.h index 6052f9e51ff..59ff8dc046a 100644 --- a/include/kinematics_user.h +++ b/include/kinematics_user.h @@ -270,6 +270,23 @@ int kinematicsUserOrientJoints(KinematicsUserContext* ctx, const double* seed, int kinematicsUserPoseJoint(KinematicsUserContext* ctx, const double* seed, int* joint); +/** + * The axes that orient the tool on the active type, as axis numbers, 0 X + * to 8 W: the first rotation then the second, and whether each turns the + * head (1) or the table (0). Two heads or two tables are ordered as + * kinematicsUserOrientJoints() orders them, the one whose axis stays put + * first; a table and a head, the table first. The letters are the type's + * declared orient, else those the joint map gives the joints. Three + * rotaries come tables first, each group in joint order. A type whose + * tool is turned by more than three joints and no table, a robot arm, + * orients with the A B C of its pose, all three head. Returns how many + * axes, 2 or 3, the unused entries -1; or -1 with every entry -1 where the + * type turns other rotaries between tool and work, or a letter cannot be + * found. + */ +int kinematicsUserOrientAxes(KinematicsUserContext* ctx, const double* seed, + int axes[3], int head[3]); + /** * kinematicsUserInitSparm() from the value of [KINS] KINEMATICS as the * HAL file hands it to loadrt: the module name first, then any of diff --git a/include/kins_module.h b/include/kins_module.h index 8443d2e621a..d29bc143332 100644 --- a/include/kins_module.h +++ b/include/kins_module.h @@ -340,17 +340,23 @@ typedef int (*kins_jacobian_fn)(const kins_params *p, const double *joint, forward starts from the pose it is handed, so the shared code seeds it with the last answer after a switch. identity says joints are axes, which a consumer may use to skip the maths altogether. primary says this is - the module's working transform, the type G43.4 switches to. machine says + a working transform, the type G43.4 switches to; a module with one per + tool head flags each, G12.1 choosing the head. machine says this is the machine frame type, the tool left out, the pivot or the flange in machine coordinates, which G13.1 and G49 select and G53.5 moves in; a module that leaves it unset on every type has its identity type stand in. A machine frame type does not read the tool offset in the parameter block, so a working transform that leaves the tool out anyway, a robot's flange, - carries primary and machine both. slides says the joints are the - machine's slides and rotaries, each in the letter the joint map gives - it, so that the carriage is the joints read through the map: the - machine frame of a module with one type, which has no machine frame - type to name. */ + carries primary and machine both. orient names the axis letters that + orient the tool, first rotation then second, "AC" for instance, or three, + tables first, on a type with three rotaries; left + NULL they are the letters the joint map gives the joints that turn the + frames, which is right for a module whose forward puts each joint in its + own letter, and a module that puts one elsewhere declares them. + slides says the joints are the machine's slides and rotaries, each in + the letter the joint map gives it, so that the carriage is the joints + read through the map: the machine frame of a module with one type, + which has no machine frame type to name. */ typedef struct kins_ops { kins_forward_fn forward; kins_inverse_fn inverse; @@ -362,6 +368,7 @@ typedef struct kins_ops { int identity; /* joints are axes */ int primary; /* the working transform */ int machine; /* the machine frame */ + const char *orient; /* orienting letters, NULL: from the joint map */ int slides; /* joints are the slides, letters by the map */ } kins_ops; diff --git a/lib/python/qtvcp/lib/mdi_text.py b/lib/python/qtvcp/lib/mdi_text.py index 712eaf78d2c..d849229a90b 100644 --- a/lib/python/qtvcp/lib/mdi_text.py +++ b/lib/python/qtvcp/lib/mdi_text.py @@ -863,8 +863,10 @@ def gcode_descriptions(gcode): G53.2 Solves the same pose as G53.1 and moves nothing. -The pose is published on #<_orient_x> to -#<_orient_c> and on #5071 to #5079, in program +The pose is published on #<_orient_x> #<_orient_y> +#<_orient_z> and the rotaries in the order the +kinematics orients with, #<_orient_rot1> to +#<_orient_rot3>, and on #5071 to #5076, in program units in the plane, with #<_orient_valid> (#5080) set to 1, so the program can reach it with a move of its own, for instance a single G0 naming X Y Z diff --git a/src/emc/kinematics/genserfuncs.c b/src/emc/kinematics/genserfuncs.c index 612a72d2b2c..783a68dc9a5 100644 --- a/src/emc/kinematics/genserfuncs.c +++ b/src/emc/kinematics/genserfuncs.c @@ -507,6 +507,65 @@ int compute_jinv(const genser_matrix * Jfwd, genser_matrix * Jinv) return GENSER_OK; } +/* What compute_jfwd() gives, straight from the DH frames in the base + frame: joint i moves along or turns about z_i, the axis of frame i + through its origin o_i, so the last frame's origin moves z_i or + z_i x (o_n - o_i) and turns 0 or z_i. The planner asks for many + Jacobians along each move, and this one skips the quaternions. */ +static void genser_jfwd_frames(const genser_struct *genser, const double *jest, + genser_matrix *Jfwd) +{ + double R[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}; + double o[3] = {0.0, 0.0, 0.0}; + double z[GENSER_MAX_JOINTS][3], oi[GENSER_MAX_JOINTS][3]; + const int n = genser->link_num; + + for (int i = 0; i < n; i++) { + const genser_link *link = &genser->links[i]; + const int prismatic = GENSER_QUANTITY_LENGTH == link->quantity; + const double th = prismatic ? link->dh.theta : jest[i]; + const double d = prismatic ? jest[i] : link->dh.d; + const double sal = sin(link->dh.alpha), cal = cos(link->dh.alpha); + const double sth = sin(th), cth = cos(th); + // as link_pose_build(): Rx(alpha) Tx(a) Rz(theta) Tz(d) + const double L[3][3] = {{cth, -sth, 0.0}, + {sth * cal, cth * cal, -sal}, + {sth * sal, cth * sal, cal}}; + const double t[3] = {link->dh.a, -sal * d, cal * d}; + double N[3][3]; + + for (int r = 0; r < 3; r++) { + o[r] += R[r][0] * t[0] + R[r][1] * t[1] + R[r][2] * t[2]; + } + for (int r = 0; r < 3; r++) { + for (int c = 0; c < 3; c++) { + N[r][c] = R[r][0] * L[0][c] + R[r][1] * L[1][c] + R[r][2] * L[2][c]; + } + } + memcpy(R, N, sizeof(R)); + for (int r = 0; r < 3; r++) { + z[i][r] = R[r][2]; + oi[i][r] = o[r]; + } + } + for (int i = 0; i < n; i++) { + const double v[3] = {o[0] - oi[i][0], o[1] - oi[i][1], o[2] - oi[i][2]}; + if (GENSER_QUANTITY_LENGTH == genser->links[i].quantity) { + for (int r = 0; r < 3; r++) { + Jfwd->el[r][i] = z[i][r]; + Jfwd->el[3 + r][i] = 0.0; + } + continue; + } + Jfwd->el[0][i] = z[i][1] * v[2] - z[i][2] * v[1]; + Jfwd->el[1][i] = z[i][2] * v[0] - z[i][0] * v[2]; + Jfwd->el[2][i] = z[i][0] * v[1] - z[i][1] * v[0]; + for (int r = 0; r < 3; r++) { + Jfwd->el[3 + r][i] = z[i][r]; + } + } +} + /* The Jacobian in the terms of kinematics.h: joints in degrees per pose word in EmcPose units, the derivative of genser_inverse(). @@ -529,8 +588,6 @@ static int genser_jacobian(const kins_params *p, const double *joint, genser_struct genser_stg; genser_struct *genser = &genser_stg; genser_matrix Jfwd, Jinv; - PmPose T_L_0; - genser_link linkout[GENSER_MAX_JOINTS] = {}; double jest[GENSER_MAX_JOINTS]; double E[3][3]; double sb, cb, sc, cc; @@ -552,12 +609,7 @@ static int genser_jacobian(const kins_params *p, const double *joint, matrix_init(&Jfwd, 6, genser->link_num); matrix_init(&Jinv, genser->link_num, 6); - for (link = 0; link < genser->link_num; link++) { - link_joint_set(&genser->links[link], jest[link], &linkout[link]); - } - retval = compute_jfwd(linkout, genser->link_num, &Jfwd, &T_L_0); - if (GENSER_OK != retval) - return -1; + genser_jfwd_frames(genser, jest, &Jfwd); retval = compute_jinv(&Jfwd, &Jinv); if (GENSER_OK != retval) return -1; // singular: no finite joint rate follows the pose @@ -691,7 +743,6 @@ static int genser_inverse(const kins_params *p, kins_scratch *s, genser_struct genser_stg; genser_struct *genser = &genser_stg; genser_matrix Jfwd, Jinv; - PmPose T_L_0; double dvw[6]; double jest[GENSER_MAX_JOINTS]; double dj[GENSER_MAX_JOINTS]; @@ -736,12 +787,7 @@ static int genser_inverse(const kins_params *p, kins_scratch *s, for (link = 0; link < genser->link_num; link++) { link_joint_set(&genser->links[link], jest[link], &linkout[link]); } - retval = compute_jfwd(linkout, genser->link_num, &Jfwd, &T_L_0); - if (GENSER_OK != retval) { - rtapi_print("ERR kI - compute_jfwd (joints: %f %f %f %f %f %f), (iterations=%d)\n", - joints[0],joints[1],joints[2],joints[3],joints[4],joints[5], genser->iterations); - return retval; - } + genser_jfwd_frames(genser, jest, &Jfwd); retval = compute_jinv(&Jfwd, &Jinv); if (GENSER_OK != retval) { rtapi_print("ERR kI - compute_jinv (joints: %f %f %f %f %f %f), (iterations=%d)\n", diff --git a/src/emc/kinematics/switchkins.c b/src/emc/kinematics/switchkins.c index e2f92709ebd..81cf190e4d1 100644 --- a/src/emc/kinematics/switchkins.c +++ b/src/emc/kinematics/switchkins.c @@ -730,7 +730,7 @@ int switchkinsInit(const int comp_id, const char* coordinates) { int i; - int identities, primaries, machines; + int identities, machines; int res = 0; char* emsg = "other"; @@ -758,13 +758,13 @@ int switchkinsInit(const int comp_id, } if (!kins_count) { emsg = "no switchkins-types provided"; goto error; } - // declarations must name provided types, and each flag is unique: - // G13.1 and G49 resolve the machine frame type from the flags and - // G43.4 the primary, so two answers is a load error. A module that + // declarations must name provided types, and identity and machine + // are unique: G13.1 and G49 resolve the machine frame type from the + // flags, so two answers is a load error. Several types may be + // primary, one per tool head, G12.1 choosing among them. A module that // names no machine frame type has its identity type stand in, which // is the truth on every machine whose slides line up with its frame. identities = 0; - primaries = 0; machines = 0; for (i=0; i < SWITCHKINS_MAX_TYPES; i++) { if (ktype_flags[i] & KINSTYPE_MACHINE) { machines++; } @@ -781,7 +781,6 @@ int switchkinsInit(const int comp_id, identities++; if (!machines) { ktype_flags[i] |= KINSTYPE_MACHINE; } } - if (ktype_flags[i] & KINSTYPE_PRIMARY) { primaries++; } rtapi_print("switchkins-type %d declared:%s%s%s\n", i, (ktype_flags[i] & KINSTYPE_IDENTITY) ? " identity" : "", (ktype_flags[i] & KINSTYPE_PRIMARY) ? " primary" : "", @@ -790,9 +789,6 @@ int switchkinsInit(const int comp_id, if (identities > 1) { emsg = "more than one identity switchkins-type declared"; goto error; } - if (primaries > 1) { - emsg = "more than one primary switchkins-type declared"; goto error; - } if (machines > 1) { emsg = "more than one machine frame switchkins-type declared"; goto error; } diff --git a/src/emc/kinematics_userspace/kinematics_user.c b/src/emc/kinematics_userspace/kinematics_user.c index a734fbcc467..d0fb6dda9f4 100644 --- a/src/emc/kinematics_userspace/kinematics_user.c +++ b/src/emc/kinematics_userspace/kinematics_user.c @@ -25,6 +25,7 @@ ********************************************************************/ #include +#include #include #include #include @@ -767,6 +768,102 @@ int kinematicsUserPoseJoint(KinematicsUserContext* ctx, const double* seed, return r; } +// the letter of joint j: the principal one, else any that maps to it +static int joint_letter(const kins_params *p, int j) +{ + int a; + + for (a = 0; a < EMCMOT_MAX_AXIS; a++) { + if (p->joint_of_axis[a] == j) { return a; } + } + for (a = 0; a < EMCMOT_MAX_AXIS; a++) { + if (p->joints_of_axis[a] & (1u << j)) { return a; } + } + return -1; +} + +int kinematicsUserOrientAxes(KinematicsUserContext* ctx, const double* seed, + int axes[3], int head[3]) +{ + static const char letters[] = "XYZABCUVW"; + const kins_ops *ops; + double j[EMCMOT_MAX_JOINTS]; + unsigned int table_mask = 0, head_mask = 0; + int joints[2] = {-1, -1}; + int i, r = -1; + + if (!axes || !head) return -1; + for (i = 0; i < 3; i++) { axes[i] = head[i] = -1; } + if (!ctx || !ctx->initialized || ctx->rt_only || !seed) return -1; + ops = ctx->info.ops[ctx->ktype]; + if (!ops->tool || !ops->work) return -1; + refresh(ctx); + pad_joints(ctx, seed, j); + frame_ctx = ctx; + if (toolFrameWorkJoints(frame_work, ctx->num_joints, j, &table_mask) == 0 + && toolFrameWorkJoints(frame_tool, ctx->num_joints, j, &head_mask) == 0 + && !(table_mask & head_mask)) { + int tables = __builtin_popcount(table_mask), heads = __builtin_popcount(head_mask); + if (heads == 2 && tables == 0) { + r = toolFrameOrientJoints(frame_tool, ctx->num_joints, j, &joints[0], &joints[1]); + head[0] = head[1] = 1; + } else if (tables == 2 && heads == 0) { + r = toolFrameOrientJoints(frame_work, ctx->num_joints, j, &joints[0], &joints[1]); + head[0] = head[1] = 0; + } else if (tables == 1 && heads == 1) { + joints[0] = __builtin_ctz(table_mask); + joints[1] = __builtin_ctz(head_mask); + head[0] = 0; + head[1] = 1; + r = 0; + } else if (tables + heads == 3) { + // three rotaries: the tables first, each group in joint order + int n = 0, jn; + for (jn = 0; jn < ctx->num_joints; jn++) { + if (table_mask & (1u << jn)) { axes[n] = jn; head[n++] = 0; } + } + for (jn = 0; jn < ctx->num_joints; jn++) { + if (head_mask & (1u << jn)) { axes[n] = jn; head[n++] = 1; } + } + frame_ctx = NULL; + for (n = 0; n < 3; n++) { + if (ops->orient && strlen(ops->orient) >= 3) { + const char *at = strchr(letters, toupper((unsigned char)ops->orient[n])); + axes[n] = at ? (int)(at - letters) : -1; + } else { + axes[n] = joint_letter(&ctx->params, axes[n]); + } + } + if (axes[0] < 0 || axes[1] < 0 || axes[2] < 0) { + for (i = 0; i < 3; i++) { axes[i] = head[i] = -1; } + return -1; + } + return 3; + } else if (heads > 3 && tables == 0) { + // an arm: the wrist is one of many joints that turn the tool, + // and the pose gives the orientation as A B C + for (i = 0; i < 3; i++) { axes[i] = 3 + i; head[i] = 1; } + frame_ctx = NULL; + return 3; + } + } + frame_ctx = NULL; + for (i = 0; i < 2 && r == 0; i++) { + if (ops->orient && ops->orient[0] && ops->orient[1]) { + const char *at = strchr(letters, toupper((unsigned char)ops->orient[i])); + axes[i] = at ? (int)(at - letters) : -1; + } else { + axes[i] = joint_letter(&ctx->params, joints[i]); + } + if (axes[i] < 0) { r = -1; } + } + if (r != 0) { + axes[0] = axes[1] = head[0] = head[1] = -1; + return -1; + } + return 2; +} + KinematicsUserContext* kinematicsUserInitString(const char* kinematics, int num_joints, int comp_id, diff --git a/src/emc/rs274ngc/interp_array.cc b/src/emc/rs274ngc/interp_array.cc index b9906756047..31ac55ecb39 100644 --- a/src/emc/rs274ngc/interp_array.cc +++ b/src/emc/rs274ngc/interp_array.cc @@ -229,7 +229,7 @@ const int Interp::required_parameters[] = { const int Interp::readonly_parameters[] = { 5021, 5022, 5023, 5024, 5025, 5026, 5027, 5028, 5029, // machine X Y ... W - 5071, 5072, 5073, 5074, 5075, 5076, 5077, 5078, 5079, 5080, // G53.2 pose X Y ... W, valid + 5071, 5072, 5073, 5074, 5075, 5076, 5077, 5078, 5079, 5080, // G53.2 pose X Y Z, rotaries 1 2 3, 0 0 0, valid 5400, // tool toolno 5401, // tool x offset 5402, // tool y offset diff --git a/src/emc/rs274ngc/interp_convert.cc b/src/emc/rs274ngc/interp_convert.cc index 852b7e4f337..a509812ae80 100644 --- a/src/emc/rs274ngc/interp_convert.cc +++ b/src/emc/rs274ngc/interp_convert.cc @@ -5740,7 +5740,8 @@ int Interp::convert_straight(int move, //!< either G_0 or G_1 CHP(find_ends(block, settings, &end_x, &end_y, &end_z, &AA_end, &BB_end, &CC_end, &u_end, &v_end, &w_end)); if (tool_vector) { - CHP(tool_vector_ends(block, settings, &AA_end, &BB_end, &CC_end)); + double *rotary_end[6] = {&AA_end, &BB_end, &CC_end, &u_end, &v_end, &w_end}; + CHP(tool_vector_ends(block, settings, rotary_end)); } if (move == G_1) { @@ -6641,7 +6642,7 @@ static int kins_type_info_available() return 0; } -// the type carrying a KINSTYPE_ flag, or -1 when the module declares none; +// the lowest type carrying a KINSTYPE_ flag, or -1 when the module declares none; // -1 for a type is "no information", and it matches every flag, so it must // be excluded before the bit test int flagged_kins_type(int flag) @@ -6711,10 +6712,14 @@ int Interp::convert_tool_length_offset(int g_code, //!< g_code being execu (_("Cannot change tool offset with cutter radius compensation on"))); if (g_code == G_43_4 || g_code == G_43_5) { int primary = flagged_kins_type(KINSTYPE_PRIMARY); + int now = GET_EXTERNAL_KINS_TYPE_FLAGS(settings->kins_type); // G43.4 is G43 on the module's working transform: switch first, then // apply the offset, as if the switch line had run and drained. With // no kinematics attached there is nothing to switch to. G43.5 is // the same, and the lines after it may give the tool axis as I J K. + // A module with a working transform per tool head flags each one + // primary: the one in force stays, from any other type the lowest. + if (now >= 0 && (now & KINSTYPE_PRIMARY)) { primary = settings->kins_type; } CHKS(primary < 0 && kins_type_info_available(), NCE_NO_PRIMARY_KINEMATICS_TYPE); if (primary >= 0 && primary != settings->kins_type) { // the switch keeps the joints and moves the point, so the point @@ -6844,12 +6849,12 @@ int Interp::convert_tool_length_offset(int g_code, //!< g_code being execu in_program.tran.x = USER_TO_PROGRAM_LEN(point.tran.x); in_program.tran.y = USER_TO_PROGRAM_LEN(point.tran.y); in_program.tran.z = USER_TO_PROGRAM_LEN(point.tran.z); - in_program.a = USER_TO_PROGRAM_ANG(point.a); - in_program.b = USER_TO_PROGRAM_ANG(point.b); - in_program.c = USER_TO_PROGRAM_ANG(point.c); - in_program.u = USER_TO_PROGRAM_LEN(point.u); - in_program.v = USER_TO_PROGRAM_LEN(point.v); - in_program.w = USER_TO_PROGRAM_LEN(point.w); + in_program.a = USER_TO_PROGRAM_AX(AXIS_A, point.a); + in_program.b = USER_TO_PROGRAM_AX(AXIS_B, point.b); + in_program.c = USER_TO_PROGRAM_AX(AXIS_C, point.c); + in_program.u = USER_TO_PROGRAM_AX(AXIS_U, point.u); + in_program.v = USER_TO_PROGRAM_AX(AXIS_V, point.v); + in_program.w = USER_TO_PROGRAM_AX(AXIS_W, point.w); USE_TOOL_LENGTH_OFFSET(tool_offset, in_program); } else { double dx, dy, dz; diff --git a/src/emc/rs274ngc/interp_internal.hh b/src/emc/rs274ngc/interp_internal.hh index 9481e67a731..7e2f9ec0a96 100644 --- a/src/emc/rs274ngc/interp_internal.hh +++ b/src/emc/rs274ngc/interp_internal.hh @@ -808,9 +808,9 @@ struct setup unsigned g68_seq_have; // bit per Q received int g68_seq_r_q; // the P2 block that gave R, or -1 double g68_seq_word[4][7]; // per Q: x y z i j k r - // the pose G53.2 last solved, in program words, for #<_orient_a> and kin + // the pose G53.2 last solved, in program words, for #<_orient_x> and kin bool orient_valid; - double orient_pose[6]; // x y z a b c + double orient_pose[6]; // x y z, the rotaries in orient order // the kinematics, for G68.3 and the orientation moves: loaded on first // use through the non-realtime loader, on a HAL component of our own void *kins_ctx; // KinematicsUserContext diff --git a/src/emc/rs274ngc/interp_namedparams.cc b/src/emc/rs274ngc/interp_namedparams.cc index e645bab91a2..6c2951cb924 100644 --- a/src/emc/rs274ngc/interp_namedparams.cc +++ b/src/emc/rs274ngc/interp_namedparams.cc @@ -59,13 +59,19 @@ enum predefined_named_parameters { NP_LINE, NP_MOTION_MODE, NP_KINS_TYPE, + NP_KINS_ORIENT_1, + NP_KINS_ORIENT_2, + NP_KINS_ORIENT_3, + NP_KINS_ORIENT_1_HEAD, + NP_KINS_ORIENT_2_HEAD, + NP_KINS_ORIENT_3_HEAD, NP_ORIENT_VALID, NP_ORIENT_X, NP_ORIENT_Y, NP_ORIENT_Z, - NP_ORIENT_A, - NP_ORIENT_B, - NP_ORIENT_C, + NP_ORIENT_ROT1, + NP_ORIENT_ROT2, + NP_ORIENT_ROT3, NP_PLANE, NP_CCOMP, NP_METRIC, @@ -553,6 +559,23 @@ int Interp::lookup_named_param(const char *nameBuf, *value = _setup.kins_type; break; + case NP_KINS_ORIENT_1: // _kins_orient_1 and kin: the axes that orient the tool + case NP_KINS_ORIENT_2: + case NP_KINS_ORIENT_3: + case NP_KINS_ORIENT_1_HEAD: + case NP_KINS_ORIENT_2_HEAD: + case NP_KINS_ORIENT_3_HEAD: + { + int axes[3], head[3]; + kins_orient(&_setup, axes, head); + if (cmd <= NP_KINS_ORIENT_3) { + *value = axes[cmd - NP_KINS_ORIENT_1]; + } else { + *value = head[cmd - NP_KINS_ORIENT_1_HEAD]; + } + } + break; + case NP_ORIENT_VALID: // _orient_valid: G53.2 has solved a pose *value = _setup.orient_valid; break; @@ -560,9 +583,9 @@ int Interp::lookup_named_param(const char *nameBuf, case NP_ORIENT_X: // _orient_x and kin: the pose G53.2 last solved case NP_ORIENT_Y: case NP_ORIENT_Z: - case NP_ORIENT_A: - case NP_ORIENT_B: - case NP_ORIENT_C: + case NP_ORIENT_ROT1: + case NP_ORIENT_ROT2: + case NP_ORIENT_ROT3: if (!_setup.orient_valid) { ERS(_("no G53.2 has solved an orientation yet")); } @@ -927,14 +950,24 @@ int Interp::init_named_parameters() // kinematics selected by G12.1 P- / G13.1, 0 when none has been selected init_readonly_param("_kins_type", NP_KINS_TYPE, PA_USE_LOOKUP); + // the axes that orient the tool on that type, 0 X to 8 W, first rotation + // then second, and whether each turns the head (1) or the table (0); -1 + // where the type does not orient with two rotaries + init_readonly_param("_kins_orient_1", NP_KINS_ORIENT_1, PA_USE_LOOKUP); + init_readonly_param("_kins_orient_2", NP_KINS_ORIENT_2, PA_USE_LOOKUP); + init_readonly_param("_kins_orient_3", NP_KINS_ORIENT_3, PA_USE_LOOKUP); + init_readonly_param("_kins_orient_1_head", NP_KINS_ORIENT_1_HEAD, PA_USE_LOOKUP); + init_readonly_param("_kins_orient_2_head", NP_KINS_ORIENT_2_HEAD, PA_USE_LOOKUP); + init_readonly_param("_kins_orient_3_head", NP_KINS_ORIENT_3_HEAD, PA_USE_LOOKUP); + // the pose G53.2 last solved: 1.0 once one has been, and its words init_readonly_param("_orient_valid", NP_ORIENT_VALID, PA_USE_LOOKUP); init_readonly_param("_orient_x", NP_ORIENT_X, PA_USE_LOOKUP); init_readonly_param("_orient_y", NP_ORIENT_Y, PA_USE_LOOKUP); init_readonly_param("_orient_z", NP_ORIENT_Z, PA_USE_LOOKUP); - init_readonly_param("_orient_a", NP_ORIENT_A, PA_USE_LOOKUP); - init_readonly_param("_orient_b", NP_ORIENT_B, PA_USE_LOOKUP); - init_readonly_param("_orient_c", NP_ORIENT_C, PA_USE_LOOKUP); + init_readonly_param("_orient_rot1", NP_ORIENT_ROT1, PA_USE_LOOKUP); + init_readonly_param("_orient_rot2", NP_ORIENT_ROT2, PA_USE_LOOKUP); + init_readonly_param("_orient_rot3", NP_ORIENT_ROT3, PA_USE_LOOKUP); // G17/18/19/17.1/18.1/19.1 -> return 170/180/190/171/181/191 init_readonly_param("_plane", NP_PLANE, PA_USE_LOOKUP); diff --git a/src/emc/rs274ngc/interp_workplane.cc b/src/emc/rs274ngc/interp_workplane.cc index d1e626df12f..4eac723ba1e 100644 --- a/src/emc/rs274ngc/interp_workplane.cc +++ b/src/emc/rs274ngc/interp_workplane.cc @@ -605,10 +605,50 @@ int Interp::kins_load(setup_pointer s) CHKS((!ctx), _("kinematics module %s cannot be loaded here"), s->kins_module); s->kins_ctx = ctx; for (int i = 0; i < EMCMOT_MAX_JOINTS; i++) { s->kins_seed[i] = 0.0; } + CHP(kins_check_orient(s)); } return INTERP_OK; } +// Every type the module evaluates here orients the tool with angular axes: +// a type whose rotaries are letters the INI file makes LINEAR would have +// G43.5 and G68.2 write degrees into a length. +int Interp::kins_check_orient(setup_pointer s) +{ + static const char letters[] = "XYZABCUVW"; + KinematicsUserContext *ctx = KINS_CTX(s); + double zero[EMCMOT_MAX_JOINTS] = {0}; + int t, i, n, axes[3], head[3]; + + for (t = 0; t < kinematicsUserGetNumTypes(ctx); t++) { + if (kinematicsUserSetType(ctx, t) != 0) { continue; } + n = kinematicsUserOrientAxes(ctx, zero, axes, head); + for (i = 0; i < n; i++) { + if (axisKindsAngular(s->axis_kinds, axes[i])) { continue; } + kins_release(s); + ERS(_("kinematics type %d of %s orients the tool with %c, which [AXIS_%c] TYPE makes LINEAR"), + t, s->kins_module, letters[axes[i]], letters[axes[i]]); + } + } + return INTERP_OK; +} + +// The axes that orient the tool on the kinematics type the program is in, +// at the joints it stands in: axis numbers 0 X to 8 W, first rotation then +// second, a robot's wrist A B C, and 1 for a head, 0 for a table. All -1 +// where the type turns other rotaries, or no module can be evaluated here. +void Interp::kins_orient(setup_pointer s, int axes[3], int head[3]) +{ + void *vctx; + double now[EMCMOT_MAX_JOINTS]; + int i; + + for (i = 0; i < 3; i++) { axes[i] = head[i] = -1; } + if (kins_context(s, &vctx) != INTERP_OK) { return; } + if (current_joints(s, (KinematicsUserContext *)vctx, now) != INTERP_OK) { return; } + kinematicsUserOrientAxes((KinematicsUserContext *)vctx, now, axes, head); +} + // the loaded module, on the kinematics type the program is in int Interp::kins_context(setup_pointer s, void **out) { @@ -637,12 +677,12 @@ void Interp::kins_set_tool(void *vctx, const EmcPose *offset) tool.tran.x = PROGRAM_TO_USER_LEN(offset->tran.x); tool.tran.y = PROGRAM_TO_USER_LEN(offset->tran.y); tool.tran.z = PROGRAM_TO_USER_LEN(offset->tran.z); - tool.a = PROGRAM_TO_USER_ANG(offset->a); - tool.b = PROGRAM_TO_USER_ANG(offset->b); - tool.c = PROGRAM_TO_USER_ANG(offset->c); - tool.u = PROGRAM_TO_USER_LEN(offset->u); - tool.v = PROGRAM_TO_USER_LEN(offset->v); - tool.w = PROGRAM_TO_USER_LEN(offset->w); + tool.a = PROGRAM_TO_USER_AX(AXIS_A, offset->a); + tool.b = PROGRAM_TO_USER_AX(AXIS_B, offset->b); + tool.c = PROGRAM_TO_USER_AX(AXIS_C, offset->c); + tool.u = PROGRAM_TO_USER_AX(AXIS_U, offset->u); + tool.v = PROGRAM_TO_USER_AX(AXIS_V, offset->v); + tool.w = PROGRAM_TO_USER_AX(AXIS_W, offset->w); kinematicsUserSetTool((KinematicsUserContext *)vctx, &tool); } @@ -668,12 +708,12 @@ void Interp::current_machine_pose(setup_pointer s, EmcPose *pose) pose->tran.x = PROGRAM_TO_USER_LEN(abs_pos[0]); pose->tran.y = PROGRAM_TO_USER_LEN(abs_pos[1]); pose->tran.z = PROGRAM_TO_USER_LEN(abs_pos[2]); - pose->a = PROGRAM_TO_USER_ANG(abs_pos[3]); - pose->b = PROGRAM_TO_USER_ANG(abs_pos[4]); - pose->c = PROGRAM_TO_USER_ANG(abs_pos[5]); - pose->u = PROGRAM_TO_USER_LEN(abs_pos[6]); - pose->v = PROGRAM_TO_USER_LEN(abs_pos[7]); - pose->w = PROGRAM_TO_USER_LEN(abs_pos[8]); + pose->a = PROGRAM_TO_USER_AX(AXIS_A, abs_pos[3]); + pose->b = PROGRAM_TO_USER_AX(AXIS_B, abs_pos[4]); + pose->c = PROGRAM_TO_USER_AX(AXIS_C, abs_pos[5]); + pose->u = PROGRAM_TO_USER_AX(AXIS_U, abs_pos[6]); + pose->v = PROGRAM_TO_USER_AX(AXIS_V, abs_pos[7]); + pose->w = PROGRAM_TO_USER_AX(AXIS_W, abs_pos[8]); } // and back: a machine pose as program coordinates, through the chain @@ -684,12 +724,12 @@ void Interp::machine_pose_to_program(setup_pointer s, const EmcPose *pose, doubl USER_TO_PROGRAM_LEN(pose->tran.y), USER_TO_PROGRAM_LEN(pose->tran.z), &prog[0], &prog[1], &prog[2]); - prog[3] = USER_TO_PROGRAM_ANG(pose->a) - s->tool_offset.a - s->AA_origin_offset - s->AA_axis_offset; - prog[4] = USER_TO_PROGRAM_ANG(pose->b) - s->tool_offset.b - s->BB_origin_offset - s->BB_axis_offset; - prog[5] = USER_TO_PROGRAM_ANG(pose->c) - s->tool_offset.c - s->CC_origin_offset - s->CC_axis_offset; - prog[6] = USER_TO_PROGRAM_LEN(pose->u) - s->tool_offset.u - s->u_origin_offset - s->u_axis_offset; - prog[7] = USER_TO_PROGRAM_LEN(pose->v) - s->tool_offset.v - s->v_origin_offset - s->v_axis_offset; - prog[8] = USER_TO_PROGRAM_LEN(pose->w) - s->tool_offset.w - s->w_origin_offset - s->w_axis_offset; + prog[3] = USER_TO_PROGRAM_AX(AXIS_A, pose->a) - s->tool_offset.a - s->AA_origin_offset - s->AA_axis_offset; + prog[4] = USER_TO_PROGRAM_AX(AXIS_B, pose->b) - s->tool_offset.b - s->BB_origin_offset - s->BB_axis_offset; + prog[5] = USER_TO_PROGRAM_AX(AXIS_C, pose->c) - s->tool_offset.c - s->CC_origin_offset - s->CC_axis_offset; + prog[6] = USER_TO_PROGRAM_AX(AXIS_U, pose->u) - s->tool_offset.u - s->u_origin_offset - s->u_axis_offset; + prog[7] = USER_TO_PROGRAM_AX(AXIS_V, pose->v) - s->tool_offset.v - s->v_origin_offset - s->v_axis_offset; + prog[8] = USER_TO_PROGRAM_AX(AXIS_W, pose->w) - s->tool_offset.w - s->w_origin_offset - s->w_axis_offset; } // whether two machine points are the same, to a hair either way @@ -898,6 +938,21 @@ int Interp::convert_work_plane_from_tool(block_pointer block, setup_pointer s) return work_plane_set(s, G_68_3, origin, rotation); } +// The rotary letters a solution for the kinematics type in force is +// written into, as axis numbers: those it orients the tool with, else the +// A B C of the pose. Returns how many. +static int orienting_letters(KinematicsUserContext *ctx, const double *now, int orienting[3]) +{ + int head[3]; + int n = kinematicsUserOrientAxes(ctx, now, orienting, head); + + if (n > 0) { return n; } + orienting[0] = 3; + orienting[1] = 4; + orienting[2] = 5; + return 3; +} + // G53.1, G53.2, G53.3 and G53.6: the rotaries to the plane's normal. G53.1 // turns the rotaries alone, in joint space; G53.6 keeps the tool centre point, // a Cartesian move; G53.3 goes to X Y Z in the plane; G53.2 only publishes the @@ -941,19 +996,34 @@ int Interp::convert_orient_tool(int code, block_pointer block, setup_pointer s) for (i = 0; i < EMCMOT_MAX_JOINTS; i++) { s->kins_seed[i] = sol[i]; } machine_pose_to_program(s, &end_pose, end_prog); + int orienting[3]; + int count = orienting_letters(ctx, now, orienting); + if (code == G_53_2) { - // STAY: solve only, nothing moves. The pose goes to the named - // parameters #<_orient_x> and kin and to #5071-#5080, for the - // program to use in a move of its own making, the way - // Heidenhain's STAY fills Q120-122. The machine state does not - // change. - for (i = 0; i < 6; i++) { s->orient_pose[i] = end_prog[i]; } + // STAY: solve only, nothing moves. X Y Z and the rotaries in the + // order the type orients with go to the named parameters + // #<_orient_x> and kin and to #5071-#5080, for the program to use + // in a move of its own making, the way Heidenhain's STAY fills + // Q120-122. The machine state does not change. + for (i = 0; i < 3; i++) { s->orient_pose[i] = end_prog[i]; } + for (i = 0; i < 3; i++) { + s->orient_pose[3 + i] = (i < count) ? end_prog[orienting[i]] : 0.0; + } s->orient_valid = true; - for (i = 0; i < 9; i++) { s->parameters[5071 + i] = end_prog[i]; } + for (i = 0; i < 6; i++) { s->parameters[5071 + i] = s->orient_pose[i]; } + for (i = 6; i < 9; i++) { s->parameters[5071 + i] = 0.0; } s->parameters[5080] = 1.0; return INTERP_OK; } + // the rotaries the solution turns, in the letters the type orients + // with; every other axis stays where it is + double rot[6] = {s->AA_current, s->BB_current, s->CC_current, + s->u_current, s->v_current, s->w_current}; + for (i = 0; i < count; i++) { + if (orienting[i] >= 3) { rot[orienting[i] - 3] = end_prog[orienting[i]]; } + } + write_canon_state_tag(block, s); if (code == G_53_1) { // the rotaries alone: the linear joints are where they are, since @@ -969,28 +1039,28 @@ int Interp::convert_orient_tool(int code, block_pointer block, setup_pointer s) } else if (code == G_53_6) { // the tool centre point stays: a Cartesian move of the rotaries STRAIGHT_TRAVERSE(block->line_number, s->current_x, s->current_y, s->current_z, - end_prog[3], end_prog[4], end_prog[5], - s->u_current, s->v_current, s->w_current); + rot[0], rot[1], rot[2], rot[3], rot[4], rot[5]); } else { double x = block->x_flag ? block->x_number : s->current_x; double y = block->y_flag ? block->y_number : s->current_y; double z = block->z_flag ? block->z_number : s->current_z; JOINT_TRAVERSE(block->line_number, NULL, 0, x, y, z, - end_prog[3], end_prog[4], end_prog[5], - s->u_current, s->v_current, s->w_current); + rot[0], rot[1], rot[2], rot[3], rot[4], rot[5]); s->current_x = x; s->current_y = y; s->current_z = z; } - s->AA_current = end_prog[3]; - s->BB_current = end_prog[4]; - s->CC_current = end_prog[5]; if (code == G_53_1) { - s->u_current = end_prog[6]; - s->v_current = end_prog[7]; - s->w_current = end_prog[8]; + // the joints went where the solver put them, every letter with them + for (i = 0; i < 6; i++) { rot[i] = end_prog[3 + i]; } } + s->AA_current = rot[0]; + s->BB_current = rot[1]; + s->CC_current = rot[2]; + s->u_current = rot[3]; + s->v_current = rot[4]; + s->w_current = rot[5]; return INTERP_OK; } @@ -1159,19 +1229,21 @@ int Interp::orient_solve(setup_pointer s, void *vctx, const PmCartesian *axis, c // G43.5: I J K on a G0 or G1 line are the tool axis, tip towards holder, in // the coordinate system the line's X Y Z are in. The rotaries come from the // tool frame inverse, every orienting joint free, the nearest pose, as program -// rotary coordinates so a rotary offset is right by construction. -int Interp::tool_vector_ends(block_pointer block, setup_pointer s, double *a, double *b, double *c) +// coordinates of the axes the kinematics type orients with (A B C U V W +// ends, 0 A to 5 W), so a rotary offset is right by construction. +int Interp::tool_vector_ends(block_pointer block, setup_pointer s, double *rotary_end[6]) { + static const char letters[] = "XYZABCUVW"; void *vctx; KinematicsUserContext *ctx; double now[EMCMOT_MAX_JOINTS], sol[EMCMOT_MAX_JOINTS]; double v[3], prog[9]; + const bool rotary_flag[6] = {block->a_flag, block->b_flag, block->c_flag, + block->u_flag, block->v_flag, block->w_flag}; PmCartesian axis; EmcPose pose; int i; - CHKS((block->a_flag || block->b_flag || block->c_flag), - _("G43.5: a tool vector and rotary words on one line give the orientation twice")); v[0] = block->i_flag ? block->i_number : 0.0; v[1] = block->j_flag ? block->j_number : 0.0; v[2] = block->k_flag ? block->k_number : 0.0; @@ -1181,6 +1253,16 @@ int Interp::tool_vector_ends(block_pointer block, setup_pointer s, double *a, do CHKS((kinematicsUserIsIdentity(ctx)), _("G43.5: a tool vector needs a kinematics type that describes the machine; select it with G12.1 first")); CHP(current_joints(s, ctx, now)); + int orienting[3]; + int count = orienting_letters(ctx, now, orienting); + for (i = 0; i < count; i++) { + CHKS((orienting[i] < 3), + _("G43.5: kinematics type %d orients the tool with %c, not a rotary axis"), + s->kins_type, letters[orienting[i]]); + CHKS((rotary_flag[orienting[i] - 3]), + _("G43.5: a tool vector and a %c word on one line give the orientation twice"), + letters[orienting[i]]); + } if (block->g_modes[GM_MODAL_0] == G_53) { axis.x = v[0]; axis.y = v[1]; @@ -1197,9 +1279,9 @@ int Interp::tool_vector_ends(block_pointer block, setup_pointer s, double *a, do _("G43.5: the kinematics cannot place the orientation it found")); for (i = 0; i < EMCMOT_MAX_JOINTS; i++) { s->kins_seed[i] = sol[i]; } machine_pose_to_program(s, &pose, prog); - *a = prog[3]; - *b = prog[4]; - *c = prog[5]; + for (i = 0; i < count; i++) { + *rotary_end[orienting[i] - 3] = prog[orienting[i]]; + } return INTERP_OK; } @@ -1293,7 +1375,7 @@ int Interp::letters_name_joints(const char *name, setup_pointer s, const struct CHKS((!p), _("%s: the kinematics module gives no joint mapping"), name); for (a = 0; a < 9; a++) { - const int angular = (a >= 3 && a <= 5); + const int angular = axisKindsAngular(s->axis_kinds, a); for (j = 0; j < njoints; j++) { int turns; if (!(p->joints_of_axis[a] & (1 << j))) { continue; } @@ -1325,12 +1407,11 @@ int Interp::slide_words(const char *name, setup_pointer s, void *vctx, const str return machine_frame_joints(name, s, ctx, flags, words, joints); } for (a = 0; a < 9; a++) { - const int angular = (a >= 3 && a <= 5); double value; if (!flags[a]) { continue; } CHKS((p->joints_of_axis[a] == 0), _("%s: %c is not a joint of this kinematics"), name, letters[a]); - value = angular ? PROGRAM_TO_USER_ANG(words[a]) : PROGRAM_TO_USER_LEN(words[a]); + value = PROGRAM_TO_USER_AX(a, words[a]); for (j = 0; j < njoints; j++) { if (p->joints_of_axis[a] & (1 << j)) { joints[j] = value; } } @@ -1358,9 +1439,8 @@ int Interp::machine_frame_joints(const char *name, setup_pointer s, void *vctx, coord[3] = &pose.a; coord[4] = &pose.b; coord[5] = &pose.c; coord[6] = &pose.u; coord[7] = &pose.v; coord[8] = &pose.w; for (a = 0; a < 9; a++) { - const int angular = (a >= 3 && a <= 5); if (!flags[a]) { continue; } - *coord[a] = angular ? PROGRAM_TO_USER_ANG(words[a]) : PROGRAM_TO_USER_LEN(words[a]); + *coord[a] = PROGRAM_TO_USER_AX(a, words[a]); } for (pass = 0; pass < 8; pass++) { double prev[EMCMOT_MAX_JOINTS], worst = 0.0; @@ -1505,9 +1585,7 @@ int Interp::convert_home_slides(int code, block_pointer block, setup_pointer s) CHP(current_joints(s, ctx, joints)); for (a = 0; a < 9; a++) { - const int angular = (a >= 3 && a <= 5); - home[a] = angular ? USER_TO_PROGRAM_ANG(parameters[base + a]) - : USER_TO_PROGRAM_LEN(parameters[base + a]); + home[a] = USER_TO_PROGRAM_AX(a, parameters[base + a]); given += flags[a]; } diff --git a/src/emc/rs274ngc/rs274ngc_interp.hh b/src/emc/rs274ngc/rs274ngc_interp.hh index 65d7ab0261e..d42bffa321a 100644 --- a/src/emc/rs274ngc/rs274ngc_interp.hh +++ b/src/emc/rs274ngc/rs274ngc_interp.hh @@ -379,7 +379,9 @@ public: int convert_orient_tool(int code, block_pointer block, setup_pointer settings); int orient_solve(setup_pointer settings, void *ctx, const PmCartesian *axis, const PmCartesian *xdir, int p, int q, const double *now, double *joints, const char *name); - int tool_vector_ends(block_pointer block, setup_pointer settings, double *a, double *b, double *c); + int tool_vector_ends(block_pointer block, setup_pointer settings, double *rotary_end[6]); + int kins_check_orient(setup_pointer s); + void kins_orient(setup_pointer s, int axes[3], int head[3]); int convert_ptp_joints(int code, int move, block_pointer block, setup_pointer settings); int convert_home_slides(int code, block_pointer block, setup_pointer settings); int convert_savehome_slides(int code, setup_pointer settings); diff --git a/src/emc/task/emccanon.cc b/src/emc/task/emccanon.cc index 74cca0814ce..cdc950016ca 100644 --- a/src/emc/task/emccanon.cc +++ b/src/emc/task/emccanon.cc @@ -1001,7 +1001,12 @@ static void kins_seed(KinematicsUserContext *ctx, const EmcPose *start) // position, or a sweep of arc is seen every few degrees or centimetres static int kins_samples(const EmcPose *start, const EmcPose *end, double sweep_deg) { - double rot = fmax(fabs(end->a - start->a), fmax(fabs(end->b - start->b), fabs(end->c - start->c))); + const double turn[6] = {end->a - start->a, end->b - start->b, end->c - start->c, + end->u - start->u, end->v - start->v, end->w - start->w}; + double rot = 0.0; + for (int n = 0; n < 6; n++) { + if (AXIS_ANG(n + 3)) { rot = fmax(rot, fabs(turn[n])); } + } double lin = sqrt(pow(end->tran.x - start->tran.x, 2) + pow(end->tran.y - start->tran.y, 2) + pow(end->tran.z - start->tran.z, 2)); int n = 3 + (int)ceil(rot / 10.0) + (int)ceil(lin / 50.0) + (int)ceil(sweep_deg / 10.0); diff --git a/src/emc/tp/tp.c b/src/emc/tp/tp.c index 33499c60bab..8c700ce339e 100644 --- a/src/emc/tp/tp.c +++ b/src/emc/tp/tp.c @@ -2182,10 +2182,24 @@ int tpAddJointLine(TP_STRUCT * const tp, const double *start, const double *end, if (tc.target < TP_POS_EPSILON) { return TP_ERR_ZERO_LENGTH; } + // it runs in joint units: the max velocity slider caps the tool as canon + // measures a straight move, along the chord between the ends: X Y Z, + // else U V W, and not at all when only the rotaries move + { + double dx = world_end.tran.x - jl->world_start.tran.x; + double dy = world_end.tran.y - jl->world_start.tran.y; + double dz = world_end.tran.z - jl->world_start.tran.z; + double du = world_end.u - jl->world_start.u; + double dv = world_end.v - jl->world_start.v; + double dw = world_end.w - jl->world_start.w; + double chord = pmSqrt(dx * dx + dy * dy + dz * dz); + if (chord < TP_POS_EPSILON) { + chord = pmSqrt(du * du + dv * dv + dw * dw); + } + tc.vlimit_scale = chord < TP_POS_EPSILON ? 0.0 : tc.target / chord; + } tc.nominal_length = tc.target; tcClampVelocityByLength(&tc); - // it runs in joint units, so the max velocity slider does not cap it - tc.vlimit_scale = 0.0; tc.indexer_jnum = -1; tcSetTermCond(&tc, NULL, TC_TERM_COND_STOP); @@ -3526,9 +3540,21 @@ STATIC tp_err_t tpHandleAbort(TP_STRUCT * const tp, TC_STRUCT * const tc, if( MOTION_ID_VALID(tp->spindle.waiting_for_index) || MOTION_ID_VALID(tp->spindle.waiting_for_atspeed) || (tc->currentvel == 0.0 && (!nexttc || nexttc->currentvel == 0.0))) { + /* stopped inside a joint interpolated segment: the machine is + where the joints put it, which the servo thread found from them + last cycle, not on the chord this planner reports; the joints + are handed out as an end so that they stay where they are */ + double stop_joints[EMCMOT_MAX_JOINTS] = {0}; + int joint_stop = tc->active && tcGetJointPos(tc, stop_joints) > 0; tpReleaseQueuedPlanners(tp); tcqInit(&tp->queue); tpForgetJoints(tp); + if (joint_stop) { + int i; + for (i = 0; i < EMCMOT_MAX_JOINTS; i++) { tp->joint_end[i] = stop_joints[i]; } + tp->joint_end_valid = 1; + tp->currentPos = emcmotStatus->carte_pos_cmd; + } tp->goalPos = tp->currentPos; tp->done = 1; tp->depth = tp->activeDepth = 0; diff --git a/tests/axis-type/axis-type.hal b/tests/axis-type/axis-type.hal index 0406391056f..7b6a4ddb2a8 100644 --- a/tests/axis-type/axis-type.hal +++ b/tests/axis-type/axis-type.hal @@ -1,6 +1,6 @@ # HAL file for the axis type test -loadrt [KINS]KINEMATICS coordinates=xyzav +loadrt [KINS]KINEMATICS loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS addf motion-command-handler servo-thread diff --git a/tests/axis-type/axis-type.ini b/tests/axis-type/axis-type.ini index 4851966fd61..dad1d44c7e4 100644 --- a/tests/axis-type/axis-type.ini +++ b/tests/axis-type/axis-type.ini @@ -34,7 +34,7 @@ MAX_LINEAR_ACCELERATION = 50000 CYCLE_TIME = 0.100 [KINS] -KINEMATICS = trivkins +KINEMATICS = trivkins coordinates=xyzav JOINTS = 5 [AXIS_X] diff --git a/tests/axis-type/test-ui.py b/tests/axis-type/test-ui.py index 41984fcaff3..59f5181100c 100755 --- a/tests/axis-type/test-ui.py +++ b/tests/axis-type/test-ui.py @@ -113,6 +113,18 @@ def near(what, got, want, tol): near("A with V at F600 under the slider, seconds", secs, 1.0, 0.1) c.maxvel(400.0) +# the machine frame codes read V as an angle too, G20 or not; V wraps, so +# where it lands is read modulo a turn +mdi("G20 G53.5 G0 V250") +s.poll() +near("V after G20 G53.5 V250, modulo a turn", s.position[V] % 360.0, 250.0, 1e-6) +mdi("G21 G28.1") +mdi("G0 V255") +mdi("G20 G28.5") +s.poll() +near("V after G20 G28.5, modulo a turn", s.position[V] % 360.0, 250.0, 1e-6) +mdi("G21") + # V wraps: 350 then 10 goes on to 370 mdi("G0 V350") mdi("G0 V10") diff --git a/tests/kins-orient-linear/README b/tests/kins-orient-linear/README new file mode 100644 index 00000000000..674867e3a64 --- /dev/null +++ b/tests/kins-orient-linear/README @@ -0,0 +1,4 @@ +A kinematics type that orients the tool with an axis the INI file makes +LINEAR is refused: 5axiskins turns the tool with B and C, and here +[AXIS_B] TYPE is LINEAR. The interpreter refuses when it first loads the +module, the G43.5 vector below, with a message naming the type and B. diff --git a/tests/kins-orient-linear/checkresult b/tests/kins-orient-linear/checkresult new file mode 100755 index 00000000000..42526aa5579 --- /dev/null +++ b/tests/kins-orient-linear/checkresult @@ -0,0 +1,3 @@ +#!/bin/sh +# test-ui.py prints PASS once the refusal names B +grep -q "^PASS$" "$1" diff --git a/tests/kins-orient-linear/sim.hal b/tests/kins-orient-linear/sim.hal new file mode 100644 index 00000000000..e92c60eb526 --- /dev/null +++ b/tests/kins-orient-linear/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-orient-linear/test-ui.py b/tests/kins-orient-linear/test-ui.py new file mode 100755 index 00000000000..3d72ea20b34 --- /dev/null +++ b/tests/kins-orient-linear/test-ui.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +# 5axiskins orients with B and C; [AXIS_B] TYPE = LINEAR: see README. + +import linuxcnc +import os +import sys + +c = linuxcnc.command() +s = linuxcnc.stat() +e = linuxcnc.error_channel() + +c.state(linuxcnc.STATE_ESTOP_RESET) +c.state(linuxcnc.STATE_ON) +c.home(-1) +c.wait_complete() +c.mode(linuxcnc.MODE_MDI) +c.wait_complete() + +said = [] +for cmd in ("G12.1 P0", "G43.5 H1", "G0 X0 K1"): + c.mdi(cmd) + c.wait_complete(30) + while True: + m = e.poll() + if not m: + break + said.append(m) + +errors = [m[1] for m in said if m[0] in (linuxcnc.NML_ERROR, linuxcnc.OPERATOR_ERROR)] +print("errors: %s" % errors) +ok = any("orients the tool with B, which [AXIS_B] TYPE makes LINEAR" in m for m in errors) +c.state(linuxcnc.STATE_ESTOP) +for f in ("sim.var", "sim.var.bak"): + try: + os.unlink(f) + except OSError: + pass +print("PASS" if ok else "FAIL: no refusal naming B") +sys.exit(0 if ok else 1) diff --git a/tests/kins-orient-linear/test.ini b/tests/kins-orient-linear/test.ini new file mode 100644 index 00000000000..0ea12355fb5 --- /dev/null +++ b/tests/kins-orient-linear/test.ini @@ -0,0 +1,131 @@ +[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, 1 is identity, 2 is the userk template +KINEMATICS = 5axiskins coordinates=xyzbcw +JOINTS = 6 + +[HAL] +HALFILE = sim.hal + +[TRAJ] +COORDINATES = XYZBCW +LINEAR_UNITS = mm +ANGULAR_UNITS = deg +DEFAULT_LINEAR_VELOCITY = 200 +MAX_LINEAR_VELOCITY = 346 +MAX_LINEAR_ACCELERATION = 800 +DEFAULT_LINEAR_ACCELERATION = 800 +MAX_ANGULAR_VELOCITY = 360 + +[EMCMOT] +EMCMOT = motmod +SERVO_PERIOD = 1000000 +COMM_TIMEOUT = 4 + +[TASK] +TASK = milltask +CYCLE_TIME = 0.010 + +[EMCIO] +TOOL_TABLE = tool.tbl + +[AXIS_X] +MIN_LIMIT = -500 +MAX_LIMIT = 500 +MAX_VELOCITY = 200 +MAX_ACCELERATION = 800 + +[AXIS_Y] +MIN_LIMIT = -500 +MAX_LIMIT = 500 +MAX_VELOCITY = 200 +MAX_ACCELERATION = 800 + +[AXIS_Z] +MIN_LIMIT = -500 +MAX_LIMIT = 500 +MAX_VELOCITY = 200 +MAX_ACCELERATION = 800 + +[AXIS_B] +TYPE = LINEAR +MIN_LIMIT = -120 +MAX_LIMIT = 120 +MAX_VELOCITY = 60 +MAX_ACCELERATION = 200 + +[AXIS_C] +MIN_LIMIT = -36000 +MAX_LIMIT = 36000 +MAX_VELOCITY = 60 +MAX_ACCELERATION = 200 + +[AXIS_W] +MIN_LIMIT = -100 +MAX_LIMIT = 500 +MAX_VELOCITY = 200 +MAX_ACCELERATION = 800 + +[JOINT_0] +TYPE = LINEAR +MIN_LIMIT = -500 +MAX_LIMIT = 500 +MAX_VELOCITY = 200 +MAX_ACCELERATION = 800 +HOME_SEARCH_VEL = 0 +HOME_SEQUENCE = 0 + +[JOINT_1] +TYPE = LINEAR +MIN_LIMIT = -500 +MAX_LIMIT = 500 +MAX_VELOCITY = 200 +MAX_ACCELERATION = 800 +HOME_SEARCH_VEL = 0 +HOME_SEQUENCE = 0 + +[JOINT_2] +TYPE = LINEAR +MIN_LIMIT = -500 +MAX_LIMIT = 500 +MAX_VELOCITY = 200 +MAX_ACCELERATION = 800 +HOME_SEARCH_VEL = 0 +HOME_SEQUENCE = 0 + +[JOINT_3] +TYPE = ANGULAR +MIN_LIMIT = -120 +MAX_LIMIT = 120 +MAX_VELOCITY = 60 +MAX_ACCELERATION = 200 +HOME_SEARCH_VEL = 0 +HOME_SEQUENCE = 0 + +[JOINT_4] +TYPE = ANGULAR +MIN_LIMIT = -36000 +MAX_LIMIT = 36000 +MAX_VELOCITY = 60 +MAX_ACCELERATION = 200 +HOME_SEARCH_VEL = 0 +HOME_SEQUENCE = 0 + +[JOINT_5] +TYPE = LINEAR +MIN_LIMIT = -100 +MAX_LIMIT = 500 +MAX_VELOCITY = 200 +MAX_ACCELERATION = 800 +HOME_SEARCH_VEL = 0 +HOME_SEQUENCE = 0 diff --git a/tests/kins-orient-linear/test.sh b/tests/kins-orient-linear/test.sh new file mode 100755 index 00000000000..079fb121f31 --- /dev/null +++ b/tests/kins-orient-linear/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash -e +rm -f sim.var sim.var.bak +linuxcnc -r test.ini diff --git a/tests/kins-orient-linear/tool.tbl b/tests/kins-orient-linear/tool.tbl new file mode 100644 index 00000000000..d793e2d60ed --- /dev/null +++ b/tests/kins-orient-linear/tool.tbl @@ -0,0 +1 @@ +T1 P1 D0.0 Z12.5 ; diff --git a/tests/kins-switch/test-ui.py b/tests/kins-switch/test-ui.py index 44b73115b3c..ed23a791a73 100755 --- a/tests/kins-switch/test-ui.py +++ b/tests/kins-switch/test-ui.py @@ -378,6 +378,53 @@ def refused(cmd, needle): mdi("G49") refused("G0 X0 K1", "K word with no") +# ---- the axes that orient the tool --------------------------------------- +# +# 5axiskins turns the tool with a head: C with its axis fixed, B carried by +# it. The interpreter finds them from the tool frame and names them by the +# joint map, as axis numbers; the identity type orients with nothing. Under +# G43.5 a word of an axis that does not orient, W here, goes with a vector. + +def param(name): + drain() + c.mdi("(debug,#<%s>)" % name) + done(30) + deadline = time.time() + 5 + while time.time() < deadline: + m = e.poll() + if not m: + time.sleep(0.01) + continue + if m[0] == linuxcnc.OPERATOR_DISPLAY: + return float(m[1]) + error("#<%s> gave no value" % name) + return None + +ORIENT = ("_kins_orient_1", "_kins_orient_2", "_kins_orient_3", + "_kins_orient_1_head", "_kins_orient_2_head", "_kins_orient_3_head") +errors_before = errors +mdi("G12.1 P0") +got = [param(n) for n in ORIENT] +if got != [5, 4, -1, 1, 1, -1]: + error("on the 5-axis type the orienting axes read %s, not C then B, both heads" % (got,)) +mdi("G13.1") +got = [param(n) for n in ORIENT] +if got != [-1, -1, -1, -1, -1, -1]: + error("on the identity type the orienting axes read %s, not none" % (got,)) +mdi("G12.1 P0") +mdi("G0 X0 Y0 Z0 B0 C0 W0") +mdi("G43.5 H1") +with_w = mdi("G0 X0 Y0 Z0 K1 W2") +if abs(with_w[5] - 2) > 1e-6: + error("a vector with a W word left W at %.4f, not 2" % with_w[5]) +mdi("G0 W0") +mdi("G49") +said = drain() +if any(m[0] in (linuxcnc.NML_ERROR, linuxcnc.OPERATOR_ERROR) for m in said): + error("the orienting axes section reported %s" % (said,)) +elif errors == errors_before: + print("the orienting axes are C then B, heads, and W goes along with a vector") + # ---- a negative kinematics number is refused ----------------------------- drain() diff --git a/tests/ptp-machine-frame/README b/tests/ptp-machine-frame/README index 08480a0f1e2..ef9d659211a 100644 --- a/tests/ptp-machine-frame/README +++ b/tests/ptp-machine-frame/README @@ -6,10 +6,12 @@ template builds: XYZBC on five joints, joint 1 a slide slanted 30 degrees in the XY plane, so machine X and Y are made by joints 0 and 1 together. Type 0 is the carriage in machine coordinates, declared the machine frame type and not an identity; type 1 the tool tip with the head tilted about Y -and the tool length from the tool table; type 2 a plain identity. +and the tool length from the tool table; type 2 a plain identity; type 3 +the tip again, a second head, declared primary as well. The test checks that G13.1 and G49 select the machine frame type rather -than the identity, that G53.5 puts the carriage at a machine frame point, +than the identity, that G43.4 stays on a primary type selected with G12.1 +and from any other goes to the lowest numbered primary, that G53.5 puts the carriage at a machine frame point, the letters not given holding their machine coordinate and not their joint, from the machine frame type and from under the tilted tip kinematics alike, that G28.5 goes to a position stored on the machine diff --git a/tests/ptp-machine-frame/slantkins.comp b/tests/ptp-machine-frame/slantkins.comp index 80febbadea4..62574995943 100644 --- a/tests/ptp-machine-frame/slantkins.comp +++ b/tests/ptp-machine-frame/slantkins.comp @@ -15,6 +15,9 @@ by B and the tool length from the tool table along the tool axis, folded so that tip and carriage agree at B zero. type2 is a plain identity, the joints as the axes, declared identity. + +type3 is type1 again, declared primary as well, the way a machine with a +second tool head declares a working transform for each. """; pin out si32 dummy=0 "one pin, which halcompile requires"; option period no; @@ -130,6 +133,13 @@ static const kins_ops tip_ops = { .primary = 1, }; +// a second head: G43.4 stays on it once G12.1 has selected it +static const kins_ops second_head_ops = { + .forward = tip_forward, + .inverse = tip_inverse, + .primary = 1, +}; + int switchkinsSetup(kparms* kp, KS* kset0, KS* kset1, KS* kset2, KF* kfwd0, KF* kfwd1, KF* kfwd2, @@ -150,6 +160,7 @@ int switchkinsSetup(kparms* kp, switchkinsRegisterOps(0, &frame_ops); switchkinsRegisterOps(1, &tip_ops); switchkinsRegisterOps(2, &KINS_IDENTITY_OPS); + switchkinsRegisterOps(3, &second_head_ops); return 0; } diff --git a/tests/ptp-machine-frame/test-ui.py b/tests/ptp-machine-frame/test-ui.py index 5110681625d..1c9cc9bcb41 100755 --- a/tests/ptp-machine-frame/test-ui.py +++ b/tests/ptp-machine-frame/test-ui.py @@ -117,6 +117,17 @@ def expect_type(what, want): expect_type("G49", 0) mdi("G12.1 P1", "G13.1") expect_type("G12.1 P1 then G13.1", 0) + +# --- two primary types: G43.4 keeps the head G12.1 selected ------------------ +mdi("G12.1 P3", "G43.4 H1") +expect_type("G12.1 P3 then G43.4, the second head", 3) +mdi("G49") +expect_type("G49 from the second head", 0) +mdi("G12.1 P2", "G43.4 H1") +expect_type("G43.4 from the identity, the lowest", 1) +mdi("G12.1 P3", "G43.4 H1") +expect_type("G43.4 again after G12.1 P3", 3) +mdi("G49") drain() # --- G53.5 is the machine frame, not the slides ------------------------------ @@ -206,6 +217,48 @@ def expect_type(what, want): mdi("G49", "G0 B0", "G53 G0 X0 Y0 Z0") drain() +# --- an abort part way through a joint interpolated move -------------------- +# under the tip with B turning, the joints run on a line in joint space +# while the tip leaves the chord between the ends; stopped part way, the +# joints stay on their line, where the inverse of the chord point would put +# X some 3 mm off at 40 percent +start = mdi("G43.4 H1", "G0 X0 Y0 Z0 B0") +end = mdi("G53.4 G0 X100 B60") +mdi("G53.4 G0 X0 B0") +c.mdi("G53.4 G1 X100 B60 F6000") +deadline = time.time() + 10 +while time.time() < deadline: + s.poll() + if s.joint_position[3] >= 24.0: + break + time.sleep(0.001) +c.abort() +done() +j = settled() +f = (j[3] - start[3]) / (end[3] - start[3]) +expect("aborted at %.0f percent of the move" % (100 * f), j, + [a + f * (b - a) for a, b in zip(start, end)], 1e-3) +c.mode(linuxcnc.MODE_MDI) +done() +mdi("G49", "G0 B0", "G53 G0 X0 Y0 Z0") +drain() + +# --- the max velocity slider caps a joint interpolated move ---------------- +# by the chord the tool takes between the ends, as a straight move: 100 mm +# at 100 mm/s takes a second, where the joints alone could do it in a tenth +c.maxvel(100.0) +done() +t = time.time() +mdi("G53.4 G0 X100") +t = time.time() - t +print("%-34s %.3f s" % ("G53.4 over 100 mm at 100 mm/s", t)) +if not 0.95 < t < 1.5: + error("G53.4 under the slider took %.3f s, not about 1 s" % t) +c.maxvel(10000.0) +done() +mdi("G53 G0 X0 Y0 Z0") +drain() + # --- the preview reads the codes on the type the machine is on ------------- # the status buffer says which type that is and what each type is; a GUI # restates where the machine stands with G53 ahead of the program, in the diff --git a/tests/ptp-robot/test-ui.py b/tests/ptp-robot/test-ui.py index 93d77c1ea8a..1a2efe37716 100755 --- a/tests/ptp-robot/test-ui.py +++ b/tests/ptp-robot/test-ui.py @@ -185,5 +185,24 @@ def check_held(what, before, after, moved): % (["%.4f" % v for v in s.position[:3]], ["%.4f" % v for v in here])) print("G53.4 back to the same point %s" % " ".join("%.4f" % v for v in back)) +# the wrist turns the tool with three joints: the arm kinematics orients +# with the A B C of its pose, all three head +mdi("G13.1") +drain() +c.mdi("(DEBUG,#<_kins_orient_1> #<_kins_orient_2> #<_kins_orient_3>" + " #<_kins_orient_1_head> #<_kins_orient_2_head> #<_kins_orient_3_head>)") +done(30) +said = None +deadline = time.time() + 5 +while said is None and time.time() < deadline: + m = e.poll() + if not m: + time.sleep(0.01) + elif m[0] == linuxcnc.OPERATOR_DISPLAY: + said = [float(v) for v in m[1].split()] +if said != [3, 4, 5, 1, 1, 1]: + error("the arm kinematics orients with %s, not A B C, heads" % (said,)) +print("orienting axes %s" % said) + print("Exiting with %d errors" % errors) sys.exit(1 if errors else 0) diff --git a/tests/remap/introspect/expected b/tests/remap/introspect/expected index 206bc4d96af..f7dfe04cee5 100644 --- a/tests/remap/introspect/expected +++ b/tests/remap/introspect/expected @@ -29,8 +29,8 @@ speed= 3000.0 global parameter set in test.ngc: 47.11 parameter set via test.ini: 3.14159 locals: ['a_new_local'] -globals: ['_a', '_a_global_set_in_test_dot_ngc', '_a_new_global', '_abs_a', '_abs_b', '_abs_c', '_abs_u', '_abs_v', '_abs_w', '_abs_x', '_abs_y', '_abs_z', '_absolute', '_adaptive_feed', '_b', '_c', '_call_level', '_ccomp', '_coord_system', '_current_pocket', '_current_tool', '_feed', '_feed_hold', '_feed_override', '_flood', '_ijk_absolute_mode', '_imperial', '_incremental', '_ini[example]variable', '_inverse_time', '_kins_type', '_lathe_diameter_mode', '_lathe_radius_mode', '_line', '_metric', '_metric_machine', '_mist', '_motion_mode', '_orient_a', '_orient_b', '_orient_c', '_orient_valid', '_orient_x', '_orient_y', '_orient_z', '_plane', '_remap_level', '_retract_old_z', '_retract_r_plane', '_rpm', '_selected_pocket', '_selected_tool', '_speed_override', '_spindle_css_mode', '_spindle_cw', '_spindle_on', '_spindle_rpm_mode', '_task', '_tool_offset', '_u', '_units_per_minute', '_units_per_rev', '_v', '_value', '_value_returned', '_vmajor', '_vminor', '_w', '_x', '_y', '_z', 'foo'] -params(): ['a_new_local', '_a', '_a_global_set_in_test_dot_ngc', '_a_new_global', '_abs_a', '_abs_b', '_abs_c', '_abs_u', '_abs_v', '_abs_w', '_abs_x', '_abs_y', '_abs_z', '_absolute', '_adaptive_feed', '_b', '_c', '_call_level', '_ccomp', '_coord_system', '_current_pocket', '_current_tool', '_feed', '_feed_hold', '_feed_override', '_flood', '_ijk_absolute_mode', '_imperial', '_incremental', '_ini[example]variable', '_inverse_time', '_kins_type', '_lathe_diameter_mode', '_lathe_radius_mode', '_line', '_metric', '_metric_machine', '_mist', '_motion_mode', '_orient_a', '_orient_b', '_orient_c', '_orient_valid', '_orient_x', '_orient_y', '_orient_z', '_plane', '_remap_level', '_retract_old_z', '_retract_r_plane', '_rpm', '_selected_pocket', '_selected_tool', '_speed_override', '_spindle_css_mode', '_spindle_cw', '_spindle_on', '_spindle_rpm_mode', '_task', '_tool_offset', '_u', '_units_per_minute', '_units_per_rev', '_v', '_value', '_value_returned', '_vmajor', '_vminor', '_w', '_x', '_y', '_z', 'foo'] +globals: ['_a', '_a_global_set_in_test_dot_ngc', '_a_new_global', '_abs_a', '_abs_b', '_abs_c', '_abs_u', '_abs_v', '_abs_w', '_abs_x', '_abs_y', '_abs_z', '_absolute', '_adaptive_feed', '_b', '_c', '_call_level', '_ccomp', '_coord_system', '_current_pocket', '_current_tool', '_feed', '_feed_hold', '_feed_override', '_flood', '_ijk_absolute_mode', '_imperial', '_incremental', '_ini[example]variable', '_inverse_time', '_kins_orient_1', '_kins_orient_1_head', '_kins_orient_2', '_kins_orient_2_head', '_kins_orient_3', '_kins_orient_3_head', '_kins_type', '_lathe_diameter_mode', '_lathe_radius_mode', '_line', '_metric', '_metric_machine', '_mist', '_motion_mode', '_orient_rot1', '_orient_rot2', '_orient_rot3', '_orient_valid', '_orient_x', '_orient_y', '_orient_z', '_plane', '_remap_level', '_retract_old_z', '_retract_r_plane', '_rpm', '_selected_pocket', '_selected_tool', '_speed_override', '_spindle_css_mode', '_spindle_cw', '_spindle_on', '_spindle_rpm_mode', '_task', '_tool_offset', '_u', '_units_per_minute', '_units_per_rev', '_v', '_value', '_value_returned', '_vmajor', '_vminor', '_w', '_x', '_y', '_z', 'foo'] +params(): ['a_new_local', '_a', '_a_global_set_in_test_dot_ngc', '_a_new_global', '_abs_a', '_abs_b', '_abs_c', '_abs_u', '_abs_v', '_abs_w', '_abs_x', '_abs_y', '_abs_z', '_absolute', '_adaptive_feed', '_b', '_c', '_call_level', '_ccomp', '_coord_system', '_current_pocket', '_current_tool', '_feed', '_feed_hold', '_feed_override', '_flood', '_ijk_absolute_mode', '_imperial', '_incremental', '_ini[example]variable', '_inverse_time', '_kins_orient_1', '_kins_orient_1_head', '_kins_orient_2', '_kins_orient_2_head', '_kins_orient_3', '_kins_orient_3_head', '_kins_type', '_lathe_diameter_mode', '_lathe_radius_mode', '_line', '_metric', '_metric_machine', '_mist', '_motion_mode', '_orient_rot1', '_orient_rot2', '_orient_rot3', '_orient_valid', '_orient_x', '_orient_y', '_orient_z', '_plane', '_remap_level', '_retract_old_z', '_retract_r_plane', '_rpm', '_selected_pocket', '_selected_tool', '_speed_override', '_spindle_css_mode', '_spindle_cw', '_spindle_on', '_spindle_rpm_mode', '_task', '_tool_offset', '_u', '_units_per_minute', '_units_per_rev', '_v', '_value', '_value_returned', '_vmajor', '_vminor', '_w', '_x', '_y', '_z', 'foo'] 14 N..... MESSAGE(" after introspect: return value=2.718280 call_level= 0.000000") 15 N..... SET_G5X_OFFSET(1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000) 16 N..... SET_XY_ROTATION(0.0000) diff --git a/tests/twp-native/test-ui.py b/tests/twp-native/test-ui.py index 85e4f2889d8..f494d962033 100755 --- a/tests/twp-native/test-ui.py +++ b/tests/twp-native/test-ui.py @@ -133,14 +133,15 @@ def in_plane(): drain() if not close(after2, stay, 1e-9): error("G53.2 moved the machine: %s became %s" % (stay, after2)) -# read the pose back through the parameters: a move to the published -# rotary words is a move to the present B and C, with the table held +# read the pose back through the parameters: the rotaries come in the +# order the type orients with, the A table, then B and C, and a move to +# them is a move to the present B and C, with the table held before3 = mdi("G0 B0 C0") -after3, samples = sampled("G0 B#<_orient_b> C#<_orient_c>") -show("G0 to #<_orient_b/c>", after3) +after3, samples = sampled("G0 B#<_orient_rot2> C#<_orient_rot3>") +show("G0 to #<_orient_rot2/rot3>", after3) drain() if abs(wrap(after3[SECONDARY] - stay[SECONDARY])) > 1e-3 or abs(wrap(after3[PRIMARY] - stay[PRIMARY])) > 1e-3: - error("#<_orient_b> #<_orient_c> held (%.4f, %.4f), G53.6 had reached (%.4f, %.4f)" + error("#<_orient_rot2> #<_orient_rot3> held (%.4f, %.4f), G53.6 had reached (%.4f, %.4f)" % (after3[SECONDARY], after3[PRIMARY], stay[SECONDARY], stay[PRIMARY])) if not close(tool_axis(after3), list(R2[:, 2]), 1e-6): error("the tool axis at the pose G53.2 published is not the plane normal") @@ -158,11 +159,26 @@ def in_plane(): if not m or m[0] not in (linuxcnc.NML_ERROR, linuxcnc.OPERATOR_ERROR): error("writing #5075 was accepted; the G53.2 pose is not read-only") drain() -c.mdi("G0 A#<_orient_a>") +# the axes the type orients with, and the first of them, the table, where +# it stands; the numbered parameters past the rotaries read 0 +c.mdi("(DEBUG,#<_kins_orient_1> #<_kins_orient_2> #<_kins_orient_3>" + " #<_kins_orient_1_head> #<_kins_orient_2_head> #<_kins_orient_3_head>" + " #<_orient_rot1> #5074 #5077 #5078 #5079)") done(30) -m = e.poll() -if m and m[0] in (linuxcnc.NML_ERROR, linuxcnc.OPERATOR_ERROR): - error("#<_orient_a> after G53.2: %s" % m[1]) +deadline = time.time() + 5 +said = None +while said is None and time.time() < deadline: + m = e.poll() + if not m: + time.sleep(0.01) + elif m[0] in (linuxcnc.NML_ERROR, linuxcnc.OPERATOR_ERROR): + error("reading the orienting axes after G53.2: %s" % m[1]) + break + elif m[0] == linuxcnc.OPERATOR_DISPLAY: + said = [float(v) for v in m[1].split()] +want = [3, 4, 5, 0, 1, 1, stay[TABLE], stay[TABLE], 0, 0, 0] +if said is None or len(said) != len(want) or not close(said, want, 1e-3): + error("the orienting axes, rot1, #5074 and #5077-#5079 read %s, not %s" % (said, want)) drain() # --- the orientation stays inside the rotary travel --------------------