-
Notifications
You must be signed in to change notification settings - Fork 0
/
craftinfo.cpp
98 lines (62 loc) · 1.51 KB
/
craftinfo.cpp
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
#include "craftinfo.h"
#include "Arduino.h"
CraftInfo::CraftInfo() :
currentAltitude_( DataPoint<float>(0, 0)),
previousAltitude_( DataPoint<float>(0, 0)),
ascentRate_( DataPoint<float>(0, 0)),
maxAltitude_( DataPoint<float>(0, -1000))
{ }
bool CraftInfo::readyToLaunch()
{
return bReadyToLaunch_;
}
void CraftInfo::setReadyToLaunch(bool bReadyToLaunch /*= true*/)
{
bReadyToLaunch_ = bReadyToLaunch;
}
void CraftInfo::calcAscentRate()
{
float deltaTime = currentAltitude_.time() - previousAltitude_.time();
float deltaAlt = (previousAltitude_.time() == 0) ? 0.0 : currentAltitude_.value() - previousAltitude_.value();
ascentRate_ = DataPoint<float>(
millis(),
(deltaAlt / (deltaTime / 1000.0 /* ms to sec conversion */))
);
}
float CraftInfo::currentAltitude()
{
return currentAltitude_.value();
}
void CraftInfo::setAltitude(DataPoint<float> newAltitude)
{
previousAltitude_ = currentAltitude_;
currentAltitude_ = newAltitude;
if (currentAltitude_.value() > maxAltitude_.value())
{
maxAltitude_ = currentAltitude_;
}
calcAscentRate();
}
float CraftInfo::ascentRate()
{
return ascentRate_.value();
}
void CraftInfo::setGroundAltitude(float groundAltitude)
{
groundAltitude_ = groundAltitude;
}
float CraftInfo::groundAltitude()
{
return groundAltitude_;
}
DataPoint<float> CraftInfo::maxAltitude()
{
return maxAltitude_;
}
DataPoint<float> CraftInfo::maxAltitudeAboveGround()
{
return DataPoint<float>(
maxAltitude_.time(),
maxAltitude_.value() - groundAltitude_
);
}