Skip to content

Commit 05adf00

Browse files
committed
hopefully fixed pathHandler
1 parent e5d4307 commit 05adf00

File tree

7 files changed

+60
-56
lines changed

7 files changed

+60
-56
lines changed

src/main/java/frc/robot/RobotContainer.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import static edu.wpi.first.units.Units.Rotations;
88

9+
import java.util.List;
10+
911
import edu.wpi.first.units.measure.Angle;
1012
import edu.wpi.first.wpilibj.Joystick;
1113
import edu.wpi.first.wpilibj.XboxController;
@@ -19,6 +21,7 @@
1921
import frc.robot.commands.algae.OpenLoopAlgaeCommand;
2022
import frc.robot.commands.algae.ProcessorAlgaeCommand;
2123
import frc.robot.commands.algae.ToggleHasAlgaeCommand;
24+
import frc.robot.commands.auton.NonProcessorShallowAutonCommand;
2225
import frc.robot.commands.biscuit.HoldBiscuitCommand;
2326
import frc.robot.commands.biscuit.JogBiscuitCommand;
2427
import frc.robot.commands.coral.EnableEjectBeamCommand;
@@ -46,6 +49,7 @@
4649
import frc.robot.commands.vision.SetVisionUpdatesCommand;
4750
import frc.robot.constants.BiscuitConstants;
4851
import frc.robot.constants.ElevatorConstants;
52+
import frc.robot.constants.PathHandlerConstants;
4953
import frc.robot.constants.RobotConstants;
5054
import frc.robot.controllers.FlyskyJoystick;
5155
import frc.robot.controllers.FlyskyJoystick.Button;
@@ -452,25 +456,24 @@ public void configurePitDashboard() {
452456
.withPosition(1, 0)
453457
.withSize(1, 1);
454458

455-
// Shuffleboard.getTab("Pit")
456-
// .add(
457-
// "Start Auton",
458-
// new NonProcessorShallowAutonCommand(
459-
// driveSubsystem,
460-
// pathHandler,
461-
// robotStateSubsystem,
462-
// algaeSubsystem,
463-
// biscuitSubsystem,
464-
// coralSubsystem,
465-
// elevatorSubsystem,
466-
// tagAlignSubsystem,
467-
// "startToJ",
468-
// PathHandlerConstants.kpathNames,
469-
// List.of('K', 'L', 'M'),
470-
// List.of(4, 4, 4),
471-
// 'J'))
472-
// .withPosition(3, 0)
473-
// .withSize(1, 1);
459+
Shuffleboard.getTab("Pit")
460+
.add(
461+
"Start Auton",
462+
new NonProcessorShallowAutonCommand(
463+
driveSubsystem,
464+
pathHandler,
465+
robotStateSubsystem,
466+
algaeSubsystem,
467+
biscuitSubsystem,
468+
coralSubsystem,
469+
elevatorSubsystem,
470+
tagAlignSubsystem,
471+
"startToJ",
472+
List.of('K', 'L', 'M'),
473+
List.of(4, 4, 4),
474+
'J'))
475+
.withPosition(3, 0)
476+
.withSize(1, 1);
474477
}
475478

476479
public Command getAutonomousCommand() {

src/main/java/frc/robot/commands/auton/NonProcessorShallowAutonCommand.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import frc.robot.commands.drive.ResetGyroCommand;
88
import frc.robot.commands.drive.SetGyroOffsetCommand;
99
import frc.robot.commands.elevator.ZeroElevatorCommand;
10+
import frc.robot.constants.PathHandlerConstants;
1011
import frc.robot.subsystems.algae.AlgaeSubsystem;
1112
import frc.robot.subsystems.biscuit.BiscuitSubsystem;
1213
import frc.robot.subsystems.coral.CoralSubsystem;
@@ -33,7 +34,6 @@ public NonProcessorShallowAutonCommand(
3334
ElevatorSubsystem elevatorSubsystem,
3435
TagAlignSubsystem tagAlignSubsystem,
3536
String startPathName,
36-
String[][] pathNames,
3737
List<Character> NodeNames,
3838
List<Integer> NodeLevels,
3939
char startNode) {
@@ -52,8 +52,13 @@ public NonProcessorShallowAutonCommand(
5252
new ResetGyroCommand(driveSubsystem),
5353
new SetGyroOffsetCommand(driveSubsystem, new Rotation2d(180)))),
5454
startPath,
55-
new frc.robot.commands.pathhHandler.StartPathHandlerCommand(
56-
pathHandler, pathNames, NodeNames, NodeLevels, startNode, false)));
55+
new frc.robot.commands.pathHandler.StartPathHandlerCommand(
56+
pathHandler,
57+
PathHandlerConstants.kShallowPathNames,
58+
NodeNames,
59+
NodeLevels,
60+
startNode,
61+
false)));
5762
}
5863

