Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tested Turret Absolute Encoder #109

Merged
merged 3 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public static class constTurret {
public static final double GEAR_RATIO = 39;
public static final NeutralModeValue NEUTRAL_MODE_VALUE = NeutralModeValue.Brake;

public static final double ABS_ENCODER_OFFSET = 0.812425;
public static final boolean ABS_ENCODER_INVERT = true;

/**
* The position, in meters, of the center of the turret relative to the center
* of the robot (Robot Coordinates).
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/frc/robot/RobotPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,6 @@ public static final class prefTurret {
public static final SN_DoublePreference turretI = new SN_DoublePreference("turretI", 0);
public static final SN_DoublePreference turretD = new SN_DoublePreference("turretD", 1);

public static final SN_DoublePreference turretAbsoluteEncoderOffset = new SN_DoublePreference(
"turretAbsoluteEncoderOffset", 0.811603);

public static final SN_DoublePreference turretDebugAngle = new SN_DoublePreference("turretDebugAngle", 90);
public static final SN_BooleanPreference turretInverted = new SN_BooleanPreference("turretInverted", false);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/subsystems/Turret.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Turret() {
turretMotor = new TalonFX(mapTurret.TURRET_MOTOR_CAN);
absoluteEncoder = new DutyCycleEncoder(mapTurret.TURRET_ABSOLUTE_ENCODER_DIO);
turretConfig = new TalonFXConfiguration();
absoluteEncoderOffset = prefTurret.turretAbsoluteEncoderOffset.getValue();
absoluteEncoderOffset = constTurret.ABS_ENCODER_OFFSET;

positionRequest = new PositionVoltage(0);
voltageRequest = new VoltageOut(0);
Expand Down Expand Up @@ -90,7 +90,7 @@ public void setTurretVoltage(double voltage) {
* Reset the turret encoder motor to absolute encoder's value
*/
public void resetTurretToAbsolutePosition() {
turretMotor.setPosition(getAbsoluteEncoder());
turretMotor.setPosition((constTurret.ABS_ENCODER_INVERT) ? -getAbsoluteEncoder() : getAbsoluteEncoder());
}

// "Get" Methods
Expand Down