Reefscape-2025/src/main/java/frc/robot/RobotContainer.java

86 lines
3.7 KiB
Java
Raw Normal View History

2025-01-27 18:21:18 -05: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.
package frc.robot;
2025-01-30 19:18:56 -05:00
import static edu.wpi.first.units.Units.*;
import com.ctre.phoenix6.swerve.SwerveModule.DriveRequestType;
import com.ctre.phoenix6.mechanisms.swerve.LegacySwerveRequest.PointWheelsAt;
import com.ctre.phoenix6.swerve.SwerveRequest;
import com.pathplanner.lib.auto.AutoBuilder;
import com.pathplanner.lib.auto.NamedCommands;
import edu.wpi.first.cameraserver.CameraServer;
2025-02-10 18:33:37 -05:00
import edu.wpi.first.math.MathUtil;
2025-01-30 19:18:56 -05:00
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
2025-01-27 18:21:18 -05:00
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
2025-02-10 19:11:48 -05:00
import edu.wpi.first.wpilibj2.command.ParallelCommandGroup;
2025-01-30 19:18:56 -05:00
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction;
import frc.robot.TunerConstants.TunerConstants;
2025-02-10 19:11:48 -05:00
import frc.robot.commands.RainBow;
import frc.robot.subsystems.Bougie;
2025-01-30 19:18:56 -05:00
import frc.robot.subsystems.CommandSwerveDrivetrain;
import frc.robot.subsystems.Grimpeur;
2025-01-27 18:21:18 -05:00
public class RobotContainer {
2025-01-30 19:18:56 -05:00
private double MaxSpeed = TunerConstants.kSpeedAt12Volts.in(MetersPerSecond); // kSpeedAt12Volts desired top speed
private double MaxAngularRate = RotationsPerSecond.of(0.75).in(RadiansPerSecond); // 3/4 of a rotation per second max angular velocity
/* Setting up bindings for necessary control of the swerve drive platform */
private final SwerveRequest.FieldCentric drive = new SwerveRequest.FieldCentric()
.withDeadband(MaxSpeed * 0.1).withRotationalDeadband(MaxAngularRate * 0.1) // Add a 10% deadband
.withDriveRequestType(DriveRequestType.OpenLoopVoltage); // Use open-loop control for drive motors
private final Telemetry logger = new Telemetry(MaxSpeed);
2025-02-06 17:59:57 -05:00
private final CommandXboxController manette1 = new CommandXboxController(0);
private final CommandXboxController manette2 = new CommandXboxController(0);
2025-01-30 19:18:56 -05:00
public final CommandSwerveDrivetrain drivetrain = TunerConstants.createDrivetrain();
private final SendableChooser<Command> autoChooser;
2025-02-10 19:11:48 -05:00
Bougie bougie = new Bougie();
2025-01-30 19:18:56 -05:00
public RobotContainer() {
autoChooser = AutoBuilder.buildAutoChooser("New Auto");
SmartDashboard.putData("Auto Mode", autoChooser);
2025-02-06 18:03:36 -05:00
configureBindings();
}
private void configureBindings() {
// Note that X is defined as forward according to WPILib convention,
// and Y is defined as to the left according to WPILib convention.
2025-01-30 19:18:56 -05:00
drivetrain.setDefaultCommand(
// Drivetrain will execute this command periodically
drivetrain.applyRequest(() ->
2025-02-10 18:33:37 -05:00
drive.withVelocityX(MathUtil.applyDeadband(-manette1.getLeftY(), 0.5)) // Drive forward with negative Y (forward)
.withVelocityY(MathUtil.applyDeadband(-manette1.getLeftX(), 0.5)) // Drive left with negative X (left)
.withRotationalRate(MathUtil.applyDeadband(-manette1.getRightX()*MaxAngularRate, 0.5)) // Drive counterclockwise with negative X (left)
2025-01-30 19:18:56 -05:00
)
);
// reset the field-centric heading on left bumper press
2025-02-06 18:43:16 -05:00
manette1.start().onTrue(drivetrain.runOnce(() -> drivetrain.seedFieldCentric()));
2025-01-27 18:21:18 -05:00
2025-01-30 19:18:56 -05:00
drivetrain.registerTelemetry(logger::telemeterize);
}
2025-01-27 18:21:18 -05:00
2025-02-10 19:11:48 -05:00
public Command getAutonomousCommand() {
2025-02-12 18:40:27 -05:00
return new ParallelCommandGroup(
autoChooser.getSelected(),
new RainBow(bougie));
2025-02-10 19:11:48 -05:00
}
2025-01-27 18:21:18 -05:00
}