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