-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tester.java
185 lines (164 loc) · 5.92 KB
/
Tester.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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.ColorSensor;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.OpticalDistanceSensor;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.CRServo;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.util.Range;
@TeleOp(name="Tester", group="Tester")
public class Tester extends LinearOpMode {
// set ye motors / servos
private String hwServo = "gemservo";
private String hwMotor = "liftermotor";
private String hwCrServo="belt drive";
private String hwColorSensor = "revsens";
// Declare OpMode members
private Servo servo = null;
private DcMotor motor = null;
private CRServo crservo = null;
private ColorSensor colorsens = null;
private String mode = "";
double servoPos = .5;
double motorPower = 0;
@Override
public void runOpMode() {
telemetry.addData("servo", hwServo);
telemetry.addData("motor", hwMotor);
telemetry.addData("CrServo", hwCrServo);
telemetry.addLine("what mode?\npress X for servo\npress B for motor\npress y for CrServo");
telemetry.update();
do {
if (gamepad1.x)
{
mode = "servo";
}
else if (gamepad1.b)
{
mode = "motor";
}
else if (gamepad1.y)
{
mode = "crservo";
}
} while (mode == "");
// Initialize the hardware variables. Note that the strings used here as parameters
// to 'get' must correspond to the names assigned during the robot configuration
// step (using the FTC Robot Controller app on the phone).
//Wait for the game to start (driver presses PLAY)
if (mode == "servo")
{
servo = hardwareMap.get(Servo.class, hwServo);
telemetry.addLine(" hit left bumper for regular, right bumper for reverse.");
telemetry.update();
boolean adv = false;
do {
if (gamepad1.left_bumper) {
adv = true;
} else if (gamepad1.right_bumper) {
servo.setDirection(Servo.Direction.REVERSE);
adv = true;
}
} while (adv == false);
}
else if (mode == "motor")
{
motor = hardwareMap.get(DcMotor.class, hwMotor);
telemetry.addLine("brakeing or floating?\nleft bumber for breaking\nright bumber for float");
telemetry.update();
boolean adv = false;
do {
if (gamepad1.left_bumper) {
motor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
adv = true;
} else if (gamepad1.right_bumper) {
motor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.FLOAT);
adv = true;
}
} while (adv == false);
}
else if (mode == "crservo")
{
crservo = hardwareMap.get(CRServo.class, hwCrServo);
}
telemetry.addData("ready to go! mode == ", mode);
telemetry.update();
waitForStart();
if (mode == "servo")
{
while (opModeIsActive()) {
if (gamepad1.a)
{
servoPos += .001;
}
else if (gamepad1.b)
{
servoPos -= .001;
}
if (gamepad1.y)
{
servoPos += .01;
}
else if (gamepad1.x)
{
servoPos -= .01;
}
servoPos = Range.clip(servoPos, 0,1);
servo.setPosition(servoPos);
telemetry.addData("servoPos", servoPos);
telemetry.update();
}
}
else if (mode == "gemservo")
{
while (opModeIsActive()) {
if (gamepad1.a)
{
servoPos += .001;
}
else if (gamepad1.b)
{
servoPos -= .001;
}
if (gamepad1.y)
{
servoPos += .01;
}
else if (gamepad1.x)
{
servoPos -= .01;
}
servoPos = Range.clip(servoPos, 0,1);
servo.setPosition(servoPos);
telemetry.addData("red", colorsens.red());
telemetry.addData("blue", colorsens.blue());
telemetry.addData("green", colorsens.green());
telemetry.addData("alpha", colorsens.alpha());
telemetry.addData("servoPos", servoPos);
telemetry.update();
}
}
else if (mode == "motor")
{
while (opModeIsActive()) {
motorPower = gamepad1.left_trigger + (-1 * gamepad1.right_trigger);
motor.setPower(motorPower);
telemetry.addData("motorPower",motorPower);
telemetry.addData("motor.getcurrentposition", motor.getCurrentPosition());
telemetry.update();
}
}
else if (mode == "crservo")
{
while (opModeIsActive()) {
motorPower = gamepad1.left_trigger + (-1 * gamepad1.right_trigger);
crservo.setPower(motorPower);
telemetry.addData("motorPower",motorPower);
telemetry.update();
}
}
}
}