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