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