[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

@@ -0,0 +1,39 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "IMUDataInternal.hpp"
using namespace wpi::hal;
namespace wpi::hal {
namespace init {
void InitializeIMUData() {
static IMUData imu;
::wpi::hal::SimIMUData = &imu;
}
} // namespace init
IMUData* SimIMUData;
} // namespace wpi::hal
extern "C" {
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI_NOINDEX(TYPE, HALSIM, IMU##CAPINAME, \
SimIMUData, LOWERNAME)
DEFINE_CAPI(double, AngleX, angleX)
DEFINE_CAPI(double, AngleY, angleY)
DEFINE_CAPI(double, AngleZ, angleZ)
DEFINE_CAPI(double, GyroRateX, gyroRateX)
DEFINE_CAPI(double, GyroRateY, gyroRateY)
DEFINE_CAPI(double, GyroRateZ, gyroRateZ)
DEFINE_CAPI(double, AccelX, accelX)
DEFINE_CAPI(double, AccelY, accelY)
DEFINE_CAPI(double, AccelZ, accelZ)
DEFINE_CAPI(double, Yaw, yaw)
} // extern "C"