Hi,

I could reproduce the bug on my computer as well.

There seems to be some confusion about what the
SetLongitude()/SetLatitude()/SetAltitude()/etc. do in
src/FDM/JSBSim/JSBSim.cxx. On one hand, they are obviously intended to
update the initial conditions (IC) of JSBSim. And, when the IC are
updated, JSBSim assumes that a trim is needed. This is what happens when
the FDM is initialized or reset.

On the other hand, during a replay, these same functions are called but
with a somewhat different goal. Obviously the intent of 'replay' is not
to modify the IC of JSBSim but to fake the calculations of the FDM for
the purpose of displaying the aircraft at the right location and right
attitude. In this case there is indeed no need for a trim.

These two purposes are not really consistent hence the problem : JSBSim
gets lost about what the intent of FlightGear is.

Attached is a patch that fixes this bug (#294 in the bug tracker). As
far as I could test, it restores the functionality of the instant replay
while keeping the restart feature (CTRL+SHIFT+ESC) functional.
Furthermore I have implemented the 2 methods suspend() and resume() in
JSBSim.cxx so that the FDM is actually suspended during the replay.

However this bug fix is not really elegant because the original code is
not so elegant itself (see explanations above).

Bertrand.

Le lundi 21 mars 2011 à 20:06 +0100, ThorstenB a écrit :
> Hi,
> not sure if anyone else had a chance to test the "instant replay" with
> JSBSim aircraft - but it indeed seems like a general issue to me. It's
> triggered by JSBSim doing a "trim" operation once playback has
> finished - which produces an output like this (with the F16 in this
> case):
> 
>   Trim Results:
>           Altitude AGL:     15  wdot: -1.83e+08 Tolerance: 1e-03  Failed
>            Pitch Angle:    -19  qdot:  9.33e+07 Tolerance: 1e-04  Failed
> 
>   Trim Statistics:
>     Total Iterations: 61
>     Sub-iterations:
>     wdot: 0 average: 0  successful:  0  stability: 3.5272
>     qdot: 0 average: 0  successful:  0  stability: 3
>     Run Count: 1201
> 
> Soon afterwards, the entire sim locks up since the FDM numerics go
> wild. I can avoid this issue by suppressing the re-trim when replay
> has finished (by forcing "needTrim = false;" in the code). All works
> well for me then - but it completely kills the "needTrim" feature in
> JSBSim, which was probably implemented for a reason...
> The trim is triggered since the FDM still has its property listeners
> connected during replay - so it thinks the aircraft position changes,
> which sets the FDM's "needTrim" flag. Might be a good idea to
> disconnect the FDM property ties during a replay - but JSBSim
> currently doesn't allow to reconnect the ties ("bind" method is not
> implemented). And the basic problem here probably is just that
> something with re-trimming an aircraft doesn't work properly.
> 
> Any ideas on what could go wrong when the FDM tries to trim an already
> trimmed aircraft?
> 
> cheers,
> Thorsten
> 
> On Sun, Mar 20, 2011 at 12:48 PM, ThorstenB <bre...@gmail.com> wrote:
> > I'm seeing an issue with the "instant replay" feature which seems to affect
> > JSBSim aircraft. The actual replay works, but once replay is finished, the
> > sim locks up or goes wild when trying to resume normal flight. Looks to me
> > as if the FDM was somehow messed up by the replay. The FDM's update is
> > suspended during replay - but I suspect there may be an issue with the tied
> > properties, which still allow the FDM to see the replayed movements. YASim
> > aircraft seem to be fine though.
> 
> ------------------------------------------------------------------------------
> Colocation vs. Managed Hosting
> A question and answer guide to determining the best fit
> for your organization - today and in the future.
> http://p.sf.net/sfu/internap-sfd2d
> _______________________________________________
> Flightgear-devel mailing list
> Flightgear-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/flightgear-devel


diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx
index 0eb2188..e2d98b6 100644
--- a/src/FDM/JSBSim/JSBSim.cxx
+++ b/src/FDM/JSBSim/JSBSim.cxx
@@ -570,6 +570,22 @@ void FGJSBsim::update( double dt )
 
 /******************************************************************************/
 
+void FGJSBsim::suspend()
+{
+  fdmex->Hold();
+  SGSubsystem::suspend();
+}
+
+/******************************************************************************/
+
+void FGJSBsim::resume()
+{
+  fdmex->Resume();
+  SGSubsystem::resume();
+}
+
+/******************************************************************************/
+
 // Convert from the FGInterface struct to the JSBsim generic_ struct
 
 bool FGJSBsim::copy_to_JSBsim()
