Skip to content

Commit

Permalink
Good turn to angle 😋
Browse files Browse the repository at this point in the history
  • Loading branch information
silverx257 committed Oct 26, 2024
1 parent b4a7c76 commit 625f07e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
29 changes: 11 additions & 18 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ public void initDefaultCommands_teleop() {
() -> {
if (swerveDrive.getTurnToAngleMode()) {
return (
driverController.getRightX() > 0.0
|| driverController.getRightY() > 0.0
Math.abs(driverController.getRightX()) > 0.05
|| Math.abs(driverController.getRightY()) > 0.05
);
}
else {
Expand All @@ -182,23 +182,16 @@ public void initDefaultCommands_teleop() {
},
// () -> false, // Turn to angle (disabled)
() -> { // Turn To angle Direction
if (Math.abs(driverController.getRightY()) > Math.abs(driverController.getRightX())) {
if (driverController.getRightY() < 0) {
return 0.0;
double xValue = commandDriverController.getRightX();
double yValue = commandDriverController.getRightY();
double magnitude = Math.sqrt((xValue*xValue) + (yValue*yValue));
if (magnitude > 0.49) {
double angle = (90 + NerdyMath.radiansToDegrees(Math.atan2(commandDriverController.getRightY(), commandDriverController.getRightX())));
angle = (((-1 * angle) % 360) + 360) % 360;
SmartDashboard.putNumber("desired angle", angle);
return angle;
}
else if (driverController.getRightY() > 0) {
return 180.0;
}
}
else if ((Math.abs(driverController.getRightY()) < Math.abs(driverController.getRightX()))) {
if (driverController.getRightX() < 0) {
return 90.0;
}
else if (driverController.getRightX() > 0) {
return 270.0;
}
}
return 0.0;
return 1000.0;
});

swerveDrive.setDefaultCommand(swerveJoystickCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ public Command turnToSubwoofer(double angleTolerance) {
return command;
}

public boolean turnToAngleMode = false;
public boolean turnToAngleMode = true;

public Command toggleTurnToAngleMode() {
return Commands.runOnce(() -> turnToAngleMode = !turnToAngleMode);
Expand Down

0 comments on commit 625f07e

Please sign in to comment.