Skip to content

Commit

Permalink
Change ModuleIOSparkMax to use absolute encoder always
Browse files Browse the repository at this point in the history
  • Loading branch information
camearle20 committed Feb 10, 2024
1 parent 4b7b5f9 commit 0bcb944
Showing 1 changed file with 2 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ModuleIOSparkMax(ModuleConfig config) {
driveMotor.setCANTimeout(250);
turnMotor.setCANTimeout(250);

for (int i = 0; i < 4; i++) {
for (int i = 0; i < 30; i++) {
turnMotor.setInverted(config.turnMotorInverted());
driveMotor.setSmartCurrentLimit(40);
turnMotor.setSmartCurrentLimit(30);
Expand Down Expand Up @@ -104,17 +104,6 @@ public ModuleIOSparkMax(ModuleConfig config) {

@Override
public void updateInputs(ModuleIOInputs inputs) {
// Reset position of encoder to absolute position every shouldResetCount cycles
// Make sure turnMotor is not moving too fast
if (++resetCounter >= shouldResetCount
&& Units.rotationsPerMinuteToRadiansPerSecond(turnRelativeEncoder.getVelocity()) <= 0.1) {
for (int i = 0; i < 4; i++) {
turnRelativeEncoder.setPosition(
absoluteEncoderValue.get().getRotations() * moduleConstants.turnReduction());
}
resetCounter = 0;
}

inputs.drivePositionRad =
Units.rotationsToRadians(driveEncoder.getPosition() / moduleConstants.driveReduction());
inputs.driveVelocityRadPerSec =
Expand Down Expand Up @@ -169,9 +158,7 @@ public void setDriveVelocitySetpoint(double velocityRadsPerSec, double ffVolts)

@Override
public void setTurnPositionSetpoint(double angleRads) {
setTurnVoltage(
turnController.calculate(
Units.rotationsToRadians(turnRelativeEncoder.getPosition()), angleRads));
setTurnVoltage(turnController.calculate(absoluteEncoderValue.get().getRadians(), angleRads));
}

@Override
Expand Down

0 comments on commit 0bcb944

Please sign in to comment.