-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRRBotTeleop.java
307 lines (278 loc) · 10.4 KB
/
RRBotTeleop.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ElapsedTime;
import com.qualcomm.robotcore.util.Range;
/**
* Teleop Opmode class, contains separate methods that update each mechanism of the robot which are called by loop()
* @author Andrew Hollabaugh
* @since 2017-09-10
*/
@TeleOp(name="RRBotTeleop")
public class RRBotTeleop extends OpMode
{
//construct an RRBotHardware object to reference its stuff
RRBotHardware robot = new RRBotHardware();
//construct drive and glyph arm classes
RRBotMecanumDrive drive = new RRBotMecanumDrive(robot);
RRBotGlyphArm glyphArm = new RRBotGlyphArm(robot, drive);
private final double GAMEPAD_TRIGGER_THRESHOLD = 0.2;
private final double JOYSTICK_DEADZONE = 0.3;
//used to detect rising edge of button presses
private boolean prevGrabberOpenButton = false;
private boolean prevGrabberReleaseButton = false;
private boolean prevWristButton = false;
private boolean prevRelicModeButton = false;
private boolean prevRelicGrabberButton = false;
private boolean prevAutoGrabberButton = false;
private boolean prevGrabberRotateButton = false;
/**
* Runs once when the init button is pressed. Sets things up for the rest of the program.
*/
@Override
public void init()
{
//initialize hardware variables by calling the init function of the RRBotHardware class via the robot object
robot.init(hardwareMap);
//set joystick deadzone to less than the default, due to the driver's preference
gamepad1.setJoystickDeadzone(0.05f);
telemetry.addData("Robot","is init");
}
/**
* Runs repeatedly after start button is pressed. Runs multiple update methods to update different robot mechanisms.
*/
@Override
public void loop()
{
DriveUpdate();
JewelArmUpdate();
//make sure glyph arm is homed before allowing it to move
if(glyphArm.hasHomed())
{
GlyphArmUpdate();
}
else
{
glyphArm.HomeArm();
}
Telemetry();
}
/**
* Runs once when the stop button is hit.
*/
@Override
public void stop()
{
//turn off the servo power module, which is connected to one the the motor ports
robot.servoPowerModule.setPower(0);
}
/**
* Updates the drive system with manual and automatic movements
*/
public void DriveUpdate()
{
//if the robot is not driving automatically, set motor power to the manual drive algorithm based on gamepad inputs
if(!drive.getIsAutoMove())
{
drive.setMotorPower(gamepad1.left_stick_x, -gamepad1.left_stick_y, gamepad1.right_stick_x, -gamepad1.right_stick_y, true);
}
else
{
drive.AutoMoveEndCheck();
}
}
/**
* Updates the jewel arm.
*/
public void JewelArmUpdate()
{
//press the a button to reset the jewel arm, just in case it goes wild during teleop
if(gamepad1.a)
{
robot.jewelArmServo1.setPosition(robot.JEWEL_ARM_SERVO_1_START_POS);
}
}
/**
* Updates the glyph/relic arm. Reads button inputs to move the arm and wrist to set positions, move grabbers, and perform routines
*/
public void GlyphArmUpdate()
{
glyphArm.UpdateValues();
//toggle relic mode when left trigger is pressed, only detects rising edge of button press
if(gamepad2.left_trigger > GAMEPAD_TRIGGER_THRESHOLD && !prevRelicModeButton)
{
prevRelicModeButton = true;
glyphArm.ToggleRelicMode();
}
if(!(gamepad2.left_trigger > GAMEPAD_TRIGGER_THRESHOLD))
{
prevRelicModeButton = false;
}
if(!glyphArm.isInRelicMode()) //not relic mode
{
//move the glyph arm to a certain state when a button is pressed
if(gamepad2.start)
{
glyphArm.MoveToStartPos();
}
else if(gamepad2.right_bumper)
{
glyphArm.MoveGlyphArmToState(GlyphArmState.FRONT_PICKUP);
}
else if(gamepad2.dpad_down)
{
glyphArm.MoveGlyphArmToState(GlyphArmState.FRONT_PICKUP_2);
}
else if(gamepad2.a)
{
glyphArm.MoveGlyphArmToState(GlyphArmState.FRONT1);
}
else if(gamepad2.b)
{
glyphArm.MoveGlyphArmToState(GlyphArmState.FRONT2);
}
else if(gamepad2.x)
{
glyphArm.MoveGlyphArmToState(GlyphArmState.FRONT3);
}
else if(gamepad2.y)
{
glyphArm.MoveGlyphArmToState(GlyphArmState.FRONT4);
}
//Run the auto glyph place routine when gamepad 1 right trigger is pressed
/*if(gamepad1.left_trigger > GAMEPAD_TRIGGER_THRESHOLD)
{
glyphArm.setIsAutoGlyphPlace(true);
}*/
/*else if(gamepad2.dpad_down)
{
glyphArm.MoveGlyphArmToState(GlyphArmState.BACK1);
}
else if(gamepad2.dpad_right)
{
glyphArm.MoveGlyphArmToState(GlyphArmState.BACK2);
}
else if(gamepad2.dpad_left)
{
glyphArm.MoveGlyphArmToState(GlyphArmState.BACK3);
}
else if(gamepad2.dpad_up)
{
glyphArm.MoveGlyphArmToState(GlyphArmState.BACK4);
}*/
//flip the wrist when right trigger is pressed, only detects rising edge of button press
if(gamepad2.right_trigger > GAMEPAD_TRIGGER_THRESHOLD && !prevWristButton)
{
prevWristButton = true;
glyphArm.FlipWrist();
}
if(!(gamepad2.right_trigger > GAMEPAD_TRIGGER_THRESHOLD))
{
prevWristButton = false;
}
//toggle servo rotation of one of the grabbers when left bumper is pressed, only detect rising edge of button press
if(gamepad2.left_bumper && !prevGrabberRotateButton)
{
prevGrabberRotateButton = true;
glyphArm.RotateGrabber();
}
if(!gamepad2.left_bumper)
{
prevGrabberRotateButton = false;
}
//open/close grabber when right bumper is pressed, only detects rising edge of button press
if(gamepad1.right_bumper && !prevGrabberOpenButton)
{
prevGrabberOpenButton = true;
glyphArm.MoveGrabber("open");
}
if(!gamepad1.right_bumper)
{
prevGrabberOpenButton = false;
}
//release glyph/close grabber when left bumper is pressed, only detects rising edge of button press
if(gamepad1.left_bumper && !prevGrabberReleaseButton)
{
prevGrabberReleaseButton = true;
glyphArm.MoveGrabber("release");
}
if(!gamepad1.left_bumper)
{
prevGrabberReleaseButton = false;
}
//auto grabber close button code
if(gamepad1.right_trigger > GAMEPAD_TRIGGER_THRESHOLD)
{
glyphArm.AutoCloseGrabber();
}
if(gamepad1.right_trigger > GAMEPAD_TRIGGER_THRESHOLD && !prevAutoGrabberButton)
{
prevAutoGrabberButton = true;
glyphArm.setHasGrabberClosed(false);
}
if(!(gamepad1.right_trigger > GAMEPAD_TRIGGER_THRESHOLD))
{
prevAutoGrabberButton = false;
}
}
else //relic mode
{
if(gamepad2.a)
{
glyphArm.MoveToRelicPickupPos(1);
}
else if(gamepad2.dpad_down)
{
glyphArm.MoveToRelicPickupPos(2);
}
else if(gamepad2.b)
{
glyphArm.MoveToRelicPlacePos();
}
else if(gamepad2.x)
{
glyphArm.MoveToRelicDonePos();
}
//open/close relic grabber when right bumper is pressed, only detects rising edge of button press
if((gamepad1.right_bumper || gamepad2.right_bumper) && !prevRelicGrabberButton)
{
prevRelicGrabberButton = true;
glyphArm.MoveRelicGrabber();
}
if(!(gamepad1.right_bumper || gamepad2.right_bumper))
{
prevRelicGrabberButton = false;
}
}
//if y axis of left joystick is outside the deadzone, EnableArmJoystick is called, which enables the arm to be moved via joystick
if(Math.abs(gamepad2.left_stick_y) > JOYSTICK_DEADZONE)
{
glyphArm.EnableArmJoystick(gamepad2.left_stick_y);
}
//if y axis of right joystick is outside deadzone, EnableWristJoystick is called, which enables the arm to be moved via joystick
if(Math.abs(gamepad2.right_stick_y) > JOYSTICK_DEADZONE)
{
glyphArm.EnableWristJoystick(gamepad2.right_stick_y);
}
}
/**
* Shows debug values to be on the driver station
*/
public void Telemetry()
{
telemetry.addData("grabber1SwitchState", glyphArm.getGrabber1SwitchState());
telemetry.addData("grabber2SwitchState", glyphArm.getGrabber2SwitchState());
telemetry.addData("ArmMotorPosition", glyphArm.getArmPos());
telemetry.addData("WristMotorPosition", glyphArm.getWristPos());
telemetry.addData("startLimit", glyphArm.getStartLimitState());
telemetry.addData("endLimit", glyphArm.getEndLimitState());
telemetry.addData("relicMode", glyphArm.isInRelicMode());
telemetry.addData("ArmCurrentState", glyphArm.getCurrentArmState());
telemetry.addData("ArmPrevState", glyphArm.getPrevArmState());
telemetry.addData("WristCurrentState", glyphArm.getCurrentWristState());
telemetry.addData("WristPrevState", glyphArm.getPrevWristState());
telemetry.addData("joystickValue", glyphArm.getJoystickValue());
telemetry.update();
}
}