Skip to content

Commit e2b5cc6

Browse files
authored
Set ThriftyNova External Encoder type using reflection (#349)
1 parent 11c7e15 commit e2b5cc6

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/main/java/swervelib/encoders/ThriftyNovaEncoderSwerve.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.thethriftybot.Conversion.VelocityUnit;
66
import com.thethriftybot.ThriftyNova;
77
import com.thethriftybot.ThriftyNova.EncoderType;
8+
import com.thethriftybot.ThriftyNova.ExternalEncoder;
89

910
import swervelib.motors.SwerveMotor;
1011
import swervelib.motors.ThriftyNovaSwerve;
@@ -42,11 +43,12 @@ public class ThriftyNovaEncoderSwerve extends SwerveAbsoluteEncoder
4243
*
4344
* @param motor {@link SwerveMotor} through which to interface with the attached encoder .
4445
*/
45-
public ThriftyNovaEncoderSwerve(SwerveMotor motor)
46+
public ThriftyNovaEncoderSwerve(SwerveMotor motor, String encoderType)
4647
{
4748
this.motor = (ThriftyNova) motor.getMotor();
4849
positionConversion = new Conversion(PositionUnit.DEGREES, EncoderType.ABS);
4950
velocityConversion = new Conversion(VelocityUnit.DEGREES_PER_SEC, EncoderType.ABS);
51+
this.motor.setExternalEncoder(ExternalEncoder.valueOf(encoderType));
5052
this.motor.useEncoderType(EncoderType.ABS);
5153
}
5254

src/main/java/swervelib/parser/json/DeviceJson.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,21 @@ public SwerveAbsoluteEncoder createEncoder(SwerveMotor motor)
111111
return new TalonSRXEncoderSwerve(motor, FeedbackDevice.PulseWidthEncodedPosition);
112112
case "talonsrx_analog":
113113
return new TalonSRXEncoderSwerve(motor, FeedbackDevice.Analog);
114-
case "thrifty_nova":
114+
case "thrifty_nova_rev":
115115
return ReflectionsManager.<SwerveAbsoluteEncoder>create(VENDOR.THRIFTYBOT,
116-
"com.thethriftybot.ThriftyNova",
117-
new Class[]{SwerveMotor.class},
118-
new Object[]{motor});
116+
"swervelib.encoders.ThriftyNovaEncoderSwerve",
117+
new Class[]{SwerveMotor.class, String.class},
118+
new Object[]{motor, "REV_ENCODER"});
119+
case "thrifty_nova_redux":
120+
return ReflectionsManager.<SwerveAbsoluteEncoder>create(VENDOR.THRIFTYBOT,
121+
"swervelib.encoders.ThriftyNovaEncoderSwerve",
122+
new Class[]{SwerveMotor.class, String.class},
123+
new Object[]{motor, "REDUX_ENCODER"});
124+
case "thrifty_nova_srx_mag":
125+
return ReflectionsManager.<SwerveAbsoluteEncoder>create(VENDOR.THRIFTYBOT,
126+
"swervelib.encoders.ThriftyNovaEncoderSwerve",
127+
new Class[]{SwerveMotor.class, String.class},
128+
new Object[]{motor, "SRX_MAG_ENCODER"});
119129
default:
120130
throw new RuntimeException(type + " is not a recognized absolute encoder type.");
121131
}

0 commit comments

Comments
 (0)