Skip to content

Commit

Permalink
Merge pull request #175 from rickfmn/patch-2
Browse files Browse the repository at this point in the history
Update SwerveSubsystem.java
  • Loading branch information
thenetworkgrinch authored Mar 14, 2024
2 parents 752f202 + c749e3c commit b2ad475
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,32 @@ public void zeroGyro()
swerveDrive.zeroGyro();
}

/**
* Checks if the alliance is red, defaults to false if alliance isn't available.
* @return true if the red alliance, false if blue. Defaults to false if none is available.
*/
private boolean isRedAlliance()
{
var alliance = DriverStation.getAlliance();
return alliance.isPresent() ? alliance.get() == DriverStation.Alliance.Red : false;
}

/**
* This will zero (calibrate) the robot to assume the current position is facing forward
*
* If red alliance rotate the robot 180 after the drviebase zero command
*/
public void zeroGyroWithAlliance()
{
if (isRedAlliance()) {
zeroGyro();
//Set the pose 180 degrees
resetOdometry(new Pose2d(getPose().getTranslation(), Rotation2d.fromDegrees(180)));
} else {
zeroGyro();
}
}

/**
* Sets the drive motors to brake/coast mode.
*
Expand Down

0 comments on commit b2ad475

Please sign in to comment.