From 73a519a95ce49db01f1b298de30e21a0d18f08f4 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Wed, 29 Jan 2014 13:50:06 +0100 Subject: [PATCH] Make the JSBSim terrain handling code compile time configurable by calling cmake -DJSBSIM_TERRAIN=1 --- CMakeLists.txt | 5 ++++ src/FDM/JSBSim/JSBSim.cxx | 53 ++++++++++++++++++++--------------- src/FDM/JSBSim/JSBSim.hxx | 2 +- src/Include/config_cmake.h.in | 1 + 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 143793f49..817733681 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,6 +142,7 @@ endif() # FlightGear build options option(SIMGEAR_SHARED "Set to ON when SimGear was built as a shared library" OFF) option(LOGGING "Set to ON to build FlightGear with logging support (default)" ON) +option(JSBSIM_TERRAIN "Set to ON to build FlightGear with JSBSim terrain handling code" OFF) option(SP_FDMS "Set to ON to build FlightGear with special-purpose FDMs" OFF) option(ENABLE_UIUC_MODEL "Set to ON to build FlightGear with UIUCModel FDM" OFF) option(ENABLE_LARCSIM "Set to ON to build FlightGear with LaRCsim FDM" OFF) @@ -175,6 +176,10 @@ else() set(FG_NDEBUG 1) endif() +if(JSBSIM_TERRAIN) + set(JSBSIM_USE_GROUNDREACTIONS 1) +endif() + if(SP_FDMS) set(ENABLE_SP_FDM 1) endif() diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index 6a4b93770..45b4b9e84 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. // -// $Id: JSBSim.cxx,v 1.64 2010/10/31 04:49:25 jberndt Exp $ +// $Id: FlightGear.cxx,v 1.15 2014/01/28 09:42:20 ehofman Exp $ #ifdef HAVE_CONFIG_H @@ -1331,27 +1331,28 @@ FGJSBsim::get_agl_ft(double t, const double pt[3], double alt_off, double contact[3], double normal[3], double vel[3], double angularVel[3], double *agl) { - const simgear::BVHMaterial* material; - simgear::BVHNode::Id id; - if (!FGInterface::get_agl_ft(t, pt, alt_off, contact, normal, vel, - angularVel, material, id)) - return false; + const simgear::BVHMaterial* material; + simgear::BVHNode::Id id; + if (!FGInterface::get_agl_ft(t, pt, alt_off, contact, normal, vel, + angularVel, material, id)) + return false; - SGGeod geodPt = SGGeod::fromCart(SG_FEET_TO_METER*SGVec3d(pt)); - SGQuatd hlToEc = SGQuatd::fromLonLat(geodPt); - *agl = dot(hlToEc.rotate(SGVec3d(0, 0, 1)), SGVec3d(contact) - SGVec3d(pt)); + SGGeod geodPt = SGGeod::fromCart(SG_FEET_TO_METER*SGVec3d(pt)); + SGQuatd hlToEc = SGQuatd::fromLonLat(geodPt); + *agl = dot(hlToEc.rotate(SGVec3d(0, 0, 1)), SGVec3d(contact) - SGVec3d(pt)); + + static SGPropertyNode_ptr terrain = fgGetNode("/sim/fdm/surface", true); #ifdef JSBSIM_USE_GROUNDREACTIONS - static SGPropertyNode_ptr terrain_nas = fgGetNode("/fdm/jsbsim/systems/fg-terrain", false); - if (material && !terrain_nas) { - double frictionFactor = (*material).get_friction_factor(); - double rollingFriction = (*material).get_rolling_friction(); - - if ((rollingFriction != 1.0) && (rollingFriction > 0.001)) { - frictionFactor = rollingFriction/0.02; - } - GroundReactions->SetFrictionFactor(frictionFactor); - + bool terrain_active = (terrain->getIntValue("override-level", -1) > 0) ? false : true; + terrain->setBoolValue("active", terrain_active); + terrain->setBoolValue("valid", (material && terrain_active) ? true : false); + if (terrain_active) + { + static bool material_valid = false; + if (material) { + GroundReactions->SetStaticFFactor((*material).get_friction_factor()); + GroundReactions->SetRollingFFactor((*material).get_rolling_friction()/0.02); // 1 Pascal = 0.00014503773800721815 lbs/in^2 double pressure = (*material).get_load_resistance(); // N/m^2 (or Pascal) GroundReactions->SetMaximumForce(pressure*0.00014503773800721815); @@ -1359,10 +1360,18 @@ FGJSBsim::get_agl_ft(double t, const double pt[3], double alt_off, GroundReactions->SetBumpiness((*material).get_bumpiness()); GroundReactions->SetSolid((*material).get_solid()); GroundReactions->SetPosition(pt); - } + material_valid = true; + } else { + if (material_valid) { + GroundReactions->resetValues(); + material_valid = false; + } + } + } +#else + terrain->setBoolValue("valid", false); #endif - - return true; + return true; } inline static double sqr(double x) diff --git a/src/FDM/JSBSim/JSBSim.hxx b/src/FDM/JSBSim/JSBSim.hxx index 56552dcac..31c63ced7 100644 --- a/src/FDM/JSBSim/JSBSim.hxx +++ b/src/FDM/JSBSim/JSBSim.hxx @@ -88,7 +88,7 @@ CLASS DOCUMENTATION documentation for main for direction on running JSBSim apart from FlightGear. @author Curtis L. Olson (original) @author Tony Peden (Maintained and refined) - @version $Id: JSBSim.hxx,v 1.15 2010/10/07 03:45:40 jberndt Exp $ + @version $Id: FlightGear.hxx,v 1.16 2014/01/28 09:42:21 ehofman Exp $ @see main in file JSBSim.cpp (use main() wrapper for standalone usage) */ diff --git a/src/Include/config_cmake.h.in b/src/Include/config_cmake.h.in index 1faa29f44..ac6579352 100644 --- a/src/Include/config_cmake.h.in +++ b/src/Include/config_cmake.h.in @@ -2,6 +2,7 @@ #cmakedefine FG_NDEBUG #cmakedefine ENABLE_SP_FDM +#cmakedefine JSBSIM_USE_GROUNDREACTIONS // JSBSim needs this, to switch from standalone to in-FG mode #define FGFS