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-04-19 20:36:59 -06:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
2022-02-15 11:05:59 -07:00
|
|
|
import java.util.logging.Logger;
|
2022-01-21 16:50:26 -07:00
|
|
|
|
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-04-19 20:36:59 -06:00
|
|
|
import edu.wpi.first.networktables.NTSendable;
|
|
|
|
|
import edu.wpi.first.networktables.NTSendableBuilder;
|
|
|
|
|
import edu.wpi.first.networktables.NetworkTable;
|
|
|
|
|
import edu.wpi.first.networktables.NetworkTableEntry;
|
|
|
|
|
import edu.wpi.first.networktables.NetworkTableInstance;
|
|
|
|
|
import edu.wpi.first.util.sendable.Sendable;
|
|
|
|
|
import edu.wpi.first.util.sendable.SendableBuilder;
|
|
|
|
|
import edu.wpi.first.util.sendable.SendableRegistry;
|
|
|
|
|
import edu.wpi.first.wpilibj.DriverStation;
|
2022-02-11 18:53:13 -07:00
|
|
|
import edu.wpi.first.wpilibj.GenericHID;
|
2022-04-19 20:36:59 -06:00
|
|
|
import edu.wpi.first.wpilibj.PowerDistribution;
|
2022-01-29 01:16:58 -07:00
|
|
|
import edu.wpi.first.wpilibj.XboxController;
|
2022-04-19 20:36:59 -06:00
|
|
|
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl;
|
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-04-20 02:39:30 -06:00
|
|
|
import edu.wpi.first.wpilibj2.command.PrintCommand;
|
2021-11-15 16:26:16 -07:00
|
|
|
import edu.wpi.first.wpilibj2.command.RunCommand;
|
|
|
|
|
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
|
2022-04-20 02:39:30 -06:00
|
|
|
import edu.wpi.first.wpilibj2.command.button.POVButton;
|
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-04-20 02:39:30 -06:00
|
|
|
import frc4388.robot.commands.AutonomousBuilder;
|
2022-03-08 16:31:42 -07:00
|
|
|
import frc4388.robot.commands.PathRecorder;
|
2022-03-14 20:10:12 -06:00
|
|
|
import frc4388.robot.commands.ExtenderIntakeCommands.ExtenderIntakeGroup;
|
2022-04-17 01:15:33 -06:00
|
|
|
import frc4388.robot.commands.shooter.TrackTarget;
|
2022-04-06 13:22:15 -06:00
|
|
|
import frc4388.robot.commands.shuffleboard.CommandSchedule;
|
2022-04-07 22:18:01 -06:00
|
|
|
import frc4388.robot.commands.shuffleboard.ShooterTuner;
|
2022-01-20 18:08:05 -07:00
|
|
|
import frc4388.robot.subsystems.BoomBoom;
|
2022-03-25 09:15:02 -06:00
|
|
|
import frc4388.robot.subsystems.Camera;
|
2022-03-22 17:41:02 -06:00
|
|
|
import frc4388.robot.subsystems.Claws;
|
2022-03-10 16:47:32 -07:00
|
|
|
import frc4388.robot.subsystems.Climber;
|
2022-03-12 15:05:32 -07:00
|
|
|
import frc4388.robot.subsystems.Extender;
|
2022-01-20 18:08:05 -07:00
|
|
|
import frc4388.robot.subsystems.Hood;
|
2022-03-05 15:32:48 -07:00
|
|
|
import frc4388.robot.subsystems.Intake;
|
2022-04-07 11:35:07 -06:00
|
|
|
import frc4388.robot.subsystems.LED;
|
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-03-05 11:29:40 -07:00
|
|
|
import frc4388.robot.subsystems.VisionOdometry;
|
2022-03-12 17:33:38 -07:00
|
|
|
import frc4388.utility.controller.ButtonBox;
|
2022-03-22 19:48:40 -06:00
|
|
|
import frc4388.utility.controller.DeadbandedXboxController;
|
2022-04-20 02:39:30 -06:00
|
|
|
import frc4388.utility.controller.XboxControllerPOV;
|
2022-04-19 20:36:59 -06:00
|
|
|
import frc4388.utility.shuffleboard.CachingSendableChooser;
|
2021-11-15 16:26:16 -07:00
|
|
|
|
|
|
|
|
/**
|
2022-04-17 01:15:33 -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.
|
2021-11-15 16:26:16 -07:00
|
|
|
*/
|
|
|
|
|
public class RobotContainer {
|
2022-04-17 01:15:33 -06:00
|
|
|
/* Robot Map */
|
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-04-17 01:15:33 -06:00
|
|
|
public final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.frontLeft, m_robotMap.frontRight, m_robotMap.backLeft, m_robotMap.backRight, m_robotMap.gyro);
|
2022-03-12 15:05:32 -07:00
|
|
|
public final Extender m_robotExtender = new Extender(m_robotMap.extenderMotor);
|
2022-04-20 02:39:30 -06:00
|
|
|
public final Intake m_robotIntake = new Intake(m_robotMap.intakeMotor);
|
|
|
|
|
public final Serializer m_robotSerializer = new Serializer(m_robotMap.serializerBelt);
|
2022-03-07 15:26:05 -07:00
|
|
|
public final Storage m_robotStorage = new Storage(m_robotMap.storageMotor);
|
|
|
|
|
public final BoomBoom m_robotBoomBoom = new BoomBoom(m_robotMap.shooterFalconLeft, m_robotMap.shooterFalconRight);
|
|
|
|
|
public final Turret m_robotTurret = new Turret(m_robotMap.shooterTurret);
|
2022-04-20 02:39:30 -06:00
|
|
|
public final Hood m_robotHood = new Hood(m_robotMap.angleAdjusterMotor);
|
|
|
|
|
public final Claws m_robotClaws = new Claws(m_robotMap.leftClaw, m_robotMap.rightClaw);
|
|
|
|
|
public final Climber m_robotClimber = new Climber(m_robotMap.elbow);
|
|
|
|
|
public final LED m_robotLED = new LED(m_robotMap.LEDController);
|
|
|
|
|
public final Camera m_robotCamera = new Camera("driver", 0, 160, 120, 40);
|
2022-03-13 19:59:55 -06:00
|
|
|
public final VisionOdometry m_robotVisionOdometry = new VisionOdometry(m_robotSwerveDrive, m_robotTurret);
|
2022-01-11 11:05:52 -07:00
|
|
|
|
2022-04-17 01:15:33 -06:00
|
|
|
/* Dashboard Tools */
|
2022-04-19 20:36:59 -06:00
|
|
|
private final CachingSendableChooser<Command> m_autoChooser = new CachingSendableChooser<>();
|
|
|
|
|
private final PathRecorder m_pathRecorder = new PathRecorder(m_robotSwerveDrive, m_autoChooser);
|
2022-03-25 08:32:58 -06:00
|
|
|
private final ShooterTuner m_shooterTuner = new ShooterTuner(m_robotBoomBoom);
|
2022-04-07 16:35:07 -06:00
|
|
|
private final CommandSchedule m_commandSchedule = new CommandSchedule(10, 5, false);
|
2022-04-17 01:15:33 -06:00
|
|
|
|
|
|
|
|
/* Controllers */
|
|
|
|
|
private final DeadbandedXboxController m_driverXbox = new DeadbandedXboxController(OIConstants.XBOX_DRIVER_ID);
|
|
|
|
|
private final DeadbandedXboxController m_operatorXbox = new DeadbandedXboxController(OIConstants.XBOX_OPERATOR_ID);
|
2022-03-12 19:02:37 -07:00
|
|
|
private final ButtonBox m_buttonBox = new ButtonBox(OIConstants.BUTTON_BOX_ID);
|
2022-03-18 17:18:39 -06:00
|
|
|
|
2022-04-20 02:39:30 -06:00
|
|
|
private boolean isClimberControlMode = false;
|
|
|
|
|
private boolean driveControlEnabled = true;
|
2022-03-18 17:18:39 -06:00
|
|
|
|
2022-01-11 11:05:52 -07:00
|
|
|
/**
|
|
|
|
|
* The container for the robot. Contains subsystems, OI devices, and commands.
|
|
|
|
|
*/
|
|
|
|
|
public RobotContainer() {
|
2022-04-20 02:39:30 -06:00
|
|
|
configureButtonBindings();
|
2022-04-19 20:36:59 -06:00
|
|
|
|
2022-04-20 02:39:30 -06:00
|
|
|
configureDefaultCommands();
|
2022-04-19 20:36:59 -06:00
|
|
|
|
2022-04-20 02:39:30 -06:00
|
|
|
AutonomousBuilder autoBuilder = new AutonomousBuilder(this);
|
|
|
|
|
m_autoChooser.addOption("OneBall", autoBuilder::buildOneBallCommand);
|
|
|
|
|
m_autoChooser.addOption("TwoBall", autoBuilder::buildTwoBallCommand);
|
|
|
|
|
m_autoChooser.setDefaultOption("ThreeBall", autoBuilder::buildThreeBallCommand);
|
2022-04-19 20:36:59 -06:00
|
|
|
|
2022-04-20 02:39:30 -06:00
|
|
|
SmartDashboard.putData("Autonomous", m_autoChooser);
|
|
|
|
|
SmartDashboard.putData("Path Recorder", m_pathRecorder);
|
|
|
|
|
SmartDashboard.putData("Shooter Tuner", m_shooterTuner);
|
|
|
|
|
SmartDashboard.putData("Command Schedule", m_commandSchedule);
|
2022-04-19 20:36:59 -06:00
|
|
|
|
2022-04-20 02:39:30 -06:00
|
|
|
putRobotDashboardData();
|
|
|
|
|
}
|
2022-04-19 20:36:59 -06:00
|
|
|
|
2022-04-20 02:39:30 -06:00
|
|
|
/* Default Commands */
|
|
|
|
|
private void configureDefaultCommands() {
|
2022-04-04 13:37:20 -06:00
|
|
|
// Swerve Drive with Input
|
2022-04-17 01:15:33 -06:00
|
|
|
m_robotSwerveDrive.setDefaultCommand(new RunCommand(() -> {
|
2022-04-20 02:39:30 -06:00
|
|
|
if (driveControlEnabled) {
|
2022-04-17 01:15:33 -06:00
|
|
|
m_robotSwerveDrive.driveWithInput(getDriverController().getLeft(), getDriverController().getRight(), true);
|
2022-04-20 02:39:30 -06:00
|
|
|
} else {
|
2022-04-17 01:15:33 -06:00
|
|
|
m_robotSwerveDrive.driveWithInput(0, 0, 0, 0, false);
|
|
|
|
|
}
|
|
|
|
|
}, m_robotSwerveDrive).withName("SwerveDrive DefaultCommand"));
|
2022-04-04 13:37:20 -06:00
|
|
|
|
|
|
|
|
// Intake with Triggers
|
2022-04-17 01:15:33 -06:00
|
|
|
m_robotIntake.setDefaultCommand(new RunCommand(() -> m_robotIntake.runWithTriggers(getOperatorController().getLeftTriggerAxis(), getOperatorController().getRightTriggerAxis()), m_robotIntake).withName("Intake DefaultCommand"));
|
|
|
|
|
|
2022-04-20 02:39:30 -06:00
|
|
|
// Shooter Idle
|
2022-04-17 01:15:33 -06:00
|
|
|
m_robotBoomBoom.setDefaultCommand(new RunCommand(() -> m_robotBoomBoom.runDrumShooter(0.45), m_robotBoomBoom).withName("BoomBoom DefaultCommand"));
|
|
|
|
|
|
|
|
|
|
// Serializer Manual
|
|
|
|
|
m_robotSerializer.setDefaultCommand(new RunCommand(() -> m_robotSerializer.setSerializer(getOperatorController().getLeftTriggerAxis() * 0.8), m_robotSerializer).withName("Serializer DefaultCommand"));
|
|
|
|
|
|
|
|
|
|
// Turret Manual
|
|
|
|
|
m_robotTurret.setDefaultCommand(new RunCommand(() -> {
|
2022-04-20 02:39:30 -06:00
|
|
|
if (!isClimberControlMode) {
|
2022-04-17 01:15:33 -06:00
|
|
|
m_robotTurret.runTurretWithInput(getOperatorController().getLeftX());
|
2022-04-20 02:39:30 -06:00
|
|
|
} else {
|
2022-04-17 01:15:33 -06:00
|
|
|
m_robotTurret.runTurretWithInput(0);
|
|
|
|
|
}
|
2022-04-20 02:39:30 -06:00
|
|
|
}, m_robotTurret).withName("Turret DefaultCommand"));
|
2022-04-17 01:15:33 -06:00
|
|
|
|
|
|
|
|
// Hood Manual
|
|
|
|
|
m_robotHood.setDefaultCommand(new RunCommand(() -> {
|
2022-04-20 02:39:30 -06:00
|
|
|
if (!isClimberControlMode) {
|
2022-04-17 01:15:33 -06:00
|
|
|
m_robotHood.runHood(getOperatorController().getLeftY());
|
2022-04-20 02:39:30 -06:00
|
|
|
} else {
|
2022-04-17 01:15:33 -06:00
|
|
|
m_robotHood.runHood(0);
|
|
|
|
|
}
|
2022-04-20 02:39:30 -06:00
|
|
|
}, m_robotHood).withName("Hood DefaultCommand"));
|
2022-04-17 01:15:33 -06:00
|
|
|
|
|
|
|
|
// Climber Manual
|
|
|
|
|
m_robotClimber.setDefaultCommand(new RunCommand(() -> {
|
2022-04-20 02:39:30 -06:00
|
|
|
if (!isClimberControlMode) {
|
2022-04-17 01:15:33 -06:00
|
|
|
m_robotClimber.setMotors(0.0);
|
2022-04-20 02:39:30 -06:00
|
|
|
} else {
|
2022-04-17 01:15:33 -06:00
|
|
|
m_robotClimber.setMotors(-getOperatorController().getRightY());
|
|
|
|
|
}
|
2022-04-20 02:39:30 -06:00
|
|
|
}, m_robotClimber).withName("Climber DefaultCommand"));
|
2022-01-11 11:05:52 -07:00
|
|
|
}
|
2022-01-15 11:31:15 -07:00
|
|
|
|
2022-01-11 11:05:52 -07:00
|
|
|
/**
|
2022-04-17 01:15:33 -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}.
|
2022-01-11 11:05:52 -07:00
|
|
|
*/
|
|
|
|
|
private void configureButtonBindings() {
|
2022-04-20 02:39:30 -06:00
|
|
|
configureDriverButtonBindings();
|
|
|
|
|
configureOperatorButtonBindings();
|
|
|
|
|
configureBoxButtonBindings();
|
|
|
|
|
}
|
2022-04-07 15:13:24 -06:00
|
|
|
|
2022-04-20 02:39:30 -06:00
|
|
|
private void configureDriverButtonBindings() {
|
|
|
|
|
// Iterate over and assign commands to all Xbox controller buttons.
|
|
|
|
|
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(false));
|
|
|
|
|
} else if (binding == XboxController.Button.kLeftStick) {
|
|
|
|
|
/* Left Stick > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
} else if (binding == XboxController.Button.kRightStick) {
|
|
|
|
|
/* Right Stick > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
} else if (binding == XboxController.Button.kA) {
|
|
|
|
|
/* A > Unbound */
|
|
|
|
|
button.whenPressed(this::switchControlMode);
|
|
|
|
|
button.whenReleased(this::switchControlMode);
|
|
|
|
|
} else if (binding == XboxController.Button.kB) {
|
|
|
|
|
/* B > Unbound */
|
|
|
|
|
button.whenPressed(this::switchDriveMode);
|
|
|
|
|
button.whenReleased(this::switchDriveMode);
|
|
|
|
|
} else if (binding == XboxController.Button.kX) {
|
|
|
|
|
/* X > Unbound */
|
|
|
|
|
button.whileHeld(new RunCommand(() -> m_robotExtender.runExtender(1.0), m_robotExtender));
|
|
|
|
|
button.whenReleased(new RunCommand(() -> m_robotExtender.runExtender(0.0), m_robotExtender));
|
|
|
|
|
} else if (binding == XboxController.Button.kY) {
|
|
|
|
|
/* Y > Unbound */
|
|
|
|
|
button.whileHeld(new RunCommand(() -> m_robotExtender.runExtender(-1.0), m_robotExtender));
|
|
|
|
|
button.whenReleased(new RunCommand(() -> m_robotExtender.runExtender(0.0), m_robotExtender));
|
|
|
|
|
} else if (binding == XboxController.Button.kBack) {
|
|
|
|
|
/* Back > Calibrate Odometry */
|
|
|
|
|
button.whenPressed(() -> resetOdometry(new Pose2d(0, 0, new Rotation2d(0))));
|
|
|
|
|
} else if (binding == XboxController.Button.kStart) {
|
|
|
|
|
/* Start > Calibrate Odometry */
|
|
|
|
|
button.whenPressed(m_robotSwerveDrive::resetGyro);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Iterate over and assign commands to cardinal Xbox controller d-pad directions.
|
|
|
|
|
for (XboxControllerPOV binding : XboxControllerPOV.values()) {
|
|
|
|
|
POVButton button = new POVButton(getDriverController(), binding.value);
|
|
|
|
|
if (binding == XboxControllerPOV.kUp) {
|
|
|
|
|
/* D-pad Up > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
} else if (binding == XboxControllerPOV.kRight) {
|
|
|
|
|
/* D-pad Right > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
} else if (binding == XboxControllerPOV.kDown) {
|
|
|
|
|
/* D-pad Down > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
} else if (binding == XboxControllerPOV.kLeft) {
|
|
|
|
|
/* D-pad Left > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-07 15:13:24 -06:00
|
|
|
|
2022-04-20 02:39:30 -06:00
|
|
|
private void configureOperatorButtonBindings() {
|
|
|
|
|
// Iterate over and assign commands to all Xbox controller buttons.
|
|
|
|
|
for (XboxController.Button binding : XboxController.Button.values()) {
|
|
|
|
|
/* ------------------------------------ Operator ------------------------------------ */
|
|
|
|
|
JoystickButton button = new JoystickButton(getDriverController(), binding.value);
|
|
|
|
|
if (binding == XboxController.Button.kLeftBumper) {
|
|
|
|
|
/* Left Bumper > Storage In */
|
|
|
|
|
button.whileHeld(new RunCommand(() -> m_robotStorage.runStorage(StorageConstants.STORAGE_SPEED)));
|
|
|
|
|
button.whenReleased(new RunCommand(() -> m_robotStorage.runStorage(0.0)));
|
|
|
|
|
} else if (binding == XboxController.Button.kRightBumper) {
|
|
|
|
|
/* Right Bumper > Storage Out */
|
|
|
|
|
button.whileHeld(new RunCommand(() -> m_robotStorage.runStorage(-StorageConstants.STORAGE_SPEED)));
|
|
|
|
|
button.whenReleased(new RunCommand(() -> m_robotStorage.runStorage(0.0)));
|
|
|
|
|
} else if (binding == XboxController.Button.kLeftStick) {
|
|
|
|
|
/* Left Stick > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
} else if (binding == XboxController.Button.kRightStick) {
|
|
|
|
|
/* Right Stick > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
} else if (binding == XboxController.Button.kA) {
|
|
|
|
|
/* A > Spit Out Ball */
|
|
|
|
|
button.whileHeld(new RunCommand(m_robotTurret::gotoMidpoint, m_robotTurret));
|
|
|
|
|
button.whileHeld(new RunCommand(() -> m_robotBoomBoom.runDrumShooter(0.25)));
|
|
|
|
|
} else if (binding == XboxController.Button.kB) {
|
|
|
|
|
/* B > Toggle Claws */
|
|
|
|
|
button.whenPressed(m_robotClaws::toggleClaws, m_robotClaws);
|
|
|
|
|
} else if (binding == XboxController.Button.kX) {
|
|
|
|
|
/* X > Toggle Extender Deployment */
|
|
|
|
|
button.whenPressed(new ExtenderIntakeGroup(m_robotIntake, m_robotExtender));
|
|
|
|
|
} else if (binding == XboxController.Button.kY) {
|
|
|
|
|
/* Y > Track Target */
|
|
|
|
|
button.whileHeld(new TrackTarget(m_robotVisionOdometry, m_robotTurret, m_robotHood, m_robotBoomBoom));
|
|
|
|
|
} else if (binding == XboxController.Button.kBack) {
|
|
|
|
|
/* Back > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
} else if (binding == XboxController.Button.kStart) {
|
|
|
|
|
/* Start > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Iterate over and assign commands to cardinal Xbox controller d-pad directions.
|
|
|
|
|
for (XboxControllerPOV binding : XboxControllerPOV.values()) {
|
|
|
|
|
POVButton button = new POVButton(getDriverController(), binding.value);
|
|
|
|
|
if (binding == XboxControllerPOV.kUp) {
|
|
|
|
|
/* D-pad Up > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
} else if (binding == XboxControllerPOV.kRight) {
|
|
|
|
|
/* D-pad Right > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
} else if (binding == XboxControllerPOV.kDown) {
|
|
|
|
|
/* D-pad Down > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
} else if (binding == XboxControllerPOV.kLeft) {
|
|
|
|
|
/* D-pad Left > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-07 15:13:24 -06:00
|
|
|
}
|
|
|
|
|
|
2022-04-20 02:39:30 -06:00
|
|
|
private void configureBoxButtonBindings() {
|
|
|
|
|
// Iterate over and assign commands to all button box buttons.
|
|
|
|
|
for (ButtonBox.Button binding : ButtonBox.Button.values()) {
|
|
|
|
|
/* ---------------------------------- Button Box ---------------------------------- */
|
|
|
|
|
JoystickButton button = new JoystickButton(getButtonBox(), binding.value);
|
|
|
|
|
if (binding == ButtonBox.Button.kRightSwitch) {
|
|
|
|
|
/* Right Switch > Unbound */
|
|
|
|
|
button.whenPressed(new PrintCommand("Unbound"));
|
|
|
|
|
} else if (binding == ButtonBox.Button.kMiddleSwitch) {
|
|
|
|
|
/* Middle Switch > Climber and Shooter mode switching */
|
|
|
|
|
button.whenPressed(() -> isClimberControlMode = true);
|
|
|
|
|
button.whenReleased(() -> isClimberControlMode = false);
|
|
|
|
|
} else if (binding == ButtonBox.Button.kLeftSwitch) {
|
|
|
|
|
/* Left Switch > Disables soft limits on press, release resets encoders (all for turret, hood, climber, and extender) */
|
|
|
|
|
button.whenPressed(() -> m_robotTurret.setTurretSoftLimits(false), m_robotTurret);
|
|
|
|
|
button.whenPressed(() -> m_robotTurret.calibrationSpeed = 0.3, m_robotTurret);
|
|
|
|
|
|
|
|
|
|
button.whenPressed(() -> m_robotHood.setHoodSoftLimits(false), m_robotHood);
|
|
|
|
|
button.whenPressed(() -> m_robotHood.calibrationSpeed = 0.3, m_robotHood);
|
|
|
|
|
|
|
|
|
|
button.whenPressed(() -> m_robotExtender.setExtenderSoftLimits(false), m_robotExtender);
|
|
|
|
|
|
|
|
|
|
button.whenReleased(() -> m_robotTurret.setTurretSoftLimits(true), m_robotTurret);
|
|
|
|
|
button.whenReleased(() -> m_robotTurret.calibrationSpeed = 1.0, m_robotTurret);
|
|
|
|
|
|
|
|
|
|
button.whenReleased(() -> m_robotHood.setHoodSoftLimits(true), m_robotHood);
|
|
|
|
|
button.whenReleased(() -> m_robotHood.calibrationSpeed = 1.0, m_robotHood);
|
|
|
|
|
|
|
|
|
|
button.whenReleased(() -> m_robotExtender.setExtenderSoftLimits(true), m_robotExtender);
|
|
|
|
|
|
|
|
|
|
button.whenReleased(() -> m_robotTurret.m_boomBoomRotateEncoder.setPosition(0), m_robotTurret);
|
|
|
|
|
button.whenReleased(() -> m_robotHood.m_angleEncoder.setPosition(0), m_robotHood);
|
|
|
|
|
button.whenReleased(() -> m_robotExtender.setEncoder(0), m_robotExtender);
|
|
|
|
|
button.whenReleased(ExtenderIntakeGroup::setDirectionToOut, m_robotIntake, m_robotExtender);
|
|
|
|
|
button.whenReleased(() -> m_robotClimber.setEncoders(0), m_robotClimber);
|
|
|
|
|
} else if (binding == ButtonBox.Button.kRightButton) {
|
|
|
|
|
/* Right Button > Extender Out */
|
|
|
|
|
button.whileHeld(new RunCommand(() -> m_robotExtender.runExtender(1.0), m_robotExtender));
|
|
|
|
|
button.whenReleased(new RunCommand(() -> m_robotExtender.runExtender(0.0), m_robotExtender));
|
|
|
|
|
} else if (binding == ButtonBox.Button.kLeftButton) {
|
|
|
|
|
/* Left Button > Extender In */
|
|
|
|
|
button.whileHeld(new RunCommand(() -> m_robotExtender.runExtender(-1.0), m_robotExtender));
|
|
|
|
|
button.whenReleased(new RunCommand(() -> m_robotExtender.runExtender(0.0), m_robotExtender));
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-07 15:13:24 -06:00
|
|
|
}
|
2022-04-04 19:30:15 -06:00
|
|
|
|
2022-04-17 01:15:33 -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() {
|
2022-04-19 20:36:59 -06:00
|
|
|
return m_autoChooser.getSelected();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-20 02:39:30 -06:00
|
|
|
public boolean isLockedOn() {
|
|
|
|
|
return m_robotTurret.isLockedOn() || m_robotHood.isLockedOn() || m_robotBoomBoom.isLockedOn();
|
2022-04-17 01:15:33 -06:00
|
|
|
}
|
|
|
|
|
|
2022-03-25 16:14:32 -06:00
|
|
|
public void switchControlMode() {
|
2022-04-20 02:39:30 -06:00
|
|
|
isClimberControlMode = !isClimberControlMode;
|
2022-03-25 16:14:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void switchDriveMode() {
|
2022-04-20 02:39:30 -06:00
|
|
|
driveControlEnabled = !driveControlEnabled;
|
2022-03-25 16:14:32 -06:00
|
|
|
}
|
|
|
|
|
|
2022-04-17 01:15:33 -06:00
|
|
|
public DeadbandedXboxController getDriverController() {
|
2022-01-11 11:05:52 -07:00
|
|
|
return m_driverXbox;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-17 01:15:33 -06:00
|
|
|
public DeadbandedXboxController getOperatorController() {
|
2022-03-21 12:29:03 -06:00
|
|
|
return m_operatorXbox;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-12 19:02:37 -07:00
|
|
|
public ButtonBox getButtonBox() {
|
|
|
|
|
return m_buttonBox;
|
2022-03-12 17:33:38 -07:00
|
|
|
}
|
|
|
|
|
|
2022-01-11 11:05:52 -07:00
|
|
|
/**
|
2022-02-17 19:52:05 -07:00
|
|
|
* Set odometry to given pose.
|
2022-04-20 02:39:30 -06: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-04-20 02:39:30 -06:00
|
|
|
|
|
|
|
|
private void putRobotDashboardData() {
|
|
|
|
|
putData("Values", builder -> {
|
|
|
|
|
builder.addDoubleProperty("Match Time", DriverStation::getMatchTime, null);
|
|
|
|
|
builder.addDoubleProperty("Claws", m_robotClaws.m_rightClaw::get, null);
|
|
|
|
|
builder.addDoubleProperty("Arm", m_robotMap.elbow::get, null);
|
|
|
|
|
builder.addDoubleProperty("Intake", m_robotMap.intakeMotor::get, null);
|
|
|
|
|
builder.addDoubleProperty("Serializer", m_robotMap.serializerBelt::get, null);
|
|
|
|
|
builder.addDoubleProperty("Storage", m_robotMap.storageMotor::get, null);
|
|
|
|
|
builder.addDoubleProperty("Drum", m_robotMap.shooterFalconRight::get, null);
|
|
|
|
|
builder.addDoubleProperty("Angle", m_robotMap.shooterTurret::get, null);
|
|
|
|
|
builder.addDoubleProperty("Hood", m_robotMap.angleAdjusterMotor::get, null);
|
|
|
|
|
builder.addBooleanProperty("Shooter Safety", this::isLockedOn, null);
|
|
|
|
|
});
|
|
|
|
|
putData("Field", m_robotSwerveDrive.m_field);
|
|
|
|
|
putData("PDP", new PowerDistribution() {
|
|
|
|
|
@Override
|
|
|
|
|
public void initSendable(SendableBuilder builder) {
|
|
|
|
|
super.initSendable(builder);
|
|
|
|
|
builder.setSmartDashboardType("PowerDistributionPanel");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
putData("Extender", new NTSendable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void initSendable(NTSendableBuilder builder) {
|
|
|
|
|
builder.setSmartDashboardType("String Chooser");
|
|
|
|
|
builder.getEntry(".instance").setDouble(0);
|
|
|
|
|
builder.addStringProperty("default", () -> "Retracted", null);
|
|
|
|
|
builder.addStringArrayProperty("options", () -> new String[] {"Retracted", "Extended"}, null);
|
|
|
|
|
builder.addStringProperty("active", () -> m_robotExtender.getPosition() <= 0 ? "Retracted" : "Extended", null);
|
|
|
|
|
builder.addStringProperty("selected", null, null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
putData("Drivebase", m_robotSwerveDrive);
|
|
|
|
|
putData("Gyro", m_robotSwerveDrive.m_gyro);
|
|
|
|
|
putData("Drive Speed", new NTSendable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void initSendable(NTSendableBuilder builder) {
|
|
|
|
|
builder.setSmartDashboardType("String Chooser");
|
|
|
|
|
builder.getEntry(".instance").setDouble(0);
|
|
|
|
|
builder.addStringProperty("default", () -> "Low", null);
|
|
|
|
|
builder.addStringArrayProperty("options", () -> new String[] {"Low", "High"}, null);
|
|
|
|
|
builder.addStringProperty("active", () -> m_robotSwerveDrive.speedAdjust == SwerveDriveConstants.JOYSTICK_TO_METERS_PER_SECOND_SLOW ? "Low" : "High", null);
|
|
|
|
|
builder.addStringProperty("selected", null, val -> m_robotSwerveDrive.speedAdjust = val.equals("Low") ? SwerveDriveConstants.JOYSTICK_TO_METERS_PER_SECOND_SLOW : SwerveDriveConstants.JOYSTICK_TO_METERS_PER_SECOND_FAST);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
putData("Accelerometer", new NTSendable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void initSendable(NTSendableBuilder builder) {
|
|
|
|
|
builder.setSmartDashboardType("3AxisAccelerometer");
|
|
|
|
|
NetworkTableEntry entryX = builder.getEntry("X");
|
|
|
|
|
NetworkTableEntry entryY = builder.getEntry("Y");
|
|
|
|
|
NetworkTableEntry entryZ = builder.getEntry("Z");
|
|
|
|
|
builder.setUpdateTable(() -> {
|
|
|
|
|
short[] data = new short[3];
|
|
|
|
|
m_robotSwerveDrive.m_gyro.getBiasedAccelerometer(data);
|
|
|
|
|
entryX.setDouble(data[0]);
|
|
|
|
|
entryY.setDouble(data[1]);
|
|
|
|
|
entryZ.setDouble(data[2]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
putData("Drive Camera", m_robotCamera);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final Map<String, Sendable> m_tablesToData = new HashMap<>();
|
|
|
|
|
private final NetworkTable m_networkTable = NetworkTableInstance.getDefault().getTable("Robot");
|
|
|
|
|
|
|
|
|
|
private synchronized void putData(String key, Sendable data) {
|
|
|
|
|
Sendable sddata = m_tablesToData.get(key);
|
|
|
|
|
if (sddata == null || sddata != data) {
|
|
|
|
|
m_tablesToData.put(key, data);
|
|
|
|
|
NetworkTable dataTable = m_networkTable.getSubTable(key);
|
|
|
|
|
SendableBuilderImpl builder = new SendableBuilderImpl();
|
|
|
|
|
builder.setTable(dataTable);
|
|
|
|
|
SendableRegistry.publish(data, builder);
|
|
|
|
|
builder.startListeners();
|
|
|
|
|
dataTable.getEntry(".name").setString(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public synchronized void updateValues() {
|
|
|
|
|
m_tablesToData.values().forEach(SendableRegistry::update);
|
|
|
|
|
}
|
2021-11-15 16:26:16 -07:00
|
|
|
}
|