Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
Originally Swadges were planned to use a LSM6DSL and a QMC6308, however, because the batteries are so close to the magnetometer, the quality of the data was low enough we decided to proceed with with a LSM6DSL-only IMU.
Unlike the accelerometer process, the IMU fuses the gyroscope and accelerometer data from the LMS6DSL. By fusing both sensors, we are able to produce a quaternion to represent the rotation of the swadge. The idea is that we run the IMU at 208 Hz, and we use the hardware FIFO built into the LSM6DSL to queue up events. Then, every frame, we empty out the FIFO.
The core system will call initAccelerometer() and deInitAccelerometer() appropriately. And you can at any point call any of the proper IMU / accel functions.
accelSetRegistersAndReset() must be called when entering a Swadge mode that uses the IMU.
accelIntegrate() should be called periodically. This can be done either in the mode's main loop or in the background draw callback. If this is called from the background draw callback, make sure to only call it once per frame, since multiple callbacks are called per-frame.
The functions you can use to get acceleration data are:
Go to the source code of this file.
Data Structures | |
struct | LSM6DSLData |
Functions | |
esp_err_t | initAccelerometer (gpio_num_t sda, gpio_num_t scl, gpio_pullup_t pullup) |
Initialize the IMU. | |
esp_err_t | deInitAccelerometer (void) |
Deinit the accelerometer (nothing to do) | |
esp_err_t | accelGetAccelVecRaw (int16_t *x, int16_t *y, int16_t *z) |
Get the RAW accelerometer "up" vector from device point of view. | |
esp_err_t | accelGetOrientVec (int16_t *x, int16_t *y, int16_t *z) |
Get the current orientation "up" vector from device point of view. | |
esp_err_t | accelGetQuaternion (float *q) |
Get the current estimated quaternion of the IMU. | |
esp_err_t | accelIntegrate (void) |
Read all pending samples in IMU and perform a sensor fusion pass. | |
esp_err_t | accelPerformCal (void) |
Initialize calibration of IMU. | |
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. | |
float | accelGetStdDevInCal (void) |
Get current divergence as the cal algorithm attempts to converge on a good cal. | |
void | accelSetRegistersAndReset (void) |
Reset the IMU's core registers. Should be done any time you are entering a mode with the IMU. | |
Variables | |
LSM6DSLData | LSM6DSL |
struct LSM6DSLData |
esp_err_t initAccelerometer | ( | gpio_num_t | sda, |
gpio_num_t | scl, | ||
gpio_pullup_t | pullup ) |
Initialize the IMU.
sda | The GPIO for the Serial DAta line |
scl | The GPIO for the Serial CLock line |
pullup | Either GPIO_PULLUP_DISABLE if there are external pullup resistors on SDA and SCL or GPIO_PULLUP_ENABLE if internal pull-ups should be used |
esp_err_t deInitAccelerometer | ( | void | ) |
Deinit the accelerometer (nothing to do)
esp_err_t accelGetAccelVecRaw | ( | int16_t * | x, |
int16_t * | y, | ||
int16_t * | z ) |
Get the RAW accelerometer "up" vector from device point of view.
esp_err_t accelGetOrientVec | ( | int16_t * | x, |
int16_t * | y, | ||
int16_t * | z ) |
Get the current orientation "up" vector from device point of view.
esp_err_t accelGetQuaternion | ( | float * | q | ) |
Get the current estimated quaternion of the IMU.
esp_err_t accelIntegrate | ( | void | ) |
Read all pending samples in IMU and perform a sensor fusion pass.
esp_err_t accelPerformCal | ( | void | ) |
Initialize calibration of IMU.
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.
int16_t xcomp; int16_t ycomp; accelGetSteeringAngleDegrees( &xcomp, &ycomp ); ESP_LOGI( "x", "%d %d %d\n", getAtan2( xcomp, ycomp ), xcomp, ycomp );
xcomp | is a pointer to receive the x component of the steering wheel (-4096-4096) +x is "right" |
ycomp | is a pointer to receive the y component of the steering wheel (-4096-4096) +y is "down" |
float accelGetStdDevInCal | ( | void | ) |
Get current divergence as the cal algorithm attempts to converge on a good cal.
void accelSetRegistersAndReset | ( | void | ) |
Reset the IMU's core registers. Should be done any time you are entering a mode with the IMU.
|
extern |