]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim.cxx
JSBSim updates.
[flightgear.git] / src / FDM / JSBSim.cxx
index 183669eada360e811873c816b202b6fc9cd8acc9..b3303625e1b8d3a62b561cadcbdf9543b396620e 100644 (file)
 #include <Controls/controls.hxx>
 #include <Main/options.hxx>
 
-#include <FDM/JSBsim/FGFDMExec.h>
-#include <FDM/JSBsim/FGAircraft.h>
-#include <FDM/JSBsim/FGFCS.h>
-#include <FDM/JSBsim/FGPosition.h>
-#include <FDM/JSBsim/FGRotation.h>
-#include <FDM/JSBsim/FGState.h>
-#include <FDM/JSBsim/FGTranslation.h>
-#include <FDM/JSBsim/FGAuxiliary.h>
-#include <FDM/JSBsim/FGDefs.h>
-#include <FDM/JSBsim/FGInitialCondition.h>
-#include <FDM/JSBsim/FGTrimLong.h>
-#include <FDM/JSBsim/FGAtmosphere.h>
-
-#include "JSBsim.hxx"
+#include <FDM/JSBSim/FGFDMExec.h>
+#include <FDM/JSBSim/FGAircraft.h>
+#include <FDM/JSBSim/FGFCS.h>
+#include <FDM/JSBSim/FGPosition.h>
+#include <FDM/JSBSim/FGRotation.h>
+#include <FDM/JSBSim/FGState.h>
+#include <FDM/JSBSim/FGTranslation.h>
+#include <FDM/JSBSim/FGAuxiliary.h>
+#include <FDM/JSBSim/FGDefs.h>
+#include <FDM/JSBSim/FGInitialCondition.h>
+#include <FDM/JSBSim/FGTrimLong.h>
+#include <FDM/JSBSim/FGAtmosphere.h>
+
+#include "JSBSim.hxx"
 
 /******************************************************************************/
 
