6
6
import edu .wpi .first .wpilibj2 .command .*;
7
7
import frc .trigon .robot .RobotContainer ;
8
8
import frc .trigon .robot .commands .commandfactories .GeneralCommands ;
9
- import frc .trigon .robot .constants .PathPlannerConstants ;
9
+ import frc .trigon .robot .constants .AutonomousConstants ;
10
10
import frc .trigon .robot .misc .objectdetectioncamera .ObjectPoseEstimator ;
11
- import frc .trigon .robot .misc .simulatedfield .SimulatedGamePieceConstants ;
12
11
import frc .trigon .robot .subsystems .swerve .SwerveCommands ;
13
- import org .littletonrobotics .junction .Logger ;
14
12
import lib .utilities .flippable .FlippableRotation2d ;
13
+ import org .littletonrobotics .junction .Logger ;
15
14
16
15
import java .util .function .Supplier ;
17
16
18
17
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 ;
21
19
private Translation2d distanceFromTrackedGamePiece ;
22
20
23
- public GamePieceAutoDriveCommand (SimulatedGamePieceConstants .GamePieceType targetGamePieceType ) {
24
- this .targetGamePieceType = targetGamePieceType ;
21
+ public GamePieceAutoDriveCommand () {
25
22
addCommands (
26
23
getTrackGamePieceCommand (),
27
24
GeneralCommands .getContinuousConditionalCommand (
28
25
getDriveToGamePieceCommand (() -> distanceFromTrackedGamePiece ),
29
26
GeneralCommands .getFieldRelativeDriveCommand (),
30
- () -> OBJECT_POSE_ESTIMATOR .getClosestObjectToRobot () != null && shouldMoveTowardsGamePiece (distanceFromTrackedGamePiece )
27
+ () -> CORAL_POSE_ESTIMATOR .getClosestObjectToRobot () != null && shouldMoveTowardsGamePiece (distanceFromTrackedGamePiece )
31
28
)
32
29
);
33
30
}
@@ -40,36 +37,36 @@ private Command getTrackGamePieceCommand() {
40
37
41
38
public static Translation2d calculateDistanceFromTrackedGamePiece () {
42
39
final Pose2d robotPose = RobotContainer .ROBOT_POSE_ESTIMATOR .getEstimatedRobotPose ();
43
- final Translation2d trackedObjectPositionOnField = OBJECT_POSE_ESTIMATOR .getClosestObjectToRobot ();
40
+ final Translation2d trackedObjectPositionOnField = CORAL_POSE_ESTIMATOR .getClosestObjectToRobot ();
44
41
if (trackedObjectPositionOnField == null )
45
42
return null ;
46
43
47
44
final Translation2d robotToGamePiece = robotPose .getTranslation ().minus (trackedObjectPositionOnField );
48
45
var distanceFromTrackedGamePiece = robotToGamePiece .rotateBy (robotPose .getRotation ().unaryMinus ());
49
46
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 );
51
48
return distanceFromTrackedGamePiece ;
52
49
}
53
50
54
51
public static Command getDriveToGamePieceCommand (Supplier <Translation2d > distanceFromTrackedGamePiece ) {
55
52
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 )),
57
54
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 ()),
60
57
GamePieceAutoDriveCommand ::calculateTargetAngle
61
58
)
62
59
);
63
60
}
64
61
65
62
public static boolean shouldMoveTowardsGamePiece (Translation2d distanceFromTrackedGamePiece ) {
66
63
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
68
65
}
69
66
70
67
public static FlippableRotation2d calculateTargetAngle () {
71
68
final Pose2d robotPose = RobotContainer .ROBOT_POSE_ESTIMATOR .getEstimatedRobotPose ();
72
- final Translation2d trackedObjectFieldRelativePosition = OBJECT_POSE_ESTIMATOR .getClosestObjectToRobot ();
69
+ final Translation2d trackedObjectFieldRelativePosition = CORAL_POSE_ESTIMATOR .getClosestObjectToRobot ();
73
70
if (trackedObjectFieldRelativePosition == null )
74
71
return null ;
75
72
0 commit comments