[wpilib][sim] Add Onboard IMU Sim (#8855)

This provides the ability to simulate parts of the Onboard IMU at the
HAL level. This allows team to use and simulate the IMU in code, and a
follow up PR could be made to the halsim_gui to add a new widget to view
and modify the data graphically.

Since the C++ IMU uses radians for angles that is what I did for the
simulator.

Partially deals with #8845
This commit is contained in:
PJ Reiniger
2026-05-07 13:01:26 -04:00
committed by GitHub
parent 3d4cabfbc9
commit 4c07aedd91
23 changed files with 713 additions and 15 deletions

View File

@@ -30,6 +30,7 @@ import org.wpilib.networktables.DoubleArrayEntry;
import org.wpilib.networktables.DoubleArrayTopic;
import org.wpilib.simulation.DifferentialDrivetrainSim;
import org.wpilib.simulation.EncoderSim;
import org.wpilib.simulation.OnboardIMUSim;
import org.wpilib.smartdashboard.Field2d;
import org.wpilib.smartdashboard.SmartDashboard;
import org.wpilib.system.RobotController;
@@ -253,8 +254,7 @@ public class Drivetrain {
leftEncoderSim.setRate(drivetrainSimulator.getLeftVelocity());
rightEncoderSim.setDistance(drivetrainSimulator.getRightPosition());
rightEncoderSim.setRate(drivetrainSimulator.getRightVelocity());
// gyroSim.setAngle(-drivetrainSimulator.getHeading().getDegrees()); // TODO(Ryan): fixup
// when sim implemented
OnboardIMUSim.setYaw(-drivetrainSimulator.getHeading().getRadians());
}
/** This function is called periodically, no matter the mode. */