7
7
import com .ctre .phoenix6 .signals .AbsoluteSensorRangeValue ;
8
8
import com .ctre .phoenix6 .signals .InvertedValue ;
9
9
import com .ctre .phoenix6 .signals .SensorDirectionValue ;
10
- import edu .wpi .first .math .geometry .Rotation2d ;
11
10
import org .team1540 .robot2024 .Constants ;
12
11
13
12
public class SwerveFactory {
@@ -28,21 +27,20 @@ public static SwerveModuleHW getModuleMotors(int id, SwerveCorner corner) {
28
27
29
28
public enum SwerveCorner {
30
29
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 );
34
33
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 ;
38
37
}
39
38
}
40
39
41
40
public static class SwerveModuleHW {
42
41
public final TalonFX driveMotor ;
43
42
public final TalonFX turnMotor ;
44
43
public final CANcoder cancoder ;
45
- public final Rotation2d cancoderOffset ;
46
44
47
45
private SwerveModuleHW (int id , SwerveCorner corner , String canbus ) {
48
46
if (id < 1 || id > 8 ) {
@@ -65,7 +63,7 @@ private SwerveModuleHW(int id, SwerveCorner corner, String canbus) {
65
63
turnConfig .CurrentLimits .SupplyCurrentLimitEnable = true ;
66
64
turnConfig .MotorOutput .Inverted = InvertedValue .Clockwise_Positive ;
67
65
68
- canCoderConfig .MagnetSensor .MagnetOffset = moduleOffsetsRots [id -1 ];
66
+ canCoderConfig .MagnetSensor .MagnetOffset = moduleOffsetsRots [id -1 ] + corner . offsetRots ;
69
67
canCoderConfig .MagnetSensor .SensorDirection = SensorDirectionValue .CounterClockwise_Positive ;
70
68
canCoderConfig .MagnetSensor .AbsoluteSensorRange = AbsoluteSensorRangeValue .Unsigned_0To1 ;
71
69
@@ -78,12 +76,7 @@ private SwerveModuleHW(int id, SwerveCorner corner, String canbus) {
78
76
79
77
this .cancoder = new CANcoder (10 + id , canbus );
80
78
81
-
82
79
this .cancoder .getConfigurator ().apply (canCoderConfig );
83
-
84
- this .cancoderOffset = Rotation2d .fromDegrees (corner .offset );
85
-
86
-
87
80
}
88
81
}
89
82
}
0 commit comments