Skip to content

Commit

Permalink
Reuse arrays for module states
Browse files Browse the repository at this point in the history
  • Loading branch information
thakurnilesh307 authored and griffey07 committed Feb 4, 2024
1 parent 05cf069 commit 5cdf069
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/main/java/frc/robot/drive/SwerveDrive.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class SwerveDrive extends RobotDriveBase {
private DoubleLogEntry omegaSpeedLog = new DoubleLogEntry(DataLogManager.getLog(), "/SwerveDrive/omegaSpeed");

private final SwerveModuleState[] moduleStates = new SwerveModuleState[4];
private final SwerveModulePosition[] modulePositions = new SwerveModulePosition[4];
private final SwerveModuleVelocities[] velocities = new SwerveModuleVelocities[4];
private final SwerveModuleVoltages[] motorVoltages = new SwerveModuleVoltages[4];

/**
* constructs the swerve drive
Expand Down Expand Up @@ -188,13 +191,11 @@ public ChassisSpeeds getChassisSpeeds() {
* @return Swerve module positions.
*/
public SwerveModulePosition[] getModulesPositions() {
SwerveModulePosition[] modulePosition = new SwerveModulePosition[4];

for (int i = 0; i < modules.length; i++) {
modulePosition[i] = modules[i].getPosition();
modulePositions[i] = modules[i].getPosition();
}

return modulePosition;
return modulePositions;
}

/**
Expand All @@ -203,8 +204,6 @@ public SwerveModulePosition[] getModulesPositions() {
* @return The swerve module velocities.
*/
public SwerveModuleVelocities[] getModuleVelocities() {
SwerveModuleVelocities[] velocities = new SwerveModuleVelocities[4];

for (int i = 0; i < modules.length; i++) {
velocities[i] = modules[i].getVelocities();
}
Expand All @@ -218,7 +217,6 @@ public SwerveModuleVelocities[] getModuleVelocities() {
* @return The module motor
*/
public SwerveModuleVoltages[] getModuleVoltages(){
SwerveModuleVoltages[] motorVoltages = new SwerveModuleVoltages[modules.length];
for (int i = 0; i < modules.length; i++) {
motorVoltages[i] = modules[i].getMotorVoltages();
}
Expand Down

0 comments on commit 5cdf069

Please sign in to comment.