-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutonomousRed_G_Gyro.java
239 lines (220 loc) · 14 KB
/
AutonomousRed_G_Gyro.java
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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.hardware.rev.RevBlinkinLedDriver;
@Autonomous(name="(RED) G [2+ Skystones->P2] GYRO", group="Red")
public class AutonomousRed_G_Gyro extends PhoenixBotSharedCode
{
//----------------------------------------------------------------------
//--- Strategy Details ---
//--- Starting Postion: P2 - Face Stones (back edge align on arena crack)
//--- Get the close skystone, deliver to foundation, turn foundation,
//--- pull 45 degree diagnal back and park in P1
//----------------------------------------------------------------------
static final double GYRO_ANGLE_BACKWALL = 0.0;
static final double GYRO_ANGLE_FRONTWALL = 180.0;
static final double GYRO_ANGLE_CENTER = 90.0;
static final double GYRO_ANGLE_STARTWALL = -90.0;
static final double STRAFE_DIST = 12;
static final double SHORTDIST_TIMEOUT = 750;
int SKYSTONE = 1;
int parkDistance = -13;
//----------------------------------------------------------------------
//--- Autonomous Code
//----------------------------------------------------------------------
@Override
public void runOpMode()
{
//----------------------------------------------------------------------
//--- Initialize
//----------------------------------------------------------------------
robot.init(hardwareMap);
InitGyro();
RedInt();
ShowMessage("(RED) G [2+ Skystones->P2] GYRO");
robot.blinkinLedDriver1.setPattern(RevBlinkinLedDriver.BlinkinPattern.RED);
sleep(1000);
robot.blinkinLedDriver1.setPattern(RevBlinkinLedDriver.BlinkinPattern.CP1_2_SINELON);
//----------------------------------------------------------------------
//--- Initialize before Start
//----------------------------------------------------------------------
SetMotorsToBrake();
//----------------------------------------------------------------------
//--- Wait for the game to start (driver presses PLAY)
//----------------------------------------------------------------------
waitForStart();
robot.TIMER_START_AUTO = System.currentTimeMillis();
//----------------------------------------------------------------------
// Set Drive Path
//----------------------------------------------------------------------
LifterToPosition(500); //--- Raise lifter (releases arm)
Strafe45(-1); //--- *** Strafe backwards 45 degrees
SmartSleep(1200); //--- ...for seconds
LifterToPosition(0); //--- Lower lifter
StopMotors(); //--- Stop moving
DriveBackwards(0.7); //--- Align back against wall
SmartSleep(200); //--- ...for seconds
StopMotors(); //--- Stop moving
StrafeLeftToShortDistance(0.3, 5000); //--- Get a set distance from the stones
SKYSTONE = ScanSkystoneLeftSide(); //--- Scan the stones and determine the skystone location
ShowMessage (""+SKYSTONE);
if (SKYSTONE == 3)
{
ShowMessage("Skystone 3");
int stoneOneDistFromWall = 4;
int stoneOneDistUnderBridge = 76;
int stoneTwoDistBack = -52;
int stoneTwoDistUnderBridge = 51;
int stoneThreeDistBack = -41;
int stoneThreeDistUnderBridge = 41;
int stoneFourDistBack = -34;
int stoneFourDistAdjustForScan = 2;
int stoneFourDistUnderBridge = 34;
//First Stone
GyroDrive(1,stoneOneDistFromWall,GYRO_ANGLE_BACKWALL); //--- Move to stone
LSidearmDown(500); //--- Skystone arm down
StrafeRight(1,STRAFE_DIST,99); //--- Strafe away from other stones
GyroDrive(1,stoneOneDistUnderBridge,GYRO_ANGLE_BACKWALL); //--- Move forward under bridge
LSidearmUp(500); //--- Skystone arm up, leaving stone
//Second Stone
GyroDrive(1,stoneTwoDistBack,GYRO_ANGLE_BACKWALL); //--- Move back to next skystone
GyroTurn(GYRO_ANGLE_BACKWALL); //--- Straighten
//--- *** HAD TO ADJUST HERE ***
StrafeLeft(1,STRAFE_DIST-1,99); //--- Strafe right to stone
StrafeLeftToShortDistance(0.3, SHORTDIST_TIMEOUT); //--- Get a set distance from the stones
LSidearmDown(500); //--- Skystone arm down
StrafeRight(1,STRAFE_DIST,99); //--- Strafe away from other stones
GyroDrive(1,stoneTwoDistUnderBridge,GYRO_ANGLE_BACKWALL); //--- Move forward under bridge
LSidearmUp(500); //--- Skystone arm up
//Third Stone
GyroDrive(1,stoneThreeDistBack,GYRO_ANGLE_BACKWALL); //--- Move back to next stone
GyroTurn(GYRO_ANGLE_BACKWALL); //--- Straighten
//--- *** HAD TO ADJUST HERE ***
StrafeLeft(1,STRAFE_DIST-1,99); //--- Strafe right to stone
StrafeLeftToShortDistance(0.3, SHORTDIST_TIMEOUT); //--- Get a set distance from the stones
LSidearmDown(500); //--- Skystone arm down
StrafeRight(1,STRAFE_DIST,99); //--- Strafe away from other stones
GyroDrive(1,stoneThreeDistUnderBridge,GYRO_ANGLE_BACKWALL); //--- Move forward under bridge
LSidearmUp(500); //--- Skystone arm up
//Fourth Stone
GyroDrive(1,stoneFourDistBack,GYRO_ANGLE_BACKWALL); //--- Move back to next stone
GyroTurn(GYRO_ANGLE_BACKWALL); //--- Straighten
StrafeLeft(1,STRAFE_DIST,99); //--- Strafe right to stone
StrafeLeftToShortDistance(0.3, 500); //--- Get a set distance from the stones
GyroDrive(1,stoneFourDistAdjustForScan,GYRO_ANGLE_BACKWALL); //--- Back up to align with stone, note have to ajust back as distance sensor needed to be centered
LSidearmDown(500); //--- Skystone arm down
StrafeRight(1,STRAFE_DIST,99); //--- Strafe away from other stones
GyroDrive(1,stoneFourDistUnderBridge,GYRO_ANGLE_BACKWALL); //--- Move forward under bridge
LSidearmUp(500); //--- Skystone arm up
}
else if (SKYSTONE == 2)
{
ShowMessage("Skystone 2");
int stoneOneDistFromWall = 11;
int stoneOneDistUnderBridge = 65;
int stoneTwoDistBack = -40;
int stoneTwoDistUnderBridge = 44;
int stoneThreeDistBack = -52;
int stoneThreeDistUnderBridge = 52;
int stoneFourDistBack = -34;
int stoneFourDistAdjustForScan = 3;
int stoneFourDistUnderBridge = 36;
//First Stone
//StrafeLeft(1,1,99);
GyroDrive(1,stoneOneDistFromWall,GYRO_ANGLE_BACKWALL); //--- Move to stone
GyroTurn(GYRO_ANGLE_BACKWALL);
LSidearmDown(500); //--- Skystone arm down
StrafeRight(1,STRAFE_DIST,99); //--- Strafe away from other stones
GyroDrive(1,stoneOneDistUnderBridge,GYRO_ANGLE_BACKWALL); //--- Move forward under bridge
LSidearmUp(500); //--- Skystone arm up, leaving stone
//Second Stone
GyroDrive(1,stoneTwoDistBack,GYRO_ANGLE_BACKWALL); //--- Move back to next skystone
GyroTurn(GYRO_ANGLE_BACKWALL); //--- Straighten
//--- *** HAD TO ADJUST HERE ***
StrafeLeft(1,STRAFE_DIST-1,99); //--- Strafe right to stone
StrafeLeftToShortDistance(0.3, 1500); //--- Get a set distance from the stones
LSidearmDown(500); //--- Skystone arm down
StrafeRight(1,STRAFE_DIST,99); //--- Strafe away from other stones
GyroDrive(1,stoneTwoDistUnderBridge,GYRO_ANGLE_BACKWALL); //--- Move forward under bridge
LSidearmUp(500); //--- Skystone arm up
//Third Stone
GyroDrive(1,stoneThreeDistBack,GYRO_ANGLE_BACKWALL); //--- Move back to next stone
GyroTurn(GYRO_ANGLE_BACKWALL); //--- Straighten
//--- *** HAD TO ADJUST HERE ***
StrafeLeft(1,STRAFE_DIST-1,99); //--- Strafe right to stone
StrafeLeftToShortDistance(0.3, 250); //--- Get a set distance from the stones
LSidearmDown(500); //--- Skystone arm down
StrafeRight(1,STRAFE_DIST,99); //--- Strafe away from other stones
GyroDrive(1,stoneThreeDistUnderBridge,GYRO_ANGLE_BACKWALL); //--- Move forward under bridge
LSidearmUp(500); //--- Skystone arm up
//Fourth Stone
GyroDrive(1,stoneFourDistBack,GYRO_ANGLE_BACKWALL); //--- Move back to next stone
GyroTurn(GYRO_ANGLE_BACKWALL); //--- Straighten
StrafeLeft(1,STRAFE_DIST,99); //--- Strafe right to stone
StrafeLeftToShortDistance(0.3, 500); //--- Get a set distance from the stones
GyroDrive(1,stoneFourDistAdjustForScan,GYRO_ANGLE_BACKWALL); //--- Back up to align with stone, note have to ajust back as distance sensor needed to be centered
LSidearmDown(500); //--- Skystone arm down
StrafeRight(1,STRAFE_DIST,99); //--- Strafe away from other stones
GyroDrive(1,stoneFourDistUnderBridge,GYRO_ANGLE_BACKWALL); //--- Move forward under bridge
LSidearmUp(500); //--- Skystone arm up
}
else if (SKYSTONE == 1)
{
ShowMessage("Skystone 1");
int stoneOneDistFromWall = 18;
int stoneOneDistUnderBridge = 57;
int stoneTwoDistBack = -36;
int stoneTwoDistAdjustForScan = 4;
int stoneTwoDistUnderBridge = 36;
int stoneThreeDistBack = -44;
int stoneThreeDistUnderBridge = 41;
int stoneFourDistBack = -49;
int stoneFourDistUnderBridge = 50;
//First Stone
//StrafeLeft(1,2,99);
GyroDrive(1,stoneOneDistFromWall,GYRO_ANGLE_BACKWALL); //--- Move to stone
LSidearmDown(500); //--- Skystone arm down
StrafeRight(1,STRAFE_DIST,99); //--- Strafe away from other stones
GyroDrive(1,stoneOneDistUnderBridge,1500); //--- Move forward under bridge
LSidearmUp(500); //--- Skystone arm up, leaving stone
//Second Stone
GyroDrive(1,stoneTwoDistBack,GYRO_ANGLE_BACKWALL); //--- Move back to next skystone
GyroTurn(GYRO_ANGLE_BACKWALL); //--- Straighten
//--- *** HAD TO ADJUST HERE ***
StrafeLeft(1,STRAFE_DIST-1,99); //--- Strafe right to stone
StrafeLeftToShortDistance(0.3, 250); //--- Get a set distance from the stones
GyroDrive(1,stoneTwoDistAdjustForScan,99);
LSidearmDown(500); //--- Skystone arm down
StrafeRight(1,STRAFE_DIST,99); //--- Strafe away from other stones
GyroDrive(1,stoneTwoDistUnderBridge,GYRO_ANGLE_BACKWALL); //--- Move forward under bridge
LSidearmUp(500); //--- Skystone arm up
//Third Stone
GyroDrive(1,stoneThreeDistBack,GYRO_ANGLE_BACKWALL); //--- Move back to next stone
GyroTurn(GYRO_ANGLE_BACKWALL); //--- Straighten
//--- *** HAD TO ADJUST HERE ***
StrafeLeft(1,STRAFE_DIST-1,99); //--- Strafe right to stone
StrafeLeftToShortDistance(0.3, 250); //--- Get a set distance from the stones
LSidearmDown(500); //--- Skystone arm down
StrafeRight(1,STRAFE_DIST,99); //--- Strafe away from other stones
GyroDrive(1,stoneThreeDistUnderBridge,GYRO_ANGLE_BACKWALL); //--- Move forward under bridge
LSidearmUp(500); //--- Skystone arm up
//Fourth Stone
GyroDrive(1,stoneFourDistBack,GYRO_ANGLE_BACKWALL); //--- Move back to next stone
GyroTurn(GYRO_ANGLE_BACKWALL); //--- Straighten
StrafeLeft(1,STRAFE_DIST,99); //--- Strafe right to stone
StrafeLeftToShortDistance(0.3, 250); //--- Get a set distance from the stones
LSidearmDown(500); //--- Skystone arm down
StrafeRight(1,STRAFE_DIST,99); //--- Strafe away from other stones
GyroDrive(1,stoneFourDistUnderBridge,GYRO_ANGLE_BACKWALL); //--- Move forward under bridge
LSidearmUp(500); //--- Skystone arm up
}
//Park
robot.tapeForwardMotor.setPower(1); //--- Tapemeasure over parking
PlayVictorySound();
SetMotorsToFloat(); //--- Turn off Motor Brakes as we just want to go back!
EncoderDrive(1,parkDistance,parkDistance);
robot.tapeForwardMotor.setPower(0); //--- Tapemeasure over parking
SmartSleep(10000);
StopMotors();
}
}