Skip to content

Commit

Permalink
Flip to red properly on autos
Browse files Browse the repository at this point in the history
  • Loading branch information
superpenguin612 committed Mar 7, 2024
1 parent 33ef0cf commit 121fcf4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj.smartdashboard.Field2d;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj2.command.Command;
Expand Down Expand Up @@ -131,6 +132,9 @@ public void periodicUpdate() {
public void displayPaths(List<PathPlannerPath> paths) {
ArrayList<Pose2d> poses = new ArrayList<Pose2d>();
for (PathPlannerPath path : paths) {
if (DriverStation.getAlliance().orElse(Alliance.Blue) == Alliance.Red) {
path = path.flipPath();
}
PathPlannerTrajectory trajectory = path.getTrajectory(new ChassisSpeeds(),
path.getStartingDifferentialPose().getRotation());

Expand Down Expand Up @@ -167,9 +171,9 @@ public void runSelectedRoutine() {
timer.start();
currentCommand = baseCommand
.beforeStarting(() -> resetOdometryConsumer.accept(getSelectedRoutine().getInitialPose()))
.andThen(Commands.runOnce(timer::stop))
.withName("auto");
currentCommand.schedule();
new Trigger(currentCommand::isFinished).onTrue(Commands.runOnce(timer::stop).ignoringDisable(true));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.pathplanner.lib.path.PathPlannerPath;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj2.command.Command;

public class AutoRoutine {
Expand Down Expand Up @@ -45,7 +47,10 @@ public List<PathPlannerPath> getPathPlannerPaths() {

public Pose2d getInitialPose() {
if (pathPlannerPaths != null) {
return initialPose;
if (DriverStation.getAlliance().orElse(Alliance.Blue) == Alliance.Red)
return Reflector.reflectPose2d(initialPose, 16.54);
else
return initialPose;
} else {
return new Pose2d();
}
Expand Down

0 comments on commit 121fcf4

Please sign in to comment.