mirror of
https://github.com/Team4388/Shirt-Cannon.git
synced 2026-06-09 08:38:05 -06:00
Add best guess base robot code
Remove unused items
This commit is contained in:
@@ -1,114 +1,138 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package frc4388.robot;
|
||||
|
||||
import edu.wpi.first.wpilibj.Joystick;
|
||||
import edu.wpi.first.networktables.EntryListenerFlags;
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.wpilibj.GenericHID;
|
||||
import edu.wpi.first.wpilibj.GenericHID.RumbleType;
|
||||
import edu.wpi.first.wpilibj.XboxController;
|
||||
import edu.wpi.first.wpilibj2.command.Command;
|
||||
import edu.wpi.first.wpilibj2.command.CommandGroupBase;
|
||||
import edu.wpi.first.wpilibj2.command.InstantCommand;
|
||||
import edu.wpi.first.wpilibj2.command.PrintCommand;
|
||||
import edu.wpi.first.wpilibj2.command.RunCommand;
|
||||
import edu.wpi.first.wpilibj2.command.WaitCommand;
|
||||
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
|
||||
import frc4388.robot.Constants.*;
|
||||
import edu.wpi.first.wpilibj2.command.button.POVButton;
|
||||
import frc4388.robot.Constants.OIConstants;
|
||||
import frc4388.robot.subsystems.Drive;
|
||||
import frc4388.robot.subsystems.LED;
|
||||
import frc4388.utility.LEDPatterns;
|
||||
import frc4388.utility.controller.IHandController;
|
||||
import frc4388.utility.controller.XboxController;
|
||||
import frc4388.robot.subsystems.Horn;
|
||||
import frc4388.robot.subsystems.Shooter;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
public class RobotContainer {
|
||||
/* RobotMap */
|
||||
private final RobotMap m_robotMap = new RobotMap();
|
||||
/* RobotMap */
|
||||
private final RobotMap m_robotMap = new RobotMap();
|
||||
|
||||
/* Subsystems */
|
||||
private final Drive m_robotDrive = new Drive(m_robotMap.leftFrontMotor, m_robotMap.rightFrontMotor,
|
||||
m_robotMap.leftBackMotor, m_robotMap.rightBackMotor, m_robotMap.driveTrain, m_robotMap.gyroDrive);
|
||||
/* Subsystems */
|
||||
private final Drive m_robotDrive = new Drive(m_robotMap.driveLeftMotor, m_robotMap.driveRightMotor, m_robotMap.driveBase);
|
||||
private final Shooter[][] m_robotShooterRows = {
|
||||
{
|
||||
new Shooter(m_robotMap.shooterLowerLefterSolenoid),
|
||||
new Shooter(m_robotMap.shooterLowerLeftSolenoid),
|
||||
new Shooter(m_robotMap.shooterLowerRightSolenoid),
|
||||
new Shooter(m_robotMap.shooterLowerRighterSolenoid),
|
||||
},
|
||||
{
|
||||
new Shooter(m_robotMap.shooterUpperLefterSolenoid),
|
||||
new Shooter(m_robotMap.shooterUpperLeftSolenoid),
|
||||
new Shooter(m_robotMap.shooterUpperRightSolenoid),
|
||||
new Shooter(m_robotMap.shooterUpperRighterSolenoid)
|
||||
}
|
||||
};
|
||||
private final Horn m_robotHorn = new Horn(m_robotMap.hornSolenoid);
|
||||
|
||||
private final LED m_robotLED = new LED(m_robotMap.LEDController);
|
||||
/* Controllers */
|
||||
private final XboxController m_controller = new XboxController(OIConstants.CONTROLLER_ID);
|
||||
private final NetworkTableInteger m_shooterRowIndex = new NetworkTableInteger("Shooter/Row", 0, 0, 1);
|
||||
private final NetworkTableInteger m_shooterColumnIndex = new NetworkTableInteger("Shooter/Column", 0, 0, 3);
|
||||
|
||||
/* Controllers */
|
||||
private final XboxController m_driverXbox = new XboxController(OIConstants.XBOX_DRIVER_ID);
|
||||
private final XboxController m_operatorXbox = new XboxController(OIConstants.XBOX_OPERATOR_ID);
|
||||
/**
|
||||
* The container for the robot. Contains subsystems, OI devices, and commands.
|
||||
*/
|
||||
public RobotContainer() {
|
||||
configureButtonBindings();
|
||||
|
||||
/**
|
||||
* The container for the robot. Contains subsystems, OI devices, and commands.
|
||||
*/
|
||||
public RobotContainer() {
|
||||
configureButtonBindings();
|
||||
/* 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));
|
||||
}
|
||||
|
||||
/* Default Commands */
|
||||
// drives the robot with a two-axis input from the driver controller
|
||||
m_robotDrive.setDefaultCommand(
|
||||
new RunCommand(() -> m_robotDrive.driveWithInput(getDriverController().getLeftYAxis(),
|
||||
getDriverController().getRightXAxis()), m_robotDrive));
|
||||
// continually sends updates to the Blinkin LED controller to keep the lights on
|
||||
m_robotLED.setDefaultCommand(new RunCommand(() -> m_robotLED.updateLED(), m_robotLED));
|
||||
/**
|
||||
* 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() {
|
||||
// B Button: Fire Selected Shooter
|
||||
new JoystickButton(getController(), XboxController.Button.kB.value).whenPressed(this::fireShooterWithFeedback);
|
||||
// A Button: Sound Horn
|
||||
new JoystickButton(getController(), XboxController.Button.kA.value).whenPressed(() -> m_robotHorn.set(true)).whenReleased(() -> m_robotHorn.set(false));
|
||||
// Right Bumper: Shift Column Selection Right
|
||||
new JoystickButton(getController(), XboxController.Button.kRightBumper.value).whenPressed(() -> m_shooterColumnIndex.set(m_shooterColumnIndex.get() + 1));
|
||||
// Left Bumper: Shift Column Selection Left
|
||||
new JoystickButton(getController(), XboxController.Button.kLeftBumper.value).whenPressed(() -> m_shooterColumnIndex.set(m_shooterColumnIndex.get() - 1));
|
||||
// D-Pad Down: Select Lower Shooter Row
|
||||
new POVButton(getController(), 180).whenPressed(() -> m_shooterRowIndex.set(0));
|
||||
// D-Pad Up: Select Upper Shooter Row
|
||||
new POVButton(getController(), 0).whenPressed(() -> m_shooterRowIndex.set(1));
|
||||
// D-Pad Left: Select Righter Shooter Column
|
||||
new POVButton(getController(), 90).whenPressed(() -> m_shooterColumnIndex.set(3));
|
||||
// D-Pad Right: Select Lefter Shooter Column
|
||||
new POVButton(getController(), 270).whenPressed(() -> m_shooterColumnIndex.set(0));
|
||||
}
|
||||
|
||||
private void fireShooterWithFeedback() {
|
||||
boolean fired = m_robotShooterRows[m_shooterRowIndex.get()][m_shooterColumnIndex.get()].set(true);
|
||||
RumbleType rumbleType = m_shooterColumnIndex.get() < 2 ? 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();
|
||||
System.out.println(m_shooterRowIndex.get() + ":" + m_shooterColumnIndex.get());
|
||||
}
|
||||
|
||||
private static class NetworkTableInteger {
|
||||
private final NetworkTableEntry m_entry;
|
||||
private final int m_defaultValue;
|
||||
|
||||
public NetworkTableInteger(String name, int defaultValue, int minValue, int maxValue) {
|
||||
m_defaultValue = defaultValue;
|
||||
m_entry = NetworkTableInstance.getDefault().getTable("SmartDashboard").getEntry(name);
|
||||
m_entry.setDouble(m_defaultValue);
|
||||
m_entry.addListener(event -> {
|
||||
if (event.value.isDouble()) {
|
||||
double entryValue = event.value.getDouble();
|
||||
double safeValue = Math.max(minValue, Math.min((int) entryValue, maxValue));
|
||||
if (entryValue != safeValue) event.getEntry().setDouble(safeValue);
|
||||
} else event.getEntry().setDouble(m_defaultValue);
|
||||
}, EntryListenerFlags.kImmediate | EntryListenerFlags.kNew | EntryListenerFlags.kUpdate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
/* Driver Buttons */
|
||||
// test command to spin the robot while pressing A on the driver controller
|
||||
new JoystickButton(getDriverJoystick(), XboxController.A_BUTTON)
|
||||
.whileHeld(() -> m_robotDrive.driveWithInput(0, 1));
|
||||
|
||||
/* Operator Buttons */
|
||||
// activates "Lit Mode"
|
||||
new JoystickButton(getOperatorJoystick(), XboxController.A_BUTTON)
|
||||
.whenPressed(() -> m_robotLED.setPattern(LEDPatterns.LAVA_RAINBOW))
|
||||
.whenReleased(() -> m_robotLED.setPattern(LEDConstants.DEFAULT_PATTERN));
|
||||
public int get() {
|
||||
return (int) m_entry.getDouble(m_defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to pass the autonomous command to the main {@link Robot} class.
|
||||
*
|
||||
* @return the command to run in autonomous
|
||||
*/
|
||||
public Command getAutonomousCommand() {
|
||||
// no auto
|
||||
return new InstantCommand();
|
||||
public void set(int value) {
|
||||
m_entry.setDouble(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add your docs here.
|
||||
*/
|
||||
public IHandController getDriverController() {
|
||||
return m_driverXbox;
|
||||
}
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add your docs here.
|
||||
*/
|
||||
public IHandController getOperatorController() {
|
||||
return m_operatorXbox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add your docs here.
|
||||
*/
|
||||
public Joystick getOperatorJoystick() {
|
||||
return m_operatorXbox.getJoyStick();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add your docs here.
|
||||
*/
|
||||
public Joystick getDriverJoystick() {
|
||||
return m_driverXbox.getJoyStick();
|
||||
}
|
||||
public XboxController getController() {
|
||||
return m_controller;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user