Skip to content

Commit 044ecba

Browse files
committed
Refactor Kinematics one file per module
1 parent bcfff3e commit 044ecba

56 files changed

Lines changed: 3810 additions & 5016 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/emc/kinematics/5axiskins.c

Lines changed: 165 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
* 9) Coordinates XYZBCW are required, AUV may be used
4343
* if specified with the coordinates parameter and will
4444
* be mapped one-to-one with the assigned joint.
45-
* 10) The direction of the tilt axis is the opposite of the
46-
* conventional axis direction. See
45+
* 10) The direction of the tilt axis is the opposite of the
46+
* conventional axis direction. See
4747
* https://linuxcnc.org/docs/html/gcode/machining-center.html
4848
********************************************************************/
4949

@@ -62,14 +62,107 @@
6262
#include "kinematics.h"
6363
#include "posemath.h"
6464
#include "switchkins.h"
65-
#include "5axiskins_math.h"
65+
66+
/* ========================================================================
67+
* Internal math (was in 5axiskins_math.h)
68+
* ======================================================================== */
69+
70+
#ifndef M_PI
71+
#define M_PI 3.14159265358979323846
72+
#endif
73+
#ifndef TO_RAD
74+
#define TO_RAD (M_PI / 180.0)
75+
#endif
76+
77+
typedef struct {
78+
double pivot_length;
79+
} fiveaxis_params_t;
80+
81+
typedef struct {
82+
int jx, jy, jz;
83+
int ja, jb, jc;
84+
int ju, jv, jw;
85+
} fiveaxis_joints_t;
86+
87+
static void fiveaxis_s2r(double r, double t, double p,
88+
double *x, double *y, double *z) {
89+
double t_rad = TO_RAD * t;
90+
double p_rad = TO_RAD * p;
91+
*x = r * sin(p_rad) * cos(t_rad);
92+
*y = r * sin(p_rad) * sin(t_rad);
93+
*z = r * cos(p_rad);
94+
}
95+
96+
static int fiveaxis_forward_impl(const fiveaxis_params_t *params,
97+
const fiveaxis_joints_t *jm,
98+
const double *joints,
99+
EmcPose *pos) {
100+
double rx, ry, rz;
101+
double b_val = (jm->jb >= 0) ? joints[jm->jb] : 0;
102+
double c_val = (jm->jc >= 0) ? joints[jm->jc] : 0;
103+
double w_val = (jm->jw >= 0) ? joints[jm->jw] : 0;
104+
105+
fiveaxis_s2r(params->pivot_length + w_val, c_val, 180.0 - b_val,
106+
&rx, &ry, &rz);
107+
108+
pos->tran.x = (jm->jx >= 0 ? joints[jm->jx] : 0) + rx;
109+
pos->tran.y = (jm->jy >= 0 ? joints[jm->jy] : 0) + ry;
110+
pos->tran.z = (jm->jz >= 0 ? joints[jm->jz] : 0) + params->pivot_length + rz;
111+
pos->a = (jm->ja >= 0) ? joints[jm->ja] : 0;
112+
pos->b = b_val;
113+
pos->c = c_val;
114+
pos->u = (jm->ju >= 0) ? joints[jm->ju] : 0;
115+
pos->v = (jm->jv >= 0) ? joints[jm->jv] : 0;
116+
pos->w = w_val;
117+
118+
return 0;
119+
}
120+
121+
static int fiveaxis_inverse_impl(const fiveaxis_params_t *params,
122+
const EmcPose *world,
123+
EmcPose *axis_values) {
124+
double rx, ry, rz;
125+
126+
fiveaxis_s2r(params->pivot_length + world->w, world->c, 180.0 - world->b,
127+
&rx, &ry, &rz);
128+
129+
axis_values->tran.x = world->tran.x - rx;
130+
axis_values->tran.y = world->tran.y - ry;
131+
axis_values->tran.z = world->tran.z - params->pivot_length - rz;
132+
axis_values->a = world->a;
133+
axis_values->b = world->b;
134+
axis_values->c = world->c;
135+
axis_values->u = world->u;
136+
axis_values->v = world->v;
137+
axis_values->w = world->w;
138+
139+
return 0;
140+
}
141+
142+
static void fiveaxis_axis_to_joints(const fiveaxis_joints_t *jm,
143+
const EmcPose *axis_values,
144+
double *joints) {
145+
if (jm->jx >= 0) joints[jm->jx] = axis_values->tran.x;
146+
if (jm->jy >= 0) joints[jm->jy] = axis_values->tran.y;
147+
if (jm->jz >= 0) joints[jm->jz] = axis_values->tran.z;
148+
if (jm->ja >= 0) joints[jm->ja] = axis_values->a;
149+
if (jm->jb >= 0) joints[jm->jb] = axis_values->b;
150+
if (jm->jc >= 0) joints[jm->jc] = axis_values->c;
151+
if (jm->ju >= 0) joints[jm->ju] = axis_values->u;
152+
if (jm->jv >= 0) joints[jm->jv] = axis_values->v;
153+
if (jm->jw >= 0) joints[jm->jw] = axis_values->w;
154+
}
155+
156+
/* ========================================================================
157+
* RT interface (reads HAL pins)
158+
* ======================================================================== */
66159

