]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Airplane.hpp
Use SG_LOG for debugging messages from the YASim helicopter model.
[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     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
137     Vector _approachControls;
138     State _approachState;
139     float _approachP;
140     float _approachT;
141     float _approachSpeed;
142     float _approachAoA;
143     float _approachWeight;
144
145     int _solutionIterations;
146     float _dragFactor;
147     float _liftRatio;
148     float _cruiseAoA;
149     float _tailIncidence;
150     Control _approachElevator;
151     char* _failureMsg;
152 };
153
154 }; // namespace yasim
155 #endif // _AIRPLANE_HPP