]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Airplane.hpp
Initial revision of Andy Ross's YASim code. This is (Y)et (A)nother Flight
[flightgear.git] / src / FDM / YASim / Airplane.hpp
1 #ifndef _AIRPLANE_HPP
2 #define _AIRPLANE_HPP
3
4 #include "ControlMap.hpp"
5 #include "Model.hpp"
6 #include "Wing.hpp"
7 #include "util/Vector.hpp"
8
9 namespace yasim {
10
11 class Gear;
12 class Thruster;
13
14 class Airplane {
15 public:
16     Airplane();
17     ~Airplane();
18
19     void iterate(float dt);
20
21     ControlMap* getControlMap();
22     Model* getModel();
23
24     void setPilotPos(float* pos);
25     void getPilotPos(float* out);
26
27     void getPilotAccel(float* out);
28
29     void setWeight(float weight);
30
31     void setWing(Wing* wing);
32     void setTail(Wing* tail);
33     void addVStab(Wing* vstab);
34
35     void addFuselage(float* front, float* back, float width);
36     int addTank(float* pos, float cap, float fuelDensity);
37     void addGear(Gear* g, float transitionTime);
38     void addThruster(Thruster* t, float mass, float* cg);
39     void addBallast(float* pos, float mass);
40
41     int addWeight(float* pos, float size);
42     void setWeight(int handle, float mass);
43
44     void setApproach(float speed, float altitude);
45     void setApproach(float speed, float altitude, float aoa); 
46     void setCruise(float speed, float altitude);
47
48     void addApproachControl(int control, float val);
49     void addCruiseControl(int control, float val);
50
51     int numGear();
52     Gear* getGear(int g);
53     void setGearState(bool down, float dt);
54
55     int numTanks();
56     void setFuelFraction(float frac); // 0-1, total amount of fuel
57     float getFuel(int tank); // in kg!
58     float getFuelDensity(int tank); // kg/m^3
59
60     void compile(); // generate point masses & such, then solve
61
62     // Solution output values
63     int getSolutionIterations();
64     float getDragCoefficient();
65     float getLiftRatio();
66     float getCruiseAoA();
67     float getTailIncidence();
68     char* getFailureMsg();
69
70 private:
71     struct Tank { float pos[3]; float cap; float fill;
72                   float density; int handle; };
73     struct Fuselage { float front[3], back[3], width; };
74     struct GearRec { Gear* gear; Surface* surf; float wgt; float time; };
75     struct ThrustRec { Thruster* thruster;
76                        int handle; float cg[3]; float mass; };
77     struct Control { int control; float val; };
78     struct WeightRec { int handle; Surface* surf; };
79
80     void runCruise();
81     void runApproach();
82     void setupState(float aoa, float speed, State* s);
83     void solveGear();
84     void solve();
85     float compileWing(Wing* w);
86     float compileFuselage(Fuselage* f);
87     void compileGear(GearRec* gr);
88     void stabilizeThrust();
89     void applyDragFactor(float factor);
90     void applyLiftRatio(float factor);
91     float clamp(float val, float min, float max);
92     float normFactor(float f);
93
94     Model _model;
95     ControlMap _controls;
96
97     float _emptyWeight;
98     float _pilotPos[3];
99
100     Wing* _wing;
101     Wing* _tail;
102
103     Vector _fuselages;
104     Vector _vstabs;
105     Vector _tanks;
106     Vector _thrusters;
107     float _ballast;
108
109     Vector _gears;
110     Vector _weights;
111     Vector _surfs; // NON-wing Surfaces
112
113     Vector _cruiseControls;
114     State _cruiseState;
115     float _cruiseRho;
116     float _cruiseSpeed;
117     float _cruiseWeight;
118
119     Vector _approachControls;
120     State _approachState;
121     float _approachRho;
122     float _approachSpeed;
123     float _approachAoA;
124     float _approachWeight;
125
126     int _solutionIterations;
127     float _dragFactor;
128     float _liftRatio;
129     float _cruiseAoA;
130     float _tailIncidence;
131     char* _failureMsg;
132 };
133
134 }; // namespace yasim
135 #endif // _AIRPLANE_HPP