Skip to content

Commit

Permalink
Added Auto-Optimization to module creation for backwards compatibilit…
Browse files Browse the repository at this point in the history
…y with MAX Swerve Modules.

Signed-off-by: thenetworkgrinch <thenetworkgrinch@users.noreply.github.com>
  • Loading branch information
thenetworkgrinch committed Aug 25, 2024
1 parent 0d35369 commit 4f7168b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/swervelib/parser/json/ModuleJson.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package swervelib.parser.json;

import com.revrobotics.AbsoluteEncoder;
import com.revrobotics.CANSparkMax;
import com.revrobotics.MotorFeedbackSensor;
import edu.wpi.first.math.util.Units;
Expand All @@ -11,6 +12,7 @@
import swervelib.parser.json.modules.BoolMotorJson;
import swervelib.parser.json.modules.ConversionFactorsJson;
import swervelib.parser.json.modules.LocationJson;
import swervelib.telemetry.Alert;

/**
* {@link swervelib.SwerveModule} JSON parsed class. Used to access the JSON data.
Expand Down Expand Up @@ -138,6 +140,13 @@ public SwerveModuleConfiguration createModuleConfiguration(
"Conversion factors cannot be 0, please configure conversion factors in physicalproperties.json or the module JSON files.");
}

// Backwards compatibility, auto-optimization.
if (conversionFactor.angle == 360 && absEncoder != null &&
absEncoder.getAbsoluteEncoder() instanceof AbsoluteEncoder && angleMotor.getMotor() instanceof CANSparkMax)
{
angleMotor.setAbsoluteEncoder(absEncoder);
}

return new SwerveModuleConfiguration(
drive.createMotor(true),
angleMotor,
Expand Down

0 comments on commit 4f7168b

Please sign in to comment.