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. */
/*----------------------------------------------------------------------------*/
package frc4388.robot ;
import java.io.File ;
2026-01-13 19:41:42 -07:00
2026-01-19 13:42:16 -07:00
import com.pathplanner.lib.commands.PathPlannerAuto ;
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 ;
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 ;
import edu.wpi.first.wpilibj2.command.RunCommand ;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup ;
// Autos
import frc4388.utility.controller.VirtualController ;
2026-01-13 18:17:37 -07:00
import frc4388.utility.controller.XboxController ;
2026-01-29 18:02:04 -07:00
import frc4388.utility.structs.LEDPatterns ;
2025-11-18 15:39:59 -08:00
import frc4388.robot.commands.MoveForTimeCommand ;
import frc4388.robot.constants.Constants ;
import frc4388.robot.constants.Constants.AutoConstants ;
2026-01-29 18:02:04 -07:00
import frc4388.robot.constants.Constants.LEDConstants ;
2025-11-18 15:39:59 -08:00
import frc4388.robot.constants.Constants.OIConstants ;
import frc4388.robot.constants.Constants.SimConstants.Mode ;
2026-01-19 13:42:16 -07:00
import frc4388.robot.constants.FieldConstants ;
2025-11-18 15:39:59 -08:00
// Subsystems
import frc4388.robot.subsystems.LED ;
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-02-07 14:51:05 -07:00
import frc4388.robot.subsystems.shooter.Shooter ;
2026-02-09 17:18:54 -08:00
import frc4388.robot.subsystems.shooter.Shooter.ShooterMode ;
2025-11-18 15:39:59 -08:00
import frc4388.robot.subsystems.swerve.SwerveDrive ;
import frc4388.robot.subsystems.vision.Vision ;
2026-01-19 13:42:16 -07:00
import frc4388.utility.DeferredBlock ;
2026-02-11 15:18:12 -07:00
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 ;
2026-01-29 18:07:19 -07:00
import frc4388.utility.structs.LEDPatterns ;
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 */
public final RobotMap m_robotMap = new RobotMap ( Mode . REAL ) ;
/* Subsystems */
2026-01-29 18:02:04 -07:00
public final LED m_robotLED = new LED ( LEDConstants . LED_SPARK_ID ) ;
2026-01-08 19:42:41 -07:00
public final Vision m_vision = new Vision ( ) ;
// public final Elevator m_robotElevator = new Elevator(m_robotMap.elevatorIO, m_robotLED);
2026-01-29 18:02:04 -07:00
// public final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.swerveDrivetrain, m_vision);
2025-11-18 15:39:59 -08:00
// public final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.swerveDrivetrain);
2026-01-08 19:42:41 -07:00
// public final LiDAR reefLidar = new LiDAR(m_robotMap.reefLidar, "Reef");
// public final LiDAR reverseLidar = new LiDAR(m_robotMap.reverseLidar, "Reverse");
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-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<>();
// ! Teleop Commands
2026-01-29 18:02:04 -07:00
// 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
// ! /* Autos */
private SendableChooser < String > autoChooser ;
private Command autoCommand ;
2026-02-07 14:51:05 -07:00
// private Command RobotShoot = new SequentialCommandGroup(
// new InstantCommand(() -> System.out.println(m_robotLED.getMode())),
// new InstantCommand(() -> m_robotLED.setMode(LEDPatterns.PARTY_TWINKLES), m_robotLED),
// new InstantCommand(() -> System.out.println(m_robotLED.getMode())),
// new WaitCommand(5),
// new InstantCommand(() -> m_robotLED.setMode(LEDPatterns.SOLID_RED), m_robotLED),
// new InstantCommand(() -> System.out.println(m_robotLED.getMode()))
// );
2026-02-09 17:18:54 -08:00
// private Command RobotShoot = new SequentialCommandGroup(
// new InstantCommand(() -> m_robotShooter.setMode(Shooter.ShooterMode.Active), m_robotShooter)
// );
2026-02-07 14:51:05 -07:00
2026-02-09 17:18:54 -08:00
// private Command RobotIntake = new SequentialCommandGroup(
// new InstantCommand(() -> m_robotIntake.setMode(Intake.IntakeMode.Down), m_robotIntake)
// );
2026-01-13 18:17:37 -07:00
public RobotContainer ( ) {
configureButtonBindings ( ) ;
2026-01-29 18:02:04 -07:00
// DeferredBlock.addBlock(() -> { // Called on first robot enable
// m_robotSwerveDrive.resetGyro();
// }, false);
2026-01-13 18:17:37 -07:00
DeferredBlock . addBlock ( ( ) - > { // Called on every robot enable
TimesNegativeOne . update ( ) ;
2026-02-11 15:18:12 -07:00
FieldPositions . update ( ) ;
2026-01-13 18:17:37 -07:00
} , true ) ;
DriverStation . silenceJoystickConnectionWarning ( true ) ;
2026-01-29 18:02:04 -07:00
// m_robotSwerveDrive.setDefaultCommand(new RunCommand(() -> {
// // IF the driver is holding the aim button, aim the robot towards the hub
// if(m_driverXbox.getRightTriggerAxis() > 0.5) {
// // Aim
// Translation2d shootTarget = new Translation2d();
// // new Rotation2()
// Rotation2d ang = m_robotSwerveDrive.getPose2d().getTranslation().minus(shootTarget).getAngle();
// m_robotSwerveDrive.driveFieldAngle(
// getDeadbandedDriverController().getLeft(),
// ang);
// } else {
// // Drive normally
// m_robotSwerveDrive.driveWithInput(
// getDeadbandedDriverController().getLeft(),
// getDeadbandedDriverController().getRight(),true);
// }
// }, m_robotSwerveDrive)
// .withName("SwerveDrive DefaultCommand"));
// m_robotSwerveDrive.setToSlow();
2026-01-13 18:17:37 -07:00
}
2025-11-18 15:39:59 -08:00
2026-01-13 18:17:37 -07:00
2025-11-18 15:39:59 -08:00
/**
2026-01-13 18:17:37 -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}.
2025-11-18 15:39:59 -08:00
*/
2026-01-13 18:17:37 -07:00
private void configureButtonBindings ( ) {
2025-11-18 15:39:59 -08:00
2026-01-13 18:17:37 -07:00
2026-01-29 18:02:04 -07:00
// new JoystickButton(getDeadbandedDriverController(), XboxController.A_BUTTON)
// .onTrue(new InstantCommand(() -> m_robotSwerveDrive.resetGyro()));
2026-01-13 18:17:37 -07:00
new JoystickButton ( getDeadbandedDriverController ( ) , XboxController . A_BUTTON )
2026-01-29 18:02:04 -07:00
. onTrue ( new InstantCommand ( ( ) - > m_robotLED . setMode ( LEDPatterns . C1C2_GRADIENT ) ) ) ;
2026-01-13 18:17:37 -07:00
2026-01-29 18:02:04 -07:00
new JoystickButton ( getDeadbandedDriverController ( ) , XboxController . B_BUTTON )
. onTrue ( new InstantCommand ( ( ) - > m_robotLED . setMode ( LEDPatterns . OCEAN_RAINBOW ) ) ) ;
new JoystickButton ( getDeadbandedDriverController ( ) , XboxController . Y_BUTTON )
. onTrue ( new InstantCommand ( ( ) - > m_robotLED . setMode ( LEDPatterns . RAINBOW_RAINBOW ) ) ) ;
new JoystickButton ( getDeadbandedDriverController ( ) , XboxController . BACK_BUTTON )
. onTrue ( new InstantCommand ( ( ) - > m_robotLED . setTo5V ( ) ) ) ;
2026-01-13 18:17:37 -07:00
2026-02-09 17:18:54 -08:00
// new Trigger(() -> getDeadbandedDriverController().getRightTriggerAxis() >= 0.8 && !operatorManualMode)
// .onTrue(RobotShoot)
// .onFalse(new InstantCommand(() -> m_robotShooter.setMode(Shooter.ShooterMode.Resting), m_robotShooter));
2026-02-07 14:51:05 -07:00
2026-02-09 17:18:54 -08:00
// new Trigger(() -> getDeadbandedDriverController().getLeftTriggerAxis() >= 0.8 && !operatorManualMode)
// .onTrue(RobotIntake)
// .onFalse(new InstantCommand(() -> m_robotIntake.setMode(Intake.IntakeMode.Up), m_robotShooter));
2026-01-13 18:17:37 -07:00
2026-01-29 18:02:04 -07:00
// new JoystickButton(getDeadbandedDriverController(), XboxController.B_BUTTON)
// .onTrue(new InstantCommand(() -> {m_robotSwerveDrive.softStop();}, m_robotSwerveDrive));
2025-11-18 15:39:59 -08:00
2026-01-29 18:02:04 -07:00
// new JoystickButton(getDeadbandedDriverController(), XboxController.RIGHT_BUMPER_BUTTON)
// .onTrue(new InstantCommand(() -> m_robotSwerveDrive.shiftUp()));
2026-01-13 19:41:42 -07:00
2026-01-29 18:02:04 -07:00
// new JoystickButton(getDeadbandedDriverController(), XboxController.LEFT_BUMPER_BUTTON)
// .onTrue(new InstantCommand(() -> m_robotSwerveDrive.shiftDown()));
2026-01-13 19:41:42 -07:00
2026-01-29 18:02:04 -07:00
// new JoystickButton(getDeadbandedDriverController(), XboxController.START_BUTTON)
// .onTrue(new InstantCommand(() -> m_robotSwerveDrive.activateLuigiMode()));
2026-01-13 19:41:42 -07:00
2026-01-29 18:02:04 -07:00
// new JoystickButton(getDeadbandedDriverController(), XboxController.BACK_BUTTON)
// .onTrue(new InstantCommand(() -> m_robotSwerveDrive.deactivateLuigiMode()));
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-01-29 18:02:04 -07:00
// autoChooserUpdated = true;
// if (filename.equals("Taxi")) {
// autoCommand = new SequentialCommandGroup(
// new MoveForTimeCommand(m_robotSwerveDrive,
// new Translation2d(0, -1),
// new Translation2d(), 1000, true
// ), new InstantCommand(()-> {m_robotSwerveDrive.softStop();} , m_robotSwerveDrive));
// } else {
// autoCommand = new PathPlannerAuto(filename);
// }
// System.out.println("Robot Auto Changed " + filename);
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;
// }
2025-11-18 15:39:59 -08:00
}