@@ -62,7 +62,7 @@
 
 int FGJSBsim::init( double dt ) {
 
-
+  bool result;
 
   FG_LOG( FG_FLIGHT, FG_INFO, "Starting and initializing JSBsim" );
   FG_LOG( FG_FLIGHT, FG_INFO, "  created FDMExec" );
@@ -75,16 +75,21 @@ int FGJSBsim::init( double dt ) {
 
   FDMExec.GetState()->Setdt( dt );
 
-  FDMExec.GetAircraft()->LoadAircraft( aircraft_path.str(),
+  result = FDMExec.GetAircraft()->LoadAircraft( aircraft_path.str(),
                                        engine_path.str(),
                                        current_options.get_aircraft() );
 
-  FG_LOG( FG_FLIGHT, FG_INFO, "  loaded aircraft" <<
-          current_options.get_aircraft() );
+  if (result) {
+    FG_LOG( FG_FLIGHT, FG_INFO, "  loaded aircraft" << current_options.get_aircraft() );
+  } else {
+    FG_LOG( FG_FLIGHT, FG_INFO, "  aircraft" << current_options.get_aircraft()
+                                << " does not exist");
+    return 0;
+  }
 
   FDMExec.GetAtmosphere()->UseInternal();
 
-  FG_LOG( FG_FLIGHT, FG_INFO, "  Initializing JSBsim with:" );
+  FG_LOG( FG_FLIGHT, FG_INFO, "  Initializing JSBSim with:" );
 
   FGInitialCondition *fgic = new FGInitialCondition(&FDMExec);
   fgic->SetAltitudeFtIC(get_Altitude());
@@ -109,10 +114,12 @@ int FGJSBsim::init( double dt ) {
   fgic->SetRollAngleRadIC(get_Phi());
   fgic->SetPitchAngleRadIC(get_Theta());
   fgic->SetHeadingRadIC(get_Psi());
-  fgic->SetLatitudeRadIC(get_Latitude());
+//  fgic->SetLatitudeRadIC(get_Latitude());
+  fgic->SetLatitudeRadIC(get_Lat_geocentric());
   fgic->SetLongitudeRadIC(get_Longitude());
 
-  FDMExec.GetPosition()->SetRunwayRadius(scenery.cur_radius);
+  FDMExec.GetPosition()->SetRunwayRadius(scenery.cur_radius*METER_TO_FEET);
+  FDMExec.GetPosition()->SetSeaLevelRadius(get_Sea_level_radius());
 
   FG_LOG( FG_FLIGHT, FG_INFO, "  phi: " <<  get_Phi());
   FG_LOG( FG_FLIGHT, FG_INFO, "  theta: " <<  get_Theta() );
@@ -121,7 +128,9 @@ int FGJSBsim::init( double dt ) {
   FG_LOG( FG_FLIGHT, FG_INFO, "  lon: " <<  get_Longitude() );
   FG_LOG( FG_FLIGHT, FG_INFO, "  alt: " <<  get_Altitude() );
 
-  if(current_options.get_trim_mode() == true) {
+  //must check > 0, != 0 will give bad result if --notrim set
+  if(current_options.get_trim_mode() > 0) {
+    FDMExec.RunIC(fgic);
     FG_LOG( FG_FLIGHT, FG_INFO, "  Starting trim..." );
     FGTrimLong *fgtrim=new FGTrimLong(&FDMExec,fgic);
     fgtrim->DoTrim();
@@ -129,13 +138,11 @@ int FGJSBsim::init( double dt ) {
     fgtrim->TrimStats();
     fgtrim->ReportState();
 
-    controls.set_elevator_trim(FDMExec.GetFCS()->GetDeCmd());
-    controls.set_trimmed_throttle(FGControls::ALL_ENGINES,FDMExec.GetFCS()->GetThrottleCmd(0)/100);
+    controls.set_elevator_trim(FDMExec.GetFCS()->GetPitchTrimCmd());
+    controls.set_throttle(FGControls::ALL_ENGINES,FDMExec.GetFCS()->GetThrottleCmd(0)/100);
     //the trimming routine only knows how to get 1 value for throttle
 
-    //for(int i=0;i<FDMExec.GetAircraft()->GetNumEngines();i++) {
-    //  controls.set_throttle(i,FDMExec.GetFCS()->GetThrottleCmd(i)/100);
-    //}
+    
     delete fgtrim;
     FG_LOG( FG_FLIGHT, FG_INFO, "  Trim complete." );
   } else {
@@ -150,7 +157,7 @@ int FGJSBsim::init( double dt ) {
 
   FG_LOG( FG_FLIGHT, FG_INFO, "  set dt" );
 
-  FG_LOG( FG_FLIGHT, FG_INFO, "Finished initializing JSBsim" );
+  FG_LOG( FG_FLIGHT, FG_INFO, "Finished initializing JSBSim" );
 
   copy_from_JSBsim();
 
@@ -179,8 +186,8 @@ int FGJSBsim::update( int multiloop ) {
   FDMExec.GetFCS()->SetPitchTrimCmd(controls.get_elevator_trim());
   FDMExec.GetFCS()->SetDrCmd( controls.get_rudder());
   FDMExec.GetFCS()->SetDfCmd( controls.get_flaps() );
-  FDMExec.GetFCS()->SetDsbCmd( 0.0 );
-  FDMExec.GetFCS()->SetDspCmd( 0.0 );
+  FDMExec.GetFCS()->SetDsbCmd( 0.0 ); //speedbrakes
+  FDMExec.GetFCS()->SetDspCmd( 0.0 ); //spoilers
   FDMExec.GetFCS()->SetThrottleCmd( FGControls::ALL_ENGINES,
                                     controls.get_throttle( 0 ) * 100.0 );
 
@@ -188,7 +195,8 @@ int FGJSBsim::update( int multiloop ) {
 
   // Inform JSBsim of the local terrain altitude; uncommented 5/3/00
   //  FDMExec.GetPosition()->SetRunwayElevation(get_Runway_altitude()); // seems to work
-  FDMExec.GetPosition()->SetRunwayRadius(scenery.cur_radius);
+  FDMExec.GetPosition()->SetRunwayRadius(scenery.cur_radius*METER_TO_FEET);
+  FDMExec.GetPosition()->SetSeaLevelRadius(get_Sea_level_radius());
 
   FDMExec.GetAtmosphere()->SetExTemperature(get_Static_temperature());
   FDMExec.GetAtmosphere()->SetExPressure(get_Static_pressure());
@@ -216,10 +224,10 @@ int FGJSBsim::update( int multiloop ) {
   }
 
   double end_elev = get_Altitude();
-  if ( time_step > 0.0 ) {
+  //if ( time_step > 0.0 ) {
     // feet per second
-    set_Climb_Rate( (end_elev - start_elev) / time_step );
-  }
+  //  set_Climb_Rate( (end_elev - start_elev) / time_step );
+  //}
 
   return 1;
 }
@@ -238,23 +246,65 @@ int FGJSBsim::copy_to_JSBsim() {
 
 int FGJSBsim::copy_from_JSBsim() {
 
+  set_Inertias( FDMExec.GetAircraft()->GetMass(),
+                FDMExec.GetAircraft()->GetIxx(),
+                FDMExec.GetAircraft()->GetIyy(),
+                FDMExec.GetAircraft()->GetIzz(),
+                FDMExec.GetAircraft()->GetIxz() );
+  
+  set_CG_Position ( FDMExec.GetAircraft()->GetXYZcg()(1),
+                    FDMExec.GetAircraft()->GetXYZcg()(2),
+                    FDMExec.GetAircraft()->GetXYZcg()(3) );
+  
+  set_Accels_Body ( FDMExec.GetTranslation()->GetUVWdot()(1),
+                    FDMExec.GetTranslation()->GetUVWdot()(2),
+                    FDMExec.GetTranslation()->GetUVWdot()(3) );
+  
+  set_Accels_CG_Body ( FDMExec.GetTranslation()->GetUVWdot()(1),
+                       FDMExec.GetTranslation()->GetUVWdot()(2),
+                       FDMExec.GetTranslation()->GetUVWdot()(3) );
+  
+  set_Accels_CG_Body_N ( FDMExec.GetTranslation()->GetNcg()(1),
+                         FDMExec.GetTranslation()->GetNcg()(2),
+                         FDMExec.GetTranslation()->GetNcg()(3) );
+  
+  set_Accels_Pilot_Body( FDMExec.GetAuxiliary()->GetPilotAccel()(1),
+                         FDMExec.GetAuxiliary()->GetPilotAccel()(2),
+                         FDMExec.GetAuxiliary()->GetPilotAccel()(3) );
+  
+  set_Accels_Pilot_Body_N( FDMExec.GetAuxiliary()->GetNpilot()(1),
+                           FDMExec.GetAuxiliary()->GetNpilot()(2),
+                           FDMExec.GetAuxiliary()->GetNpilot()(3) );
+  
+                           
+  
+  set_Nlf( FDMExec.GetAircraft()->GetNlf());                       
+  
+  
+   
   // Velocities
 
   set_Velocities_Local( FDMExec.GetPosition()->GetVn(),
                         FDMExec.GetPosition()->GetVe(),
                         FDMExec.GetPosition()->GetVd() );
 
+  set_Velocities_Wind_Body( FDMExec.GetTranslation()->GetUVW()(1),
+                            FDMExec.GetTranslation()->GetUVW()(2),
+                            FDMExec.GetTranslation()->GetUVW()(3)  );
+  
   set_V_equiv_kts( FDMExec.GetAuxiliary()->GetVequivalentKTS() );
 
   //set_V_calibrated( FDMExec.GetAuxiliary()->GetVcalibratedFPS() );
 
   set_V_calibrated_kts( FDMExec.GetAuxiliary()->GetVcalibratedKTS() );
+  
+  set_V_ground_speed ( FDMExec.GetPosition()->GetVground() );
 
   set_Omega_Body( FDMExec.GetState()->GetParameter(FG_ROLLRATE),
                   FDMExec.GetState()->GetParameter(FG_PITCHRATE),
                   FDMExec.GetState()->GetParameter(FG_YAWRATE) );
 
-  set_Euler_Rates( FDMExec.GetRotation()->Getphi(),
+  /* HUH!?! */ set_Euler_Rates( FDMExec.GetRotation()->Getphi(),
                    FDMExec.GetRotation()->Gettht(),
                    FDMExec.GetRotation()->Getpsi() );
 
@@ -302,9 +352,8 @@ int FGJSBsim::copy_from_JSBsim() {
   set_cos_lat_geocentric( lat_geoc );
   set_sin_cos_longitude( lon );
   set_sin_cos_latitude( lat_geod );
+  
+  set_Climb_Rate(FDMExec.GetPosition()->Gethdot());
 
   return 1;
 }
-
-/******************************************************************************/
-