-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_RRelic.java0
143 lines (111 loc) · 4.64 KB
/
auto_RRelic.java0
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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DistanceSensor;
import com.qualcomm.robotcore.util.Range;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import android.graphics.Color;
import com.qualcomm.robotcore.hardware.ColorSensor;
//import android.speech.tts.TextToSpeech;
@Autonomous(name = "RedRelic-enc", group = "encoders")
public class auto_RRelic extends LinearOpMode {
private Botbot robot = new Botbot();
ColorSensor colorSense;
DcMotor frontLeft;
DcMotor frontRight;
DcMotor backLeft;
DcMotor backRight;
@Override
public void runOpMode() throws InterruptedException{
robot.init(hardwareMap);
telemetry.addData("Robot", "ready");
colorSense = hardwareMap.get(ColorSensor.class, "sensor_color_distance");
float hsv[] = {0F, 0F, 0F};
final float values[] = hsv;
int scale = 1;
boolean colorIsRed = false;
waitForStart();
robot.jewelArm.setPosition(1);
wait(1000);
Color.RGBToHSV((int) (colorSense.red() * scale),
(int) (colorSense.green() * scale),
(int) (colorSense.blue() * scale),
hsv);
if(hsv[0] < 100 || hsv[0] > 300) colorIsRed = true;
else colorIsRed = false;
if(!colorIsRed) {
driveTime((float) 0.2, (float) 0.2, 300);
robot.jewelArm.setPosition(0.4);
wait(1000);
telemetry.addData("color", "blue");
} else {
driveTime((float) -0.2, (float) -0.2, 300);
robot.jewelArm.setPosition(0.4);
wait(1000);
telemetry.addData("color", "red");
driveTime((float) 0.2, (float) 0.2, 700);
}
driveTime((float) 1, (float) 0.2, 500);
robot.removerOne.setPower(1);
robot.removerTwo.setPower(1);
wait(5000);
robot.removerOne.setPower(0);
robot.removerTwo.setPower(0);
driveTime((float) 0.3, (float) 0.3, 200);
driveTime((float) 0.5, (float) 0.5, 500);
//robot.jewelArm.setPosition(0);
telemetry.addData("done", "done");
updateTelemetry(telemetry);
wait(10000);
}
private void wait(int time) {
try {
Thread.sleep(time);
}
catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
private void setAll(float fl, float fr, float bl, float br) {
robot.frontLeft.setPower(fl);
robot.frontRight.setPower(fr);
robot.backLeft.setPower(bl);
robot.backRight.setPower(br);
}
private void driveTime(float l, float r, int time) {
setAll(l, r, l, r);
wait(time);
setAll(0, 0, 0, 0);
}
/*private void driveEncoder(int posL, int posR, double powerL, double powerR, boolean left) {
robot.frontLeft.setTargetPosition(robot.frontLeft.getCurrentPosition() + posL);
robot.frontRight.setTargetPosition(robot.frontRight.getCurrentPosition() + posR);
robot.backLeft.setTargetPosition(robot.backLeft.getCurrentPosition() + posL);
robot.backRight.setTargetPosition(robot.backRight.getCurrentPosition() + posR);
robot.frontLeft.setPower(powerL);
robot.frontRight.setPower(powerR);
robot.backLeft.setPower(powerL);
robot.backRight.setPower(powerR);
if (left) {
while(robot.backLeft.isBusy()) {
telemetry.addData("backLeft", robot.backLeft.getCurrentPosition());
telemetry.addData("backRight", robot.backRight.getCurrentPosition());
telemetry.addData("frontLeft", robot.frontLeft.getCurrentPosition());
telemetry.addData("frontRight", robot.frontRight.getCurrentPosition());
updateTelemetry(telemetry);
}
} else {
while(robot.backRight.isBusy()) {
telemetry.addData("backLeft", robot.backLeft.getCurrentPosition());
telemetry.addData("backRight", robot.backRight.getCurrentPosition());
telemetry.addData("frontLeft", robot.frontLeft.getCurrentPosition());
telemetry.addData("frontRight", robot.frontRight.getCurrentPosition());
updateTelemetry(telemetry);
}
}
robot.frontLeft.setPower(0);
robot.frontRight.setPower(0);
robot.backLeft.setPower(0);
robot.backRight.setPower(0);
}*/
}