Skip to content

Commit 2225b78

Browse files
committed
Merge branch 'gyro_trim'
2 parents 6f24ed3 + 5546d51 commit 2225b78

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/main/java/frc/robot/subsystems/drive/Drive.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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;

src/main/java/frc/robot/subsystems/drive/GyroIOPigeon2.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.ctre.phoenix6.CANBus;
2020
import com.ctre.phoenix6.StatusCode;
2121
import com.ctre.phoenix6.StatusSignal;
22+
import com.ctre.phoenix6.configs.GyroTrimConfigs;
2223
import com.ctre.phoenix6.configs.Pigeon2Configuration;
2324
import 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

0 commit comments

Comments
 (0)