-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreturn.h
75 lines (64 loc) · 1.8 KB
/
return.h
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
#ifndef RETURN_H
#define RETURN_H
#include "xc.h"
#include "drive.h"
#include "math.h"
#define BUMPING_DISTANCE 6
#define ALLIGNMENT_DISTANCE 8
#define COLOR_QRD ADC1BUF13
#define QRD_THRESHOLD 300
static enum circle turning_direction = CLOCKWISE;
void returnSample() {
if (COLOR_QRD < QRD_THRESHOLD) {
turning_direction = COUNTERCLOCKWISE;
} else {
turning_direction = CLOCKWISE;
}
drive_completed = false;
collect_flag = true;
driveStraight(ALLIGNMENT_DISTANCE + (turning_direction ^ 1)*1, FORWARD);
while(!drive_completed) {
driveStraight(ALLIGNMENT_DISTANCE + (turning_direction ^ 1)*2, FORWARD);
}
drive_completed = false;
collect_flag = false;
if (turning_direction == COUNTERCLOCKWISE) {
turnRobot(86, turning_direction);
while(!drive_completed) {
turnRobot(86, turning_direction);
}
} else {
turnRobot(80, turning_direction);
while(!drive_completed) {
turnRobot(80, turning_direction);
}
}
drive_completed = false;
driveStraight(BUMPING_DISTANCE, REVERSE);
while(!drive_completed) {
driveStraight(BUMPING_DISTANCE, REVERSE);
}
stopRobot();
createTimer(1, 7500, 256);
while(!timer_complete) {
}
stopTimers();
drive_completed = false;
collect_flag = true;
driveStraight(BUMPING_DISTANCE-1.5, FORWARD);
while(!drive_completed) {
driveStraight(BUMPING_DISTANCE-1.5, FORWARD);
}
drive_completed = false;
collect_flag = false;
turnRobot(90, turning_direction ^ 1);
while(!drive_completed) {
turnRobot(90, turning_direction ^ 1);
}
stripe_steps = 0;
stripe_count = 0;
stripe_flag = false;
current_state = FOLLOW_LINE;
_AD1IE = 1;
}
#endif /* RETURN_H */