X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FYASim%2FYASim.cxx;h=88e2ed60583e855e2598bdedae5558530a3a1be8;hb=5161029fc5394e305defe2260ab5a12c47249433;hp=efa82483825f154c063c1c657adf42954d6ac8fa;hpb=0cabedaa4f8ce11bdab4d182937110d111d2590c;p=flightgear.git diff --git a/src/FDM/YASim/YASim.cxx b/src/FDM/YASim/YASim.cxx index efa824838..88e2ed605 100644 --- a/src/FDM/YASim/YASim.cxx +++ b/src/FDM/YASim/YASim.cxx @@ -1,8 +1,12 @@ -#include #include +#include +#include +#include #include + #include
#include
+#include #include "FGFDM.hpp" #include "Atmosphere.hpp" @@ -19,7 +23,9 @@ using namespace yasim; -static const float RAD2DEG = 180/3.14159265358979323846; +static const float YASIM_PI = 3.14159265358979323846; +static const float RAD2DEG = 180/YASIM_PI; +static const float PI2 = YASIM_PI*2; static const float RAD2RPM = 9.54929658551; static const float M2FT = 3.2808399; static const float FT2M = 0.3048; @@ -45,7 +51,7 @@ void YASim::printDEBUG() // fgGetFloat("/engines/engine[0]/epr"), // fgGetFloat("/engines/engine[0]/egt")); -// printf("gear: %f\n", fgGetFloat("/controls/gear-down")); +// printf("gear: %f\n", fgGetFloat("/controls/gear/gear-down")); // printf("alpha %5.1f beta %5.1f\n", get_Alpha()*57.3, get_Beta()*57.3); @@ -86,7 +92,7 @@ void YASim::report() float cg[3]; char buf[256]; a->getModel()->getBody()->getCG(cg); - sprintf(buf, " CG: %.1f, %.1f, %.1f", cg[0], cg[1], cg[2]); + sprintf(buf, " CG: %.3f, %.3f, %.3f", cg[0], cg[1], cg[2]); SG_LOG(SG_FLIGHT, SG_INFO, buf); if(a->getFailureMsg()) { @@ -122,12 +128,25 @@ void YASim::init() // Superclass hook common_init(); - m->setCrashed(false); + // Figure out the initial speed type + string speed_set = fgGetString("/sim/presets/speed-set", "UVW"); + if (speed_set == "NED") + _speed_set = NED; + else if (speed_set == "UVW") + _speed_set = UVW; + else if (speed_set == "knots") + _speed_set = KNOTS; + else if (speed_set == "mach") + _speed_set = MACH; + else { + _speed_set = UVW; + SG_LOG(SG_FLIGHT, SG_ALERT, "Unknown speed type " << speed_set); + } + // Build a filename and parse it - SGPath f(globals->get_fg_root()); - f.append("Aircraft-yasim"); + SGPath f(fgGetString("/sim/aircraft-dir")); f.append(fgGetString("/sim/aero")); f.concat(".xml"); readXML(f.str(), *_fdm); @@ -149,23 +168,23 @@ void YASim::init() node->setDoubleValue("yoffset-in", pos[1]); node->setDoubleValue("zoffset-in", pos[2]); } - for(i=0; inumThrusters(); i++) { - // Sanify the initial input conditions - char buf[64]; - sprintf(buf, "/controls/throttle[%d]", i); fgSetFloat(buf, 0); - sprintf(buf, "/controls/mixture[%d]", i); fgSetFloat(buf, 1); - sprintf(buf, "/controls/propeller-pitch[%d]", i); fgSetFloat(buf, 1); - sprintf(buf, "/controls/afterburner[%d]", i); fgSetFloat(buf, 0); - } - - fgSetFloat("/controls/slats", 0); - fgSetFloat("/controls/spoilers", 0); +// for(i=0; inumThrusters(); i++) { +// // Sanify the initial input conditions +// char buf[64]; +// sprintf(buf, "/controls/engines/engine[%d]/throttle", i); fgSetFloat(buf, 0); +// sprintf(buf, "/controls/engines/engine[%d]/mixture", i); fgSetFloat(buf, 1); +// sprintf(buf, "/controls/engines/engine[%d]/propeller-pitch", i); fgSetFloat(buf, 1); +// sprintf(buf, "/controls/engines/engine[%d]/augmentation", i); fgSetFloat(buf, 0); +// } + +// fgSetFloat("/controls/flight/slats", 0); +// fgSetFloat("/controls/flight/spoilers", 0); // Are we at ground level? If so, lift the plane up so the gear // clear the ground. double runway_altitude = get_Runway_altitude(); - fgSetBool("/controls/gear-down", false); if(get_Altitude() - runway_altitude < 50) { + fgSetBool("/controls/gear/gear-down", false); float minGearZ = 1e18; for(i=0; inumGear(); i++) { Gear* g = a->getGear(i); @@ -175,7 +194,7 @@ void YASim::init() minGearZ = pos[2]; } _set_Altitude(runway_altitude - minGearZ*M2FT); - fgSetBool("/controls/gear-down", true); + fgSetBool("/controls/gear/gear-down", true); } // The pilot's eyepoint @@ -234,7 +253,7 @@ void YASim::copyToYASim(bool copyState) wind[2] = get_V_down_airmass() * FT2M * -1.0; // Get ground elevation from the FGinterface's FGlocation data - double ground = getACModel()->get3DModel()->getFGLocation()->get_cur_elev_m(); + double ground = getACModel()->get3DModel()->getSGLocation()->get_cur_elev_m(); // cout << "YASIM: ground = " << ground << endl; float pressure = fgGetFloat("/environment/pressure-inhg") * INHG2PA; @@ -255,10 +274,48 @@ void YASim::copyToYASim(bool copyState) Glue::euler2orient(roll, pitch, hdg, s.orient); Math::mmul33(s.orient, xyz2ned, s.orient); - // Copy in the existing velocity for now... - Math::set3(model->getState()->v, s.v); + // Velocity + string speed_set = fgGetString("/sim/presets/speed-set", "UVW"); + float v[3]; + bool needCopy = false; + switch (_speed_set) { + case NED: + v[0] = get_V_north() * FT2M * -1.0; + v[1] = get_V_east() * FT2M * -1.0; + v[2] = get_V_down() * FT2M * -1.0; + break; + case UVW: + v[0] = get_uBody() * FT2M; + v[1] = get_vBody() * FT2M; + v[2] = get_wBody() * FT2M; + Math::tmul33(s.orient, v, v); + break; + case KNOTS: + v[0] = Atmosphere::spdFromVCAS(get_V_calibrated_kts()/MPS2KTS, + pressure, temp); + v[1] = 0; + v[2] = 0; + Math::tmul33(s.orient, v, v); + needCopy = true; + break; + case MACH: + v[0] = Atmosphere::spdFromMach(get_Mach_number(), temp); + v[1] = 0; + v[2] = 0; + Math::tmul33(s.orient, v, v); + needCopy = true; + break; + default: + v[0] = 0; + v[1] = 0; + v[2] = 0; + break; + } + if (!copyState) + _speed_set = UVW; // change to this after initial setting + Math::set3(v, s.v); - if(copyState) + if(copyState || needCopy) model->setState(&s); // wind @@ -365,7 +422,7 @@ void YASim::copyFromYASim() wind[2] = get_V_down_airmass() * FT2M * -1.0; Math::tmul33(xyz2ned, wind, wind); // Wind in global Math::sub3(s->v, wind, v); // V - wind in global - Math::vmul33(s->orient, s->v, v); // to body coordinates + Math::vmul33(s->orient, v, v); // to body coordinates _set_Velocities_Wind_Body(v[0]*M2FT, -v[1]*M2FT, -v[2]*M2FT); _set_V_rel_wind(Math::mag3(v)*M2FT); // units? @@ -386,7 +443,12 @@ void YASim::copyFromYASim() _set_Accels_CG_Body(M2FT*v[0], -M2FT*v[1], -M2FT*v[2]); _fdm->getAirplane()->getPilotAccel(v); - _set_Accels_Pilot_Body(M2FT*v[0], M2FT*v[1], -M2FT*v[2]); + _set_Accels_Pilot_Body(-M2FT*v[0], M2FT*v[1], M2FT*v[2]); + + // There is no property for pilot G's, but I need it for a panel + // instrument. Hack this in here, and REMOVE IT WHEN IT FINDS A + // REAL HOME! + fgSetFloat("/accelerations/pilot-g", -v[2]/9.8); // The one appears (!) to want inverted pilot acceleration // numbers, in G's... @@ -404,6 +466,8 @@ void YASim::copyFromYASim() Math::mmul33(s->orient, tmp, tmp); float roll, pitch, hdg; Glue::orient2euler(tmp, &roll, &pitch, &hdg); + // make heading positive value + if(hdg < 0.0) hdg += PI2; _set_Euler_Angles(roll, pitch, hdg); // rotation @@ -430,10 +494,6 @@ void YASim::copyFromYASim() node->setBoolValue("running", t->isRunning()); node->setBoolValue("cranking", t->isCranking()); - // Note: assumes all tanks have the same fuel density! - node->setDoubleValue("fuel-flow-gph", CM2GALS * t->getFuelFlow() - / airplane->getFuelDensity(0)); - float tmp[3]; t->getThrust(tmp); node->setDoubleValue("prop-thrust", Math::mag3(tmp) * KG2LBS / 9.8);