Skip to content

Commit bfb687e

Browse files
committed
introduce "conventional-directions" HAL pin.
when set to true, rotational axes direction will follow the conventions as documented in the manual
1 parent 5dd57ea commit bfb687e

6 files changed

Lines changed: 132 additions & 102 deletions

File tree

configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzac-trt.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ HALCMD = sets :z-offset 10
6969
HALCMD = setp xyzac-trt-kins.x-rot-point 0
7070
HALCMD = setp xyzac-trt-kins.y-rot-point 0
7171
HALCMD = setp xyzac-trt-kins.z-rot-point 0
72+
HALCMD = setp xyzac-trt-kins.conventional-directions 0
7273

7374
[HALUI]
7475
# NOTE: kinstype==0 is identity kins because sparm=identityfirst

configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzac-trt.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@ Hal Input pins:
2828
X, Y and Z rot-point pins represent the
2929
offsets of the center of rotation of the C axis
3030
relative to the machine absolute zero
31+
32+
Hal Input pins:
33+
xyzac-trt-kins.conventional-directions
34+
35+
Pin conventional-directions is false by default. If true,
36+
axis directions follow the conventions as defined
37+
at https://linuxcnc.org/docs/html/gcode/machining-center.html#_rotational_axes

configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzbc-trt.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ HALCMD = sets :z-offset -15
6969
HALCMD = setp xyzbc-trt-kins.x-rot-point 0
7070
HALCMD = setp xyzbc-trt-kins.y-rot-point 0
7171
HALCMD = setp xyzbc-trt-kins.z-rot-point 0
72+
HALCMD = setp xyzbc-trt-kins.conventional-directions 0
7273

7374
[HALUI]
7475
# NOTE: kinstype==0 is identity kins because sparm=identityfirst

configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzbc-trt.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ of rotation of the B axis relative to the center
2121
of rotation of the C axis.
2222

2323
Hal Input pins:
24-
xyzac-trt-kins.x-rot-point
25-
xyzac-trt-kins.y-rot-point
26-
xyzac-trt-kins.z-rot-point
24+
xyzbc-trt-kins.x-rot-point
25+
xyzbc-trt-kins.y-rot-point
26+
xyzbc-trt-kins.z-rot-point
2727

2828
X, Y and Z rot-point pins represent the
2929
offsets of the center of rotation of the C axis
3030
relative to the machine absolute zero
31+
32+
Hal Input pins:
33+
xyzbc-trt-kins.conventional-directions
34+
35+
Pin conventional-directions is false by default. If true,
36+
axis directions follow the conventions as defined
37+
at https://linuxcnc.org/docs/html/gcode/machining-center.html#_rotational_axes

src/emc/kinematics/maxkins.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
struct haldata {
3434
hal_float_t *pivot_length;
35+
hal_bit_t *conventional_directions; //default is false
3536
} *haldata;
3637

