/
xyzac-trt-kins.c
157 lines (127 loc) · 4.64 KB
/
xyzac-trt-kins.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**************************************************************************
* Copyright 2016 Rudy du Preez <rudy@asmsa.co.za>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
**************************************************************************/
/********************************************************************
* Kinematics for 5 axis mill named 'xyzac-trt'.
* This mill has a tilting table (A axis) and horizontal rotary
* mounted to the table (C axis).
********************************************************************/
#include "kinematics.h"
#include "posemath.h"
#include "hal.h"
#include "rtapi.h"
#include "rtapi_math.h"
// sequential joint number assignments
#define JX 0
#define JY 1
#define JZ 2
#define JA 3
#define JC 4
struct haldata {
hal_float_t *z_offset;
hal_float_t *y_offset;
hal_float_t *tool_offset;
} *haldata;
int kinematicsForward(const double *joints,
EmcPose * pos,
const KINEMATICS_FORWARD_FLAGS * fflags,
KINEMATICS_INVERSE_FLAGS * iflags)
{
double dy = *(haldata->y_offset);
double dz = *(haldata->z_offset);
double dt = *(haldata->tool_offset);
double a_rad = joints[JA]*TO_RAD;
double c_rad = joints[JC]*TO_RAD;
dz = dz + dt;
pos->tran.x = + cos(c_rad) * (joints[JX] )
+ sin(c_rad) * cos(a_rad) * (joints[JY] - dy)
+ sin(c_rad) * sin(a_rad) * (joints[JZ] - dz)
+ sin(c_rad) * dy;
pos->tran.y = - sin(c_rad) * (joints[JX] )
+ cos(c_rad) * cos(a_rad) * (joints[JY] - dy)
+ cos(c_rad) * sin(a_rad) * (joints[JZ] - dz)
+ cos(c_rad) * dy;
pos->tran.z = + 0
- sin(a_rad) * (joints[JY] - dy)
+ cos(a_rad) * (joints[JZ] - dz)
+ dz;
pos->a = joints[JA];
pos->c = joints[JC];
pos->b = 0;
pos->w = 0;
pos->u = 0;
pos->v = 0;
return 0;
}
int kinematicsInverse(const EmcPose * pos,
double *joints,
const KINEMATICS_INVERSE_FLAGS * iflags,
KINEMATICS_FORWARD_FLAGS * fflags)
{
double dz = *(haldata->z_offset);
double dy = *(haldata->y_offset);
double dt = *(haldata->tool_offset);
double c_rad = pos->c*TO_RAD;
double a_rad = pos->a*TO_RAD;
dz = dz + dt;
joints[JX] = + cos(c_rad) * pos->tran.x
- sin(c_rad) * pos->tran.y;
joints[JY] = + sin(c_rad) * cos(a_rad) * pos->tran.x
+ cos(c_rad) * cos(a_rad) * pos->tran.y
- sin(a_rad) * pos->tran.z
- cos(a_rad) * dy
+ sin(a_rad) * dz + dy;
joints[JZ] = + sin(c_rad) * sin(a_rad) * pos->tran.x
+ cos(c_rad) * sin(a_rad) * pos->tran.y
+ cos(a_rad) * pos->tran.z
- sin(a_rad) * dy
- cos(a_rad) * dz
+ dz;
joints[JA] = pos->a;
joints[JC] = pos->c;
return 0;
}
KINEMATICS_TYPE kinematicsType()
{
return KINEMATICS_BOTH;
}
#include "rtapi.h"
#include "rtapi_app.h"
#include "hal.h"
EXPORT_SYMBOL(kinematicsType);
EXPORT_SYMBOL(kinematicsInverse);
EXPORT_SYMBOL(kinematicsForward);
MODULE_LICENSE("GPL");
int comp_id;
int rtapi_app_main(void) {
int res = 0;
comp_id = hal_init("xyzac-trt-kins");
if(comp_id < 0) return comp_id;
haldata = hal_malloc(sizeof(struct haldata));
if((res = hal_pin_float_new("xyzac-trt-kins.y-offset",
HAL_IO, &(haldata->y_offset), comp_id)) < 0) goto error;
if((res = hal_pin_float_new("xyzac-trt-kins.z-offset",
HAL_IO, &(haldata->z_offset), comp_id)) < 0) goto error;
if((res = hal_pin_float_new("xyzac-trt-kins.tool-offset",
HAL_IN, &(haldata->tool_offset), comp_id)) < 0) goto error;
hal_ready(comp_id);
return 0;
error:
hal_exit(comp_id);
return res;
}
void rtapi_app_exit(void) { hal_exit(comp_id); }