-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDONT.java
More file actions
241 lines (207 loc) · 8.58 KB
/
DONT.java
File metadata and controls
241 lines (207 loc) · 8.58 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
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
package org.firstinspires.ftc.teamcode;
import com.bylazar.configurables.annotations.Configurable;
import com.pedropathing.follower.Follower;
import com.pedropathing.geometry.BezierCurve;
import com.pedropathing.geometry.BezierLine;
import com.pedropathing.geometry.Pose;
import com.pedropathing.paths.PathChain;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.pedropathing.util.Timer;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import org.firstinspires.ftc.teamcode.pedroPathing.Constants;
// this thing is going to explode if you run it
@Disabled
@Configurable
@Autonomous(name = "DONT")
public class DONT extends OpMode {
private Follower follower;
private Timer actionTimer;
private int pathState = 0;
private boolean pathStarted = false; // Tracks if path has been started
private final Pose startPose = new Pose(20.187, 125.383, Math.toRadians(142));
private Paths paths;
private DualMotorFlywheelController flywheel;
private DcMotor Intake;
private DcMotor Launcher;
public static double minDistance = 7;
public static double maxDistance = 148;
public static double minVelocity = 1200; // rpm close & near–air-shot
public static double maxVelocity = 3400; // rpm long shot
public static double goalX = 14.178;
public static double goalY = 135.582;
private double scale(double input, double inMin, double inMax, double outMin, double outMax) {
input = Math.max(inMin, Math.min(input, inMax));
return outMin + (outMax - outMin) * ((input - inMin) / (inMax - inMin));
}
public static class Paths {
public PathChain ShootingPosition;
public PathChain Pickup1;
public PathChain Pickup1ToShootingPose;
public PathChain Pickup2;
public PathChain FinalPose;
public Paths(Follower follower) {
ShootingPosition = follower.pathBuilder()
.addPath(new BezierLine(new Pose(20.187, 125.383), new Pose(43.738, 102.505)))
.setLinearHeadingInterpolation(Math.toRadians(142), Math.toRadians(142))
.build();
Pickup1 = follower.pathBuilder()
.addPath(new BezierCurve(new Pose(43.738, 102.505),
new Pose(63.925, 79.402),
new Pose(18.393, 83.664)))
.setLinearHeadingInterpolation(Math.toRadians(142), Math.toRadians(180))
.build();
Pickup1ToShootingPose = follower.pathBuilder()
.addPath(new BezierCurve(new Pose(18.393, 83.664),
new Pose(63.925, 79.402),
new Pose(43.738, 102.505)))
.setLinearHeadingInterpolation(Math.toRadians(180), Math.toRadians(142))
.build();
Pickup2 = follower.pathBuilder()
.addPath(new BezierCurve(new Pose(43.738, 102.505),
new Pose(105.869, 53.159),
new Pose(17.944, 59.888)))
.setLinearHeadingInterpolation(Math.toRadians(142), Math.toRadians(180))
.build();
FinalPose = follower.pathBuilder()
.addPath(new BezierCurve(new Pose(17.944, 59.888),
new Pose(105.869, 53.159),
new Pose(43.738, 102.505)))
.setLinearHeadingInterpolation(Math.toRadians(180), Math.toRadians(142))
.build();
}
}
@Override
public void init() {
actionTimer = new Timer();
Timer opmodeTimer = new Timer();
opmodeTimer.resetTimer();
Intake = hardwareMap.get(DcMotorEx.class, "Intake");
Launcher = hardwareMap.get(DcMotorEx.class, "Launcher");
follower = Constants.createFollower(hardwareMap);
follower.setStartingPose(startPose);
paths = new Paths(follower);
flywheel = new DualMotorFlywheelController(hardwareMap, "flywheel1", "flywheel2");
flywheel.setPIDF(0.003, 0.0, 0.0002, 0.00012); // tune these
}
@Override
public void loop() {
follower.update();
// Compute distance to goal
Pose pose = follower.getPose();
double dx = goalX - pose.getX();
double dy = goalY - pose.getY();
double distance = Math.hypot(dx, dy);
// Scale distance → flywheel velocity
double targetRPM = scale(distance, minDistance, maxDistance, minVelocity, maxVelocity);
flywheel.setTargetVelocity(targetRPM);
flywheel.update(); // single update per loop
telemetry.addData("path state", pathState);
telemetry.addData("x", pose.getX());
telemetry.addData("y", pose.getY());
telemetry.addData("heading", Math.toDegrees(pose.getHeading()));
telemetry.addData("flywheel target RPM", targetRPM);
telemetry.addData("flywheel actual RPM", flywheel.getVelocity());
telemetry.update();
// Path-following state machine
switch (pathState) {
case 0: // Move to shooting position
if (!pathStarted) {
follower.followPath(paths.ShootingPosition);
pathStarted = true;
}
if (!follower.isBusy()) {
pathState++;
pathStarted = false;
actionTimer.resetTimer();
}
break;
case 1: // Shoot
if (actionTimer.getElapsedTime() < 2.0) {
// TODO: trigger shooter servo/intake
Launcher.setPower(-1);
} else {
pathState++;
actionTimer.resetTimer();
}
break;
case 2: // Move to pickup 1
if (!pathStarted) {
follower.followPath(paths.Pickup1);
pathStarted = true;
}
if (!follower.isBusy()) {
pathState++;
pathStarted = false;
actionTimer.resetTimer();
}
break;
case 3: // Pick up first object
if (actionTimer.getElapsedTime() < 1.5) {
// TODO: activate intake
Intake.setPower(-1);
} else {
pathState++;
actionTimer.resetTimer();
}
break;
case 4: // Return to shooting position
if (!pathStarted) {
follower.followPath(paths.Pickup1ToShootingPose);
pathStarted = true;
}
if (!follower.isBusy()) {
pathState++;
pathStarted = false;
actionTimer.resetTimer();
}
break;
case 5: // Shoot again
if (actionTimer.getElapsedTime() < 2.0) {
// TODO: trigger shooter servo/intake
Launcher.setPower(-1);
} else {
pathState++;
actionTimer.resetTimer();
}
break;
case 6: // Move to pickup 2
if (!pathStarted) {
follower.followPath(paths.Pickup2);
pathStarted = true;
}
if (!follower.isBusy()) {
pathState++;
pathStarted = false;
actionTimer.resetTimer();
}
break;
case 7: // Pick up second object
if (actionTimer.getElapsedTime() < 1.5) {
// TODO: activate intake
Intake.setPower(-1);
} else {
pathState++;
actionTimer.resetTimer();
}
break;
case 8: // Move to final pose
if (!pathStarted) {
follower.followPath(paths.FinalPose);
pathStarted = true;
actionTimer.resetTimer(); // start shooting timer
}
// Once at final pose, activate launcher for 3 seconds
if (!follower.isBusy()) {
if (actionTimer.getElapsedTime() < 3.0) {
// TODO: trigger shooter servo/intake here
Launcher.setPower(-1);
}
}
break;
}
// Telemetry
}
}