3738
int kinematicsForward(const double *joints,
@@ -41,23 +42,26 @@ int kinematicsForward(const double *joints,
4142
{
4243
(void)fflags;
4344
(void)iflags;
45+
46+
const real_t con = *(haldata->conventional_directions) ? 1.0 : -1.0;
47+
4448
// B correction
45-
double zb = (*(haldata->pivot_length) + joints[8]) * cos(d2r(joints[4]));
46-
double xb = (*(haldata->pivot_length) + joints[8]) * sin(d2r(joints[4]));
49+
const double zb = (*(haldata->pivot_length) + joints[8]) * cos(d2r(joints[4]));
50+
const double xb = (*(haldata->pivot_length) + joints[8]) * sin(d2r(joints[4]));
4751

4852
// C correction
49-
double xyr = hypot(joints[0], joints[1]);
50-
double xytheta = atan2(joints[1], joints[0]) + d2r(joints[5]);
53+
const double xyr = hypot(joints[0], joints[1]);
54+
const double xytheta = atan2(joints[1], joints[0]) + d2r(joints[5]);
5155

5256
// U correction
53-
double zv = joints[6] * sin(d2r(joints[4]));
54-
double xv = joints[6] * cos(d2r(joints[4]));
57+
const double zv = joints[6] * sin(d2r(joints[4]));
58+
const double xv = joints[6] * cos(d2r(joints[4]));
5559

5660
// V correction is always in joint 1 only
5761

58-
pos->tran.x = xyr * cos(xytheta) + xb - xv;
62+
pos->tran.x = xyr * cos(xytheta) - (con * xb) - xv;
5963
pos->tran.y = xyr * sin(xytheta) - joints[7];
60-
pos->tran.z = joints[2] - zb + zv + *(haldata->pivot_length);
64+
pos->tran.z = joints[2] - zb - (con * zv) + *(haldata->pivot_length);
6165

6266
pos->a = joints[3];
6367
pos->b = joints[4];
@@ -76,23 +80,26 @@ int kinematicsInverse(const EmcPose * pos,
7680
{
7781
(void)iflags;
7882
(void)fflags;
83+
84+
const real_t con = *(haldata->conventional_directions) ? 1.0 : -1.0;
85+
7986
// B correction
80-
double zb = (*(haldata->pivot_length) + pos->w) * cos(d2r(pos->b));
81-
double xb = (*(haldata->pivot_length) + pos->w) * sin(d2r(pos->b));
87+
const double zb = (*(haldata->pivot_length) + pos->w) * cos(d2r(pos->b));
88+
const double xb = (*(haldata->pivot_length) + pos->w) * sin(d2r(pos->b));
8289

8390
// C correction
84-
double xyr = hypot(pos->tran.x, pos->tran.y);
85-
double xytheta = atan2(pos->tran.y, pos->tran.x) - d2r(pos->c);
91+
const double xyr = hypot(pos->tran.x, pos->tran.y);
92+
const double xytheta = atan2(pos->tran.y, pos->tran.x) - d2r(pos->c);
8693

8794
// U correction
88-
double zv = pos->u * sin(d2r(pos->b));
89-
double xv = pos->u * cos(d2r(pos->b));
95+
const double zv = pos->u * sin(d2r(pos->b));
96+
const double xv = pos->u * cos(d2r(pos->b));
9097

9198
// V correction is always in joint 1 only
9299

93-
joints[0] = xyr * cos(xytheta) - xb + xv;
100+
joints[0] = xyr * cos(xytheta) + (con * xb) + xv;
94101
joints[1] = xyr * sin(xytheta) + pos->v;
95-
joints[2] = pos->tran.z + zb + zv - *(haldata->pivot_length);
102+
joints[2] = pos->tran.z + zb - (con * zv) - *(haldata->pivot_length);
96103

97104
joints[3] = pos->a;
98105
joints[4] = pos->b;
@@ -127,10 +134,13 @@ int rtapi_app_main(void) {
127134
haldata = hal_malloc(sizeof(struct haldata));
128135

129136
result = hal_pin_float_new("maxkins.pivot-length", HAL_IO, &(haldata->pivot_length), comp_id);
137+
138+
result += hal_pin_bit_new("maxkins.conventional-directions", HAL_IN, &(haldata->conventional_directions), comp_id);
139+
130140
if(result < 0) goto error;
131141

132142
*(haldata->pivot_length) = 0.666;
133-
143+
*(haldata->conventional_directions) = 0; // default is unconventional
134144
hal_ready(comp_id);
135145
return 0;
136146

src/emc/kinematics/trtfuncs.c

Lines changed: 86 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct haldata {
6060
hal_float_t *y_offset;
6161
hal_float_t *z_offset;
6262
hal_float_t *tool_offset;
63+
hal_bit_t *conventional_directions; // default: false
6364
} *haldata;
6465

6566

@@ -140,6 +141,8 @@ int trtKinematicsSetup(const int comp_id,
140141
"%s.z-offset",kp->halprefix);
141142
res += hal_pin_float_newf(HAL_IN, &(haldata->tool_offset), comp_id,
142143
"%s.tool-offset",kp->halprefix);
144+
res += hal_pin_bit_newf(HAL_IN, &(haldata->conventional_directions), comp_id,
145+
"%s.conventional-directions", kp->halprefix);
143146
if (res) {goto error;}
144147
return 0;
145148

@@ -155,31 +158,31 @@ int xyzacKinematicsForward(const double *joints,
155158
{
156159
(void)fflags;
157160
(void)iflags;
158-
double x_rot_point = *(haldata->x_rot_point);
159-
double y_rot_point = *(haldata->y_rot_point);
160-
double z_rot_point = *(haldata->z_rot_point);
161-
double dt = *(haldata->tool_offset);
162-
double dy = *(haldata->y_offset);
163-
double dz = *(haldata->z_offset);
164-
double a_rad = joints[JA]*TO_RAD;
165-
double c_rad = joints[JC]*TO_RAD;
166-
167-
dz = dz + dt;
168-
169-
pos->tran.x = + cos(c_rad) * (joints[JX] - x_rot_point)
170-
+ sin(c_rad) * cos(a_rad) * (joints[JY] - dy - y_rot_point)
171-
+ sin(c_rad) * sin(a_rad) * (joints[JZ] - dz - z_rot_point)
172-
+ sin(c_rad) * dy
161+
const double x_rot_point = *(haldata->x_rot_point);
162+
const double y_rot_point = *(haldata->y_rot_point);
163+
const double z_rot_point = *(haldata->z_rot_point);
164+
const double dt = *(haldata->tool_offset);
165+
const double dy = *(haldata->y_offset);
166+
const double dz = *(haldata->z_offset) + dt;
167+
const double a_rad = joints[JA]*TO_RAD;
168+
const double c_rad = joints[JC]*TO_RAD;
169+
170+
const real_t con = *(haldata->conventional_directions) ? 1.0 : -1.0;
171+
172+
pos->tran.x = + cos(c_rad) * (joints[JX] - x_rot_point)
173+
- con * sin(c_rad) * cos(a_rad) * (joints[JY] - dy - y_rot_point)
174+
+ sin(c_rad) * sin(a_rad) * (joints[JZ] - dz - z_rot_point)
175+
- con * sin(c_rad) * dy
173176
+ x_rot_point;
174177

175-
pos->tran.y = - sin(c_rad) * (joints[JX] - x_rot_point)
176-
+ cos(c_rad) * cos(a_rad) * (joints[JY] - dy - y_rot_point)
177-
+ cos(c_rad) * sin(a_rad) * (joints[JZ] - dz - z_rot_point)
178-
+ cos(c_rad) * dy
178+
pos->tran.y = + con * sin(c_rad) * (joints[JX] - x_rot_point)
179+
+ cos(c_rad) * cos(a_rad) * (joints[JY] - dy - y_rot_point)
180+
- con * cos(c_rad) * sin(a_rad) * (joints[JZ] - dz - z_rot_point)
181+
+ cos(c_rad) * dy
179182
+ y_rot_point;
180183

181184
pos->tran.z = + 0
182-
- sin(a_rad) * (joints[JY] - dy - y_rot_point)
185+
+ con * sin(a_rad) * (joints[JY] - dy - y_rot_point)
183186
+ cos(a_rad) * (joints[JZ] - dz - z_rot_point)
184187
+ dz
185188
+ z_rot_point;
@@ -203,36 +206,36 @@ int xyzacKinematicsInverse(const EmcPose * pos,
203206
{
204207
(void)iflags;
205208
(void)fflags;
206-
double x_rot_point = *(haldata->x_rot_point);
207-
double y_rot_point = *(haldata->y_rot_point);
208-
double z_rot_point = *(haldata->z_rot_point);
209-
double dy = *(haldata->y_offset);
210-
double dz = *(haldata->z_offset);
211-
double dt = *(haldata->tool_offset);
212-
double a_rad = pos->a*TO_RAD;
213-
double c_rad = pos->c*TO_RAD;
209+
const double x_rot_point = *(haldata->x_rot_point);
210+
const double y_rot_point = *(haldata->y_rot_point);
211+
const double z_rot_point = *(haldata->z_rot_point);
212+
const double dy = *(haldata->y_offset);
213+
const double dt = *(haldata->tool_offset);
214+
const double dz = *(haldata->z_offset) + dt;
215+
const double a_rad = pos->a*TO_RAD;
216+
const double c_rad = pos->c*TO_RAD;
214217

215-
EmcPose P; // computed position
218+
const real_t con = *(haldata->conventional_directions) ? 1.0 : -1.0;
216219

217-
dz = dz + dt;
220+
EmcPose P; // computed position
218221

219-
P.tran.x = + cos(c_rad) * (pos->tran.x - x_rot_point)
220-
- sin(c_rad) * (pos->tran.y - y_rot_point)
222+
P.tran.x = + cos(c_rad) * (pos->tran.x - x_rot_point)
223+
+ con * sin(c_rad) * (pos->tran.y - y_rot_point)
221224
+ x_rot_point;
222225

223-
P.tran.y = + sin(c_rad) * cos(a_rad) * (pos->tran.x - x_rot_point)
224-
+ cos(c_rad) * cos(a_rad) * (pos->tran.y - y_rot_point)
225-
- sin(a_rad) * (pos->tran.z - z_rot_point)
226-
- cos(a_rad) * dy
227-
+ sin(a_rad) * dz
226+
P.tran.y = - con * sin(c_rad) * cos(a_rad) * (pos->tran.x - x_rot_point)
227+
+ cos(c_rad) * cos(a_rad) * (pos->tran.y - y_rot_point)
228+
+ con * sin(a_rad) * (pos->tran.z - z_rot_point)
229+
- cos(a_rad) * dy
230+
- con * sin(a_rad) * dz
228231
+ dy
229232
+ y_rot_point;
230233

231-
P.tran.z = + sin(c_rad) * sin(a_rad) * (pos->tran.x - x_rot_point)
232-
+ cos(c_rad) * sin(a_rad) * (pos->tran.y - y_rot_point)
233-
+ cos(a_rad) * (pos->tran.z - z_rot_point)
234-
- sin(a_rad) * dy
235-
- cos(a_rad) * dz
234+
P.tran.z = + sin(c_rad) * sin(a_rad) * (pos->tran.x - x_rot_point)
235+
- con * cos(c_rad) * sin(a_rad) * (pos->tran.y - y_rot_point)
236+
+ cos(a_rad) * (pos->tran.z - z_rot_point)
237+
+ con * sin(a_rad) * dy
238+
- cos(a_rad) * dz
236239
+ dz
237240
+ z_rot_point;
238241

@@ -264,31 +267,31 @@ int xyzbcKinematicsForward(const double *joints,
264267
(void)fflags;
265268
(void)iflags;
266269
// Note: 'principal' joints are used
267-
double x_rot_point = *(haldata->x_rot_point);
268-
double y_rot_point = *(haldata->y_rot_point);
269-
double z_rot_point = *(haldata->z_rot_point);
270-
double dx = *(haldata->x_offset);
271-
double dz = *(haldata->z_offset);
272-
double dt = *(haldata->tool_offset);
273-
dz = dz + dt;
274-
double b_rad = joints[JB]*TO_RAD;
275-
double c_rad = joints[JC]*TO_RAD;
276-
277-
278-
pos->tran.x = cos(c_rad) * cos(b_rad) * (joints[JX] - dx - x_rot_point)
279-
+ sin(c_rad) * (joints[JY] - y_rot_point)
280-
- cos(c_rad) * sin(b_rad) * (joints[JZ] - dz - z_rot_point)
281-
+ cos(c_rad) * dx
270+
const double x_rot_point = *(haldata->x_rot_point);
271+
const double y_rot_point = *(haldata->y_rot_point);
272+
const double z_rot_point = *(haldata->z_rot_point);
273+
const double dx = *(haldata->x_offset);
274+
const double dt = *(haldata->tool_offset);
275+
const double dz = *(haldata->z_offset) + dt;
276+
const double b_rad = joints[JB]*TO_RAD;
277+
const double c_rad = joints[JC]*TO_RAD;
278+
279+
const real_t con = *(haldata->conventional_directions) ? 1.0 : -1.0;
280+
281+
pos->tran.x = cos(c_rad) * cos(b_rad) * (joints[JX] - dx - x_rot_point)
282+
- con * sin(c_rad) * (joints[JY] - y_rot_point)
283+
+ con * cos(c_rad) * sin(b_rad) * (joints[JZ] - dz - z_rot_point)
284+
+ cos(c_rad) * dx
282285
+ x_rot_point;
283286

284-
pos->tran.y = - sin(c_rad) * cos(b_rad) * (joints[JX] - dx - x_rot_point)
285-
+ cos(c_rad) * (joints[JY] - y_rot_point)
286-
+ sin(c_rad) * sin(b_rad) * (joints[JZ] - dz - z_rot_point)
287-
- sin(c_rad) * dx
287+
pos->tran.y = + con * sin(c_rad) * cos(b_rad) * (joints[JX] - dx - x_rot_point)
288+
+ cos(c_rad) * (joints[JY] - y_rot_point)
289+
+ sin(c_rad) * sin(b_rad) * (joints[JZ] - dz - z_rot_point)
290+
+ con * sin(c_rad) * dx
288291
+ y_rot_point;
289292

290-
pos->tran.z = sin(b_rad) * (joints[JX] - dx - x_rot_point)
291-
+ cos(b_rad) * (joints[JZ] - dz - z_rot_point)
293+
pos->tran.z = - con * sin(b_rad) * (joints[JX] - dx - x_rot_point)
294+
+ cos(b_rad) * (joints[JZ] - dz - z_rot_point)
292295
+ dz
293296
+ z_rot_point;
294297

@@ -311,33 +314,34 @@ int xyzbcKinematicsInverse(const EmcPose * pos,
311314
{
312315
(void)iflags;
313316
(void)fflags;
314-
double x_rot_point = *(haldata->x_rot_point);
315-
double y_rot_point = *(haldata->y_rot_point);
316-
double z_rot_point = *(haldata->z_rot_point);
317-
double dx = *(haldata->x_offset);
318-
double dz = *(haldata->z_offset);
319-
double dt = *(haldata->tool_offset);
320-
dz = dz + dt;
321-
double b_rad = pos->b*TO_RAD;
322-
double c_rad = pos->c*TO_RAD;
323-
double dpx = -cos(b_rad)*dx - sin(b_rad)*dz + dx;
324-
double dpz = sin(b_rad)*dx - cos(b_rad)*dz + dz;
317+
const double x_rot_point = *(haldata->x_rot_point);
318+
const double y_rot_point = *(haldata->y_rot_point);
319+
const double z_rot_point = *(haldata->z_rot_point);
320+
const double dx = *(haldata->x_offset);
321+
const double dt = *(haldata->tool_offset);
322+
const double dz = *(haldata->z_offset) + dt;
323+
const double b_rad = pos->b*TO_RAD;
324+
const double c_rad = pos->c*TO_RAD;
325+
const double dpx = -cos(b_rad)*dx + sin(b_rad)*dz + dx;
326+
const double dpz = -sin(b_rad)*dx - cos(b_rad)*dz + dz;
327+
328+
const real_t con = *(haldata->conventional_directions) ? 1.0 : -1.0;
325329

326330
EmcPose P; // computed position
327331

328-
P.tran.x = + cos(c_rad) * cos(b_rad) * (pos->tran.x - x_rot_point)
329-
- sin(c_rad) * cos(b_rad) * (pos->tran.y - y_rot_point)
330-
+ sin(b_rad) * (pos->tran.z - z_rot_point)
332+
P.tran.x = + cos(c_rad) * cos(b_rad) * (pos->tran.x - x_rot_point)
333+
+ con * sin(c_rad) * cos(b_rad) * (pos->tran.y - y_rot_point)
334+
- con * sin(b_rad) * (pos->tran.z - z_rot_point)
331335
+ dpx
332336
+ x_rot_point;
333337

334-
P.tran.y = + sin(c_rad) * (pos->tran.x - x_rot_point)
335-
+ cos(c_rad) * (pos->tran.y - y_rot_point)
338+
P.tran.y = - con * sin(c_rad) * (pos->tran.x - x_rot_point)
339+
+ cos(c_rad) * (pos->tran.y - y_rot_point)
336340
+ y_rot_point;
337341

338-
P.tran.z = - cos(c_rad) * sin(b_rad) * (pos->tran.x - x_rot_point)
339-
+ sin(c_rad) * sin(b_rad) * (pos->tran.y - y_rot_point)
340-
+ cos(b_rad) * (pos->tran.z - z_rot_point)
342+
P.tran.z = + con * cos(c_rad) * sin(b_rad) * (pos->tran.x - x_rot_point)
343+
+ sin(c_rad) * sin(b_rad) * (pos->tran.y - y_rot_point)
344+
+ cos(b_rad) * (pos->tran.z - z_rot_point)
341345
+ dpz
342346
+ z_rot_point;
343347

0 commit comments

Comments
 (0)