-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCalculations.h
56 lines (53 loc) · 1.44 KB
/
Calculations.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
#include "BNO055_RT.h"
#include "Triple.h"
// Check engine cuttoff values
double alpha; // = .05;
double maxAcceleration; // = 0;
// calcVelocity() values
Triple prevVelocity;
double prevTime;
/*
@description : checks acceleration to see if engine has been cut off
@returns : true if engine cutoff detected; false if if not
@acceleration : current acceleration
*/
bool checkEngineCutOff(double acceleration)
{
if (acceleration < -2)
{
return true;
}
// if (acceleration < -1)
// {
// maxAcceleration = acceleration;
// }
// // Checks to see if acceleration has dipped with a leniancy value
// else if (acceleration < maxAcceleration - (maxAcceleration * alpha))
// {
// return true;
// }
}
void initCalculationValues()
{
prevVelocity.x = 0;
prevVelocity.y = 0;
prevVelocity.z = 0;
prevTime = millis();
alpha = .05;
maxAcceleration = 0;
}
/*
@returns Triple velocity
*/
Triple calcVelocity(Triple acceleration)
{
Triple velocity;
velocity.x = prevVelocity.x + ((acceleration.x) * ((millis() - prevTime) / 1000));
velocity.y = prevVelocity.y + ((acceleration.y) * ((millis() - prevTime) / 1000));
velocity.z = prevVelocity.z + ((acceleration.z) * ((millis() - prevTime) / 1000));
prevTime = millis();
double prevVelocity_X = velocity.x;
double prevVelocity_Y = velocity.y;
double prevVelocity_Z = velocity.z;
return velocity;
}