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