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:
39
hal/src/main/native/sim/mockdata/IMUData.cpp
Normal file
39
hal/src/main/native/sim/mockdata/IMUData.cpp
Normal 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"
|
||||
Reference in New Issue
Block a user