67160
struct haldata {
68161
hal_float_t *pivot_length;
69162
} *haldata;
70163
static int fiveaxis_max_joints;
71164

72-
// Joint mapping struct for math functions
165+
// Joint mapping struct
73166
static fiveaxis_joints_t jmap;
74167

75168
// assignments of principal joints to axis letters:
@@ -93,7 +186,7 @@ static int fiveaxis_KinematicsForward(const double *joints,
93186
(void)iflags;
94187
fiveaxis_params_t params;
95188
params.pivot_length = *(haldata->pivot_length);
96-
return fiveaxis_forward_math(&params, &jmap, joints, pos);
189+
return fiveaxis_forward_impl(&params, &jmap, joints, pos);
97190
} //fiveaxis_KinematicsForward()
98191

99192
static int fiveaxis_KinematicsInverse(const EmcPose * pos,
@@ -108,7 +201,7 @@ static int fiveaxis_KinematicsInverse(const EmcPose * pos,
108201

109202
// Compute axis values using pure math function
110203
EmcPose P;
111-
fiveaxis_inverse_math(&params, pos, &P);
204+
fiveaxis_inverse_impl(&params, pos, &P);
112205

113206
// update joints with support for
114207
// multiple-joints per-coordinate letter:
@@ -237,3 +330,69 @@ int switchkinsSetup(kparms* kp,
237330

238331
return 0;
239332
} // switchkinsSetup()
333+
334+
/* ========================================================================
335+
* Non-RT interface for userspace trajectory planner
336+
* ======================================================================== */
337+
#include "kinematics_params.h"
338+
339+
int nonrt_kinematicsForward(const void *params,
340+
const double *joints,
341+
EmcPose *pos)
342+
{
343+
const kinematics_params_t *kp = (const kinematics_params_t *)params;
344+
fiveaxis_params_t p;
345+
fiveaxis_joints_t jm;
346+
347+
p.pivot_length = kp->params.fiveaxis.pivot_length;
348+
jm.jx = kp->axis_to_joint[0]; jm.jy = kp->axis_to_joint[1];
349+
jm.jz = kp->axis_to_joint[2]; jm.ja = kp->axis_to_joint[3];
350+
jm.jb = kp->axis_to_joint[4]; jm.jc = kp->axis_to_joint[5];
351+
jm.ju = kp->axis_to_joint[6]; jm.jv = kp->axis_to_joint[7];
352+
jm.jw = kp->axis_to_joint[8];
353+
354+
return fiveaxis_forward_impl(&p, &jm, joints, pos);
355+
}
356+
357+
int nonrt_kinematicsInverse(const void *params,
358+
const EmcPose *pos,
359+
double *joints)
360+
{
361+
const kinematics_params_t *kp = (const kinematics_params_t *)params;
362+
fiveaxis_params_t p;
363+
fiveaxis_joints_t jm;
364+
EmcPose axis_values;
365+
366+
p.pivot_length = kp->params.fiveaxis.pivot_length;
367+
jm.jx = kp->axis_to_joint[0]; jm.jy = kp->axis_to_joint[1];
368+
jm.jz = kp->axis_to_joint[2]; jm.ja = kp->axis_to_joint[3];
369+
jm.jb = kp->axis_to_joint[4]; jm.jc = kp->axis_to_joint[5];
370+
jm.ju = kp->axis_to_joint[6]; jm.jv = kp->axis_to_joint[7];
371+
jm.jw = kp->axis_to_joint[8];
372+
373+
fiveaxis_inverse_impl(&p, pos, &axis_values);
374+
fiveaxis_axis_to_joints(&jm, &axis_values, joints);
375+
return 0;
376+
}
377+
378+
int nonrt_refresh(void *params,
379+
int (*read_float)(const char *, double *),
380+
int (*read_bit)(const char *, int *),
381+
int (*read_s32)(const char *, int *))
382+
{
383+
kinematics_params_t *kp = (kinematics_params_t *)params;
384+
(void)read_bit; (void)read_s32;
385+
386+
if (read_float("5axiskins.pivot-length",
387+
&kp->params.fiveaxis.pivot_length) != 0)
388+
return -1;
389+
390+
return 0;
391+
}
392+
393+
int nonrt_is_identity(void) { return 0; }
394+
395+
EXPORT_SYMBOL(nonrt_kinematicsForward);
396+
EXPORT_SYMBOL(nonrt_kinematicsInverse);
397+
EXPORT_SYMBOL(nonrt_refresh);
398+
EXPORT_SYMBOL(nonrt_is_identity);

src/emc/kinematics/5axiskins_math.h

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)