-
Notifications
You must be signed in to change notification settings - Fork 0
/
TricycleOp.java
125 lines (111 loc) · 3.2 KB
/
TricycleOp.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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.util.ElapsedTime;
@TeleOp(name = "Tricycle Op Mode Blue", group = "OpMode")
public class TricycleOp extends OpMode
{
private DriveTrain drive;
private Carousel carousel;
private Elevator elevator;
// Debug
private ElapsedTime runtime = new ElapsedTime();
/**
* Set your Alliance color here
* This will auto update subsystem code for the correct movements to be
* done by the robot.
*/
Utilities.Alliance alliance = Utilities.Alliance.BLUE;
/**
* Code that will run when init button is pressed
*/
@Override
public void init()
{
drive = new DriveTrain(hardwareMap, alliance);
carousel = new Carousel(hardwareMap, alliance);
elevator = new Elevator(hardwareMap);
telemetry.addData("Status", "Initialized");
telemetry.update();
}
/**
* Code that will run when the stop button is pressed or the robot is stopped
*/
@Override
public void stop()
{
drive.navXClose(); // Close the navX comms
drive.holonomicDrive(0.0, 0.0, 0.0); // Make sure robot is stopped
elevator.moveElevator(0.0); // Make sure elevator is stopped
carousel.spinCarousel(0); // Make sure servo is stopped
telemetry.addData("Status", "Stopped");
telemetry.update();
}
/**
* Code that will run when the op mode is first enabled
*/
@Override
public void init_loop()
{
runtime.reset();
drive.zeroYaw(); // Zero the yaw at the start
}
/**
* Code that will run every robot loop
*/
@Override
public void loop()
{
/**
* Controller inputs from user
*/
double y = -gamepad1.left_stick_y;
double x = gamepad1.left_stick_x;
double z = gamepad1.right_stick_x;
// Drive
if (gamepad1.right_bumper) // Strafe Right
{
drive.holonomicDrive(1, 0.0, 0.0);
}
else if (gamepad1.left_bumper) // Strafe Left
{
drive.holonomicDrive(-1, 0.0, 0.0);
}
else if (gamepad1.x) // Turn robot to default angle for first gate
{
drive.turnToDefault();
}
else if (gamepad1.y) // Turn robot to angle required for the other gate
{
drive.turnToSharedObject();
}
else // Default drive with joysticks
{
drive.holonomicDrive(x, y, z);
}
// Carousel
if (gamepad1.a) // Spin Carousel
{
carousel.spinCarousel(1);
}
else
{
carousel.spinCarousel(0);
}
// Elevator
if (gamepad1.dpad_up) // Move elevator up
{
elevator.moveElevator(0.5);
}
else if (gamepad1.dpad_down) // Move elevator down
{
elevator.moveElevator(-0.5);
}
else
{
elevator.moveElevator(0.0);
}
telemetry.addData("Status", "Run Time: " + runtime.toString());
telemetry.update();
}
}