-
Notifications
You must be signed in to change notification settings - Fork 0
/
Auto_TEST.java
253 lines (207 loc) · 6.08 KB
/
Auto_TEST.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
249
250
251
252
253
/*
* 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.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.hardware.ColorSensor;
@Autonomous(name = "USE ME Auto_TEST", group = "competition")
public class Auto_TEST extends LinearOpMode {
// Declare OpMode members.
private DcMotor leftWheel = null;
private DcMotor rightWheel = null;
private DcMotor centerWheel = null;
private DcMotor relicExtender = null;
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 int LIFTERMAX = 4000;
private int RELICEXTENDERMAX = 999999999;
private int RELICARMMAX = 999999999;
private String team = "";
private String location = "";
private ColorSensor colorsens = null;
public void print(String Line) {
telemetry.addLine(Line);
telemetry.update();
}
public void drive(int time) {
if (time > 0) {
leftWheel.setPower(.5);
rightWheel.setPower(.5);
} else if (time < 0) {
leftWheel.setPower(-.5);
rightWheel.setPower(-.5);
time = time * -1;
}
sleep(time);
leftWheel.setPower(0);
rightWheel.setPower(0);
sleep(200);
}
public void turn(int time) {
if (time > 0) {
leftWheel.setPower(.5);
rightWheel.setPower(-.5);
} else if (time < 0) {
leftWheel.setPower(-.5);
rightWheel.setPower(.5);
time = time * -1;
}
sleep(time);
leftWheel.setPower(0);
rightWheel.setPower(0);
sleep(200);
}
private void gliffSetlocation(double location) {
leftGliffServo.setPosition(location);
rightGliffServo.setPosition(location);
}
@Override
public void runOpMode() {
leftWheel = hardwareMap.get(DcMotor.class, "leftwheel");
rightWheel = hardwareMap.get(DcMotor.class, "rightwheel");
centerWheel = hardwareMap.get(DcMotor.class, "CenterWheel");
rightCompliant = hardwareMap.get(DcMotor.class, "rightcompliant");
leftCompliant = hardwareMap.get(DcMotor.class, "leftcompliant");
leftWheel.setDirection(DcMotor.Direction.REVERSE);
leftWheel.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
rightWheel.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
centerWheel.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
leftCompliant.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
rightCompliant.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
lifterMotor = hardwareMap.get(DcMotor.class, "liftermotor");
lifterMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
lifterMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
lifterMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
leftGliffServo = hardwareMap.get(Servo.class, "leftServo");
rightGliffServo = hardwareMap.get(Servo.class, "rightServo");
rightGliffServo.scaleRange(0.43, 0.63);
leftGliffServo.scaleRange(0.33, 0.45);
leftGliffServo.setDirection(Servo.Direction.REVERSE);
gemServo = hardwareMap.get(Servo.class, "gemServo");
gemServo.scaleRange(0.141, .8);
relicArm = hardwareMap.get(DcMotor.class, "relicArm");
relicExtender = hardwareMap.get(DcMotor.class, "relicExtender");
relicServo = hardwareMap.get(Servo.class, "relicServo");
relicArm.setMode(DcMotor.RunMode.RUN_TO_POSITION);
relicArm.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
relicExtender.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
colorsens = hardwareMap.get(ColorSensor.class, "revsens");
telemetry.addLine("press B for red, X for blue on controller 1");
telemetry.update();
while (team == "") {
if (gamepad1.b) {
team = "red";
} else if (gamepad1.x) {
team = "blue";
}
}
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 == "") {
if (gamepad1.y) {
location = "close";
} else if (gamepad1.a) {
location = "far";
}
}
telemetry.addData("Team", team);
telemetry.addData("location relative to the relic mat", location);
telemetry.update();
// Wait for the game to start
waitForStart();
print("STARTING!");
gemServo.setPosition(0);
gliffSetlocation(1);
sleep(700);
lifterMotor.setPower(1);
sleep(700);
lifterMotor.setPower(0);
sleep(1000);
telemetry.addData("colorsens: red: %d", colorsens.red());
telemetry.addData("blue:",colorsens.blue());
telemetry.update();
if (team == "red") {
if (colorsens.red() > colorsens.blue()) {
turn(300);
gemServo.setPosition(1);
sleep(20);
turn(-300);
} else {
turn(-300);
gemServo.setPosition(1);
sleep(20);
turn(300);
}
} else {
// we are on blue team
if (colorsens.blue() > colorsens.red()) {
turn(300);
gemServo.setPosition(1);
sleep(20);
turn(-300);
} else {
turn(-300);
gemServo.setPosition(1);
sleep(20);
turn(300);
}
}
//get ready to get off the balance board & face box
if (team == "red") {
drive(-1100);
if (location == "far") {
centerWheel.setPower(.25);
sleep(500);
} else
turn(-675);
} else {
// we are on blue
drive(1100);
if (location == "far"){
centerWheel.setPower(-.25);
sleep(500);
} else {
turn(-625);
}
}
// AFTER THIS; we are now in the safe zone
drive(600);
// attempt to shove the block into the crypt
if (team == "red")
{
centerWheel.setPower(-1);
}
else{
centerWheel.setPower(1);
}
sleep(200);
drive(150);
gliffSetlocation(0);
sleep(600);
centerWheel.setPower(0);
drive(1000);
drive(-1000);
//turn around to the feild
turn(635 * 2);
drive(-1500);
lifterMotor.setPower(-.5);
sleep(500);
lifterMotor.setPower(0);
}
}