// $Id$
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
#include <simgear/compiler.h>
#ifdef SG_MATH_EXCEPTION_CLASH
#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>
#include <FDM/JSBSim/FGPropertyManager.h>
#include "JSBSim.hxx"
+static inline double
+FMAX (double a, double b)
+{
+ return a > b ? a : b;
+}
+
+
/******************************************************************************/
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() );
SGPath engine_path( globals->get_fg_root() );
engine_path.append( "Engine" );
- set_delta_t( dt );
State->Setdt( dt );
result = fdmex->LoadModel( aircraft_path.str(),
fgSetDouble("/fdm/trim/aileron", FCS->GetDaCmd());
fgSetDouble("/fdm/trim/rudder", FCS->GetDrCmd());
- startup_trim = fgGetNode("/sim/startup/trim", true);
+ startup_trim = fgGetNode("/sim/presets/trim", true);
trimmed = fgGetNode("/fdm/trim/trimmed", true);
trimmed->setBoolValue(false);
aileron_trim = fgGetNode("/fdm/trim/aileron", true );
rudder_trim = fgGetNode("/fdm/trim/rudder", true );
-
- stall_warning = fgGetNode("/sim/aero/alarms/stall-warning",true);
+ stall_warning = fgGetNode("/sim/alarms/stall-warning",true);
stall_warning->setDoubleValue(0);
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);
+ turbulence = fgGetNode("environment/turbulence-norm",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);
+
}
/******************************************************************************/
FGJSBsim::~FGJSBsim(void) {
- if (fdmex != NULL) {
- delete fdmex; fdmex=NULL;
- delete fgic; fgic=NULL;
- }
+ delete fdmex;
}
/******************************************************************************/
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());
+ Atmosphere->SetTurbGain(turbulence->getDoubleValue() *
+ turbulence->getDoubleValue() *
+ 100.0);
+ } 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:" );
// 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;
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;
}
FCS->SetDfCmd( globals->get_controls()->get_flaps() );
FCS->SetDsbCmd( 0.0 ); //speedbrakes
FCS->SetDspCmd( 0.0 ); //spoilers
- FCS->SetLBrake( globals->get_controls()->get_brake( 0 ) );
- FCS->SetRBrake( globals->get_controls()->get_brake( 1 ) );
+
+ // Parking brake sets minimum braking
+ // level for mains.
+ double parking_brake = globals->get_controls()->get_parking_brake();
+ FCS->SetLBrake(FMAX(globals->get_controls()->get_brake(0), parking_brake));
+ FCS->SetRBrake(FMAX(globals->get_controls()->get_brake(1), parking_brake));
FCS->SetCBrake( globals->get_controls()->get_brake( 2 ) );
+
FCS->SetGearCmd( globals->get_controls()->get_gear_down());
for (i = 0; i < Propulsion->GetNumEngines(); i++) {
FGEngine * eng = Propulsion->GetEngine(i);
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->SetTurbGain(turbulence->getDoubleValue() *
+ turbulence->getDoubleValue() *
+ 100.0);
+
+ 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() << ", "
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 );
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) );
&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;
}
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;
}
&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;
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();
void FGJSBsim::do_trim(void) {
FGTrim *fgtrim;
- if(fgic->GetVcalibratedKtsIC() < 10 ) {
+ if( fgGetBool("/sim/presets/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();
fgic->SetClimbRateFpsIC( get_Climb_Rate() );
}
}
+