Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.

Commit 8f0ed77

Browse files
Added SwerveDrive.getGyro(). reformatted code.
Signed-off-by: thenetworkgrinch <thenetworkgrinch@users.noreply.github.com>
1 parent d153712 commit 8f0ed77

File tree

4 files changed

+32
-23
lines changed

4 files changed

+32
-23
lines changed

src/main/java/swervelib/SwerveDrive.java

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,7 @@ public void drive(ChassisSpeeds velocity, boolean isOpenLoop, Translation2d cent
451451
{
452452
velocity.omegaRadiansPerSecond =
453453
swerveController.headingCalculate(getOdometryHeading().getRadians(), lastHeadingRadians);
454-
}
455-
else
454+
} else
456455
{
457456
lastHeadingRadians = getOdometryHeading().getRadians();
458457
}
@@ -679,6 +678,33 @@ public SwerveModulePosition[] getModulePositions()
679678
return positions;
680679
}
681680

681+
/**
682+
* Getter for the {@link SwerveIMU}.
683+
*
684+
* @return generated {@link SwerveIMU}
685+
*/
686+
public SwerveIMU getGyro()
687+
{
688+
return swerveDriveConfiguration.imu;
689+
}
690+
691+
/**
692+
* Set the expected gyroscope angle using a {@link Rotation3d} object. To reset gyro, set to a new {@link Rotation3d}
693+
* subtracted from the current gyroscopic readings {@link SwerveIMU#getRotation3d()}.
694+
*
695+
* @param gyro expected gyroscope angle as {@link Rotation3d}.
696+
*/
697+
public void setGyro(Rotation3d gyro)
698+
{
699+
if (SwerveDriveTelemetry.isSimulation)
700+
{
701+
setGyroOffset(simIMU.getGyroRotation3d().minus(gyro));
702+
} else
703+
{
704+
setGyroOffset(imu.getRawRotation3d().minus(gyro));
705+
}
706+
}
707+
682708
/**
683709
* Resets the gyro angle to zero and resets odometry to the same position, but facing toward 0.
684710
*/
@@ -1042,24 +1068,6 @@ public void addVisionMeasurement(Pose2d robotPose, double timestamp)
10421068
// resetOdometry(newOdometry);
10431069
}
10441070

1045-
1046-
/**
1047-
* Set the expected gyroscope angle using a {@link Rotation3d} object. To reset gyro, set to a new {@link Rotation3d}
1048-
* subtracted from the current gyroscopic readings {@link SwerveIMU#getRotation3d()}.
1049-
*
1050-
* @param gyro expected gyroscope angle as {@link Rotation3d}.
1051-
*/
1052-
public void setGyro(Rotation3d gyro)
1053-
{
1054-
if (SwerveDriveTelemetry.isSimulation)
1055-
{
1056-
setGyroOffset(simIMU.getGyroRotation3d().minus(gyro));
1057-
} else
1058-
{
1059-
setGyroOffset(imu.getRawRotation3d().minus(gyro));
1060-
}
1061-
}
1062-
10631071
/**
10641072
* Helper function to get the {@link SwerveDrive#swerveController} for the {@link SwerveDrive} which can be used to
10651073
* generate {@link ChassisSpeeds} for the robot to orient it correctly given axis or angles, and apply

src/main/java/swervelib/SwerveModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ public void setDesiredState(SwerveModuleState desiredState, boolean isOpenLoop,
205205
} else
206206
{
207207
double cosineScalar = 1.0;
208-
if (configuration.useCosineCompensator) {
208+
if (configuration.useCosineCompensator)
209+
{
209210
// Taken from the CTRE SwerveModule class.
210211
// https://api.ctr-electronics.com/phoenix6/release/java/src-html/com/ctre/phoenix6/mechanisms/swerve/SwerveModule.html#line.46
211212
/* From FRC 900's whitepaper, we add a cosine compensator to the applied drive velocity */

src/main/java/swervelib/parser/SwerveModuleConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public SwerveModuleConfiguration(
164164
false,
165165
false,
166166
false,
167-
name,
167+
name,
168168
useCosineCompensator);
169169
}
170170

src/main/java/swervelib/parser/json/ModuleJson.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class ModuleJson
5656
/**
5757
* Should do cosine compensation when not pointing correct direction;.
5858
*/
59-
public boolean useCosineCompensator = true;
59+
public boolean useCosineCompensator = true;
6060

6161
/**
6262
* Create the swerve module configuration based off of parsed data.

0 commit comments

Comments
 (0)