]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Airplane.hpp
Add support for a turbo prop condition lever.
[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 "Rotor.hpp"
8 #include "Vector.hpp"
9
10 namespace yasim {
11
12 class Gear;
13 class Thruster;
14
15 class Airplane {
16 public:
17     Airplane();
18     ~Airplane();
19
20     void iterate(float dt);
21     void calcFuelWeights();
22
23     ControlMap* getControlMap();
24     Model* getModel();
25
26     void setPilotPos(float* pos);
27     void getPilotPos(float* out);
28
29     void getPilotAccel(float* out);
30
31     void setWeight(float weight);
32
33     void setWing(Wing* wing);
34     void setTail(Wing* tail);
35     void addVStab(Wing* vstab);
36
37     void addRotor(Rotor* Rotor);
38     int getNumRotors() {return _rotors.size();}
39     Rotor* getRotor(int i) {return (Rotor*)_rotors.get(i);}
40
41     void addFuselage(float* front, float* back, float width,
42                      float taper=1, float mid=0.5);
43     int addTank(float* pos, float cap, float fuelDensity);
44     void addGear(Gear* g);
45     void addThruster(Thruster* t, float mass, float* cg);
46     void addBallast(float* pos, float mass);
47
48     int addWeight(float* pos, float size);
49     void setWeight(int handle, float mass);
50
51     void setApproach(float speed, float altitude, float aoa, float fuel);
52     void setCruise(float speed, float altitude, float fuel);
53
54     void setElevatorControl(int control);
55     void addApproachControl(int control, float val);
56     void addCruiseControl(int control, float val);
57
58     void addSolutionWeight(bool approach, int idx, float wgt);
59
60     int numGear();
61     Gear* getGear(int g);
62
63     int numThrusters() { return _thrusters.size(); }
64     Thruster* getThruster(int n) {
65         return ((ThrustRec*)_thrusters.get(n))->thruster; }
66     
67     int numTanks();
68     void setFuelFraction(float frac); // 0-1, total amount of fuel
69     float getFuel(int tank); // in kg!
70     float setFuel(int tank, float fuel); // in kg!
71     float getFuelDensity(int tank); // kg/m^3
72     float getTankCapacity(int tank);
73
74     void compile(); // generate point masses & such, then solve
75     void initEngines();
76     void stabilizeThrust();
77
78     // Solution output values
79     int getSolutionIterations();
80     float getDragCoefficient();
81     float getLiftRatio();
82     float getCruiseAoA();
83     float getTailIncidence();
84     float getApproachElevator() { return _approachElevator.val; }
85     char* getFailureMsg();
86
87 private:
88     struct Tank { float pos[3]; float cap; float fill;
89                   float density; int handle; };
90     struct Fuselage { float front[3], back[3], width, taper, mid; };
91     struct GearRec { Gear* gear; Surface* surf; float wgt; };
92     struct ThrustRec { Thruster* thruster;
93                        int handle; float cg[3]; float mass; };
94     struct Control { int control; float val; };
95     struct WeightRec { int handle; Surface* surf; };
96     struct SolveWeight { bool approach; int idx; float wgt; };
97
98     void runCruise();
99     void runApproach();
100     void setupState(float aoa, float speed, State* s);
101     void solveGear();
102     void solve();
103     void solveHelicopter();
104     float compileWing(Wing* w);
105     float compileRotor(Rotor* w);
106     float compileFuselage(Fuselage* f);
107     void compileGear(GearRec* gr);
108     void applyDragFactor(float factor);
109     void applyLiftRatio(float factor);
110     float clamp(float val, float min, float max);
111     void addContactPoint(float* pos);
112     void compileContactPoints();
113     float normFactor(float f);
114     void updateGearState();
115     void setupWeights(bool isApproach);
116
117     Model _model;
118     ControlMap _controls;
119
120     float _emptyWeight;
121     float _pilotPos[3];
122
123     Wing* _wing;
124     Wing* _tail;
125
126     Vector _fuselages;
127     Vector _vstabs;
128     Vector _tanks;
129     Vector _thrusters;
130     float _ballast;
131
132     Vector _gears;
133     Vector _contacts; // non-gear ground contact points
134     Vector _weights;
135     Vector _surfs; // NON-wing Surfaces
136
137     Vector _rotors;
138
139     Vector _solveWeights;
140
141     Vector _cruiseControls;
142     State _cruiseState;
143     float _cruiseP;
144     float _cruiseT;
145     float _cruiseSpeed;
146     float _cruiseWeight;
147     float _cruiseFuel;
148
149     Vector _approachControls;
150     State _approachState;
151     float _approachP;
152     float _approachT;
153     float _approachSpeed;
154     float _approachAoA;
155     float _approachWeight;
156     float _approachFuel;
157
158     int _solutionIterations;
159     float _dragFactor;
160     float _liftRatio;
161     float _cruiseAoA;
162     float _tailIncidence;
163     Control _approachElevator;
164     char* _failureMsg;
165 };
166
167 }; // namespace yasim
168 #endif // _AIRPLANE_HPP