Skip to content

Commit fb2088e

Browse files
committed
fix: make swerve offset units consistent, swerve offsets happen in the same place
1 parent 32d3ff0 commit fb2088e

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

src/main/java/org/team1540/robot2024/subsystems/drive/ModuleIOTalonFX.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,12 @@ public class ModuleIOTalonFX implements ModuleIO {
4343
private final StatusSignal<Double> turnAppliedVolts;
4444
private final StatusSignal<Double> turnCurrent;
4545

46-
private final Rotation2d absoluteEncoderOffset;
47-
4846
private final boolean isCANFD;
4947

5048
public ModuleIOTalonFX(SwerveFactory.SwerveModuleHW hw) {
5149
driveTalon = hw.driveMotor;
5250
turnTalon = hw.turnMotor;
5351
cancoder = hw.cancoder;
54-
absoluteEncoderOffset = hw.cancoderOffset;
5552

5653
isCANFD = CANBus.isNetworkFD(CAN_BUS);
5754

@@ -113,7 +110,7 @@ public void updateInputs(ModuleIOInputs inputs) {
113110
inputs.driveAppliedVolts = driveAppliedVolts.getValueAsDouble();
114111
inputs.driveCurrentAmps = driveCurrent.getValueAsDouble();
115112

116-
inputs.turnAbsolutePosition = Rotation2d.fromRotations(turnAbsolutePosition.getValueAsDouble()).plus(absoluteEncoderOffset);
113+
inputs.turnAbsolutePosition = Rotation2d.fromRotations(turnAbsolutePosition.getValueAsDouble());
117114
inputs.turnPosition = Rotation2d.fromRotations(turnPosition.getValueAsDouble() / TURN_GEAR_RATIO);
118115
inputs.turnVelocityRadPerSec = Units.rotationsToRadians(turnVelocity.getValueAsDouble()) / TURN_GEAR_RATIO;
119116
inputs.turnAppliedVolts = turnAppliedVolts.getValueAsDouble();

src/main/java/org/team1540/robot2024/util/swerve/SwerveFactory.java

+7-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.ctre.phoenix6.signals.AbsoluteSensorRangeValue;
88
import com.ctre.phoenix6.signals.InvertedValue;
99
import com.ctre.phoenix6.signals.SensorDirectionValue;
10-
import edu.wpi.first.math.geometry.Rotation2d;
1110
import org.team1540.robot2024.Constants;
1211

1312
public class SwerveFactory {
@@ -28,21 +27,20 @@ public static SwerveModuleHW getModuleMotors(int id, SwerveCorner corner) {
2827

2928
public enum SwerveCorner {
3029
FRONT_LEFT(0),
31-
FRONT_RIGHT(90),
32-
BACK_LEFT(270),
33-
BACK_RIGHT(180);
30+
FRONT_RIGHT(0.25),
31+
BACK_LEFT(0.75),
32+
BACK_RIGHT(0.5);
3433

35-
private final double offset;
36-
SwerveCorner(double offset) {
37-
this.offset = offset;
34+
private final double offsetRots;
35+
SwerveCorner(double offsetRots) {
36+
this.offsetRots = offsetRots;
3837
}
3938
}
4039

4140
public static class SwerveModuleHW {
4241
public final TalonFX driveMotor;
4342
public final TalonFX turnMotor;
4443
public final CANcoder cancoder;
45-
public final Rotation2d cancoderOffset;
4644

4745
private SwerveModuleHW(int id, SwerveCorner corner, String canbus) {
4846
if (id < 1 || id > 8) {
@@ -65,7 +63,7 @@ private SwerveModuleHW(int id, SwerveCorner corner, String canbus) {
6563
turnConfig.CurrentLimits.SupplyCurrentLimitEnable = true;
6664
turnConfig.MotorOutput.Inverted = InvertedValue.Clockwise_Positive;
6765

68-
canCoderConfig.MagnetSensor.MagnetOffset = moduleOffsetsRots[id-1];
66+
canCoderConfig.MagnetSensor.MagnetOffset = moduleOffsetsRots[id-1] + corner.offsetRots;
6967
canCoderConfig.MagnetSensor.SensorDirection = SensorDirectionValue.CounterClockwise_Positive;
7068
canCoderConfig.MagnetSensor.AbsoluteSensorRange = AbsoluteSensorRangeValue.Unsigned_0To1;
7169

@@ -78,12 +76,7 @@ private SwerveModuleHW(int id, SwerveCorner corner, String canbus) {
7876

7977
this.cancoder = new CANcoder(10 + id, canbus);
8078

81-
8279
this.cancoder.getConfigurator().apply(canCoderConfig);
83-
84-
this.cancoderOffset = Rotation2d.fromDegrees(corner.offset);
85-
86-
8780
}
8881
}
8982
}

0 commit comments

Comments
 (0)