]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/proptest.cpp
c3484c5004b64fd13fa302633282bebbd72de13d
[flightgear.git] / src / FDM / YASim / proptest.cpp
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "Math.hpp"
5 #include "FGFDM.hpp"
6 #include "PropEngine.hpp"
7 #include "Propeller.hpp"
8 #include "Atmosphere.hpp"
9
10 using namespace yasim;
11
12 // Usage: proptest plane.xml [alt-ft] [spd-ktas]
13
14 // Stubs.  Not needed by a batch program, but required to link.
15 class SGPropertyNode;
16 bool fgSetFloat (const char * name, float val) { return false; }
17 bool fgSetBool(char const * name, bool val) { return false; }
18 bool fgGetBool(char const * name, bool def) { return false; }
19 SGPropertyNode* fgGetNode (const char * path, bool create) { return 0; }
20 SGPropertyNode* fgGetNode (const char * path, int i, bool create) { return 0; }
21 float fgGetFloat (const char * name, float defaultValue) { return 0; }
22 float fgGetDouble (const char * name, double defaultValue) { return 0; }
23 float fgSetDouble (const char * name, double defaultValue) { return 0; }
24
25 static const float KTS2MPS = 0.514444444444;
26 static const float RPM2RAD = 0.10471975512;
27 static const float HP2W = 745.700;
28 static const float FT2M = 0.3048;
29 static const float N2LB = 0.224809;
30
31 // static const float DEG2RAD = 0.0174532925199;
32 // static const float LBS2N = 4.44822;
33 // static const float LBS2KG = 0.45359237;
34 // static const float KG2LBS = 2.2046225;
35 // static const float CM2GALS = 264.172037284;
36 // static const float INHG2PA = 3386.389;
37 // static const float K2DEGF = 1.8;
38 // static const float K2DEGFOFFSET = -459.4;
39 // static const float CIN2CM = 1.6387064e-5;
40 // static const float YASIM_PI = 3.14159265358979323846;
41
42 const int COUNT = 100;
43
44 int main(int argc, char** argv)
45 {
46     FGFDM fdm;
47
48     // Read
49     try {
50         readXML(argv[1], fdm);
51     } catch (const sg_exception &e) {
52         printf("XML parse error: %s (%s)\n",
53                e.getFormattedMessage().c_str(), e.getOrigin().c_str());
54     }
55
56     Airplane* airplane = fdm.getAirplane();
57     PropEngine* pe = airplane->getThruster(0)->getPropEngine();
58     Propeller* prop = pe->getPropeller();
59     Engine* eng = pe->getEngine();
60
61     pe->init();
62     pe->setMixture(1);
63     pe->setFuelState(true);
64     eng->setBoost(1);
65
66     float alt = (argc > 2 ? atof(argv[2]) : 0) * FT2M;
67     pe->setAir(Atmosphere::getStdPressure(alt),
68                Atmosphere::getStdTemperature(alt),
69                Atmosphere::getStdDensity(alt));
70  
71     float speed = (argc > 3 ? atof(argv[3]) : 0) * KTS2MPS;
72     float wind[3];
73     wind[0] = -speed; wind[1] = wind[2] = 0;
74     pe->setWind(wind);
75
76     printf("Alt: %f\n", alt / FT2M);
77     printf("Spd: %f\n", speed / KTS2MPS);
78     for(int i=0; i<COUNT; i++) {
79         float throttle = i/(COUNT-1.0);
80         pe->setThrottle(throttle);
81         pe->stabilize();
82
83         float rpm = pe->getOmega() * (1/RPM2RAD);
84
85         float tmp[3];
86         pe->getThrust(tmp);
87         float thrust = Math::mag3(tmp);
88
89         float power = pe->getOmega() * eng->getTorque();
90
91         float eff = thrust * speed / power;
92
93         printf("%6.3f: %6.1frpm %6.1flbs %6.1fhp %6.1f%% torque: %f\n",
94                throttle, rpm, thrust * N2LB, power * (1/HP2W), 100*eff, eng->getTorque());
95     }
96
97     printf("\n");
98     printf("Propeller vs. RPM\n");
99     printf("-----------------\n");
100     for(int i=0; i<COUNT; i++) {
101         float thrust, torque, rpm = 3000 * i/(COUNT-1.0);
102         float omega = rpm * RPM2RAD;
103         prop->calc(Atmosphere::getStdDensity(alt),
104                    speed, omega, &thrust, &torque);
105         float power = torque * omega;
106         float eff = (thrust * speed) / power;
107         printf("%6.1frpm %6.1flbs %6.1fhp %.1f%% torque: %f\n",
108                rpm, thrust * N2LB, power * (1/HP2W), 100*eff, torque);
109     }
110 }