]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Airplane.hpp
763e8d5ead84e82a81694713a191cc09b6ef2736
[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 consumeFuel(float dt);
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 numTanks();
64     void setFuelFraction(float frac); // 0-1, total amount of fuel
65     float getFuel(int tank); // in kg!
66     float getFuelDensity(int tank); // kg/m^3
67     float getTankCapacity(int tank);
68
69     void compile(); // generate point masses & such, then solve
70     void initEngines();
71     void stabilizeThrust();
72
73     // Solution output values
74     int getSolutionIterations();
75     float getDragCoefficient();
76     float getLiftRatio();
77     float getCruiseAoA();
78     float getTailIncidence();
79     float getApproachElevator() { return _approachElevator.val; }
80     char* getFailureMsg();
81
82 private:
83     struct Tank { float pos[3]; float cap; float fill;
84                   float density; int handle; };
85     struct Fuselage { float front[3], back[3], width, taper, mid; };
86     struct GearRec { Gear* gear; Surface* surf; float wgt; };
87     struct ThrustRec { Thruster* thruster;
88                        int handle; float cg[3]; float mass; };
89     struct Control { int control; float val; };
90     struct WeightRec { int handle; Surface* surf; };
91     struct SolveWeight { bool approach; int idx; float wgt; };
92
93     void runCruise();
94     void runApproach();
95     void setupState(float aoa, float speed, State* s);
96     void solveGear();
97     void solve();
98     void solveHelicopter();
99     float compileWing(Wing* w);
100     float compileRotor(Rotor* w);
101     float compileFuselage(Fuselage* f);
102     void compileGear(GearRec* gr);
103     void applyDragFactor(float factor);
104     void applyLiftRatio(float factor);
105     float clamp(float val, float min, float max);
106     void addContactPoint(float* pos);
107     void compileContactPoints();
108     float normFactor(float f);
109     void updateGearState();
110     void setupWeights(bool isApproach);
111
112     Model _model;
113     ControlMap _controls;
114
115     float _emptyWeight;
116     float _pilotPos[3];
117
118     Wing* _wing;
119     Wing* _tail;
120
121     Vector _fuselages;
122     Vector _vstabs;
123     Vector _tanks;
124     Vector _thrusters;
125     float _ballast;
126
127     Vector _gears;
128     Vector _contacts; // non-gear ground contact points
129     Vector _weights;
130     Vector _surfs; // NON-wing Surfaces
131
132     Vector _rotors;
133
134     Vector _solveWeights;
135
136     Vector _cruiseControls;
137     State _cruiseState;
138     float _cruiseP;
139     float _cruiseT;
140     float _cruiseSpeed;
141     float _cruiseWeight;
142     float _cruiseFuel;
143
144     Vector _approachControls;
145     State _approachState;
146     float _approachP;
147     float _approachT;
148     float _approachSpeed;
149     float _approachAoA;
150     float _approachWeight;
151     float _approachFuel;
152
153     int _solutionIterations;
154     float _dragFactor;
155     float _liftRatio;
156     float _cruiseAoA;
157     float _tailIncidence;
158     Control _approachElevator;
159     char* _failureMsg;
160 };
161
162 }; // namespace yasim
163 #endif // _AIRPLANE_HPP