Files
Shirt-Cannon/src/main/java/frc4388/robot/RobotContainer.java
T

188 lines
9.7 KiB
Java
Raw Normal View History

2022-04-25 16:47:06 -06:00
package frc4388.robot;
2022-04-28 01:04:35 -06:00
import edu.wpi.first.util.sendable.Sendable;
2022-04-26 14:55:02 -06:00
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.GenericHID.RumbleType;
import edu.wpi.first.wpilibj.XboxController;
2022-04-28 01:04:35 -06:00
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
2022-04-25 16:47:06 -06:00
import edu.wpi.first.wpilibj2.command.Command;
2022-04-26 14:55:02 -06:00
import edu.wpi.first.wpilibj2.command.CommandGroupBase;
2022-04-25 16:47:06 -06:00
import edu.wpi.first.wpilibj2.command.InstantCommand;
2022-04-26 14:55:02 -06:00
import edu.wpi.first.wpilibj2.command.PrintCommand;
2022-04-25 16:47:06 -06:00
import edu.wpi.first.wpilibj2.command.RunCommand;
2022-04-26 14:55:02 -06:00
import edu.wpi.first.wpilibj2.command.WaitCommand;
2022-04-25 16:47:06 -06:00
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
2022-04-26 14:55:02 -06:00
import edu.wpi.first.wpilibj2.command.button.POVButton;
import frc4388.robot.Constants.OIConstants;
2022-04-25 16:47:06 -06:00
import frc4388.robot.subsystems.Drive;
2022-04-26 14:55:02 -06:00
import frc4388.robot.subsystems.Horn;
import frc4388.robot.subsystems.Shooter;
2022-04-25 16:47:06 -06:00
/**
2022-04-26 14:55:02 -06:00
* This class is where the bulk of the robot should be declared. Since Command-based is a
* "declarative" paradigm, very little robot logic should actually be handled in the {@link Robot}
* periodic methods (other than the scheduler calls). Instead, the structure of the robot (including
* subsystems, commands, and button mappings) should be declared here.
2022-04-25 16:47:06 -06:00
*/
public class RobotContainer {
2022-04-26 14:55:02 -06:00
/* RobotMap */
private final RobotMap m_robotMap = new RobotMap();
2022-04-25 16:47:06 -06:00
2022-04-26 14:55:02 -06:00
/* Subsystems */
2022-07-04 22:02:13 -06:00
private final Drive m_robotDrive = new Drive(m_robotMap.driveMotorLeftLeader, m_robotMap.driveMotorRightLeader, m_robotMap.driveBase);
2022-04-28 01:04:35 -06:00
2023-04-26 11:42:48 -06:00
private final Shooter m_robotShooterBottomLeft = new Shooter(m_robotMap.shooterSolenoidBottomLeft);
private final Shooter m_robotShooterBottomMiddle = new Shooter(m_robotMap.shooterSolenoidBottomMiddle);
private final Shooter m_robotShooterBottomRight = new Shooter(m_robotMap.shooterSolenoidBottomRight);
private final Shooter m_robotShooterTopLeft = new Shooter(m_robotMap.shooterSolenoidTopLeft);
private final Shooter m_robotShooterTopMiddle = new Shooter(m_robotMap.shooterSolenoidTopMiddle);
private final Shooter m_robotShooterTopRight = new Shooter(m_robotMap.shooterSolenoidTopRight);
// private final Shooter m_robotShooterBottomLeftOuter = new Shooter(m_robotMap.shooterSolenoidBottomLeftOuter);
// private final Shooter m_robotShooterBottomLeftInner = new Shooter(m_robotMap.shooterSolenoidBottomLeftInner);
// private final Shooter m_robotShooterBottomRightInner = new Shooter(m_robotMap.shooterSolenoidBottomRightInner);
// private final Shooter m_robotShooterBottomRightOuter = new Shooter(m_robotMap.shooterSolenoidBottomRightOuter);
// private final Shooter m_robotShooterTopLeftOuter = new Shooter(m_robotMap.shooterSolenoidTopLeftOuter);
// private final Shooter m_robotShooterTopLeftInner = new Shooter(m_robotMap.shooterSolenoidTopLeftInner);
// private final Shooter m_robotShooterTopRightInner = new Shooter(m_robotMap.shooterSolenoidTopRightInner);
// private final Shooter m_robotShooterTopRightOuter = new Shooter(m_robotMap.shooterSolenoidTopRightOuter);
// private final Horn m_robotHorn = new Horn(m_robotMap.hornSolenoid);
2022-04-25 16:47:06 -06:00
2022-04-26 14:55:02 -06:00
/* Controllers */
private final XboxController m_controller = new XboxController(OIConstants.CONTROLLER_ID);
2022-04-25 16:47:06 -06:00
2022-04-26 14:55:02 -06:00
/**
* The container for the robot. Contains subsystems, OI devices, and commands.
*/
public RobotContainer() {
configureButtonBindings();
2022-04-25 16:47:06 -06:00
2022-04-26 14:55:02 -06:00
/* Default Commands */
// drives the robot with a two-axis input from the driver controller
m_robotDrive.setDefaultCommand(new RunCommand(() -> m_robotDrive.arcadeDrive(getController().getLeftY(), getController().getRightX()), m_robotDrive));
}
2022-04-25 16:47:06 -06:00
2022-04-26 14:55:02 -06:00
/**
* Use this method to define your button->command mappings. Buttons can be created by instantiating
* a {@link GenericHID} or one of its subclasses ({@link edu.wpi.first.wpilibj.Joystick} or
* {@link XboxController}), and then passing it to a
* {@link edu.wpi.first.wpilibj2.command.button.JoystickButton}.
*/
private void configureButtonBindings() {
2022-07-04 22:02:13 -06:00
// X Button: Fire Top Left Shooter
2023-04-26 11:42:48 -06:00
new JoystickButton(getController(), XboxController.Button.kX.value).whenPressed(() -> fireShooterWithFeedback(m_robotShooterTopLeft));
// Y Button: Fire Top Middle Shooter
new JoystickButton(getController(), XboxController.Button.kY.value).whenPressed(() -> fireShooterWithFeedback(m_robotShooterTopMiddle));
// B Button: Fire Top Right Shooter
new JoystickButton(getController(), XboxController.Button.kB.value).whenPressed(() -> fireShooterWithFeedback(m_robotShooterTopRight));
2022-07-04 22:02:13 -06:00
// D-Pad Left: Fire Bottom Righter Shooter
2023-04-26 11:42:48 -06:00
new POVButton(getController(), 270).whenPressed(() -> fireShooterWithFeedback(m_robotShooterBottomLeft));
// D-Pad Up: Fire Bottom Middle Shooter
new POVButton(getController(), 0).whenPressed(() -> fireShooterWithFeedback(m_robotShooterBottomMiddle));
// D-Pad Right: Fire Bottom Right Shooter
new POVButton(getController(), 90).whenPressed(() -> fireShooterWithFeedback(m_robotShooterBottomRight));
// // Y Button: Fire Top Lefter Shooter
// new JoystickButton(getController(), XboxController.Button.kY.value).whenPressed(putToDashboard("Y", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterTopLeftOuter)).withName("Fire Top Lefter")));
// // B Button: Fire Top Right Shooter
// new JoystickButton(getController(), XboxController.Button.kB.value).whenPressed(putToDashboard("B", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterTopRightInner)).withName("Fire Top Right")));
// // A Button: Fire Top Righter Shooter
// new JoystickButton(getController(), XboxController.Button.kA.value).whenPressed(putToDashboard("A", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterTopRightOuter)).withName("Fire Top Righter")));
// // X Button: Fire Top Left Shooter
// new JoystickButton(getController(), XboxController.Button.kX.value).whenPressed(putToDashboard("X", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterTopLeftInner)).withName("Fire Top Left")));
// // D-Pad Up: Fire Bottom Lefter Shooter
// new POVButton(getController(), 0).whenPressed(putToDashboard("Up", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterBottomLeftOuter)).withName("Fire Bottom Lefter")));
// // D-Pad Right: Fire Bottom Right Shooter
// new POVButton(getController(), 90).whenPressed(putToDashboard("Right", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterBottomRightInner)).withName("Fire Bottom Right")));
// // D-Pad Left: Fire Bottom Righter Shooter
// new POVButton(getController(), 180).whenPressed(putToDashboard("Down", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterBottomRightOuter)).withName("Fire Bottom Righter")));
// // D-Pad Up: Fire Bottom Left Shooter
// new POVButton(getController(), 270).whenPressed(putToDashboard("Left", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterBottomLeftInner)).withName("Fire Bottom Left")));
// Right menu button, aka Start: Reset Barrels
new JoystickButton(getController(), XboxController.Button.kStart.value).whenPressed(() -> ResetShooters());
// Left menu button, aka Back: Fire all barrels
new JoystickButton(getController(), XboxController.Button.kBack.value).whenPressed(() -> FireAll());
// Do we even have this on the robot?
// // Right Bumper: Sound Horn
// new JoystickButton(getController(), XboxController.Button.kRightBumper.value).whenPressed(() -> m_robotHorn.set(true)).whenReleased(() -> m_robotHorn.set(false));
// // Left Bumper: Sound Horn
// new JoystickButton(getController(), XboxController.Button.kLeftBumper.value).whenPressed(() -> m_robotHorn.set(true)).whenReleased(() -> m_robotHorn.set(false));
2022-04-26 14:55:02 -06:00
}
2022-04-25 16:47:06 -06:00
2022-04-28 01:04:35 -06:00
private static <T extends Sendable> T putToDashboard(String key, T data) {
SmartDashboard.putData(key, data);
return data;
}
private void fireShooterWithFeedback(Shooter shooter) {
2022-07-04 22:02:13 -06:00
boolean fired = shooter.fire();
RumbleType rumbleType = shooter.getName().indexOf('L', 13) >= 0 ? RumbleType.kLeftRumble : RumbleType.kRightRumble;
2022-04-26 14:55:02 -06:00
double value = fired ? 0.3 : 0.6;
double duration = fired ? 0.3 : 0.4;
CommandGroupBase.sequence(new InstantCommand(() -> getController().setRumble(rumbleType, value)), new WaitCommand(duration), new InstantCommand(() -> getController().setRumble(rumbleType, 0.0))).schedule();
}
2022-04-25 16:47:06 -06:00
2022-04-26 14:55:02 -06:00
/**
* Use this to pass the autonomous command to the main {@link Robot} class.
*
* @return the command to run in autonomous
*/
public Command getAutonomousCommand() {
return new PrintCommand("No Autonomous");
}
2022-04-25 16:47:06 -06:00
2022-04-26 14:55:02 -06:00
public XboxController getController() {
return m_controller;
}
2023-04-26 11:42:48 -06:00
public void ResetShooters() {
m_robotShooterBottomLeft.ready();
m_robotShooterBottomMiddle.ready();
m_robotShooterBottomRight.ready();
m_robotShooterTopLeft.ready();
m_robotShooterTopMiddle.ready();
m_robotShooterTopRight.ready();
// m_robotShooterBottomLeftOuter.ready();
// m_robotShooterBottomLeftInner.ready();
// m_robotShooterBottomRightInner.ready();
// m_robotShooterBottomRightOuter.ready();
// m_robotShooterTopLeftOuter.ready();
// m_robotShooterTopLeftInner.ready();
// m_robotShooterTopRightInner.ready();
// m_robotShooterTopRightOuter.ready();
}
public void FireAll() {
m_robotShooterBottomLeft.fire();
m_robotShooterBottomMiddle.fire();
m_robotShooterBottomRight.fire();
m_robotShooterTopLeft.fire();
m_robotShooterTopMiddle.fire();
m_robotShooterTopRight.fire();
// m_robotShooterBottomLeftOuter.fire();
// m_robotShooterBottomLeftInner.fire();
// m_robotShooterBottomRightInner.fire();
// m_robotShooterBottomRightOuter.fire();
// m_robotShooterTopLeftOuter.fire();
// m_robotShooterTopLeftInner.fire();
// m_robotShooterTopRightInner.fire();
// m_robotShooterTopRightOuter.fire();
}
2022-04-25 16:47:06 -06:00
}