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