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"));
52 // FIXME: read seed from somewhere?
54 _turb = new Turbulence(10, seed);
60 for(i=0; i<_axes.size(); i++) {
61 AxisRec* a = (AxisRec*)_axes.get(i);
65 for(i=0; i<_thrusters.size(); i++) {
66 EngRec* er = (EngRec*)_thrusters.get(i);
71 for(i=0; i<_weights.size(); i++) {
72 WeightRec* wr = (WeightRec*)_weights.get(i);
76 for(i=0; i<_controlProps.size(); i++)
77 delete (PropOut*)_controlProps.get(i);
80 void FGFDM::iterate(float dt)
83 _airplane.iterate(dt);
85 // Do fuel stuff (FIXME: should stash SGPropertyNode objects here)
87 for(int i=0; i<_airplane.numThrusters(); i++) {
88 Thruster* t = _airplane.getThruster(i);
90 sprintf(buf, "/engines/engine[%d]/out-of-fuel", i);
91 t->setFuelState(!fgGetBool(buf));
93 sprintf(buf, "/engines/engine[%d]/fuel-consumed-lbs", i);
94 double consumed = fgGetDouble(buf) + dt * t->getFuelFlow();
95 fgSetDouble(buf, consumed);
97 for(int i=0; i<_airplane.numTanks(); i++) {
98 sprintf(buf, "/consumables/fuel/tank[%d]/level-lbs", i);
99 _airplane.setFuel(i, LBS2KG * fgGetFloat(buf));
101 _airplane.calcFuelWeights();
103 setOutputProperties();
106 Airplane* FGFDM::getAirplane()
113 // Allows the user to start with something other than full fuel
114 _airplane.setFuelFraction(fgGetFloat("/sim/fuel-fraction", 1));
116 // Read out the resulting fuel state
118 for(int i=0; i<_airplane.numTanks(); i++) {
119 sprintf(buf, "/consumables/fuel/tank[%d]/level-lbs", i);
120 fgSetDouble(buf, _airplane.getFuel(i) * KG2LBS);
122 double density = _airplane.getFuelDensity(i);
123 sprintf(buf, "/consumables/fuel/tank[%d]/density-ppg", i);
124 fgSetDouble(buf, density * (KG2LBS/CM2GALS));
126 sprintf(buf, "/consumables/fuel/tank[%d]/level-gal_us", i);
127 fgSetDouble(buf, _airplane.getFuel(i) * CM2GALS / density);
129 sprintf(buf, "/consumables/fuel/tank[%d]/capacity-gal_us", i);
130 fgSetDouble(buf, CM2GALS * _airplane.getTankCapacity(i)/density);
133 // This has a nasty habit of being false at startup. That's not
135 fgSetBool("/controls/gear/gear-down", true);
137 _airplane.getModel()->setTurbulence(_turb);
140 // Not the worlds safest parser. But it's short & sweet.
141 void FGFDM::startElement(const char* name, const XMLAttributes &atts)
143 XMLAttributes* a = (XMLAttributes*)&atts;
147 if(eq(name, "airplane")) {
148 _airplane.setWeight(attrf(a, "mass") * LBS2KG);
149 } else if(eq(name, "approach")) {
150 float spd = attrf(a, "speed") * KTS2MPS;
151 float alt = attrf(a, "alt", 0) * FT2M;
152 float aoa = attrf(a, "aoa", 0) * DEG2RAD;
153 _airplane.setApproach(spd, alt, aoa, attrf(a, "fuel", 0.2));
155 } else if(eq(name, "cruise")) {
156 float spd = attrf(a, "speed") * KTS2MPS;
157 float alt = attrf(a, "alt") * FT2M;
158 _airplane.setCruise(spd, alt, attrf(a, "fuel", 0.5));
160 } else if(eq(name, "solve-weight")) {
161 int idx = attri(a, "idx");
162 float wgt = attrf(a, "weight") * LBS2KG;
163 _airplane.addSolutionWeight(!_cruiseCurr, idx, wgt);
164 } else if(eq(name, "cockpit")) {
165 v[0] = attrf(a, "x");
166 v[1] = attrf(a, "y");
167 v[2] = attrf(a, "z");
168 _airplane.setPilotPos(v);
169 } else if(eq(name, "rotor")) {
170 _airplane.addRotor(parseRotor(a, name));
171 } else if(eq(name, "wing")) {
172 _airplane.setWing(parseWing(a, name));
173 } else if(eq(name, "hstab")) {
174 _airplane.setTail(parseWing(a, name));
175 } else if(eq(name, "vstab") || eq(name, "mstab")) {
176 _airplane.addVStab(parseWing(a, name));
177 } else if(eq(name, "propeller")) {
179 } else if(eq(name, "thruster")) {
180 SimpleJet* j = new SimpleJet();
182 v[0] = attrf(a, "x"); v[1] = attrf(a, "y"); v[2] = attrf(a, "z");
184 _airplane.addThruster(j, 0, v);
185 v[0] = attrf(a, "vx"); v[1] = attrf(a, "vy"); v[2] = attrf(a, "vz");
187 j->setThrust(attrf(a, "thrust") * LBS2N);
188 } else if(eq(name, "jet")) {
191 v[0] = attrf(a, "x");
192 v[1] = attrf(a, "y");
193 v[2] = attrf(a, "z");
194 float mass = attrf(a, "mass") * LBS2KG;
195 j->setMaxThrust(attrf(a, "thrust") * LBS2N,
196 attrf(a, "afterburner", 0) * LBS2N);
197 j->setVectorAngle(attrf(a, "rotate", 0) * DEG2RAD);
198 j->setReverseThrust(attrf(a, "reverse", 0.2));
200 float n1min = attrf(a, "n1-idle", 55);
201 float n1max = attrf(a, "n1-max", 102);
202 float n2min = attrf(a, "n2-idle", 73);
203 float n2max = attrf(a, "n2-max", 103);
204 j->setRPMs(n1min, n1max, n2min, n2max);
206 j->setTSFC(attrf(a, "tsfc", 0.8));
207 if(a->hasAttribute("egt")) j->setEGT(attrf(a, "egt"));
208 if(a->hasAttribute("epr")) j->setEPR(attrf(a, "epr"));
209 if(a->hasAttribute("exhaust-speed"))
210 j->setVMax(attrf(a, "exhaust-speed") * KTS2MPS);
213 _airplane.addThruster(j, mass, v);
214 sprintf(buf, "/engines/engine[%d]", _nextEngine++);
215 EngRec* er = new EngRec();
217 er->prefix = dup(buf);
219 } else if(eq(name, "gear")) {
220 Gear* g = new Gear();
222 v[0] = attrf(a, "x");
223 v[1] = attrf(a, "y");
224 v[2] = attrf(a, "z");
228 v[2] = attrf(a, "compression", 1);
229 g->setCompression(v);
230 g->setBrake(attrf(a, "skid", 0));
231 g->setStaticFriction(attrf(a, "sfric", 0.8));
232 g->setDynamicFriction(attrf(a, "dfric", 0.7));
233 g->setSpring(attrf(a, "spring", 1));
234 g->setDamping(attrf(a, "damp", 1));
235 _airplane.addGear(g);
236 } else if(eq(name, "fuselage")) {
238 v[0] = attrf(a, "ax");
239 v[1] = attrf(a, "ay");
240 v[2] = attrf(a, "az");
241 b[0] = attrf(a, "bx");
242 b[1] = attrf(a, "by");
243 b[2] = attrf(a, "bz");
244 float taper = attrf(a, "taper", 1);
245 float mid = attrf(a, "midpoint", 0.5);
246 _airplane.addFuselage(v, b, attrf(a, "width"), taper, mid);
247 } else if(eq(name, "tank")) {
248 v[0] = attrf(a, "x");
249 v[1] = attrf(a, "y");
250 v[2] = attrf(a, "z");
251 float density = 6.0; // gasoline, in lbs/gal
252 if(a->hasAttribute("jet")) density = 6.72;
253 density *= LBS2KG*CM2GALS;
254 _airplane.addTank(v, attrf(a, "capacity") * LBS2KG, density);
255 } else if(eq(name, "ballast")) {
256 v[0] = attrf(a, "x");
257 v[1] = attrf(a, "y");
258 v[2] = attrf(a, "z");
259 _airplane.addBallast(v, attrf(a, "mass") * LBS2KG);
260 } else if(eq(name, "weight")) {
262 } else if(eq(name, "stall")) {
263 Wing* w = (Wing*)_currObj;
264 w->setStall(attrf(a, "aoa") * DEG2RAD);
265 w->setStallWidth(attrf(a, "width", 2) * DEG2RAD);
266 w->setStallPeak(attrf(a, "peak", 1.5));
267 } else if(eq(name, "flap0")) {
268 ((Wing*)_currObj)->setFlap0(attrf(a, "start"), attrf(a, "end"),
269 attrf(a, "lift"), attrf(a, "drag"));
270 } else if(eq(name, "flap1")) {
271 ((Wing*)_currObj)->setFlap1(attrf(a, "start"), attrf(a, "end"),
272 attrf(a, "lift"), attrf(a, "drag"));
273 } else if(eq(name, "slat")) {
274 ((Wing*)_currObj)->setSlat(attrf(a, "start"), attrf(a, "end"),
275 attrf(a, "aoa"), attrf(a, "drag"));
276 } else if(eq(name, "spoiler")) {
277 ((Wing*)_currObj)->setSpoiler(attrf(a, "start"), attrf(a, "end"),
278 attrf(a, "lift"), attrf(a, "drag"));
279 /* } else if(eq(name, "collective")) {
280 ((Rotor*)_currObj)->setcollective(attrf(a, "min"), attrf(a, "max"));
281 } else if(eq(name, "cyclic")) {
282 ((Rotor*)_currObj)->setcyclic(attrf(a, "ail"), attrf(a, "ele"));
284 } else if(eq(name, "actionpt")) {
285 v[0] = attrf(a, "x");
286 v[1] = attrf(a, "y");
287 v[2] = attrf(a, "z");
288 ((Thruster*)_currObj)->setPosition(v);
289 } else if(eq(name, "dir")) {
290 v[0] = attrf(a, "x");
291 v[1] = attrf(a, "y");
292 v[2] = attrf(a, "z");
293 ((Thruster*)_currObj)->setDirection(v);
294 } else if(eq(name, "control-setting")) {
295 // A cruise or approach control setting
296 const char* axis = a->getValue("axis");
297 float value = attrf(a, "value", 0);
299 _airplane.addCruiseControl(parseAxis(axis), value);
301 _airplane.addApproachControl(parseAxis(axis), value);
302 } else if(eq(name, "control-input")) {
304 // A mapping of input property to a control
305 int axis = parseAxis(a->getValue("axis"));
306 int control = parseOutput(a->getValue("control"));
308 opt |= a->hasAttribute("split") ? ControlMap::OPT_SPLIT : 0;
309 opt |= a->hasAttribute("invert") ? ControlMap::OPT_INVERT : 0;
310 opt |= a->hasAttribute("square") ? ControlMap::OPT_SQUARE : 0;
312 ControlMap* cm = _airplane.getControlMap();
313 if(a->hasAttribute("src0")) {
314 cm->addMapping(axis, control, _currObj, opt,
315 attrf(a, "src0"), attrf(a, "src1"),
316 attrf(a, "dst0"), attrf(a, "dst1"));
318 cm->addMapping(axis, control, _currObj, opt);
320 } else if(eq(name, "control-output")) {
321 // A property output for a control on the current object
322 ControlMap* cm = _airplane.getControlMap();
323 int type = parseOutput(a->getValue("control"));
324 int handle = cm->getOutputHandle(_currObj, type);
326 PropOut* p = new PropOut();
327 p->prop = fgGetNode(a->getValue("prop"), true);
330 p->left = !(a->hasAttribute("side") &&
331 eq("right", a->getValue("side")));
332 p->min = attrf(a, "min", cm->rangeMin(type));
333 p->max = attrf(a, "max", cm->rangeMax(type));
334 _controlProps.add(p);
336 } else if(eq(name, "control-speed")) {
337 ControlMap* cm = _airplane.getControlMap();
338 int type = parseOutput(a->getValue("control"));
339 int handle = cm->getOutputHandle(_currObj, type);
340 float time = attrf(a, "transition-time", 0);
342 cm->setTransitionTime(handle, time);
344 SG_LOG(SG_FLIGHT,SG_ALERT,"Unexpected tag '"
345 << name << "' found in YASim aircraft description");
350 void FGFDM::getExternalInput(float dt)
354 _turb->setMagnitude(fgGetFloat("/environment/turbulence/magnitude-norm"));
355 _turb->update(dt, fgGetFloat("/environment/turbulence/rate-hz"));
358 ControlMap* cm = _airplane.getControlMap();
361 for(i=0; i<_axes.size(); i++) {
362 AxisRec* a = (AxisRec*)_axes.get(i);
363 float val = fgGetFloat(a->name, 0);
364 cm->setInput(a->handle, val);
366 cm->applyControls(dt);
369 for(i=0; i<_weights.size(); i++) {
370 WeightRec* wr = (WeightRec*)_weights.get(i);
371 _airplane.setWeight(wr->handle, LBS2KG * fgGetFloat(wr->prop));
374 for(i=0; i<_thrusters.size(); i++) {
375 EngRec* er = (EngRec*)_thrusters.get(i);
376 Thruster* t = er->eng;
378 if(t->getPropEngine()) {
379 PropEngine* p = t->getPropEngine();
380 sprintf(buf, "%s/rpm", er->prefix);
381 p->setOmega(fgGetFloat(buf, 500) * RPM2RAD);
386 void FGFDM::setOutputProperties()
391 float grossWgt = _airplane.getModel()->getBody()->getTotalMass() * KG2LBS;
392 fgSetFloat("/yasim/gross-weight-lbs", grossWgt);
394 ControlMap* cm = _airplane.getControlMap();
395 for(i=0; i<_controlProps.size(); i++) {
396 PropOut* p = (PropOut*)_controlProps.get(i);
398 ? cm->getOutput(p->handle)
399 : cm->getOutputR(p->handle));
400 float rmin = cm->rangeMin(p->type);
401 float rmax = cm->rangeMax(p->type);
402 float frac = (val - rmin) / (rmax - rmin);
403 val = frac*(p->max - p->min) + p->min;
404 p->prop->setFloatValue(val);
407 for(i=0; i<_airplane.getNumRotors(); i++) {
408 Rotor*r=(Rotor*)_airplane.getRotor(i);
412 while(j = r->getValueforFGSet(j, b, &f))
413 if(b[0]) fgSetFloat(b,f);
415 for(j=0; j < r->numRotorparts(); j++) {
416 Rotorpart* s = (Rotorpart*)r->getRotorpart(j);
420 b=s->getAlphaoutput(k);
421 if(b[0]) fgSetFloat(b, s->getAlpha(k));
424 for(j=0; j < r->numRotorblades(); j++) {
425 Rotorblade* s = (Rotorblade*)r->getRotorblade(j);
428 for (k=0; k<2; k++) {
429 b = s->getAlphaoutput(k);
430 if(b[0]) fgSetFloat(b, s->getAlpha(k));
435 float fuelDensity = _airplane.getFuelDensity(0); // HACK
436 for(i=0; i<_thrusters.size(); i++) {
437 EngRec* er = (EngRec*)_thrusters.get(i);
438 Thruster* t = er->eng;
440 sprintf(buf, "%s/fuel-flow-gph", er->prefix);
441 fgSetFloat(buf, (t->getFuelFlow()/fuelDensity) * 3600 * CM2GALS);
443 if(t->getPropEngine()) {
444 PropEngine* p = t->getPropEngine();
446 sprintf(buf, "%s/rpm", er->prefix);
447 fgSetFloat(buf, p->getOmega() / RPM2RAD);
450 if(t->getPistonEngine()) {
451 PistonEngine* p = t->getPistonEngine();
453 sprintf(buf, "%s/mp-osi", er->prefix);
454 fgSetFloat(buf, p->getMP() * (1/INHG2PA));
456 sprintf(buf, "%s/egt-degf", er->prefix);
457 fgSetFloat(buf, p->getEGT() * K2DEGF + K2DEGFOFFSET);
461 Jet* j = t->getJet();
463 sprintf(buf, "%s/n1", er->prefix);
464 fgSetFloat(buf, j->getN1());
466 sprintf(buf, "%s/n2", er->prefix);
467 fgSetFloat(buf, j->getN2());
469 sprintf(buf, "%s/epr", er->prefix);
470 fgSetFloat(buf, j->getEPR());
472 sprintf(buf, "%s/egt-degf", er->prefix);
473 fgSetFloat(buf, j->getEGT() * K2DEGF + K2DEGFOFFSET);
478 Wing* FGFDM::parseWing(XMLAttributes* a, const char* type)
480 Wing* w = new Wing();
483 if(eq(type, "vstab"))
489 pos[0] = attrf(a, "x");
490 pos[1] = attrf(a, "y");
491 pos[2] = attrf(a, "z");
494 w->setLength(attrf(a, "length"));
495 w->setChord(attrf(a, "chord"));
496 w->setSweep(attrf(a, "sweep", 0) * DEG2RAD);
497 w->setTaper(attrf(a, "taper", 1));
498 w->setDihedral(attrf(a, "dihedral", defDihed) * DEG2RAD);
499 w->setCamber(attrf(a, "camber", 0));
500 w->setIncidence(attrf(a, "incidence", 0) * DEG2RAD);
501 w->setTwist(attrf(a, "twist", 0) * DEG2RAD);
503 // The 70% is a magic number that sorta kinda seems to match known
504 // throttle settings to approach speed.
505 w->setInducedDrag(0.7*attrf(a, "idrag", 1));
507 float effect = attrf(a, "effectiveness", 1);
508 w->setDragScale(w->getDragScale()*effect);
514 Rotor* FGFDM::parseRotor(XMLAttributes* a, const char* type)
516 Rotor* w = new Rotor();
521 pos[0] = attrf(a, "x");
522 pos[1] = attrf(a, "y");
523 pos[2] = attrf(a, "z");
527 normal[0] = attrf(a, "nx");
528 normal[1] = attrf(a, "ny");
529 normal[2] = attrf(a, "nz");
530 w->setNormal(normal);
533 forward[0] = attrf(a, "fx");
534 forward[1] = attrf(a, "fy");
535 forward[2] = attrf(a, "fz");
536 w->setForward(forward);
538 w->setMaxCyclicail(attrf(a, "maxcyclicail", 7.6));
539 w->setMaxCyclicele(attrf(a, "maxcyclicele", 4.94));
540 w->setMinCyclicail(attrf(a, "mincyclicail", -7.6));
541 w->setMinCyclicele(attrf(a, "mincyclicele", -4.94));
542 w->setMaxCollective(attrf(a, "maxcollective", 15.8));
543 w->setMinCollective(attrf(a, "mincollective", -0.2));
544 w->setDiameter(attrf(a, "diameter", 10.2));
545 w->setWeightPerBlade(attrf(a, "weightperblade", 44));
546 w->setNumberOfBlades(attrf(a, "numblades", 4));
547 w->setRelBladeCenter(attrf(a, "relbladecenter", 0.7));
548 w->setDynamic(attrf(a, "dynamic", 0.7));
549 w->setDelta3(attrf(a, "delta3", 0));
550 w->setDelta(attrf(a, "delta", 0));
551 w->setTranslift(attrf(a, "translift", 0.05));
552 w->setC2(attrf(a, "dragfactor", 1));
553 w->setStepspersecond(attrf(a, "stepspersecond", 120));
554 w->setRPM(attrf(a, "rpm", 424));
555 w->setRelLenHinge(attrf(a, "rellenflaphinge", 0.07));
556 w->setAlpha0((attrf(a, "flap0", -5))*YASIM_PI/180);
557 w->setAlphamin((attrf(a, "flapmin", -15))/180*YASIM_PI);
558 w->setAlphamax((attrf(a, "flapmax", 15))*YASIM_PI/180);
559 w->setAlpha0factor(attrf(a, "flap0factor", 1));
560 w->setTeeterdamp(attrf(a,"teeterdamp",.0001));
561 w->setMaxteeterdamp(attrf(a,"maxteeterdamp",1000));
562 w->setRelLenTeeterHinge(attrf(a,"rellenteeterhinge",0.01));
563 void setAlphamin(float f);
564 void setAlphamax(float f);
565 void setAlpha0factor(float f);
570 if(a->hasAttribute("name"))
571 w->setName(a->getValue("name") );
572 if(a->hasAttribute("alphaout0"))
573 w->setAlphaoutput(0,a->getValue("alphaout0") );
574 if(a->hasAttribute("alphaout1")) w->setAlphaoutput(1,a->getValue("alphaout1") );
575 if(a->hasAttribute("alphaout2")) w->setAlphaoutput(2,a->getValue("alphaout2") );
576 if(a->hasAttribute("alphaout3")) w->setAlphaoutput(3,a->getValue("alphaout3") );
577 if(a->hasAttribute("coneout")) w->setAlphaoutput(4,a->getValue("coneout") );
578 if(a->hasAttribute("yawout")) w->setAlphaoutput(5,a->getValue("yawout") );
579 if(a->hasAttribute("rollout")) w->setAlphaoutput(6,a->getValue("rollout") );
581 w->setPitchA(attrf(a, "pitch_a", 10));
582 w->setPitchB(attrf(a, "pitch_b", 10));
583 w->setForceAtPitchA(attrf(a, "forceatpitch_a", 3000));
584 w->setPowerAtPitch0(attrf(a, "poweratpitch_0", 300));
585 w->setPowerAtPitchB(attrf(a, "poweratpitch_b", 3000));
586 if(attrb(a,"notorque"))
588 if(attrb(a,"simblades"))
595 void FGFDM::parsePropeller(XMLAttributes* a)
598 cg[0] = attrf(a, "x");
599 cg[1] = attrf(a, "y");
600 cg[2] = attrf(a, "z");
601 float mass = attrf(a, "mass") * LBS2KG;
602 float moment = attrf(a, "moment");
603 float radius = attrf(a, "radius");
604 float speed = attrf(a, "cruise-speed") * KTS2MPS;
605 float omega = attrf(a, "cruise-rpm") * RPM2RAD;
606 float power = attrf(a, "cruise-power") * HP2W;
607 float rho = Atmosphere::getStdDensity(attrf(a, "cruise-alt") * FT2M);
609 // Hack, fix this pronto:
610 float engP = attrf(a, "eng-power") * HP2W;
611 float engS = attrf(a, "eng-rpm") * RPM2RAD;
613 Propeller* prop = new Propeller(radius, speed, omega, rho, power);
614 PistonEngine* eng = new PistonEngine(engP, engS);
615 PropEngine* thruster = new PropEngine(prop, eng, moment);
616 _airplane.addThruster(thruster, mass, cg);
618 if(a->hasAttribute("displacement"))
619 eng->setDisplacement(attrf(a, "displacement") * CIN2CM);
621 if(a->hasAttribute("compression"))
622 eng->setCompression(attrf(a, "compression"));
624 if(a->hasAttribute("turbo-mul")) {
625 float mul = attrf(a, "turbo-mul");
626 float mp = attrf(a, "wastegate-mp", 1e6) * INHG2PA;
627 eng->setTurboParams(mul, mp);
630 if(a->hasAttribute("takeoff-power")) {
631 float power0 = attrf(a, "takeoff-power") * HP2W;
632 float omega0 = attrf(a, "takeoff-rpm") * RPM2RAD;
633 prop->setTakeoff(omega0, power0);
636 if(a->hasAttribute("max-rpm")) {
637 float max = attrf(a, "max-rpm") * RPM2RAD;
638 float min = attrf(a, "min-rpm") * RPM2RAD;
639 thruster->setVariableProp(min, max);
642 if(a->hasAttribute("manual-pitch")) {
643 prop->setManualPitch();
646 thruster->setGearRatio(attrf(a, "gear-ratio", 1));
649 sprintf(buf, "/engines/engine[%d]", _nextEngine++);
650 EngRec* er = new EngRec();
652 er->prefix = dup(buf);
658 // Turns a string axis name into an integer for use by the
659 // ControlMap. Creates a new axis if this one hasn't been defined
661 int FGFDM::parseAxis(const char* name)
664 for(i=0; i<_axes.size(); i++) {
665 AxisRec* a = (AxisRec*)_axes.get(i);
666 if(eq(a->name, name))
670 // Not there, make a new one.
671 AxisRec* a = new AxisRec();
673 a->handle = _airplane.getControlMap()->newInput();
678 int FGFDM::parseOutput(const char* name)
680 if(eq(name, "THROTTLE")) return ControlMap::THROTTLE;
681 if(eq(name, "MIXTURE")) return ControlMap::MIXTURE;
682 if(eq(name, "STARTER")) return ControlMap::STARTER;
683 if(eq(name, "MAGNETOS")) return ControlMap::MAGNETOS;
684 if(eq(name, "ADVANCE")) return ControlMap::ADVANCE;
685 if(eq(name, "REHEAT")) return ControlMap::REHEAT;
686 if(eq(name, "BOOST")) return ControlMap::BOOST;
687 if(eq(name, "VECTOR")) return ControlMap::VECTOR;
688 if(eq(name, "PROP")) return ControlMap::PROP;
689 if(eq(name, "BRAKE")) return ControlMap::BRAKE;
690 if(eq(name, "STEER")) return ControlMap::STEER;
691 if(eq(name, "EXTEND")) return ControlMap::EXTEND;
692 if(eq(name, "INCIDENCE")) return ControlMap::INCIDENCE;
693 if(eq(name, "FLAP0")) return ControlMap::FLAP0;
694 if(eq(name, "FLAP1")) return ControlMap::FLAP1;
695 if(eq(name, "SLAT")) return ControlMap::SLAT;
696 if(eq(name, "SPOILER")) return ControlMap::SPOILER;
697 if(eq(name, "CASTERING")) return ControlMap::CASTERING;
698 if(eq(name, "PROPPITCH")) return ControlMap::PROPPITCH;
699 if(eq(name, "COLLECTIVE")) return ControlMap::COLLECTIVE;
700 if(eq(name, "CYCLICAIL")) return ControlMap::CYCLICAIL;
701 if(eq(name, "CYCLICELE")) return ControlMap::CYCLICELE;
702 if(eq(name, "ROTORENGINEON")) return ControlMap::ROTORENGINEON;
703 if(eq(name, "REVERSE_THRUST")) return ControlMap::REVERSE_THRUST;
704 SG_LOG(SG_FLIGHT,SG_ALERT,"Unrecognized control type '"
705 << name << "' in YASim aircraft description.");
710 void FGFDM::parseWeight(XMLAttributes* a)
712 WeightRec* wr = new WeightRec();
715 v[0] = attrf(a, "x");
716 v[1] = attrf(a, "y");
717 v[2] = attrf(a, "z");
719 wr->prop = dup(a->getValue("mass-prop"));
720 wr->size = attrf(a, "size", 0);
721 wr->handle = _airplane.addWeight(v, wr->size);
726 bool FGFDM::eq(const char* a, const char* b)
728 // Figure it out for yourself. :)
729 while(*a && *b && *a == *b) { a++; b++; }
733 char* FGFDM::dup(const char* s)
737 char* s2 = new char[len+1];
739 while((*p++ = *s++));
744 int FGFDM::attri(XMLAttributes* atts, char* attr)
746 if(!atts->hasAttribute(attr)) {
747 SG_LOG(SG_FLIGHT,SG_ALERT,"Missing '" << attr <<
748 "' in YASim aircraft description");
751 return attri(atts, attr, 0);
754 int FGFDM::attri(XMLAttributes* atts, char* attr, int def)
756 const char* val = atts->getValue(attr);
757 if(val == 0) return def;
758 else return atol(val);
761 float FGFDM::attrf(XMLAttributes* atts, char* attr)
763 if(!atts->hasAttribute(attr)) {
764 SG_LOG(SG_FLIGHT,SG_ALERT,"Missing '" << attr <<
765 "' in YASim aircraft description");
768 return attrf(atts, attr, 0);
771 float FGFDM::attrf(XMLAttributes* atts, char* attr, float def)
773 const char* val = atts->getValue(attr);
774 if(val == 0) return def;
775 else return (float)atof(val);
778 // ACK: the dreaded ambiguous string boolean. Remind me to shoot Maik
779 // when I have a chance. :). Unless you have a parser that can check
780 // symbol constants (we don't), this kind of coding is just a Bad
781 // Idea. This implementation, for example, silently returns a boolean
782 // falsehood for values of "1", "yes", "True", and "TRUE". Which is
783 // especially annoying preexisting boolean attributes in the same
784 // parser want to see "1" and will choke on a "true"...
786 // Unfortunately, this usage creeped into existing configuration files
787 // while I wasn't active, and it's going to be hard to remove. Issue
788 // a warning to nag people into changing their ways for now...
789 bool FGFDM::attrb(XMLAttributes* atts, char* attr)
791 const char* val = atts->getValue(attr);
792 if(val == 0) return false;
795 SG_LOG(SG_FLIGHT, SG_ALERT, "Warning: " <<
796 "deprecated 'true' boolean in YASim configuration file. " <<
797 "Use numeric booleans (attribute=\"1\") instead");
800 return attri(atts, attr, 0) ? true : false;
803 }; // namespace yasim