]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Airplane.hpp
Patch from Melchior Franz:
[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 "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                      float taper=1, float mid=0.5);
37     int addTank(float* pos, float cap, float fuelDensity);
38     void addGear(Gear* g);
39     void addThruster(Thruster* t, float mass, float* cg);
40     void addBallast(float* pos, float mass);
41
42     int addWeight(float* pos, float size);
43     void setWeight(int handle, float mass);
44
45     void setApproach(float speed, float altitude);
46     void setApproach(float speed, float altitude, float aoa); 
47     void setCruise(float speed, float altitude);
48
49     void setElevatorControl(int control);
50     void addApproachControl(int control, float val);
51     void addCruiseControl(int control, float val);
52
53     int numGear();
54     Gear* getGear(int g);
55
56     int numTanks();
57     void setFuelFraction(float frac); // 0-1, total amount of fuel
58     float getFuel(int tank); // in kg!
59     float getFuelDensity(int tank); // kg/m^3
60
61     void compile(); // generate point masses & such, then solve
62     void initEngines();
63     void stabilizeThrust();
64
65     // Solution output values
66     int getSolutionIterations();
67     float getDragCoefficient();
68     float getLiftRatio();
69     float getCruiseAoA();
70     float getTailIncidence();
71     float getApproachElevator() { return _approachElevator.val; }
72     char* getFailureMsg();
73
74 private:
75     struct Tank { float pos[3]; float cap; float fill;
76                   float density; int handle; };
77     struct Fuselage { float front[3], back[3], width, taper, mid; };
78     struct GearRec { Gear* gear; Surface* surf; float wgt; };
79     struct ThrustRec { Thruster* thruster;
80                        int handle; float cg[3]; float mass; };
81     struct Control { int control; float val; };
82     struct WeightRec { int handle; Surface* surf; };
83
84     void runCruise();
85     void runApproach();
86     void setupState(float aoa, float speed, State* s);
87     void solveGear();
88     void solve();
89     float compileWing(Wing* w);
90     float compileFuselage(Fuselage* f);
91     void compileGear(GearRec* gr);
92     void applyDragFactor(float factor);
93     void applyLiftRatio(float factor);
94     float clamp(float val, float min, float max);
95     void addContactPoint(float* pos);
96     void compileContactPoints();
97     float normFactor(float f);
98     void updateGearState();
99
100     Model _model;
101     ControlMap _controls;
102
103     float _emptyWeight;
104     float _pilotPos[3];
105
106     Wing* _wing;
107     Wing* _tail;
108
109     Vector _fuselages;
110     Vector _vstabs;
111     Vector _tanks;
112     Vector _thrusters;
113     float _ballast;
114
115     Vector _gears;
116     Vector _contacts; // non-gear ground contact points
117     Vector _weights;
118     Vector _surfs; // NON-wing Surfaces
119
120     Vector _cruiseControls;
121     State _cruiseState;
122     float _cruiseP;
123     float _cruiseT;
124     float _cruiseSpeed;
125     float _cruiseWeight;
126
127     Vector _approachControls;
128     State _approachState;
129     float _approachP;
130     float _approachT;
131     float _approachSpeed;
132     float _approachAoA;
133     float _approachWeight;
134
135     int _solutionIterations;
136     float _dragFactor;
137     float _liftRatio;
138     float _cruiseAoA;
139     float _tailIncidence;
140     Control _approachElevator;
141     char* _failureMsg;
142 };
143
144 }; // namespace yasim
145 #endif // _AIRPLANE_HPP