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