Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
imu_utils.h File Reference

Detailed Description

Design Philosophy

Streaming IMU data may be tricky to interpret for something simple like shake detection. This utility provides a simple interface for shake detection. It should not be used when full orientation data is needed.

Usage

Call checkForShake() frequently, like from a Swadge Mode's main loop. You do not need to call accelIntegrate() or accelGetAccelVecRaw() elsewhere. When it returns true, then the shake state has changed and the isShook argument can be checked for the current shake state.

Example

// These variables are static to preserve their value between calls.
// Ideally they are contained in a Swadge Mode struct
static vec3d_t lastOrientation;
static list_t shakeHistory;
static bool isShook;
if (checkForShake(&lastOrientation, &shakeHistory, &isShook))
{
if (isShook)
{
ESP_LOGD("IMU", "Shake detected!");
}
else
{
ESP_LOGD("IMU", "Shake stopped");
}
}
bool checkForShake(vec3d_t *lastOrientation, list_t *shakeHistory, bool *isShook)
Check if a shake was detected. All of the arguments for this function are both inputs and outputs.
Definition imu_utils.c:26
A general purpose 3D vector.
Definition imu_utils.h:49
A doubly linked list with pointers to the first and last nodes.
Definition linked_list.h:87

Go to the source code of this file.

Data Structures

struct  vec3d_t
 A general purpose 3D vector. More...
 

Functions

bool checkForShake (vec3d_t *lastOrientation, list_t *shakeHistory, bool *isShook)
 Check if a shake was detected. All of the arguments for this function are both inputs and outputs.
 

Data Structure Documentation

◆ vec3d_t

struct vec3d_t
Data Fields
int16_t x The x component of the vector.
int16_t y The y component of the vector.
int16_t z The z component of the vector.

Function Documentation

◆ checkForShake()

bool checkForShake ( vec3d_t * lastOrientation,
list_t * shakeHistory,
bool * isShook )

Check if a shake was detected. All of the arguments for this function are both inputs and outputs.

This will return if the shake state changed, not if it is shaking or not. The argument isShook will contain the shake state.

This calls accelIntegrate() and accelGetAccelVecRaw(), so neither of those functions needs to be called elsewhere. Because this function calls accelIntegrate(), it should be called relatively frequently.

Parameters
lastOrientationThe last IMU orientation, should only be set by this function
shakeHistoryA list of shake values to see when the Swadge settles
isShooktrue if the Swadge is shaking, false if it is not
Returns
true if the shake state changed (no shake to shake or vice versa), false if it did not