@@ -1011,7 +1027,9 @@ void FGJSBsim::set_Latitude(double lat)
     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET  );
     fgic->SetLatitudeRadIC( lat_geoc );
-    needTrim=true;
+
+    if (!fdmex->Holding())
+      needTrim=true;
 }
 
 
@@ -1024,7 +1042,9 @@ void FGJSBsim::set_Longitude(double lon)
 
     update_ic();
     fgic->SetLongitudeRadIC( lon );
-    needTrim=true;
+
+    if (!fdmex->Holding())
+      needTrim=true;
 }
 
 // Sets the altitude above sea level.
@@ -1049,7 +1069,9 @@ void FGJSBsim::set_Altitude(double alt)
           "Terrain elevation: " << FGInterface::get_Runway_altitude() * SG_METER_TO_FEET );
     fgic->SetLatitudeRadIC( lat_geoc );
     fgic->SetAltitudeASLFtIC(alt);
-    needTrim=true;
+
+    if (!fdmex->Holding())
+      needTrim=true;
 }
 
 void FGJSBsim::set_V_calibrated_kts(double vc)
@@ -1061,7 +1083,9 @@ void FGJSBsim::set_V_calibrated_kts(double vc)
 
     update_ic();
     fgic->SetVcalibratedKtsIC(vc);
-    needTrim=true;
+
+    if (!fdmex->Holding())
+      needTrim=true;
 }
 
 void FGJSBsim::set_Mach_number(double mach)
@@ -1073,7 +1097,9 @@ void FGJSBsim::set_Mach_number(double mach)
 
     update_ic();
     fgic->SetMachIC(mach);
-    needTrim=true;
+
+    if (!fdmex->Holding())
+      needTrim=true;
 }
 
 void FGJSBsim::set_Velocities_Local( double north, double east, double down )
@@ -1088,7 +1114,9 @@ void FGJSBsim::set_Velocities_Local( double north, double east, double down )
     fgic->SetVNorthFpsIC(north);
     fgic->SetVEastFpsIC(east);
     fgic->SetVDownFpsIC(down);
-    needTrim=true;
+
+    if (!fdmex->Holding())
+      needTrim=true;
 }
 
 void FGJSBsim::set_Velocities_Wind_Body( double u, double v, double w)
@@ -1103,7 +1131,9 @@ void FGJSBsim::set_Velocities_Wind_Body( double u, double v, double w)
     fgic->SetUBodyFpsIC(u);
     fgic->SetVBodyFpsIC(v);
     fgic->SetWBodyFpsIC(w);
-    needTrim=true;
+
+    if (!fdmex->Holding())
+      needTrim=true;
 }
 
 //Euler angles
@@ -1119,7 +1149,9 @@ void FGJSBsim::set_Euler_Angles( double phi, double theta, double psi )
     fgic->SetThetaRadIC(theta);
     fgic->SetPhiRadIC(phi);
     fgic->SetPsiRadIC(psi);
-    needTrim=true;
+
+    if (!fdmex->Holding())
+      needTrim=true;
 }
 
 //Flight Path
@@ -1137,7 +1169,9 @@ void FGJSBsim::set_Climb_Rate( double roc)
     if( !(fabs(roc) > 1 && fabs(fgic->GetFlightPathAngleRadIC()) < 0.01) ) {
       fgic->SetClimbRateFpsIC(roc);
     }
-    needTrim=true;
+
+    if (!fdmex->Holding())
+      needTrim=true;
 }
 
 void FGJSBsim::set_Gamma_vert_rad( double gamma)
@@ -1148,7 +1182,9 @@ void FGJSBsim::set_Gamma_vert_rad( double gamma)
     if( !(fabs(gamma) < 0.01 && fabs(fgic->GetClimbRateFpsIC()) > 1) ) {
       fgic->SetFlightPathAngleRadIC(gamma);
     }
-    needTrim=true;
+
+    if (!fdmex->Holding())
+      needTrim=true;
 }
 
 void FGJSBsim::init_gear(void )
diff --git a/src/FDM/JSBSim/JSBSim.hxx b/src/FDM/JSBSim/JSBSim.hxx
index a01146b..ca52f92 100644
--- a/src/FDM/JSBSim/JSBSim.hxx
+++ b/src/FDM/JSBSim/JSBSim.hxx
@@ -113,6 +113,12 @@ public:
     /// Unbind properties
     void unbind();
 
+    /// Suspend integration
+    void suspend();
+
+    /// Resume integration
+    void resume();
+
     /// @name Position Parameter Set
     //@{
     /** Set geocentric latitude
------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to