-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautonomous.c
274 lines (258 loc) · 5.73 KB
/
autonomous.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
/////////////////////////////////////////////////////////////////////////////////////////
//
// Funciones Pre-Autonomas
//
//
//
//
/////////////////////////////////////////////////////////////////////////////////////////
void brazoUp()
{
int a=0;
while (a==0){
if(SensorValue[dgtl4]==0){
a=1;
motor[port1] = 0;
motor[port10] = 0;
}
else {
motor[port1] = 127;
motor[port10] = 127;
}
}
}
void brazoDown()
{
int a=0;
while (a==0){
if(SensorValue[dgtl3]==0){
a=1;
motor[port1] = 0;
motor[port10] = 0;
}
else {
motor[port1] = -127;
motor[port10] = -127;
}
}
}
void brazoDownMed()
{
motor[port1] = -127;
motor[port10] = -127;
wait1Msec(200);
motor[port1] = 0;
motor[port10] = 0;
}
void brazoUpMed(float tiempo)
{
motor[port1] = 127;
motor[port10] = 127;
wait1Msec(tiempo*1000);
motor[port1] = 0;
motor[port10] = 0;
}
void adelante(int velocidad, float tiempo, int brazo)
{
motor[port2] = velocidad/4;
motor[port3] = velocidad/4;
motor[port4] = velocidad/4;
motor[port5] = velocidad/4;
wait1Msec(200);
motor[port2] = velocidad/2;
motor[port3] = velocidad/2;
motor[port4] = velocidad/2;
motor[port5] = velocidad/2;
wait1Msec(200);
while(SensorValue[dgtl1]==1 && SensorValue[dgtl5]==1) {
motor[port2] = velocidad;
motor[port3] = velocidad;
motor[port4] = velocidad;
motor[port5] = velocidad;
if (brazo==1) {
brazoUp();
}
}
motor[port2] = velocidad;
motor[port3] = velocidad;
motor[port4] = velocidad;
motor[port5] = velocidad;
wait1Msec(tiempo*1000);
motor[port2] = 0;
motor[port3] = 0;
motor[port4] = 0;
motor[port5] = 0;
}
void adelanteTiempo(int velocidad, float tiempo, int brazo)
{
motor[port2] = velocidad/4;
motor[port3] = velocidad/4;
motor[port4] = velocidad/4;
motor[port5] = velocidad/4;
wait1Msec(200);
motor[port2] = velocidad/2;
motor[port3] = velocidad/2;
motor[port4] = velocidad/2;
motor[port5] = velocidad/2;
wait1Msec(200);
if (brazo==1) {
brazoUp();
}
motor[port2] = velocidad;
motor[port3] = velocidad;
motor[port4] = velocidad;
motor[port5] = velocidad;
wait1Msec(tiempo*1000);
motor[port2] = 0;
motor[port3] = 0;
motor[port4] = 0;
motor[port5] = 0;
}
void transversal(int velocidad, float tiempo, int brazo)
{
motor[port7] = velocidad/4;
wait1Msec(200);
motor[port7] = velocidad/2;
wait1Msec(200);
if (brazo==1) {
brazoUp();
}
motor[port7] = velocidad;
wait1Msec(tiempo*1000);
motor[port7] = 0;
}
void atras(int velocidad, float tiempo, int brazo)
{
motor[port2] = -velocidad;
motor[port3] = -velocidad;
motor[port4] = -velocidad;
motor[port5] = -velocidad;
if (brazo==1){
brazoUpMed(1.2);
}
wait1Msec(tiempo*1000);
motor[port2] = 0;
motor[port3] = 0;
motor[port4] = 0;
motor[port5] = 0;
}
void click()
{
int a=0;
while (a==0) {
if(SensorValue[dgtl2]==0){
a=1;
}
}
}
void orugaTraga(int velocidad)
{
motor[port9]=-velocidad;
}
void orugaEscupe(int velocidad)
{
motor[port9]=velocidad;
}
void orugaOff()
{
motor[port9]=0;
}
void adelanteLine(int velocidad, int lado)
{
int turnLeft=0;
int turnRight=0;
motor[port2] = velocidad;
motor[port3] = velocidad;
motor[port4] = velocidad;
motor[port5] = velocidad;
wait1Msec(1000);
if (lado==-1) {
while(SensorValue[lnL]>2960) {
motor[port2] = velocidad;
motor[port3] = velocidad;
motor[port4] = velocidad;
motor[port5] = velocidad;
}
}
else {
while(SensorValue[lnR]>2900) {
motor[port2] = velocidad;
motor[port3] = velocidad;
motor[port4] = velocidad;
motor[port5] = velocidad;
}
}
motor[port2] = velocidad * lado;
motor[port3] = velocidad * lado;
motor[port4] = -velocidad * lado;
motor[port5] = -velocidad* lado;
wait1Msec(160);
motor[port2] = 0;
motor[port3] = 0;
motor[port4] = 0;
motor[port5] = 0;
brazoUp();
while(SensorValue[dgtl1]==1 && SensorValue[dgtl5]==1 && SensorValue[dgtl6]==1) {
motor[port2] = velocidad/2-turnLeft;
motor[port3] = velocidad/2-turnLeft;
motor[port4] = velocidad/2-turnRight;
motor[port5] = velocidad/2-turnRight;
if (SensorValue[lnR]<2900) {
turnLeft=velocidad/2;
}
else if (SensorValue[lnL]<2960) {
turnRight=velocidad/2;
}
else {
turnLeft=0;
turnRight=0;
}
}
motor[port2] = 0;
motor[port3] = 0;
motor[port4] = 0;
motor[port5] = 0;
}
void girar(int velocidad,float tiempo, int lado) {
motor[port2]= velocidad;
motor[port3]= velocidad;
motor[port4]= -velocidad;
motor[port5]= -velocidad;
wait1Msec(tiempo * 1000);
motor[port2]= 0;
motor[port3]= 0;
motor[port4]= 0;
motor[port5]= 0;
}
void autoAdelante(int lado) {
//brazoUp();
//adelante(127, 0, 0); //3 espacio: Levantar brazo mientras avanza =1,
//brazoDownMed();
//atras(127, 1.5, 0);
//brazoDown();
//click();
//adelante(127, 0, 1);
//brazoDownMed();
//atras(127, 1.5, 0);
//brazoDown();
//click();
//adelanteTiempo(127, 1.5, 0); //Levantar brazo mientras avanza =1,
////adelanteLine(127, lado); //Lado Derecho = 1, Lado Izquierdo = -1
adelanteTiempo(127, 1.5, 0); //Levantar brazo mientras avanza =1,
orugaEscupe(127);
}
void autoAtras(int lado) {
orugaTraga(127);
adelanteTiempo(127, 0.4, 0); //Levantar brazo mientras avanza =1,
wait1Msec(200);
orugaOff();
//girar(127, 0.4, 1);
transversal((65*lado), 2, 0);
atras(127, 1.1, 0);
transversal((65*lado), 1.6, 0);
adelanteTiempo(127, 0.6, 0); //Levantar brazo mientras avanza =1,
atras(127, 1.3, 0); //brazoupMed 1
adelanteTiempo(127, 0.5, 0); //Levantar brazo mientras avanza =1,
transversal((65*lado), 1, 0);
atras(127, 1, 0);
}