]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/JSBSim.cxx
JSBSim updates. This update changes the file format, so an update of the base
[flightgear.git] / src / FDM / JSBSim / JSBSim.cxx
index 27b40ab83f7acc82d9aa246dfb3fb2153b8ad832..1fbc7b05452a8eb0081c5a8bfd89a314934a835d 100644 (file)
@@ -34,7 +34,7 @@
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/sg_path.hxx>
 
-#include <Scenery/scenery.hxx>
+#include <FDM/flight.hxx>
 
 #include <Aircraft/aircraft.hxx>
 #include <Controls/controls.hxx>
@@ -85,12 +85,9 @@ FGJSBsim::FGJSBsim( double dt )
     Position        = fdmex->GetPosition();
     Auxiliary       = fdmex->GetAuxiliary();
     Aerodynamics    = fdmex->GetAerodynamics();
-    GroundReactions = fdmex->GetGroundReactions();  
-  
-    
-    Atmosphere->UseInternal();
+    GroundReactions = fdmex->GetGroundReactions(); 
     
-    fgic=new FGInitialCondition(fdmex);
+    fgic=fdmex->GetIC();
     needTrim=true;
   
     SGPath aircraft_path( globals->get_fg_root() );
@@ -98,7 +95,6 @@ FGJSBsim::FGJSBsim( double dt )
 
     SGPath engine_path( globals->get_fg_root() );
     engine_path.append( "Engine" );
-    set_delta_t( dt );
     State->Setdt( dt );
 
     result = fdmex->LoadModel( aircraft_path.str(),
@@ -176,6 +172,14 @@ FGJSBsim::FGJSBsim( double dt )
     rudder_pos_pct->setDoubleValue(0);
     flap_pos_pct->setDoubleValue(0);
 
+    temperature = fgGetNode("/environment/temperature-degc",true);
+    pressure = fgGetNode("/environment/pressure-inhg",true);
+    density = fgGetNode("/environment/density-slugft3",true);
+    
+    wind_from_north= fgGetNode("/environment/wind-from-north-fps",true);
+    wind_from_east = fgGetNode("/environment/wind-from-east-fps" ,true);
+    wind_from_down = fgGetNode("/environment/wind-from-down-fps" ,true);
+     
 
 }
 /******************************************************************************/
