-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrive.java
202 lines (188 loc) · 7.12 KB
/
drive.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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.hardware.rev.RevBlinkinLedDriver;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.HardwareMap;
@TeleOp (name = "TrulyIntelligentTeleopSoftware", group = "sus")
public class drive extends LinearOpMode {
// initialize robot
@Override
public void runOpMode() throws InterruptedException {
robot bot = new robot(hardwareMap, this);
waitForStart();
double lx, rx, ly; // intialize variables for the gamepad
boolean in = true;
byte wristExt = 0; //0 fully ext, 1 half ext, 2 fully ext
byte armExt = 0; //0 reset, 1 half ext, 2 fully ext
boolean wristExtLate = false;
boolean armExtLate1 = false;
boolean armExtLate2 = false;
boolean armExtLate3 = false;
boolean slowModeLate = false;
double slowMode = 1.0;
boolean slow = false;
while(opModeIsActive()) {
// set the gamepad variables
lx = gamepad1.left_stick_x;
rx = gamepad1.right_stick_x;
ly = -gamepad1.left_stick_y;
// arithmetic to get motor values - not scaled
double lf = ly + rx + lx;
double lb = ly + rx - lx;
double rf = ly - rx - lx;
double rb = ly - rx + lx;
// scale the motor values
double ratio;
double max = Math.max(Math.max(Math.abs(lb), Math.abs(lf)), Math.max(Math.abs(rb), Math.abs(rf)));
double magnitude = Math.sqrt((lx * lx) + (ly * ly) + (rx * rx));
if (max == 0) {
ratio = 0;
}
else {
ratio = .64 * magnitude / max ;
}
// sets the motor power
bot.leftFront.setPower(lf * ratio * slowMode);
bot.leftBack.setPower(lb * ratio * slowMode);
bot.rightFront.setPower(rf * ratio * slowMode);
bot.rightBack.setPower(rb * ratio * slowMode);
// motor powers are slowed
// turns on the carousel motor
if (gamepad2.left_bumper) {
bot.spinCarousel(1);
}
else if (gamepad2.right_bumper){
bot.spinCarousel(-1);
}
else{
bot.spin.setPower(0);
}
if (gamepad1.y && !slowModeLate) {
if (!slow) {
slowMode = 0.5;
slow = true;
}
else{
slowMode = 1.0;
slow = false;
}
}
//servo controls for arm
//wrist:
if(gamepad2.a && !wristExtLate)
{
if(wristExt == 1)
{
bot.wristReset();
wristExt = 0;
}
else if(wristExt == 0)
{
bot.wristDrop();
wristExt = 1;
}
}
telemetry.addData("Wrist Extension: ", wristExt);
//arm:
if(gamepad2.y && !armExtLate1)
{
wristExt = 0;
if(armExt != 0)
{
bot.armReset();
armExt = 0;
}
else if(armExt == 0)
{
bot.armToTop();
armExt = 1;
}
}
if(gamepad2.x && !armExtLate2)
{
wristExt = 0;
if(armExt != 0)
{
bot.armReset();
armExt = 0;
}
else if(armExt == 0)
{
bot.armToMiddle();
armExt = 2;
}
}
if(gamepad2.b && !armExtLate3)
{
wristExt = 0;
if(armExt != 0)
{
bot.armReset();
armExt = 0;
}
else if(armExt == 0)
{
bot.armToBottom();
armExt = 3;
}
}
//put values for late booleans
wristExtLate = gamepad2.a;
armExtLate1 = gamepad2.y;
armExtLate2 = gamepad2.x;
armExtLate3 = gamepad2.b;
slowModeLate = gamepad1.y;
//collection controls
if(gamepad2.left_trigger > 0.5){
bot.intake.setPower(0.8);
}
else if(gamepad2.right_trigger > 0.5){
bot.intake.setPower(-0.8);
}
else {
bot.intake.setPower(0);
}
if (gamepad2.dpad_down) {
bot.blinkinLedDriver.setPattern(RevBlinkinLedDriver.BlinkinPattern.RED);
}
else if (gamepad2.dpad_up){
bot.blinkinLedDriver.setPattern(RevBlinkinLedDriver.BlinkinPattern.BLUE);
}
// adds telemetry data
telemetry.addData("heading", bot.imu.getAngularOrientation().firstAngle);
telemetry.addData("heading3", bot.imu.getAngularOrientation().thirdAngle);
double angle = bot.imu.getAngularOrientation().thirdAngle;
if (angle > 0.2 || angle < -0.2){
bot.blinkinLedDriver.setPattern(RevBlinkinLedDriver.BlinkinPattern.BLUE);
}
else {
bot.blinkinLedDriver.setPattern(RevBlinkinLedDriver.BlinkinPattern.GREEN);
}
//range: front wheels off ground 0.08 to -1.5
//back wheels off ground 0.08 to 1.5
//telemetry.addData("carousel", bot.spin.getPower());
//telemetry.addData("leftFront:", bot.rightBack.getPower());
// telemetry.addData("lf",lf);
// telemetry.addData("rf", rf);
// telemetry.addData("lb", lb);
// telemetry.addData("rb",rb);
// for (int i = 0; i<robot.encoderMotors.length; i++)
// {
// telemetry.addData("encodermotors" + i + ": ", robot.encoderMotors[i].getCurrentPosition());
// }
//telemetry.addData("Average Encoder Motors: ", Util.getAverageEncoderPosition(robot.encoderMotors));
//telemetry.addData("rightFront:", bot.rightFront.getCurrentPosition());
//telemetry.addData("leftSticky", gamepad1.left_stick_y);
// telemetry.addData("wrist: ", bot.wrist.getPosition());
// telemetry.addData("arm: ", bot.arm.getPosition());
// telemetry.addData("leftFront: ", bot.leftFront.getCurrentPosition());
// telemetry.addData("lf", bot.leftFront.getPortNumber());
// telemetry.addData("lb", bot.leftBack.getPortNumber());
// telemetry.addData("rf", bot.rightFront.getPortNumber());
// telemetry.addData("rb", bot.rightBack.getPortNumber());
//telemetry.addData("in: ", in);
telemetry.update();
}
}
}