mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[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:
41
wpilibc/src/test/python/test_onboard_imu.py
Normal file
41
wpilibc/src/test/python/test_onboard_imu.py
Normal file
@@ -0,0 +1,41 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user