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