File tree Expand file tree Collapse file tree
src/main/java/frc/robot/subsystems/drive Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -73,6 +73,9 @@ public class Drive extends SubsystemBase {
7373 static final double ODOMETRY_FREQUENCY = new CANBus (CompTunerConstants .DrivetrainConstants .CANBusName ).isNetworkFD () ? 250.0 : 100.0 ;
7474 public final double DRIVE_BASE_RADIUS ;
7575
76+ // Gyro degrees-per-rotation correction/trim
77+ static final double GYRO_YAW_DEG_PER_ROT_CORRECTION = -0.97 ;
78+
7679 // These constants should change for every drivebase
7780 private final LinearVelocity SPEED_12_VOLTS ;
7881 private final RobotConfig PP_CONFIG ;
Original file line number Diff line number Diff line change 1919import com .ctre .phoenix6 .CANBus ;
2020import com .ctre .phoenix6 .StatusCode ;
2121import com .ctre .phoenix6 .StatusSignal ;
22+ import com .ctre .phoenix6 .configs .GyroTrimConfigs ;
2223import com .ctre .phoenix6 .configs .Pigeon2Configuration ;
2324import com .ctre .phoenix6 .hardware .Pigeon2 ;
2425
@@ -41,14 +42,18 @@ public GyroIOPigeon2(int Pigeon2Id, CANBus bus) {
4142 pigeon = new Pigeon2 (Pigeon2Id , bus );
4243 yaw = pigeon .getYaw ();
4344 yawVelocity = pigeon .getAngularVelocityZWorld ();
44-
4545 pigeon .getConfigurator ().apply (new Pigeon2Configuration ());
4646 pigeon .getConfigurator ().setYaw (0.0 );
4747 yaw .setUpdateFrequency (Drive .ODOMETRY_FREQUENCY );
4848 yawVelocity .setUpdateFrequency (50.0 );
4949 pigeon .optimizeBusUtilization ();
5050 yawTimestampQueue = PhoenixOdometryThread .getInstance ().makeTimestampQueue ();
5151 yawPositionQueue = PhoenixOdometryThread .getInstance ().registerSignal (pigeon .getYaw ());
52+
53+ // Improve pigeon's yaw accuracy using the Gyroscope Sensitivity Calibration procedure
54+ GyroTrimConfigs trimConfigs = new GyroTrimConfigs ();
55+ trimConfigs .GyroScalarZ = Drive .GYRO_YAW_DEG_PER_ROT_CORRECTION ;
56+ pigeon .getConfigurator ().apply (trimConfigs );
5257 }
5358
5459 @ Override
You can’t perform that action at this time.
0 commit comments