-
Notifications
You must be signed in to change notification settings - Fork 1
/
Auto.java
248 lines (211 loc) · 6.41 KB
/
Auto.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
240
241
242
243
244
245
246
247
248
/*
* turn(625) gives you a turn to the leftby 90 degrees.
* this method can be given negative numbers in order to turn right.
*
* drive()
*
*
*/
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.hardware.CRServo;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.hardware.ColorSensor;
@Autonomous(name = "auto", group = "competition")
public class Auto extends LinearOpMode {
// Declare OpMode members.
private DcMotor leftWheel = null;
private DcMotor rightWheel = null;
private DcMotor centerWheel = null;
public static final double GLYPHTOPLEFTOPEN = 0.65;
public static final double GLYPHTOPLEFTCLOSED = 0.46;
public static final double GLYPHTOPRIGHTOPEN = 0.14;
public static final double GLYPHTOPRIGHTCLOSED = 0.37;
private static final double speed = .3;
private static final int gemDist = 400;
private static final int closeToCrypt = 3100;
private static final int cornerToCrypt = -1000;
private static final int cornerForeward = 2000;
private static final int nintydeg = 1100;
private static final int intoCrypt = -800;
private DcMotor relicArm = null;
private Servo relicServo = null;
private DcMotor lifterMotor = null;
private int LIFTERMIN = 0;
private Servo leftGliffServo = null;
private Servo rightGliffServo = null;
private DcMotor leftCompliant = null;
private DcMotor rightCompliant = null;
private Servo gemServo = null;
private Servo GlyphTopLeft = null;
private Servo GlyphTopRight = null;
private CRServo GlyphLifter = null;
public enum Locations {
Close, Far
};
private Locations location;
public enum Teams {
Red, Blue, Testing
};
private Teams team;
private ColorSensor colorsens = null;
public void print(String Line) {
telemetry.addLine(Line);
telemetry.update();
}
public void drive(int delta) {
int curLeft = leftWheel.getCurrentPosition();
int curRight = rightWheel.getCurrentPosition();
leftWheel.setTargetPosition(curLeft + delta);
rightWheel.setTargetPosition(curRight + delta);
leftWheel.setPower(speed);
rightWheel.setPower(speed);
while ((leftWheel.isBusy() || rightWheel.isBusy()) && !isStopRequested())
{
sleep(10);
}
leftWheel.setPower(0);
rightWheel.setPower(0);
}
public void turn(int delta) {
int curLeft = leftWheel.getCurrentPosition();
int curRight = rightWheel.getCurrentPosition();
leftWheel.setTargetPosition(curLeft + delta);
rightWheel.setTargetPosition(curRight - delta);
leftWheel.setPower(speed);
rightWheel.setPower(speed);
while ((leftWheel.isBusy() || rightWheel.isBusy()) && !isStopRequested())
{
sleep(10);
}
leftWheel.setPower(0);
rightWheel.setPower(0);
}
@Override
public void runOpMode() {
leftWheel = hardwareMap.get(DcMotor.class, "leftwheel");
rightWheel = hardwareMap.get(DcMotor.class, "rightwheel");
rightCompliant = hardwareMap.get(DcMotor.class, "rightcompliant");
leftCompliant = hardwareMap.get(DcMotor.class, "leftcompliant");
GlyphTopLeft = hardwareMap.get(Servo.class, "glyphTopLeft");
GlyphTopRight = hardwareMap.get(Servo.class, "glyphTopRight");
GlyphLifter = hardwareMap.get(CRServo.class, "belt drive");
GlyphLifter.setDirection(DcMotor.Direction.REVERSE);
leftWheel.setMode(DcMotor.RunMode.RUN_TO_POSITION);
rightWheel.setMode(DcMotor.RunMode.RUN_TO_POSITION);
rightWheel.setDirection(DcMotor.Direction.REVERSE);
leftWheel.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
rightWheel.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
leftCompliant.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
rightCompliant.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
gemServo = hardwareMap.get(Servo.class, "gemservo");
colorsens = hardwareMap.get(ColorSensor.class, "revsens");
telemetry.addLine("press B for red, X for blue on controller 1");
telemetry.update();
while (team == null || opModeIsActive()) {
if (gamepad1.b) {
team = Teams.Red;
} else if (gamepad1.x) {
team = Teams.Blue;
}
else if (gamepad1.y) {
team = Teams.Testing;
}
}
sleep(300);
telemetry.addData("press Y for CLOSE TO THE RELIC SCORING MAT," +
"press A for FAR FROM THE RELIC SCORING MAT\n\n team was ", team);
telemetry.update();
while (location == null || opModeIsActive()) {
if (gamepad1.y) {
location = Locations.Close;
} else if (gamepad1.a) {
location = Locations.Far;
}
}
telemetry.addData("Team", team);
telemetry.addData("location relative to the relic mat", location);
telemetry.update();
// Wait for the game to start
waitForStart();
if (team == Teams.Testing)
{
print("red > blue ");
return;
}
GlyphTopLeft.setPosition(GLYPHTOPLEFTCLOSED);
GlyphTopRight.setPosition(GLYPHTOPRIGHTCLOSED);
GlyphLifter.setPower(-1);
gemServo.setPosition(0.04);
sleep(1500);
GlyphLifter.setPower(0);
if (team == Teams.Red)
{
if (colorsens.blue() > colorsens.red())
{
print("red > blue ");
drive(-gemDist);
gemServo.setPosition(.9);
sleep(500);
drive(gemDist);
print("end of gems");
} else
{
print("blue > red");
drive(gemDist);
gemServo.setPosition(.9);
sleep(500);
drive(-gemDist);
}
}
else if (team == Teams.Blue)
{
if (colorsens.blue() > colorsens.red()){
drive(gemDist);
gemServo.setPosition(.9);
sleep(500);
drive(-gemDist);
}
else {
drive(-gemDist);
gemServo.setPosition(.9);
sleep(500);
drive(gemDist);
}
} // team == blue
// END OF GEMS
if (team == Teams.Red)
{
if (location == Locations.Close)
{
drive(closeToCrypt);
turn(nintydeg);
}
else
{
drive(cornerForeward);
turn(-nintydeg);
drive(cornerToCrypt);
turn (-nintydeg);
}// location == far
} // team == blue
else
{
if (location == Locations.Close)
{
drive(-closeToCrypt);
turn(nintydeg);
}
else {
drive(-cornerForeward);
turn(-nintydeg);
drive(cornerToCrypt);
turn(nintydeg);
}
} // if team == red for board to crypt
drive(intoCrypt);
turn(nintydeg/6);
} // end of program
}// end of class