Skip to content

Commit 40d0be5

Browse files
Refactor ThriftyNova imports and encoder methods
1 parent 554c4f6 commit 40d0be5

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

lib/motor-controllers/thrifty-nova.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
export const getImports = () => `import com.thriftyrobotics.nova.hardware.ThriftyNova;
2-
import com.thriftyrobotics.nova.hardware.ThriftyEncoder;
3-
import com.thriftyrobotics.nova.controller.PIDController;
4-
import com.thriftyrobotics.nova.controller.ControlMode;
5-
import com.thriftyrobotics.nova.controller.NeutralMode;`
1+
export const getImports = () => `import com.thriftybot.devices.ThriftyNova;`
62

7-
export const getDeclaration = () => `private final ThriftyNova motor;
8-
private final ThriftyEncoder encoder;
9-
private final PIDController pidController;`
3+
export const getDeclaration = () => `private final ThriftyNova motor;`
104

115
export const getInitialization = () => `motor = new ThriftyNova(canID);
126
137
// Configure motor
14-
motor.setNeutralMode(brakeMode ? NeutralMode.BRAKE : NeutralMode.COAST);
15-
16-
// Configure encoder
17-
encoder = motor.getEncoder();
18-
encoder.setPosition(0);
8+
motor.setBrakeMode(brakeMode);
199
2010
// Configure PID controller
2111
pidController = motor.getPIDController();
@@ -46,9 +36,9 @@ export const getPeriodic = () => ``
4636
export const getSimulationPeriodic = () => ``
4737

4838
export const getMethods = () => ({
49-
getPositionMethod: `return encoder.getPosition() / gearRatio;`,
39+
getPositionMethod: `return encoder.getPositionQuad() / gearRatio;`,
5040

51-
getVelocityMethod: `return encoder.getVelocity() / gearRatio;`,
41+
getVelocityMethod: `return encoder.getVelocityQuad() / gearRatio;`,
5242

5343
setPositionMethod: `double adjustedPosition = position * gearRatio;
5444
double ffVolts = feedforward.calculate(getVelocity(), acceleration);

0 commit comments

Comments
 (0)