Added new SparkMAX analog encoder option, fixed 'none' absolute encoder type

This commit is contained in:
thenetworkgrinch
2023-12-05 16:25:42 -06:00
parent 04466ef81d
commit e0d572b5a5
126 changed files with 1012 additions and 343 deletions

View File

@@ -1,5 +1,7 @@
package swervelib.parser.json;
import com.revrobotics.CANSparkMax;
import com.revrobotics.MotorFeedbackSensor;
import edu.wpi.first.math.util.Units;
import swervelib.encoders.SwerveAbsoluteEncoder;
import swervelib.motors.SwerveMotor;
@@ -30,7 +32,7 @@ public class ModuleJson
* {@link swervelib.math.SwerveMath#calculateDegreesPerSteeringRotation(double, double)} for angle motors or
* {@link swervelib.math.SwerveMath#calculateMetersPerRotation(double, double, double)} for drive motors.
*/
public MotorConfigDouble conversionFactor = new MotorConfigDouble(0, 0);
public MotorConfigDouble conversionFactor = new MotorConfigDouble(0, 0);
/**
* Absolute encoder device configuration.
*/
@@ -71,10 +73,12 @@ public class ModuleJson
SwerveAbsoluteEncoder absEncoder = encoder.createEncoder(angleMotor);
// If the absolute encoder is attached.
if (absEncoder == null)
if (absEncoder != null && angleMotor.getMotor() instanceof CANSparkMax)
{
absEncoder = angle.createIntegratedEncoder(angleMotor);
angleMotor.setAbsoluteEncoder(absEncoder);
if (absEncoder.getAbsoluteEncoder() instanceof MotorFeedbackSensor)
{
angleMotor.setAbsoluteEncoder(absEncoder);
}
}
// Set the conversion factors to null if they are both 0.