Skip to content

Commit

Permalink
refactor: make pivot encoder offset a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
mimizh2418 committed May 13, 2024
1 parent 4973d8c commit 8739d33
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/team1540/robot2024/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ public static class Pivot {
public static final int MOTOR_ID = 9;
public static final int CANCODER_ID = 10;


// TODO: determine ratios
public static final double CANCODER_TO_PIVOT = 28.0 / 15.0;
public static final double MOTOR_TO_CANCODER = 56.0;
public static final Rotation2d ENCODER_OFFSET = Rotation2d.fromRadians(0.01215595);

public static final double CHAIN_FACTOR = 1.04;
public static final double TOTAL_GEAR_RATIO = MOTOR_TO_CANCODER * CANCODER_TO_PIVOT;
Expand Down Expand Up @@ -192,7 +192,6 @@ public static class Pivot {
public static final double MAX_ACCEL_RPS2 = 2;
public static final double JERK_RPS3 = 2000;


public static final ShooterSetpoint HUB_SHOOT = new ShooterSetpoint(Rotation2d.fromRadians(1.06184));
public static final ShooterSetpoint PODIUM_SHOOT = new ShooterSetpoint(0.07, 6000,5000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public ShooterPivotIOTalonFX() {
motor.optimizeBusUtilization();
cancoder.optimizeBusUtilization();
motor.setPosition(
Rotation2d.fromRotations(absolutePosition.getValueAsDouble() / CANCODER_TO_PIVOT * CHAIN_FACTOR).plus(Rotation2d.fromRadians(0.03856 - 0.02649405)).getRotations()
Rotation2d.fromRotations(absolutePosition.getValueAsDouble() / CANCODER_TO_PIVOT * CHAIN_FACTOR).plus(ENCODER_OFFSET).getRotations()
);
}

Expand All @@ -99,12 +99,11 @@ public void updateInputs(ShooterPivotIOInputs inputs) {
inputs.isAtForwardLimit = forwardLimit.getValue() == ForwardLimitValue.ClosedToGround;
inputs.isAtReverseLimit = reverseLimit.getValue() == ReverseLimitValue.ClosedToGround;
inputs.position = Rotation2d.fromRotations(position.getValueAsDouble());
inputs.absolutePosition = Rotation2d.fromRotations(absolutePosition.getValueAsDouble() / CANCODER_TO_PIVOT * CHAIN_FACTOR).plus(Rotation2d.fromRadians(0.03865 - 0.02649405));
inputs.absolutePosition = Rotation2d.fromRotations(absolutePosition.getValueAsDouble() / CANCODER_TO_PIVOT * CHAIN_FACTOR).plus(ENCODER_OFFSET);
inputs.velocityRPS = velocity.getValueAsDouble();
inputs.appliedVolts = appliedVoltage.getValueAsDouble();
inputs.currentAmps = current.getValueAsDouble();
inputs.tempCelsius = temp.getValueAsDouble();

}

@Override
Expand Down

0 comments on commit 8739d33

Please sign in to comment.