X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FJSBSim%2FJSBSim.cxx;h=0eb21888e30cf6c994f3a3a8fcafe5ed32cb45af;hb=96a902a2eb6e4a64cd4b225eb68fd85c07901903;hp=a915539cc8025cee7420c88704ec5d17962dfe46;hpb=0b86f8f63c00f053872704bb667c22d94523d71c;p=flightgear.git diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index a915539cc..0eb21888e 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -18,7 +18,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -// $Id: JSBSim.cxx,v 1.62 2010/07/14 05:50:40 ehofman Exp $ +// $Id: JSBSim.cxx,v 1.64 2010/10/31 04:49:25 jberndt Exp $ #ifdef HAVE_CONFIG_H @@ -26,6 +26,7 @@ #endif #include +#include #include // size_t #include @@ -97,14 +98,15 @@ public: /** Compute the altitude above ground. */ virtual double GetAGLevel(double t, const FGLocation& l, - FGLocation& cont, - FGColumnVector3& n, FGColumnVector3& v) const { + FGLocation& cont, FGColumnVector3& n, + FGColumnVector3& v, FGColumnVector3& w) const { double loc_cart[3] = { l(eX), l(eY), l(eZ) }; - double contact[3], normal[3], vel[3], agl = 0; + double contact[3], normal[3], vel[3], angularVel[3], agl = 0; mInterface->get_agl_ft(t, loc_cart, SG_METER_TO_FEET*2, contact, normal, - vel, &agl); + vel, angularVel, &agl); n = FGColumnVector3( normal[0], normal[1], normal[2] ); v = FGColumnVector3( vel[0], vel[1], vel[2] ); + w = FGColumnVector3( angularVel[0], angularVel[1], angularVel[2] ); cont = FGColumnVector3( contact[0], contact[1], contact[2] ); return agl; } @@ -211,15 +213,25 @@ FGJSBsim::FGJSBsim( double dt ) // Set initial fuel levels if provided. for (unsigned int i = 0; i < Propulsion->GetNumTanks(); i++) { + double d; SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true); - if (node->getChild("level-gal_us", 0, false) != 0) { - Propulsion->GetTank(i)->SetContents(node->getDoubleValue("level-gal_us") * 6.6); + FGTank* tank = Propulsion->GetTank(i); + + d = node->getNode( "density-ppg", true )->getDoubleValue(); + if( d > 0.0 ) { + tank->SetDensity( d ); + } else { + node->getNode( "density-ppg", true )->setDoubleValue( SG_MAX2(tank->GetDensity(), 0.1) ); + } + + d = node->getNode( "level-lbs", true )->getDoubleValue(); + if( d > 0.0 ) { + tank->SetContents( d ); } else { - node->setDoubleValue("level-lbs", Propulsion->GetTank(i)->GetContents()); - node->setDoubleValue("level-gal_us", Propulsion->GetTank(i)->GetContents() / 6.6); + node->getNode( "level-lbs", true )->setDoubleValue( tank->GetContents() ); } - node->setDoubleValue("capacity-gal_us", - Propulsion->GetTank(i)->GetCapacity() / 6.6); + /* Capacity is read-only in FGTank and can't be overwritten from FlightGear */ + node->getNode("capacity-gal_us", true )->setDoubleValue( tank->GetCapacityGallons() ); } Propulsion->SetFuelFreeze((fgGetNode("/sim/freeze/fuel",true))->getBoolValue()); @@ -289,6 +301,8 @@ FGJSBsim::FGJSBsim( double dt ) fgGetDouble("/fdm/jsbsim/systems/hook/tailhook-offset-x-in", 196), fgGetDouble("/fdm/jsbsim/systems/hook/tailhook-offset-y-in", 0), fgGetDouble("/fdm/jsbsim/systems/hook/tailhook-offset-z-in", -16)); + last_hook_tip[0] = 0; last_hook_tip[1] = 0; last_hook_tip[2] = 0; + last_hook_root[0] = 0; last_hook_root[1] = 0; last_hook_root[2] = 0; crashed = false; } @@ -419,6 +433,14 @@ void FGJSBsim::init() /******************************************************************************/ +void FGJSBsim::unbind() +{ + fdmex->Unbind(); + FGInterface::unbind(); +} + +/******************************************************************************/ + // Run an iteration of the EOM (equations of motion) void FGJSBsim::update( double dt ) @@ -451,7 +473,7 @@ void FGJSBsim::update( double dt ) // ground in this area. double groundCacheRadius = acrad + 2*dt*Propagate->GetUVW().Magnitude(); double alt, slr, lat, lon; - FGColumnVector3 cart = Auxiliary->GetLocationVRP(); + FGLocation cart = Auxiliary->GetLocationVRP(); if ( needTrim && startup_trim->getBoolValue() ) { alt = fgic->GetAltitudeASLFtIC(); slr = fgic->GetSeaLevelRadiusFtIC(); @@ -487,9 +509,9 @@ void FGJSBsim::update( double dt ) if ( needTrim ) { if ( startup_trim->getBoolValue() ) { - double contact[3], d[3], agl; + double contact[3], d[3], vel[3], agl; get_agl_ft(fdmex->GetSimTime(), cart_pos, SG_METER_TO_FEET*2, contact, - d, d, &agl); + d, vel, d, &agl); double terrain_alt = sqrt(contact[0]*contact[0] + contact[1]*contact[1] + contact[2]*contact[2]) - fgic->GetSeaLevelRadiusFtIC(); @@ -497,6 +519,13 @@ void FGJSBsim::update( double dt ) "Ready to trim, terrain elevation is: " << terrain_alt * SG_METER_TO_FEET ); + if (fgGetBool("/sim/presets/onground")) { + FGColumnVector3 gndVelNED = cart.GetTec2l() + * FGColumnVector3(vel[0], vel[1], vel[2]); + fgic->SetVNorthFpsIC(gndVelNED(1)); + fgic->SetVEastFpsIC(gndVelNED(2)); + fgic->SetVDownFpsIC(gndVelNED(3)); + } fgic->SetTerrainElevationFtIC( terrain_alt ); do_trim(); } else { @@ -511,7 +540,7 @@ void FGJSBsim::update( double dt ) } FGJSBBase::Message* msg; - while (msg = fdmex->ProcessNextMessage()) { + while ((msg = fdmex->ProcessNextMessage()) != NULL) { // msg = fdmex->ProcessNextMessage(); switch (msg->type) { case FGJSBBase::Message::eText: @@ -607,7 +636,7 @@ bool FGJSBsim::copy_to_JSBsim() } // end FGTurbine code block case FGEngine::etRocket: { // FGRocket code block - FGRocket* eng = (FGRocket*)Propulsion->GetEngine(i); +// FGRocket* eng = (FGRocket*)Propulsion->GetEngine(i); break; } // end FGRocket code block case FGEngine::etTurboprop: @@ -658,8 +687,13 @@ bool FGJSBsim::copy_to_JSBsim() for (i = 0; i < Propulsion->GetNumTanks(); i++) { SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true); FGTank * tank = Propulsion->GetTank(i); - tank->SetContents(node->getDoubleValue("level-gal_us") * 6.6); -// tank->SetContents(node->getDoubleValue("level-lbs")); + double fuelDensity = node->getDoubleValue("density-ppg"); + + if (fuelDensity < 0.1) + fuelDensity = 6.0; // Use average fuel value + + tank->SetDensity(fuelDensity); + tank->SetContents(node->getDoubleValue("level-lbs")); } Propulsion->SetFuelFreeze((fgGetNode("/sim/freeze/fuel",true))->getBoolValue()); @@ -743,7 +777,7 @@ bool FGJSBsim::copy_from_JSBsim() double loc_cart[3] = { l(FGJSBBase::eX), l(FGJSBBase::eY), l(FGJSBBase::eZ) }; double contact[3], d[3], sd, t; is_valid_m(&t, d, &sd); - get_agl_ft(t, loc_cart, SG_METER_TO_FEET*2, contact, d, d, &sd); + get_agl_ft(t, loc_cart, SG_METER_TO_FEET*2, contact, d, d, d, &sd); double rwrad = FGColumnVector3( contact[0], contact[1], contact[2] ).Magnitude(); _set_Runway_altitude( rwrad - get_Sea_level_radius() ); @@ -794,7 +828,7 @@ bool FGJSBsim::copy_from_JSBsim() break; case FGEngine::etRocket: { // FGRocket code block - FGRocket* eng = (FGRocket*)Propulsion->GetEngine(i); +// FGRocket* eng = (FGRocket*)Propulsion->GetEngine(i); } // end FGRocket code block break; case FGEngine::etTurbine: @@ -805,7 +839,7 @@ bool FGJSBsim::copy_from_JSBsim() node->setDoubleValue("egt-degf", 32 + eng->GetEGT()*9/5); node->setBoolValue("augmentation", eng->GetAugmentation()); node->setBoolValue("water-injection", eng->GetInjection()); - node->setBoolValue("ignition", eng->GetIgnition()); + node->setBoolValue("ignition", eng->GetIgnition() != 0); node->setDoubleValue("nozzle-pos-norm", eng->GetNozzle()); node->setDoubleValue("inlet-pos-norm", eng->GetInlet()); node->setDoubleValue("oil-pressure-psi", eng->getOilPressure_psi()); @@ -824,7 +858,7 @@ bool FGJSBsim::copy_from_JSBsim() node->setDoubleValue("n1", eng->GetN1()); //node->setDoubleValue("n2", eng->GetN2()); node->setDoubleValue("itt_degf", 32 + eng->GetITT()*9/5); - node->setBoolValue("ignition", eng->GetIgnition()); + node->setBoolValue("ignition", eng->GetIgnition() != 0); node->setDoubleValue("nozzle-pos-norm", eng->GetNozzle()); node->setDoubleValue("inlet-pos-norm", eng->GetInlet()); node->setDoubleValue("oil-pressure-psi", eng->getOilPressure_psi()); @@ -832,7 +866,7 @@ bool FGJSBsim::copy_from_JSBsim() node->setBoolValue("cutoff", eng->GetCutoff()); node->setBoolValue("starting", eng->GetEngStarting()); node->setBoolValue("generator-power", eng->GetGeneratorPower()); - node->setBoolValue("damaged", eng->GetCondition()); + node->setBoolValue("damaged", eng->GetCondition() != 0); node->setBoolValue("ielu-intervent", eng->GetIeluIntervent()); node->setDoubleValue("oil-temperature-degf", eng->getOilTemp_degF()); // node->setBoolValue("onfire", eng->GetFire()); @@ -864,7 +898,7 @@ bool FGJSBsim::copy_from_JSBsim() switch (thruster->GetType()) { case FGThruster::ttNozzle: { // FGNozzle code block - FGNozzle* noz = (FGNozzle*)thruster; +// FGNozzle* noz = (FGNozzle*)thruster; } // end FGNozzle code block break; case FGThruster::ttPropeller: @@ -878,7 +912,7 @@ bool FGJSBsim::copy_from_JSBsim() break; case FGThruster::ttRotor: { // FGRotor code block - FGRotor* rotor = (FGRotor*)thruster; +// FGRotor* rotor = (FGRotor*)thruster; } // end FGRotor code block break; case FGThruster::ttDirect: @@ -897,7 +931,12 @@ bool FGJSBsim::copy_from_JSBsim() FGTank* tank = Propulsion->GetTank(i); double contents = tank->GetContents(); double temp = tank->GetTemperature_degC(); - node->setDoubleValue("level-gal_us", contents/6.6); + double fuelDensity = tank->GetDensity(); + + if (fuelDensity < 0.1) + fuelDensity = 6.0; // Use average fuel value + + node->setDoubleValue("density-ppg" , fuelDensity); node->setDoubleValue("level-lbs", contents); if (temp != -9999.0) node->setDoubleValue("temperature_degC", temp); } @@ -1178,8 +1217,8 @@ void FGJSBsim::do_trim(void) globals->get_controls()->set_elevator_trim(FCS->GetPitchTrimCmd()); globals->get_controls()->set_elevator(FCS->GetDeCmd()); - globals->get_controls()->set_throttle(FGControls::ALL_ENGINES, - FCS->GetThrottleCmd(0)); + for( unsigned i = 0; i < Propulsion->GetNumEngines(); i++ ) + globals->get_controls()->set_throttle(i, FCS->GetThrottleCmd(i)); globals->get_controls()->set_aileron(FCS->GetDaCmd()); globals->get_controls()->set_rudder( FCS->GetDrCmd()); @@ -1204,9 +1243,8 @@ void FGJSBsim::update_ic(void) bool FGJSBsim::get_agl_ft(double t, const double pt[3], double alt_off, double contact[3], double normal[3], double vel[3], - double *agl) + double angularVel[3], double *agl) { - double angularVel[3]; const SGMaterial* material; simgear::BVHNode::Id id; if (!FGInterface::get_agl_ft(t, pt, alt_off, contact, normal, vel, @@ -1289,10 +1327,12 @@ void FGJSBsim::update_external_forces(double t_off) double contact[3]; double ground_normal[3]; double ground_vel[3]; + double ground_angular_vel[3]; double root_agl_ft; if (!got_wire) { - bool got = get_agl_ft(t_off, hook_area[1], 0, contact, ground_normal, ground_vel, &root_agl_ft); + bool got = get_agl_ft(t_off, hook_area[1], 0, contact, ground_normal, + ground_vel, ground_angular_vel, &root_agl_ft); if (got && root_agl_ft > 0 && root_agl_ft < hook_length) { FGColumnVector3 ground_normal_body = Tl2b * (Tec2l * FGColumnVector3(ground_normal[0], ground_normal[1], ground_normal[2])); FGColumnVector3 contact_body = Tl2b * Location.LocationToLocal(FGColumnVector3(contact[0], contact[1], contact[2]));