4 #include <Main/fg_props.hxx>
7 #include "SimpleJet.hpp"
9 #include "Atmosphere.hpp"
10 #include "PropEngine.hpp"
11 #include "Propeller.hpp"
12 #include "PistonEngine.hpp"
14 #include "Rotorpart.hpp"
15 #include "Rotorblade.hpp"
21 // Some conversion factors
22 static const float KTS2MPS = 0.514444444444;
23 static const float FT2M = 0.3048;
24 static const float DEG2RAD = 0.0174532925199;
25 static const float RPM2RAD = 0.10471975512;
26 static const float LBS2N = 4.44822;
27 static const float LBS2KG = 0.45359237;
28 static const float KG2LBS = 2.2046225;
29 static const float CM2GALS = 264.172037284;
30 static const float HP2W = 745.700;
31 static const float INHG2PA = 3386.389;
32 static const float K2DEGF = 1.8;
33 static const float K2DEGFOFFSET = -459.4;
34 static const float CIN2CM = 1.6387064e-5;
35 static const float YASIM_PI = 3.14159265358979323846;
37 // Stubs, so that this can be compiled without the FlightGear
38 // binary. What's the best way to handle this?
40 // float fgGetFloat(char* name, float def) { return 0; }
41 // void fgSetFloat(char* name, float val) {}
47 // Map /controls/flight/elevator to the approach elevator control. This
48 // should probably be settable, but there are very few aircraft
49 // who trim their approaches using things other than elevator.
50 _airplane.setElevatorControl(parseAxis("/controls/flight/elevator-trim"));
56 for(i=0; i<_axes.size(); i++) {
57 AxisRec* a = (AxisRec*)_axes.get(i);
61 for(i=0; i<_thrusters.size(); i++) {
62 EngRec* er = (EngRec*)_thrusters.get(i);
67 for(i=0; i<_weights.size(); i++) {
68 WeightRec* wr = (WeightRec*)_weights.get(i);
72 for(i=0; i<_controlProps.size(); i++)
73 delete (PropOut*)_controlProps.get(i);
76 void FGFDM::iterate(float dt)
79 _airplane.iterate(dt);
81 if(fgGetBool("/sim/freeze/fuel") != true)
82 _airplane.consumeFuel(dt);
84 setOutputProperties();
87 Airplane* FGFDM::getAirplane()
94 // Allows the user to start with something other than full fuel
95 _airplane.setFuelFraction(fgGetFloat("/sim/fuel-fraction", 1));
97 // This has a nasty habit of being false at startup. That's not
99 fgSetBool("/controls/gear/gear-down", true);
102 // Not the worlds safest parser. But it's short & sweet.
103 void FGFDM::startElement(const char* name, const XMLAttributes &atts)
105 XMLAttributes* a = (XMLAttributes*)&atts;
109 if(eq(name, "airplane")) {
110 _airplane.setWeight(attrf(a, "mass") * LBS2KG);
111 } else if(eq(name, "approach")) {
112 float spd = attrf(a, "speed") * KTS2MPS;
113 float alt = attrf(a, "alt", 0) * FT2M;
114 float aoa = attrf(a, "aoa", 0) * DEG2RAD;
115 _airplane.setApproach(spd, alt, aoa);
117 } else if(eq(name, "cruise")) {
118 float spd = attrf(a, "speed") * KTS2MPS;
119 float alt = attrf(a, "alt") * FT2M;
120 _airplane.setCruise(spd, alt);
122 } else if(eq(name, "cockpit")) {
123 v[0] = attrf(a, "x");
124 v[1] = attrf(a, "y");
125 v[2] = attrf(a, "z");
126 _airplane.setPilotPos(v);
127 } else if(eq(name, "rotor")) {
128 _airplane.addRotor(parseRotor(a, name));
129 } else if(eq(name, "wing")) {
130 _airplane.setWing(parseWing(a, name));
131 } else if(eq(name, "hstab")) {
132 _airplane.setTail(parseWing(a, name));
133 } else if(eq(name, "vstab")) {
134 _airplane.addVStab(parseWing(a, name));
135 } else if(eq(name, "mstab")) {
136 _airplane.addVStab(parseWing(a, name));
137 } else if(eq(name, "propeller")) {
139 } else if(eq(name, "thruster")) {
140 SimpleJet* j = new SimpleJet();
142 v[0] = attrf(a, "x"); v[1] = attrf(a, "y"); v[2] = attrf(a, "z");
144 _airplane.addThruster(j, 0, v);
145 v[0] = attrf(a, "vx"); v[1] = attrf(a, "vy"); v[2] = attrf(a, "vz");
147 j->setThrust(attrf(a, "thrust") * LBS2N);
148 } else if(eq(name, "jet")) {
151 v[0] = attrf(a, "x");
152 v[1] = attrf(a, "y");
153 v[2] = attrf(a, "z");
154 float mass = attrf(a, "mass") * LBS2KG;
155 j->setMaxThrust(attrf(a, "thrust") * LBS2N,
156 attrf(a, "afterburner", 0) * LBS2N);
157 j->setVectorAngle(attrf(a, "rotate", 0) * DEG2RAD);
159 float n1min = attrf(a, "n1-idle", 55);
160 float n1max = attrf(a, "n1-max", 102);
161 float n2min = attrf(a, "n2-idle", 73);
162 float n2max = attrf(a, "n2-max", 103);
163 j->setRPMs(n1min, n1max, n2min, n2max);
165 j->setTSFC(attrf(a, "tsfc", 0.8));
166 if(a->hasAttribute("egt")) j->setEGT(attrf(a, "egt"));
167 if(a->hasAttribute("epr")) j->setEPR(attrf(a, "epr"));
168 if(a->hasAttribute("exhaust-speed"))
169 j->setVMax(attrf(a, "exhaust-speed") * KTS2MPS);
172 _airplane.addThruster(j, mass, v);
173 sprintf(buf, "/engines/engine[%d]", _nextEngine++);
174 EngRec* er = new EngRec();
176 er->prefix = dup(buf);
178 } else if(eq(name, "gear")) {
179 Gear* g = new Gear();
181 v[0] = attrf(a, "x");
182 v[1] = attrf(a, "y");
183 v[2] = attrf(a, "z");
187 v[2] = attrf(a, "compression", 1);
188 g->setCompression(v);
189 g->setBrake(attrf(a, "skid", 0));
190 g->setStaticFriction(attrf(a, "sfric", 0.8));
191 g->setDynamicFriction(attrf(a, "dfric", 0.7));
192 g->setSpring(attrf(a, "spring", 1));
193 g->setDamping(attrf(a, "damp", 1));
194 _airplane.addGear(g);
195 } else if(eq(name, "fuselage")) {
197 v[0] = attrf(a, "ax");
198 v[1] = attrf(a, "ay");
199 v[2] = attrf(a, "az");
200 b[0] = attrf(a, "bx");
201 b[1] = attrf(a, "by");
202 b[2] = attrf(a, "bz");
203 float taper = attrf(a, "taper", 1);
204 float mid = attrf(a, "midpoint", 0.5);
205 _airplane.addFuselage(v, b, attrf(a, "width"), taper, mid);
206 } else if(eq(name, "tank")) {
207 v[0] = attrf(a, "x");
208 v[1] = attrf(a, "y");
209 v[2] = attrf(a, "z");
210 float density = 6.0; // gasoline, in lbs/gal
211 if(a->hasAttribute("jet")) density = 6.72;
212 density *= LBS2KG*CM2GALS;
213 _airplane.addTank(v, attrf(a, "capacity") * LBS2KG, density);
214 } else if(eq(name, "ballast")) {
215 v[0] = attrf(a, "x");
216 v[1] = attrf(a, "y");
217 v[2] = attrf(a, "z");
218 _airplane.addBallast(v, attrf(a, "mass") * LBS2KG);
219 } else if(eq(name, "weight")) {
221 } else if(eq(name, "stall")) {
222 Wing* w = (Wing*)_currObj;
223 w->setStall(attrf(a, "aoa") * DEG2RAD);
224 w->setStallWidth(attrf(a, "width", 2) * DEG2RAD);
225 w->setStallPeak(attrf(a, "peak", 1.5));
226 } else if(eq(name, "flap0")) {
227 ((Wing*)_currObj)->setFlap0(attrf(a, "start"), attrf(a, "end"),
228 attrf(a, "lift"), attrf(a, "drag"));
229 } else if(eq(name, "flap1")) {
230 ((Wing*)_currObj)->setFlap1(attrf(a, "start"), attrf(a, "end"),
231 attrf(a, "lift"), attrf(a, "drag"));
232 } else if(eq(name, "slat")) {
233 ((Wing*)_currObj)->setSlat(attrf(a, "start"), attrf(a, "end"),
234 attrf(a, "aoa"), attrf(a, "drag"));
235 } else if(eq(name, "spoiler")) {
236 ((Wing*)_currObj)->setSpoiler(attrf(a, "start"), attrf(a, "end"),
237 attrf(a, "lift"), attrf(a, "drag"));
238 /* } else if(eq(name, "collective")) {
239 ((Rotor*)_currObj)->setcollective(attrf(a, "min"), attrf(a, "max"));
240 } else if(eq(name, "cyclic")) {
241 ((Rotor*)_currObj)->setcyclic(attrf(a, "ail"), attrf(a, "ele"));
243 } else if(eq(name, "actionpt")) {
244 v[0] = attrf(a, "x");
245 v[1] = attrf(a, "y");
246 v[2] = attrf(a, "z");
247 ((Thruster*)_currObj)->setPosition(v);
248 } else if(eq(name, "dir")) {
249 v[0] = attrf(a, "x");
250 v[1] = attrf(a, "y");
251 v[2] = attrf(a, "z");
252 ((Thruster*)_currObj)->setDirection(v);
253 } else if(eq(name, "control-setting")) {
254 // A cruise or approach control setting
255 const char* axis = a->getValue("axis");
256 float value = attrf(a, "value", 0);
258 _airplane.addCruiseControl(parseAxis(axis), value);
260 _airplane.addApproachControl(parseAxis(axis), value);
261 } else if(eq(name, "control-input")) {
263 // A mapping of input property to a control
264 int axis = parseAxis(a->getValue("axis"));
265 int control = parseOutput(a->getValue("control"));
267 opt |= a->hasAttribute("split") ? ControlMap::OPT_SPLIT : 0;
268 opt |= a->hasAttribute("invert") ? ControlMap::OPT_INVERT : 0;
269 opt |= a->hasAttribute("square") ? ControlMap::OPT_SQUARE : 0;
271 ControlMap* cm = _airplane.getControlMap();
272 if(a->hasAttribute("src0")) {
273 cm->addMapping(axis, control, _currObj, opt,
274 attrf(a, "src0"), attrf(a, "src1"),
275 attrf(a, "dst0"), attrf(a, "dst1"));
277 cm->addMapping(axis, control, _currObj, opt);
279 } else if(eq(name, "control-output")) {
280 // A property output for a control on the current object
281 ControlMap* cm = _airplane.getControlMap();
282 int type = parseOutput(a->getValue("control"));
283 int handle = cm->getOutputHandle(_currObj, type);
285 PropOut* p = new PropOut();
286 p->prop = fgGetNode(a->getValue("prop"), true);
289 p->left = !(a->hasAttribute("side") &&
290 eq("right", a->getValue("side")));
291 p->min = attrf(a, "min", cm->rangeMin(type));
292 p->max = attrf(a, "max", cm->rangeMax(type));
293 _controlProps.add(p);
295 } else if(eq(name, "control-speed")) {
296 ControlMap* cm = _airplane.getControlMap();
297 int type = parseOutput(a->getValue("control"));
298 int handle = cm->getOutputHandle(_currObj, type);
299 float time = attrf(a, "transition-time", 0);
301 cm->setTransitionTime(handle, time);
303 SG_LOG(SG_FLIGHT,SG_ALERT,"Unexpected tag '"
304 << name << "' found in YASim aircraft description");
309 void FGFDM::getExternalInput(float dt)
314 ControlMap* cm = _airplane.getControlMap();
317 for(i=0; i<_axes.size(); i++) {
318 AxisRec* a = (AxisRec*)_axes.get(i);
319 float val = fgGetFloat(a->name, 0);
320 cm->setInput(a->handle, val);
322 cm->applyControls(dt);
325 for(i=0; i<_weights.size(); i++) {
326 WeightRec* wr = (WeightRec*)_weights.get(i);
327 _airplane.setWeight(wr->handle, LBS2KG * fgGetFloat(wr->prop));
330 for(i=0; i<_thrusters.size(); i++) {
331 EngRec* er = (EngRec*)_thrusters.get(i);
332 Thruster* t = er->eng;
334 if(t->getPropEngine()) {
335 PropEngine* p = t->getPropEngine();
336 sprintf(buf, "%s/rpm", er->prefix);
337 p->setOmega(fgGetFloat(buf) * RPM2RAD);
342 void FGFDM::setOutputProperties()
347 float grossWgt = _airplane.getModel()->getBody()->getTotalMass() * KG2LBS;
348 fgSetFloat("/yasim/gross-weight-lbs", grossWgt);
350 ControlMap* cm = _airplane.getControlMap();
351 for(i=0; i<_controlProps.size(); i++) {
352 PropOut* p = (PropOut*)_controlProps.get(i);
354 ? cm->getOutput(p->handle)
355 : cm->getOutputR(p->handle));
356 float rmin = cm->rangeMin(p->type);
357 float rmax = cm->rangeMax(p->type);
358 float frac = (val - rmin) / (rmax - rmin);
359 val = frac*(p->max - p->min) + p->min;
360 p->prop->setFloatValue(val);
363 float totalFuel = 0, totalCap = 0;
364 float fuelDensity = 720; // in kg/m^3, default to gasoline: ~6 lb/gal
365 for(i=0; i<_airplane.numTanks(); i++) {
366 fuelDensity = _airplane.getFuelDensity(i);
367 sprintf(buf, "/consumables/fuel/tank[%d]/level-gal_us", i);
368 fgSetFloat(buf, CM2GALS*_airplane.getFuel(i)/fuelDensity);
369 sprintf(buf, "/consumables/fuel/tank[%d]/level-lbs", i);
370 fgSetFloat(buf, KG2LBS*_airplane.getFuel(i));
371 totalFuel += _airplane.getFuel(i);
372 totalCap += _airplane.getTankCapacity(i);
375 fgSetFloat("/consumables/fuel/total-fuel-lbs", KG2LBS*totalFuel);
376 fgSetFloat("/consumables/fuel/total-fuel-gals",
377 CM2GALS*totalFuel/fuelDensity);
378 fgSetFloat("/consumables/fuel/total-fuel-norm", totalFuel/totalCap);
381 for(i=0; i<_airplane.getNumRotors(); i++) {
382 Rotor*r=(Rotor*)_airplane.getRotor(i);
386 while(j=r->getValueforFGSet(j,b,&f))
394 for(j=0; j<r->numRotorparts(); j++) {
395 Rotorpart* s = (Rotorpart*)r->getRotorpart(j);
400 b=s->getAlphaoutput(k);
403 fgSetFloat(b,s->getAlpha(k));
404 //printf("setting [%s]\n",b);
408 for(j=0; j<r->numRotorblades(); j++) {
409 Rotorblade* s = (Rotorblade*)r->getRotorblade(j);
414 b=s->getAlphaoutput(k);
417 fgSetFloat(b,s->getAlpha(k));
424 for(i=0; i<_thrusters.size(); i++) {
425 EngRec* er = (EngRec*)_thrusters.get(i);
426 Thruster* t = er->eng;
428 sprintf(buf, "%s/fuel-flow-gph", er->prefix);
429 fgSetFloat(buf, (t->getFuelFlow()/fuelDensity) * 3600 * CM2GALS);
431 if(t->getPropEngine()) {
432 PropEngine* p = t->getPropEngine();
434 sprintf(buf, "%s/rpm", er->prefix);
435 fgSetFloat(buf, p->getOmega() / RPM2RAD);
438 if(t->getPistonEngine()) {
439 PistonEngine* p = t->getPistonEngine();
441 sprintf(buf, "%s/mp-osi", er->prefix);
442 fgSetFloat(buf, p->getMP() * (1/INHG2PA));
444 sprintf(buf, "%s/egt-degf", er->prefix);
445 fgSetFloat(buf, p->getEGT() * K2DEGF + K2DEGFOFFSET);
449 Jet* j = t->getJet();
451 sprintf(buf, "%s/n1", er->prefix);
452 fgSetFloat(buf, j->getN1());
454 sprintf(buf, "%s/n2", er->prefix);
455 fgSetFloat(buf, j->getN2());
457 sprintf(buf, "%s/epr", er->prefix);
458 fgSetFloat(buf, j->getEPR());
460 sprintf(buf, "%s/egt-degf", er->prefix);
461 fgSetFloat(buf, j->getEGT() * K2DEGF + K2DEGFOFFSET);
466 Wing* FGFDM::parseWing(XMLAttributes* a, const char* type)
468 Wing* w = new Wing();
471 if(eq(type, "vstab"))
477 pos[0] = attrf(a, "x");
478 pos[1] = attrf(a, "y");
479 pos[2] = attrf(a, "z");
482 w->setLength(attrf(a, "length"));
483 w->setChord(attrf(a, "chord"));
484 w->setSweep(attrf(a, "sweep", 0) * DEG2RAD);
485 w->setTaper(attrf(a, "taper", 1));
486 w->setDihedral(attrf(a, "dihedral", defDihed) * DEG2RAD);
487 w->setCamber(attrf(a, "camber", 0));
488 w->setIncidence(attrf(a, "incidence", 0) * DEG2RAD);
489 w->setTwist(attrf(a, "twist", 0) * DEG2RAD);
491 // The 70% is a magic number that sorta kinda seems to match known
492 // throttle settings to approach speed.
493 w->setInducedDrag(0.7*attrf(a, "idrag", 1));
495 float effect = attrf(a, "effectiveness", 1);
496 w->setDragScale(w->getDragScale()*effect);
501 Rotor* FGFDM::parseRotor(XMLAttributes* a, const char* type)
503 Rotor* w = new Rotor();
508 pos[0] = attrf(a, "x");
509 pos[1] = attrf(a, "y");
510 pos[2] = attrf(a, "z");
514 normal[0] = attrf(a, "nx");
515 normal[1] = attrf(a, "ny");
516 normal[2] = attrf(a, "nz");
517 w->setNormal(normal);
520 forward[0] = attrf(a, "fx");
521 forward[1] = attrf(a, "fy");
522 forward[2] = attrf(a, "fz");
523 w->setForward(forward);
527 w->setMaxCyclicail(attrf(a, "maxcyclicail", 7.6));
528 w->setMaxCyclicele(attrf(a, "maxcyclicele", 4.94));
529 w->setMinCyclicail(attrf(a, "mincyclicail", -7.6));
530 w->setMinCyclicele(attrf(a, "mincyclicele", -4.94));
531 w->setMaxCollective(attrf(a, "maxcollective", 15.8));
532 w->setMinCollective(attrf(a, "mincollective", -0.2));
533 w->setDiameter(attrf(a, "diameter", 10.2));
534 w->setWeightPerBlade(attrf(a, "weightperblade", 44));
535 w->setNumberOfBlades(attrf(a, "numblades", 4));
536 w->setRelBladeCenter(attrf(a, "relbladecenter", 0.7));
537 w->setDynamic(attrf(a, "dynamic", 0.7));
538 w->setDelta3(attrf(a, "delta3", 0));
539 w->setDelta(attrf(a, "delta", 0));
540 w->setTranslift(attrf(a, "translift", 0.05));
541 w->setC2(attrf(a, "dragfactor", 1));
542 w->setStepspersecond(attrf(a, "stepspersecond", 120));
543 w->setRPM(attrf(a, "rpm", 424));
544 w->setRelLenHinge(attrf(a, "rellenflaphinge", 0.07));
545 w->setAlpha0((attrf(a, "flap0", -5))*YASIM_PI/180);
546 w->setAlphamin((attrf(a, "flapmin", -15))/180*YASIM_PI);
547 w->setAlphamax((attrf(a, "flapmax", 15))*YASIM_PI/180);
548 w->setAlpha0factor(attrf(a, "flap0factor", 1));
549 w->setTeeterdamp(attrf(a,"teeterdamp",.0001));
550 w->setMaxteeterdamp(attrf(a,"maxteeterdamp",1000));
551 w->setRelLenTeeterHinge(attrf(a,"rellenteeterhinge",0.01));
552 void setAlphamin(float f);
553 void setAlphamax(float f);
554 void setAlpha0factor(float f);
556 if(attristrue(a,"ccw"))
559 if(a->hasAttribute("name"))
560 w->setName(a->getValue("name") );
561 if(a->hasAttribute("alphaout0"))
562 w->setAlphaoutput(0,a->getValue("alphaout0") );
563 if(a->hasAttribute("alphaout1")) w->setAlphaoutput(1,a->getValue("alphaout1") );
564 if(a->hasAttribute("alphaout2")) w->setAlphaoutput(2,a->getValue("alphaout2") );
565 if(a->hasAttribute("alphaout3")) w->setAlphaoutput(3,a->getValue("alphaout3") );
566 if(a->hasAttribute("coneout")) w->setAlphaoutput(4,a->getValue("coneout") );
567 if(a->hasAttribute("yawout")) w->setAlphaoutput(5,a->getValue("yawout") );
568 if(a->hasAttribute("rollout")) w->setAlphaoutput(6,a->getValue("rollout") );
570 w->setPitchA(attrf(a, "pitch_a", 10));
571 w->setPitchB(attrf(a, "pitch_b", 10));
572 w->setForceAtPitchA(attrf(a, "forceatpitch_a", 3000));
573 w->setPowerAtPitch0(attrf(a, "poweratpitch_0", 300));
574 w->setPowerAtPitchB(attrf(a, "poweratpitch_b", 3000));
575 if(attristrue(a,"notorque"))
577 if(attristrue(a,"simblades"))
588 void FGFDM::parsePropeller(XMLAttributes* a)
591 cg[0] = attrf(a, "x");
592 cg[1] = attrf(a, "y");
593 cg[2] = attrf(a, "z");
594 float mass = attrf(a, "mass") * LBS2KG;
595 float moment = attrf(a, "moment");
596 float radius = attrf(a, "radius");
597 float speed = attrf(a, "cruise-speed") * KTS2MPS;
598 float omega = attrf(a, "cruise-rpm") * RPM2RAD;
599 float power = attrf(a, "cruise-power") * HP2W;
600 float rho = Atmosphere::getStdDensity(attrf(a, "cruise-alt") * FT2M);
602 // Hack, fix this pronto:
603 float engP = attrf(a, "eng-power") * HP2W;
604 float engS = attrf(a, "eng-rpm") * RPM2RAD;
606 Propeller* prop = new Propeller(radius, speed, omega, rho, power);
607 PistonEngine* eng = new PistonEngine(engP, engS);
608 PropEngine* thruster = new PropEngine(prop, eng, moment);
609 _airplane.addThruster(thruster, mass, cg);
611 if(a->hasAttribute("displacement"))
612 eng->setDisplacement(attrf(a, "displacement") * CIN2CM);
614 if(a->hasAttribute("compression"))
615 eng->setCompression(attrf(a, "compression"));
617 if(a->hasAttribute("turbo-mul")) {
618 float mul = attrf(a, "turbo-mul");
619 float mp = attrf(a, "wastegate-mp", 1e6) * INHG2PA;
620 eng->setTurboParams(mul, mp);
623 if(a->hasAttribute("takeoff-power")) {
624 float power0 = attrf(a, "takeoff-power") * HP2W;
625 float omega0 = attrf(a, "takeoff-rpm") * RPM2RAD;
626 prop->setTakeoff(omega0, power0);
629 if(a->hasAttribute("max-rpm")) {
630 float max = attrf(a, "max-rpm") * RPM2RAD;
631 float min = attrf(a, "min-rpm") * RPM2RAD;
632 thruster->setVariableProp(min, max);
635 if(a->hasAttribute("manual-pitch")) {
636 prop->setManualPitch();
640 sprintf(buf, "/engines/engine[%d]", _nextEngine++);
641 EngRec* er = new EngRec();
643 er->prefix = dup(buf);
649 // Turns a string axis name into an integer for use by the
650 // ControlMap. Creates a new axis if this one hasn't been defined
652 int FGFDM::parseAxis(const char* name)
655 for(i=0; i<_axes.size(); i++) {
656 AxisRec* a = (AxisRec*)_axes.get(i);
657 if(eq(a->name, name))
661 // Not there, make a new one.
662 AxisRec* a = new AxisRec();
664 a->handle = _airplane.getControlMap()->newInput();
669 int FGFDM::parseOutput(const char* name)
671 if(eq(name, "THROTTLE")) return ControlMap::THROTTLE;
672 if(eq(name, "MIXTURE")) return ControlMap::MIXTURE;
673 if(eq(name, "STARTER")) return ControlMap::STARTER;
674 if(eq(name, "MAGNETOS")) return ControlMap::MAGNETOS;
675 if(eq(name, "ADVANCE")) return ControlMap::ADVANCE;
676 if(eq(name, "REHEAT")) return ControlMap::REHEAT;
677 if(eq(name, "BOOST")) return ControlMap::BOOST;
678 if(eq(name, "VECTOR")) return ControlMap::VECTOR;
679 if(eq(name, "PROP")) return ControlMap::PROP;
680 if(eq(name, "BRAKE")) return ControlMap::BRAKE;
681 if(eq(name, "STEER")) return ControlMap::STEER;
682 if(eq(name, "EXTEND")) return ControlMap::EXTEND;
683 if(eq(name, "INCIDENCE")) return ControlMap::INCIDENCE;
684 if(eq(name, "FLAP0")) return ControlMap::FLAP0;
685 if(eq(name, "FLAP1")) return ControlMap::FLAP1;
686 if(eq(name, "SLAT")) return ControlMap::SLAT;
687 if(eq(name, "SPOILER")) return ControlMap::SPOILER;
688 if(eq(name, "CASTERING")) return ControlMap::CASTERING;
689 if(eq(name, "PROPPITCH")) return ControlMap::PROPPITCH;
690 if(eq(name, "COLLECTIVE")) return ControlMap::COLLECTIVE;
691 if(eq(name, "CYCLICAIL")) return ControlMap::CYCLICAIL;
692 if(eq(name, "CYCLICELE")) return ControlMap::CYCLICELE;
693 if(eq(name, "ROTORENGINEON")) return ControlMap::ROTORENGINEON;
694 SG_LOG(SG_FLIGHT,SG_ALERT,"Unrecognized control type '"
695 << name << "' in YASim aircraft description.");
700 void FGFDM::parseWeight(XMLAttributes* a)
702 WeightRec* wr = new WeightRec();
705 v[0] = attrf(a, "x");
706 v[1] = attrf(a, "y");
707 v[2] = attrf(a, "z");
709 wr->prop = dup(a->getValue("mass-prop"));
710 wr->size = attrf(a, "size", 0);
711 wr->handle = _airplane.addWeight(v, wr->size);
716 bool FGFDM::eq(const char* a, const char* b)
718 // Figure it out for yourself. :)
719 while(*a && *b && *a == *b) { a++; b++; }
723 char* FGFDM::dup(const char* s)
727 char* s2 = new char[len+1];
729 while((*p++ = *s++));
734 int FGFDM::attri(XMLAttributes* atts, char* attr)
736 if(!atts->hasAttribute(attr)) {
737 SG_LOG(SG_FLIGHT,SG_ALERT,"Missing '" << attr <<
738 "' in YASim aircraft description");
741 return attri(atts, attr, 0);
744 int FGFDM::attri(XMLAttributes* atts, char* attr, int def)
746 const char* val = atts->getValue(attr);
747 if(val == 0) return def;
748 else return atol(val);
751 float FGFDM::attrf(XMLAttributes* atts, char* attr)
753 if(!atts->hasAttribute(attr)) {
754 SG_LOG(SG_FLIGHT,SG_ALERT,"Missing '" << attr <<
755 "' in YASim aircraft description");
758 return attrf(atts, attr, 0);
761 float FGFDM::attrf(XMLAttributes* atts, char* attr, float def)
763 const char* val = atts->getValue(attr);
764 if(val == 0) return def;
765 else return (float)atof(val);
768 bool FGFDM::attristrue(XMLAttributes* atts, char* attr)
770 const char* val = atts->getValue(attr);
771 if(val == 0) return false;
772 else return eq(val,"true");
775 }; // namespace yasim