forked from PhilipNelson5/AscentRateCalculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiftCalc.cpp
60 lines (45 loc) · 1.86 KB
/
LiftCalc.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
#include "termColors.hpp"
#include "ARCfuncs.hpp"
#include <iostream>
int main()
{
double chute = 0.33;
double balloon = 3.8;
double payload = 6.0;
double lift_min = 0.0;
double lift_max = 20.0;
double ascent_target = 7.0;
std::cout << WHITE << "Enter the following values as floating point numbers in American pounds (lbs)\n";
std::cout << BOLDWHITE
<< "\nParachute Weight" << RESET << " (press enter for default of .33 lbs) : ";
chute = getInput(chute);
std::cout << BOLDWHITE << "\nBalloon Weight" << RESET << " (press enter for default of 3.8 lbs) : ";
balloon = getInput(balloon);
std::cout << BOLDWHITE << "\nPayload Weight" << RESET <<" (press enter for default of 6.0 lbs) : ";
payload = getInput(payload);
std::cout << BOLDWHITE << "\nEstimate maximum balloon lift" << RESET << " (press enter for default of 20.0 lbs) : ";
lift_max = getInput(lift_max);
std::cout << BOLDWHITE << "\nEstimate minimum balloon lift" << RESET << " (press enter for default of 0.0 lbs) : ";
lift_min = getInput(lift_min);
std::cout << BOLDWHITE << "\nTarget ascent rate" << RESET << " (press enter for default of 7 m/s) : ";
ascent_target = getInput(ascent_target);
double lift_med, asc;
while(calcAscent(lift_max, chute, payload, balloon) < ascent_target)
lift_max += 5;
while(calcAscent(lift_min, chute, payload, balloon) > ascent_target)
lift_min -= 5;
do
{
lift_med = (lift_min + lift_max) / 2;
asc = calcAscent(lift_med, chute, payload, balloon);
if (asc > ascent_target)
lift_max = lift_med;
else if (asc < ascent_target)
lift_min = lift_med;
} while (fabs(ascent_target - asc) >= .001);
std::cout << std::endl
<< RED << lift_med << " lbs" << RESET
<< " of nozzle lift are required" << std::endl
<< "to achieve " << GREEN << asc << " m/s" << RESET
<< " ascent rate" << std::endl;
}