-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIMUManager.cpp
More file actions
85 lines (70 loc) · 1.45 KB
/
Copy pathIMUManager.cpp
File metadata and controls
85 lines (70 loc) · 1.45 KB
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
#include "IMUManager.h"
IMUManager::IMUManager(LSM6DS3Class& _IMU, unsigned long _pollFrequency, unsigned long currentTime):IMU(_IMU), pollFrequency(_pollFrequency)
{
shakeCount = 0;
shakeForce = 2.5;
shakeThreshold = 3;
nextPollTime = currentTime + pollFrequency;
}
void IMUManager::poll(unsigned long currentTime)
{
if(currentTime < nextPollTime) return;
nextPollTime = currentTime + pollFrequency;
if (IMU.accelerationAvailable())
{
IMU.readAcceleration(xAccel, yAccel, zAccel);
}
if (IMU.gyroscopeAvailable())
{
IMU.readGyroscope(xAngular, yAngular, zAngular);
}
if (IMU.temperatureAvailable())
{
IMU.readTemperature(temperature);
}
if((abs(xAccel) > shakeForce) || (abs(yAccel) > shakeForce) || (abs(zAccel) > shakeForce))
{
shakeCount++;
}
else
{
if(shakeCount > 0) shakeCount--;
}
}
bool IMUManager::isShaken()
{
if(shakeCount > shakeThreshold)
{
shakeCount = 0;
return true;
}
return false;
}
float IMUManager::GetXAcceleration()
{
return xAccel;
}
float IMUManager::GetYAcceleration()
{
return yAccel;
}
float IMUManager::GetZAcceleration()
{
return zAccel;
}
float IMUManager::GetXAngular()
{
return xAngular;
}
float IMUManager::GetYAngular()
{
return yAngular;
}
float IMUManager::GetZAngular()
{
return zAngular;
}
float IMUManager::GetTemperature()
{
return temperature;
}