Implement shooter readiness

Speed up shooter side detection for haptics
Change some variable names
This commit is contained in:
nathanrsxtn
2022-07-04 22:02:13 -06:00
parent 65cf0dd3a3
commit 74af4b2f2a
4 changed files with 98 additions and 76 deletions
+12 -12
View File
@@ -11,21 +11,21 @@ package frc4388.robot;
*/
public final class Constants {
public static final class DriveConstants {
public static final int DRIVE_LEFT_LEADER_CAN_ID = 2;
public static final int DRIVE_RIGHT_LEADER_CAN_ID = 3;
public static final int DRIVE_LEFT_FOLLOWER_CAN_ID = 4;
public static final int DRIVE_RIGHT_FOLLOWER_CAN_ID = 5;
public static final int DRIVE_LEFT_LEADER_ID = 2;
public static final int DRIVE_RIGHT_LEADER_ID = 3;
public static final int DRIVE_LEFT_FOLLOWER_ID = 4;
public static final int DRIVE_RIGHT_FOLLOWER_ID = 5;
}
public static final class ShooterConstants {
public static final int SHOOTER_LOWER_LEFTER_SOLENOID_ID = 1;
public static final int SHOOTER_LOWER_LEFT_SOLENOID_ID = 2;
public static final int SHOOTER_LOWER_RIGHT_SOLENOID_ID = 3;
public static final int SHOOTER_LOWER_RIGHTER_SOLENOID_ID = 4;
public static final int SHOOTER_UPPER_LEFTER_SOLENOID_ID = 5;
public static final int SHOOTER_UPPER_LEFT_SOLENOID_ID = 6;
public static final int SHOOTER_UPPER_RIGHT_SOLENOID_ID = 7;
public static final int SHOOTER_UPPER_RIGHTER_SOLENOID_ID = 8;
public static final int SHOOTER_SOLENOID_BOTTOM_LEFT_OUTER_ID = 1;
public static final int SHOOTER_SOLENOID_BOTTOM_LEFT_INNER_ID = 2;
public static final int SHOOTER_SOLENOID_BOTTOM_RIGHT_INNER_ID = 3;
public static final int SHOOTER_SOLENOID_BOTTOM_RIGHT_OUTER_ID = 4;
public static final int SHOOTER_SOLENOID_TOP_LEFT_OUTER_ID = 5;
public static final int SHOOTER_SOLENOID_TOP_LEFT_INNER_ID = 6;
public static final int SHOOTER_SOLENOID_TOP_RIGHT_INNER_ID = 7;
public static final int SHOOTER_SOLENOID_TOP_RIGHT_OUTER_ID = 8;
}
public static final class HornConstants {
+27 -27
View File
@@ -29,17 +29,17 @@ public class RobotContainer {
private final RobotMap m_robotMap = new RobotMap();
/* Subsystems */
private final Drive m_robotDrive = new Drive(m_robotMap.driveLeftLeaderMotor, m_robotMap.driveRightLeaderMotor, m_robotMap.driveBase);
private final Drive m_robotDrive = new Drive(m_robotMap.driveMotorLeftLeader, m_robotMap.driveMotorRightLeader, 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_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_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);
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);
@@ -64,23 +64,23 @@ public class RobotContainer {
* {@link edu.wpi.first.wpilibj2.command.button.JoystickButton}.
*/
private void configureButtonBindings() {
// 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")));
// 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 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")));
// 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 Bumper: Sound Horn
new JoystickButton(getController(), XboxController.Button.kRightBumper.value).whenPressed(() -> m_robotHorn.set(true)).whenReleased(() -> m_robotHorn.set(false));
@@ -94,8 +94,8 @@ public class RobotContainer {
}
private void fireShooterWithFeedback(Shooter shooter) {
boolean fired = shooter.set(true);
RumbleType rumbleType = shooter.getName().contains("Left") ? RumbleType.kLeftRumble : RumbleType.kRightRumble;
boolean fired = shooter.fire();
RumbleType rumbleType = shooter.getName().indexOf('L', 13) >= 0 ? RumbleType.kLeftRumble : RumbleType.kRightRumble;
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();
+34 -34
View File
@@ -31,56 +31,56 @@ public class RobotMap {
}
/* Drive Subsystem */
public final WPI_TalonSRX driveLeftLeaderMotor = new WPI_TalonSRX(DRIVE_LEFT_LEADER_CAN_ID);
public final WPI_TalonSRX driveRightLeaderMotor = new WPI_TalonSRX(DRIVE_RIGHT_LEADER_CAN_ID);
public final WPI_TalonSRX driveLeftFollowerMotor = new WPI_TalonSRX(DRIVE_LEFT_FOLLOWER_CAN_ID);
public final WPI_TalonSRX driveRightFollowerMotor = new WPI_TalonSRX(DRIVE_RIGHT_FOLLOWER_CAN_ID);
public final WPI_TalonSRX driveMotorLeftLeader = new WPI_TalonSRX(DRIVE_LEFT_LEADER_ID);
public final WPI_TalonSRX driveMotorRightLeader = new WPI_TalonSRX(DRIVE_RIGHT_LEADER_ID);
public final WPI_TalonSRX driveMotorLeftFollower = new WPI_TalonSRX(DRIVE_LEFT_FOLLOWER_ID);
public final WPI_TalonSRX driveMotorRightFollower = new WPI_TalonSRX(DRIVE_RIGHT_FOLLOWER_ID);
public final DifferentialDrive driveBase = new DifferentialDrive(driveLeftLeaderMotor, driveRightLeaderMotor);
public final DifferentialDrive driveBase = new DifferentialDrive(driveMotorLeftLeader, driveMotorRightLeader);
private void configureDriveMotorControllers() {
driveLeftLeaderMotor.configFactoryDefault();
driveRightLeaderMotor.configFactoryDefault();
driveLeftFollowerMotor.configFactoryDefault();
driveRightFollowerMotor.configFactoryDefault();
driveMotorLeftLeader.configFactoryDefault();
driveMotorRightLeader.configFactoryDefault();
driveMotorLeftFollower.configFactoryDefault();
driveMotorRightFollower.configFactoryDefault();
driveLeftLeaderMotor.setNeutralMode(NeutralMode.Brake);
driveRightLeaderMotor.setNeutralMode(NeutralMode.Brake);
driveLeftFollowerMotor.setNeutralMode(NeutralMode.Brake);
driveRightFollowerMotor.setNeutralMode(NeutralMode.Brake);
driveMotorLeftLeader.setNeutralMode(NeutralMode.Brake);
driveMotorRightLeader.setNeutralMode(NeutralMode.Brake);
driveMotorLeftFollower.setNeutralMode(NeutralMode.Brake);
driveMotorRightFollower.setNeutralMode(NeutralMode.Brake);
driveLeftFollowerMotor.follow(driveLeftLeaderMotor);
driveRightFollowerMotor.follow(driveRightLeaderMotor);
driveMotorLeftFollower.follow(driveMotorLeftLeader);
driveMotorRightFollower.follow(driveMotorRightLeader);
}
/* Horn Subsystem */
public final Solenoid hornSolenoid = new Solenoid(PneumaticsModuleType.REVPH, HORN_SOLENOID_ID);
/* Shooter Subsystem */
public final Solenoid shooterLowerLefterSolenoid = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_LOWER_LEFTER_SOLENOID_ID);
public final Solenoid shooterLowerLeftSolenoid = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_LOWER_LEFT_SOLENOID_ID);
public final Solenoid shooterLowerRightSolenoid = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_LOWER_RIGHT_SOLENOID_ID);
public final Solenoid shooterLowerRighterSolenoid = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_LOWER_RIGHTER_SOLENOID_ID);
public final Solenoid shooterUpperLefterSolenoid = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_UPPER_LEFTER_SOLENOID_ID);
public final Solenoid shooterUpperLeftSolenoid = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_UPPER_LEFT_SOLENOID_ID);
public final Solenoid shooterUpperRightSolenoid = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_UPPER_RIGHT_SOLENOID_ID);
public final Solenoid shooterUpperRighterSolenoid = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_UPPER_RIGHTER_SOLENOID_ID);
public final Solenoid shooterSolenoidBottomLeftOuter = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_SOLENOID_BOTTOM_LEFT_OUTER_ID);
public final Solenoid shooterSolenoidBottomLeftInner = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_SOLENOID_BOTTOM_LEFT_INNER_ID);
public final Solenoid shooterSolenoidBottomRightInner = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_SOLENOID_BOTTOM_RIGHT_INNER_ID);
public final Solenoid shooterSolenoidBottomRightOuter = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_SOLENOID_BOTTOM_RIGHT_OUTER_ID);
public final Solenoid shooterSolenoidTopLeftOuter = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_SOLENOID_TOP_LEFT_OUTER_ID);
public final Solenoid shooterSolenoidTopLeftInner = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_SOLENOID_TOP_LEFT_INNER_ID);
public final Solenoid shooterSolenoidTopRightInner = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_SOLENOID_TOP_RIGHT_INNER_ID);
public final Solenoid shooterSolenoidTopRightOuter = new Solenoid(PneumaticsModuleType.REVPH, SHOOTER_SOLENOID_TOP_RIGHT_OUTER_ID);
private void configureLiveWindow() {
SendableRegistry.setName(driveLeftFollowerMotor, "Drive", "Left Follower Motor");
SendableRegistry.setName(driveRightFollowerMotor, "Drive", "Right Follower Motor");
SendableRegistry.setName(driveBase, "Drive", "Drive Base");
SendableRegistry.setName(driveMotorLeftFollower, "Drive", "Motor Left Follower");
SendableRegistry.setName(driveMotorRightFollower, "Drive", "Motor Right Follower");
SendableRegistry.setName(driveBase, "Drive", "Base");
SendableRegistry.setName(hornSolenoid, "Horn", "Solenoid");
SendableRegistry.setName(shooterLowerLefterSolenoid, "Shooter", "Lower Lefter Solenoid");
SendableRegistry.setName(shooterLowerLeftSolenoid, "Shooter", "Lower Left Solenoid");
SendableRegistry.setName(shooterLowerRightSolenoid, "Shooter", "Lower Right Solenoid");
SendableRegistry.setName(shooterLowerRighterSolenoid, "Shooter", "Lower Righter Solenoid");
SendableRegistry.setName(shooterUpperLefterSolenoid, "Shooter", "Upper Lefter Solenoid");
SendableRegistry.setName(shooterUpperLeftSolenoid, "Shooter", "Upper Left Solenoid");
SendableRegistry.setName(shooterUpperRightSolenoid, "Shooter", "Upper Right Solenoid");
SendableRegistry.setName(shooterUpperRighterSolenoid, "Shooter", "Upper Righter Solenoid");
SendableRegistry.setName(shooterSolenoidBottomLeftOuter, "Shooter", "Solenoid Bottom Left Outer");
SendableRegistry.setName(shooterSolenoidBottomLeftInner, "Shooter", "Solenoid Bottom Left Inner");
SendableRegistry.setName(shooterSolenoidBottomRightInner, "Shooter", "Solenoid Bottom Right Inner");
SendableRegistry.setName(shooterSolenoidBottomRightOuter, "Shooter", "Solenoid Bottom Right Outer");
SendableRegistry.setName(shooterSolenoidTopLeftOuter, "Shooter", "Solenoid Top Left Outer");
SendableRegistry.setName(shooterSolenoidTopLeftInner, "Shooter", "Solenoid Top Left Inner");
SendableRegistry.setName(shooterSolenoidTopRightInner, "Shooter", "Solenoid Top Right Inner");
SendableRegistry.setName(shooterSolenoidTopRightOuter, "Shooter", "Solenoid Top Right Outer");
}
}
@@ -10,9 +10,31 @@ public class Shooter extends SubsystemBase {
m_solenoid = solenoid;
}
public boolean set(boolean on) {
if (m_solenoid.get() == on) return false;
m_solenoid.set(on);
/**
* Check if the shooter is ready to fire.
*
* @return True if the shooter is ready or false if the shooter is not ready
*/
public boolean isReady() {
return !m_solenoid.get();
}
/**
* Ready the shooter to fire.
*/
public void ready() {
m_solenoid.set(false);
}
/**
* Fire the shooter if it is ready.
*
* @return True if the shooter was ready or false if the shooter was not ready
*/
public boolean fire() {
if (!isReady())
return false;
m_solenoid.set(true);
return true;
}
}