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

@@ -9,6 +9,7 @@ import swervelib.encoders.AnalogAbsoluteEncoderSwerve;
import swervelib.encoders.CANCoderSwerve;
import swervelib.encoders.CanAndCoderSwerve;
import swervelib.encoders.PWMDutyCycleEncoderSwerve;
import swervelib.encoders.SparkMaxAnalogEncoderSwerve;
import swervelib.encoders.SparkMaxEncoderSwerve;
import swervelib.encoders.SwerveAbsoluteEncoder;
import swervelib.imu.ADIS16448Swerve;
@@ -61,9 +62,12 @@ public class DeviceJson
switch (type)
{
case "none":
return null;
case "integrated":
case "attached":
return null;
return new SparkMaxEncoderSwerve(motor, 1);
case "sparkmax_analog":
return new SparkMaxAnalogEncoderSwerve(motor);
case "canandcoder":
return new SparkMaxEncoderSwerve(motor, 360);
case "canandcoder_can":
@@ -180,24 +184,4 @@ public class DeviceJson
throw new RuntimeException(type + " is not a recognized absolute encoder type.");
}
}
/**
* Create a {@link SwerveAbsoluteEncoder} from the data port on the motor controller.
*
* @param motor The motor to create the absolute encoder from.
* @return {@link SwerveAbsoluteEncoder} from the motor controller.
*/
public SwerveAbsoluteEncoder createIntegratedEncoder(SwerveMotor motor)
{
switch (type)
{
case "sparkmax":
return new SparkMaxEncoderSwerve(motor, 1);
case "falcon":
case "talonfx":
return null;
}
throw new RuntimeException(
"Could not create absolute encoder from data port of " + type + " id " + id);
}
}