Files
2026KPopRobotHunters/src/main/java/frc4388/robot/RobotContainer.java
T

606 lines
26 KiB
Java
Raw Normal View History

2025-11-18 15:39:59 -08: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. */
/*----------------------------------------------------------------------------*/
2026-03-20 20:01:06 -06: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.
2025-11-18 15:39:59 -08:00
package frc4388.robot;
import java.io.File;
2026-03-20 20:01:06 -06:00
import java.util.Optional;
2026-01-13 19:41:42 -07:00
2026-02-21 15:55:29 -07:00
import com.pathplanner.lib.auto.NamedCommands;
2026-01-19 13:42:16 -07:00
import com.pathplanner.lib.commands.PathPlannerAuto;
2026-02-21 14:08:32 -08:00
import edu.wpi.first.math.geometry.Pose2d;
2026-01-13 19:41:42 -07:00
import edu.wpi.first.math.geometry.Rotation2d;
2025-11-18 15:39:59 -08:00
import edu.wpi.first.math.geometry.Translation2d;
2026-01-13 18:17:37 -07:00
import edu.wpi.first.wpilibj.DriverStation;
2025-11-18 15:39:59 -08:00
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.RobotBase;
2026-03-05 17:22:50 -07:00
import edu.wpi.first.wpilibj.smartdashboard.Field2d;
2025-11-18 15:39:59 -08:00
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
2026-01-19 13:42:16 -07:00
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
2025-11-18 15:39:59 -08:00
// Commands
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;
2026-03-20 20:01:06 -06:00
import edu.wpi.first.wpilibj2.command.ParallelCommandGroup;
2025-11-18 15:39:59 -08:00
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
2026-02-21 15:55:29 -07:00
import edu.wpi.first.wpilibj2.command.WaitCommand;
2026-02-27 20:02:12 -07:00
import edu.wpi.first.wpilibj2.command.WaitUntilCommand;
2026-02-11 16:36:51 -07:00
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import edu.wpi.first.wpilibj2.command.button.Trigger;
2026-03-10 08:39:05 -06:00
import frc4388.robot.commands.Swerve.StayInPosition;
import frc4388.robot.commands.alignment.AutoAlign;
2025-11-18 15:39:59 -08:00
import frc4388.robot.constants.Constants;
2026-03-21 15:49:44 -06:00
import frc4388.robot.constants.FieldConstants;
2025-11-18 15:39:59 -08:00
import frc4388.robot.constants.Constants.OIConstants;
import frc4388.robot.constants.Constants.SimConstants.Mode;
2026-02-07 14:51:05 -07:00
import frc4388.robot.subsystems.intake.Intake;
2026-02-09 17:18:54 -08:00
import frc4388.robot.subsystems.intake.Intake.IntakeMode;
2026-03-10 08:39:05 -06:00
import frc4388.robot.subsystems.led.LED;
2026-02-07 14:51:05 -07:00
import frc4388.robot.subsystems.shooter.Shooter;
import frc4388.robot.subsystems.shooter.ShooterConstants;
2026-03-12 18:05:14 -06:00
import frc4388.robot.subsystems.swerve.SimpleSwerveSim;
2025-11-18 15:39:59 -08:00
import frc4388.robot.subsystems.swerve.SwerveDrive;
2026-03-10 08:39:05 -06:00
import frc4388.robot.subsystems.vision.Lidar;
2025-11-18 15:39:59 -08:00
import frc4388.robot.subsystems.vision.Vision;
2026-01-19 13:42:16 -07:00
import frc4388.utility.DeferredBlock;
import frc4388.utility.compute.FieldPositions;
2026-01-19 13:42:16 -07:00
import frc4388.utility.compute.TimesNegativeOne;
import frc4388.utility.controller.DeadbandedXboxController;
// Autos
import frc4388.utility.controller.VirtualController;
import frc4388.utility.controller.XboxController;
2025-11-18 15:39:59 -08: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 (2including subsystems,
* commands, and button mappings) should be declared here.
*/
public class RobotContainer {
/* RobotMap */
2026-03-12 00:08:36 -06:00
public final RobotMap m_robotMap = new RobotMap(RobotBase.isReal() ? Mode.REAL : Mode.SIM);
2025-11-18 15:39:59 -08:00
2026-02-14 10:55:51 -08:00
/*Limit Switch */
2026-02-14 15:57:33 -07:00
// public final DigitalInput m_armLimitSwitch = new DigitalInput(9);
2026-02-14 10:55:51 -08:00
2025-11-18 15:39:59 -08:00
/* Subsystems */
// public final Lidar m_lidar = new Lidar();
2026-02-11 16:39:09 -07:00
public final LED m_robotLED = new LED(Constants.LEDConstants.LED_SPARK_ID);
2026-03-12 18:05:14 -06:00
public final SimpleSwerveSim m_robotSwerveSIM = new SimpleSwerveSim();
2026-02-11 16:36:51 -07:00
//Testing of Colors
2026-02-20 20:59:06 -08:00
public final Vision m_vision = new Vision(m_robotMap.rightCamera, m_robotMap.leftCamera);
2026-02-11 16:36:51 -07:00
public final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.swerveDrivetrain, m_vision);
2026-02-14 15:57:33 -07:00
public final Intake m_robotIntake = new Intake(m_robotMap.intakeIO);
2026-02-11 16:36:51 -07:00
public final Shooter m_robotShooter = new Shooter(m_robotMap.shooterIO, m_robotSwerveDrive, m_robotIntake, m_robotLED);
2026-02-12 14:36:26 -07:00
2025-11-18 15:39:59 -08:00
/* Controllers */
private final DeadbandedXboxController m_driverXbox = new DeadbandedXboxController(OIConstants.XBOX_DRIVER_ID);
private final DeadbandedXboxController m_operatorXbox = new DeadbandedXboxController(OIConstants.XBOX_OPERATOR_ID);
2026-02-14 10:55:51 -08:00
2026-01-13 18:17:37 -07:00
// private final ButtonBox m_buttonBox = new ButtonBox(OIConstants.BUTTONBOX_ID);
2025-11-18 15:39:59 -08:00
// public List<Subsystem> subsystems = new ArrayList<>();
2026-03-10 08:39:05 -06:00
private final StayInPosition m_stayInPosition = new StayInPosition(m_robotSwerveDrive);
2026-03-10 08:39:05 -06:00
private Pose2d currentPose = new Pose2d(0, 0, new Rotation2d());
// ! Teleop Commands
public void stop() {
new InstantCommand(()->{}, m_robotSwerveDrive).schedule();
m_robotSwerveDrive.stopModules();
Constants.AutoConstants.Y_OFFSET_TRIM.set(0);
}
2025-11-18 15:39:59 -08:00
2026-03-10 08:39:05 -06:00
// ! /* Autos */
private SendableChooser<String> autoChooser;
private Command autoCommand;
private Command IntakeExtended = new SequentialCommandGroup(
new InstantCommand(() -> m_robotIntake.setMode(IntakeMode.Extended), m_robotIntake)
);
// private Command LidarIntake = new SequentialCommandGroup(
// // Right now this will just go to the closest ball constantly updating - need to make it so it locks on one ball
// // RobotIntakeDown,
// // new WaitCommand(1),
// // new InstantCommand(() -> System.out.println("Closest Ball: " + m_lidar.getClosestBall())),
// new AutoAlign(m_robotSwerveDrive, m_vision, m_lidar, true)
// // new RunCommand(
// // () -> m_robotSwerveDrive.driveWithInput(
// // m_lidar.getClosestBall(),
// // new Translation2d(m_lidar.getLatestBallAngle().getCos() * 0.1, 0),
// // false
// // ),
// // m_robotSwerveDrive
// // )
// // .withTimeout(5.0)
// // .andThen(new InstantCommand(() -> m_robotSwerveDrive.softStop(), m_robotSwerveDrive))
// );
private Command RobotRev = new SequentialCommandGroup(
2026-03-20 15:40:07 -06:00
new InstantCommand(() -> m_robotShooter.spinUpShooting(), m_robotShooter),
2026-03-10 08:39:05 -06:00
IntakeExtended,
2026-03-25 11:39:55 -06:00
new InstantCommand(() -> m_robotIntake.setMode(IntakeMode.Idle), m_robotIntake)
2026-03-10 08:39:05 -06:00
);
2026-03-20 20:01:06 -06:00
private Command RobotShootDriving = new SequentialCommandGroup(
2026-03-20 20:33:15 -06:00
new RunCommand(() ->
m_robotSwerveDrive.enableRotationOverride(FieldPositions.HUB_POSITION, ShooterConstants.AIM_LEAD_TIME.get(), FieldPositions.HUB_POSITION)
).withTimeout(20)
2026-03-20 20:01:06 -06:00
).finallyDo((interrupted) ->
m_robotSwerveDrive.disableRotationOverride()
);
2026-03-10 08:39:05 -06:00
private Command IntakeRetracted = new SequentialCommandGroup(
new InstantCommand(() -> m_robotIntake.setMode(IntakeMode.Retracted), m_robotIntake)
);
private Command RobotShoot = new SequentialCommandGroup(
// TEST NEW AUTO ALIGN
//new AutoAlign(m_robotSwerveDrive, m_vision, new Pose2d(FieldPositions.HUB_POSITION, new Rotation2d(0)), false),
new WaitUntilCommand(m_robotShooter::isShooterUpToSpeed),
new InstantCommand(()-> m_robotShooter.allowShooting(), m_robotShooter),
2026-03-21 13:04:40 -06:00
new WaitCommand(5),
2026-03-10 08:39:05 -06:00
IntakeRetracted,
2026-03-21 15:49:44 -06:00
new WaitCommand(10),
2026-03-10 08:39:05 -06:00
new InstantCommand(() -> m_robotShooter.denyShooting(), m_robotShooter),
new InstantCommand(()->m_robotShooter.spinUpIdle(), m_robotShooter)
);
2026-02-22 14:02:31 -07:00
2026-01-13 19:41:42 -07:00
2026-03-10 08:39:05 -06:00
public RobotContainer() {
2026-03-28 15:56:54 -06:00
configureButtonBindings();
2026-03-10 08:39:05 -06:00
// Called on first robot enable
DeferredBlock.addBlock(() -> {
m_robotSwerveDrive.resetGyro();
}, false);
// Called on every robot enable
DeferredBlock.addBlock(() -> {
TimesNegativeOne.update();
FieldPositions.update();
2026-02-11 16:36:51 -07:00
m_robotIntake.io.updateGains();
m_robotShooter.io.updateGains();
2026-03-10 08:39:05 -06:00
}, true);
NamedCommands.registerCommand("Robot Rev Up", RobotRev);
NamedCommands.registerCommand("Intake Retracted", IntakeRetracted);
NamedCommands.registerCommand("Robot Shoot", RobotShoot);
// NamedCommands.registerCommand("Lidar Intake", LidarIntake);
NamedCommands.registerCommand("Intake Extended", IntakeExtended);
2026-03-20 20:01:06 -06:00
NamedCommands.registerCommand("Robot Shoot Driving", RobotShootDriving);
2026-03-21 15:49:44 -06:00
NamedCommands.registerCommand("WaitShooter", new WaitUntilCommand(m_robotShooter::isShooterUpToSpeed));
NamedCommands.registerCommand("AllowShooting", new InstantCommand(() -> m_robotShooter.allowShooting(), m_robotShooter));
NamedCommands.registerCommand("DenyShooting", new InstantCommand(() -> m_robotShooter.denyShooting(), m_robotShooter));
NamedCommands.registerCommand("SpinUpShooting", new InstantCommand(() -> m_robotShooter.spinUpShooting(), m_robotShooter));
NamedCommands.registerCommand("SpinUpIdle", new InstantCommand(() -> m_robotShooter.spinUpIdle(), m_robotShooter));
2026-03-10 08:39:05 -06:00
2026-03-21 15:49:44 -06:00
NamedCommands.registerCommand("BumpOffsetForward", new InstantCommand(() -> {
if (TimesNegativeOne.isRed) {
m_robotSwerveDrive.offsetOdoPosition(FieldConstants.BUMP_OFFSET_RED);
} else {
m_robotSwerveDrive.offsetOdoPosition(FieldConstants.BUMP_OFFSET_BLUE);
}
}));
NamedCommands.registerCommand("BumpOffsetReverse", new InstantCommand(() -> {
if (!TimesNegativeOne.isRed) {
m_robotSwerveDrive.offsetOdoPosition(FieldConstants.BUMP_OFFSET_RED);
} else {
m_robotSwerveDrive.offsetOdoPosition(FieldConstants.BUMP_OFFSET_BLUE);
}
}));
2026-03-10 08:39:05 -06:00
DriverStation.silenceJoystickConnectionWarning(true);
// Drive normally
m_robotSwerveDrive.setDefaultCommand(new RunCommand(() -> {
m_robotSwerveDrive.driveWithInput(
getDeadbandedDriverController().getLeft(),
getDeadbandedDriverController().getRight(),true);
}, m_robotSwerveDrive)
.withName("SwerveDrive DefaultCommand"));
2026-02-11 16:36:51 -07:00
2026-03-10 08:39:05 -06:00
m_robotSwerveDrive.setToSlow();
makeAutoChooser();
SmartDashboard.putData("Auto Chooser", autoChooser);
}
/**
* 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 controls
new JoystickButton(getDeadbandedDriverController(), XboxController.A_BUTTON)
.onTrue(new InstantCommand(() -> m_robotSwerveDrive.resetGyro()));
new JoystickButton(getDeadbandedDriverController(), XboxController.RIGHT_BUMPER_BUTTON)
.onTrue(new InstantCommand(() -> m_robotSwerveDrive.shiftUp()));
new JoystickButton(getDeadbandedDriverController(), XboxController.LEFT_BUMPER_BUTTON)
.onTrue(new InstantCommand(() -> m_robotSwerveDrive.shiftDown()));
new JoystickButton(getDeadbandedDriverController(), XboxController.BACK_BUTTON)
.onTrue(new InstantCommand(() -> {
m_robotIntake.io.updateGains();
m_robotShooter.io.updateGains();
}));
// TEST-> the driver is holding the left trigger, drive slow and rotation up
new Trigger(() -> getDeadbandedDriverController().getLeftTriggerAxis() >= 0.5)
.onTrue(new InstantCommand(() -> {
m_robotSwerveDrive.setToSlow();
m_robotSwerveDrive.shiftUpRot();
}))
.onFalse(new InstantCommand(() -> {
m_robotSwerveDrive.setToFast();
m_robotSwerveDrive.shiftDownRot();
}));
2026-03-19 18:32:02 -06:00
//TEST - > X positino on wheels
2026-03-10 08:39:05 -06:00
new JoystickButton(getDeadbandedDriverController(), XboxController.X_BUTTON)
2026-03-19 14:21:46 -06:00
.whileTrue(new RunCommand(() -> {
m_robotSwerveDrive.defenseXPosition();
2026-03-14 18:57:04 -06:00
}, m_robotSwerveDrive))
2026-03-19 14:21:46 -06:00
.onFalse(new InstantCommand(() -> {
m_robotSwerveDrive.stopDefenseXPosition();
2026-03-19 18:32:02 -06:00
}));
2026-03-19 14:21:46 -06:00
2026-03-19 18:32:02 -06:00
//TEST - > PID positinon
new JoystickButton(getDeadbandedDriverController(), XboxController.B_BUTTON)
.onTrue(new InstantCommand(() -> {
currentPose = m_robotSwerveDrive.getCurrentPose();
}))
.whileTrue(new RunCommand(() -> {
m_stayInPosition.goToTargetPose(currentPose);
}, m_robotSwerveDrive))
.onFalse(new InstantCommand(() -> {
m_robotSwerveDrive.softStop();
2026-03-14 18:57:04 -06:00
2026-02-14 10:55:51 -08:00
}));
2026-02-11 16:36:51 -07:00
2026-03-14 18:29:15 -06:00
2026-02-11 16:36:51 -07:00
// IF the driver is holding the aim button, aim the robot towards the hub and shooter ready
new Trigger(() -> getDeadbandedDriverController().getRightTriggerAxis() >= 0.5)
2026-03-19 18:32:02 -06:00
.onTrue(new InstantCommand(() -> {
m_robotSwerveDrive.setToSlow();
}))
.whileTrue(new RunCommand(() -> {
m_robotSwerveDrive.driveFacingPosition(
2026-03-15 11:17:55 -06:00
getDeadbandedDriverController().getLeft(),
FieldPositions.HUB_POSITION,
2026-03-19 18:32:02 -06:00
ShooterConstants.AIM_LEAD_TIME.get()
2026-03-15 11:17:55 -06:00
);
}, m_robotSwerveDrive)
2026-02-14 12:33:03 -07:00
);
2026-02-11 16:36:51 -07:00
// D-PAD fine alignment
new Trigger(() -> getDeadbandedDriverController().getPOV() != -1)
.whileTrue(new RunCommand(
() -> m_robotSwerveDrive.driveFine(
new Translation2d(
1,
Rotation2d.fromDegrees(getDeadbandedDriverController().getPOV())
),
getDeadbandedDriverController().getRight(), 0.15
), m_robotSwerveDrive))
.onFalse(new InstantCommand(() -> m_robotSwerveDrive.softStop(), m_robotSwerveDrive));
2026-02-14 12:33:03 -07:00
//Operator Controls
2026-02-25 15:33:01 -08:00
// new Trigger(() -> getDeadbandedOperatorController().getRightTriggerAxis() >= 0.5)
// .onTrue(new InstantCommand(() -> {
// m_robotIntake.setMode(IntakeMode.Extended);
// }));
//allow shooting with right trigger
2026-02-17 18:53:26 -08:00
new Trigger(() -> getDeadbandedOperatorController().getRightTriggerAxis() >= 0.5)
2026-02-14 12:33:03 -07:00
.onTrue(new InstantCommand(() -> {
2026-02-25 15:33:01 -08:00
m_robotShooter.allowShooting();
})).onFalse(new InstantCommand(() -> {
m_robotShooter.denyShooting();
2026-02-14 12:33:03 -07:00
}));
2026-02-25 15:33:01 -08:00
2026-02-25 16:35:40 -08:00
new JoystickButton(getDeadbandedOperatorController(), XboxController.LEFT_BUMPER_BUTTON)
2026-02-16 15:57:24 -07:00
.onTrue(new InstantCommand(() -> {
2026-02-25 16:35:40 -08:00
m_robotShooter.spinUpFeeding();
m_robotIntake.rollerStop();
}))
.onFalse(new InstantCommand(() -> {
m_robotShooter.spinUpIdle();
2026-02-14 12:33:03 -07:00
}));
2026-02-23 16:58:14 -07:00
2026-02-25 15:33:01 -08:00
//set shooter ready (rev) with left trigger hold
2026-02-17 18:53:26 -08:00
new Trigger(() -> getDeadbandedOperatorController().getLeftTriggerAxis() >= 0.5)
2026-02-14 12:33:03 -07:00
.onTrue(new InstantCommand(() -> {
2026-03-03 17:22:29 -07:00
m_robotIntake.setMode(IntakeMode.Idle);
2026-02-25 15:33:01 -08:00
m_robotIntake.rollerStop();
2026-03-20 15:40:07 -06:00
m_robotShooter.spinUpShooting();
2026-02-25 15:33:01 -08:00
}))
.onFalse(new InstantCommand(() -> {
2026-02-24 13:50:30 -07:00
m_robotShooter.spinUpIdle();
2026-02-14 12:33:03 -07:00
}));
2026-02-25 16:35:40 -08:00
new JoystickButton(getDeadbandedOperatorController(), XboxController.RIGHT_BUMPER_BUTTON)
2026-02-23 16:58:14 -07:00
.onTrue(new InstantCommand(() -> {
2026-02-25 16:35:40 -08:00
m_robotIntake.setMode(IntakeMode.Retracted);
2026-02-23 16:58:14 -07:00
}));
2026-02-21 12:54:16 -08:00
new JoystickButton(getDeadbandedOperatorController(), XboxController.A_BUTTON)
.onTrue(new InstantCommand(() -> {
2026-02-25 16:35:40 -08:00
m_robotIntake.setMode(IntakeMode.Extended);
2026-02-14 12:33:03 -07:00
}));
2026-02-14 15:00:40 -07:00
2026-02-22 14:02:31 -07:00
new JoystickButton(getDeadbandedOperatorController(), XboxController.X_BUTTON)
2026-02-16 16:19:51 -07:00
.onTrue(new InstantCommand(() -> {
2026-02-22 14:02:31 -07:00
m_robotIntake.setMode(IntakeMode.Extending);
2026-02-16 16:19:51 -07:00
}))
.onFalse(new InstantCommand(() -> {
m_robotIntake.setMode(IntakeMode.Idle);
2026-02-14 15:00:40 -07:00
}));
2026-02-22 14:02:31 -07:00
new JoystickButton(getDeadbandedOperatorController(), XboxController.Y_BUTTON)
2026-02-16 16:19:51 -07:00
.onTrue(new InstantCommand(() -> {
2026-02-22 14:02:31 -07:00
m_robotIntake.setMode(IntakeMode.Retracting);
2026-02-16 16:19:51 -07:00
}))
.onFalse(new InstantCommand(() -> {
m_robotIntake.setMode(IntakeMode.Idle);
2026-02-14 15:00:40 -07:00
}));
2026-02-14 12:33:03 -07:00
2026-02-22 14:02:31 -07:00
// new JoystickButton(getDeadbandedOperatorController(), XboxController.B_BUTTON)
// .onTrue(new InstantCommand(() -> {
// m_robotClimber.toggleDeployed();
// }));
2026-03-20 15:40:07 -06:00
}
private void configureSINGLEBindings() {
//Driver controls
2026-03-21 15:49:44 -06:00
// new JoystickButton(getDeadbandedDriverController(), XboxController.A_BUTTON)
// .onTrue(new InstantCommand(() -> m_robotSwerveDrive.resetGyro()));
2026-03-20 15:40:07 -06:00
new JoystickButton(getDeadbandedDriverController(), XboxController.A_BUTTON)
2026-03-21 15:49:44 -06:00
.onTrue(new InstantCommand(() -> m_robotSwerveDrive.offsetOdoPosition(FieldConstants.BUMP_OFFSET_RED)));
2026-03-20 15:40:07 -06:00
new JoystickButton(getDeadbandedDriverController(), XboxController.RIGHT_BUMPER_BUTTON)
.onTrue(new InstantCommand(() -> m_robotSwerveDrive.shiftUp()));
new JoystickButton(getDeadbandedDriverController(), XboxController.LEFT_BUMPER_BUTTON)
.onTrue(new InstantCommand(() -> m_robotSwerveDrive.shiftDown()));
// TEST-> the driver is holding the left trigger, drive slow and rotation up
// new Trigger(() -> getDeadbandedDriverController().getLeftTriggerAxis() >= 0.5)
// .onTrue(new InstantCommand(() -> {
// m_robotSwerveDrive.setToSlow();
// m_robotSwerveDrive.shiftUpRot();
// }))
// .onFalse(new InstantCommand(() -> {
// m_robotSwerveDrive.setToFast();
// m_robotSwerveDrive.shiftDownRot();
// }));
//TEST - > X positino on wheels
new JoystickButton(getDeadbandedDriverController(), XboxController.BACK_BUTTON)
.whileTrue(new RunCommand(() -> {
m_robotSwerveDrive.defenseXPosition();
}, m_robotSwerveDrive))
.onFalse(new InstantCommand(() -> {
m_robotSwerveDrive.stopDefenseXPosition();
}));
//TEST - > PID positinon
new JoystickButton(getDeadbandedDriverController(), XboxController.B_BUTTON)
.onTrue(new InstantCommand(() -> {
currentPose = m_robotSwerveDrive.getCurrentPose();
}))
.whileTrue(new RunCommand(() -> {
m_stayInPosition.goToTargetPose(currentPose);
}, m_robotSwerveDrive))
.onFalse(new InstantCommand(() -> {
m_robotSwerveDrive.softStop();
}));
// IF the driver is holding the aim button, aim the robot towards the hub and shooter ready
new Trigger(() -> getDeadbandedDriverController().getLeftTriggerAxis() >= 0.5)
.onTrue(new InstantCommand(() -> {
m_robotSwerveDrive.setToSlow();
}))
.whileTrue(new RunCommand(() -> {
m_robotSwerveDrive.driveFacingPosition(
getDeadbandedDriverController().getLeft(),
FieldPositions.HUB_POSITION,
ShooterConstants.AIM_LEAD_TIME.get()
);
}, m_robotSwerveDrive)
);
// D-PAD fine alignment
new Trigger(() -> getDeadbandedDriverController().getPOV() != -1)
.whileTrue(new RunCommand(
() -> m_robotSwerveDrive.driveFine(
new Translation2d(
1,
Rotation2d.fromDegrees(getDeadbandedDriverController().getPOV())
),
getDeadbandedDriverController().getRight(), 0.15
), m_robotSwerveDrive))
.onFalse(new InstantCommand(() -> m_robotSwerveDrive.softStop(), m_robotSwerveDrive));
//allow shooting with right trigger
new Trigger(() -> getDeadbandedDriverController().getRightTriggerAxis() >= 0.5)
2026-03-19 14:21:46 -06:00
.onTrue(new InstantCommand(() -> {
2026-03-20 15:40:07 -06:00
m_robotShooter.allowShooting();
})).onFalse(new InstantCommand(() -> {
m_robotShooter.denyShooting();
}));
//set shooter ready (rev) with left trigger hold
new Trigger(() -> getDeadbandedDriverController().getLeftTriggerAxis() >= 0.5)
.onTrue(new InstantCommand(() -> {
m_robotIntake.setMode(IntakeMode.Idle);
m_robotIntake.rollerStop();
m_robotShooter.spinUpShooting();
2026-03-19 14:21:46 -06:00
}))
.onFalse(new InstantCommand(() -> {
m_robotShooter.spinUpIdle();
}));
2026-03-20 15:40:07 -06:00
new JoystickButton(getDeadbandedDriverController(), XboxController.X_BUTTON)
.onTrue(new InstantCommand(() -> {
m_robotIntake.setMode(IntakeMode.Extending);
}))
.onFalse(new InstantCommand(() -> {
m_robotIntake.setMode(IntakeMode.Idle);
}));
new JoystickButton(getDeadbandedDriverController(), XboxController.Y_BUTTON)
.onTrue(new InstantCommand(() -> {
m_robotIntake.setMode(IntakeMode.Retracting);
}))
.onFalse(new InstantCommand(() -> {
m_robotIntake.setMode(IntakeMode.Idle);
}));
2026-02-14 12:33:03 -07:00
2026-03-20 15:40:07 -06:00
}
2026-02-11 16:36:51 -07:00
//.onTrue(new InstantCommand(() -> m_robotLED.setMode(LEDPatterns.SOLID_PINK_HOT)));
2025-11-18 15:39:59 -08:00
/**
* Use this to pass the autonomous command to the main {@link Robot} class.
*
* @return the command to run in autonomous
*/
public Command getAutonomousCommand() {
//return autoPlayback;
//return new GotoPositionCommand(m_robotSwerveDrive, m_vision)
//return autoChooser.getSelected();
// try{
// // // Load the path you want to follow using its name in the GUI
// return autoCommand;
// } catch (Exception e) {
// DriverStation.reportError("Path planner error: " + e.getMessage(), e.getStackTrace());
return autoCommand;
// }
// return new PathPlannerAuto("Line-up-no-arm");
// zach told me to do the below comment
//return new GotoPositionCommand(m_robotSwerveDrive, m_vision);
// return new GotoPositionCommand(m_robotSwerveDrive, m_vision, AutoConstants.targetpos);
}
public boolean autoChooserUpdated = false;
public void makeAutoChooser() {
autoChooser = new SendableChooser<String>();
File dir;
if(RobotBase.isReal()) {
dir = new File("/home/lvuser/deploy/pathplanner/autos/");
} else {
// dir = new File("C:\\Users\\Ridgebotics\\Documents\\GitHub\\2025RidgeScape\\src\\main\\deploy\\pathplanner\\autos\\");
2026-01-19 19:42:29 -07:00
dir = new File("C:\\Users\\Ridgebotics\\Documents\\GitHub\\2026KPopRobotHunters\\src\\main\\deploy\\pathplanner\\autos\\");
2025-11-18 15:39:59 -08:00
}
String[] autos = dir.list();
if(autos == null) return;
for (String auto : autos) {
if (auto.endsWith(".auto"))
autoChooser.addOption(auto.replaceAll(".auto", ""), auto.replaceAll(".auto", ""));
// System.out.println(auto);
}
autoChooser.onChange((filename) -> {
2026-02-11 16:36:51 -07:00
autoChooserUpdated = true;
2026-02-24 17:49:26 -07:00
// if (filename.equals("Taxi%")) {
2026-02-21 14:08:32 -08:00
// autoCommand = new SequentialCommandGroup(
// new MoveForTimeCommand(m_robotSwerveDrive,
// new Translation2d(0, -1),
// new Translation2d(), 1000, true
// ), new InstantCommand(()-> {m_robotSwerveDrive.softStop();} , m_robotSwerveDrive));
// } else {
2026-02-11 16:36:51 -07:00
autoCommand = new PathPlannerAuto(filename);
2026-02-21 14:08:32 -08:00
// }
2026-02-11 16:36:51 -07:00
System.out.println("Robot Auto Changed " + filename);
2026-02-21 14:08:32 -08:00
//----
PathPlannerAuto auto = new PathPlannerAuto(filename);
m_robotSwerveDrive.setInitalPose(auto.getStartingPose());
//-----
2025-11-18 15:39:59 -08:00
});
2026-01-19 13:42:16 -07:00
SmartDashboard.putData(autoChooser);
2025-11-18 15:39:59 -08:00
}
/**
* A button binding for two controllers, preferably an {@link DeadbandedXboxController Xbox Controller} and {@link VirtualController Virtual Xbox Controller}
* @param joystickA A controller
* @param joystickB A controller
* @param buttonNumber The button to bind to
*/
public Trigger DualJoystickButton(GenericHID joystickA, GenericHID joystickB, int buttonNumber) {
return new Trigger(() -> (joystickA.getRawButton(buttonNumber) || joystickB.getRawButton(buttonNumber)));
}
public DeadbandedXboxController getDeadbandedDriverController() {
return this.m_driverXbox;
}
public DeadbandedXboxController getDeadbandedOperatorController() {
return this.m_operatorXbox;
}
2026-01-13 18:17:37 -07:00
// public ButtonBox getButtonBox() {
// return this.m_buttonBox;
// }
2026-02-11 16:36:51 -07:00
}