Skip to content
This repository was archived by the owner on Dec 6, 2025. It is now read-only.

Commit 11c7e15

Browse files
Merge pull request #348 from FRC5010/dev
2 parents 6ff6bda + aa82aa0 commit 11c7e15

File tree

5 files changed

+277
-144
lines changed

5 files changed

+277
-144
lines changed

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package swervelib.encoders;
22

3+
import com.thethriftybot.Conversion;
4+
import com.thethriftybot.Conversion.PositionUnit;
5+
import com.thethriftybot.Conversion.VelocityUnit;
6+
import com.thethriftybot.ThriftyNova;
7+
import com.thethriftybot.ThriftyNova.EncoderType;
8+
39
import swervelib.motors.SwerveMotor;
410
import swervelib.motors.ThriftyNovaSwerve;
511

@@ -12,7 +18,7 @@ public class ThriftyNovaEncoderSwerve extends SwerveAbsoluteEncoder
1218
/**
1319
* The absolute encoder is directly interfaced through the Thrifty Nova motor.
1420
*/
15-
protected ThriftyNovaSwerve motor;
21+
protected ThriftyNova motor;
1622
/**
1723
* Inversion state of the attached encoder.
1824
*/
@@ -21,7 +27,15 @@ public class ThriftyNovaEncoderSwerve extends SwerveAbsoluteEncoder
2127
* Offset of the absolute encoder.
2228
*/
2329
protected double offset = 0.0;
24-
30+
/**
31+
* Position conversion object for the motor encoder
32+
*/
33+
private Conversion positionConversion;
34+
/**
35+
* Velocity conversion object for the motor encoder
36+
*/
37+
private Conversion velocityConversion;
38+
2539
/**
2640
* Create the {@link ThriftyNovaEncoderSwerve} object as an absolute encoder from the {@link ThriftyNovaSwerve}
2741
* motor.
@@ -30,8 +44,10 @@ public class ThriftyNovaEncoderSwerve extends SwerveAbsoluteEncoder
3044
*/
3145
public ThriftyNovaEncoderSwerve(SwerveMotor motor)
3246
{
33-
this.motor = (ThriftyNovaSwerve) motor;
34-
motor.setAbsoluteEncoder(null);
47+
this.motor = (ThriftyNova) motor.getMotor();
48+
positionConversion = new Conversion(PositionUnit.DEGREES, EncoderType.ABS);
49+
velocityConversion = new Conversion(VelocityUnit.DEGREES_PER_SEC, EncoderType.ABS);
50+
this.motor.useEncoderType(EncoderType.ABS);
3551
}
3652

3753
@Override
@@ -40,7 +56,6 @@ public void close()
4056
// ThriftyNova encoder gets closed with the motor
4157
// I don't think an encoder getting closed should
4258
// close the entire motor so i will keep this empty
43-
// sparkFlex.close();
4459
}
4560

4661
/**
@@ -78,7 +93,9 @@ public void configure(boolean inverted)
7893
@Override
7994
public double getAbsolutePosition()
8095
{
81-
return (motor.getPosition() + offset) * (inverted ? -1.0 : 1.0);
96+
double rawMotor = motor.getPosition();
97+
double convertedMotor = positionConversion.fromMotor(rawMotor);
98+
return (convertedMotor + offset) * (inverted ? -1.0 : 1.0);
8299
}
83100

84101
/**
@@ -111,6 +128,6 @@ public boolean setAbsoluteEncoderOffset(double offset)
111128
@Override
112129
public double getVelocity()
113130
{
114-
return motor.getVelocity();
131+
return velocityConversion.fromMotor(motor.getVelocity()) * (inverted ? -1.0 : 1.0);
115132
}
116133
}

0 commit comments

Comments
 (0)