Goal
Use WPILib 2027's OnboardIMU, the IMU built into the Systemcore, in two ways:
- On the real robot, as a backup when the Redux Boron (Canandgyro) disconnects.
- In sim, as the primary gyro, because the Boron cannot be simulated.
Background
- The Boron is the only gyro (
GyroIOBoron, sampled at high rate by CanandgyroThread). When it disconnects, Drive estimates heading by integrating module kinematics (Drive.java around line 196) and raises the gyroDisconnected alert. Kinematic heading drifts with wheel slip, which is exactly when a gyro matters.
- The Boron has no simulation support. The ReduxLib
2027.0.0-alpha-7 jar has no simulation classes and no SimDevice references. Redux's only mention of simulation is a 2023 changelog note that says "Proper simulation support is planned."
- So the sim uses
new GyroIO() {}, which always reports connected = false. The sim therefore always runs the kinematic fallback, and the connected-gyro path (odometryYawPositions) never runs in sim. The alert is only hidden because Drive skips it in SIM mode.
OnboardIMU API (checked with javap on the alpha-7 jar):
- The constructor is
OnboardIMU(MountOrientation), where MountOrientation is FLAT, LANDSCAPE, or PORTRAIT.
- Methods:
getRotation2d(), getYawRadians(), resetYaw(), getRotation3d(), and getGyroRateZ(), among others.
- Simulation:
org.wpilib.simulation.OnboardIMUSim offers setYaw, setGyroRateZ, and angle and acceleration setters.
Plan
Caveats
Done when
- On the robot, unplugging the Boron mid-drive switches heading to the IMU without a visible pose jump, and the log shows the source change.
- In sim,
Drive runs with a connected gyro, not the kinematic fallback.
- The
AutoSimTest tracking assertions still pass.
Goal
Use WPILib 2027's
OnboardIMU, the IMU built into the Systemcore, in two ways:Background
GyroIOBoron, sampled at high rate byCanandgyroThread). When it disconnects,Driveestimates heading by integrating module kinematics (Drive.javaaround line 196) and raises thegyroDisconnectedalert. Kinematic heading drifts with wheel slip, which is exactly when a gyro matters.2027.0.0-alpha-7jar has no simulation classes and noSimDevicereferences. Redux's only mention of simulation is a 2023 changelog note that says "Proper simulation support is planned."new GyroIO() {}, which always reportsconnected = false. The sim therefore always runs the kinematic fallback, and the connected-gyro path (odometryYawPositions) never runs in sim. The alert is only hidden becauseDriveskips it in SIM mode.OnboardIMUAPI (checked with javap on the alpha-7 jar):OnboardIMU(MountOrientation), whereMountOrientationisFLAT,LANDSCAPE, orPORTRAIT.getRotation2d(),getYawRadians(),resetYaw(),getRotation3d(), andgetGyroRateZ(), among others.org.wpilib.simulation.OnboardIMUSimofferssetYaw,setGyroRateZ, and angle and acceleration setters.Plan
GyroIOOnboardIMU implements GyroIO. It reports yaw, yaw rate,connected, and one odometry sample per loop.GyroIOOnboardIMUinRobot's SIM case.OnboardIMUSim. Until Sim drivetrain with chassis dynamics, so module-force feedforward matters in sim #39 adds chassis dynamics, set it from the heading integrated from module kinematics. That adds no new physics, but it runs the connected-gyro code path in sim for the first time.Caveats
MountOrientationmatches how the Systemcore is mounted, and that yaw is CCW-positive like the Boron.CanandgyroThread. Reading the IMU once per loop is likely fine for a backup, but that's an assumption to measure.GyroIOinputs, which AdvantageKit logs, so replay stays consistent. Keep the source-selection logic driven only by logged inputs.Done when
Driveruns with a connected gyro, not the kinematic fallback.AutoSimTesttracking assertions still pass.