9#include <simgear/debug/logstream.hxx>
13#include "yasim-common.hpp"
16#include "SimpleJet.hpp"
19#include "Launchbar.hpp"
20#include "Atmosphere.hpp"
21#include "PropEngine.hpp"
22#include "Propeller.hpp"
23#include "PistonEngine.hpp"
24#include "TurbineEngine.hpp"
25#include "ElectricEngine.hpp"
27#include "Rotorpart.hpp"
45 _turb =
new Turbulence(10,
seed);
50 for(
int i=0;
i<_thrusters.size();
i++) {
51 EngRec* er = (EngRec*)_thrusters.get(
i);
56 for(
int i=0;
i<_weights.size();
i++) {
57 WeightRec* wr = (WeightRec*)_weights.get(
i);
61 for(
int i=0;
i<_controlOutputs.size();
i++)
62 delete (ControlOutput*)_controlOutputs.get(
i);
67void FGFDM::property_associations(
68 std::function<
void(
const std::string& from,
const std::string& to)> fn
71 for (
auto& a: _property_to_properties) {
72 for (
auto& b: a.second) {
78void FGFDM::iterate(
float dt)
81 _airplane.iterate(dt);
84 for(
int i=0;
i<_airplane.numThrusters();
i++) {
85 Thruster* t = _airplane.getThruster(
i);
87 bool out_of_fuel = _fuel_props[
i]._out_of_fuel->getBoolValue();
88 t->setFuelState(!out_of_fuel);
90 double consumed = _fuel_props[
i]._fuel_consumed_lbs->getDoubleValue();
91 _fuel_props[
i]._fuel_consumed_lbs->setDoubleValue(
92 consumed + dt * KG2LBS * t->getFuelFlow());
94 for(
int i=0;
i<_airplane.numTanks();
i++) {
95 _airplane.setFuel(
i, LBS2KG * _tank_level_lbs[
i]->getFloatValue());
97 _airplane.calcFuelWeights();
99 setOutputProperties(dt);
102Airplane* FGFDM::getAirplane()
110 Surface::resetIDgen();
111 _turb_magnitude_norm =
fgGetNode(
"/environment/turbulence/magnitude-norm",
true);
112 _turb_rate_hz =
fgGetNode(
"/environment/turbulence/rate-hz",
true);
115 _gross_weight_lbs = _yasimN->getNode(
"gross-weight-lbs",
true);
118 fgGetNode(
"/yasim/gross-weight-lbs",
true)->alias(_gross_weight_lbs,
false);
121 _yasimN->getNode(
"config-version",
true)->setIntValue(_airplane.getVersion());
122 _yasimN->getNode(
"model/cg-x-min",
true)->setFloatValue(_airplane.getCGHardLimitXMin());
123 _yasimN->getNode(
"model/cg-x-max",
true)->setFloatValue(_airplane.getCGHardLimitXMax());
126 _cg_x = _yasimN->getNode(
"cg-x-m",
true);
127 _cg_xmacN = _yasimN->getNode(
"cg-x-mac",
true);
128 _cg_y = _yasimN->getNode(
"cg-y-m",
true);
129 _cg_z = _yasimN->getNode(
"cg-z-m",
true);
130 _vxN = _yasimN->getNode(
"velocities/v-x",
true);
131 _vyN = _yasimN->getNode(
"velocities/v-y",
true);
132 _vzN = _yasimN->getNode(
"velocities/v-z",
true);
133 _vrxN = _yasimN->getNode(
"velocities/vrot-x",
true);
134 _vryN = _yasimN->getNode(
"velocities/vrot-y",
true);
135 _vrzN = _yasimN->getNode(
"velocities/vrot-z",
true);
136 _axN = _yasimN->getNode(
"accelerations/a-x",
true);
137 _ayN = _yasimN->getNode(
"accelerations/a-y",
true);
138 _azN = _yasimN->getNode(
"accelerations/a-z",
true);
139 _arxN = _yasimN->getNode(
"accelerations/arot-x",
true);
140 _aryN = _yasimN->getNode(
"accelerations/arot-y",
true);
141 _arzN = _yasimN->getNode(
"accelerations/arot-z",
true);
144 _airplane.setFuelFraction(
fgGetFloat(
"/sim/fuel-fraction", 1));
147 _thrust_props.clear();
148 for (
int i=0;
i<_thrusters.size();
i++) {
149 SGPropertyNode_ptr node =
fgGetNode(
"engines/engine",
i,
true);
150 Thruster* t = ((EngRec*)_thrusters.get(
i))->eng;
153 tp._running = node->getChild(
"running", 0,
true);
154 tp._cranking = node->getChild(
"cranking", 0,
true);
155 tp._prop_thrust = node->getChild(
"prop-thrust", 0,
true);
156 tp._thrust_lbs = node->getChild(
"thrust-lbs", 0,
true);
157 tp._fuel_flow_gph = node->getChild(
"fuel-flow-gph", 0,
true);
159 if(t->getPropEngine())
161 tp._rpm = node->getChild(
"rpm", 0,
true);
162 tp._torque_ftlb = node->getChild(
"torque-ftlb", 0,
true);
164 PropEngine*
p = t->getPropEngine();
165 if(
p->getEngine()->isPistonEngine())
167 tp._mp_osi = node->getChild(
"mp-osi", 0,
true);
168 tp._mp_inhg = node->getChild(
"mp-inhg", 0,
true);
169 tp._egt_degf = node->getChild(
"egt-degf", 0,
true);
171 tp._oil_temperature_degf = node->getChild(
"oil-temperature-degf", 0,
true);
172 tp._boost_gauge_inhg = node->getChild(
"boost-gauge-inhg", 0,
true);
173 }
else if(
p->getEngine()->isTurbineEngine()) {
174 tp._n2 = node->getChild(
"n2", 0,
true);
180 tp._n1 = node->getChild(
"n1", 0,
true);
181 tp._n2 = node->getChild(
"n2", 0,
true);
182 tp._epr = node->getChild(
"epr", 0,
true);
183 tp._egt_degf = node->getChild(
"egt-degf", 0,
true);
185 _thrust_props.push_back(tp);
190 for(
int i=0;
i<_airplane.numThrusters();
i++) {
191 SGPropertyNode_ptr e =
fgGetNode(
"engines/engine",
i,
true);
193 f._out_of_fuel = e->getChild(
"out-of-fuel", 0,
true);
194 f._fuel_consumed_lbs = e->getChild(
"fuel-consumed-lbs", 0,
true);
195 _fuel_props.push_back(f);
199 _tank_level_lbs.clear();
200 for(
int i=0;
i<_airplane.numTanks();
i++) {
202 snprintf(buf, 256,
"/consumables/fuel/tank[%d]/level-lbs",
i);
204 _tank_level_lbs.push_back(
fgGetNode(buf,
true));
206 double density = _airplane.getFuelDensity(
i);
207 snprintf(buf, 256,
"/consumables/fuel/tank[%d]/density-ppg",
i);
214 snprintf(buf, 256,
"/consumables/fuel/tank[%d]/capacity-gal_us",
i);
215 fgSetDouble(buf, CM2GALS * _airplane.getTankCapacity(
i)/density);
218 if (_yasimN->getBoolValue(
"respect-external-gear-state") ==
false) {
219 fgSetBool(
"/controls/gear/gear-down",
true);
222 _airplane.getModel()->setTurbulence(_turb);
225void FGFDM::endElement(
const char*
name)
231void FGFDM::startElement(
const char*
name,
const XMLAttributes &a)
237 if (_xml_depth < _xml_last_control_depth) {
260 _control_to_input_properties.clear();
261 _control_to_output_properties.clear();
264 if(!strcmp(
name,
"airplane")) { parseAirplane(&a); }
265 else if(!strcmp(
name,
"approach") || !strcmp(
name,
"cruise")) {
266 parseApproachCruise(&a,
name);
268 else if(!strcmp(
name,
"solve-weight")) { parseSolveWeight(&a); }
269 else if(!strcmp(
name,
"cockpit")) { parseCockpit(&a); }
270 else if(!strcmp(
name,
"rotor")) { parseRotor(&a,
name); }
271 else if(!strcmp(
name,
"rotorgear")) { parseRotorGear(&a); }
272 else if(!strcmp(
name,
"wing") || !strcmp(
name,
"hstab") || !strcmp(
name,
"vstab") || !strcmp(
name,
"mstab")) {
273 parseWing(&a,
name, &_airplane);
275 else if(!strcmp(
name,
"piston-engine")) { parsePistonEngine(&a); }
276 else if(!strcmp(
name,
"turbine-engine")) { parseTurbineEngine(&a); }
277 else if(!strcmp(
name,
"electric-engine")) { parseElectricEngine(&a); }
278 else if(!strcmp(
name,
"propeller")) { parsePropeller(&a); }
279 else if(!strcmp(
name,
"thruster")) { parseThruster(&a); }
280 else if(!strcmp(
name,
"jet")) { parseJet(&a); }
281 else if(!strcmp(
name,
"hitch")) { parseHitch(&a); }
282 else if(!strcmp(
name,
"tow")) { parseTow(&a); }
283 else if(!strcmp(
name,
"winch")) { parseWinch(&a); }
284 else if(!strcmp(
name,
"gear")) { parseGear(&a); }
285 else if(!strcmp(
name,
"hook")) { parseHook(&a); }
286 else if(!strcmp(
name,
"launchbar")) { parseLaunchbar(&a); }
287 else if(!strcmp(
name,
"fuselage")) { parseFuselage(&a); }
288 else if(!strcmp(
name,
"tank")) { parseTank(&a); }
289 else if(!strcmp(
name,
"ballast")) { parseBallast(&a); }
290 else if(!strcmp(
name,
"weight")) { parseWeight(&a); }
291 else if(!strcmp(
name,
"stall")) { parseStall(&a); }
292 else if(!strcmp(
name,
"flap0") || !strcmp(
name,
"flap1") || !strcmp(
name,
"spoiler") || !strcmp(
name,
"slat")) {
295 else if(!strcmp(
name,
"actionpt")) {
297 ((Thruster*)_currObj)->setPosition(v);
299 else if(!strcmp(
name,
"dir")) {
301 ((Thruster*)_currObj)->setDirection(v);
303 else if(!strcmp(
name,
"control-setting")) { parseControlSetting(&a); }
304 else if(!strcmp(
name,
"control-input")) {
305 _xml_last_control_depth = _xml_depth;
308 else if(!strcmp(
name,
"control-output")) {
309 _xml_last_control_depth = _xml_depth;
312 else if(!strcmp(
name,
"control-speed")) { parseControlSpeed(&a); }
314 SG_LOG(SG_FLIGHT,SG_ALERT,
"Unexpected tag '" <<
name <<
"' found in YASim aircraft description");
319void FGFDM::parseAirplane(
const XMLAttributes* a)
322 if(a->hasAttribute(
"mass")) { f = attrf(a,
"mass") * LBS2KG; }
323 else if (a->hasAttribute(
"mass-lbs")) { f = attrf(a,
"mass-lbs") * LBS2KG; }
324 else if (a->hasAttribute(
"mass-kg")) { f = attrf(a,
"mass-kg"); }
326 SG_LOG(SG_FLIGHT,SG_ALERT,
"YASim fatal: missing attribute, airplane needs one of {mass-lbs, mass-kg}");
329 _airplane.setEmptyWeight(f);
330 if(a->hasAttribute(
"version")) { _airplane.setVersion(a->getValue(
"version")); }
331 if( !_airplane.isVersionOrNewer( YASIM_VERSION::CURRENT ) ) {
332 SG_LOG(SG_FLIGHT, SG_DEV_ALERT,
"This aircraft does not use the latest yasim configuration version.");
334 _airplane.setDesiredCGRangeInPercentOfMAC(attrf(a,
"cg-min", 0.25f), attrf(a,
"cg-max", 0.3f));
336 if (a->hasAttribute(
"mtow-lbs")) { _airplane.setMTOW(attrf(a,
"mtow-lbs") * LBS2KG); }
337 else if (a->hasAttribute(
"mtow-kg")) { _airplane.setMTOW(attrf(a,
"mtow-kg")); }
338 if (a->hasAttribute(
"solver-mode")) { _airplane.setSolverMode(attri(a,
"solver-mode")); }
341void FGFDM::parseApproachCruise(
const XMLAttributes* a,
const char*
name)
344 if (a->hasAttribute(
"speed")) { spd = attrf(a,
"speed") * KTS2MPS; }
345 else if (a->hasAttribute(
"speed-kt")) { spd = attrf(a,
"speed-kt") * KTS2MPS; }
346 else if (a->hasAttribute(
"speed-kmh")) { spd = attrf(a,
"speed-kmh") * KMH2MPS; }
348 SG_LOG(SG_FLIGHT,SG_ALERT,
"YASim fatal: missing attribute, "<<
name <<
" needs one of {speed-kt, speed-kmh}");
351 if (a->hasAttribute(
"alt")) { alt = attrf(a,
"alt") * FT2M; }
352 else if (a->hasAttribute(
"alt-ft")) { alt = attrf(a,
"alt-ft") * FT2M; }
353 else if (a->hasAttribute(
"alt-m")) { alt = attrf(a,
"alt-m"); }
354 float gla = attrf(a,
"glide-angle", 0) *
DEG2RAD;
355 if (!strcmp(
name,
"approach")) {
356 float aoa = attrf(a,
"aoa", 0) *
DEG2RAD;
357 _airplaneCfg = Airplane::Configuration::APPROACH;
358 _airplane.setConfig(_airplaneCfg, spd, alt, attrf(a,
"fuel", 0.2), gla, aoa);
361 _airplaneCfg = Airplane::Configuration::CRUISE;
362 _airplane.setConfig(_airplaneCfg, spd, alt, attrf(a,
"fuel", 0.5), gla);
366void FGFDM::parseSolveWeight(
const XMLAttributes* a)
369 int idx = attri(a,
"idx");
370 if(a->hasAttribute(
"weight")) { f = attrf(a,
"weight") * LBS2KG; }
371 else if(a->hasAttribute(
"weight-lbs")) { f = attrf(a,
"weight-lbs") * LBS2KG; }
372 else if(a->hasAttribute(
"weight-kg")) { f = attrf(a,
"weight-kg"); }
374 SG_LOG(SG_FLIGHT,SG_ALERT,
"YASim fatal: missing attribute, solve-weight needs one of {weight-lbs, weight-kg}");
377 _airplane.addSolutionWeight(_airplaneCfg, idx, f);
380void FGFDM::parseCockpit(
const XMLAttributes* a)
384 _airplane.setPilotPos(v);
388void FGFDM::getExternalInput(
float dt)
392 _turb->setMagnitude(_turb_magnitude_norm->getFloatValue());
393 _turb->update(dt, _turb_rate_hz->getFloatValue());
396 ControlMap* cm = _airplane.getControlMap();
399 for(
int i=0;
i < cm->numProperties();
i++) {
400 ControlMap::PropHandle *
p = cm->getProperty(
i);
402 cm->setInput(
p->handle, val);
404 cm->applyControls(dt);
407 for(
int i=0;
i<_weights.size();
i++) {
408 WeightRec* wr = (WeightRec*)_weights.get(
i);
409 _airplane.setWeight(wr->handle, LBS2KG *
fgGetFloat(wr->prop));
412 for(
int i=0;
i<_thrusters.size();
i++) {
413 EngRec* er = (EngRec*)_thrusters.get(
i);
414 Thruster* t = er->eng;
416 if(t->getPropEngine()) {
417 PropEngine*
p = t->getPropEngine();
418 snprintf(buf, 256,
"%s/rpm", er->prefix.c_str());
426static void moveprop(SGPropertyNode* node,
const std::string& prop,
427 float target,
float frac)
429 float val = node->getFloatValue(prop);
430 if(frac > 1) frac = 1;
431 if(frac < 0) frac = 0;
432 val += (target - val) * frac;
433 node->setFloatValue(prop, val);
436void FGFDM::setOutputProperties(
float dt)
438 float grossWgt = _airplane.getModel()->getBody()->getTotalMass() * KG2LBS;
439 _gross_weight_lbs->setFloatValue(grossWgt);
442 _airplane.getModel()->getBody()->getCG(cg);
443 _cg_x->setFloatValue(cg[0]);
444 _cg_y->setFloatValue(cg[1]);
445 _cg_z->setFloatValue(cg[2]);
446 _cg_xmacN->setFloatValue(_airplane.getCGMAC());
448 State* s = _airplane.getModel()->getState();
449 float v[3], acc[3], rot[3], racc[3];
450 Math::vmul33(s->orient, s->v, v);
451 Math::vmul33(s->orient, s->acc, acc);
452 Math::vmul33(s->orient, s->rot, rot);
453 Math::vmul33(s->orient, s->racc, racc);
455 _vxN->setFloatValue(v[0]);
456 _vyN->setFloatValue(v[1]);
457 _vzN->setFloatValue(v[2]);
458 _vrxN->setFloatValue(rot[0]);
459 _vryN->setFloatValue(rot[1]);
460 _vrzN->setFloatValue(rot[2]);
461 _axN->setFloatValue(acc[0]);
462 _ayN->setFloatValue(acc[1]);
463 _azN->setFloatValue(acc[2]);
464 _arxN->setFloatValue(racc[0]);
465 _aryN->setFloatValue(racc[1]);
466 _arzN->setFloatValue(racc[2]);
468 ControlMap* cm = _airplane.getControlMap();
469 for(
int i=0;
i<_controlOutputs.size();
i++) {
470 ControlOutput*
p = (ControlOutput*)_controlOutputs.get(
i);
472 ? cm->getOutput(
p->handle)
473 : cm->getOutputR(
p->handle));
474 float rmin = cm->rangeMin(
p->control);
475 float rmax = cm->rangeMax(
p->control);
476 float frac = (val - rmin) / (rmax - rmin);
478 val = frac*(
p->max -
p->min) +
p->min;
479 p->prop->setFloatValue(val);
482 for(
int i=0;
i<_airplane.getRotorgear()->getNumRotors();
i++) {
483 Rotor*r=(Rotor*)_airplane.getRotorgear()->getRotor(
i);
487 while((j = r->getValueforFGSet(j, b, &f)))
490 while((j = _airplane.getRotorgear()->getValueforFGSet(j, b, &f)))
492 for(j=0; j < r->numRotorparts(); j+=r->numRotorparts()>>2) {
493 Rotorpart* s = (Rotorpart*)r->getRotorpart(j);
497 b=s->getAlphaoutput(k);
504 float fuelDensity = 1.0;
505 if(_airplane.numTanks())
506 fuelDensity = _airplane.getFuelDensity(0);
507 for(
int i=0;
i<_thrusters.size();
i++) {
508 EngRec* er = (EngRec*)_thrusters.get(
i);
509 Thruster* t = er->eng;
510 SGPropertyNode * node =
fgGetNode(
"engines/engine",
i,
true);
512 ThrusterProps& tp = _thrust_props[
i];
515 tp._running->setBoolValue(t->isRunning());
516 tp._cranking->setBoolValue(t->isCranking());
520 float lbs = Math::mag3(tmp) * (KG2LBS/9.8);
521 if (tmp[0] < 0) lbs = -lbs;
522 tp._prop_thrust->setFloatValue(lbs);
523 tp._thrust_lbs->setFloatValue(lbs);
524 tp._fuel_flow_gph->setFloatValue(
525 (t->getFuelFlow()/fuelDensity) * 3600 * CM2GALS);
527 if(t->getPropEngine()) {
528 PropEngine*
p = t->getPropEngine();
529 tp._rpm->setFloatValue(
p->getOmega() * (1/RPM2RAD));
530 tp._torque_ftlb->setFloatValue(
531 p->getEngine()->getTorque() * NM2FTLB);
533 if(
p->getEngine()->isPistonEngine()) {
534 PistonEngine* pe =
p->getEngine()->isPistonEngine();
535 tp._mp_osi->setFloatValue(pe->getMP() * (1/INHG2PA));
536 tp._mp_inhg->setFloatValue(pe->getMP() * (1/INHG2PA));
537 tp._egt_degf->setFloatValue(
538 pe->getEGT() * K2DEGF + K2DEGFOFFSET);
539 tp._oil_temperature_degf->setFloatValue(
540 pe->getOilTemp() * K2DEGF + K2DEGFOFFSET);
541 tp._boost_gauge_inhg->setFloatValue(
542 pe->getBoost() * (1/INHG2PA));
543 }
else if(
p->getEngine()->isTurbineEngine()) {
544 TurbineEngine* te =
p->getEngine()->isTurbineEngine();
545 tp._n2->setFloatValue(te->getN2());
550 Jet* j = t->getJet();
551 tp._n1->setFloatValue(j->getN1());
552 tp._n2->setFloatValue(j->getN2());
553 tp._epr->setFloatValue(j->getEPR());
554 tp._egt_degf->setFloatValue(
555 j->getEGT() * K2DEGF + K2DEGFOFFSET);
561 float pnorm = j->getPerfNorm();
562 moveprop(node,
"oilp-norm", pnorm, dt/3);
563 moveprop(node,
"oilt-norm", pnorm, dt/30);
564 moveprop(node,
"itt-norm", pnorm, dt/1);
569void FGFDM::parseWing(
const XMLAttributes* a,
const char* type, Airplane* airplane)
574 if(!strcmp(type,
"vstab")) {
579 float base[3] {0,0,0};
581 float length = attrf(a,
"length");
586 float twist = attrf(a,
"twist", 0) *
DEG2RAD;
590 float isSection = attrb(a,
"append");
593 chord = attrf(a,
"chord");
594 incidence = attrf(a,
"incidence", 0) *
DEG2RAD;
597 if (a->hasAttribute(
"x") || a->hasAttribute(
"y") || a->hasAttribute(
"z") ||
598 a->hasAttribute(
"chord") || a->hasAttribute(
"incidence")
600 SG_LOG(SG_FLIGHT, SG_WARN,
"YASim warning: redundant attribute in wing definition \n"
601 "when using <wing append=\"1\" ...> x, y, z, chord and incidence will be ignored. ");
606 float sweep = attrf(a,
"sweep", 0) *
DEG2RAD;
607 float taper = attrf(a,
"taper", 1);
608 float dihedral = attrf(a,
"dihedral", defDihed) *
DEG2RAD;
611 float camber = attrf(a,
"camber", 0);
612 if (!airplane->isVersionOrNewer(YASIM_VERSION::V_2017_2) && (camber == 0)) {
613 SG_LOG(SG_FLIGHT, SG_DEV_WARN,
"YASIM warning: versions before 2017.2 are buggy for wings with camber=0");
618 float idrag = 0.7*attrf(a,
"idrag", 1);
622 if (!strcmp(type,
"wing"))
624 w = airplane->getWing();
626 else if (!strcmp(type,
"hstab")) {
627 w = airplane->getTail();
628 if (a->hasAttribute(
"incidence-max-deg")) w->setIncidenceMax(attrf(a,
"incidence-max-deg") *
DEG2RAD);
629 if (a->hasAttribute(
"incidence-min-deg")) w->setIncidenceMin(attrf(a,
"incidence-min-deg") *
DEG2RAD);
631 w =
new Wing(airplane, mirror);
635 _wingSection = w->addWingSection(base, chord, length, taper, sweep, dihedral, twist, camber, idrag, incidence);
636 if (!strcmp(type,
"vstab") || !strcmp(type,
"mstab"))
638 airplane->addVStab(w);
641 float dragFactor = attrf(a,
"pdrag", 1);
642 if (a->hasAttribute(
"effectiveness")) {
650 dragFactor = attrf(a,
"effectiveness", 1);
652 w->setSectionDrag(_wingSection, dragFactor);
653 if (a->hasAttribute(
"flow")) {
654 const char* flowregime = a->getValue(
"flow");
655 if (!strcmp(flowregime,
"TRANSONIC")) {
656 w->setFlowRegime(FLOW_TRANSONIC);
657 const float mcrit = attrf(a,
"mcrit", 0.6f);
658 if ( (mcrit > 0.0f) && (mcrit <= 1.0f)) {
659 w->setCriticalMachNumber(mcrit);
661 SG_LOG(SG_FLIGHT, SG_ALERT,
"YASim warning: invalid input for critical mach number. Defaulting to mcrit=0.6.");
665 w->setFlowRegime(FLOW_SUBSONIC);
670void FGFDM::parseRotor(
const XMLAttributes* a,
const char* type)
672 Rotor* w =
new Rotor();
681 normal[0] = attrf(a,
"nx");
682 normal[1] = attrf(a,
"ny");
683 normal[2] = attrf(a,
"nz");
684 w->setNormal(normal);
687 forward[0] = attrf(a,
"fx");
688 forward[1] = attrf(a,
"fy");
689 forward[2] = attrf(a,
"fz");
690 w->setForward(forward);
692 w->setMaxCyclicail(attrf(a,
"maxcyclicail", 7.6));
693 w->setMaxCyclicele(attrf(a,
"maxcyclicele", 4.94));
694 w->setMinCyclicail(attrf(a,
"mincyclicail", -7.6));
695 w->setMinCyclicele(attrf(a,
"mincyclicele", -4.94));
696 w->setMaxCollective(attrf(a,
"maxcollective", 15.8));
697 w->setMinCollective(attrf(a,
"mincollective", -0.2));
698 w->setDiameter(attrf(a,
"diameter", 10.2));
699 w->setWeightPerBlade(attrf(a,
"weightperblade", 44));
700 w->setNumberOfBlades(attrf(a,
"numblades", 4));
701 w->setRelBladeCenter(attrf(a,
"relbladecenter", 0.7));
702 w->setDynamic(attrf(a,
"dynamic", 0.7));
703 w->setDelta3(attrf(a,
"delta3", 0));
704 w->setDelta(attrf(a,
"delta", 0));
705 w->setTranslift(attrf(a,
"translift", 0.05));
706 w->setC2(attrf(a,
"dragfactor", 1));
707 w->setStepspersecond(attrf(a,
"stepspersecond", 120));
708 w->setPhiNull((attrf(a,
"phi0", 0))*
YASIM_PI/180);
709 w->setRPM(attrf(a,
"rpm", 424));
710 w->setRelLenHinge(attrf(a,
"rellenflaphinge", 0.07));
711 w->setAlpha0((attrf(a,
"flap0", -5))*
YASIM_PI/180);
712 w->setAlphamin((attrf(a,
"flapmin", -15))/180*
YASIM_PI);
713 w->setAlphamax((attrf(a,
"flapmax", 15))*
YASIM_PI/180);
714 w->setAlpha0factor(attrf(a,
"flap0factor", 1));
715 w->setTeeterdamp(attrf(a,
"teeterdamp",.0001));
716 w->setMaxteeterdamp(attrf(a,
"maxteeterdamp",1000));
717 w->setRelLenTeeterHinge(attrf(a,
"rellenteeterhinge",0.01));
718 w->setBalance(attrf(a,
"balance",1.0));
719 w->setMinTiltYaw(attrf(a,
"mintiltyaw",0.0));
720 w->setMinTiltPitch(attrf(a,
"mintiltpitch",0.0));
721 w->setMinTiltRoll(attrf(a,
"mintiltroll",0.0));
722 w->setMaxTiltYaw(attrf(a,
"maxtiltyaw",0.0));
723 w->setMaxTiltPitch(attrf(a,
"maxtiltpitch",0.0));
724 w->setMaxTiltRoll(attrf(a,
"maxtiltroll",0.0));
725 w->setTiltCenterX(attrf(a,
"tiltcenterx",0.0));
726 w->setTiltCenterY(attrf(a,
"tiltcentery",0.0));
727 w->setTiltCenterZ(attrf(a,
"tiltcenterz",0.0));
728 w->setDownwashFactor(attrf(a,
"downwashfactor", 1));
731 if(attrb(a,
"sharedflaphinge"))
732 w->setSharedFlapHinge(
true);
734 if(a->hasAttribute(
"name")) w->setName(a->getValue(
"name"));
735 if(a->hasAttribute(
"alphaout0")) w->setAlphaoutput(0,a->getValue(
"alphaout0"));
736 if(a->hasAttribute(
"alphaout1")) w->setAlphaoutput(1,a->getValue(
"alphaout1"));
737 if(a->hasAttribute(
"alphaout2")) w->setAlphaoutput(2,a->getValue(
"alphaout2"));
738 if(a->hasAttribute(
"alphaout3")) w->setAlphaoutput(3,a->getValue(
"alphaout3"));
739 if(a->hasAttribute(
"coneout")) w->setAlphaoutput(4,a->getValue(
"coneout"));
740 if(a->hasAttribute(
"yawout")) w->setAlphaoutput(5,a->getValue(
"yawout"));
741 if(a->hasAttribute(
"rollout")) w->setAlphaoutput(6,a->getValue(
"rollout"));
743 w->setPitchA(attrf(a,
"pitch-a", 10));
744 w->setPitchB(attrf(a,
"pitch-b", 10));
745 w->setForceAtPitchA(attrf(a,
"forceatpitch-a", 3000));
746 w->setPowerAtPitch0(attrf(a,
"poweratpitch-0", 300));
747 w->setPowerAtPitchB(attrf(a,
"poweratpitch-b", 3000));
748 if(attrb(a,
"notorque")) w->setNotorque(1);
750#define p(x) if (a->hasAttribute(#x)) w->setParameter((char *)#x,attrf(a,#x) );
751#define p2(x,y) if (a->hasAttribute(y)) w->setParameter((char *)#x,attrf(a,y) );
752 p2(translift_ve,
"translift-ve")
753 p2(translift_maxfactor,
"translift-maxfactor")
754 p2(ground_effect_constant,
"ground-effect-constant")
755 p2(vortex_state_lift_factor,
"vortex-state-lift-factor")
756 p2(vortex_state_c1,
"vortex-state-c1")
757 p2(vortex_state_c2,
"vortex-state-c2")
758 p2(vortex_state_c3,
"vortex-state_c3")
759 p2(vortex_state_e1,
"vortex-state-e1")
760 p2(vortex_state_e2,
"vortex-state-e2")
762 p2(number_of_segments,
"number-of-segments")
763 p2(number_of_parts,
"number-of-parts")
764 p2(rel_len_where_incidence_is_measured,
"rel-len-where-incidence-is-measured")
767 p2(airfoil_incidence_no_lift,
"airfoil-incidence-no-lift")
768 p2(rel_len_blade_start,
"rel-len-blade-start")
769 p2(incidence_stall_zero_speed,
"incidence-stall-zero-speed")
770 p2(incidence_stall_half_sonic_speed,
"incidence-stall-half-sonic-speed")
771 p2(lift_factor_stall,
"lift-factor-stall")
772 p2(stall_change_over,
"stall-change-over")
773 p2(drag_factor_stall,
"drag-factor-stall")
774 p2(airfoil_lift_coefficient,
"airfoil-lift-coefficient")
775 p2(airfoil_drag_coefficient0,
"airfoil-drag-coefficient0")
776 p2(airfoil_drag_coefficient1,
"airfoil-drag-coefficient1")
777 p2(cyclic_factor,
"cyclic-factor")
778 p2(rotor_correction_factor,
"rotor-correction-factor")
782 _airplane.getModel()->getRotorgear()->addRotor(w);
785void FGFDM::parseRotorGear(
const XMLAttributes* a)
787 Rotorgear* r = _airplane.getModel()->getRotorgear();
789 #define p(x) if (a->hasAttribute(#x)) r->setParameter((char *)#x,attrf(a,#x) );
790 #define p2(x,y) if (a->hasAttribute(y)) r->setParameter((char *)#x,attrf(a,y) );
791 p2(max_power_engine,
"max-power-engine")
792 p2(engine_prop_factor,
"engine-prop-factor")
795 p2(max_power_rotor_brake,
"max-power-rotor-brake")
796 p2(rotorgear_friction,
"rotorgear-friction")
797 p2(engine_accel_limit,
"engine-accel-limit")
803void FGFDM::parsePistonEngine(
const XMLAttributes* a)
805 float engP = attrf(a,
"eng-power") *
HP2W;
806 float engS = attrf(a,
"eng-rpm") * RPM2RAD;
808 PistonEngine* eng =
new PistonEngine(engP, engS);
810 if(a->hasAttribute(
"displacement"))
811 eng->setDisplacement(attrf(a,
"displacement") *
CIN2CM);
813 if(a->hasAttribute(
"compression"))
814 eng->setCompression(attrf(a,
"compression"));
816 if(a->hasAttribute(
"min-throttle"))
817 eng->setMinThrottle(attrf(a,
"min-throttle"));
819 if(a->hasAttribute(
"turbo-mul")) {
820 float mul = attrf(a,
"turbo-mul");
821 float mp = attrf(a,
"wastegate-mp", 1e6) * INHG2PA;
822 eng->setTurboParams(mul, mp);
823 eng->setTurboLag(attrf(a,
"turbo-lag", 2));
826 if(a->hasAttribute(
"supercharger"))
827 eng->setSupercharger(attrb(a,
"supercharger"));
829 ((PropEngine*)_currObj)->setEngine(eng);
832void FGFDM::parseTurbineEngine(
const XMLAttributes* a)
834 float power = attrf(a,
"eng-power") *
HP2W;
835 float omega = attrf(a,
"eng-rpm") * RPM2RAD;
836 float alt = attrf(a,
"alt") * FT2M;
837 float flatRating = attrf(a,
"flat-rating") *
HP2W;
838 TurbineEngine* eng =
new TurbineEngine(power, omega, alt, flatRating);
840 if(a->hasAttribute(
"n2-low-idle"))
841 eng->setN2Range(attrf(a,
"n2-low-idle"), attrf(a,
"n2-high-idle"),
845 if(a->hasAttribute(
"bsfc"))
846 eng->setFuelConsumption(attrf(a,
"bsfc") * (LBS2KG/(3600*
HP2W)));
848 ((PropEngine*)_currObj)->setEngine(eng);
851void FGFDM::parseElectricEngine(
const XMLAttributes* a)
853 float Kv = attrf(a,
"Kv") * RPM2RAD;
854 float voltage = attrf(a,
"voltage");
855 float Rm = attrf(a,
"Rm");
856 ElectricEngine* eng =
new ElectricEngine(voltage, Kv, Rm);
858 ((PropEngine*)_currObj)->setEngine(eng);
862void FGFDM::parsePropeller(
const XMLAttributes* a)
865 PistonEngine* eng = 0;
866 if(a->hasAttribute(
"eng-power")) {
867 SG_LOG(SG_FLIGHT,SG_ALERT,
"WARNING: "
868 <<
"Legacy engine definition in YASim configuration file. "
870 float engP = attrf(a,
"eng-power") *
HP2W;
871 float engS = attrf(a,
"eng-rpm") * RPM2RAD;
872 eng =
new PistonEngine(engP, engS);
873 if(a->hasAttribute(
"displacement"))
874 eng->setDisplacement(attrf(a,
"displacement") *
CIN2CM);
875 if(a->hasAttribute(
"compression"))
876 eng->setCompression(attrf(a,
"compression"));
877 if(a->hasAttribute(
"turbo-mul")) {
878 float mul = attrf(a,
"turbo-mul");
879 float mp = attrf(a,
"wastegate-mp", 1e6) * INHG2PA;
880 eng->setTurboParams(mul, mp);
887 float mass = attrf(a,
"mass") * LBS2KG;
888 float moment = attrf(a,
"moment");
889 float radius = attrf(a,
"radius");
890 float speed = attrf(a,
"cruise-speed") * KTS2MPS;
891 float omega = attrf(a,
"cruise-rpm") * RPM2RAD;
892 float power = attrf(a,
"cruise-power") *
HP2W;
893 float rho = Atmosphere::getStdDensity(attrf(a,
"cruise-alt") * FT2M);
895 Propeller* prop =
new Propeller(radius, speed, omega, rho, power);
896 PropEngine* thruster =
new PropEngine(prop, eng, moment);
897 _airplane.addThruster(thruster, mass, cg);
900 float fine_stop = attrf(a,
"fine-stop", 0.25f);
901 float coarse_stop = attrf(a,
"coarse-stop", 4.0f);
902 prop->setStops(fine_stop, coarse_stop);
904 if(a->hasAttribute(
"takeoff-power")) {
905 float power0 = attrf(a,
"takeoff-power") *
HP2W;
906 float omega0 = attrf(a,
"takeoff-rpm") * RPM2RAD;
907 prop->setTakeoff(omega0, power0);
910 if(a->hasAttribute(
"max-rpm")) {
911 float max = attrf(a,
"max-rpm") * RPM2RAD;
912 float min = attrf(a,
"min-rpm") * RPM2RAD;
913 thruster->setVariableProp(
min, max);
916 if(attrb(a,
"contra"))
917 thruster->setContraPair(
true);
919 if(a->hasAttribute(
"manual-pitch")) {
920 prop->setManualPitch();
923 thruster->setGearRatio(attrf(a,
"gear-ratio", 1));
926 snprintf(buf, 64,
"/engines/engine[%d]", _nextEngine++);
927 EngRec* er =
new EngRec();
935void FGFDM::parseThruster(
const XMLAttributes* a)
938 SimpleJet* j =
new SimpleJet();
942 _airplane.addThruster(j, 0, v);
943 v[0] = attrf(a,
"vx"); v[1] = attrf(a,
"vy"); v[2] = attrf(a,
"vz");
945 j->setThrust(attrf(a,
"thrust") * LBS2N);
948void FGFDM::parseJet(
const XMLAttributes* a)
955 if(a->hasAttribute(
"mass")) { mass = attrf(a,
"mass") * LBS2KG; }
956 else if(a->hasAttribute(
"mass-lbs")) { mass = attrf(a,
"mass-lbs") * LBS2KG; }
957 else if(a->hasAttribute(
"mass-kg")) { mass = attrf(a,
"mass-kg"); }
959 SG_LOG(SG_FLIGHT,SG_ALERT,
"YASim fatal: missing attribute, jet needs one of {mass-lbs, mass-kg}");
962 j->setMaxThrust(attrf(a,
"thrust") * LBS2N, attrf(a,
"afterburner", 0) * LBS2N);
963 j->setVectorAngle(attrf(a,
"rotate", 0) *
DEG2RAD);
964 j->setReverseThrust(attrf(a,
"reverse", 0.2));
966 float n1min = attrf(a,
"n1-idle", 55);
967 float n1max = attrf(a,
"n1-max", 102);
968 float n2min = attrf(a,
"n2-idle", 73);
969 float n2max = attrf(a,
"n2-max", 103);
970 j->setRPMs(n1min, n1max, n2min, n2max);
972 j->setTSFC(attrf(a,
"tsfc", 0.8));
973 j->setATSFC(attrf(a,
"atsfc", 0.0));
974 if(a->hasAttribute(
"egt")) j->setEGT(attrf(a,
"egt"));
975 if(a->hasAttribute(
"epr")) j->setEPR(attrf(a,
"epr"));
976 if(a->hasAttribute(
"exhaust-speed"))
977 j->setVMax(attrf(a,
"exhaust-speed") * KTS2MPS);
978 if(a->hasAttribute(
"spool-time"))
979 j->setSpooling(attrf(a,
"spool-time"));
982 _airplane.addThruster(j, mass, v);
984 snprintf(buf, 64,
"/engines/engine[%d]", _nextEngine++);
985 EngRec* er =
new EngRec();
991void FGFDM::parseHitch(
const XMLAttributes* a)
994 Hitch* h =
new Hitch(a->getValue(
"name"));
998 if(a->hasAttribute(
"force-is-calculated-by-other")) h->setForceIsCalculatedByOther(attrb(a,
"force-is-calculated-by-other"));
999 _airplane.addHitch(h);
1002void FGFDM::parseTow(
const XMLAttributes* a)
1004 Hitch* h = (Hitch*)_currObj;
1005 if(a->hasAttribute(
"length"))
1006 h->setTowLength(attrf(a,
"length"));
1007 if(a->hasAttribute(
"elastic-constant"))
1008 h->setTowElasticConstant(attrf(a,
"elastic-constant"));
1009 if(a->hasAttribute(
"break-force"))
1010 h->setTowBreakForce(attrf(a,
"break-force"));
1011 if(a->hasAttribute(
"weight-per-meter"))
1012 h->setTowWeightPerM(attrf(a,
"weight-per-meter"));
1013 if(a->hasAttribute(
"mp-auto-connect-period"))
1014 h->setMpAutoConnectPeriod(attrf(a,
"mp-auto-connect-period"));
1017void FGFDM::parseWinch(
const XMLAttributes* a)
1019 Hitch* h = (Hitch*)_currObj;
1021 pos[0] = attrd(a,
"x",0);
1022 pos[1] = attrd(a,
"y",0);
1023 pos[2] = attrd(a,
"z",0);
1024 h->setWinchPosition(pos);
1025 if(a->hasAttribute(
"max-speed"))
1026 h->setWinchMaxSpeed(attrf(a,
"max-speed"));
1027 if(a->hasAttribute(
"power"))
1028 h->setWinchPower(attrf(a,
"power") * 1000);
1029 if(a->hasAttribute(
"max-force"))
1030 h->setWinchMaxForce(attrf(a,
"max-force"));
1031 if(a->hasAttribute(
"initial-tow-length"))
1032 h->setWinchInitialTowLength(attrf(a,
"initial-tow-length"));
1033 if(a->hasAttribute(
"max-tow-length"))
1034 h->setWinchMaxTowLength(attrf(a,
"max-tow-length"));
1035 if(a->hasAttribute(
"min-tow-length"))
1036 h->setWinchMinTowLength(attrf(a,
"min-tow-length"));
1039void FGFDM::parseGear(
const XMLAttributes* a)
1042 Gear*
g =
new Gear();
1046 if (a->hasAttribute(
"wheel-x")) {
1047 v[0] = attrf(a,
"wheel-x");
1048 v[1] = attrf(a,
"wheel-y");
1049 v[2] = attrf(a,
"wheel-z");
1056 float nrm = Math::mag3(v);
1057 if (_vehicle_radius < nrm)
1058 _vehicle_radius = nrm;
1059 if(a->hasAttribute(
"upx")) {
1060 v[0] = attrf(a,
"upx");
1061 v[1] = attrf(a,
"upy");
1062 v[2] = attrf(a,
"upz");
1069 for(
int i=0;
i<3;
i++)
1070 v[
i] *= attrf(a,
"compression", 1);
1071 g->setCompression(v);
1073 if (a->hasAttribute(
"wheel-axle-x")) {
1074 v[0] = attrf(a,
"wheel-axle-x");
1075 v[1] = attrf(a,
"wheel-axle-y");
1076 v[2] = attrf(a,
"wheel-axle-z");
1083 g->setWheelAxle( v);
1085 g->setWheelRadius( attrf(a,
"wheel-radius", 0));
1086 g->setTyreRadius( attrf(a,
"tyre-radius", 0));
1088 g->setBrake(attrf(a,
"skid", 0));
1089 g->setInitialLoad(attrf(a,
"initial-load", 0));
1090 g->setStaticFriction(attrf(a,
"sfric", 0.8));
1091 g->setDynamicFriction(attrf(a,
"dfric", 0.7));
1092 g->setSpring(attrf(a,
"spring", 1));
1093 g->setSpring2(attrf(a,
"spring2", 0));
1094 g->setDamping(attrf(a,
"damp", 1));
1095 if(a->hasAttribute(
"on-water"))
g->setOnWater(attrb(a,
"on-water"));
1096 if(a->hasAttribute(
"on-solid"))
g->setOnSolid(attrb(a,
"on-solid"));
1097 if(a->hasAttribute(
"ignored-by-solver"))
g->setIgnoreWhileSolving(attrb(a,
"ignored-by-solver"));
1098 g->setSpringFactorNotPlaning(attrf(a,
"spring-factor-not-planing", 1));
1099 g->setSpeedPlaning(attrf(a,
"speed-planing", 0) * KTS2MPS);
1100 g->setReduceFrictionByExtension(attrf(a,
"reduce-friction-by-extension", 0));
1101 g->setStiction(attrf(a,
"stiction", 0));
1102 g->setStictionABS(attrf(a,
"stiction-abs", 0));
1103 _airplane.addGear(g);
1106void FGFDM::parseHook(
const XMLAttributes* a)
1109 Hook* h =
new Hook();
1113 float length = attrf(a,
"length", 1.0);
1114 h->setLength(length);
1115 float nrm = length+Math::mag3(v);
1116 if (_vehicle_radius < nrm)
1117 _vehicle_radius = nrm;
1118 h->setDownAngle(attrf(a,
"down-angle", 70) *
DEG2RAD);
1119 h->setUpAngle(attrf(a,
"up-angle", 0) *
DEG2RAD);
1120 _airplane.addHook(h);
1123void FGFDM::parseLaunchbar(
const XMLAttributes* a)
1126 Launchbar* l =
new Launchbar();
1129 l->setLaunchbarMount(v);
1130 v[0] = attrf(a,
"holdback-x", v[0]);
1131 v[1] = attrf(a,
"holdback-y", v[1]);
1132 v[2] = attrf(a,
"holdback-z", v[2]);
1133 l->setHoldbackMount(v);
1134 float length = attrf(a,
"length", 1.0);
1135 l->setLength(length);
1136 l->setDownAngle(attrf(a,
"down-angle", 45) *
DEG2RAD);
1137 l->setUpAngle(attrf(a,
"up-angle", -45) *
DEG2RAD);
1138 l->setHoldbackLength(attrf(a,
"holdback-length", 2.0));
1139 _airplane.addLaunchbar(l);
1142void FGFDM::parseFuselage(
const XMLAttributes* a)
1146 v[0] = attrf(a,
"ax");
1147 v[1] = attrf(a,
"ay");
1148 v[2] = attrf(a,
"az");
1149 b[0] = attrf(a,
"bx");
1150 b[1] = attrf(a,
"by");
1151 b[2] = attrf(a,
"bz");
1152 float taper = attrf(a,
"taper", 1);
1153 float mid = attrf(a,
"midpoint", 0.5);
1154 if (_airplane.isVersionOrNewer(YASIM_VERSION::V_32)) {
1163 float cx = attrf(a,
"cx", 1);
1164 float cy = attrf(a,
"cy", 1);
1165 float cz = attrf(a,
"cz", 1);
1166 float idrag = attrf(a,
"idrag", 1);
1167 _airplane.addFuselage(v, b, attrf(a,
"width"), taper, mid, cx, cy, cz, idrag);
1170void FGFDM::parseTank(
const XMLAttributes* a)
1174 float density = 6.0;
1175 if(a->hasAttribute(
"jet")) density = 6.72;
1176 density *= LBS2KG*CM2GALS;
1178 if(a->hasAttribute(
"capacity")) { capacity = attrf(a,
"capacity") * LBS2KG; }
1179 else if(a->hasAttribute(
"capacity-lbs")) { capacity = attrf(a,
"capacity-lbs") * LBS2KG; }
1180 else if(a->hasAttribute(
"capacity-kg")) { capacity = attrf(a,
"capacity-kg"); }
1182 SG_LOG(SG_FLIGHT,SG_ALERT,
"YASim fatal: missing attribute, tank needs one of {capacity-lbs, capacity-kg}");
1185 _airplane.addTank(v, capacity, density);
1188void FGFDM::parseBallast(
const XMLAttributes* a)
1193 if(a->hasAttribute(
"mass")) { f = attrf(a,
"mass") * LBS2KG; }
1194 else if (a->hasAttribute(
"mass-lbs")) { f = attrf(a,
"mass-lbs") * LBS2KG; }
1195 else if (a->hasAttribute(
"mass-kg")) { f = attrf(a,
"mass-kg"); }
1197 SG_LOG(SG_FLIGHT,SG_ALERT,
"YASim fatal: missing attribute, airplane needs one of {mass-lbs, mass-kg}");
1200 _airplane.addBallast(v, f);
1210void FGFDM::parseWeight(
const XMLAttributes* a)
1212 WeightRec* wr =
new WeightRec();
1216 wr->prop = std::string{a->getValue(
"mass-prop")};
1217 wr->size = attrf(a,
"size", 0);
1218 wr->handle = _airplane.addWeight(v, wr->size);
1222void FGFDM::parseStall(
const XMLAttributes* a)
1224 Wing* w = (Wing*)_currObj;
1226 sp.aoa = attrf(a,
"aoa") *
DEG2RAD;
1227 sp.width = attrf(a,
"width", 2) *
DEG2RAD;
1228 sp.peak = attrf(a,
"peak", 1.5);
1229 w->setSectionStallParams(_wingSection, sp);
1232void FGFDM::parseFlap(
const XMLAttributes* a,
const char*
name)
1235 fp.start = attrf(a,
"start");
1236 fp.end = attrf(a,
"end");
1237 if (!strcmp(
name,
"slat")) {
1238 fp.aoa = attrf(a,
"aoa");
1241 fp.lift = attrf(a,
"lift");
1243 fp.drag = attrf(a,
"drag");
1244 if (!strcmp(
name,
"flap0")) {
1245 ((Wing*)_currObj)->setFlapParams(_wingSection, WING_FLAP0, fp);
1247 if (!strcmp(
name,
"flap1")) {
1248 ((Wing*)_currObj)->setFlapParams(_wingSection, WING_FLAP1, fp);
1250 if (!strcmp(
name,
"spoiler")) {
1251 ((Wing*)_currObj)->setFlapParams(_wingSection, WING_SPOILER, fp);
1253 if (!strcmp(
name,
"slat")) {
1254 ((Wing*)_currObj)->setFlapParams(_wingSection, WING_SLAT, fp);
1258void FGFDM::parseControlSetting(
const XMLAttributes* a)
1261 float value = attrf(a,
"value", 0);
1262 _airplane.addControlSetting(_airplaneCfg, a->getValue(
"axis"), value);
1265void FGFDM::parseControlIn(
const XMLAttributes* a)
1268 ControlMap::ControlType control = ControlMap::parseControl(a->getValue(
"control"));
1270 opt |= a->hasAttribute(
"split") ? ControlMap::OPT_SPLIT : 0;
1271 opt |= a->hasAttribute(
"invert") ? ControlMap::OPT_INVERT : 0;
1272 opt |= a->hasAttribute(
"square") ? ControlMap::OPT_SQUARE : 0;
1273 float src0, src1, dst0, dst1;
1274 src0 = dst0 = ControlMap::rangeMin(control);
1275 src1 = dst1 = ControlMap::rangeMax(control);
1276 if(a->hasAttribute(
"src0")) {
1277 src0 = attrf(a,
"src0");
1278 src1 = attrf(a,
"src1");
1279 dst0 = attrf(a,
"dst0");
1280 dst1 = attrf(a,
"dst1");
1282 _airplane.addControlInput(a->getValue(
"axis"), control, _currObj, _wingSection, opt, src0, src1, dst0, dst1);
1285 std::string control_name = a->getValue(
"control");
1286 std::string in = a->getValue(
"axis");
1287 _control_to_input_properties[control_name].insert(in);
1288 for (
auto& out: _control_to_output_properties[control_name]) {
1289 _property_to_properties[in].insert(out);
1293void FGFDM::parseControlOut(
const XMLAttributes* a)
1296 ControlMap* cm = _airplane.getControlMap();
1297 ControlMap::ControlType control = ControlMap::parseControl(a->getValue(
"control"));
1298 ControlMap::ObjectID oid = ControlMap::getObjectID(_currObj, _wingSection);
1300 ControlOutput*
p =
new ControlOutput();
1301 p->prop =
fgGetNode(a->getValue(
"prop"),
true);
1302 p->handle = cm->getOutputHandle(oid, control);
1303 p->control = control;
1304 p->left = !(a->hasAttribute(
"side") &&
1305 !strcmp(
"right", a->getValue(
"side")));
1307 p->min = attrf(a,
"min", cm->rangeMin(control));
1308 p->max = attrf(a,
"max", cm->rangeMax(control));
1309 _controlOutputs.add(
p);
1312 std::string control_name = a->getValue(
"control");
1313 std::string out = a->getValue(
"prop");
1314 _control_to_output_properties[control_name].insert(out);
1315 for (
auto& in: _control_to_input_properties[control_name]) {
1316 _property_to_properties[in].insert(out);
1320void FGFDM::parseControlSpeed(
const XMLAttributes* a)
1322 ControlMap* cm = _airplane.getControlMap();
1323 ControlMap::ControlType control = ControlMap::parseControl(a->getValue(
"control"));
1324 ControlMap::ObjectID oid = ControlMap::getObjectID(_currObj, _wingSection);
1325 int handle = cm->getOutputHandle(oid, control);
1326 float time = attrf(a,
"transition-time", 0);
1327 cm->setTransitionTime(handle, time);
1330int FGFDM::attri(
const XMLAttributes* atts,
const char* attr)
1332 if(!atts->hasAttribute(attr)) {
1333 SG_LOG(SG_FLIGHT,SG_ALERT,
"Missing '" << attr <<
1334 "' in YASim aircraft description");
1337 return attri(atts, attr, 0);
1340int FGFDM::attri(
const XMLAttributes* atts,
const char* attr,
int def)
1342 const char* val = atts->getValue(attr);
1343 if(val == 0)
return def;
1344 else return atol(val);
1347float FGFDM::attrf(
const XMLAttributes* atts,
const char* attr)
1349 if(!atts->hasAttribute(attr)) {
1350 SG_LOG(SG_FLIGHT,SG_ALERT,
"Missing '" << attr <<
1351 "' in YASim aircraft description");
1354 return attrf(atts, attr, 0);
1357float FGFDM::attrf(
const XMLAttributes* atts,
const char* attr,
float def)
1359 const char* val = atts->getValue(attr);
1360 if(val == 0)
return def;
1361 else return (
float)
atof(val);
1364void FGFDM::attrf_xyz(
const XMLAttributes* atts,
float* out)
1366 out[0] = attrf(atts,
"x");
1367 out[1] = attrf(atts,
"y");
1368 out[2] = attrf(atts,
"z");
1371double FGFDM::attrd(
const XMLAttributes* atts,
const char* attr)
1373 if(!atts->hasAttribute(attr)) {
1374 SG_LOG(SG_FLIGHT,SG_ALERT,
"Missing '" << attr <<
1375 "' in YASim aircraft description");
1378 return attrd(atts, attr, 0);
1381double FGFDM::attrd(
const XMLAttributes* atts,
const char* attr,
double def)
1383 const char* val = atts->getValue(attr);
1384 if(val == 0)
return def;
1385 else return atof(val);
1399bool FGFDM::attrb(
const XMLAttributes* atts,
const char* attr)
1401 const char* val = atts->getValue(attr);
1402 if(val == 0)
return false;
1404 if(!strcmp(val,
"true")) {
1405 SG_LOG(SG_FLIGHT, SG_ALERT,
"Warning: " <<
1406 "deprecated 'true' boolean in YASim configuration file. " <<
1407 "Use numeric booleans (attribute=\"1\") instead");
1410 return attri(atts, attr, 0) ? true :
false;
static const float YASIM_PI
static const float DEG2RAD
static void moveprop(SGPropertyNode *node, const std::string &prop, float target, float frac)
static const float CIN2CM
static double atof(const string &str)
bool fgSetDouble(const char *name, double defaultValue)
Set a double value for a property.
bool fgSetBool(char const *name, bool val)
Set a bool value for a property.
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
float fgGetFloat(const char *name, float defaultValue)
Get a float value for a property.
bool fgSetFloat(const char *name, float val)
Set a float value for a property.