5
5
import com .ctre .phoenix6 .hardware .CANcoder ;
6
6
import com .ctre .phoenix6 .hardware .TalonFX ;
7
7
import com .ctre .phoenix6 .signals .AbsoluteSensorRangeValue ;
8
+ import com .ctre .phoenix6 .signals .FeedbackSensorSourceValue ;
8
9
import com .ctre .phoenix6 .signals .InvertedValue ;
9
10
import com .ctre .phoenix6 .signals .SensorDirectionValue ;
10
11
import org .team1540 .robot2024 .Constants ;
@@ -49,6 +50,11 @@ private SwerveModuleHW(int id, SwerveCorner corner, String canbus) {
49
50
if (canbus == null ) {
50
51
canbus = "" ;
51
52
}
53
+
54
+ int driveID = 30 + id ;
55
+ int turnID = 20 + id ;
56
+ int canCoderID = 10 + id ;
57
+
52
58
TalonFXConfiguration driveConfig = new TalonFXConfiguration ();
53
59
TalonFXConfiguration turnConfig = new TalonFXConfiguration ();
54
60
CANcoderConfiguration canCoderConfig = new CANcoderConfiguration ();
@@ -62,21 +68,23 @@ private SwerveModuleHW(int id, SwerveCorner corner, String canbus) {
62
68
turnConfig .CurrentLimits .SupplyCurrentLimit = 30.0 ;
63
69
turnConfig .CurrentLimits .SupplyCurrentLimitEnable = true ;
64
70
turnConfig .MotorOutput .Inverted = InvertedValue .Clockwise_Positive ;
71
+ turnConfig .Feedback .FeedbackRemoteSensorID = canCoderID ;
72
+ turnConfig .Feedback .FeedbackSensorSource = FeedbackSensorSourceValue .FusedCANcoder ;
73
+ turnConfig .Feedback .SensorToMechanismRatio = 1.0 ;
74
+ turnConfig .Feedback .RotorToSensorRatio = Constants .Drivetrain .TURN_GEAR_RATIO ;
65
75
66
76
canCoderConfig .MagnetSensor .MagnetOffset = moduleOffsetsRots [id -1 ] + corner .offsetRots ;
67
77
canCoderConfig .MagnetSensor .SensorDirection = SensorDirectionValue .CounterClockwise_Positive ;
68
78
canCoderConfig .MagnetSensor .AbsoluteSensorRange = AbsoluteSensorRangeValue .Unsigned_0To1 ;
69
79
70
- this .driveMotor = new TalonFX (30 + id , canbus );
80
+ this .driveMotor = new TalonFX (driveID , canbus );
71
81
this .driveMotor .getConfigurator ().apply (driveConfig );
72
82
73
- this .turnMotor = new TalonFX (20 + id , canbus );
83
+ this .cancoder = new CANcoder (canCoderID , canbus );
84
+ this .cancoder .getConfigurator ().apply (canCoderConfig );
74
85
86
+ this .turnMotor = new TalonFX (turnID , canbus );
75
87
this .turnMotor .getConfigurator ().apply (turnConfig );
76
-
77
- this .cancoder = new CANcoder (10 + id , canbus );
78
-
79
- this .cancoder .getConfigurator ().apply (canCoderConfig );
80
88
}
81
89
}
82
90
}
0 commit comments