Files
allwpilib/wpilibc/src/test/python/test_onboard_imu.py
PJ Reiniger 111130d8bb [copybara] Sync with robotpy (#8964)
GitOrigin-RevId: 9dff8f977401e78be0bb6f39cea2328320ab2d95
2026-06-08 19:22:48 -07:00

43 lines
1.0 KiB
Python

from wpilib import OnboardIMU
from wpilib.simulation import OnboardIMUSim
def test_sim_device() -> None:
imu = OnboardIMU(OnboardIMU.MountOrientation.FLAT)
sim = OnboardIMUSim()
assert 0.0 == imu.getAngleX()
assert 0.0 == imu.getAngleY()
assert 0.0 == imu.getAngleZ()
assert 0.0 == imu.getGyroRateX()
assert 0.0 == imu.getGyroRateY()
assert 0.0 == imu.getGyroRateZ()
assert 0.0 == imu.getAccelX()
assert 0.0 == imu.getAccelY()
assert 0.0 == imu.getAccelZ()
sim.setAngleX(1)
sim.setAngleY(2)
sim.setAngleZ(3)
sim.setGyroRateX(3.504)
sim.setGyroRateY(1.91)
sim.setGyroRateZ(22.9)
sim.setAccelX(-1)
sim.setAccelY(-2)
sim.setAccelZ(-3)
assert 1.0 == imu.getAngleX()
assert 2.0 == imu.getAngleY()
assert 3.0 == imu.getAngleZ()
assert 3.504 == imu.getGyroRateX()
assert 1.91 == imu.getGyroRateY()
assert 22.9 == imu.getGyroRateZ()
assert -1.0 == imu.getAccelX()
assert -2.0 == imu.getAccelY()
assert -3.0 == imu.getAccelZ()