-
Notifications
You must be signed in to change notification settings - Fork 0
/
Movernos.cpp
188 lines (175 loc) · 3.94 KB
/
Movernos.cpp
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
/*
* Name: Movernos.cpp
* Description:
*
*
*/
#include <vexMotor.h>
#include "Config.h"
#include "Sensores.h"
#include "Posibilidades.h"
#define num 255
#define factor 10
vexMotor vMotorLeftDown;
vexMotor vMotorLeftUp;
vexMotor vMotorRightUp;
vexMotor vMotorRightDown;
int x = 0;
int y = 0;
float angle = 0;
int arrayM[100];
int countM=0;
int arrayD[100];
int countD=0;
void motorsSetup()
{
vMotorLeftDown.attach(leftMotor);
vMotorLeftUp.attach(rightMotor);
vMotorRightUp.attach(frontMotor);
vMotorRightDown.attach(backMotor);
}
char decisionR(String codigo){
char posib;
if(codigo.length()<= 1)
posib=codigo.charAt(0);
else{
arrayD[countD]= countM;
countD++;
long m =random(codigo.length());
posib = codigo.charAt(m);
}
return posib;
}
void MovernosHacia(String P)
{
char posibilidad = decisionR(P);
switch(posibilidad)
{
case '1': x = 0;
y = num;
arrayM[countM]=3;
countM++;
break;
case '2': x = num;
y = 0;
arrayM[countM]=4;
countM++;
break;
case '3': x = 0;
y = -num;
arrayM[countM]=1;
countM++;
break;
case '4': x = -num;
y = 0;
arrayM[countM]=2;
countM++;
break;
//case '9': aUltimaD();
//break;
default: x = 0;
y = 0;
countM++;
break;
}
long lCurrentDistance = getDistance(posibilidad);
float fRampAngle = 0;
while(getDistance(posibilidad) < (lCurrentDistance-30))
{
//Angulo //Actualizar el angulo para corregir la trayectoria
vMotorLeftDown.write(-x+y-angle*factor);
vMotorLeftUp.write(x-y-angle*factor);
vMotorRightUp.write(-x-y-angle*factor);
vMotorRightDown.write(x+y-angle*factor);
fRampAngle += getAngleX();
if (fRampAngle > 20 )
{
pos ActualPos = getPosition();
universo[ActualPos.x][ActualPos.y][ActualPos.z-1];
}
if (fRampAngle < -20 )
{
pos ActualPos = getPosition();
universo[ActualPos.x][ActualPos.y][ActualPos.z+1];
}
while(fRampAngle < -20){
vMotorLeftDown.write(0);
vMotorLeftUp.write(0);
vMotorRightUp.write(0);
vMotorRightDown.write(0);
}
}
vMotorLeftDown.write(0);
vMotorLeftUp.write(0);
vMotorRightUp.write(0);
vMotorRightDown.write(0);
}
void aUltimaD()
{
for(int h=countM ; h>0 ; h--)
{
char posibilidad = decisionR(String(arrayM[h]));
switch(posibilidad)
{
case '1': x = 0;
y = num;
arrayM[countM]=3;
break;
case '2': x = num;
y = 0;
arrayM[countM]=4;
break;
case '3': x = 0;
y = -num;
arrayM[countM]=1;
break;
case '4': x = -num;
y = 0;
arrayM[countM]=2;
break;
//case '9': aUltimaD();
break;
default: x = 0;
y = 0;
break;
}
long lCurrentDistance = getDistance(posibilidad);
while(getDistance(posibilidad) < (lCurrentDistance-30))
{
//Angulo //Actualizar el angulo para corregir la trayectoria
vMotorLeftDown.write(-x+y-angle*factor);
vMotorLeftUp.write(x-y-angle*factor);
vMotorRightUp.write(-x-y-angle*factor);
vMotorRightDown.write(x+y-angle*factor);
}
vMotorLeftDown.write(0);
vMotorLeftUp.write(0);
vMotorRightUp.write(0);
vMotorRightDown.write(0);
countM--;
}
countD--;
}
void EstarEnRampa()
{
}
void Rotacion(float AnguloDeseado)
{
float fAnguloActual = 0;
while(fAnguloActual<AnguloDeseado)
{
vMotorLeftDown.write(100);
vMotorLeftUp.write(100);
vMotorRightUp.write(100);
vMotorRightDown.write(100);
fAnguloActual += getAngle();
}
}
void test()
{
//Angulo //Actualizar el angulo para corregir la trayectoria
vMotorLeftDown.write(0);
vMotorLeftUp.write(0);
vMotorRightUp.write(0);
vMotorRightDown.write(0);
}