1 #include "Atmosphere.hpp"
2 #include "ControlMap.hpp"
6 #include "RigidBody.hpp"
8 #include "Thruster.hpp"
10 #include "Airplane.hpp"
15 inline float norm(float f) { return f<1 ? 1/f : f; }
16 inline float abs(float f) { return f<0 ? -f : f; }
18 // Solver threshold. How close to the solution are we trying
19 // to get? Trying too hard can result in oscillations about
20 // the correct solution, which is bad. Stick this in as a
21 // compile time constant for now, and consider making it
22 // settable per-model.
23 const float STHRESH = 1;
25 // How slowly do we change values in the solver. Too slow, and
26 // the solution converges very slowly. Too fast, and it can
28 const float SOLVE_TWEAK = 0.3226;
33 _pilotPos[0] = _pilotPos[1] = _pilotPos[2] = 0;
56 for(i=0; i<_fuselages.size(); i++)
57 delete (Fuselage*)_fuselages.get(i);
58 for(i=0; i<_tanks.size(); i++)
59 delete (Tank*)_tanks.get(i);
60 for(i=0; i<_thrusters.size(); i++)
61 delete (ThrustRec*)_thrusters.get(i);
62 for(i=0; i<_gears.size(); i++)
63 delete (GearRec*)_gears.get(i);
64 for(i=0; i<_surfs.size(); i++)
65 delete (Surface*)_surfs.get(i);
66 for(i=0; i<_contacts.size(); i++)
67 delete[] (float*)_contacts.get(i);
70 void Airplane::iterate(float dt)
72 // The gear might have moved. Change their aerodynamics.
78 void Airplane::consumeFuel(float dt)
80 // This is a really simple implementation that assumes all engines
81 // draw equally from all tanks in proportion to the amount of fuel
82 // stored there. Needs to be fixed, but that has to wait for a
83 // decision as to what the property interface will look like.
85 float fuelFlow = 0, totalFuel = 0.00001; // <-- overflow protection
86 for(i=0; i<_thrusters.size(); i++)
87 fuelFlow += ((ThrustRec*)_thrusters.get(i))->thruster->getFuelFlow();
88 for(i=0; i<_tanks.size(); i++)
89 totalFuel += ((Tank*)_tanks.get(i))->fill;
90 for(i=0; i<_tanks.size(); i++) {
91 Tank* t = (Tank*)_tanks.get(i);
92 t->fill -= dt * fuelFlow * (t->fill/totalFuel);
99 for(int i=0; i<_thrusters.size(); i++)
100 ((ThrustRec*)_thrusters.get(i))->thruster->setFuelState(false);
102 // Set the tank masses on the RigidBody
103 for(i=0; i<_tanks.size(); i++) {
104 Tank* t = (Tank*)_tanks.get(i);
105 _model.getBody()->setMass(t->handle, t->fill);
109 ControlMap* Airplane::getControlMap()
114 Model* Airplane::getModel()
119 void Airplane::getPilotAccel(float* out)
121 State* s = _model.getState();
124 Glue::geodUp(s->pos, out);
125 Math::mul3(-9.8f, out, out);
127 // The regular acceleration
129 Math::mul3(-1, s->acc, tmp);
130 Math::add3(tmp, out, out);
132 // Convert to aircraft coordinates
133 Math::vmul33(s->orient, out, out);
135 // FIXME: rotational & centripetal acceleration needed
138 void Airplane::setPilotPos(float* pos)
141 for(i=0; i<3; i++) _pilotPos[i] = pos[i];
144 void Airplane::getPilotPos(float* out)
147 for(i=0; i<3; i++) out[i] = _pilotPos[i];
150 int Airplane::numGear()
152 return _gears.size();
155 Gear* Airplane::getGear(int g)
157 return ((GearRec*)_gears.get(g))->gear;
160 void Airplane::updateGearState()
162 for(int i=0; i<_gears.size(); i++) {
163 GearRec* gr = (GearRec*)_gears.get(i);
164 float ext = gr->gear->getExtension();
166 gr->surf->setXDrag(ext);
167 gr->surf->setYDrag(ext);
168 gr->surf->setZDrag(ext);
172 void Airplane::setApproach(float speed, float altitude)
174 // The zero AoA will become a calculated stall AoA in compile()
175 setApproach(speed, altitude, 0);
178 void Airplane::setApproach(float speed, float altitude, float aoa)
180 _approachSpeed = speed;
181 _approachP = Atmosphere::getStdPressure(altitude);
182 _approachT = Atmosphere::getStdTemperature(altitude);
186 void Airplane::setCruise(float speed, float altitude)
188 _cruiseSpeed = speed;
189 _cruiseP = Atmosphere::getStdPressure(altitude);
190 _cruiseT = Atmosphere::getStdTemperature(altitude);
195 void Airplane::setElevatorControl(int control)
197 _approachElevator.control = control;
198 _approachElevator.val = 0;
199 _approachControls.add(&_approachElevator);
202 void Airplane::addApproachControl(int control, float val)
204 Control* c = new Control();
205 c->control = control;
207 _approachControls.add(c);
210 void Airplane::addCruiseControl(int control, float val)
212 Control* c = new Control();
213 c->control = control;
215 _cruiseControls.add(c);
218 int Airplane::numTanks()
220 return _tanks.size();
223 float Airplane::getFuel(int tank)
225 return ((Tank*)_tanks.get(tank))->fill;
228 float Airplane::getFuelDensity(int tank)
230 return ((Tank*)_tanks.get(tank))->density;
233 float Airplane::getTankCapacity(int tank)
235 return ((Tank*)_tanks.get(tank))->cap;
238 void Airplane::setWeight(float weight)
240 _emptyWeight = weight;
243 void Airplane::setWing(Wing* wing)
248 void Airplane::setTail(Wing* tail)
253 void Airplane::addVStab(Wing* vstab)
258 void Airplane::addFuselage(float* front, float* back, float width,
259 float taper, float mid)
261 Fuselage* f = new Fuselage();
264 f->front[i] = front[i];
265 f->back[i] = back[i];
273 int Airplane::addTank(float* pos, float cap, float density)
275 Tank* t = new Tank();
277 for(i=0; i<3; i++) t->pos[i] = pos[i];
280 t->density = density;
281 t->handle = 0xffffffff;
282 return _tanks.add(t);
285 void Airplane::addGear(Gear* gear)
287 GearRec* g = new GearRec();
293 void Airplane::addThruster(Thruster* thruster, float mass, float* cg)
295 ThrustRec* t = new ThrustRec();
296 t->thruster = thruster;
299 for(i=0; i<3; i++) t->cg[i] = cg[i];
303 void Airplane::addBallast(float* pos, float mass)
305 _model.getBody()->addMass(mass, pos);
309 int Airplane::addWeight(float* pos, float size)
311 WeightRec* wr = new WeightRec();
312 wr->handle = _model.getBody()->addMass(0, pos);
314 wr->surf = new Surface();
315 wr->surf->setPosition(pos);
316 wr->surf->setTotalDrag(size*size);
317 _model.addSurface(wr->surf);
318 _surfs.add(wr->surf);
320 return _weights.add(wr);
323 void Airplane::setWeight(int handle, float mass)
325 WeightRec* wr = (WeightRec*)_weights.get(handle);
327 _model.getBody()->setMass(wr->handle, mass);
329 // Kill the aerodynamic drag if the mass is exactly zero. This is
330 // how we simulate droppable stores.
332 wr->surf->setXDrag(0);
333 wr->surf->setYDrag(0);
334 wr->surf->setZDrag(0);
336 wr->surf->setXDrag(1);
337 wr->surf->setYDrag(1);
338 wr->surf->setZDrag(1);
342 void Airplane::setFuelFraction(float frac)
345 for(i=0; i<_tanks.size(); i++) {
346 Tank* t = (Tank*)_tanks.get(i);
347 t->fill = frac * t->cap;
348 _model.getBody()->setMass(t->handle, t->cap * frac);
352 float Airplane::getDragCoefficient()
357 float Airplane::getLiftRatio()
362 float Airplane::getCruiseAoA()
367 float Airplane::getTailIncidence()
369 return _tailIncidence;
372 char* Airplane::getFailureMsg()
377 int Airplane::getSolutionIterations()
379 return _solutionIterations;
382 void Airplane::setupState(float aoa, float speed, State* s)
384 float cosAoA = Math::cos(aoa);
385 float sinAoA = Math::sin(aoa);
386 s->orient[0] = cosAoA; s->orient[1] = 0; s->orient[2] = sinAoA;
387 s->orient[3] = 0; s->orient[4] = 1; s->orient[5] = 0;
388 s->orient[6] = -sinAoA; s->orient[7] = 0; s->orient[8] = cosAoA;
390 s->v[0] = speed; s->v[1] = 0; s->v[2] = 0;
394 s->pos[i] = s->rot[i] = s->acc[i] = s->racc[i] = 0;
396 // Put us 1m above the origin, or else the gravity computation in
401 void Airplane::addContactPoint(float* pos)
403 float* cp = new float[3];
410 float Airplane::compileWing(Wing* w)
412 // The tip of the wing is a contact point
415 addContactPoint(tip);
416 if(w->isMirrored()) {
418 addContactPoint(tip);
421 // Make sure it's initialized. The surfaces will pop out with
422 // total drag coefficients equal to their areas, which is what we
428 for(i=0; i<w->numSurfaces(); i++) {
429 Surface* s = (Surface*)w->getSurface(i);
431 float td = s->getTotalDrag();
434 _model.addSurface(s);
436 float mass = w->getSurfaceWeight(i);
437 mass = mass * Math::sqrt(mass);
440 _model.getBody()->addMass(mass, pos);
446 float Airplane::compileFuselage(Fuselage* f)
448 // The front and back are contact points
449 addContactPoint(f->front);
450 addContactPoint(f->back);
454 Math::sub3(f->front, f->back, fwd);
455 float len = Math::mag3(fwd);
456 float wid = f->width;
457 int segs = (int)Math::ceil(len/wid);
458 float segWgt = len*wid/segs;
460 for(j=0; j<segs; j++) {
461 float frac = (j+0.5f) / segs;
465 scale = f->taper+(1-f->taper) * (frac / f->mid);
467 scale = f->taper+(1-f->taper) * (frac - f->mid) / (1 - f->mid);
471 Math::mul3(frac, fwd, pos);
472 Math::add3(f->back, pos, pos);
474 // _Mass_ weighting goes as surface area^(3/2)
475 float mass = scale*segWgt * Math::sqrt(scale*segWgt);
476 _model.getBody()->addMass(mass, pos);
479 // Make a Surface too
480 Surface* s = new Surface();
482 float sideDrag = len/wid;
483 s->setYDrag(sideDrag);
484 s->setZDrag(sideDrag);
485 s->setTotalDrag(scale*segWgt);
487 // FIXME: fails for fuselages aligned along the Y axis
489 float *x=o, *y=o+3, *z=o+6; // nicknames for the axes
491 y[0] = 0; y[1] = 1; y[2] = 0;
492 Math::cross3(x, y, z);
494 Math::cross3(z, x, y);
495 s->setOrientation(o);
497 _model.addSurface(s);
503 // FIXME: should probably add a mass for the gear, too
504 void Airplane::compileGear(GearRec* gr)
508 // Make a Surface object for the aerodynamic behavior
509 Surface* s = new Surface();
512 // Put the surface at the half-way point on the gear strut, give
513 // it a drag coefficient equal to a square of the same dimension
514 // (gear are really draggy) and make it symmetric. Assume that
515 // the "length" of the gear is 3x the compression distance
516 float pos[3], cmp[3];
517 g->getCompression(cmp);
518 float length = 3 * Math::mag3(cmp);
520 Math::mul3(0.5, cmp, cmp);
521 Math::add3(pos, cmp, pos);
524 s->setTotalDrag(length*length);
527 _model.addSurface(s);
531 void Airplane::compileContactPoints()
533 // Figure it will compress by 20cm
536 comp[0] = 0; comp[1] = 0; comp[2] = DIST;
538 // Give it a spring constant such that at full compression it will
539 // hold up 10 times the planes mass. That's about right. Yeah.
540 float mass = _model.getBody()->getTotalMass();
541 float spring = (1/DIST) * 9.8f * 10.0f * mass;
542 float damp = 2 * Math::sqrt(spring * mass);
545 for(i=0; i<_contacts.size(); i++) {
546 float *cp = (float*)_contacts.get(i);
548 Gear* g = new Gear();
551 g->setCompression(comp);
552 g->setSpring(spring);
557 g->setStaticFriction(0.6f);
558 g->setDynamicFriction(0.5f);
564 void Airplane::compile()
567 ground[0] = 0; ground[1] = 0; ground[2] = 1;
568 _model.setGroundPlane(ground, -100000);
570 RigidBody* body = _model.getBody();
571 int firstMass = body->numMasses();
573 // Generate the point masses for the plane. Just use unitless
574 // numbers for a first pass, then go back through and rescale to
575 // make the weight right.
579 aeroWgt += compileWing(_wing);
580 aeroWgt += compileWing(_tail);
582 for(i=0; i<_vstabs.size(); i++) {
583 aeroWgt += compileWing((Wing*)_vstabs.get(i));
587 for(i=0; i<_fuselages.size(); i++) {
588 aeroWgt += compileFuselage((Fuselage*)_fuselages.get(i));
591 // Count up the absolute weight we have
592 float nonAeroWgt = _ballast;
593 for(i=0; i<_thrusters.size(); i++)
594 nonAeroWgt += ((ThrustRec*)_thrusters.get(i))->mass;
596 // Rescale to the specified empty weight
597 float wscale = (_emptyWeight-nonAeroWgt)/aeroWgt;
598 for(i=firstMass; i<body->numMasses(); i++)
599 body->setMass(i, body->getMass(i)*wscale);
601 // Add the thruster masses
602 for(i=0; i<_thrusters.size(); i++) {
603 ThrustRec* t = (ThrustRec*)_thrusters.get(i);
604 body->addMass(t->mass, t->cg);
607 // Add the tanks, empty for now.
609 for(i=0; i<_tanks.size(); i++) {
610 Tank* t = (Tank*)_tanks.get(i);
611 t->handle = body->addMass(0, t->pos);
614 _cruiseWeight = _emptyWeight + totalFuel*0.5f;
615 _approachWeight = _emptyWeight + totalFuel*0.2f;
619 // Add surfaces for the landing gear.
620 for(i=0; i<_gears.size(); i++)
621 compileGear((GearRec*)_gears.get(i));
623 // The Thruster objects
624 for(i=0; i<_thrusters.size(); i++) {
625 ThrustRec* tr = (ThrustRec*)_thrusters.get(i);
626 tr->handle = _model.addThruster(tr->thruster);
631 float gespan = _wing->getGroundEffect(gepos);
632 _model.setGroundEffect(gepos, gespan, 0.15f);
637 // Do this after solveGear, because it creates "gear" objects that
638 // we don't want to affect.
639 compileContactPoints();
642 void Airplane::solveGear()
645 _model.getBody()->getCG(cg);
647 // Calculate spring constant weightings for the gear. Weight by
648 // the inverse of the distance to the c.g. in the XY plane, which
649 // should be correct for most gear arrangements. Add 50cm of
650 // "buffer" to keep things from blowing up with aircraft with a
651 // single gear very near the c.g. (AV-8, for example).
654 for(i=0; i<_gears.size(); i++) {
655 GearRec* gr = (GearRec*)_gears.get(i);
658 Math::sub3(cg, pos, pos);
659 gr->wgt = 1.0f/(0.5f+Math::sqrt(pos[0]*pos[0] + pos[1]*pos[1]));
663 // Renormalize so they sum to 1
664 for(i=0; i<_gears.size(); i++)
665 ((GearRec*)_gears.get(i))->wgt /= total;
667 // The force at max compression should be sufficient to stop a
668 // plane moving downwards at 2x the approach descent rate. Assume
669 // a 3 degree approach.
670 float descentRate = 2.0f*_approachSpeed/19.1f;
672 // Spread the kinetic energy according to the gear weights. This
673 // will results in an equal compression fraction (not distance) of
675 float energy = 0.5f*_approachWeight*descentRate*descentRate;
677 for(i=0; i<_gears.size(); i++) {
678 GearRec* gr = (GearRec*)_gears.get(i);
679 float e = energy * gr->wgt;
681 gr->gear->getCompression(comp);
682 float len = Math::mag3(comp);
684 // Energy in a spring: e = 0.5 * k * len^2
685 float k = 2 * e / (len*len);
687 gr->gear->setSpring(k * gr->gear->getSpring());
689 // Critically damped (too damped, too!)
690 gr->gear->setDamping(2*Math::sqrt(k*_approachWeight*gr->wgt)
691 * gr->gear->getDamping());
693 // These are pretty generic
694 gr->gear->setStaticFriction(0.8f);
695 gr->gear->setDynamicFriction(0.7f);
699 void Airplane::initEngines()
701 for(int i=0; i<_thrusters.size(); i++) {
702 ThrustRec* tr = (ThrustRec*)_thrusters.get(i);
703 tr->thruster->init();
707 void Airplane::stabilizeThrust()
710 for(i=0; i<_thrusters.size(); i++)
711 _model.getThruster(i)->stabilize();
714 void Airplane::runCruise()
716 setupState(_cruiseAoA, _cruiseSpeed, &_cruiseState);
717 _model.setState(&_cruiseState);
718 _model.setAir(_cruiseP, _cruiseT,
719 Atmosphere::calcStdDensity(_cruiseP, _cruiseT));
721 // The control configuration
724 for(i=0; i<_cruiseControls.size(); i++) {
725 Control* c = (Control*)_cruiseControls.get(i);
726 _controls.setInput(c->control, c->val);
728 _controls.applyControls(1000000); // Huge dt value
732 Math::mul3(-1, _cruiseState.v, wind);
733 Math::vmul33(_cruiseState.orient, wind, wind);
735 // Cruise is by convention at 50% tank capacity
736 setFuelFraction(0.5);
738 // Set up the thruster parameters and iterate until the thrust
740 for(i=0; i<_thrusters.size(); i++) {
741 Thruster* t = ((ThrustRec*)_thrusters.get(i))->thruster;
743 t->setAir(_cruiseP, _cruiseT,
744 Atmosphere::calcStdDensity(_cruiseP, _cruiseT));
750 // Precompute thrust in the model, and calculate aerodynamic forces
751 _model.getBody()->recalc();
752 _model.getBody()->reset();
753 _model.initIteration();
754 _model.calcForces(&_cruiseState);
757 void Airplane::runApproach()
759 setupState(_approachAoA, _approachSpeed, &_approachState);
760 _model.setState(&_approachState);
761 _model.setAir(_approachP, _approachT,
762 Atmosphere::calcStdDensity(_approachP, _approachT));
764 // The control configuration
767 for(i=0; i<_approachControls.size(); i++) {
768 Control* c = (Control*)_approachControls.get(i);
769 _controls.setInput(c->control, c->val);
771 _controls.applyControls(1000000);
775 Math::mul3(-1, _approachState.v, wind);
776 Math::vmul33(_approachState.orient, wind, wind);
778 // Approach is by convention at 20% tank capacity
779 setFuelFraction(0.2f);
781 // Run the thrusters until they get to a stable setting. FIXME:
782 // this is lots of wasted work.
783 for(i=0; i<_thrusters.size(); i++) {
784 Thruster* t = ((ThrustRec*)_thrusters.get(i))->thruster;
786 t->setAir(_approachP, _approachT,
787 Atmosphere::calcStdDensity(_approachP, _approachT));
793 // Precompute thrust in the model, and calculate aerodynamic forces
794 _model.getBody()->recalc();
795 _model.getBody()->reset();
796 _model.initIteration();
797 _model.calcForces(&_approachState);
800 void Airplane::applyDragFactor(float factor)
802 float applied = Math::pow(factor, SOLVE_TWEAK);
803 _dragFactor *= applied;
804 _wing->setDragScale(_wing->getDragScale() * applied);
805 _tail->setDragScale(_tail->getDragScale() * applied);
807 for(i=0; i<_vstabs.size(); i++) {
808 Wing* w = (Wing*)_vstabs.get(i);
809 w->setDragScale(w->getDragScale() * applied);
811 for(i=0; i<_surfs.size(); i++) {
812 Surface* s = (Surface*)_surfs.get(i);
813 s->setTotalDrag(s->getTotalDrag() * applied);
817 void Airplane::applyLiftRatio(float factor)
819 float applied = Math::pow(factor, SOLVE_TWEAK);
820 _liftRatio *= applied;
821 _wing->setLiftRatio(_wing->getLiftRatio() * applied);
822 _tail->setLiftRatio(_tail->getLiftRatio() * applied);
824 for(i=0; i<_vstabs.size(); i++) {
825 Wing* w = (Wing*)_vstabs.get(i);
826 w->setLiftRatio(w->getLiftRatio() * applied);
830 float Airplane::clamp(float val, float min, float max)
832 if(val < min) return min;
833 if(val > max) return max;
837 float Airplane::normFactor(float f)
844 void Airplane::solve()
846 static const float ARCMIN = 0.0002909f;
849 _solutionIterations = 0;
853 printf("%d %f %f %f %f %f\n", //DEBUG
859 _approachElevator.val);
862 if(_solutionIterations++ > 10000) {
863 _failureMsg = "Solution failed to converge after 10000 iterations";
867 // Run an iteration at cruise, and extract the needed numbers:
870 _model.getThrust(tmp);
871 float thrust = tmp[0];
873 _model.getBody()->getAccel(tmp);
874 Math::tmul33(_cruiseState.orient, tmp, tmp);
875 float xforce = _cruiseWeight * tmp[0];
876 float clift0 = _cruiseWeight * tmp[2];
878 _model.getBody()->getAngularAccel(tmp);
879 Math::tmul33(_cruiseState.orient, tmp, tmp);
880 float pitch0 = tmp[1];
882 // Run an approach iteration, and do likewise
885 _model.getBody()->getAngularAccel(tmp);
886 Math::tmul33(_approachState.orient, tmp, tmp);
887 double apitch0 = tmp[1];
889 _model.getBody()->getAccel(tmp);
890 Math::tmul33(_approachState.orient, tmp, tmp);
891 float alift = _approachWeight * tmp[2];
893 // Modify the cruise AoA a bit to get a derivative
894 _cruiseAoA += ARCMIN;
896 _cruiseAoA -= ARCMIN;
898 _model.getBody()->getAccel(tmp);
899 Math::tmul33(_cruiseState.orient, tmp, tmp);
900 float clift1 = _cruiseWeight * tmp[2];
902 // Do the same with the tail incidence
903 _tail->setIncidence(_tailIncidence + ARCMIN);
905 _tail->setIncidence(_tailIncidence);
907 _model.getBody()->getAngularAccel(tmp);
908 Math::tmul33(_cruiseState.orient, tmp, tmp);
909 float pitch1 = tmp[1];
912 float awgt = 9.8f * _approachWeight;
914 float dragFactor = thrust / (thrust-xforce);
915 float liftFactor = awgt / (awgt+alift);
916 float aoaDelta = -clift0 * (ARCMIN/(clift1-clift0));
917 float tailDelta = -pitch0 * (ARCMIN/(pitch1-pitch0));
920 if(dragFactor <= 0 || liftFactor <= 0)
923 // And the elevator control in the approach. This works just
924 // like the tail incidence computation (it's solving for the
925 // same thing -- pitching moment -- by diddling a different
927 const float ELEVDIDDLE = 0.001f;
928 _approachElevator.val += ELEVDIDDLE;
930 _approachElevator.val -= ELEVDIDDLE;
932 _model.getBody()->getAngularAccel(tmp);
933 Math::tmul33(_approachState.orient, tmp, tmp);
934 double apitch1 = tmp[1];
935 float elevDelta = -apitch0 * (ELEVDIDDLE/(apitch1-apitch0));
937 // Now apply the values we just computed. Note that the
938 // "minor" variables are deferred until we get the lift/drag
939 // numbers in the right ballpark.
941 applyDragFactor(dragFactor);
942 applyLiftRatio(liftFactor);
944 // DON'T do the following until the above are sane
945 if(normFactor(dragFactor) > STHRESH*1.0001
946 || normFactor(liftFactor) > STHRESH*1.0001)
951 // OK, now we can adjust the minor variables:
952 _cruiseAoA += SOLVE_TWEAK*aoaDelta;
953 _tailIncidence += SOLVE_TWEAK*tailDelta;
955 _cruiseAoA = clamp(_cruiseAoA, -0.175f, 0.175f);
956 _tailIncidence = clamp(_tailIncidence, -0.175f, 0.175f);
958 if(abs(xforce/_cruiseWeight) < STHRESH*0.0001 &&
959 abs(alift/_approachWeight) < STHRESH*0.0001 &&
960 abs(aoaDelta) < STHRESH*.000017 &&
961 abs(tailDelta) < STHRESH*.000017)
963 // If this finaly value is OK, then we're all done
964 if(abs(elevDelta) < STHRESH*0.0001)
967 // Otherwise, adjust and do the next iteration
968 _approachElevator.val += SOLVE_TWEAK * elevDelta;
969 if(abs(_approachElevator.val) > 1) {
970 _failureMsg = "Insufficient elevator to trim for approach";
976 if(_dragFactor < 1e-06 || _dragFactor > 1e6) {
977 _failureMsg = "Drag factor beyond reasonable bounds.";
979 } else if(_liftRatio < 1e-04 || _liftRatio > 1e4) {
980 _failureMsg = "Lift ratio beyond reasonable bounds.";
982 } else if(Math::abs(_cruiseAoA) >= .17453293) {
983 _failureMsg = "Cruise AoA > 10 degrees";
985 } else if(Math::abs(_tailIncidence) >= .17453293) {
986 _failureMsg = "Tail incidence > 10 degrees";
990 }; // namespace yasim