-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotor_control009.c
544 lines (514 loc) · 24.2 KB
/
motor_control009.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
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
//motor_control009.c //name and version of the code
#include "sumovore.h" //header which has preset functions for LED and Sumobot in general
#include "motor_control.h" //header containing motor functions.
#include <delays.h> //to implement delays in the function.
void spin_left(void); //spins the robot left on center axis.
void turn_left(void); //turns the robot left.
void straight_fwd(void); //makes the robot go straight.
void turn_right(void); //turns the robot right
void spin_right(void); //spins the robot left on center axis.
void Check_Gaps(void); //check for gaps in the track.
void right_right_angle_turns(void); //turns the robot right by 90 degrees.
void left_right_angle_turns(void); //turns the robot left by 90 degrees.
void sharp_right_turns(void); //for sharp right turns (the angle is less than 90 degrees.)
void sharp_left_turns(void); //for sharp left turns (the angle is less than 90 degrees.)
void merge_right(void); //merges to a track on the robot's right.
void merge_left(void); //merges to a track on the robot's left.
//added this
void final_ends(void); //the final action the robot will take when it reaches the end line. (stops the robot.)
void motor_control(void) //Different scenerios that will light up the LEDs in a certain way,
//and the motor reactions to the scenarios.
{
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) straight_fwd(); //00100
else if (SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) spin_left(); //10000
else if (SeeLine.b.Left&&SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) spin_left(); //11000
else if (!SeeLine.b.Left&&SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) turn_left(); //01000
else if (!SeeLine.b.Left&&SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) turn_left(); //01100
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&SeeLine.b.CntRight&&!SeeLine.b.Right) turn_right();//00010
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&SeeLine.b.CntRight&&!SeeLine.b.Right) turn_right(); //00110
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&SeeLine.b.Right) spin_right();//00001
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&SeeLine.b.CntRight&&SeeLine.b.Right) spin_right(); //00011
else if ( (SeeLine.B ) == 0b00000u) Check_Gaps(); //00000 //all LEDs OFF
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&SeeLine.b.CntRight&&SeeLine.b.Right) right_right_angle_turns(); //00111
else if (SeeLine.b.Left&&SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) left_right_angle_turns(); //11100
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&SeeLine.b.Right) sharp_right_turns(); //00101
else if (SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) sharp_left_turns(); //10100
else if (SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&SeeLine.b.CntRight&&!SeeLine.b.Right) merge_right(); //10010
else if (!SeeLine.b.Left&&SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&SeeLine.b.Right) merge_left(); //01001
else if (SeeLine.b.Left&&SeeLine.b.CntLeft&&!SeeLine.b.Center&&SeeLine.b.CntRight&&!SeeLine.b.Right) merge_right(); //11010
else if (!SeeLine.b.Left&&SeeLine.b.CntLeft&&!SeeLine.b.Center&&SeeLine.b.CntRight&&SeeLine.b.Right) merge_left(); //01011
else if (SeeLine.b.Left&&SeeLine.b.CntLeft&&SeeLine.b.Center&&SeeLine.b.CntRight&&SeeLine.b.Right) final_ends(); //11111 //all LEDs ON
}
void spin_left(void) // to spin left
{
set_motor_speed(left, rev_fast, 0); //left wheel goes reverse //wheels move in opposite direction
set_motor_speed(right, fast, 0); //right wheel goes straight //to spin the robot right on center axis.
}
void turn_left(void) // to turn left
{
set_motor_speed(left, medium, 0); //left wheel medium down (for prev. versions, left wheel stops.)
set_motor_speed(right, fast, 0); //right wheel maintains fast speed
}
void straight_fwd(void) // to move forward
{
set_motor_speed(left, fast, 0); // both left wheel and //-40 for motor adjustment to match
set_motor_speed(right, fast, -40); // right wheel moves fast //speed of both wheels
}
void spin_right(void) // to spin left
{
set_motor_speed(left, fast, 0); //left wheel goes straight //wheels move in opposite direction
set_motor_speed(right, rev_fast, 0); //right wheels goes reverse //to spin the robot left on center axis
}
void turn_right(void) //to turn right
{
set_motor_speed(left, fast, 0); //left wheel maintains fast speed
set_motor_speed(right, medium, 0); //right wheels medium down (for prev. versions, right wheel stops.)
}
void merge_right(void) //not merging left <--------- don't know what this is supposed to be
{
set_motor_speed(left, fast, 0); //NOTE:: this is the same as turn right in v004
set_motor_speed(right, stop, 0); //NOTE:: this is the same as turn right in v004
}
void merge_left(void) //not merging right <-------- don't know what this is supposed to be
{
set_motor_speed(left, stop, 0); //NOTE:: this is the same as turn left
set_motor_speed(right, fast, -40);//NOTE:: this is the same as turn left (also, -40 for motor adjustment)
}
//************* CHECK GAPS *************//
void Check_Gaps(void) //checks gaps and makes a 180 degree turn after going about 8cm (needs to be exact.)
{
int sensor_check = 0; //variable sensor check
for(sensor_check; sensor_check < 10; sensor_check++) //executes 20 times, looking for gaps in each count.
{
check_sensors(); //constantly keeps checking for LED combinations
if ( (SeeLine.B ) == 0b00000u) //all LEDs OFF
{
straight_fwd(); //go straight
Delay10KTCYx(20); //0.025s OR 25ms.
if( sensor_check == 9) //last condition
{
turn_180 ();
straight_fwd();
}
}
else
{
sensor_check = 9;
}
}
}
//*****************RIGHT RIGHT ANGLE TURN********************//
void right_right_angle_turns(void) //right right angle turns, if-else cases cover sharp turns as well
{
straight_fwd();
Delay10KTCYx(50); //Changed from Delay10KTCYx(25); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations.
if ( (SeeLine.B ) == 0b00000u) //all LEDs OFF.
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //while all off; 00000
{
spin_right(); //spins the robot right.
check_sensors(); //constantly keeps checking to see LED combinations.
}
}
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&SeeLine.b.CntRight&&!SeeLine.b.Right) //00010
{
straight_fwd(); //go straight
Delay10KTCYx(50); //Changed from Delay10KTCYx(25); (v 009)
check_sensors();
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000
{
spin_right(); //spins the robot right.
check_sensors(); //constantly keeps checking to see LED combinations.
}
}
}
else if (!SeeLine.b.Left&&SeeLine.b.CntLeft&&SeeLine.b.Center&&SeeLine.b.CntRight&&!SeeLine.b.Right) //01110
{
straight_fwd(); //Go straight.
Delay10KTCYx(50); //Changed from Delay10KTCYx(25); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations.
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000
{
spin_right(); //Rotates Right
check_sensors(); //constantly keeps checking to see LED combinations.
}
}
}
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00100
{
straight_fwd(); //Go straight.
Delay10KTCYx(50); //Changed from Delay10KTCYx(25); (v 009)
check_sensors(); //contantly keeps checking to see LED combinations.
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000
{
spin_right(); //spins right
check_sensors(); //constantly keeps checking to see LED combinations.
}
}
}
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&SeeLine.b.CntRight&&!SeeLine.b.Right) //00110
{
straight_fwd(); //Go straight.
Delay10KTCYx(50); //Changed from Delay10KTCYx(25); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations.
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000
{
spin_right(); //Rotates right.
check_sensors(); //constantly keeps checking to see LED combinations.
}
}
}
else;
}
//*************************LEFT RIGHT ANGLE TURN*****************************//
void left_right_angle_turns(void) //left right angle turns, if else cases cover sharp turns aswell
{
straight_fwd(); //go straight
Delay10KTCYx(50); //Changed from Delay10KTCYx(25); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations.
if ( (SeeLine.B ) == 0b00000u) //all LEDS OFF
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_left(); //spins left (was spin right in v004)
check_sensors(); //constantly keeps checking to see LED combinations.
}
}
else if (!SeeLine.b.Left&&SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//01000
{
straight_fwd();
Delay10KTCYx(50); //Changed from Delay10KTCYx(25); (v 009)
check_sensors();
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_left(); //spins left (was spin right in v004).
check_sensors(); //constantly keeps checking to see LED combinations.
}
}
}
else if (!SeeLine.b.Left&&SeeLine.b.CntLeft&&SeeLine.b.Center&&SeeLine.b.CntRight&&!SeeLine.b.Right)//01110
{
straight_fwd(); //go straight
Delay10KTCYx(50); //Changed from Delay10KTCYx(25); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations.
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_left(); //spins left (was spin right in v004).
check_sensors(); //constantly keeps checking to see LED combinations.
}
}
}
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00100
{
straight_fwd(); //go straight
Delay10KTCYx(50); //Changed from Delay10KTCYx(25); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations.
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_left(); //spins left (was spin right in v004).
check_sensors(); //constantly keeps checking to see LED combinations. }
}
}
else if (!SeeLine.b.Left&&SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//01100
{
straight_fwd(); //go straight
Delay10KTCYx(50); //Changed from Delay10KTCYx(25); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations.
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_left(); //spins left (was spins right in v004);
check_sensors(); //constantly keeps checking to see LED combinations.
}
}
}
else;
}
}
//***************************SHARP RIGHT TURN******************//
void sharp_right_turns(void) //sharp right turns
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000 sees nothing
{
spin_right(); //spins right
check_sensors(); //constantly keeps checking to see LED combinations
}
}
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&SeeLine.b.Right) //00101
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations.
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000
{
spin_right(); //spins right
check_sensors(); //constantly keeps checking to see LED combinations.
}
}
}
//THIS WAS ADDED IN v008
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&SeeLine.b.CntRight&&SeeLine.b.Right)//00111
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_right(); //spins right
check_sensors(); //constantly keeps checking to see LED combinations
}
}
}
//FUNCTION STOPS HERE
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&SeeLine.b.CntRight&&SeeLine.b.Right) //00011
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right) //00000
{
spin_right(); //spins right
check_sensors(); //constantly keeps checking to see LED combinations
}
}
}
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&SeeLine.b.CntRight&&!SeeLine.b.Right)//00010
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_right(); //spins right
check_sensors(); //constantly keeps checking to see LED combinations.
}
}
}
else if (!SeeLine.b.Left&&SeeLine.b.CntLeft&&SeeLine.b.Center&&SeeLine.b.CntRight&&!SeeLine.b.Right)//01110
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations.
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_right(); //spins right
check_sensors(); //constantly keeps checking to see LED combinations
}
}
}
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00100
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_right(); //spins right
check_sensors(); //constantly keeps checking to see LED combinations
}
}
}
else if (!SeeLine.b.Left&&SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//01100
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_right(); //spins right
check_sensors(); //constanlty keeps checking to see LED combinations
}
}
}
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&SeeLine.b.CntRight&&!SeeLine.b.Right)//00110
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations.
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_right(); //spins right
check_sensors(); //constantly keeps checking to see LED combinations.
}
}
}
else;
}
//**********************SHARP LEFT TURNS*********************//
void sharp_left_turns(void) //sharp left turns
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_left(); //spins left (was spin right in v004)
check_sensors(); //constantly keeps checking to see LED combinations
}
}
else if (SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//10100
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_left(); //spins left (was spin right in v004);
check_sensors(); //constantly keeps checking to see LED combinations
}
}
}
//WE ADDED THIS LINE TO SEE IF IT MAKES A DIFFERENCE (ADDED IN v008)
else if (SeeLine.b.Left&&SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//11100
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_left(); //spins left (was spin right in v004)
check_sensors(); //constantly keeps checking to see LED combinations
}
}
}
//THIS LINE FUNCTION ENDS HERE
else if (SeeLine.b.Left&&SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//11000
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_left(); //spins left (was spin right in v004);
check_sensors(); //constantly keeps checking to see LED combinations
}
}
}
else if (!SeeLine.b.Left&&SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//01000
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_left(); //spins left (was spin right in v004)
check_sensors(); //constantly keeps checking to see LED combinations
}
}
}
else if (!SeeLine.b.Left&&SeeLine.b.CntLeft&&SeeLine.b.Center&&SeeLine.b.CntRight&&!SeeLine.b.Right)//01110
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_left(); //spins left (was spin right in v004)
check_sensors(); //constantly keeps checking to see LED combinations
}
}
}
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00100
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_left(); //spins left (was spin right in v004)
check_sensors(); //constantly keeps checking to see LED combinations
}
}
}
else if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&SeeLine.b.Center&&SeeLine.b.CntRight&&!SeeLine.b.Right)//00110
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
spin_left(); //spins left (was spin right in v004)
check_sensors(); //constantly keeps checking to see LED combinations
}
}
}
else if (!SeeLine.b.Left&&SeeLine.b.CntLeft&&SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//01100
{
straight_fwd(); //go straight
Delay10KTCYx(130); //Changed from Delay10KTCYx(50); (v 009)
check_sensors(); //constantly keeps checking to see LED combinations
if (!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//00000
{
while(!SeeLine.b.Left&&!SeeLine.b.CntLeft&&!SeeLine.b.Center&&!SeeLine.b.CntRight&&!SeeLine.b.Right)//0000
{
spin_left(); //spins left (was spin right in v004)
check_sensors(); //constantly keeps checking to see LED combinations.
}
}
}
else;
}
void final_ends(void) //stops robot when it comes to black platform
{
straight_fwd(); //go straight
Delay10KTCYx(150); //0.1875s
check_sensors(); //constantly keeps checking to see LED combinations
while(SeeLine.b.Left&&SeeLine.b.CntLeft&&SeeLine.b.Center&&SeeLine.b.CntRight&&SeeLine.b.Right) //11111 //all LEDs ON
{
motors_brake_all(); //stops all motor
check_sensors(); //constantly keeps checking to see LED combinations
}
}