2022-01-11 11:05:52 -07:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2021-11-15 16:26:16 -07:00
|
|
|
|
|
|
|
|
package frc4388.robot;
|
|
|
|
|
|
2022-02-15 11:05:59 -07:00
|
|
|
import java.util.logging.Logger;
|
2022-01-21 16:50:26 -07:00
|
|
|
|
2022-02-07 19:49:27 -07:00
|
|
|
import com.pathplanner.lib.PathPlannerTrajectory.PathPlannerState;
|
2022-02-04 19:02:41 -07:00
|
|
|
import com.pathplanner.lib.commands.PPSwerveControllerCommand;
|
|
|
|
|
|
2022-01-29 14:39:46 -07:00
|
|
|
import edu.wpi.first.math.controller.PIDController;
|
|
|
|
|
import edu.wpi.first.math.controller.ProfiledPIDController;
|
2022-01-22 15:55:04 -07:00
|
|
|
import edu.wpi.first.math.geometry.Pose2d;
|
2022-01-29 14:39:46 -07:00
|
|
|
import edu.wpi.first.math.geometry.Rotation2d;
|
2022-02-11 18:53:13 -07:00
|
|
|
import edu.wpi.first.wpilibj.GenericHID;
|
2022-01-29 01:16:58 -07:00
|
|
|
import edu.wpi.first.wpilibj.XboxController;
|
2022-02-16 22:31:00 -07:00
|
|
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
2021-11-15 16:26:16 -07:00
|
|
|
import edu.wpi.first.wpilibj2.command.Command;
|
2022-02-03 20:53:43 -07:00
|
|
|
import edu.wpi.first.wpilibj2.command.InstantCommand;
|
2021-11-15 16:26:16 -07:00
|
|
|
import edu.wpi.first.wpilibj2.command.RunCommand;
|
2022-02-03 20:53:43 -07:00
|
|
|
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
|
2021-11-15 16:26:16 -07:00
|
|
|
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
|
2022-02-11 18:53:13 -07:00
|
|
|
import frc4388.robot.Constants.OIConstants;
|
2022-03-05 22:57:55 -07:00
|
|
|
import frc4388.robot.Constants.StorageConstants;
|
2022-02-11 18:59:00 -07:00
|
|
|
import frc4388.robot.Constants.SwerveDriveConstants;
|
2022-03-08 16:31:42 -07:00
|
|
|
import frc4388.robot.commands.PathRecorder;
|
2022-01-20 18:08:05 -07:00
|
|
|
import frc4388.robot.subsystems.BoomBoom;
|
|
|
|
|
import frc4388.robot.subsystems.Hood;
|
2022-03-05 15:32:48 -07:00
|
|
|
import frc4388.robot.subsystems.Intake;
|
2022-01-15 14:20:49 -07:00
|
|
|
import frc4388.robot.subsystems.Serializer;
|
2022-02-26 15:41:54 -07:00
|
|
|
import frc4388.robot.subsystems.Storage;
|
2021-12-02 17:51:06 -07:00
|
|
|
import frc4388.robot.subsystems.SwerveDrive;
|
2022-01-20 18:08:05 -07:00
|
|
|
import frc4388.robot.subsystems.Turret;
|
2022-01-29 01:16:58 -07:00
|
|
|
import frc4388.utility.controller.DeadbandedXboxController;
|
2021-11-15 16:26:16 -07: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.
|
|
|
|
|
*/
|
|
|
|
|
public class RobotContainer {
|
2022-02-25 01:33:32 -07:00
|
|
|
private static final Logger LOGGER = Logger.getLogger(RobotContainer.class.getSimpleName());
|
2022-01-11 11:05:52 -07:00
|
|
|
/* RobotMap */
|
2022-03-07 15:26:05 -07:00
|
|
|
public final RobotMap m_robotMap = new RobotMap();
|
2022-01-11 11:05:52 -07:00
|
|
|
|
2022-03-11 23:25:05 -07:00
|
|
|
/* Subsystems */
|
2022-03-05 15:32:48 -07:00
|
|
|
public final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.leftFront, m_robotMap.leftBack, m_robotMap.rightFront, m_robotMap.rightBack, m_robotMap.gyro);
|
2022-03-07 15:26:05 -07:00
|
|
|
public final Serializer m_robotSerializer = new Serializer(m_robotMap.serializerBelt, /*m_robotMap.serializerShooterBelt,*/ m_robotMap.serializerBeam);
|
|
|
|
|
public final Intake m_robotIntake = new Intake(m_robotMap.intakeMotor, m_robotMap.extenderMotor, m_robotSerializer);
|
|
|
|
|
public final Storage m_robotStorage = new Storage(m_robotMap.storageMotor);
|
2022-03-06 11:14:30 -07:00
|
|
|
// private final LED m_robotLED = new LED(m_robotMap.LEDController);
|
2022-03-07 15:26:05 -07:00
|
|
|
public final BoomBoom m_robotBoomBoom = new BoomBoom(m_robotMap.shooterFalconLeft, m_robotMap.shooterFalconRight);
|
|
|
|
|
public final Hood m_robotHood = new Hood(m_robotMap.angleAdjusterMotor);
|
|
|
|
|
public final Turret m_robotTurret = new Turret(m_robotMap.shooterTurret);
|
2022-03-06 18:14:49 -07:00
|
|
|
// private final VisionOdometry m_robotVisionOdometry = new VisionOdometry(m_robotSwerveDrive, m_robotTurret);*/
|
2022-03-06 00:24:47 -07:00
|
|
|
|
2022-01-11 11:05:52 -07:00
|
|
|
/* Controllers */
|
2022-01-29 01:16:58 -07:00
|
|
|
private final XboxController m_driverXbox = new DeadbandedXboxController(OIConstants.XBOX_DRIVER_ID);
|
|
|
|
|
private final XboxController m_operatorXbox = new DeadbandedXboxController(OIConstants.XBOX_OPERATOR_ID);
|
2022-01-11 11:05:52 -07:00
|
|
|
|
2022-03-01 20:23:01 -07:00
|
|
|
/* Autonomous */
|
2022-03-08 16:31:42 -07:00
|
|
|
private final PathRecorder m_pathChooser = new PathRecorder(m_robotSwerveDrive);
|
2022-02-16 22:31:00 -07:00
|
|
|
|
2022-01-11 11:05:52 -07:00
|
|
|
/**
|
|
|
|
|
* The container for the robot. Contains subsystems, OI devices, and commands.
|
|
|
|
|
*/
|
|
|
|
|
public RobotContainer() {
|
|
|
|
|
configureButtonBindings();
|
|
|
|
|
/* Default Commands */
|
2022-03-05 11:12:33 -07:00
|
|
|
|
2022-03-06 00:48:38 -07:00
|
|
|
// Swerve Drive with Input
|
2022-03-07 15:26:05 -07:00
|
|
|
m_robotSwerveDrive.setDefaultCommand(
|
2022-01-15 11:31:15 -07:00
|
|
|
new RunCommand(() -> m_robotSwerveDrive.driveWithInput(
|
2022-02-11 18:53:13 -07:00
|
|
|
getDriverController().getLeftX(),
|
|
|
|
|
getDriverController().getLeftY(),
|
2022-03-07 15:26:05 -07:00
|
|
|
//getDriverController().getRightX(),
|
2022-02-11 18:53:13 -07:00
|
|
|
getDriverController().getRightX(),
|
2022-03-07 15:26:05 -07:00
|
|
|
getDriverController().getRightY(),
|
2022-02-11 18:53:13 -07:00
|
|
|
true),
|
2022-03-07 15:26:05 -07:00
|
|
|
m_robotSwerveDrive).withName("Swerve driveWithInput defaultCommand"));
|
2022-03-06 00:48:38 -07:00
|
|
|
// Intake with Triggers
|
2022-03-05 22:57:55 -07:00
|
|
|
m_robotIntake.setDefaultCommand(
|
|
|
|
|
new RunCommand(() -> m_robotIntake.runWithTriggers(
|
2022-03-07 15:26:05 -07:00
|
|
|
getOperatorController().getLeftTriggerAxis(),
|
|
|
|
|
getOperatorController().getRightTriggerAxis()),
|
2022-03-05 22:57:55 -07:00
|
|
|
m_robotIntake).withName("Intake runWithTriggers defaultCommand"));
|
2022-03-06 00:48:38 -07:00
|
|
|
// Storage Management
|
2022-03-06 11:14:30 -07:00
|
|
|
/*m_robotStorage.setDefaultCommand(
|
2022-03-05 22:57:55 -07:00
|
|
|
new RunCommand(() -> m_robotStorage.manageStorage(),
|
2022-03-06 11:14:30 -07:00
|
|
|
m_robotStorage).withName("Storage manageStorage defaultCommand"));*/
|
2022-03-06 00:48:38 -07:00
|
|
|
// Serializer Management
|
2022-03-07 15:26:05 -07:00
|
|
|
// m_robotSerializer.setDefaultCommand(
|
|
|
|
|
// new RunCommand(() -> m_robotSerializer.setSerializer(0.8),//m_robotSerializer.setSerializerStateWithBeam(),
|
|
|
|
|
// m_robotSerializer).withName("Serializer setSerializerStateWithBeam defaultCommand"));
|
2022-03-06 00:48:38 -07:00
|
|
|
// Turret Manual
|
2022-03-06 18:14:49 -07:00
|
|
|
m_robotTurret.setDefaultCommand(
|
2022-03-07 15:26:05 -07:00
|
|
|
new RunCommand(() -> m_robotTurret.runTurretWithInput(getOperatorController().getLeftX()),
|
2022-03-06 18:14:49 -07:00
|
|
|
m_robotTurret).withName("Turret runTurretWithInput defaultCommand"));
|
|
|
|
|
m_robotHood.setDefaultCommand(
|
|
|
|
|
new RunCommand(() -> m_robotHood.runHood(getOperatorController().getRightY() * 0.1), m_robotHood));
|
2022-03-06 00:48:38 -07:00
|
|
|
// m_robotTurret.setDefaultCommand(
|
|
|
|
|
// new AimToCenter(m_robotTurret, m_robotSwerveDrive, m_robotVisionOdometry));
|
2022-01-11 11:05:52 -07:00
|
|
|
|
|
|
|
|
// continually sends updates to the Blinkin LED controller to keep the lights on
|
2022-03-08 16:31:42 -07:00
|
|
|
|
|
|
|
|
// m_robotLED.setDefaultCommand(new RunCommand(m_robotLED::updateLED, m_robotLED).withName("LED update defaultCommand"));
|
|
|
|
|
// Creates a button on the SmartDashboard that will record the path of the robot.
|
|
|
|
|
SmartDashboard.putData("Path Recording", m_pathChooser);
|
2022-01-11 11:05:52 -07:00
|
|
|
}
|
2022-01-15 11:31:15 -07:00
|
|
|
|
2022-01-11 11:05:52 -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() {
|
2022-03-11 23:25:05 -07:00
|
|
|
for (XboxController.Button binding : XboxController.Button.values()) {
|
|
|
|
|
/* ------------------------------------ Driver ------------------------------------ */
|
|
|
|
|
JoystickButton button = new JoystickButton(getDriverController(), binding.value);
|
|
|
|
|
if (binding == XboxController.Button.kLeftBumper)
|
|
|
|
|
/* Left Bumper > Shift Down */ button.whenPressed(() -> m_robotSwerveDrive.highSpeed(false));
|
|
|
|
|
else if (binding == XboxController.Button.kRightBumper)
|
|
|
|
|
/* Right Bumper > Shift Up */ button.whenPressed(() -> m_robotSwerveDrive.highSpeed(true));
|
|
|
|
|
else if (binding == XboxController.Button.kLeftStick)
|
|
|
|
|
/* Left Stick > Unbound */ {/* No Commands */}
|
|
|
|
|
else if (binding == XboxController.Button.kRightStick)
|
|
|
|
|
/* Right Stick > Unbound */ {/* No Commands */}
|
|
|
|
|
else if (binding == XboxController.Button.kA)
|
|
|
|
|
/* A > Unbound */ {/* No Commands */}
|
|
|
|
|
else if (binding == XboxController.Button.kB)
|
|
|
|
|
/* B > Unbound */ {/* No Commands */}
|
|
|
|
|
else if (binding == XboxController.Button.kX)
|
|
|
|
|
/* X > TEMP */ button.whenPressed(() -> {
|
|
|
|
|
m_robotMap.leftFront.reset();
|
|
|
|
|
m_robotMap.rightFront.reset();
|
|
|
|
|
m_robotMap.leftBack.reset();
|
|
|
|
|
m_robotMap.rightBack.reset();
|
|
|
|
|
});
|
|
|
|
|
else if (binding == XboxController.Button.kY)
|
|
|
|
|
/* Y > Unbound */ {/* No Commands */}
|
|
|
|
|
else if (binding == XboxController.Button.kBack)
|
|
|
|
|
/* Start > Reset Odometry */ button.whenPressed(() -> resetOdometry(new Pose2d(0, 0, new Rotation2d(0))));
|
|
|
|
|
else if (binding == XboxController.Button.kStart)
|
|
|
|
|
/* Start > Reset Gyro */ button.whenPressed(m_robotSwerveDrive::resetGyro);
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------ Operator ------------------------------------ */
|
|
|
|
|
button = new JoystickButton(getDriverController(), binding.value);
|
|
|
|
|
if (binding == XboxController.Button.kLeftBumper)
|
|
|
|
|
/* Left Bumper > Storage Out */ button
|
|
|
|
|
.whileHeld(() -> m_robotStorage.runStorage(-StorageConstants.STORAGE_SPEED), m_robotStorage)
|
|
|
|
|
.whenReleased(() -> m_robotStorage.runStorage(0.0), m_robotStorage);
|
|
|
|
|
else if (binding == XboxController.Button.kRightBumper)
|
|
|
|
|
/* Right Bumper > Storage In */ button
|
|
|
|
|
.whileHeld(() -> m_robotStorage.runStorage(StorageConstants.STORAGE_SPEED), m_robotStorage)
|
|
|
|
|
.whenReleased(() -> m_robotStorage.runStorage(0.0), m_robotStorage);
|
|
|
|
|
else if (binding == XboxController.Button.kLeftStick)
|
|
|
|
|
/* Left Stick > Unbound */ {/* No Commands */}
|
|
|
|
|
else if (binding == XboxController.Button.kRightStick)
|
|
|
|
|
/* Right Stick > Unbound */ {/* No Commands */}
|
|
|
|
|
else if (binding == XboxController.Button.kA)
|
|
|
|
|
// /* A > Shoot with Odo */ // button.whenPressed(new Shoot(m_robotSwerveDrive, m_robotBoomBoom, m_robotTurret, m_robotHood))
|
|
|
|
|
/* A > Unbound */ {/* No Commands */}
|
|
|
|
|
else if (binding == XboxController.Button.kB)
|
|
|
|
|
// /* B > Shoot with Lime */ // button.whenPressed(new TrackTarget(m_robotTurret, m_robotBoomBoom, m_robotHood, m_robotSwerveDrive, m_robotVisionOdometry))
|
|
|
|
|
/* B > Reset Hood*/
|
|
|
|
|
button.whenPressed(new InstantCommand(() -> m_robotHood.m_angleEncoder.setPosition(0)));
|
|
|
|
|
else if (binding == XboxController.Button.kX)
|
|
|
|
|
// /* X > Extend Intake */ // button.whenPressed(() -> m_robotIntake.runExtender(true))
|
|
|
|
|
/* X > Run Shooter */ button
|
|
|
|
|
.whileHeld(() -> m_robotBoomBoom.runDrumShooter(0.3))
|
|
|
|
|
.whenReleased(() -> m_robotBoomBoom.runDrumShooter(0.0));
|
|
|
|
|
else if (binding == XboxController.Button.kY)
|
|
|
|
|
// /* Y > Retract Intake */ // operatorButton.whenPressed(() -> m_robotIntake.runExtender(false))
|
|
|
|
|
/* Y > Unbound */ {/* No Commands */}
|
|
|
|
|
else if (binding == XboxController.Button.kBack)
|
|
|
|
|
/* Back > Unbound */ {/* No Commands */}
|
|
|
|
|
else if (binding == XboxController.Button.kStart)
|
|
|
|
|
/* Start > Unbound */ {/* No Commands */}
|
|
|
|
|
}
|
2022-01-11 11:05:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Use this to pass the autonomous command to the main {@link Robot} class.
|
|
|
|
|
*
|
|
|
|
|
* @return the command to run in autonomous
|
|
|
|
|
*/
|
2022-02-16 22:31:00 -07:00
|
|
|
public Command getAutonomousCommand() {
|
2022-03-08 16:31:42 -07:00
|
|
|
if (m_pathChooser.getPath() != null) {
|
2022-02-16 22:31:00 -07:00
|
|
|
PIDController xController = SwerveDriveConstants.X_CONTROLLER;
|
|
|
|
|
PIDController yController = SwerveDriveConstants.Y_CONTROLLER;
|
|
|
|
|
ProfiledPIDController thetaController = SwerveDriveConstants.THETA_CONTROLLER;
|
|
|
|
|
thetaController.enableContinuousInput(-Math.PI, Math.PI);
|
|
|
|
|
|
2022-03-08 16:31:42 -07:00
|
|
|
PathPlannerState initialState = m_pathChooser.getPath().getInitialState();
|
2022-02-16 22:31:00 -07:00
|
|
|
Pose2d initialPosition = new Pose2d(initialState.poseMeters.getTranslation(), initialState.holonomicRotation);
|
|
|
|
|
return new SequentialCommandGroup(
|
|
|
|
|
new InstantCommand(m_robotSwerveDrive.m_gyro::reset),
|
|
|
|
|
new InstantCommand(() -> m_robotSwerveDrive.resetOdometry(initialPosition)),
|
2022-03-08 16:31:42 -07:00
|
|
|
new PPSwerveControllerCommand(m_pathChooser.getPath(), m_robotSwerveDrive::getOdometry,
|
2022-02-16 22:31:00 -07:00
|
|
|
m_robotSwerveDrive.m_kinematics, xController, yController, thetaController,
|
|
|
|
|
m_robotSwerveDrive::setModuleStates, m_robotSwerveDrive),
|
|
|
|
|
new InstantCommand(m_robotSwerveDrive::stopModules)).withName("Run Autonomous Path");
|
|
|
|
|
} else {
|
2022-02-25 01:33:32 -07:00
|
|
|
LOGGER.severe("No auto selected.");
|
2022-03-05 11:12:33 -07:00
|
|
|
return new RunCommand(() -> {
|
|
|
|
|
}).withName("No Autonomous Path");
|
2022-02-15 11:05:59 -07:00
|
|
|
}
|
2022-01-11 11:05:52 -07:00
|
|
|
}
|
|
|
|
|
|
2022-01-29 01:16:58 -07:00
|
|
|
public XboxController getDriverController() {
|
2022-01-11 11:05:52 -07:00
|
|
|
return m_driverXbox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-02-17 19:52:05 -07:00
|
|
|
* Get odometry.
|
2022-03-05 11:12:33 -07:00
|
|
|
*
|
2022-02-17 19:52:05 -07:00
|
|
|
* @return Odometry
|
2022-01-11 11:05:52 -07:00
|
|
|
*/
|
2022-01-22 15:55:04 -07:00
|
|
|
public Pose2d getOdometry() {
|
|
|
|
|
return m_robotSwerveDrive.getOdometry();
|
|
|
|
|
}
|
2022-01-24 17:00:06 -07:00
|
|
|
|
2022-01-11 11:05:52 -07:00
|
|
|
/**
|
2022-02-17 19:52:05 -07:00
|
|
|
* Set odometry to given pose.
|
2022-03-05 11:12:33 -07:00
|
|
|
*
|
2022-02-17 19:52:05 -07:00
|
|
|
* @param pose Pose to set odometry to.
|
2022-01-11 11:05:52 -07:00
|
|
|
*/
|
2022-02-05 11:50:49 -07:00
|
|
|
public void resetOdometry(Pose2d pose) {
|
2022-01-29 14:39:46 -07:00
|
|
|
m_robotSwerveDrive.resetOdometry(pose);
|
2022-01-24 17:00:06 -07:00
|
|
|
}
|
2022-02-11 18:53:13 -07:00
|
|
|
|
2022-01-29 01:16:58 -07:00
|
|
|
public XboxController getOperatorController() {
|
2022-01-11 11:05:52 -07:00
|
|
|
return m_operatorXbox;
|
|
|
|
|
}
|
2021-11-15 16:26:16 -07:00
|
|
|
}
|