@@ -194,13 +198,40 @@ FGJSBsim::~FGJSBsim(void) {
 void FGJSBsim::init() {
     
     SG_LOG( SG_FLIGHT, SG_INFO, "Starting and initializing JSBsim" );
-   
+
     // Explicitly call the superclass's
     // init method first.
+
+#ifdef FG_WEATHERCM
+    Atmosphere->UseInternal();
+#else
+    if (fgGetBool("/environment/params/control-fdm-atmosphere")) {
+      Atmosphere->UseExternal();
+      Atmosphere->SetExTemperature(
+                  9.0/5.0*(temperature->getDoubleValue()+273.15) );
+      Atmosphere->SetExPressure(pressure->getDoubleValue()*70.726566);
+      Atmosphere->SetExDensity(density->getDoubleValue());
+    } else {
+      Atmosphere->UseInternal();
+    }
+#endif
+    
+    fgic->SetVnorthFpsIC( wind_from_north->getDoubleValue() );
+    fgic->SetVeastFpsIC( wind_from_east->getDoubleValue() );
+    fgic->SetVdownFpsIC( wind_from_down->getDoubleValue() );
+
+    //Atmosphere->SetExTemperature(get_Static_temperature());
+    //Atmosphere->SetExPressure(get_Static_pressure());
+    //Atmosphere->SetExDensity(get_Density());
+    SG_LOG(SG_FLIGHT,SG_INFO,"T,p,rho: " << fdmex->GetAtmosphere()->GetTemperature()
+     << ", " << fdmex->GetAtmosphere()->GetPressure() 
+     << ", " << fdmex->GetAtmosphere()->GetDensity() );
+
     common_init();
     copy_to_JSBsim();
+    
 
-    fdmex->RunIC(fgic); //loop JSBSim once w/o integrating
+    fdmex->RunIC(); //loop JSBSim once w/o integrating
     copy_from_JSBsim(); //update the bus
 
     SG_LOG( SG_FLIGHT, SG_INFO, "  Initialized JSBSim with:" );
@@ -261,7 +292,12 @@ void FGJSBsim::init() {
 // Run an iteration of the EOM (equations of motion)
 
 void
-FGJSBsim::update( int multiloop ) {
+FGJSBsim::update( double dt ) {
+
+    if (is_suspended())
+      return;
+
+    int multiloop = _calc_multiloop(dt);
 
     int i;
 
@@ -271,17 +307,15 @@ FGJSBsim::update( int multiloop ) {
 
     trimmed->setBoolValue(false);
     
-
-    
     if ( needTrim ) {
       if ( startup_trim->getBoolValue() ) {
         SG_LOG(SG_FLIGHT, SG_INFO,
           "Ready to trim, terrain altitude is: " 
-            << scenery.get_cur_elev() * SG_METER_TO_FEET );
-        fgic->SetTerrainAltitudeFtIC( scenery.get_cur_elev() * SG_METER_TO_FEET );
+            << cur_fdm_state->get_Runway_altitude() * SG_METER_TO_FEET );
+        fgic->SetTerrainAltitudeFtIC( cur_fdm_state->get_ground_elev_ft() );
         do_trim();
       } else {
-        fdmex->RunIC(fgic);  //apply any changes made through the set_ functions
+        fdmex->RunIC();  //apply any changes made through the set_ functions
       }
       needTrim = false;  
     }    
@@ -355,17 +389,19 @@ bool FGJSBsim::copy_to_JSBsim() {
       eng->SetStarter( globals->get_controls()->get_starter(i) );
     }
 
-    _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET );
+    _set_Runway_altitude( cur_fdm_state->get_Runway_altitude() );
     Position->SetSeaLevelRadius( get_Sea_level_radius() );
     Position->SetRunwayRadius( get_Runway_altitude() 
                                + get_Sea_level_radius() );
 
-    Atmosphere->SetExTemperature(get_Static_temperature());
-    Atmosphere->SetExPressure(get_Static_pressure());
-    Atmosphere->SetExDensity(get_Density());
-    Atmosphere->SetWindNED(get_V_north_airmass(),
-                           get_V_east_airmass(),
-                           get_V_down_airmass());
+    Atmosphere->SetExTemperature(
+                  9.0/5.0*(temperature->getDoubleValue()+273.15) );
+    Atmosphere->SetExPressure(pressure->getDoubleValue()*70.726566);
+    Atmosphere->SetExDensity(density->getDoubleValue());
+
+    Atmosphere->SetWindNED( wind_from_north->getDoubleValue(),
+                            wind_from_east->getDoubleValue(),
+                            wind_from_down->getDoubleValue() );
 //    SG_LOG(SG_FLIGHT,SG_INFO, "Wind NED: "
 //                  << get_V_north_airmass() << ", "
 //                  << get_V_east_airmass()  << ", "
@@ -517,7 +553,7 @@ bool FGJSBsim::copy_from_JSBsim() {
 
     update_gear();
     
-    stall_warning->setDoubleValue( Aircraft->GetStallWarn() );
+    stall_warning->setDoubleValue( Aerodynamics->GetStallWarn() );
     
     /* elevator_pos_deg->setDoubleValue( FCS->GetDePos()*SG_RADIANS_TO_DEGREES );
     left_aileron_pos_deg->setDoubleValue( FCS->GetDaLPos()*SG_RADIANS_TO_DEGREES );
@@ -529,7 +565,7 @@ bool FGJSBsim::copy_from_JSBsim() {
     elevator_pos_pct->setDoubleValue( FCS->GetDePos(ofNorm) );
     left_aileron_pos_pct->setDoubleValue( FCS->GetDaLPos(ofNorm) );
     right_aileron_pos_pct->setDoubleValue( -1*FCS->GetDaLPos(ofNorm) );
-    rudder_pos_pct->setDoubleValue( FCS->GetDrPos(ofNorm) );
+    rudder_pos_pct->setDoubleValue( -1*FCS->GetDrPos(ofNorm) );
     flap_pos_pct->setDoubleValue( FCS->GetDfPos(ofNorm) );
 
     
@@ -572,8 +608,8 @@ void FGJSBsim::set_Latitude(double lat) {
                       &sea_level_radius_meters, &lat_geoc );
     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET  );    
-    _set_Runway_altitude(  scenery.get_cur_elev() * SG_METER_TO_FEET  );
-    fgic->SetTerrainAltitudeFtIC( scenery.get_cur_elev() * SG_METER_TO_FEET  );
+    _set_Runway_altitude( cur_fdm_state->get_Runway_altitude() );
+    fgic->SetTerrainAltitudeFtIC( cur_fdm_state->get_ground_elev_ft() );
     fgic->SetLatitudeRadIC( lat_geoc );
     needTrim=true;
 }
@@ -583,8 +619,8 @@ void FGJSBsim::set_Longitude(double lon) {
     SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Longitude: " << lon );
     update_ic();
     fgic->SetLongitudeRadIC( lon );
-    _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET  );
-    fgic->SetTerrainAltitudeFtIC( scenery.get_cur_elev() * SG_METER_TO_FEET  );
+    _set_Runway_altitude( cur_fdm_state->get_Runway_altitude() );
+    fgic->SetTerrainAltitudeFtIC( cur_fdm_state->get_ground_elev_ft() );
     needTrim=true;
 }
 
@@ -601,10 +637,10 @@ void FGJSBsim::set_Altitude(double alt) {
                   &sea_level_radius_meters, &lat_geoc);
     _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET  );
     fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
-    _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET  );
-    fgic->SetTerrainAltitudeFtIC( scenery.get_cur_elev() * SG_METER_TO_FEET  );
+    _set_Runway_altitude( cur_fdm_state->get_Runway_altitude() );
+    fgic->SetTerrainAltitudeFtIC( cur_fdm_state->get_ground_elev_ft() );
     SG_LOG(SG_FLIGHT, SG_INFO,
-          "Terrain altitude: " << scenery.get_cur_elev() * SG_METER_TO_FEET );
+          "Terrain altitude: " << cur_fdm_state->get_Runway_altitude() * SG_METER_TO_FEET );
     fgic->SetLatitudeRadIC( lat_geoc );
     fgic->SetAltitudeFtIC(alt);
     needTrim=true;
@@ -684,44 +720,6 @@ void FGJSBsim::set_Gamma_vert_rad( double gamma) {
     needTrim=true;
 }
 
-void FGJSBsim::set_Static_pressure(double p) {
-    SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_pressure: " << p );
-    
-    update_ic();
-    Atmosphere->SetExPressure(p);
-    if(Atmosphere->External() == true)
-      needTrim=true;
-}
-
-void FGJSBsim::set_Static_temperature(double T) {
-    SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_temperature: " << T );
-    
-    Atmosphere->SetExTemperature(T);
-    if(Atmosphere->External() == true)
-      needTrim=true;
-}
-
-void FGJSBsim::set_Density(double rho) {
-    SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Density: " << rho );
-    
-    Atmosphere->SetExDensity(rho);
-    if(Atmosphere->External() == true)
-      needTrim=true;
-}
-  
-void FGJSBsim::set_Velocities_Local_Airmass (double wnorth, 
-                         double weast, 
-                         double wdown ) {
-    //SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local_Airmass: " 
-    //   << wnorth << ", " << weast << ", " << wdown );
-    
-    _set_Velocities_Local_Airmass( wnorth, weast, wdown );
-    fgic->SetWindNEDFpsIC( wnorth, weast, wdown );
-    if(Atmosphere->External() == true)
-        needTrim=true;
-}     
-
 void FGJSBsim::init_gear(void ) {
     
     FGGroundReactions* gr=fdmex->GetGroundReactions();
@@ -756,11 +754,11 @@ void FGJSBsim::update_gear(void) {
 void FGJSBsim::do_trim(void) {
 
         FGTrim *fgtrim;
-        if(fgic->GetVcalibratedKtsIC() < 10 ) {
+        if( fgGetBool("/sim/startup/onground") ) {
             fgic->SetVcalibratedKtsIC(0.0);
-            fgtrim=new FGTrim(fdmex,fgic,tGround);
+            fgtrim=new FGTrim(fdmex,tGround);
         } else {
-            fgtrim=new FGTrim(fdmex,fgic,tLongitudinal);
+            fgtrim=new FGTrim(fdmex,tLongitudinal);
         }
         if( !fgtrim->DoTrim() ) {
             fgtrim->Report();