Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
hdw-imu.h
Go to the documentation of this file.
1
43#ifndef _HDW_IMU_H_
44#define _HDW_IMU_H_
45
46#include <stdint.h>
47
48#include <hal/gpio_types.h>
49#include <soc/gpio_num.h>
50#include <esp_err.h>
51
52#include "quaternions.h"
53
54typedef struct
55{
56 int32_t temp;
57 uint32_t computetime;
58 uint32_t performCal; // 1 if expecting a zero cal.
59
60 // Quats are wxyz.
61 // You can take a vector, in controller space, rotate by this quat, and you get it in world space.
62 float fqQuatLast[4]; // Delta
63 float fqQuat[4]; // Absolute
64
65 // The last raw accelerometer (NOT FUSED)
66 float fvLastAccelRaw[3];
67
68 // Bias for all of the euler angles.
69 float fvBias[3];
70
71 // Used for calibration
72 float fvDeviation[3];
73 float fvAverage[3];
74
75 uint32_t sampCount;
76
77 // For debug
79 int32_t gyroaccum[3];
80 int16_t gyrolast[3];
81 int16_t accellast[3];
82 float fCorrectLast[3];
84
85extern LSM6DSLData LSM6DSL;
86
87esp_err_t initAccelerometer(gpio_num_t sda, gpio_num_t scl, gpio_pullup_t pullup);
88esp_err_t deInitAccelerometer(void);
89esp_err_t accelGetAccelVecRaw(int16_t* x, int16_t* y, int16_t* z);
90esp_err_t accelGetOrientVec(int16_t* x, int16_t* y, int16_t* z);
91esp_err_t accelGetQuaternion(float* q);
92esp_err_t accelIntegrate(void);
93esp_err_t accelPerformCal(void);
94esp_err_t accelGetSteeringAngleDegrees(int16_t* xcomp, int16_t* ycomp);
95float accelGetStdDevInCal(void);
97
98#endif
uint32_t computetime
Definition hdw-imu.h:57
esp_err_t accelGetOrientVec(int16_t *x, int16_t *y, int16_t *z)
Get the current orientation "up" vector from device point of view.
Definition hdw-imu.c:638
esp_err_t initAccelerometer(gpio_num_t sda, gpio_num_t scl, gpio_pullup_t pullup)
Initialize the IMU.
Definition hdw-imu.c:265
LSM6DSLData LSM6DSL
Definition hdw-imu.c:98
uint32_t sampCount
Definition hdw-imu.h:75
esp_err_t accelGetSteeringAngleDegrees(int16_t *xcomp, int16_t *ycomp)
Get a steering wheel style input. Use getAtan2( xcomp, ycomp ) to get angle. 0..360 with 180 being up...
Definition hdw-imu.c:698
uint32_t performCal
Definition hdw-imu.h:58
esp_err_t accelGetQuaternion(float *q)
Get the current estimated quaternion of the IMU.
Definition hdw-imu.c:653
int lastreadr
Definition hdw-imu.h:78
esp_err_t accelPerformCal(void)
Initialize calibration of IMU.
Definition hdw-imu.c:668
esp_err_t accelIntegrate(void)
Read all pending samples in IMU and perform a sensor fusion pass.
Definition hdw-imu.c:363
float accelGetStdDevInCal(void)
Get current divergence as the cal algorithm attempts to converge on a good cal.
Definition hdw-imu.c:736
esp_err_t accelGetAccelVecRaw(int16_t *x, int16_t *y, int16_t *z)
Get the RAW accelerometer "up" vector from device point of view.
Definition hdw-imu.c:625
int32_t temp
Definition hdw-imu.h:56
esp_err_t deInitAccelerometer(void)
Deinit the accelerometer (nothing to do)
Definition hdw-imu.c:353
void accelSetRegistersAndReset(void)
Reset the IMU's core registers. Should be done any time you are entering a mode with the IMU.
Definition hdw-imu.c:748
Definition hdw-imu.h:55