Skip to content

Commit

Permalink
Update getDriveBaseRadiusMeters() to find a better radius
Browse files Browse the repository at this point in the history
No longer relies on the front Left being the largest or equal radius.
  • Loading branch information
Technologyman00 committed Jan 17, 2024
1 parent ae6f1c2 commit 480bf99
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/java/swervelib/parser/SwerveDriveConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,19 @@ public SwerveModule[] createModules(SwerveModuleConfiguration[] swerves, SimpleM
*/
public double getDriveBaseRadiusMeters()
{
Translation2d furthestModule = moduleLocationsMeters[0];
return Math.abs(Math.sqrt(Math.pow(furthestModule.getX(), 2) + Math.pow(furthestModule.getY(), 2)));
//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]);

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

//Return Largest Radius
return largestRadius;
}
}

0 comments on commit 480bf99

Please sign in to comment.