Skip to content

Commit

Permalink
Merge pull request #150 from Blargleflakes/YAGSL_issue_44
Browse files Browse the repository at this point in the history
Heading correction logic now reads in current heading
  • Loading branch information
thenetworkgrinch authored Jan 26, 2024
2 parents 37e9c5e + 23fca48 commit 7089f41
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/main/java/swervelib/SwerveDrive.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ public class SwerveDrive
* Deadband for speeds in heading correction.
*/
private double HEADING_CORRECTION_DEADBAND = 0.01;
/**
* Whether heading correction PID is currently active.
*/
private boolean correctionEnabled = false;
/**
* Swerve IMU device for sensing the heading of the robot.
*/
Expand Down Expand Up @@ -453,16 +449,12 @@ public void drive(ChassisSpeeds velocity, boolean isOpenLoop, Translation2d cent
&& (Math.abs(velocity.vxMetersPerSecond) > HEADING_CORRECTION_DEADBAND
|| Math.abs(velocity.vyMetersPerSecond) > HEADING_CORRECTION_DEADBAND))
{
if (!correctionEnabled)
{
lastHeadingRadians = getOdometryHeading().getRadians();
correctionEnabled = true;
}
velocity.omegaRadiansPerSecond =
swerveController.headingCalculate(lastHeadingRadians, getOdometryHeading().getRadians());
} else
swerveController.headingCalculate(getOdometryHeading().getRadians(), lastHeadingRadians);
}
else
{
correctionEnabled = false;
lastHeadingRadians = getOdometryHeading().getRadians();
}
}

Expand Down

0 comments on commit 7089f41

Please sign in to comment.