5964
public void reassignAlliance() {

src/main/java/frc/robot/commands/pathhHandler/KillPathHandlerCommand.java renamed to src/main/java/frc/robot/commands/pathHandler/KillPathHandlerCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package frc.robot.commands.pathhHandler;
1+
package frc.robot.commands.pathHandler;
22

33
import edu.wpi.first.wpilibj2.command.InstantCommand;
44
import frc.robot.subsystems.pathHandler.PathHandler;

src/main/java/frc/robot/commands/pathhHandler/SetPathHandlerCommand.java renamed to src/main/java/frc/robot/commands/pathHandler/SetPathHandlerCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package frc.robot.commands.pathhHandler;
1+
package frc.robot.commands.pathHandler;
22

33
import edu.wpi.first.wpilibj2.command.InstantCommand;
44
import frc.robot.subsystems.pathHandler.PathHandler;

src/main/java/frc/robot/commands/pathhHandler/StartPathHandlerCommand.java renamed to src/main/java/frc/robot/commands/pathHandler/StartPathHandlerCommand.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
package frc.robot.commands.pathhHandler;
1+
package frc.robot.commands.pathHandler;
22

33
import edu.wpi.first.wpilibj2.command.Command;
44
import frc.robot.subsystems.pathHandler.PathHandler;
55
import java.util.List;
66

77
public class StartPathHandlerCommand extends Command {
88
private PathHandler pathHandler;
9-
private String[][] pathNames;
10-
private List<Character> NodeNames;
11-
private List<Integer> NodeLevels;
12-
private Character startNode;
13-
private boolean mirrorToProcessor;
149

1510
public StartPathHandlerCommand(
1611
PathHandler pathHandler,
@@ -19,12 +14,11 @@ public StartPathHandlerCommand(
1914
List<Integer> NodeLevels,
2015
Character startNode,
2116
boolean mirrorToProcessor) {
22-
this.pathHandler = pathHandler;
23-
this.pathNames = pathNames;
24-
this.NodeNames = NodeNames;
25-
this.NodeLevels = NodeLevels;
26-
this.startNode = startNode;
27-
this.mirrorToProcessor = mirrorToProcessor;
17+
pathHandler.setPathNames(pathNames);
18+
pathHandler.setNodeNames(NodeNames);
19+
pathHandler.setNodeLevels(NodeLevels);
20+
pathHandler.setStartNode(startNode);
21+
pathHandler.setMirrorToProcessor(mirrorToProcessor);
2822
}
2923

3024
public StartPathHandlerCommand(PathHandler pathHandler) {
@@ -33,13 +27,6 @@ public StartPathHandlerCommand(PathHandler pathHandler) {
3327

3428
@Override
3529
public void initialize() {
36-
if (pathNames != null) {
37-
pathHandler.setPathNames(pathNames);
38-
pathHandler.setNodeNames(NodeNames);
39-
pathHandler.setNodeLevels(NodeLevels);
40-
pathHandler.setStartNode(startNode);
41-
pathHandler.setMirrorToProcessor(mirrorToProcessor);
42-
}
4330
pathHandler.startPathHandler();
4431
}
4532

src/main/java/frc/robot/constants/PathHandlerConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package frc.robot.constants;
22

33
public class PathHandlerConstants {
4-
public static final String[][] kpathNames = {
4+
public static final String[][] kShallowPathNames = {
55
{
66
"fetchToA",
77
"fetchToB",

src/main/java/frc/robot/subsystems/pathHandler/PathHandler.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import choreo.Choreo;
44
import choreo.trajectory.SwerveSample;
55
import choreo.trajectory.Trajectory;
6+
import edu.wpi.first.wpilibj.DriverStation.Alliance;
67
import edu.wpi.first.wpilibj.Timer;
78
import frc.robot.constants.DriveConstants;
9+
import frc.robot.constants.PathHandlerConstants;
810
import frc.robot.constants.RobotStateConstants;
911
import frc.robot.constants.TagServoingConstants;
1012
import frc.robot.subsystems.drive.DriveSubsystem;
@@ -24,21 +26,25 @@ public class PathHandler extends MeasurableSubsystem {
2426
private TagAlignSubsystem tagAlignSubsystem;
2527
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(PathHandler.class);
2628

29+
// parameters
30+
private String[][] pathNames =
31+
PathHandlerConstants.kShallowPathNames; // the array of paths, in string form
32+
private List<Character> nodeNames; // the list of nodes, in order, to score on
33+
private List<Integer> nodeLevels; // the list of levels, in order, to score on
34+
private Character startNode = 'a'; // the node that the robot starts in front of
35+
private boolean mirrorToProcessor =
36+
false; // whether the robot starts and fetches on the processor side.
37+
2738
private PathStates curState = PathStates.DONE;
2839
private boolean isHandling = false;
29-
private List<Character> nodeNames;
30-
private List<Integer> nodeLevels;
3140
private Timer timer = new Timer();
3241
private List<Trajectory<SwerveSample>> fetchPaths;
3342
private List<Trajectory<SwerveSample>> placePaths;
34-
private String[][] pathNames = new String[12][2];
3543
private Trajectory<SwerveSample> currPath;
3644
private String currPathString;
3745
private boolean runningPath = false;
3846
private boolean isServoing = false;
3947
private boolean mirrorTrajectory = false;
40-
private boolean mirrorToProcessor = false;
41-
private Character startNode = 'a';
4248

4349
public PathHandler(
4450
DriveSubsystem driveSubsystem,
@@ -55,8 +61,8 @@ public PathHandler(
5561
TagAlignSubsystem tagAlignSubsystem,
5662
RobotStateSubsystem robotStateSubsystem,
5763
String[][] pathNames,
58-
List<Character> NodeNames,
59-
List<Integer> NodeLevels,
64+
List<Character> nodeNames,
65+
List<Integer> nodeLevels,
6066
Character startNode,
6167
boolean mirrorToProcessor) {
6268
this.driveSubsystem = driveSubsystem;
@@ -73,17 +79,18 @@ public void setPathNames(String[][] pathNames) {
7379
if (!isHandling) {
7480
this.pathNames = pathNames;
7581
}
82+
reassignAlliance();
7683
}
7784

78-
public void setNodeNames(List<Character> NodeNames) {
85+
public void setNodeNames(List<Character> nodeNames) {
7986
if (!isHandling) {
80-
this.nodeNames = NodeNames;
87+
this.nodeNames = nodeNames;
8188
}
8289
}
8390

84-
public void setNodeLevels(List<Integer> NodeLevels) {
91+
public void setNodeLevels(List<Integer> nodeLevels) {
8592
if (!isHandling) {
86-
this.nodeLevels = NodeLevels;
93+
this.nodeLevels = nodeLevels;
8794
}
8895
}
8996

@@ -163,7 +170,7 @@ private void drivePathServo() {
163170
if (isHandling && runningPath && currPath != null && isServoing) {
164171
driveSubsystem.calculateControllerServo(
165172
mirrorToProcessor(currPath.sampleAt(timer.get(), mirrorTrajectory).get()),
166-
0.0); // TODO: use tag servoing here when ready
173+
tagAlignSubsystem.calculateAlignY());
167174
if (timer.hasElapsed(currPath.getTotalTime())) {
168175
driveSubsystem.setAutoDebugMsg("End " + currPathString);
169176
runningPath = false;
@@ -200,6 +207,8 @@ private Trajectory<SwerveSample> nextPath() {
200207
private void advanceNodes() {
201208
if (nodeNames.size() > 0) {
202209
nodeNames.remove(0);
210+
tagAlignSubsystem.setup(
211+
mirrorTrajectory ? Alliance.Red : Alliance.Blue, (nodeNames.get(0) - 'a') % 2 == 0);
203212
}
204213
}
205214

0 commit comments

Comments
 (0)