This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclifford_R4.ino
298 lines (237 loc) · 8.3 KB
/
clifford_R4.ino
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
#include <Adafruit_NeoPixel.h>
//#include <Adafruit_NeoPixel.h>
#include <math.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 19
#define NUMPIXELS 12
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500;
int currentColour = 0;
int currentXoffset;
int currentYoffset;
int blobCounter;
//IO Pin Assignments
int drillPin = 15;
int quillSolPin = 0;
int housingSolPin = 1;
int bigBenPin = 2;
int xStepperStep = 4;
int xStepperDir = 3;
int yStepperStep = 5;
int yStepperDir = 14;
int lsA = 6;
int lsB = 7;
int lsC = 8;
int lsD = 9;
int lsE = 10;
int lsF = 11;
int pauseButton = 16;
// Pin 13 has an LED connected on most Arduino boards.
// Pin 11 has the LED on Teensy 2.0
// Pin 6 has the LED on Teensy++ 2.0
// Pin 13 has the LED on Teensy 3.0
// give it a name:
int led = 13;
//Hole Pattern Data
const float plateAngle = 0.0;
float datumHoles[3][2] = {
{-250.0,0.0},
{-250.0,-250.0},
{250.0,0.0}
};
float constrainedHoles[10][2] = {
{12.5,-212.5},
{37.5,-212.5},
{62.5,-212.5},
{87.5,-212.5},
{112.5,-212.5},
{137.5,-212.5},
{162.5,-212.5},
{187.5,-212.5},
{212.5,-212.5},
{237.5,-212.5}
};
float patternCoords[252][2] = {
{-225.0,75.0}, {-225.0,50.0}, {-225.0,25.0}, {-225.0,0.0}, {-225.0,-25.0}, {-225.0,-50.0}, {-225.0,-75.0},
{-200.0,75.0}, {-200.0,50.0}, {-200.0,25.0}, {-200.0,0.0}, {-200.0,-25.0}, {-200.0,-50.0}, {-200.0,-75.0},
{-175.0,75.0}, {-175.0,50.0}, {-175.0,25.0}, {-175.0,0.0}, {-175.0,-25.0}, {-175.0,-50.0}, {-175.0,-75.0},
{-150.0,75.0}, {-150.0,50.0}, {-150.0,25.0}, {-150.0,0.0}, {-150.0,-25.0}, {-150.0,-50.0}, {-150.0,-75.0},
{-125.0,75.0}, {-125.0,50.0}, {-125.0,25.0}, {-125.0,0.0}, {-125.0,-25.0}, {-125.0,-50.0}, {-125.0,-75.0},
{-100.0,75.0}, {-100.0,50.0}, {-100.0,25.0}, {-100.0,0.0}, {-100.0,-25.0}, {-100.0,-50.0}, {-100.0,-75.0},
{-75.0,75.0}, {-75.0,50.0}, {-75.0,25.0}, {-75.0,0.0}, {-75.0,-25.0}, {-75.0,-50.0}, {-75.0,-75.0},
{-50.0,75.0}, {-50.0,50.0}, {-50.0,25.0}, {-50.0,0.0}, {-50.0,-25.0}, {-50.0,-50.0}, {-50.0,-75.0},
{-25.0,75.0}, {-25.0,50.0}, {-25.0,25.0}, {-25.0,0.0}, {-25.0,-25.0}, {-25.0,-50.0}, {-25.0,-75.0},
{0.0,75.0}, {0.0,50.0}, {0.0,25.0}, {0.0,0.0}, {0.0,-25.0}, {0.0,-50.0}, {0.0,-75.0},
{25.0,75.0}, {25.0,50.0}, {25.0,25.0}, {25.0,0.0}, {25.0,-25.0}, {25.0,-50.0}, {25.0,-75.0},
{50.0,75.0}, {50.0,50.0}, {50.0,25.0}, {50.0,0.0}, {50.0,-25.0}, {50.0,-50.0}, {50.0,-75.0},
{75.0,75.0}, {75.0,50.0}, {75.0,25.0}, {75.0,0.0}, {75.0,-25.0}, {75.0,-50.0}, {75.0,-75.0},
{100.0,75.0}, {100.0,50.0}, {100.0,25.0}, {100.0,0.0}, {100.0,-25.0}, {100.0,-50.0}, {100.0,-75.0},
{125.0,75.0}, {125.0,50.0}, {125.0,25.0}, {125.0,0.0}, {125.0,-25.0}, {125.0,-50.0}, {125.0,-75.0},
{150.0,75.0}, {150.0,50.0}, {150.0,25.0}, {150.0,0.0}, {150.0,-25.0}, {150.0,-50.0}, {150.0,-75.0},
{175.0,75.0}, {175.0,50.0}, {175.0,25.0}, {175.0,0.0}, {175.0,-25.0}, {175.0,-50.0}, {175.0,-75.0},
{200.0,75.0}, {200.0,50.0}, {200.0,25.0}, {200.0,0.0}, {200.0,-25.0}, {200.0,-50.0}, {200.0,-75.0},
{225.0,75.0}, {225.0,50.0}, {225.0,25.0}, {225.0,0.0}, {225.0,-25.0}, {225.0,-50.0}, {225.0,-75.0},
{25.0,275.0}, {25.0,250.0}, {25.0,225.0}, {25.0,200.0}, {25.0,175.0}, {25.0,150.0}, {25.0,125.0},
{50.0,275.0}, {50.0,250.0}, {50.0,225.0}, {50.0,200.0}, {50.0,175.0}, {50.0,150.0}, {50.0,125.0},
{75.0,275.0}, {75.0,250.0}, {75.0,225.0}, {75.0,200.0}, {75.0,175.0}, {75.0,150.0}, {75.0,125.0},
{100.0,275.0}, {100.0,250.0}, {100.0,225.0}, {100.0,200.0}, {100.0,175.0}, {100.0,150.0}, {100.0,125.0},
{125.0,275.0}, {125.0,250.0}, {125.0,225.0}, {125.0,200.0}, {125.0,175.0}, {125.0,150.0}, {125.0,125.0},
{150.0,275.0}, {150.0,250.0}, {150.0,225.0}, {150.0,200.0}, {150.0,175.0}, {150.0,150.0}, {150.0,125.0},
{175.0,275.0}, {175.0,250.0}, {175.0,225.0}, {175.0,200.0}, {175.0,175.0}, {175.0,150.0}, {175.0,125.0},
{200.0,275.0}, {200.0,250.0}, {200.0,225.0}, {200.0,200.0}, {200.0,175.0}, {200.0,150.0}, {200.0,125.0},
{225.0,275.0}, {225.0,250.0}, {225.0,225.0}, {225.0,200.0}, {225.0,175.0}, {225.0,150.0}, {225.0,125.0},
{-225.0,-125.0}, {-225.0,-150.0}, {-225.0,-175.0}, {-225.0,-200.0}, {-225.0,-225.0}, {-225.0,-250.0}, {-225.0,-275.0},
{-200.0,-125.0}, {-200.0,-150.0}, {-200.0,-175.0}, {-200.0,-200.0}, {-200.0,-225.0}, {-200.0,-250.0}, {-200.0,-275.0},
{-175.0,-125.0}, {-175.0,-150.0}, {-175.0,-175.0}, {-175.0,-200.0}, {-175.0,-225.0}, {-175.0,-250.0}, {-175.0,-275.0},
{-150.0,-125.0}, {-150.0,-150.0}, {-150.0,-175.0}, {-150.0,-200.0}, {-150.0,-225.0}, {-150.0,-250.0}, {-150.0,-275.0},
{-125.0,-125.0}, {-125.0,-150.0}, {-125.0,-175.0}, {-125.0,-200.0}, {-125.0,-225.0}, {-125.0,-250.0}, {-125.0,-275.0},
{-100.0,-125.0}, {-100.0,-150.0}, {-100.0,-175.0}, {-100.0,-200.0}, {-100.0,-225.0}, {-100.0,-250.0}, {-100.0,-275.0},
{-75.0,-125.0}, {-75.0,-150.0}, {-75.0,-175.0}, {-75.0,-200.0}, {-75.0,-225.0}, {-75.0,-250.0}, {-75.0,-275.0},
{-50.0,-125.0}, {-50.0,-150.0}, {-50.0,-175.0}, {-50.0,-200.0}, {-50.0,-225.0}, {-50.0,-250.0}, {-50.0,-275.0},
};
boolean holeIsDrilled [252];
double absoluteXPosition, absoluteYPosition;
double localXPosition, localYPosition; //Position of the centre drill
float cameraXOffset = -50.0; //Measure these values (to the centre drill)
float cameraYOffset = 50.0;
boolean encodersEnabled = false;
int encoderAXPin = 0;
int encoderBXPin = 0;
int encoderAYPin = 0;
int encoderBYPin = 0;
long programStartTime = 0;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
Serial.begin(115200);
//Initialize IO Pins
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
pinMode(drillPin, OUTPUT);
digitalWrite(drillPin, HIGH);
pinMode(quillSolPin, OUTPUT);
pinMode(housingSolPin, OUTPUT);
pinMode(bigBenPin, OUTPUT);
digitalWrite(quillSolPin, HIGH);
digitalWrite(housingSolPin, HIGH);
digitalWrite(bigBenPin, HIGH);
pinMode(xStepperStep,OUTPUT);
pinMode(xStepperDir,OUTPUT);
pinMode(yStepperStep,OUTPUT);
pinMode(yStepperDir,OUTPUT);
digitalWrite(xStepperStep,HIGH);
digitalWrite(xStepperDir,HIGH);
digitalWrite(yStepperStep,HIGH);
digitalWrite(yStepperDir,HIGH);
pinMode(lsA, INPUT);
pinMode(lsB, INPUT);
pinMode(lsC, INPUT);
pinMode(lsD, INPUT);
pinMode(lsE, INPUT);
pinMode(lsF, INPUT);
pinMode(pauseButton, INPUT_PULLUP);
digitalWrite(pauseButton, HIGH);
//
// if (encodersEnabled)
// {
// //Enable pins with pullup resistors, attach ISRs
// pinMode(encoderAXPin, INPUT);
// digitalWrite(encoderAXPin, HIGH);
// pinMode(encoderBXPin, INPUT);
// digitalWrite(encoderBXPin, HIGH);
// attachInterrupt(encoderAXPin, encoderAX, CHANGE);
// attachInterrupt(encoderBXPin, encoderBX, CHANGE);
//
// pinMode(encoderAYPin, INPUT);
// digitalWrite(encoderAYPin, HIGH);
// pinMode(encoderBYPin, INPUT);
// digitalWrite(encoderBYPin, HIGH);
// attachInterrupt(encoderAYPin, encoderAY, CHANGE);
// attachInterrupt(encoderBYPin, encoderBY, CHANGE);
//
// }
for (int i=0; i<252; i++)
holeIsDrilled[i] = false;
//Adjust coordinates
mirrorX();
if (plateAngle != 0.0)
{
rotateCoords();
}
pixels.begin();
setColour(5);
}
// the loop routine runs over and over again forever:
void loop() {
// digitalWrite(housingSolPin, LOW);\
// delay(5000);
//
// fireBigBen();
// drillsOn();
// housingDown();
// digitalWrite(housingSolPin, LOW);
// delay(20000);
// housingUp();
// drillsOff();
// delay(5000);
// retractBigBen();
//
// abort();
delay(1000);
while(digitalRead(pauseButton)==HIGH)
{
delay(1);
digitalWrite(led, HIGH);
}
programStartTime = millis();
delay(7000);
fireBigBen();
//homeMachine();
//seekDatum();
absoluteXPosition = 0.0;
absoluteYPosition = 0.0;
//lookForHole();
localXPosition = datumHoles[0][0];
localYPosition = datumHoles[0][1];
drillConstrainedHoles();
// seekDatum();
//
// lookForHole();
drillHolePattern();
endSequence();
}
void handlePauseButton()
{
if (digitalRead(pauseButton) == HIGH)
{
drillsOff();
housingUp();
quillUp();
while(digitalRead(pauseButton) == HIGH)
{
delay(1);
}
}
}
void handleTimeout()
{
if(millis() - programStartTime > 3660000)
{
endSequence();
}
}
void endSequence()
{
digitalWrite(led, HIGH);
drillsOff();
quillUp();
housingUp();
homeMachine();
retractBigBen();
while(true)
{
delay(1000);
}
}