forked from nicholaskell/Teacup_Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.c
243 lines (214 loc) · 4.62 KB
/
home.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include "home.h"
/** \file
\brief Homing routines
*/
#include "dda.h"
#include "dda_queue.h"
#include "delay.h"
#include "pinio.h"
#include "gcode_parse.h"
/// home all 3 axes
void home() {
#if defined X_MIN_PIN
home_x_negative();
#elif defined X_MAX_PIN
home_x_positive();
#endif
#if defined Y_MIN_PIN
home_y_negative();
#elif defined Y_MAX_PIN
home_y_positive();
#endif
#if defined Z_MIN_PIN
home_z_negative();
#elif defined Z_MAX_PIN
home_z_positive();
#endif
}
/// find X MIN endstop
void home_x_negative() {
#if defined X_MIN_PIN
TARGET t = startpoint;
t.X = -1000000;
#ifdef SLOW_HOMING
// hit home soft
t.F = SEARCH_FEEDRATE_X;
#else
// hit home hard
t.F = MAXIMUM_FEEDRATE_X;
#endif
enqueue_home(&t, 0x1, 1);
#ifndef SLOW_HOMING
// back off slowly
t.X = +1000000;
t.F = SEARCH_FEEDRATE_X;
enqueue_home(&t, 0x1, 0);
#endif
// set X home
queue_wait(); // we have to wait here, see G92
#ifdef X_MIN
startpoint.X = next_target.target.X = (int32_t)(X_MIN * 1000.0);
#else
startpoint.X = next_target.target.X = 0;
#endif
dda_new_startpoint();
#endif
}
/// find X_MAX endstop
void home_x_positive() {
#if defined X_MAX_PIN && ! defined X_MAX
#warning X_MAX_PIN defined, but not X_MAX. home_x_positive() disabled.
#endif
#if defined X_MAX_PIN && defined X_MAX
TARGET t = startpoint;
t.X = +1000000;
#ifdef SLOW_HOMING
// hit home soft
t.F = SEARCH_FEEDRATE_X;
#else
// hit home hard
t.F = MAXIMUM_FEEDRATE_X;
#endif
enqueue_home(&t, 0x1, 1);
#ifndef SLOW_HOMING
// back off slowly
t.X = -1000000;
t.F = SEARCH_FEEDRATE_X;
enqueue_home(&t, 0x1, 0);
#endif
// set X home
queue_wait();
// set position to MAX
startpoint.X = next_target.target.X = (int32_t)(X_MAX * 1000.);
dda_new_startpoint();
// go to zero
t.X = 0;
t.F = MAXIMUM_FEEDRATE_X;
enqueue(&t);
#endif
}
/// fund Y MIN endstop
void home_y_negative() {
#if defined Y_MIN_PIN
TARGET t = startpoint;
t.Y = -1000000;
#ifdef SLOW_HOMING
// hit home soft
t.F = SEARCH_FEEDRATE_Y;
#else
// hit home hard
t.F = MAXIMUM_FEEDRATE_Y;
#endif
enqueue_home(&t, 0x2, 1);
#ifndef SLOW_HOMING
// back off slowly
t.Y = +1000000;
t.F = SEARCH_FEEDRATE_Y;
enqueue_home(&t, 0x2, 0);
#endif
// set Y home
queue_wait();
#ifdef Y_MIN
startpoint.Y = next_target.target.Y = (int32_t)(Y_MIN * 1000.);
#else
startpoint.Y = next_target.target.Y = 0;
#endif
dda_new_startpoint();
#endif
}
/// find Y MAX endstop
void home_y_positive() {
#if defined Y_MAX_PIN && ! defined Y_MAX
#warning Y_MAX_PIN defined, but not Y_MAX. home_y_positive() disabled.
#endif
#if defined Y_MAX_PIN && defined Y_MAX
TARGET t = startpoint;
t.Y = +1000000;
#ifdef SLOW_HOMING
// hit home soft
t.F = SEARCH_FEEDRATE_Y;
#else
// hit home hard
t.F = MAXIMUM_FEEDRATE_Y;
#endif
enqueue_home(&t, 0x2, 1);
#ifndef SLOW_HOMING
// back off slowly
t.X = -1000000;
t.F = SEARCH_FEEDRATE_Y;
enqueue_home(&t, 0x2, 0);
#endif
// set Y home
queue_wait();
// set position to MAX
startpoint.Y = next_target.target.Y = (int32_t)(Y_MAX * 1000.);
dda_new_startpoint();
// go to zero
t.Y = 0;
t.F = MAXIMUM_FEEDRATE_Y;
enqueue(&t);
#endif
}
/// find Z MIN endstop
void home_z_negative() {
#if defined Z_MIN_PIN
TARGET t = startpoint;
t.Z = -1000000;
#ifdef SLOW_HOMING
// hit home soft
t.F = SEARCH_FEEDRATE_Z;
#else
// hit home hard
t.F = MAXIMUM_FEEDRATE_Z;
#endif
enqueue_home(&t, 0x4, 1);
#ifndef SLOW_HOMING
// back off slowly
t.Z = +1000000;
t.F = SEARCH_FEEDRATE_Z;
enqueue_home(&t, 0x4, 0);
#endif
// set Z home
queue_wait();
#ifdef Z_MIN
startpoint.Z = next_target.target.Z = (int32_t)(Z_MIN * 1000.);
#else
startpoint.Z = next_target.target.Z = 0;
#endif
dda_new_startpoint();
z_disable();
#endif
}
/// find Z MAX endstop
void home_z_positive() {
#if defined Z_MAX_PIN && ! defined Z_MAX
#warning Z_MAX_PIN defined, but not Z_MAX. home_z_positive() disabled.
#endif
#if defined Z_MAX_PIN && defined Z_MAX
TARGET t = startpoint;
t.Z = +1000000;
#ifdef SLOW_HOMING
// hit home soft
t.F = SEARCH_FEEDRATE_Z;
#else
// hit home hard
t.F = MAXIMUM_FEEDRATE_Z;
#endif
enqueue_home(&t, 0x4, 1);
#ifndef SLOW_HOMING
// back off slowly
t.Z = -1000000;
t.F = SEARCH_FEEDRATE_Z;
enqueue_home(&t, 0x4, 0);
#endif
// set Z home
queue_wait();
// set position to MAX
startpoint.Z = next_target.target.Z = (int32_t)(Z_MAX * 1000.);
dda_new_startpoint();
// go to zero
t.Z = 0;
t.F = MAXIMUM_FEEDRATE_Z;
enqueue(&t);
#endif
}