36
36
#define YSERVO 6
37
37
#define ZSERVO 7
38
38
39
+ #define SENSEPIN 53
40
+
39
41
#define TOLERANCE .3//this sets how close to the target point the tool must be before it moves on.
40
42
#define MOVETOLERANCE .2 //this sets how close the machine must be to the target line at any given moment
41
43
@@ -1159,6 +1161,7 @@ void G10(String readString){
1159
1161
int ManualControl (String readString ){
1160
1162
String readString2 = readString ;
1161
1163
int stringLength = readString2 .length ();
1164
+ long tmptime = millis ();
1162
1165
while (1 ){
1163
1166
if (Serial .available ()){
1164
1167
while (Serial .available ()) {
@@ -1174,23 +1177,51 @@ int ManualControl(String readString){
1174
1177
if (stringLength > 0 ){
1175
1178
Serial .println (readString2 );
1176
1179
1177
- if (readString2 == "Exit Manual Control" ){
1180
+ if (readString2 == "Exit Manual Control " ){
1178
1181
Serial .println ("Test Complete" );
1179
1182
return (1 );
1180
1183
}
1181
- if (readString2 .indexOf ('X' ) > 2 ){
1184
+ if (readString2 .indexOf ('X' ) > 2 && readString2 . indexOf ( 'B' ) == 0 ){
1182
1185
x .write ((readString2 .substring (5 )).toInt ());
1186
+ tmptime = millis ();
1183
1187
}
1184
- if (readString2 .indexOf ('Y' ) > 2 ){
1188
+ if (readString2 .indexOf ('Y' ) > 2 && readString2 . indexOf ( 'B' ) == 0 ){
1185
1189
y .write ((readString2 .substring (5 )).toInt ());
1190
+ tmptime = millis ();
1186
1191
}
1187
- if (readString2 .indexOf ('Z' ) > 2 ){
1192
+ if (readString2 .indexOf ('Z' ) > 2 && readString2 . indexOf ( 'B' ) == 0 ){
1188
1193
z .write ((readString2 .substring (5 )).toInt ());
1194
+ tmptime = millis ();
1189
1195
}
1190
1196
1191
1197
Serial .println ("gready" );
1192
1198
}
1199
+ if (millis () - tmptime > 5000 ){
1200
+ Serial .println ("Test Complete - Timed Out" );
1201
+ return (1 );
1202
+ }
1193
1203
1194
1204
readString2 = "" ;
1195
1205
}
1196
1206
}
1207
+
1208
+ float toolOffset (int pin ){
1209
+ long tmptime = millis ();
1210
+ long tmpTimeout = millis ();
1211
+ while (1 ){
1212
+ tmptime = millis ();
1213
+ location .ztarget = location .ztarget - .05 ;
1214
+ while (millis () - tmptime < 100 ){ //This is just a delay which doesn't loose the machine's position.
1215
+ SetPos (& location );
1216
+ SetTarget (location .xtarget , location .ytarget , location .ztarget , & location , 123 );
1217
+
1218
+ if (digitalRead (pin ) == 0 ){ //The surface has been found
1219
+ return (location .zpos );
1220
+ }
1221
+ }
1222
+ if (millis () - tmpTimeout > 3000 ){ //if it has to move down for more than three seconds it will time out
1223
+ Serial .println ("Surface not found, position the tool closer to the sufrace and try again." );
1224
+ return (location .zpos );
1225
+ }
1226
+ }
1227
+ }
0 commit comments