Files
2024AcrossTheRidgebotiverse/src/main/java/frc4388/robot/RobotContainer.java
T

280 lines
13 KiB
Java
Raw Normal View History

2024-01-08 11:38:08 -07:00
/*----------------------------------------------------------------------------*/
/* 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 java.time.Instant;
2024-01-18 17:56:52 -07:00
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
2024-01-08 11:38:08 -07:00
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.ConditionalCommand;
2024-01-08 11:38:08 -07:00
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import edu.wpi.first.wpilibj2.command.WaitUntilCommand;
2024-01-08 11:38:08 -07:00
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import frc4388.robot.Constants.OIConstants;
import frc4388.robot.commands.Autos.PlaybackChooser;
2024-01-08 11:38:08 -07:00
import frc4388.robot.commands.Swerve.JoystickPlayback;
import frc4388.robot.commands.Swerve.JoystickRecorder;
2024-02-13 20:01:12 -07:00
import frc4388.robot.commands.Intake.ArmIntakeIn;
import frc4388.robot.commands.Intake.RotateIntakeToPosition;
2024-01-08 11:38:08 -07:00
import frc4388.robot.subsystems.LED;
2024-02-16 21:49:50 -07:00
import frc4388.robot.subsystems.Limelight;
2024-01-08 13:47:43 -07:00
import frc4388.robot.subsystems.SwerveDrive;
2024-01-20 10:10:17 -07:00
import frc4388.robot.subsystems.Shooter;
import frc4388.robot.subsystems.Intake;
2024-01-08 13:47:43 -07:00
import frc4388.utility.controller.DeadbandedXboxController;
2024-01-08 11:38:08 -07:00
import frc4388.utility.controller.XboxController;
/**
* 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();
/* Subsystems */
2024-02-13 20:01:12 -07:00
private final LED m_robotLED = new LED();
2024-01-08 11:38:08 -07:00
2024-01-08 13:47:43 -07:00
public final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.leftFront,
m_robotMap.rightFront,
m_robotMap.leftBack,
m_robotMap.rightBack,
m_robotMap.gyro);
2024-01-25 19:43:04 -07:00
private final Shooter m_robotShooter = new Shooter(m_robotMap.leftShooter, m_robotMap.rightShooter);
2024-01-26 18:10:29 -07:00
private final Intake m_robotIntake = new Intake(m_robotMap.intakeMotor, m_robotMap.pivotMotor);
2024-01-25 19:43:04 -07:00
//private final Intake m_robotIntake = new Intake(m_robotMap.intakeMotor, m_robotMap.pivotMotor);
2024-01-08 13:47:43 -07:00
2024-01-08 11:38:08 -07:00
/* Controllers */
2024-01-08 13:47:43 -07:00
private final DeadbandedXboxController m_driverXbox = new DeadbandedXboxController(OIConstants.XBOX_DRIVER_ID);
private final DeadbandedXboxController m_operatorXbox = new DeadbandedXboxController(OIConstants.XBOX_OPERATOR_ID);
2024-01-08 11:38:08 -07:00
2024-02-16 21:49:50 -07:00
private Limelight limelight = new Limelight();
2024-02-13 20:01:12 -07:00
private Command intakeToShootStuff = new ArmIntakeIn(m_robotIntake, m_robotShooter);
private SequentialCommandGroup intakeToShoot = new SequentialCommandGroup(
new InstantCommand(() -> m_robotIntake.pidIn()),
2024-02-13 20:01:12 -07:00
new InstantCommand(() -> m_robotShooter.spin())
);
private SequentialCommandGroup outtakeToShootFull = new SequentialCommandGroup(
new InstantCommand(() -> m_robotShooter.spin()),
new InstantCommand(() -> m_robotIntake.handoff())
);
private SequentialCommandGroup intakeInToOut = new SequentialCommandGroup(
2024-02-13 20:01:12 -07:00
new InstantCommand(() -> m_robotIntake.rotateArmOut2(), m_robotIntake),
new RunCommand(() -> m_robotIntake.limitNote(), m_robotIntake).until(m_robotIntake.getArmFowardLimitState()),
2024-02-14 19:44:24 -07:00
new InstantCommand(() -> m_robotShooter.spin(), m_robotShooter)
);
2024-02-13 20:01:12 -07:00
private SequentialCommandGroup i = new SequentialCommandGroup(
intakeToShootStuff, intakeToShoot
);
2024-02-13 20:01:12 -07:00
private SequentialCommandGroup ejectToShoot = new SequentialCommandGroup(
new InstantCommand(() -> m_robotShooter.spin(), m_robotShooter),
new InstantCommand(() -> m_robotIntake.handoff(), m_robotIntake)
);
private SequentialCommandGroup turnOffShoot = new SequentialCommandGroup(
new InstantCommand(() -> m_robotShooter.stop(), m_robotShooter),
new InstantCommand(() -> m_robotIntake.stopIntakeMotors(), m_robotIntake)
);
2024-02-16 21:49:50 -07:00
/* Autos */
private Command taxi = new JoystickPlayback(m_robotSwerveDrive, "Taxi.txt");
private Command startLeftMoveRight = new JoystickPlayback(m_robotSwerveDrive, "StartLeftMoveRight.txt");
private Command startRightMoveLeft = new JoystickPlayback(m_robotSwerveDrive, "StartRightMoveLeft.txt");
2024-02-16 21:49:50 -07:00
private SequentialCommandGroup oneNoteStartingSpeaker = new SequentialCommandGroup (
ejectToShoot,
taxi
);
private SequentialCommandGroup oneNoteStartingFromLeft = new SequentialCommandGroup(
startLeftMoveRight,
ejectToShoot,
taxi
);
private SequentialCommandGroup oneNoteStartingFromRight = new SequentialCommandGroup(
startRightMoveLeft,
ejectToShoot,
taxi
);
private PlaybackChooser playbackChooser = new PlaybackChooser(m_robotSwerveDrive)
2024-02-16 21:49:50 -07:00
.addOption("Taxi Auto", taxi)
.addOption("One Note Auto Starting in Front of Speaker", oneNoteStartingSpeaker)
.addOption("One Note Auto Starting from Left Position", oneNoteStartingFromLeft)
.addOption("One Note Auto Starting from Right Position", oneNoteStartingFromRight)
.buildDisplay();
2024-02-16 21:49:50 -07:00
2024-01-08 11:38:08 -07:00
/**
* 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
2024-01-12 20:29:50 -07:00
m_robotSwerveDrive.setDefaultCommand(new RunCommand(() -> {
m_robotSwerveDrive.driveWithInput(getDeadbandedDriverController().getLeft(),
getDeadbandedDriverController().getRight(),
true);
2024-01-13 15:39:56 -07:00
}, m_robotSwerveDrive)
.withName("SwerveDrive DefaultCommand"));
2024-01-08 11:38:08 -07:00
// continually sends updates to the Blinkin LED controller to keep the lights on
m_robotLED.setDefaultCommand(new RunCommand(() -> m_robotLED.updateLED(), m_robotLED));
2024-02-16 21:49:50 -07:00
// SmartDashboard.putNumber("Velocity Output", m_robotIntake.getVelocity());
// m_robotIntake.resetPostion();
2024-01-08 11:38:08 -07: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() {
/* Driver Buttons */
2024-01-13 15:39:56 -07:00
new JoystickButton(getDeadbandedDriverController(), XboxController.A_BUTTON)
.onTrue(new InstantCommand(() -> m_robotSwerveDrive.resetGyro(), m_robotSwerveDrive));
/* Auto Recording */
// new JoystickButton(getDeadbandedDriverController(), XboxController.RIGHT_BUMPER_BUTTON)
2024-01-22 17:25:37 -07:00
// .whileTrue(new JoystickRecorder(m_robotSwerveDrive,
// () -> getDeadbandedDriverController().getLeftX(),
// () -> getDeadbandedDriverController().getLeftY(),
// () -> getDeadbandedDriverController().getRightX(),
// () -> getDeadbandedDriverController().getRightY(),
// "IntenseTaxi.txt"))
// .onFalse(new InstantCommand());
2024-02-13 20:01:12 -07:00
new JoystickButton(getDeadbandedDriverController(), XboxController.X_BUTTON)
.onTrue(new JoystickPlayback(m_robotSwerveDrive, "Taxi.txt"))
.onFalse(new InstantCommand());
/* Speed */
new JoystickButton(getDeadbandedDriverController(), XboxController.RIGHT_BUMPER_BUTTON) // final
2024-01-22 17:25:37 -07:00
.onTrue(new InstantCommand(() -> m_robotSwerveDrive.shiftUp()));
// .onFalse(new InstantCommand(() -> m_robotSwerveDrive.setToFast()));
new JoystickButton(getDeadbandedDriverController(), XboxController.LEFT_BUMPER_BUTTON) // final
2024-01-22 17:25:37 -07:00
.onTrue(new InstantCommand(() -> m_robotSwerveDrive.shiftDown()));
2024-01-26 18:10:29 -07:00
/* Operator Buttons */
// new JoystickButton(getDeadbandedDriverController(), XboxController.B_BUTTON)
// .onTrue(new InstantCommand(() -> m_robotIntake.spinIntakeMotor(), m_robotIntake))
// .onFalse(new InstantCommand(() -> m_robotIntake.stopIntakeMotors(), m_robotIntake));
// new JoystickButton(getDeadbandedOperatorController(), XboxController.A_BUTTON)
// .onTrue(new InstantCommand(() -> new RotateIntakeToPosition(m_robotIntake, 360).execute(), m_robotIntake))
// .onFalse(new InstantCommand(() -> new RotateIntakeToPosition(m_robotIntake, 0).execute(), m_robotShooter));
2024-02-13 20:01:12 -07:00
new JoystickButton(getDeadbandedOperatorController(), XboxController.Y_BUTTON)
.onTrue(new InstantCommand(() -> m_robotIntake.pidIn()))
.onFalse(new InstantCommand(() -> m_robotIntake.stopArmMotor()));
2024-02-16 21:49:50 -07:00
new JoystickButton(getDeadbandedOperatorController(), XboxController.A_BUTTON)
2024-02-13 20:01:12 -07:00
.onTrue(new InstantCommand(() -> m_robotIntake.pidOut()))
.onFalse(new InstantCommand(() -> m_robotIntake.stopArmMotor()));
2024-02-16 21:49:50 -07:00
// Override Intake Position encoder: out
new JoystickButton(getDeadbandedOperatorController(), XboxController.BACK_BUTTON)
.onTrue(new InstantCommand(() -> m_robotIntake.setPosition(-53), m_robotIntake));
// Override Intake Position encoder: out
new JoystickButton(getDeadbandedOperatorController(), XboxController.START_BUTTON)
.onTrue(new InstantCommand(() -> m_robotIntake.setPosition(0), m_robotIntake));
// //Pull arm in
// new JoystickButton(getDeadbandedOperatorController(), XboxController.RIGHT_BUMPER_BUTTON)
// .onTrue(new InstantCommand(() -> m_robotIntake.pidIn(), m_robotIntake))
// .onFalse(new InstantCommand(() -> m_robotIntake.stopArmMotor(), m_robotIntake));
// //Pull arm out
// new JoystickButton(getDeadbandedOperatorController(), XboxController.LEFT_BUMPER_BUTTON)
// .onTrue(new InstantCommand(() -> m_robotIntake.pidOut(), m_robotIntake))
// .onFalse(new InstantCommand(() -> m_robotIntake.stopArmMotor(), m_robotIntake));
// //Intake Note
// new JoystickButton(getDeadbandedOperatorController(), XboxController.B_BUTTON)
// .onTrue(new InstantCommand(() -> m_robotIntake.spinIntakeMotor(), m_robotIntake))
// .onFalse(new InstantCommand(() -> m_robotIntake.stopIntakeMotors(), m_robotIntake));
// //Outtake Note
// new JoystickButton(getDeadbandedOperatorController(), XboxController.Y_BUTTON)
// .onTrue(new InstantCommand(() -> m_robotIntake.handoff(), m_robotIntake))
// .onFalse(new InstantCommand(() -> m_robotIntake.stopIntakeMotors(), m_robotIntake));
2024-02-13 20:01:12 -07:00
//Spin Shooter Motors
2024-02-16 21:49:50 -07:00
new JoystickButton(getDeadbandedOperatorController(), XboxController.X_BUTTON)
2024-02-13 20:01:12 -07:00
.onTrue(new InstantCommand(() -> m_robotShooter.spin(), m_robotShooter))
.onFalse(new InstantCommand(() -> m_robotShooter.stop(), m_robotShooter));
// //Intake Note and ramp up shooter to 40%
// new JoystickButton(getDeadbandedOperatorController(), XboxController.A_BUTTON)
// .onTrue(intakeToShoot);
// //Ramps up shooter to 100% to Shooter
// new JoystickButton(getDeadbandedOperatorController(), XboxController.B_BUTTON)
// .onTrue(outtakeToShootFull);
new JoystickButton(getDeadbandedOperatorController(), XboxController.LEFT_BUMPER_BUTTON)
2024-02-13 20:01:12 -07:00
.onTrue(ejectToShoot)
.onFalse(turnOffShoot);
new JoystickButton(getDeadbandedOperatorController(), XboxController.RIGHT_BUMPER_BUTTON)
.onTrue(i)
.onFalse(new InstantCommand(() -> m_robotIntake.pidIn()));
2024-01-12 20:29:50 -07:00
2024-01-08 11:38:08 -07:00
}
/**
* Use this to pass the autonomous command to the main {@link Robot} class.
*
* @return the command to run in autonomous
*/
2024-02-13 20:01:12 -07:00
public Command getAutonomousCommand() {
//no auto
return playbackChooser.getCommand();
}
2024-01-08 11:38:08 -07:00
/**
* Add your docs here.
*/
2024-01-08 13:47:43 -07:00
public DeadbandedXboxController getDeadbandedDriverController() {
return this.m_driverXbox;
2024-01-08 11:38:08 -07:00
}
2024-01-08 13:47:43 -07:00
public DeadbandedXboxController getDeadbandedOperatorController() {
return this.m_operatorXbox;
2024-01-08 11:38:08 -07:00
}
}