Debian Codegraph @

src/FDM/YASim/FGFDM.hpp

raw symbols SCIP
1 #ifndef _FGFDM_HPP
2 #define _FGFDM_HPP
3
4 #include <simgear/xml/easyxml.hxx>
5 #include <simgear/props/props.hxx>
6
7 #include "Airplane.hpp"
8 #include "Vector.hpp"
9
10 #include <map>
11 #include <set>
12 #include <string>
13
14
15 namespace yasim {
16
17 class Wing;
18 class Version;
19
20 // This class forms the "glue" to the FlightGear codebase. It handles
21 // parsing of XML airplane files, interfacing to the properties
22 // system, and providing data for the use of the FGInterface object.
23 class FGFDM : public XMLVisitor {
24 public:
25 FGFDM();
26 ~FGFDM();
27 void init();
28 void iterate(float dt);
29 void getExternalInput(float dt=1e6);
30
31 Airplane* getAirplane();
32
33 // XML parsing callback from XMLVisitor
34 virtual void startElement(const char* name, const XMLAttributes &atts);
35 virtual void endElement(const char* name);
36
37 float getVehicleRadius(void) const { return _vehicle_radius; }
38
39 void property_associations(
40 std::function<void(const std::string& from, const std::string& to)> fn
41 );
42
43 private:
44 struct EngRec {
45 std::string prefix;
46 Thruster* eng {nullptr};
47 };
48 struct WeightRec {
49 std::string prop;
50 float size {0};
51 int handle {0};
52 };
53 struct ControlOutput {
54 int handle {0};
55 SGPropertyNode* prop {nullptr};
56 ControlMap::ControlType control;
57 bool left {false};
58 float min {0};
59 float max {0};
60 };
61
62 void parseAirplane(const XMLAttributes* a);
63 void parseApproachCruise(const XMLAttributes* a, const char* name);
64 void parseSolveWeight(const XMLAttributes* a);
65 void parseCockpit(const XMLAttributes* a);
66
67
68 void setOutputProperties(float dt);
69
70 void parseRotor(const XMLAttributes* a, const char* name);
71 void parseRotorGear(const XMLAttributes* a);
72 void parseWing(const XMLAttributes* a, const char* name, Airplane* airplane);
73 int parseOutput(const char* name);
74 void parseWeight(const XMLAttributes* a);
75 void parseStall(const XMLAttributes* a);
76 void parseFlap(const XMLAttributes* a, const char* name);
77
78 void parseTurbineEngine(const XMLAttributes* a);
79 void parsePistonEngine(const XMLAttributes* a);
80 void parseElectricEngine(const XMLAttributes* a);
81 void parsePropeller(const XMLAttributes* a);
82 void parseThruster(const XMLAttributes* a);
83 void parseJet(const XMLAttributes* a);
84 void parseHitch(const XMLAttributes* a);
85 void parseTow(const XMLAttributes* a);
86 void parseWinch(const XMLAttributes* a);
87 void parseGear(const XMLAttributes* a);
88 void parseHook(const XMLAttributes* a);
89 void parseLaunchbar(const XMLAttributes* a);
90 void parseFuselage(const XMLAttributes* a);
91 void parseTank(const XMLAttributes* a);
92 void parseBallast(const XMLAttributes* a);
93 void parseControlSetting(const XMLAttributes* a);
94 void parseControlIn(const XMLAttributes* a);
95 void parseControlOut(const XMLAttributes* a);
96 void parseControlSpeed(const XMLAttributes* a);
97
98
99 int attri(const XMLAttributes* atts, const char* attr);
100 int attri(const XMLAttributes* atts, const char* attr, int def);
101 float attrf(const XMLAttributes* atts, const char* attr);
102 float attrf(const XMLAttributes* atts, const char* attr, float def);
103 void attrf_xyz(const XMLAttributes* atts, float* out);
104 double attrd(const XMLAttributes* atts, const char* attr);
105 double attrd(const XMLAttributes* atts, const char* attr, double def);
106 bool attrb(const XMLAttributes* atts, const char* attr);
107
108 // The core Airplane object we manage.
109 Airplane _airplane;
110
111 // Aerodynamic turbulence model
112 Turbulence* _turb;
113
114 // Settable weights
115 Vector _weights;
116
117 // Engine types. Contains an EngRec structure.
118 Vector _thrusters;
119
120 // Output properties for the ControlMap
121 Vector _controlOutputs;
122
123 // Radius of the vehicle, for intersection testing.
124 float _vehicle_radius {0};
125
126 // Parsing temporaries
127 void* _currObj {nullptr};
128 Airplane::Configuration _airplaneCfg;
129 int _nextEngine {0};
130 int _wingSection {0};
131 int _xml_depth {0};
132 int _xml_last_control_depth {0};
133
134 class FuelProps
135 {
136 public:
137 SGPropertyNode_ptr _out_of_fuel;
138 SGPropertyNode_ptr _fuel_consumed_lbs;
139 };
140
141 class ThrusterProps
142 {
143 public:
144 SGPropertyNode_ptr _running, _cranking;
145 SGPropertyNode_ptr _prop_thrust, _thrust_lbs, _fuel_flow_gph;
146 SGPropertyNode_ptr _rpm, _torque_ftlb, _mp_osi, _mp_inhg;
147 SGPropertyNode_ptr _oil_temperature_degf, _boost_gauge_inhg;
148 SGPropertyNode_ptr _n1, _n2, _epr, _egt_degf;
149 };
150
151 SGPropertyNode_ptr _turb_magnitude_norm, _turb_rate_hz;
152 SGPropertyNode_ptr _gross_weight_lbs;
153 SGPropertyNode_ptr _cg_x;
154 SGPropertyNode_ptr _cg_y;
155 SGPropertyNode_ptr _cg_z;
156 SGPropertyNode_ptr _yasimN;
157
158 std::vector<SGPropertyNode_ptr> _tank_level_lbs;
159 std::vector<ThrusterProps> _thrust_props;
160 std::vector<FuelProps> _fuel_props;
161 SGPropertyNode_ptr _vxN;
162 SGPropertyNode_ptr _vyN;
163 SGPropertyNode_ptr _vzN;
164 SGPropertyNode_ptr _vrxN;
165 SGPropertyNode_ptr _vryN;
166 SGPropertyNode_ptr _vrzN;
167 SGPropertyNode_ptr _axN;
168 SGPropertyNode_ptr _ayN;
169 SGPropertyNode_ptr _azN;
170 SGPropertyNode_ptr _arxN;
171 SGPropertyNode_ptr _aryN;
172 SGPropertyNode_ptr _arzN;
173 SGPropertyNode_ptr _cg_xmacN;
174
175 // Used on startup when gathering information about associated properties,
176 // e.g. /controls/flight/flaps and /surface-positions/flap-pos-norm.
177 std::map<std::string, std::set<std::string>> _control_to_input_properties;
178 std::map<std::string, std::set<std::string>> _control_to_output_properties;
179 std::map<std::string, std::set<std::string>> _property_to_properties;
180
181 };
182
183 }; // namespace yasim
184 #endif // _FGFDM_HPP