-
Notifications
You must be signed in to change notification settings - Fork 0
/
TeleOpTest.java
213 lines (178 loc) · 8.79 KB
/
TeleOpTest.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
/*
Code by Brison
DO NOT TOUCH - MAKE COPY TO EDIT
made 4th quarter 2021
*/
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.DcMotor.RunMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ElapsedTime;
import com.qualcomm.robotcore.util.Range;
@TeleOp(name="TeleOpTest", group="")
public class TeleOpTest extends LinearOpMode {
private ElapsedTime runtime = new ElapsedTime();
private DcMotor frontLeft;
private DcMotor frontRight;
private DcMotor backRight;
private DcMotor backLeft;
private DcMotor duck;
private DcMotor intake;
private DcMotor lifter;
private double angle;
private double magnitude;
private double magnitudeA;
private double magnitudeB;
private double direction;
private double posChange;
private double prePos = 0;
private double postPos = 0;
private double frontRightPower = 0;
private double backLeftPower = 0;
private double frontLeftPower = 0;
private double backRightPower = 0;
private double duckPower = 0;
private double intakePower = 0;
private double linearPower = 0;
private int intakeToggle = 0;
private double sprint = 1.5;
@Override
public void runOpMode() {
telemetry.addData("Status", "Initialized");
telemetry.update();
frontLeft = hardwareMap.get(DcMotorEx.class, "frontLeft");
frontRight = hardwareMap.get(DcMotor.class, "frontRight");
backRight = hardwareMap.get(DcMotor.class, "backRight");
backLeft = hardwareMap.get(DcMotor.class, "backLeft");
intake = hardwareMap.get(DcMotor.class, "intake");
duck = hardwareMap.get(DcMotor.class, "duckRusher");
lifter = hardwareMap.get(DcMotor.class, "lifter");
frontLeft.setDirection(DcMotor.Direction.REVERSE);
backLeft.setDirection(DcMotor.Direction.REVERSE);
waitForStart();
runtime.reset();
frontLeft.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
frontRight.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
backRight.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
backLeft.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
intake.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
duck.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
lifter.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
frontLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
frontRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
backRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
backLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
intake.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
duck.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
lifter.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
while (opModeIsActive()) {
magnitudeB = gamepad1.right_stick_x;
magnitude = Math.hypot(Math.abs(gamepad1.left_stick_x), Math.abs(gamepad1.left_stick_y));
if (gamepad1.right_bumper) {
duckPower = 1;
} else if (gamepad1.left_bumper) {
duckPower = -1;
} else
duckPower = 0;
if (magnitude > 1) {
magnitude = 1;
}
angle = Math.toDegrees(Math.atan2(gamepad1.left_stick_x, -gamepad1.left_stick_y));
if (gamepad1.left_stick_y == 0 && gamepad1.left_stick_x == 0) {
angle = 0;
}
if (angle == 0) {
frontRightPower = magnitude - magnitudeB;
backRightPower = magnitude - magnitudeB;
frontLeftPower = magnitude + magnitudeB;
backLeftPower = magnitude + magnitudeB;
}
if (angle == 180) {
frontRightPower = -magnitude - magnitudeB;
backRightPower = -magnitude - magnitudeB;
frontLeftPower = -magnitude + magnitudeB;
backLeftPower = -magnitude + magnitudeB;
}
if (angle == 90) {
frontRightPower = -magnitude - magnitudeB;
backRightPower = magnitude - magnitudeB;
frontLeftPower = magnitude + magnitudeB;
backLeftPower = -magnitude + magnitudeB;
}
if (angle == -90) {
frontRightPower = magnitude - magnitudeB;
backRightPower = -magnitude - magnitudeB;
frontLeftPower = -magnitude + magnitudeB;
backLeftPower = magnitude + magnitudeB;
}
if (angle > -90 && angle < 0) {
frontRightPower = magnitude - magnitudeB;
backLeftPower = magnitude + magnitudeB;
frontLeftPower = (0.0222 * angle + 1) * magnitude + magnitudeB;
backRightPower = (0.0222 * angle + 1) * magnitude - magnitudeB;
}
if (angle > 0 && angle < 90) {
frontLeftPower = magnitude + magnitudeB;
backRightPower = magnitude - magnitudeB;
frontRightPower = (-0.0222 * angle + 1) * magnitude - magnitudeB;
backLeftPower = (-0.0222 * angle + 1) * magnitude + magnitudeB;
}
if (angle > 90 && angle < 180) {
frontRightPower = -magnitude - magnitudeB;
backLeftPower = -magnitude + magnitudeB;
frontLeftPower = (-0.0222 * angle + 3) * magnitude + magnitudeB;
backRightPower = (-0.0222 * angle + 3) * magnitude - magnitudeB;
}
if (angle > -180 && angle < -90) {
frontLeftPower = -magnitude + magnitudeB;
backRightPower = -magnitude - magnitudeB;
frontRightPower = (0.0222 * angle + 3) * magnitude - magnitudeB;
backLeftPower = (0.0222 * angle + 3) * magnitude + magnitudeB;
}
if (gamepad1.right_stick_button) {
if (sprint == 1.5) {
sprint = 0.8;
} else if (sprint == 0.8) {
sprint = 1.5;
}
}
frontRight.setPower(frontRightPower * sprint);
backRight.setPower(backRightPower * sprint);
frontLeft.setPower(frontLeftPower * sprint);
backLeft.setPower(backLeftPower * sprint);
if (gamepad1.right_bumper == false && gamepad1.left_bumper == false) {
duckPower = 0;
duck.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
}else if(gamepad1.right_bumper == true && gamepad1.left_bumper == false){
duckPower = 0.46;
duck.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
}else if(gamepad1.right_bumper == false && gamepad1.left_bumper == true){
duckPower = -.46;
duck.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
}
duck.setPower(duckPower);
if (magnitude == 0 && magnitudeB == 0) {
frontRight.setPower(0);
frontRight.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
backRight.setPower(0);
backRight.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
frontLeft.setPower(0);
frontLeft.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
backLeft.setPower(0);
backLeft.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
}
telemetry.addData("Positions", "frontLeft (%.2f), frontRight (%.2f)", frontLeftPower, frontRightPower);
telemetry.addData("Positions", "backLeft (%.2f), backRight (%.2f)", backLeftPower, backRightPower);
telemetry.addData("magnitude", magnitude);
telemetry.addData("angle", angle);
telemetry.addData("StickY", gamepad1.left_stick_y);
telemetry.addData("StickX", gamepad1.left_stick_x);
telemetry.addData("Sprint", sprint);
telemetry.update();
}
}
}