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)
312 ControlMap* cm = _airplane.getControlMap();
315 for(i=0; i<_axes.size(); i++) {
316 AxisRec* a = (AxisRec*)_axes.get(i);
317 float val = fgGetFloat(a->name, 0);
318 cm->setInput(a->handle, val);
320 cm->applyControls(dt);
323 for(i=0; i<_weights.size(); i++) {
324 WeightRec* wr = (WeightRec*)_weights.get(i);
325 _airplane.setWeight(wr->handle, LBS2KG * fgGetFloat(wr->prop));
329 void FGFDM::setOutputProperties()
334 float grossWgt = _airplane.getModel()->getBody()->getTotalMass() * KG2LBS;
335 fgSetFloat("/yasim/gross-weight-lbs", grossWgt);
337 ControlMap* cm = _airplane.getControlMap();
338 for(i=0; i<_controlProps.size(); i++) {
339 PropOut* p = (PropOut*)_controlProps.get(i);
341 ? cm->getOutput(p->handle)
342 : cm->getOutputR(p->handle));
343 float rmin = cm->rangeMin(p->type);
344 float rmax = cm->rangeMax(p->type);
345 float frac = (val - rmin) / (rmax - rmin);
346 val = frac*(p->max - p->min) + p->min;
347 p->prop->setFloatValue(val);
350 float totalFuel = 0, totalCap = 0;
351 float fuelDensity = 720; // in kg/m^3, default to gasoline: ~6 lb/gal
352 for(i=0; i<_airplane.numTanks(); i++) {
353 fuelDensity = _airplane.getFuelDensity(i);
354 sprintf(buf, "/consumables/fuel/tank[%d]/level-gal_us", i);
355 fgSetFloat(buf, CM2GALS*_airplane.getFuel(i)/fuelDensity);
356 sprintf(buf, "/consumables/fuel/tank[%d]/level-lbs", i);
357 fgSetFloat(buf, KG2LBS*_airplane.getFuel(i));
358 totalFuel += _airplane.getFuel(i);
359 totalCap += _airplane.getTankCapacity(i);
362 fgSetFloat("/consumables/fuel/total-fuel-lbs", KG2LBS*totalFuel);
363 fgSetFloat("/consumables/fuel/total-fuel-gals",
364 CM2GALS*totalFuel/fuelDensity);
365 fgSetFloat("/consumables/fuel/total-fuel-norm", totalFuel/totalCap);
368 for(i=0; i<_airplane.getNumRotors(); i++) {
369 Rotor*r=(Rotor*)_airplane.getRotor(i);
373 while(j=r->getValueforFGSet(j,b,&f))
381 for(j=0; j<r->numRotorparts(); j++) {
382 Rotorpart* s = (Rotorpart*)r->getRotorpart(j);
387 b=s->getAlphaoutput(k);
390 fgSetFloat(b,s->getAlpha(k));
391 //printf("setting [%s]\n",b);
395 for(j=0; j<r->numRotorblades(); j++) {
396 Rotorblade* s = (Rotorblade*)r->getRotorblade(j);
401 b=s->getAlphaoutput(k);
404 fgSetFloat(b,s->getAlpha(k));
411 for(i=0; i<_thrusters.size(); i++) {
412 EngRec* er = (EngRec*)_thrusters.get(i);
413 Thruster* t = er->eng;
415 sprintf(buf, "%s/fuel-flow-gph", er->prefix);
416 fgSetFloat(buf, (t->getFuelFlow()/fuelDensity) * 3600 * CM2GALS);
418 if(t->getPropEngine()) {
419 PropEngine* p = t->getPropEngine();
421 sprintf(buf, "%s/rpm", er->prefix);
422 fgSetFloat(buf, p->getOmega() / RPM2RAD);
425 if(t->getPistonEngine()) {
426 PistonEngine* p = t->getPistonEngine();
428 sprintf(buf, "%s/mp-osi", er->prefix);
429 fgSetFloat(buf, p->getMP() * (1/INHG2PA));
431 sprintf(buf, "%s/egt-degf", er->prefix);
432 fgSetFloat(buf, p->getEGT() * K2DEGF + K2DEGFOFFSET);
436 Jet* j = t->getJet();
438 sprintf(buf, "%s/n1", er->prefix);
439 fgSetFloat(buf, j->getN1());
441 sprintf(buf, "%s/n2", er->prefix);
442 fgSetFloat(buf, j->getN2());
444 sprintf(buf, "%s/epr", er->prefix);
445 fgSetFloat(buf, j->getEPR());
447 sprintf(buf, "%s/egt-degf", er->prefix);
448 fgSetFloat(buf, j->getEGT() * K2DEGF + K2DEGFOFFSET);
453 Wing* FGFDM::parseWing(XMLAttributes* a, const char* type)
455 Wing* w = new Wing();
458 if(eq(type, "vstab"))
464 pos[0] = attrf(a, "x");
465 pos[1] = attrf(a, "y");
466 pos[2] = attrf(a, "z");
469 w->setLength(attrf(a, "length"));
470 w->setChord(attrf(a, "chord"));
471 w->setSweep(attrf(a, "sweep", 0) * DEG2RAD);
472 w->setTaper(attrf(a, "taper", 1));
473 w->setDihedral(attrf(a, "dihedral", defDihed) * DEG2RAD);
474 w->setCamber(attrf(a, "camber", 0));
475 w->setIncidence(attrf(a, "incidence", 0) * DEG2RAD);
476 w->setTwist(attrf(a, "twist", 0) * DEG2RAD);
478 // The 70% is a magic number that sorta kinda seems to match known
479 // throttle settings to approach speed.
480 w->setInducedDrag(0.7*attrf(a, "idrag", 1));
482 float effect = attrf(a, "effectiveness", 1);
483 w->setDragScale(w->getDragScale()*effect);
488 Rotor* FGFDM::parseRotor(XMLAttributes* a, const char* type)
490 Rotor* w = new Rotor();
495 pos[0] = attrf(a, "x");
496 pos[1] = attrf(a, "y");
497 pos[2] = attrf(a, "z");
501 normal[0] = attrf(a, "nx");
502 normal[1] = attrf(a, "ny");
503 normal[2] = attrf(a, "nz");
504 w->setNormal(normal);
507 forward[0] = attrf(a, "fx");
508 forward[1] = attrf(a, "fy");
509 forward[2] = attrf(a, "fz");
510 w->setForward(forward);
514 w->setMaxCyclicail(attrf(a, "maxcyclicail", 7.6));
515 w->setMaxCyclicele(attrf(a, "maxcyclicele", 4.94));
516 w->setMinCyclicail(attrf(a, "mincyclicail", -7.6));
517 w->setMinCyclicele(attrf(a, "mincyclicele", -4.94));
518 w->setMaxCollective(attrf(a, "maxcollective", 15.8));
519 w->setMinCollective(attrf(a, "mincollective", -0.2));
520 w->setDiameter(attrf(a, "diameter", 10.2));
521 w->setWeightPerBlade(attrf(a, "weightperblade", 44));
522 w->setNumberOfBlades(attrf(a, "numblades", 4));
523 w->setRelBladeCenter(attrf(a, "relbladecenter", 0.7));
524 w->setDynamic(attrf(a, "dynamic", 0.7));
525 w->setDelta3(attrf(a, "delta3", 0));
526 w->setDelta(attrf(a, "delta", 0));
527 w->setTranslift(attrf(a, "translift", 0.05));
528 w->setC2(attrf(a, "dragfactor", 1));
529 w->setStepspersecond(attrf(a, "stepspersecond", 120));
530 w->setRPM(attrf(a, "rpm", 424));
531 w->setRelLenHinge(attrf(a, "rellenflaphinge", 0.07));
532 w->setAlpha0((attrf(a, "flap0", -5))*YASIM_PI/180);
533 w->setAlphamin((attrf(a, "flapmin", -15))/180*YASIM_PI);
534 w->setAlphamax((attrf(a, "flapmax", 15))*YASIM_PI/180);
535 w->setAlpha0factor(attrf(a, "flap0factor", 1));
536 w->setTeeterdamp(attrf(a,"teeterdamp",.0001));
537 w->setMaxteeterdamp(attrf(a,"maxteeterdamp",1000));
538 w->setRelLenTeeterHinge(attrf(a,"rellenteeterhinge",0.01));
539 void setAlphamin(float f);
540 void setAlphamax(float f);
541 void setAlpha0factor(float f);
543 if(attristrue(a,"ccw"))
546 if(a->hasAttribute("name"))
547 w->setName(a->getValue("name") );
548 if(a->hasAttribute("alphaout0"))
549 w->setAlphaoutput(0,a->getValue("alphaout0") );
550 if(a->hasAttribute("alphaout1")) w->setAlphaoutput(1,a->getValue("alphaout1") );
551 if(a->hasAttribute("alphaout2")) w->setAlphaoutput(2,a->getValue("alphaout2") );
552 if(a->hasAttribute("alphaout3")) w->setAlphaoutput(3,a->getValue("alphaout3") );
553 if(a->hasAttribute("coneout")) w->setAlphaoutput(4,a->getValue("coneout") );
554 if(a->hasAttribute("yawout")) w->setAlphaoutput(5,a->getValue("yawout") );
555 if(a->hasAttribute("rollout")) w->setAlphaoutput(6,a->getValue("rollout") );
557 w->setPitchA(attrf(a, "pitch_a", 10));
558 w->setPitchB(attrf(a, "pitch_b", 10));
559 w->setForceAtPitchA(attrf(a, "forceatpitch_a", 3000));
560 w->setPowerAtPitch0(attrf(a, "poweratpitch_0", 300));
561 w->setPowerAtPitchB(attrf(a, "poweratpitch_b", 3000));
562 if(attristrue(a,"notorque"))
564 if(attristrue(a,"simblades"))
575 void FGFDM::parsePropeller(XMLAttributes* a)
578 cg[0] = attrf(a, "x");
579 cg[1] = attrf(a, "y");
580 cg[2] = attrf(a, "z");
581 float mass = attrf(a, "mass") * LBS2KG;
582 float moment = attrf(a, "moment");
583 float radius = attrf(a, "radius");
584 float speed = attrf(a, "cruise-speed") * KTS2MPS;
585 float omega = attrf(a, "cruise-rpm") * RPM2RAD;
586 float power = attrf(a, "cruise-power") * HP2W;
587 float rho = Atmosphere::getStdDensity(attrf(a, "cruise-alt") * FT2M);
589 // Hack, fix this pronto:
590 float engP = attrf(a, "eng-power") * HP2W;
591 float engS = attrf(a, "eng-rpm") * RPM2RAD;
593 Propeller* prop = new Propeller(radius, speed, omega, rho, power);
594 PistonEngine* eng = new PistonEngine(engP, engS);
595 PropEngine* thruster = new PropEngine(prop, eng, moment);
596 _airplane.addThruster(thruster, mass, cg);
598 if(a->hasAttribute("displacement"))
599 eng->setDisplacement(attrf(a, "displacement") * CIN2CM);
601 if(a->hasAttribute("compression"))
602 eng->setCompression(attrf(a, "compression"));
604 if(a->hasAttribute("turbo-mul")) {
605 float mul = attrf(a, "turbo-mul");
606 float mp = attrf(a, "wastegate-mp", 1e6) * INHG2PA;
607 eng->setTurboParams(mul, mp);
610 if(a->hasAttribute("takeoff-power")) {
611 float power0 = attrf(a, "takeoff-power") * HP2W;
612 float omega0 = attrf(a, "takeoff-rpm") * RPM2RAD;
613 prop->setTakeoff(omega0, power0);
616 if(a->hasAttribute("max-rpm")) {
617 float max = attrf(a, "max-rpm") * RPM2RAD;
618 float min = attrf(a, "min-rpm") * RPM2RAD;
619 thruster->setVariableProp(min, max);
622 if(a->hasAttribute("manual-pitch")) {
623 prop->setManualPitch();
627 sprintf(buf, "/engines/engine[%d]", _nextEngine++);
628 EngRec* er = new EngRec();
630 er->prefix = dup(buf);
636 // Turns a string axis name into an integer for use by the
637 // ControlMap. Creates a new axis if this one hasn't been defined
639 int FGFDM::parseAxis(const char* name)
642 for(i=0; i<_axes.size(); i++) {
643 AxisRec* a = (AxisRec*)_axes.get(i);
644 if(eq(a->name, name))
648 // Not there, make a new one.
649 AxisRec* a = new AxisRec();
651 a->handle = _airplane.getControlMap()->newInput();
656 int FGFDM::parseOutput(const char* name)
658 if(eq(name, "THROTTLE")) return ControlMap::THROTTLE;
659 if(eq(name, "MIXTURE")) return ControlMap::MIXTURE;
660 if(eq(name, "STARTER")) return ControlMap::STARTER;
661 if(eq(name, "MAGNETOS")) return ControlMap::MAGNETOS;
662 if(eq(name, "ADVANCE")) return ControlMap::ADVANCE;
663 if(eq(name, "REHEAT")) return ControlMap::REHEAT;
664 if(eq(name, "BOOST")) return ControlMap::BOOST;
665 if(eq(name, "VECTOR")) return ControlMap::VECTOR;
666 if(eq(name, "PROP")) return ControlMap::PROP;
667 if(eq(name, "BRAKE")) return ControlMap::BRAKE;
668 if(eq(name, "STEER")) return ControlMap::STEER;
669 if(eq(name, "EXTEND")) return ControlMap::EXTEND;
670 if(eq(name, "INCIDENCE")) return ControlMap::INCIDENCE;
671 if(eq(name, "FLAP0")) return ControlMap::FLAP0;
672 if(eq(name, "FLAP1")) return ControlMap::FLAP1;
673 if(eq(name, "SLAT")) return ControlMap::SLAT;
674 if(eq(name, "SPOILER")) return ControlMap::SPOILER;
675 if(eq(name, "CASTERING")) return ControlMap::CASTERING;
676 if(eq(name, "PROPPITCH")) return ControlMap::PROPPITCH;
677 if(eq(name, "COLLECTIVE")) return ControlMap::COLLECTIVE;
678 if(eq(name, "CYCLICAIL")) return ControlMap::CYCLICAIL;
679 if(eq(name, "CYCLICELE")) return ControlMap::CYCLICELE;
680 if(eq(name, "ROTORENGINEON")) return ControlMap::ROTORENGINEON;
681 SG_LOG(SG_FLIGHT,SG_ALERT,"Unrecognized control type '"
682 << name << "' in YASim aircraft description.");
687 void FGFDM::parseWeight(XMLAttributes* a)
689 WeightRec* wr = new WeightRec();
692 v[0] = attrf(a, "x");
693 v[1] = attrf(a, "y");
694 v[2] = attrf(a, "z");
696 wr->prop = dup(a->getValue("mass-prop"));
697 wr->size = attrf(a, "size", 0);
698 wr->handle = _airplane.addWeight(v, wr->size);
703 bool FGFDM::eq(const char* a, const char* b)
705 // Figure it out for yourself. :)
706 while(*a && *b && *a == *b) { a++; b++; }
710 char* FGFDM::dup(const char* s)
714 char* s2 = new char[len+1];
716 while((*p++ = *s++));
721 int FGFDM::attri(XMLAttributes* atts, char* attr)
723 if(!atts->hasAttribute(attr)) {
724 SG_LOG(SG_FLIGHT,SG_ALERT,"Missing '" << attr <<
725 "' in YASim aircraft description");
728 return attri(atts, attr, 0);
731 int FGFDM::attri(XMLAttributes* atts, char* attr, int def)
733 const char* val = atts->getValue(attr);
734 if(val == 0) return def;
735 else return atol(val);
738 float FGFDM::attrf(XMLAttributes* atts, char* attr)
740 if(!atts->hasAttribute(attr)) {
741 SG_LOG(SG_FLIGHT,SG_ALERT,"Missing '" << attr <<
742 "' in YASim aircraft description");
745 return attrf(atts, attr, 0);
748 float FGFDM::attrf(XMLAttributes* atts, char* attr, float def)
750 const char* val = atts->getValue(attr);
751 if(val == 0) return def;
752 else return (float)atof(val);
755 bool FGFDM::attristrue(XMLAttributes* atts, char* attr)
757 const char* val = atts->getValue(attr);
758 if(val == 0) return false;
759 else return eq(val,"true");
762 }; // namespace yasim