Skip to content

Commit b49b513

Browse files
committed
no more craashing
1 parent 430e21f commit b49b513

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/main/java/frc/trigon/robot/commands/commandclasses/GamePieceAutoDriveCommand.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,25 @@
66
import edu.wpi.first.wpilibj2.command.*;
77
import frc.trigon.robot.RobotContainer;
88
import frc.trigon.robot.commands.commandfactories.GeneralCommands;
9-
import frc.trigon.robot.constants.PathPlannerConstants;
9+
import frc.trigon.robot.constants.AutonomousConstants;
1010
import frc.trigon.robot.misc.objectdetectioncamera.ObjectPoseEstimator;
11-
import frc.trigon.robot.misc.simulatedfield.SimulatedGamePieceConstants;
1211
import frc.trigon.robot.subsystems.swerve.SwerveCommands;
13-
import org.littletonrobotics.junction.Logger;
1412
import lib.utilities.flippable.FlippableRotation2d;
13+
import org.littletonrobotics.junction.Logger;
1514

1615
import java.util.function.Supplier;
1716

1817
public class GamePieceAutoDriveCommand extends ParallelCommandGroup {
19-
private static final ObjectPoseEstimator OBJECT_POSE_ESTIMATOR = RobotContainer.OBJECT_POSE_ESTIMATOR;
20-
private final SimulatedGamePieceConstants.GamePieceType targetGamePieceType;
18+
private static final ObjectPoseEstimator CORAL_POSE_ESTIMATOR = RobotContainer.CORAL_POSE_ESTIMATOR;
2119
private Translation2d distanceFromTrackedGamePiece;
2220

23-
public GamePieceAutoDriveCommand(SimulatedGamePieceConstants.GamePieceType targetGamePieceType) {
24-
this.targetGamePieceType = targetGamePieceType;
21+
public GamePieceAutoDriveCommand() {
2522
addCommands(
2623
getTrackGamePieceCommand(),
2724
GeneralCommands.getContinuousConditionalCommand(
2825
getDriveToGamePieceCommand(() -> distanceFromTrackedGamePiece),
2926
GeneralCommands.getFieldRelativeDriveCommand(),
30-
() -> OBJECT_POSE_ESTIMATOR.getClosestObjectToRobot() != null && shouldMoveTowardsGamePiece(distanceFromTrackedGamePiece)
27+
() -> CORAL_POSE_ESTIMATOR.getClosestObjectToRobot() != null && shouldMoveTowardsGamePiece(distanceFromTrackedGamePiece)
3128
)
3229
);
3330
}
@@ -40,36 +37,36 @@ private Command getTrackGamePieceCommand() {
4037

4138
public static Translation2d calculateDistanceFromTrackedGamePiece() {
4239
final Pose2d robotPose = RobotContainer.ROBOT_POSE_ESTIMATOR.getEstimatedRobotPose();
43-
final Translation2d trackedObjectPositionOnField = OBJECT_POSE_ESTIMATOR.getClosestObjectToRobot();
40+
final Translation2d trackedObjectPositionOnField = CORAL_POSE_ESTIMATOR.getClosestObjectToRobot();
4441
if (trackedObjectPositionOnField == null)
4542
return null;
4643

4744
final Translation2d robotToGamePiece = robotPose.getTranslation().minus(trackedObjectPositionOnField);
4845
var distanceFromTrackedGamePiece = robotToGamePiece.rotateBy(robotPose.getRotation().unaryMinus());
4946
Logger.recordOutput("GamePieceAutoDrive/DistanceFromTrackedGamePiece", distanceFromTrackedGamePiece);
50-
Logger.recordOutput("GamePieceAutoDrive/XDistanceFromTrackedGamePiece", PathPlannerConstants.GAME_PIECE_AUTO_DRIVE_X_PID_CONTROLLER.getSetpoint().position);
47+
Logger.recordOutput("GamePieceAutoDrive/XDistanceFromTrackedGamePiece", AutonomousConstants.GAME_PIECE_AUTO_DRIVE_X_PID_CONTROLLER.getSetpoint().position);
5148
return distanceFromTrackedGamePiece;
5249
}
5350

5451
public static Command getDriveToGamePieceCommand(Supplier<Translation2d> distanceFromTrackedGamePiece) {
5552
return new SequentialCommandGroup(
56-
new InstantCommand(() -> PathPlannerConstants.GAME_PIECE_AUTO_DRIVE_X_PID_CONTROLLER.reset(distanceFromTrackedGamePiece.get().getX(), RobotContainer.SWERVE.getSelfRelativeVelocity().vxMetersPerSecond)),
53+
new InstantCommand(() -> AutonomousConstants.GAME_PIECE_AUTO_DRIVE_X_PID_CONTROLLER.reset(distanceFromTrackedGamePiece.get().getX(), RobotContainer.SWERVE.getSelfRelativeVelocity().vxMetersPerSecond)),
5754
SwerveCommands.getClosedLoopSelfRelativeDriveCommand(
58-
() -> PathPlannerConstants.GAME_PIECE_AUTO_DRIVE_X_PID_CONTROLLER.calculate(distanceFromTrackedGamePiece.get().getX()),
59-
() -> PathPlannerConstants.GAME_PIECE_AUTO_DRIVE_Y_PID_CONTROLLER.calculate(distanceFromTrackedGamePiece.get().getY()),
55+
() -> AutonomousConstants.GAME_PIECE_AUTO_DRIVE_X_PID_CONTROLLER.calculate(distanceFromTrackedGamePiece.get().getX()),
56+
() -> AutonomousConstants.GAME_PIECE_AUTO_DRIVE_Y_PID_CONTROLLER.calculate(distanceFromTrackedGamePiece.get().getY()),
6057
GamePieceAutoDriveCommand::calculateTargetAngle
6158
)
6259
);
6360
}
6461

6562
public static boolean shouldMoveTowardsGamePiece(Translation2d distanceFromTrackedGamePiece) {
6663
return distanceFromTrackedGamePiece != null &&
67-
(distanceFromTrackedGamePiece.getNorm() > PathPlannerConstants.AUTO_COLLECTION_INTAKE_OPEN_CHECK_DISTANCE_METERS);//TODO: If intake is open
64+
(distanceFromTrackedGamePiece.getNorm() > AutonomousConstants.AUTO_COLLECTION_INTAKE_OPEN_CHECK_DISTANCE_METERS);//TODO: If intake is open
6865
}
6966

7067
public static FlippableRotation2d calculateTargetAngle() {
7168
final Pose2d robotPose = RobotContainer.ROBOT_POSE_ESTIMATOR.getEstimatedRobotPose();
72-
final Translation2d trackedObjectFieldRelativePosition = OBJECT_POSE_ESTIMATOR.getClosestObjectToRobot();
69+
final Translation2d trackedObjectFieldRelativePosition = CORAL_POSE_ESTIMATOR.getClosestObjectToRobot();
7370
if (trackedObjectFieldRelativePosition == null)
7471
return null;
7572

0 commit comments

Comments
 (0)