-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerialRefs.cpp
343 lines (267 loc) · 6.28 KB
/
SerialRefs.cpp
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
//
//
//
#include "SerialRefs.h"
#include "defs.h"
SerialCommand SCmd;
extern motion_xy motionxy;
extern motion_z motionz;
void Serial_init()
{
SCmd.addCommand("MOVRELXY", moveXY_rel_serial);
SCmd.addCommand("MOVABSXY", moveXY_abs_serial);
SCmd.addCommand("MOVRELZ", moveZ_rel_serial);
SCmd.addCommand("MOVABSZ", moveZ_abs_serial);
SCmd.addCommand("HOMEXY", home_XY_serial);
SCmd.addCommand("RESET_POSXY", XY_init_absolute_serial);
SCmd.addCommand("HOMEZ", home_Z_serial);
SCmd.addCommand("RESET_POSZ", Z_init_absolute_serial);
SCmd.addCommand("SELHEAD", SelectProbe_serial);
SCmd.addCommand("FINDSURFACE", find_surface_serial);
SCmd.addCommand("GETPOS", get_pos_serial);
SCmd.addCommand("SHUTDOWN", shutdown_serial);
SCmd.setDefaultHandler(unrecognized);
}
// This gets set as the default handler, and gets called when no other command matches.
void unrecognized(const char *command) {
Serial.println("What?");
}
void moveXY_rel_serial()
{
float posx = 0.0;
float posy = 0.0;
float speed = 0.0;
char *arg;
arg = SCmd.next();
if (arg != NULL)
{
posx=atof(arg); // Converts a char string to float
}
else return;
arg = SCmd.next();
if (arg != NULL)
{
posy=atof(arg); // Converts a char string to float
}
else return;
arg = SCmd.next();
if (arg != NULL)
{
speed=atof(arg); // Converts a char string to float
}
else return;
Serial.print("Relative XY motion to (");
Serial.print(posx);
Serial.print(", ");
Serial.print(posy);
Serial.print(") at a speed of ");
Serial.print(speed);
Serial.print(".\n");
moveXY_rel(posx, posy, speed);
Serial.print("MOVRELXY DONE\n\n");
}
void moveXY_abs_serial()
{
float posx = 0.0;
float posy = 0.0;
float speed = 0.0;
char *arg;
arg = SCmd.next();
if (arg != NULL)
{
posx=atof(arg); // Converts a char string to an integer
}
else return;
arg = SCmd.next();
if (arg != NULL)
{
posy=atof(arg); // Converts a char string to an integer
}
else return;
arg = SCmd.next();
if (arg != NULL)
{
speed=atof(arg); // Converts a char string to an integer
}
else return;
Serial.print("Absolute XY motion to (");
Serial.print(posx);
Serial.print(", ");
Serial.print(posy);
Serial.print(") at a speed of ");
Serial.print(speed);
Serial.print(".\n");
moveXY_abs(posx, posy, speed);
Serial.print("MOVABSXY DONE\n\n");
}
void moveZ_rel_serial()
{
float posz = 0.0;
float speed = 0.0;
int hardstop = 0;
int contact = 0;
float indent = 1.0;
char *arg;
arg = SCmd.next();
if (arg != NULL)
{
posz=atof(arg); // Converts a char string to an integer
}
else return;
arg = SCmd.next();
if (arg != NULL)
{
speed=atof(arg); // Converts a char string to an integer
}
else return;
arg = SCmd.next();
if (arg != NULL)
{
hardstop=atoi(arg); // Converts a char string to an integer
}
arg = SCmd.next();
if (arg != NULL)
{
contact=atoi(arg); // Converts a char string to an integer
}
arg = SCmd.next();
if (arg != NULL)
{
indent=atof(arg); // Converts a char string to an integer
}
Serial.print("Relative Z motion to ");
Serial.print(posz);
Serial.print(" at a speed of ");
Serial.print(speed);
Serial.print(".\n");
moveZ_rel(posz, speed, (hardstop != 0), (contact != 0), indent);
Serial.print("MOVRELZ DONE\n\n");
}
void moveZ_abs_serial()
{
float posz = 0.0;
float speed = 0.0;
int hardstop = 0;
int contact = 0;
float indent = 1.0;
char *arg;
arg = SCmd.next();
if (arg != NULL)
{
posz=atof(arg); // Converts a char string to an integer
}
else return;
arg = SCmd.next();
if (arg != NULL)
{
speed=atof(arg); // Converts a char string to an integer
}
else return;
arg = SCmd.next();
if (arg != NULL)
{
hardstop=atoi(arg); // Converts a char string to an integer
}
arg = SCmd.next();
if (arg != NULL)
{
contact=atoi(arg); // Converts a char string to an integer
}
arg = SCmd.next();
if (arg != NULL)
{
indent=atof(arg); // Converts a char string to an integer
}
Serial.print("Absolute Z motion to ");
Serial.print(posz);
Serial.print(" at a speed of ");
Serial.print(speed);
Serial.print(".\n");
moveZ_abs(posz, speed, (hardstop != 0), (contact != 0), indent);
Serial.print("MOVABSZ DONE\n\n");
}
void SelectProbe_serial()
{
int probe = 0;
char *arg;
arg = SCmd.next();
if (arg != NULL)
{
probe=atoi(arg); // Converts a char string to an integer
}
else return;
Serial.print("Selecting probe number ");
Serial.print(probe);
Serial.print(".\n");
SelectProbe(probe);
Serial.print("SELHEAD DONE\n\n");
}
void home_XY_serial() {
Serial.print("Homing XY axes.\n");
home_XY();
Serial.print("HOMEXY DONE\n\n");
}
void XY_init_absolute_serial() {
Serial.print("Resetting XY position.\n");
XY_init_absolute();
Serial.print("RESET_POSXY DONE\n\n");
}
void home_Z_serial() {
Serial.print("Homing Z axis.\n");
home_Z();
Serial.print("HOMEZ DONE\n\n");
}
void Z_init_absolute_serial() {
Serial.print("Resetting Z position.\n");
Z_init_absolute();
Serial.print("RESET_POSZ DONE\n\n");
}
void find_surface_serial()
{
float pos = 0.0;
int threshold = 0;
char *arg;
arg = SCmd.next();
if (arg != NULL)
{
threshold=atoi(arg); // Converts a char string to an integer
}
else return;
Serial.print("Finding material surface...\n\n");
//pos=find_surface_lc(threshold);
pos=find_surface_cont();
Serial.print("POS: ");
Serial.print(pos);
Serial.print("\n");
Serial.print("FINDSURFACE DONE\n\n");
}
void get_pos_serial() {
char *arg;
int numaxis = 0;
arg = SCmd.next();
if (arg != NULL)
{
numaxis=atoi(arg); // Converts a char string to an integer
}
else return;
delay(200);
Serial.print("POS: ");
switch(numaxis) {
case 1: Serial.print(motionxy.pos_x);
Serial.print("\n");
break;
case 2: Serial.print(motionxy.pos_y);
Serial.print("\n");
break;
case 3: Serial.print(motionz.pos_z);
Serial.print("\n");
break;
}
Serial.print("GETPOS DONE\n\n");
}
void shutdown_serial() {
WRITE(SUICIDE_PIN, LOW);
WRITE(PS_ON_PIN, LOW);
WRITE(O19V_ENABLE_PIN, LOW);
Serial.print("SHUTDOWN DONE\n\n");
}