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