forked from Pedro-Pathing/Quickstart
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainAuto.java
More file actions
217 lines (174 loc) · 8.66 KB
/
MainAuto.java
File metadata and controls
217 lines (174 loc) · 8.66 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
package org.firstinspires.ftc.teamcode; // make sure this aligns with class location
//HIIII pls don't delete
import com.pedropathing.follower.Follower;
import com.pedropathing.geometry.BezierCurve;
import com.pedropathing.geometry.BezierLine;
import com.pedropathing.geometry.Pose;
import com.pedropathing.paths.Path;
import com.pedropathing.paths.PathChain;
import com.pedropathing.util.Timer;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import org.firstinspires.ftc.teamcode.pedroPathing.Constants;
import org.firstinspires.ftc.teamcode.subsystems.Intake;
@Autonomous(name = "Main Auto")
public class MainAuto extends OpMode {
private Follower follower;
private Timer pathTimer, actionTimer, opmodeTimer;
private int pathState;
/*
private final Pose poseA = new Pose(48, 12, Math.toRadians(180)); // Start Pose of our robot.
private final Pose poseB = new Pose(18, 84, Math.toRadians(135));
private final Pose poseC = new Pose(74, 77, Math.toRadians(50));
private final Pose poseD = new Pose(21, 60, Math.toRadians(50));
private final Pose poseE = new Pose(73, 80, Math.toRadians(50));
private final Pose poseF = new Pose(18, 36, Math.toRadians(50));
private final Pose poseG = new Pose(75, 81, Math.toRadians(50));
private Path startPosition;
private PathChain moveB, moveC, moveD, moveE, moveF;
*/
private final Pose startPose = new Pose(48, 12, Math.toRadians(90)); // Start Pose of our robot.
private final Pose pickUp1 = new Pose(18, 84, Math.toRadians(180));
private final Pose pickUp1C1 = new Pose(57, 90);
private final Pose pickUp1C2 = new Pose(57, 84);
private final Pose pickUp2 = new Pose(18, 60, Math.toRadians(180));
private final Pose pickUp2C1 = new Pose(75, 57);
private final Pose pickUp2C2 = new Pose(66, 60);
private final Pose pickUp3 = new Pose(18, 36, Math.toRadians(180));
private final Pose pickUp3C1 = new Pose(72, 30);
private final Pose pickUp3C2 = new Pose(72, 36);
private final Pose shootPose = new Pose(75, 87, Math.toRadians(330));
private Path startPosition;
private PathChain shoot1, intake2, shoot2, intake3, shoot3, goToStart;
public void buildPaths() {
//startPosition = new Path(new BezierLine(startPose, pickUp1));
startPosition = new Path(new BezierCurve(startPose, pickUp1C1, pickUp1C2, pickUp1));
startPosition.setLinearHeadingInterpolation(Math.toRadians(180), Math.toRadians(180));
shoot1 = follower.pathBuilder()
.addPath(new BezierLine(pickUp1, shootPose))
.setLinearHeadingInterpolation(Math.toRadians(180), Math.toRadians(330))
.build();
intake2 = follower.pathBuilder()
//.addPath(new BezierLine(shootPose, pickUp2))
.addPath(new BezierCurve(shootPose, pickUp2C1, pickUp2C2 ,pickUp2))
.setLinearHeadingInterpolation(Math.toRadians(180), Math.toRadians(180))
.build();
shoot2 = follower.pathBuilder()
.addPath(new BezierLine(pickUp2, shootPose))
.setLinearHeadingInterpolation(Math.toRadians(180), Math.toRadians(330))
.build();
intake3 = follower.pathBuilder()
//.addPath(new BezierLine(shootPose, pickUp3))
.addPath(new BezierCurve(shootPose, pickUp3C1, pickUp3C2 ,pickUp3))
.setLinearHeadingInterpolation(Math.toRadians(180), Math.toRadians(180))
.build();
shoot3 = follower.pathBuilder()
.addPath(new BezierLine(pickUp3, shootPose))
.setLinearHeadingInterpolation(Math.toRadians(180), Math.toRadians(330))
.build();
goToStart = follower.pathBuilder()
.addPath(new BezierLine(shootPose, startPose))
.setLinearHeadingInterpolation(Math.toRadians(90), Math.toRadians(90))
.build();
}
public void autonomousPathUpdate() {
switch (pathState) {
case 0:
follower.followPath(startPosition);
setPathState(1);
break;
case 1:
/* This case checks the robot's position and will wait until the robot position is close (1 inch away) from the scorePose's position */
if(!follower.isBusy()) {
/* Score Preload */
/* Since this is a pathChain, we can have Pedro hold the end point while we are grabbing the sample */
follower.followPath(shoot1, 0.7, true);
setPathState(2);
}
break;
case 2:
/* This case checks the robot's position and will wait until the robot position is close (1 inch away) from the scorePose's position */
if(!follower.isBusy()) {
/* Score Preload */
/* Since this is a pathChain, we can have Pedro hold the end point while we are grabbing the sample */
follower.followPath(intake2, .7,true);
setPathState(3);
}
break;
case 3:
/* This case checks the robot's position and will wait until the robot position is close (1 inch away) from the scorePose's position */
if(!follower.isBusy()) {
/* Score Preload */
/* Since this is a pathChain, we can have Pedro hold the end point while we are grabbing the sample */
follower.followPath(shoot2, .7,true);
setPathState(4);
}
break;
case 4:
/* This case checks the robot's position and will wait until the robot position is close (1 inch away) from the scorePose's position */
if(!follower.isBusy()) {
/* Score Preload */
/* Since this is a pathChain, we can have Pedro hold the end point while we are grabbing the sample */
follower.followPath(intake3, .7,true);
setPathState(5);
}
break;
case 5:
/* This case checks the robot's position and will wait until the robot position is close (1 inch away) from the scorePose's position */
if(!follower.isBusy()) {
/* Score Preload */
/* Since this is a pathChain, we can have Pedro hold the end point while we are grabbing the sample */
follower.followPath(shoot3, .7,true);
setPathState(6);
}
break;
case 6:
/* This case checks the robot's position and will wait until the robot position is close (1 inch away) from the scorePose's position */
if(!follower.isBusy()) {
/* Score Preload */
/* Since this is a pathChain, we can have Pedro hold the end point while we are grabbing the sample */
follower.followPath(goToStart, .7,true);
setPathState(-1);
}
}
}
/** These change the states of the paths and actions. It will also reset the timers of the individual switches **/
public void setPathState(int pState) {
pathState = pState;
pathTimer.resetTimer();
}
@Override
public void loop() {
// These loop the movements of the robot, these must be called continuously in order to work
follower.update();
autonomousPathUpdate();
// Feedback to Driver Hub for debugging
telemetry.addData("path state", pathState);
telemetry.addData("x", follower.getPose().getX());
telemetry.addData("y", follower.getPose().getY());
telemetry.addData("heading", follower.getPose().getHeading());
telemetry.update();
}
@Override
public void init() {
pathTimer = new Timer();
opmodeTimer = new Timer();
opmodeTimer.resetTimer();
follower = Constants.createFollower(hardwareMap);
buildPaths();
follower.setStartingPose(startPose);
}
/** This method is called continuously after Init while waiting for "play". **/
@Override
public void init_loop() {}
/** This method is called once at the start of the OpMode.
* It runs all the setup actions, including building paths and starting the path system **/
@Override
public void start() {
opmodeTimer.resetTimer();
setPathState(0);
}
/** We do not use this because everything should automatically disable **/
@Override
public void stop() {}
}