From 557a8794834cbd74337f8c388216002be079b933 Mon Sep 17 00:00:00 2001 From: ehofman Date: Thu, 2 Jun 2005 08:51:47 +0000 Subject: [PATCH] =?UTF-8?q?Mathias=20Fr=F6hlich:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this is basically the past patch I sent to the list and which should now really (...!?!?) fix the no ground below aircraft problem. Reasons: I understood my remaining thinko I introduced with the prevous patch, and the same thinko I made in my test cases. The feedback from the list told me that it should help. --- src/FDM/JSBSim/FGTable.cpp | 3 +- src/FDM/JSBSim/JSBSim.cxx | 75 ++++++++++++++--------------- src/FDM/JSBSim/filtersjb/FGGain.cpp | 11 ++++- src/FDM/groundcache.cxx | 9 ++-- src/Scenery/hitlist.cxx | 9 ++-- 5 files changed, 59 insertions(+), 48 deletions(-) diff --git a/src/FDM/JSBSim/FGTable.cpp b/src/FDM/JSBSim/FGTable.cpp index 62fdf465e..f54418f20 100644 --- a/src/FDM/JSBSim/FGTable.cpp +++ b/src/FDM/JSBSim/FGTable.cpp @@ -66,6 +66,7 @@ FGTable::FGTable(int NRows, int NCols, int NTables) Data = Allocate(); // this data array will contain the keys for the associated tables Tables.reserve(nTables); for (int i=0; i -#include #include // size_t #ifdef SG_MATH_EXCEPTION_CLASH @@ -39,6 +38,7 @@ #include #include #include +#include #include @@ -92,6 +92,7 @@ public: sgCartToGeod( pt, &lat, &lon, &alt); return alt * SG_METER_TO_FEET; } + /** Compute the altitude above ground. */ virtual double GetAGLevel(double t, const FGLocation& l, FGLocation& cont, @@ -116,7 +117,6 @@ FGJSBsim::FGJSBsim( double dt ) : FGInterface(dt) { bool result; - // Set up the debugging level // FIXME: this will not respond to // runtime changes @@ -208,7 +208,7 @@ FGJSBsim::FGJSBsim( double dt ) } } Propulsion->SetFuelFreeze((fgGetNode("/sim/freeze/fuel",true))->getBoolValue()); - + fgSetDouble("/fdm/trim/pitch-trim", FCS->GetPitchTrimCmd()); fgSetDouble("/fdm/trim/throttle", FCS->GetThrottleCmd(0)); fgSetDouble("/fdm/trim/aileron", FCS->GetDaCmd()); @@ -316,6 +316,14 @@ void FGJSBsim::init() << ", " << fdmex->GetAtmosphere()->GetPressure() << ", " << fdmex->GetAtmosphere()->GetDensity() ); + if (fgGetBool("/sim/presets/running")) { + for (int i=0; i < Propulsion->GetNumEngines(); i++) { + SGPropertyNode * node = fgGetNode("engines/engine", i, true); + node->setBoolValue("running", true); + Propulsion->GetEngine(i)->SetRunning(true); + } + } + common_init(); copy_to_JSBsim(); @@ -399,12 +407,13 @@ void FGJSBsim::update( double dt ) // Compute the potential movement of this aircraft and query for the // ground in this area. double groundCacheRadius = acrad + 2*dt*Propagate->GetUVW().Magnitude(); + double alt, slr, lat, lon; FGColumnVector3 cart = Auxiliary->GetLocationVRP(); if ( needTrim && startup_trim->getBoolValue() ) { - double alt = fgic->GetAltitudeFtIC(); - double slr = fgic->GetSeaLevelRadiusFtIC(); - double lat = fgic->GetLatitudeDegIC() * SGD_DEGREES_TO_RADIANS; - double lon = fgic->GetLongitudeDegIC() * SGD_DEGREES_TO_RADIANS; + alt = fgic->GetAltitudeFtIC(); + slr = fgic->GetSeaLevelRadiusFtIC(); + lat = fgic->GetLatitudeDegIC() * SGD_DEGREES_TO_RADIANS; + lon = fgic->GetLongitudeDegIC() * SGD_DEGREES_TO_RADIANS; cart = FGLocation(lon, lat, alt+slr); } double cart_pos[3] = { cart(1), cart(2), cart(3) }; @@ -412,10 +421,14 @@ void FGJSBsim::update( double dt ) groundCacheRadius ); if (!cache_ok) { SG_LOG(SG_FLIGHT, SG_WARN, - "FGInterface is beeing called without scenery below the aircraft!"); - return; + "FGInterface is being called without scenery below the aircraft!"); + cout << "altitude = " << alt << endl; + cout << "sea level radius = " << slr << endl; + cout << "latitude = " << lat << endl; + cout << "longitude = " << lon << endl; + //return; } - + copy_to_JSBsim(); trimmed->setBoolValue(false); @@ -544,7 +557,7 @@ bool FGJSBsim::copy_to_JSBsim() } // end FGEngine code block } - + Propagate->SetSeaLevelRadius( get_Sea_level_radius() ); Atmosphere->SetExTemperature( @@ -575,7 +588,7 @@ bool FGJSBsim::copy_to_JSBsim() SGPropertyNode* node = fgGetNode("/systems/refuel", true); Propulsion->SetRefuel(node->getDoubleValue("contact")); Propulsion->SetFuelFreeze((fgGetNode("/sim/freeze/fuel",true))->getBoolValue()); - + return true; } @@ -622,34 +635,9 @@ bool FGJSBsim::copy_from_JSBsim() Propagate->GetUVW(3) ); // Make the HUD work ... - { - const FGLocation& l = Auxiliary->GetLocationVRP(); - double xyz[3] = { l(eX)*SG_FEET_TO_METER, - l(eY)*SG_FEET_TO_METER, - l(eZ)*SG_FEET_TO_METER }; - double lat, lon, alt; - sgCartToGeod(xyz, &lat, &lon, &alt); - FGQuaternion Tec2geodhl(0, -0.5*M_PI-lat, lon); - - FGColumnVector3 ecVel = l.GetTl2ec()*Propagate->GetVel(); - FGColumnVector3 geodhlVel = Tec2geodhl.GetT()*ecVel; - - _set_Velocities_Ground( geodhlVel(eNorth)*SG_FEET_TO_METER, - geodhlVel(eEast)*SG_FEET_TO_METER, - -geodhlVel(eDown)*SG_FEET_TO_METER ); - - // Transform the acceleration to the earth centered frame and then - // back to the geodetic hl frame. - FGColumnVector3 accel = Propagate->GetUVWdot(); - accel -= Propagate->GetUVW()*Propagate->GetPQR(); - accel = Propagate->GetTb2l()*accel; - accel = l.GetTl2ec()*accel; - accel = Tec2geodhl.GetT()*accel; - - _set_Accels_Local( accel(eNorth)*SG_FEET_TO_METER, - accel(eEast)*SG_FEET_TO_METER, - -accel(eDown)*SG_FEET_TO_METER); - } + _set_Velocities_Ground( Propagate->GetVel(eNorth), + Propagate->GetVel(eEast), + -Propagate->GetVel(eDown) ); _set_V_rel_wind( Auxiliary->GetVt() ); @@ -825,6 +813,13 @@ bool FGJSBsim::copy_from_JSBsim() speedbrake_pos_pct->setDoubleValue( FCS->GetDsbPos(ofNorm) ); spoilers_pos_pct->setDoubleValue( FCS->GetDspPos(ofNorm) ); + // force a sim reset if crashed (altitude AGL < 0) + if (get_Altitude_AGL() < 0.0) { + fgSetBool("/sim/crashed", true); + SGPropertyNode* node = fgGetNode("/sim/presets", true); + globals->get_commands()->execute("old-reinit-dialog", node); + } + return true; } diff --git a/src/FDM/JSBSim/filtersjb/FGGain.cpp b/src/FDM/JSBSim/filtersjb/FGGain.cpp index cee78f566..7417c9395 100644 --- a/src/FDM/JSBSim/filtersjb/FGGain.cpp +++ b/src/FDM/JSBSim/filtersjb/FGGain.cpp @@ -182,13 +182,22 @@ void FGGain::convert(void) cout << endl; cout << " " << endl; - cout << " " << (InputNodes[0]->GetFullyQualifiedName()).substr(12) << "" << endl; + if (invert) + cout << " -" << (InputNodes[0]->GetFullyQualifiedName()).substr(12) << "" << endl; + else + cout << " " << (InputNodes[0]->GetFullyQualifiedName()).substr(12) << "" << endl; if (Gain != 1.0) cout << " " << Gain << "" << endl; if (Type == "PURE_GAIN") { // PURE_GAIN } else if (Type == "SCHEDULED_GAIN") { // SCHEDULED_GAIN + cout << " " << endl; + cout << " " << ScheduledBy->GetFullyQualifiedName().substr(12) << "" << endl; + cout << " " << endl; + Table->Print(20); + cout << " " << endl; + cout << "
" << endl; } else if (Type == "AEROSURFACE_SCALE") { // AEROSURFACE_SCALE cout << " " << endl; cout << " " << Min << "" << endl; diff --git a/src/FDM/groundcache.cxx b/src/FDM/groundcache.cxx index b008857b7..6c2654083 100644 --- a/src/FDM/groundcache.cxx +++ b/src/FDM/groundcache.cxx @@ -131,7 +131,8 @@ static inline bool fgdPointInTriangle( sgdVec3 point, sgdVec3 tri[3] ) SGDfloat tmp = (y2 - y3); SGDfloat tmpn = (x2 - x3); int side1 = SG_SIGN (tmp * (rx - x3) + (y3 - ry) * tmpn); - int side2 = SG_SIGN (tmp * (x1 - x3) + (y3 - side1*eps - y1) * tmpn); + int side2 = SG_SIGN (tmp * (x1 - x3) + (y3 - y1) * tmpn + + side1 * eps * fabs(tmpn)); if ( side1 != side2 ) { // printf("failed side 1 check\n"); return false; @@ -141,7 +142,8 @@ static inline bool fgdPointInTriangle( sgdVec3 point, sgdVec3 tri[3] ) tmp = (y3 - ry); tmpn = (x3 - rx); side1 = SG_SIGN (tmp * (x2 - rx) + (ry - y2) * tmpn); - side2 = SG_SIGN (tmp * (x1 - rx) + (ry - side1*eps - y1) * tmpn); + side2 = SG_SIGN (tmp * (x1 - rx) + (ry - y1) * tmpn + + side1 * eps * fabs(tmpn)); if ( side1 != side2 ) { // printf("failed side 2 check\n"); return false; @@ -151,7 +153,8 @@ static inline bool fgdPointInTriangle( sgdVec3 point, sgdVec3 tri[3] ) tmp = (y2 - ry); tmpn = (x2 - rx); side1 = SG_SIGN (tmp * (x3 - rx) + (ry - y3) * tmpn); - side2 = SG_SIGN (tmp * (x1 - rx) + (ry - side1*eps - y1) * tmpn); + side2 = SG_SIGN (tmp * (x1 - rx) + (ry - y1) * tmpn + + side1 * eps * fabs(tmpn)); if ( side1 != side2 ) { // printf("failed side 3 check\n"); return false; diff --git a/src/Scenery/hitlist.cxx b/src/Scenery/hitlist.cxx index 1318c4acb..fa5781c61 100644 --- a/src/Scenery/hitlist.cxx +++ b/src/Scenery/hitlist.cxx @@ -187,7 +187,8 @@ static inline bool fgdPointInTriangle( sgdVec3 point, sgdVec3 tri[3] ) SGDfloat tmp = (y2 - y3); SGDfloat tmpn = (x2 - x3); int side1 = SG_SIGN (tmp * (rx - x3) + (y3 - ry) * tmpn); - int side2 = SG_SIGN (tmp * (x1 - x3) + (y3 - side1*eps - y1) * tmpn); + int side2 = SG_SIGN (tmp * (x1 - x3) + (y3 - y1) * tmpn + + side1 * eps * fabs(tmpn)); if ( side1 != side2 ) { // printf("failed side 1 check\n"); return false; @@ -197,7 +198,8 @@ static inline bool fgdPointInTriangle( sgdVec3 point, sgdVec3 tri[3] ) tmp = (y3 - ry); tmpn = (x3 - rx); side1 = SG_SIGN (tmp * (x2 - rx) + (ry - y2) * tmpn); - side2 = SG_SIGN (tmp * (x1 - rx) + (ry - side1*eps - y1) * tmpn); + side2 = SG_SIGN (tmp * (x1 - rx) + (ry - y1) * tmpn + + side1 * eps * fabs(tmpn)); if ( side1 != side2 ) { // printf("failed side 2 check\n"); return false; @@ -207,7 +209,8 @@ static inline bool fgdPointInTriangle( sgdVec3 point, sgdVec3 tri[3] ) tmp = (y2 - ry); tmpn = (x2 - rx); side1 = SG_SIGN (tmp * (x3 - rx) + (ry - y3) * tmpn); - side2 = SG_SIGN (tmp * (x1 - rx) + (ry - side1*eps - y1) * tmpn); + side2 = SG_SIGN (tmp * (x1 - rx) + (ry - y1) * tmpn + + side1 * eps * fabs(tmpn)); if ( side1 != side2 ) { // printf("failed side 3 check\n"); return false;