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

117 lines
6.5 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-04-28 01:04:35 -06:00
private final Drive m_robotDrive = new Drive(m_robotMap.driveLeftLeaderMotor, m_robotMap.driveRightLeaderMotor, m_robotMap.driveBase);
private final Shooter m_robotShooterLowerLefterSolenoid = new Shooter(m_robotMap.shooterLowerLefterSolenoid);
private final Shooter m_robotShooterLowerLeftSolenoid = new Shooter(m_robotMap.shooterLowerLeftSolenoid);
private final Shooter m_robotShooterLowerRightSolenoid = new Shooter(m_robotMap.shooterLowerRightSolenoid);
private final Shooter m_robotShooterLowerRighterSolenoid = new Shooter(m_robotMap.shooterLowerRighterSolenoid);
private final Shooter m_robotShooterUpperLefterSolenoid = new Shooter(m_robotMap.shooterUpperLefterSolenoid);
private final Shooter m_robotShooterUpperLeftSolenoid = new Shooter(m_robotMap.shooterUpperLeftSolenoid);
private final Shooter m_robotShooterUpperRightSolenoid = new Shooter(m_robotMap.shooterUpperRightSolenoid);
private final Shooter m_robotShooterUpperRighterSolenoid = new Shooter(m_robotMap.shooterUpperRighterSolenoid);
2022-04-26 14:55:02 -06:00
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-04-28 01:04:35 -06:00
// Y Button: Fire Upper Lefter Shooter
new JoystickButton(getController(), XboxController.Button.kY.value).whenPressed(putToDashboard("Y", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterUpperLefterSolenoid)).withName("Fire Upper Lefter")));
// B Button: Fire Upper Right Shooter
new JoystickButton(getController(), XboxController.Button.kB.value).whenPressed(putToDashboard("B", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterUpperRightSolenoid)).withName("Fire Upper Right")));
// A Button: Fire Upper Righter Shooter
new JoystickButton(getController(), XboxController.Button.kA.value).whenPressed(putToDashboard("A", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterUpperRighterSolenoid)).withName("Fire Upper Righter")));
// X Button: Fire Upper Left Shooter
new JoystickButton(getController(), XboxController.Button.kX.value).whenPressed(putToDashboard("X", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterUpperLeftSolenoid)).withName("Fire Upper Left")));
// D-Pad Up: Fire Lower Lefter Shooter
new POVButton(getController(), 0).whenPressed(putToDashboard("Up", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterLowerLefterSolenoid)).withName("Fire Lower Lefter")));
// D-Pad Right: Fire Lower Right Shooter
new POVButton(getController(), 90).whenPressed(putToDashboard("Right", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterLowerRightSolenoid)).withName("Fire Lower Right")));
// D-Pad Left: Fire Lower Righter Shooter
new POVButton(getController(), 180).whenPressed(putToDashboard("Down", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterLowerRighterSolenoid)).withName("Fire Lower Righter")));
// D-Pad Up: Fire Lower Left Shooter
new POVButton(getController(), 270).whenPressed(putToDashboard("Left", new InstantCommand(() -> fireShooterWithFeedback(m_robotShooterLowerLeftSolenoid)).withName("Fire Lower Left")));
// 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) {
boolean fired = shooter.set(true);
RumbleType rumbleType = shooter.getName().contains("Left") ? 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;
}
2022-04-25 16:47:06 -06:00
}