forked from Traumflug/Teacup_Firmware
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dda_kinematics.c
57 lines (45 loc) · 1.94 KB
/
dda_kinematics.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
#include "dda_kinematics.h"
/** \file G-code axis system to stepper motor axis system conversion.
*/
#include <stdlib.h>
#include "dda_maths.h"
void
carthesian_to_carthesian(const TARGET *startpoint, const TARGET *target,
axes_uint32_t delta_um, axes_int32_t steps) {
enum axis_e i;
for (i = X; i < E; i++) {
delta_um[i] = (uint32_t)labs(target->axis[i] - startpoint->axis[i]);
steps[i] = um_to_steps(target->axis[i], i);
}
/* Replacing the above five lines with this costs about 200 bytes binary
size on AVR, but also takes about 120 clock cycles less during movement
preparation. The smaller version was kept for our Arduino Nano friends.
delta_um[X] = (uint32_t)labs(target->axis[X] - startpoint->axis[X]);
steps[X] = um_to_steps(target->axis[X], X);
delta_um[Y] = (uint32_t)labs(target->axis[Y] - startpoint->axis[Y]);
steps[Y] = um_to_steps(target->axis[Y], Y);
delta_um[Z] = (uint32_t)labs(target->axis[Z] - startpoint->axis[Z]);
steps[Z] = um_to_steps(target->axis[Z], Z);
*/
}
void
carthesian_to_corexy(const TARGET *startpoint, const TARGET *target,
axes_uint32_t delta_um, axes_int32_t steps) {
delta_um[X] = (uint32_t)labs((target->axis[X] - startpoint->axis[X]) +
(target->axis[Y] - startpoint->axis[Y]));
delta_um[Y] = (uint32_t)labs((target->axis[X] - startpoint->axis[X]) -
(target->axis[Y] - startpoint->axis[Y]));
delta_um[Z] = (uint32_t)labs(target->axis[Z] - startpoint->axis[Z]);
axes_um_to_steps_corexy(target->axis, steps);
}
void axes_um_to_steps_cartesian(const axes_int32_t um, axes_int32_t steps) {
enum axis_e i;
for (i = X; i < E; i++) {
steps[i] = um_to_steps(um[i], i);
}
}
void axes_um_to_steps_corexy(const axes_int32_t um, axes_int32_t steps) {
steps[X] = um_to_steps(um[X] + um[Y], X);
steps[Y] = um_to_steps(um[X] - um[Y], Y);
steps[Z] = um_to_steps(um[Z], Z);
}