Skip to content
This repository was archived by the owner on Aug 23, 2025. It is now read-only.

Commit 20f324e

Browse files
John-CamsShasshUNewbie9012
committed
Added turntoAngle
Binded turntoAngle to a controller button. Co-Authored-By: ShasshU <[email protected]> Co-Authored-By: Newbie9012 <[email protected]>
1 parent 802b6d2 commit 20f324e

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/main/java/frc/robot/RobotContainer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public class RobotContainer {
7676

7777
public CANdleSubSystem CANdle = new CANdleSubSystem();
7878
private SwerveJoystickCommand swerveJoystickCommand;
79-
public boolean turnToAngleMode = false;
8079

8180
/**
8281
* The container for the robot. Contain
@@ -171,7 +170,7 @@ public void initDefaultCommands_teleop() {
171170
// driverController::getR2Button, // Precision/"Sniper Button"
172171
() -> driverController.getR2Button(), // Precision mode (disabled)
173172
() -> {
174-
if (turnToAngleMode) {
173+
if (swerveDrive.getTurnToAngleMode()) {
175174
return (
176175
driverController.getRightX() > 0.0
177176
|| driverController.getRightY() > 0.0
@@ -306,6 +305,8 @@ public void configureBindings_teleop() {
306305
)
307306
);
308307

308+
309+
309310
commandOperatorController.povUp().onTrue(
310311
Commands.runOnce(() -> superSystem.incrementOffset(0.5))
311312
);
@@ -317,7 +318,7 @@ public void configureBindings_teleop() {
317318
);
318319
commandDriverController.touchpad().whileTrue(superSystem.shoot())
319320
.whileFalse(superSystem.stow());
320-
commandDriverController.
321+
commandDriverController.triangle().onTrue(swerveDrive.toggleTurnToAngleMode());
321322

322323
commandDriverController.L2().whileTrue(Commands.sequence(
323324
Commands.race(

src/main/java/frc/robot/commands/SwerveJoystickCommand.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import edu.wpi.first.math.kinematics.SwerveModuleState;
1717
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1818
import edu.wpi.first.wpilibj2.command.Command;
19+
import edu.wpi.first.wpilibj2.command.Commands;
1920
import frc.robot.Constants.ControllerConstants;
2021
import frc.robot.Constants.SwerveAutoConstants;
2122
import frc.robot.Constants.SwerveDriveConstants;
@@ -26,7 +27,6 @@
2627
import frc.robot.util.filters.Filter;
2728
import frc.robot.util.filters.FilterSeries;
2829
import frc.robot.util.filters.ScaleFilter;
29-
3030
public class SwerveJoystickCommand extends Command {
3131
private final SwerveDrivetrain swerveDrive;
3232
private final Supplier<Double> xSpdFunction, ySpdFunction, turningSpdFunction;
@@ -122,6 +122,7 @@ public void initialize() {}
122122

123123
@Override
124124
public void execute() {
125+
125126
if (towSupplier.get()) {
126127
swerveDrive.setModuleStates(SwerveDriveConstants.towModuleStates);
127128
return;
@@ -199,6 +200,9 @@ public void execute() {
199200

200201
}
201202

203+
204+
205+
202206
public double getTargetAngle() {
203207
return targetAngle;
204208
}

src/main/java/frc/robot/subsystems/swerve/SwerveDrivetrain.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,17 @@ public Command turnToSubwoofer(double angleTolerance) {
479479
command.addRequirements(this);
480480
return command;
481481
}
482+
483+
public boolean turnToAngleMode = false;
484+
485+
public Command toggleTurnToAngleMode() {
486+
return Commands.runOnce(() -> turnToAngleMode = !turnToAngleMode);
487+
}
488+
489+
public boolean getTurnToAngleMode() {
490+
return turnToAngleMode;
491+
}
492+
482493
/**
483494
* Get the position of each swerve module
484495
* @return An array of swerve module positions

0 commit comments

Comments
 (0)