forked from Puara/puara-gestures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuara_gestures.h
161 lines (145 loc) · 5.73 KB
/
puara_gestures.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//****************************************************************************//
// Puara Module Manager - high-level gestural descriptors //
// Metalab - Société des Arts Technologiques (SAT) //
// Input Devices and Music Interaction Laboratory (IDMIL), McGill University //
// Edu Meneses (2022) - https://www.edumeneses.com //
//****************************************************************************//
#ifndef PUARA_GESTURES_H
#define PUARA_GESTURES_H
#include <deque>
#include <cmath>
#include <algorithm>
#include "esp_timer.h"
#include "IMU_Sensor_Fusion/imu_orientation.h"
class PuaraGestures {
private:
// Intertial measurements
const int BUFFER_SIZE = 5;
float accelX;
float accelY;
float accelZ;
std::deque<float> gyroBuffers[3]; // Need buffer to compute shake/jab
float gyroX;
float gyroY;
float gyroZ;
float magX;
float magY;
float magZ;
// Shake and Jab
const int leakyShakeFreq = 10;
unsigned long leakyShakeTimerX;
unsigned long leakyShakeTimerY;
unsigned long leakyShakeTimerZ;
float shakeX;
float shakeY;
float shakeZ;
float jabX;
float jabY;
float jabZ;
int jabThreshold = 10;
void updateJabShake();
// Orientation
const float DECLINATION = -14.14; // Declination at Montreal on 2020-03-12
IMU_Orientation orientation;
void updateOrientation();
// touch array
int touchSizeEdge = 4; // amount of touch stripes for top and bottom portions (arbitrary)
float touchAverage (float * touchArrayStrips, int firstStrip, int lastStrip);
float touchAverage (int * touchArrayStrips, int firstStrip, int lastStrip);
int lastState_blobPos[4];
int maxBlobs = 4; // max amount of blobs to be detected
int blobAmount; // amount of detected blobs
int blobCenter[4]; // shows the "center" (index) of each blob (former blobArray)
int blobPos[4]; // starting position (index) of each blob
float blobSize[4]; // "size" (amount of stripes) of each blob
void blobDetection1D (int *discrete_touch, int touchSize);
const int leakyBrushFreq = 100; // leaking frequency (Hz)
unsigned long leakyBrushTimer = 0;
const int leakyRubFreq = 100;
unsigned long leakyRubTimer = 0;
int brushCounter[4];
float arrayAverageZero (float * Array, int ArraySize);
void bitShiftArrayL (int * origArray, int * shiftedArray, int arraySize, int shift);
// button
unsigned int buttonCount;
unsigned int buttonCountInterval = 200;
int buttonValue;
bool buttonPress = false;
unsigned int buttonTap;
unsigned int buttonDtap;
unsigned int buttonTtap;
bool buttonHold;
unsigned int buttonHoldInterval = 5000;
unsigned int buttonFilterPeriod = 10;
long buttonTimer;
unsigned long buttonPressTime;
unsigned int buttonThreshold = 1;
public:
float leakyIntegrator (float reading, float old_value, float leak, int frequency, unsigned long& timer);
// Inertial measurement updates (accelerometer, gyroscope, magnetometer)
/* IMPORTANT NOTE- axes signs should be updated following below:
*
* Top view
* ___________
* | Y |
* | ^ |
* | | |
* | o--->X |
* | Z^ |
* |___________|
*
*/
void setAccelerometerValues(float accelX, float accelY, float accelZ); // in m/sec^2
void setGyroscopeValues(float gyroX, float gyroY, float gyroZ); // in degrees/sec
void setMagnetometerValues(float magX, float magY, float magZ); // in Gauss
void updateInertialGestures(); // Updates shake, jab and orientation
// General inertial sensor signals
float getAccelX();
float getAccelY();
float getAccelZ();
float getGyroX();
float getGyroY();
float getGyroZ();
float getMagX();
float getMagY();
float getMagZ();
float getYaw();
float getPitch();
float getRoll();
// Shake and Jab
float getShakeX();
float getShakeY();
float getShakeZ();
float getJabX();
float getJabY();
float getJabZ();
// Orientation quaternion and euler values
IMU_Orientation::Quaternion getOrientationQuaternion();
IMU_Orientation::Euler getOrientationEuler();
// touch array
void updateTouchArray (int *discrete_touch, int touchSize);
float touchAll; // f, 0--1
float touchTop; // f, 0--1
float touchMiddle; // f, 0--1
float touchBottom; // f, 0--1
float brush; // f, 0--? (~cm/s)
float multiBrush[4]; // ffff, 0--? (~cm/s)
float rub; // f, 0--? (~cm/s)
float multiRub[4]; // ffff, 0--? (~cm/s)
// button
void updateButton(int buttonValue);
void updateTrigButton(int buttonValue);
unsigned int getButtonCount();
bool getButtonTouch();
unsigned int getButtonPressTime();
unsigned int getButtonValue();
unsigned int getButtonTap();
unsigned int getButtonDTap();
unsigned int getButtonTTap();
bool getButtonHold();
unsigned int getButtonHoldInterval();
unsigned int setButtonHoldInterval(int value);
unsigned int getButtonThreshold();
unsigned int setButtonThreshold(int value);
};
#endif