-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto002
451 lines (408 loc) · 12.1 KB
/
auto002
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
#pragma config(Hubs, S1, HTMotor, HTMotor, HTMotor, HTMotor)
#pragma config(Hubs, S3, HTServo, none, none, none)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Sensor, S2, HTSMUX, sensorI2CCustom)
#pragma config(Sensor, S3, , sensorI2CMuxController)
#pragma config(Sensor, S4, RGB, sensorCOLORFULL)
#pragma config(Motor, mtr_S1_C1_1, yellow, tmotorTetrix, openLoop, encoder)
#pragma config(Motor, mtr_S1_C1_2, red, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C2_1, blue, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C2_2, green, tmotorTetrix, openLoop, encoder)
#pragma config(Motor, mtr_S1_C3_1, arm, tmotorTetrix, openLoop, encoder)
#pragma config(Motor, mtr_S1_C3_2, whisk, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C4_1, lift, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C4_2, flag, tmotorTetrix, openLoop)
#pragma config(Servo, srvo_S3_C1_1, autoflipper, tServoStandard)
#pragma config(Servo, srvo_S3_C1_2, wrist, tServoStandard)
#pragma config(Servo, srvo_S3_C1_3, servo3, tServoNone)
#pragma config(Servo, srvo_S3_C1_4, servo4, tServoNone)
#pragma config(Servo, srvo_S3_C1_5, servo5, tServoNone)
#pragma config(Servo, srvo_S3_C1_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// auto002.c
//the SMUX is plugged into PORT 2
// the gyro is in port 4 of the SMUX
// the ir is in port 3 of the SMUX
#include "JoystickDriver.c";
#include "statuslight.c";
#include "Sample Programs/NXT/3rd Party Sensor Drivers/drivers/XanderDriverSuite/rdpartyrobotcdr-3.3.1/drivers/hitechnic-sensormux.h"
#include "Sample Programs/NXT/3rd Party Sensor Drivers/drivers/XanderDriverSuite/rdpartyrobotcdr-3.3.1/drivers/hitechnic-gyro.h" //for gyro sensor
#include "Sample Programs/NXT/3rd Party Sensor Drivers/drivers/XanderDriverSuite/rdpartyrobotcdr-3.3.1/drivers/hitechnic-colour-v2.h" //for color sensor
#include "Sample Programs/NXT/3rd Party Sensor Drivers/drivers/XanderDriverSuite/rdpartyrobotcdr-3.3.1/drivers/hitechnic-irseeker-v2.h" //for IR seeker sensor
//#include "Sample Programs/NXT/3rd Party Sensor Drivers/drivers/XanderDriverSuite/rdpartyrobotcdr-3.3.1/drivers/LEGOTS-driver.h" //for touch sensor
#define HTGYRO msensor_S2_4
#define INF msensor_S2_3
float heading = 0;
float heading2 = 4;
int back = 0;
int truncate = 0;
int isthree = 0;
////////////////////////////////////////////Allstop Below//////////////////////////////////////////////////////////////////
void allStop(){
motor[yellow] = 0;
motor[green] = 0;
motor[blue] = 0;
motor[red] = 0;
}
////////////////////////////////////////////Allstop Above///////////////////////////////////////////////////////////////
////////////////////////////////////////////Ramp Below//////////////////////////////////////////////////////////////////
void ramp(){
heading = 0;
nMotorEncoder[yellow] = 0;
nMotorEncoder[green] = 0;
while (nMotorEncoder[yellow] < 2000 || nMotorEncoder[green] > -2000 ){//do that straffing thingy to avoid wood. Numbers might be wrong
motor[red] = -50;
motor[yellow] = 50;
motor[green] = -50;
motor[blue] = 50;
}
//old thing
//motor[blue] = 50;
//motor[red] = -50;
//motor[yellow] = 50;
//motor[green] = -50;
//wait10Msec(50);
allStop();
float localHeading = 0;
heading2 = 0;
//drive in front of ramp
motor[blue] = 50;
wait10Msec(10);
motor[red] = -50;
wait10Msec(200);
allStop();
//turn to face ramp with GYRO
motor[red] = -10;
motor[yellow] = -10;
motor[green] = -10;
motor[blue] = -10;
localHeading=heading2;
eraseDisplay();
while (localHeading > -45){
PlayTone(622,38);
nxtDisplayCenteredTextLine(6, "Heading: %2.3f", localHeading);
localHeading=heading2;
}
allStop();
//old turning thing
//motor[red] = -10;
//motor[yellow] = -10;
//motor[green] = -10;
//motor[blue] = -10;
//wait10Msec(130);
//allStop();
//drive up on that ramp, man
nMotorEncoder[yellow] = 0;
nMotorEncoder[green] = 0;
time1[T4] = 0;
while (nMotorEncoder[yellow] > -4000 && nMotorEncoder[green] < 4000 && time1[T4] < 2000 ){//go to apex of ramp
motor[red] = -100;
motor[yellow] = -100;
motor[green] = 100;
motor[blue] = 100;
}
allStop();
eraseDisplay();
nxtDisplayCenteredTextLine(3, "All Finished");
while(true){//pause while on the ramp until the end of autonomous.
wait10Msec(1);
}
}
////////////////////////////////////////////Ramp Above////////////////////////////////////////////////////////////////////
////////////////////////////////////////////Recall Below//////////////////////////////////////////////////////////////////
void recall(){
float localHeading = 0;
heading2 = 0;
//drive back to start position
while (nMotorEncoder[yellow] >= 900 || nMotorEncoder[green] <= -900){
motor[green] = 30;
motor[yellow] = -30;
}
allStop();
motor[yellow] = -50;
motor[red] = -50;
motor[blue] = 50;
motor[green] = 50;
nMotorEncoder[yellow] = 0;
nMotorEncoder[green] = 0;
while (nMotorEncoder[yellow] > -750 || nMotorEncoder[green] < 750 ){
}
allStop();
motor[blue] = 50;
motor[red] = -50;
wait10Msec(300);
allStop();
wait10Msec(1);
motor[yellow] = -30;
motor[red] = -30;
motor[blue] = -30;
motor[green] = -30;
heading2 = heading;
localHeading=heading2;
while (localHeading > -32){
PlayTone(622,38);
nxtDisplayCenteredTextLine(6, "Heading: %2.3f", localHeading);
localHeading=heading2;
}
allStop();
nMotorEncoder[yellow] = 0;
nMotorEncoder[green] = 0;
motor[red] = 100;
motor[green] = -100;
motor[blue] = -100;
motor[yellow] = 100;
time1[T4] = 0;
while (nMotorEncoder[green] > -4000 && nMotorEncoder[green] < 4000 && time1[T4] < 2000 ){//go to apex of ramp
}
allStop();
while(true){
}
}
////////////////////////////////////////////Recall Above///////////////////////////////////////////////////////
////////////////////////////////////////////Gyro Below//////////////////////////////////////////////////////////
task gyro(){
float rotSpeed = 0;
float heading = 0;
time1[T1] = 0;
while (true){
while (time1[T1] < 20)
wait1Msec(1);
rotSpeed = HTGYROreadRot(HTGYRO);
heading += rotSpeed * (time1[T1] / 1000.0);
nxtDisplayCenteredTextLine(2, "Timer: %2.3f", (time1[T1]));
time1[T1]=0;
nxtDisplayCenteredTextLine(3, "Heading: %2.3f", heading);/*
if (heading >= 360)
heading = (heading - 360);
if (heading <= -1)
heading = (heading + 360);*/
heading2=heading;
}
}
////////////////////////////////////////////Gyro Above//////////////////////////////////////////////////////////////////
////////////////////////////////////////////Dump Below//////////////////////////////////////////////////////////////////
void dump(){
int isback;
isback = back;
if(isthree == 1){
while (nMotorEncoder[yellow] > 4500 || nMotorEncoder[green] < -4500 ){
motor[green] = 30;
motor[yellow] = -30;
}
}
StartTask(gyro);
heading = 0;
heading2 = 0;
float localHeading = 0;
allStop();
PlayTone(622,38);
//rotate to face buckets
motor[red] = 20;
motor[yellow] = 20;
motor[green] = 20;
motor[blue] = 20;
localHeading=heading2;
while (localHeading < 40){
nxtDisplayCenteredTextLine(6, "Heading: %2.3f", localHeading);
localHeading=heading2;
}
allStop();
//stop and dump
servo[autoflipper] = 65;
wait10Msec(100);
servo[autoflipper] = 240;
//turn back and stop
motor[red] = -10;
motor[yellow] = -10;
motor[green] = -10;
motor[blue] = -10;
while (localHeading >= 0){
localHeading=heading2;
}
allStop();
//if come back was selected
eraseDisplay();
if (isback == 1){
recall();
nxtDisplayCenteredTextLine(1,"Recalled");
}
//keep driving to end and a bit more
while (nMotorEncoder[yellow] <= 8500 && nMotorEncoder[green] >= -8500 && time1[T3] < 30000){
motor[green] = -30;
motor[yellow] = 30;
nxtDisplayCenteredTextLine(1,"Time: %f", time1[T3]);
}
allStop();
ramp();
//float ramp_up = heading;
}//END DUMP SECTION
////////////////////////////////////////////Dump Above///////////////////////////////////////////////////////////////////
////////////////////////////////////////////Drive Below//////////////////////////////////////////////////////////////////
void drive(){
time1[T3] = 0;
nMotorEncoder[yellow] = 0;
nMotorEncoder[green] = 0;
//herro frind
//===first bucket===
while (nMotorEncoder[yellow] < 970 || nMotorEncoder[green] > -970 ){//first 1470
motor[green] = -30;
motor[yellow] = 30;
}
PlayTone(622,38);
if (HTIRS2readDCDir(INF) == 3){
dump();
}
//===secoend bucket===
while (nMotorEncoder[yellow] < 2000 || nMotorEncoder[green] > -2000 ){//secoend 2500
motor[green] = -30;
motor[yellow] = 30;
}
PlayTone(622,38); wait10Msec(2);
if (HTIRS2readDCDir(INF) == 3){
dump();
}
//===third bucket===
while (nMotorEncoder[yellow] < 4500 || nMotorEncoder[green] > -4500 ){//third 4800
motor[green] = -30;
motor[yellow] = 30;
}
PlayTone(622,38);
if (HTIRS2readDCDir(INF) == 3){
isthree = 1;
dump();
}
//dump anyway if truncate was selected
if (truncate == 1){
isthree = 1;
dump();
}
//===fourth bucket===
while (nMotorEncoder[yellow] < 5350 || nMotorEncoder[green] > -5350 ){//fourth 5850
motor[green] = -30;
motor[yellow] = 30;
}
PlayTone(622,38);
if (HTIRS2readDCDir(INF) == 3){
dump();
}else{
//dump anyway if it hasen't found the beacon
dump();
}
}
////////////////////////////////////////////Drive Above/////////////////////////////////////////////////////////////////
////////////////////////////////////////////Main Below//////////////////////////////////////////////////////////////////
task main (){
int isthree = 0;
StartTask(blinker);
color1 = "red";
color2 = "none";
HTGYROstartCal(HTGYRO);
servo[wrist] = 0;
servo[autoflipper] = 240;
disableDiagnosticsDisplay();
eraseDisplay();
color1 = "red";
int button = 0;
int waittime = 0;
//add opposite side?
//wait 15 sec
nxtDisplayCenteredTextLine(3, "<-- Wait 15 sec");
nxtDisplayCenteredTextLine(2, "No wait -->");
while(waittime == 0){
if(nNxtButtonPressed == 2){
waittime = 2;
button = 2;
//wait mode
}
if(nNxtButtonPressed == 1){
waittime = 1;
button = 1;
//no wait
}
}
while(nNxtButtonPressed == button){
wait10Msec(10);
}
//Truncate run after third bin, should probably be combined with the come back part
button = 0;
truncate = 2;
eraseDisplay();
nxtDisplayCenteredTextLine(3, "<-- Truncate");
nxtDisplayCenteredTextLine(2, "Full Run-->");
while(truncate == 2){
if(nNxtButtonPressed == 2){
truncate = 1;
button = 2;
//truncate
}
if(nNxtButtonPressed == 1){
truncate = 0;
button = 1;
//proceedes with a full run.
}
}
//stops the NXT from skipping ahead
while(nNxtButtonPressed == button){
wait10Msec(10);
}
//Come back after dump option
button = 0;
back = 2;
eraseDisplay();
nxtDisplayCenteredTextLine(3, "<-- Come back");
nxtDisplayCenteredTextLine(2, "Go on -->");
while(back == 2){
if(nNxtButtonPressed == 2){
back = 1;
button = 2;
//comes back
wait1Msec(10);
}
if(nNxtButtonPressed == 1){
back = 0;
button = 1;
//goes ahead
}
}
while(nNxtButtonPressed == button){
wait10Msec(10);
}
//test mode or tournament option
int waitstart = 0;
nxtDisplayCenteredTextLine(3, "<-- Test Mode");
nxtDisplayCenteredTextLine(2, "Tournament -->");
while(waitstart == 0){
if(nNxtButtonPressed == 2){
nxtDisplayCenteredTextLine(3, "On test mode");
waitstart = 1;
wait10Msec(100);
if (waittime == 2){
wait10Msec(1500);
}
//test mode
}
if(nNxtButtonPressed == 1){
waitstart = 1;
//tournament mode
nxtDisplayCenteredTextLine(2, "Waiting");
nxtDisplayCenteredTextLine(3, "for Start");
color1 = "blue";
waitForStart();
if (waittime == 2){
wait10Msec(1500);
}
}
}
color1 = "blue";
PlayTone(322,33);
drive();
eraseDisplay();
while(true){
nxtDisplayCenteredTextLine(4, "encoder: %2.3f", (nMotorEncoder[yellow]));
nxtDisplayCenteredTextLine(3, "IR: %i", HTIRS2readDCDir(INF));
if (HTSMUXreadPowerStatus(HTSMUX))
nxtDisplayTextLine(7, "SMUX Batt: bad");
else
nxtDisplayTextLine(7, "SMUX Batt: good");
}
}