forked from steam09/FallBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGARY.cpp
More file actions
188 lines (163 loc) · 3.97 KB
/
GARY.cpp
File metadata and controls
188 lines (163 loc) · 3.97 KB
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
#include <kipr/wombat.h>
// Wheels & Motors
const int frontLeftWheel = 3;
const int frontRightWheel = 1;
const int backLeftWheel = 2;
const int backRightWheel = 0;
// Arm
const int hingeServo = 0; // high values is pi radians, low values pi 3 radians
const int topServo = 1; // 0 is down 45 degrees, 2000 is 60 degrees in the unit circle
// Sensors
const int frontLeftTape = 1;
const int frontRightTape = 0;
// Button
const int frontLeftButton = 1;
const int frontRightButton = 0;
const int backLeftButton = 3;
const int backRightButton = 2;
const int whiteTapeValue = 3500; // HIGHER IS DARKER
void calibration();
void resetMotors();
void measureDistances();
void yIncrease(int distance);
void xIncrease(int distance);
void yDecrease(int distance);
void xDecrease(int distance);
void rotateLeft();
void rotateRight();
void calibrateTape();
int main()
{
yDecrease(10);
xIncrease(500);
xDecrease(5);
xIncrease(5);
yIncrease(10);
xDecrease(15);
// Yeah top right board
msleep(500);
xDecrease(150);
yDecrease(400);
xDecrease(60);
msleep(500);
// first stove
xIncrease(50);
yIncrease(400);
xIncrease(150);
// seasoning
yDecrease(140);
yIncrease(10);
xDecrease(150);
yDecrease(580);
xDecrease(70);
msleep(500);
// stove
xIncrease(50);
yIncrease(600);
}
void calibration() {
resetMotors();
(digital(0) == 0) ? printf("Left is stronger!\n") : printf("Right Button Pressed!\n");
if (digital(0) == 0) {
freeze(0);
gmpc(0);
}
else {
freeze(1);
gmpc(1);
}
ao();
printf("Right: %d, Left: %d\n", gmpc(0), gmpc(1));
}
void resetMotors() {
cmpc(frontLeftWheel);
cmpc(frontRightWheel);
cmpc(backLeftWheel);
cmpc(backRightWheel);
msleep(50);
}
void measureDistances() {
}
void yIncrease(int distance) {
motor(frontLeftWheel, 100);
motor(backRightWheel, 100);
motor(frontRightWheel, -100);
motor(backLeftWheel, -100);
msleep(distance * 10);
ao();
msleep(300);
}
void xIncrease(int distance) {
motor(frontLeftWheel, 100);
motor(backRightWheel, 100);
motor(frontRightWheel, 100);
motor(backLeftWheel, 100);
msleep(distance * 10);
ao();
msleep(300);
}
void yDecrease(int distance) {
motor(frontLeftWheel, -100);
motor(backRightWheel, -100);
motor(frontRightWheel, 100);
motor(backLeftWheel, 100);
msleep(distance * 10);
ao();
msleep(300);
}
void xDecrease(int distance) {
motor(frontLeftWheel, -100);
motor(backRightWheel, -100);
motor(frontRightWheel, -100);
motor(backLeftWheel, -100);
msleep(distance * 10);
ao();
msleep(300);
}
void rotateLeft() {
motor(frontLeftWheel, -100);
motor(backRightWheel, 100);
motor(frontRightWheel, 100);
motor(backLeftWheel, -100);
msleep(1000);
ao();
}
void rotateRight() {
motor(frontLeftWheel, 100);
motor(backRightWheel, -100);
motor(frontRightWheel, -100);
motor(backLeftWheel, 100);
msleep(1000);
ao();
}
void calibrateTape() {
while ((digital(frontLeftTape) < 3000) && (digital(frontRightTape) < 3000)) {
motor(frontLeftWheel, 10);
motor(backRightWheel, 10);
motor(frontRightWheel, 10);
motor(backLeftWheel, 10);
msleep(10);
ao();
}
msleep(500);
while (digital(frontLeftTape) < 3500) {
freeze(frontRightWheel);
freeze(backRightWheel);
motor(frontLeftWheel, 10);
motor(backLeftWheel, 10);
printf("%d", digital(frontLeftTape));
printf("%d", digital(frontRightTape));
msleep(5);
}
while (digital(frontRightTape) < 3500) {
freeze(frontLeftWheel);
freeze(backLeftWheel);
motor(frontRightWheel, 10);
motor(backRightWheel, 10);
printf("%d", digital(frontLeftTape));
printf("%d", digital(frontRightTape));
msleep(5);
}
ao();
printf("%d", gmpc(0));
}