Skip to content

Commit

Permalink
Fixed getDriveBaseRadiusMeters() as it incorrectly assumed there will…
Browse files Browse the repository at this point in the history
… always be 4 modules.

Previously assumed there would be 4 modules now allows for any amount greater than 2.
  • Loading branch information
Technologyman00 committed Jan 18, 2024
1 parent 480bf99 commit 93d91aa
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/main/java/swervelib/parser/SwerveDriveConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,14 @@ public SwerveModule[] createModules(SwerveModuleConfiguration[] swerves, SimpleM
*/
public double getDriveBaseRadiusMeters()
{
//Find Center of Robot by adding all module offsets together. Should be zero, but incase it isn't
Translation2d centerOfModules = moduleLocationsMeters[0].plus(moduleLocationsMeters[1])
.plus(moduleLocationsMeters[2]).plus(moduleLocationsMeters[3]);
Translation2d centerOfModules = moduleLocationsMeters[0];

//Find Largest Radius by checking the distance to the center point
double largestRadius = centerOfModules.getDistance(moduleLocationsMeters[0]);
//Calculate the Center by adding all module offsets together.
for(int i=1; i<moduleLocationsMeters.length; i++){
if(largestRadius < centerOfModules.getDistance(moduleLocationsMeters[i])){
largestRadius = centerOfModules.getDistance(moduleLocationsMeters[i]);
}
}
centerOfModules = centerOfModules.plus(moduleLocationsMeters[i]);
}

//Return Largest Radius
return largestRadius;
return centerOfModules.getDistance(moduleLocationsMeters[0]);
}
}

0 comments on commit 93d91aa

Please sign in to comment.