Added support for CANandCoder

This commit is contained in:
thenetworkgrinch
2023-08-09 15:05:33 -05:00
parent d356dec4d0
commit f88fdfb6cf
4 changed files with 66 additions and 47 deletions

View File

@@ -49,27 +49,16 @@ public class DeviceJson
*/
public SwerveAbsoluteEncoder createEncoder(SwerveMotor motor)
{
SwerveAbsoluteEncoder attachedChoice = null;
switch (type)
{
case "none":
case "integrated":
case "attached":
if (motor instanceof SparkMaxBrushedMotorSwerve || motor instanceof SparkMaxSwerve)
{
attachedChoice = new SparkMaxEncoderSwerve(motor);
motor.setAbsoluteEncoder(attachedChoice);
} else if (motor instanceof TalonFXSwerve || motor instanceof TalonSRXSwerve)
{
motor.setAbsoluteEncoder(null);
} else
{
throw new RuntimeException(
"Could not create absolute encoder from data port of " + type + " id " + id);
}
return attachedChoice;
return null;
case "canandcoder":
return new CanAndCoderSwerve(motor);
return new SparkMaxEncoderSwerve(motor, 360);
case "canandcoder_can":
return new CanAndCoderSwerve(id);
case "thrifty":
case "throughbore":
case "dutycycle":
@@ -160,4 +149,24 @@ 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);
}
}