44
55package frc .robot ;
66
7+ import static edu .wpi .first .units .Units .*;
8+
79import com .ctre .phoenix6 .hardware .Pigeon2 ;
810import com .ctre .phoenix6 .swerve .SwerveDrivetrain .SwerveDriveState ;
11+ import com .ctre .phoenix6 .swerve .SwerveRequest ;
912import edu .wpi .first .epilogue .Logged ;
1013import edu .wpi .first .wpilibj2 .command .Command ;
1114import edu .wpi .first .wpilibj2 .command .Commands ;
@@ -25,26 +28,74 @@ public class RobotContainer {
2528 private Kicker kicker = new Kicker ();
2629 private CommandXboxController controller = new CommandXboxController (0 );
2730 private SwerveDriveState driveState = new SwerveDriveState ();
31+ private final SwerveRequest .FieldCentric drive = new SwerveRequest .FieldCentric ();
32+ private double MaxSpeed = TunerConstants .kSpeedAt12Volts .in (MetersPerSecond );
33+ private double MaxAngularRate = RotationsPerSecond .of (0.75 ).in (RadiansPerSecond );
34+
35+ // Should I move these to a config file?
2836
2937 public RobotContainer () {
3038 configureBindings ();
3139 }
3240
3341 private void configureBindings () {
42+ // Default Commands + Drivetrain
43+ flywheel .setDefaultCommand (
44+ new FlywheelCommand (flywheel , FlywheelCommand .Position .DEFAULT_SHOT , drivetrain ));
45+
46+ // Drivetrain Teleop drive with controller inputs
47+ drivetrain .setDefaultCommand (
48+ drivetrain .applyRequest (
49+ () ->
50+ drive
51+ .withVelocityX (-controller .getLeftY () * MaxSpeed )
52+ .withVelocityY (-controller .getLeftX () * MaxSpeed )
53+ .withRotationalRate (-controller .getRightX () * MaxAngularRate )));
54+
55+ // Buttons
56+
3457 // Y = Shoot Toggle
35- controller .y ().toggleOnTrue (new KickerCommand (kicker , KickerCommand .Position .OUTTAKE ));
58+ controller
59+ .y ()
60+ .toggleOnTrue (
61+ Commands .parallel (
62+ new KickerCommand (kicker , KickerCommand .Position .OUTTAKE ),
63+ new HopperCommand (hopper , HopperCommand .Position .SHOOT_RETRACT_EXTEND ),
64+ // We may need to change this, because if controller also presses X at the same time
65+ // bad things could happen
66+ new IntakeCommand (intake , IntakeCommand .Position .SLOW_INTAKE )));
3667 // X = intake toggle
3768 controller .x ().toggleOnTrue (new IntakeCommand (intake , IntakeCommand .Position .INTAKE ));
3869 // Right Stick Down = Extend/Retract Hopper
39- controller .rightStick ().onTrue (new ToggleHopperCommand (hopper ));
70+ controller
71+ .rightStick ()
72+ .toggleOnTrue (new HopperCommand (hopper , HopperCommand .Position .EXTEND_RETRACT ));
4073 // Right Trigger = Climb Extend
41- controller .rightTrigger ().toggleOnTrue (new ClimbCommand (climb , ClimbCommand .Position .CLIMB ));
74+ controller
75+ .rightTrigger ()
76+ .whileTrue (new ClimbCommand (climb , ClimbCommand .Position .DIRECTIONAL_CLIMB ));
4277 // Left Trigger = Climb Extend
43- controller .leftTrigger ().toggleOnTrue (new ClimbCommand (climb , ClimbCommand .Position .UNCLIMB ));
78+ controller
79+ .leftTrigger ()
80+ .whileTrue (new ClimbCommand (climb , ClimbCommand .Position .DIRECTIONAL_UNCLIMB ));
81+ // Back button = Zero Pigeon gyro
82+ controller .back ().onTrue (Commands .runOnce (() -> zeroPigeon ()));
83+ // Left Bumper = Flywheel Toggle for hub shot speeds
84+ controller
85+ .leftBumper ()
86+ .toggleOnTrue (new FlywheelCommand (flywheel , FlywheelCommand .Position .HUB_SHOT , drivetrain ));
87+ // Right Bumper = Flywheel Toggle for tower shot speeds
88+ controller
89+ .rightBumper ()
90+ .toggleOnTrue (
91+ new FlywheelCommand (flywheel , FlywheelCommand .Position .TOWER_SHOT , drivetrain ));
4492 }
4593
4694 public Command getAutonomousCommand () {
47- return Commands .print ("No autonomous command configured" );
95+ // Not finished yet
96+ // Does withDeadline work here?
97+ return (Commands .run (() -> flywheel .getDefaultCommand (), flywheel ))
98+ .withDeadline (Commands .waitSeconds (5 ));
4899 }
49100
50101 public static void zeroPigeon () {
0 commit comments