forked from FIRST-Tech-Challenge/FtcRobotController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWCRobotMethods.java
More file actions
197 lines (166 loc) · 6.29 KB
/
Copy pathWCRobotMethods.java
File metadata and controls
197 lines (166 loc) · 6.29 KB
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
package org.firstinspires.ftc.teamcode;
import static com.qualcomm.robotcore.hardware.DcMotorSimple.Direction.FORWARD;
import static com.qualcomm.robotcore.hardware.DcMotorSimple.Direction.REVERSE;
import static org.firstinspires.ftc.robotcore.external.navigation.AngleUnit.RADIANS;
import static java.lang.Math.PI;
import static java.lang.Math.abs;
import static java.lang.Math.cos;
import static java.lang.Math.log;
import static java.lang.Math.sin;
import com.qualcomm.hardware.bosch.BHI260IMU;
import com.qualcomm.hardware.rev.RevHubOrientationOnRobot;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.Gamepad;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.IMU;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.util.Range;
import com.shprobotics.pestocore.processing.MotorCortex;
import org.firstinspires.ftc.robotcore.external.Telemetry;
import org.opencv.core.Mat;
public class WCRobotMethods {
DcMotor frontLeft;
DcMotor backRight;
DcMotor backLeft;
DcMotor frontRight;
DcMotor Outtake;
DcMotor Intake;
Servo arm;
BHI260IMU imu;
Telemetry telemetry;
DcMotor deadWheelLeft;
DcMotor deadWheelRight;
DcMotor deadWheelCenter;
// DcMotor slide1;
// DcMotor slide2;
DcMotor Middle;
DcMotor Gecko;
Servo Arm;
double imu_zero;
double rotation;
public WCRobotMethods(HardwareMap hardwareMap, Telemetry t) {
telemetry = t;
Intake = hardwareMap.get(DcMotor.class, "intake");
Middle = hardwareMap.get(DcMotor.class, "mid");
Outtake = hardwareMap.get(DcMotor.class, "outtake");
Gecko = hardwareMap.get(DcMotor.class, "gecko");
Arm = hardwareMap.get(Servo.class, "arm");
// slide1 = hardwareMap.get(DcMotor.class, "slide1");
// slide2 = hardwareMap.get(DcMotor.class, "slide2");
frontLeft = hardwareMap.get(DcMotor.class, "frontLeft");
frontRight = hardwareMap.get(DcMotor.class, "frontRight");
backLeft = hardwareMap.get(DcMotor.class, "backLeft");
backRight = hardwareMap.get(DcMotor.class, "backRight");
//DeadWheels
deadWheelCenter = hardwareMap.get(DcMotor.class, "frontRight");
deadWheelRight = hardwareMap.get(DcMotor.class, "backRight");
deadWheelLeft = hardwareMap.get(DcMotor.class, "frontLeft");
frontLeft.setDirection(FORWARD);
frontRight.setDirection(REVERSE);
backLeft.setDirection(FORWARD);
backRight.setDirection(REVERSE);
arm = hardwareMap.get(Servo.class, "arm");
imu = hardwareMap.get(BHI260IMU.class, "imu");
rotation = 0;
IMU.Parameters myIMUparameters;
myIMUparameters = new IMU.Parameters(
new RevHubOrientationOnRobot(
RevHubOrientationOnRobot.LogoFacingDirection.RIGHT,
RevHubOrientationOnRobot.UsbFacingDirection.UP
)
);
imu.initialize(myIMUparameters);
}
public void updateTelemetry(Telemetry telemetry) {
telemetry.update();
}
public void stopAll() {
frontLeft.setPower(0);
frontRight.setPower(0);
backRight.setPower(0);
backLeft.setPower(0);
}
public void driveWithStick(Gamepad gamepadStick) {
robotOrientedDrive(gamepadStick.left_stick_x, -gamepadStick.left_stick_y, gamepadStick.right_stick_x);
}
public void fieldOrientedDrive() {
}
public void armTop() {
arm.setPosition(0.25);
}
public void armBlock() {
arm.setPosition(0.9);
}
public void resetIMU() {
deadWheelRight.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
deadWheelLeft.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
deadWheelCenter.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
deadWheelRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
deadWheelLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
deadWheelCenter.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
}
public void robotOrientedDrive(double x, double y, double r) {
frontLeft.setPower(y + x + r);
frontRight.setPower(y - x - r);
backLeft.setPower(y - x + r);
backRight.setPower(y + x - r);
}
public void fieldOrientedDrive(double x0, double y0, double r) {
double theta = getRotation();
double x = x0 * sin(theta) - y0 * cos(theta);
double y = x0 * cos(theta) + y0 * sin(theta);
robotOrientedDrive(x, y, r);
}
public double getRotation() {
return imu.getRobotYawPitchRollAngles().getYaw(RADIANS) - imu_zero;
}
public double normalizeAngle(double angle) {
while (angle > Math.PI) angle -= 2 * Math.PI;
while (angle < -Math.PI) angle += 2 * Math.PI;
return angle;
}
public void moveForward(double time) {
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < time * 1000) {
Intake.setPower(0.5);
robotOrientedDrive(0, -0.5, 0);
}
stopAll();
}
public void rotate(double time) {
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < time * 1000) {
robotOrientedDrive(0, 0, 0.5);
}
stopAll();
}
public void rotateOp(double time) {
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < time * 1000) {
robotOrientedDrive(0, 0, -0.5);
}
stopAll();
}
public void rotatenormal(double time) {
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < time * 1000) {
robotOrientedDrive(0, 0, 0.5);
}
stopAll();
}
public void moveMid(double power) {
Middle.setPower(power);
Intake.setPower(power);
Gecko.setPower(power);
}
public void initImu() {
IMU.Parameters myIMUparameters;
myIMUparameters = new IMU.Parameters(
new RevHubOrientationOnRobot(
RevHubOrientationOnRobot.LogoFacingDirection.UP,
RevHubOrientationOnRobot.UsbFacingDirection.FORWARD
)
);
imu.initialize(myIMUparameters);
}
}