vex_sdk/
imu.rs

1//! V5 Inertial Sensor
2
3use core::ffi::c_double;
4
5use crate::device::V5_DeviceT;
6
7#[repr(C, packed)]
8#[derive(Default, Debug, Copy, Clone, PartialEq)]
9pub struct V5_DeviceImuRaw {
10    pub x: c_double,
11    pub y: c_double,
12    pub z: c_double,
13    pub w: c_double,
14}
15
16#[repr(C, packed)]
17#[derive(Default, Debug, Copy, Clone, PartialEq)]
18pub struct V5_DeviceImuQuaternion {
19    pub a: c_double,
20    pub b: c_double,
21    pub c: c_double,
22    pub d: c_double,
23}
24
25#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
26#[repr(transparent)]
27pub struct V5ImuOrientationMode(pub core::ffi::c_uchar);
28
29impl V5ImuOrientationMode {
30    pub const kImuOrientationZUp: Self = Self(0x00);
31    pub const kImuOrientationZDown: Self = Self(0x10);
32    pub const kImuOrientationXUp: Self = Self(0x20);
33    pub const kImuOrientationXDown: Self = Self(0x30);
34    pub const kImuOrientationYUp: Self = Self(0x40);
35    pub const kImuOrientationYDown: Self = Self(0x50);
36    pub const kImuOrientationAuto: Self = Self(0x80);
37}
38
39#[repr(C, packed)]
40#[derive(Default, Debug, Copy, Clone, PartialEq)]
41pub struct V5_DeviceImuAttitude {
42    pub pitch: c_double,
43    pub roll: c_double,
44    pub yaw: c_double,
45}
46
47unsafe extern "system" {
48    pub fn vexDeviceImuReset(device: V5_DeviceT);
49    pub fn vexDeviceImuHeadingGet(device: V5_DeviceT) -> c_double;
50    pub fn vexDeviceImuDegreesGet(device: V5_DeviceT) -> c_double;
51    pub fn vexDeviceImuQuaternionGet(device: V5_DeviceT, data: *mut V5_DeviceImuQuaternion);
52    pub fn vexDeviceImuAttitudeGet(device: V5_DeviceT, data: *mut V5_DeviceImuAttitude);
53    pub fn vexDeviceImuRawGyroGet(device: V5_DeviceT, data: *mut V5_DeviceImuRaw);
54    pub fn vexDeviceImuRawAccelGet(device: V5_DeviceT, data: *mut V5_DeviceImuRaw);
55    pub fn vexDeviceImuStatusGet(device: V5_DeviceT) -> u32;
56    pub fn vexDeviceImuModeSet(device: V5_DeviceT, mode: u32);
57    pub fn vexDeviceImuModeGet(device: V5_DeviceT) -> u32;
58    pub fn vexDeviceImuDataRateSet(device: V5_DeviceT, rate: u32);
59}