1 // JSBsim.cxx -- interface to the JSBsim flight model
3 // Written by Curtis Olson, started February 1999.
5 // Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <simgear/compiler.h>
26 #ifdef SG_MATH_EXCEPTION_CLASH
32 #include <simgear/constants.h>
33 #include <simgear/debug/logstream.hxx>
34 #include <simgear/math/sg_geodesy.hxx>
35 #include <simgear/misc/sg_path.hxx>
37 #include <Scenery/scenery.hxx>
39 #include <Aircraft/aircraft.hxx>
40 #include <Controls/controls.hxx>
41 #include <Main/globals.hxx>
42 #include <Main/fg_props.hxx>
44 #include <FDM/JSBSim/FGFDMExec.h>
45 #include <FDM/JSBSim/FGAircraft.h>
46 #include <FDM/JSBSim/FGFCS.h>
47 #include <FDM/JSBSim/FGPosition.h>
48 #include <FDM/JSBSim/FGRotation.h>
49 #include <FDM/JSBSim/FGState.h>
50 #include <FDM/JSBSim/FGTranslation.h>
51 #include <FDM/JSBSim/FGAuxiliary.h>
52 #include <FDM/JSBSim/FGInitialCondition.h>
53 #include <FDM/JSBSim/FGTrim.h>
54 #include <FDM/JSBSim/FGAtmosphere.h>
55 #include <FDM/JSBSim/FGMassBalance.h>
56 #include <FDM/JSBSim/FGAerodynamics.h>
57 #include <FDM/JSBSim/FGLGear.h>
60 /******************************************************************************/
62 FGJSBsim::FGJSBsim( double dt )
67 fdmex = new FGFDMExec;
69 State = fdmex->GetState();
70 Atmosphere = fdmex->GetAtmosphere();
71 FCS = fdmex->GetFCS();
72 MassBalance = fdmex->GetMassBalance();
73 Propulsion = fdmex->GetPropulsion();
74 Aircraft = fdmex->GetAircraft();
75 Translation = fdmex->GetTranslation();
76 Rotation = fdmex->GetRotation();
77 Position = fdmex->GetPosition();
78 Auxiliary = fdmex->GetAuxiliary();
79 Aerodynamics = fdmex->GetAerodynamics();
80 GroundReactions = fdmex->GetGroundReactions();
83 Atmosphere->UseInternal();
85 fgic=new FGInitialCondition(fdmex);
88 SGPath aircraft_path( globals->get_fg_root() );
89 aircraft_path.append( "Aircraft" );
91 SGPath engine_path( globals->get_fg_root() );
92 engine_path.append( "Engine" );
96 result = fdmex->LoadModel( aircraft_path.str(),
98 fgGetString("/sim/aero") );
101 SG_LOG( SG_FLIGHT, SG_INFO, " loaded aero.");
103 SG_LOG( SG_FLIGHT, SG_INFO,
104 " aero does not exist (you may have mis-typed the name).");
108 SG_LOG( SG_FLIGHT, SG_INFO, "" );
109 SG_LOG( SG_FLIGHT, SG_INFO, "" );
110 SG_LOG( SG_FLIGHT, SG_INFO, "After loading aero definition file ..." );
112 int Neng = Propulsion->GetNumEngines();
113 SG_LOG( SG_FLIGHT, SG_INFO, "num engines = " << Neng );
115 if ( GroundReactions->GetNumGearUnits() <= 0 ) {
116 SG_LOG( SG_FLIGHT, SG_ALERT, "num gear units = "
117 << GroundReactions->GetNumGearUnits() );
118 SG_LOG( SG_FLIGHT, SG_ALERT, "This is a very bad thing because with 0 gear units, the ground trimming");
119 SG_LOG( SG_FLIGHT, SG_ALERT, "routine (coming up later in the code) will core dump.");
120 SG_LOG( SG_FLIGHT, SG_ALERT, "Halting the sim now, and hoping a solution will present itself soon!");
127 // Set initial fuel levels if provided.
128 for (unsigned int i = 0; i < Propulsion->GetNumTanks(); i++) {
129 SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
130 if (node->getChild("level-gal_us", 0, false) != 0)
131 Propulsion->GetTank(i)
132 ->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
135 fgSetDouble("/fdm/trim/pitch-trim", FCS->GetPitchTrimCmd());
136 fgSetDouble("/fdm/trim/throttle", FCS->GetThrottleCmd(0));
137 fgSetDouble("/fdm/trim/aileron", FCS->GetDaCmd());
138 fgSetDouble("/fdm/trim/rudder", FCS->GetDrCmd());
140 startup_trim = fgGetNode("/sim/startup/trim", true);
142 trimmed = fgGetNode("/fdm/trim/trimmed", true);
143 trimmed->setBoolValue(false);
145 pitch_trim = fgGetNode("/fdm/trim/pitch-trim", true );
146 throttle_trim = fgGetNode("/fdm/trim/throttle", true );
147 aileron_trim = fgGetNode("/fdm/trim/aileron", true );
148 rudder_trim = fgGetNode("/fdm/trim/rudder", true );
151 stall_warning = fgGetNode("/sim/aero/alarms/stall-warning",true);
152 stall_warning->setDoubleValue(0);
155 /******************************************************************************/
156 FGJSBsim::~FGJSBsim(void) {
158 delete fdmex; fdmex=NULL;
159 delete fgic; fgic=NULL;
163 /******************************************************************************/
165 // Initialize the JSBsim flight model, dt is the time increment for
166 // each subsequent iteration through the EOM
168 void FGJSBsim::init() {
170 SG_LOG( SG_FLIGHT, SG_INFO, "Starting and initializing JSBsim" );
172 // Explicitly call the superclass's
173 // init method first.
177 fdmex->RunIC(fgic); //loop JSBSim once w/o integrating
178 copy_from_JSBsim(); //update the bus
180 SG_LOG( SG_FLIGHT, SG_INFO, " Initialized JSBSim with:" );
182 switch(fgic->GetSpeedSet()) {
184 SG_LOG(SG_FLIGHT,SG_INFO, " Vn,Ve,Vd= "
185 << Position->GetVn() << ", "
186 << Position->GetVe() << ", "
187 << Position->GetVd() << " ft/s");
190 SG_LOG(SG_FLIGHT,SG_INFO, " U,V,W= "
191 << Translation->GetUVW(1) << ", "
192 << Translation->GetUVW(2) << ", "
193 << Translation->GetUVW(3) << " ft/s");
196 SG_LOG(SG_FLIGHT,SG_INFO, " Mach: "
197 << Translation->GetMach() );
201 SG_LOG(SG_FLIGHT,SG_INFO, " Indicated Airspeed: "
202 << Auxiliary->GetVcalibratedKTS() << " knots" );
206 stall_warning->setDoubleValue(0);
208 SG_LOG( SG_FLIGHT, SG_INFO, " Bank Angle: "
209 << Rotation->Getphi()*RADTODEG << " deg" );
210 SG_LOG( SG_FLIGHT, SG_INFO, " Pitch Angle: "
211 << Rotation->Gettht()*RADTODEG << " deg" );
212 SG_LOG( SG_FLIGHT, SG_INFO, " True Heading: "
213 << Rotation->Getpsi()*RADTODEG << " deg" );
214 SG_LOG( SG_FLIGHT, SG_INFO, " Latitude: "
215 << Position->GetLatitude() << " deg" );
216 SG_LOG( SG_FLIGHT, SG_INFO, " Longitude: "
217 << Position->GetLongitude() << " deg" );
218 SG_LOG( SG_FLIGHT, SG_INFO, " Altitude: "
219 << Position->Geth() << " feet" );
220 SG_LOG( SG_FLIGHT, SG_INFO, " loaded initial conditions" );
222 SG_LOG( SG_FLIGHT, SG_INFO, " set dt" );
224 SG_LOG( SG_FLIGHT, SG_INFO, "Finished initializing JSBSim" );
226 SG_LOG( SG_FLIGHT, SG_INFO, "FGControls::get_gear_down()= " <<
227 globals->get_controls()->get_gear_down() );
233 /******************************************************************************/
235 // Run an iteration of the EOM (equations of motion)
238 FGJSBsim::update( int multiloop ) {
242 // double save_alt = 0.0;
246 trimmed->setBoolValue(false);
249 if ( startup_trim->getBoolValue() ) {
250 SG_LOG(SG_FLIGHT, SG_INFO,
251 "Ready to trim, terrain altitude is: "
252 << scenery.get_cur_elev() * SG_METER_TO_FEET );
253 SG_LOG( SG_FLIGHT, SG_INFO, "position = "
254 << fgGetDouble("/position/longitude-deg") << ", "
255 << fgGetDouble("/position/latitude-deg") );
256 fgic->SetTerrainAltitudeFtIC( scenery.get_cur_elev() * SG_METER_TO_FEET );
259 fdmex->RunIC(fgic); //apply any changes made through the set_ functions
264 for ( i=0; i < multiloop; i++ ) {
268 FGJSBBase::Message* msg;
269 while (fdmex->ReadMessage()) {
270 msg = fdmex->ProcessMessage();
272 case FGJSBBase::Message::eText:
273 SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text );
275 case FGJSBBase::Message::eBool:
276 SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text << " " << msg->bVal );
278 case FGJSBBase::Message::eInteger:
279 SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text << " " << msg->iVal );
281 case FGJSBBase::Message::eDouble:
282 SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text << " " << msg->dVal );
285 SG_LOG( SG_FLIGHT, SG_INFO, "Unrecognized message type." );
290 // translate JSBsim back to FG structure so that the
291 // autopilot (and the rest of the sim can use the updated values
295 /******************************************************************************/
297 // Convert from the FGInterface struct to the JSBsim generic_ struct
299 bool FGJSBsim::copy_to_JSBsim() {
302 // copy control positions into the JSBsim structure
304 FCS->SetDaCmd( globals->get_controls()->get_aileron());
305 FCS->SetRollTrimCmd( globals->get_controls()->get_aileron_trim() );
306 FCS->SetDeCmd( globals->get_controls()->get_elevator());
307 FCS->SetPitchTrimCmd( globals->get_controls()->get_elevator_trim() );
308 FCS->SetDrCmd( -globals->get_controls()->get_rudder() );
309 FCS->SetYawTrimCmd( -globals->get_controls()->get_rudder_trim() );
310 FCS->SetDfCmd( globals->get_controls()->get_flaps() );
311 FCS->SetDsbCmd( 0.0 ); //speedbrakes
312 FCS->SetDspCmd( 0.0 ); //spoilers
313 FCS->SetLBrake( globals->get_controls()->get_brake( 0 ) );
314 FCS->SetRBrake( globals->get_controls()->get_brake( 1 ) );
315 FCS->SetCBrake( globals->get_controls()->get_brake( 2 ) );
316 FCS->SetGearCmd( globals->get_controls()->get_gear_down());
317 for (i = 0; i < Propulsion->GetNumEngines(); i++) {
318 FGEngine * eng = Propulsion->GetEngine(i);
319 SGPropertyNode * node = fgGetNode("engines/engine", i, true);
320 FCS->SetThrottleCmd(i, globals->get_controls()->get_throttle(i));
321 FCS->SetMixtureCmd(i, globals->get_controls()->get_mixture(i));
322 FCS->SetPropAdvanceCmd(i, globals->get_controls()->get_prop_advance(i));
323 Propulsion->GetThruster(i)->SetRPM(node->getDoubleValue("rpm"));
324 eng->SetMagnetos( globals->get_controls()->get_magnetos(i) );
325 eng->SetStarter( globals->get_controls()->get_starter(i) );
328 _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET );
329 Position->SetSeaLevelRadius( get_Sea_level_radius() );
330 Position->SetRunwayRadius( get_Runway_altitude()
331 + get_Sea_level_radius() );
333 Atmosphere->SetExTemperature(get_Static_temperature());
334 Atmosphere->SetExPressure(get_Static_pressure());
335 Atmosphere->SetExDensity(get_Density());
336 Atmosphere->SetWindNED(get_V_north_airmass(),
337 get_V_east_airmass(),
338 get_V_down_airmass());
339 // SG_LOG(SG_FLIGHT,SG_INFO, "Wind NED: "
340 // << get_V_north_airmass() << ", "
341 // << get_V_east_airmass() << ", "
342 // << get_V_down_airmass() );
344 for (i = 0; i < Propulsion->GetNumTanks(); i++) {
345 SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
346 FGTank * tank = Propulsion->GetTank(i);
347 tank->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
348 // tank->SetContents(node->getDoubleValue("level-lb"));
354 /******************************************************************************/
356 // Convert from the JSBsim generic_ struct to the FGInterface struct
358 bool FGJSBsim::copy_from_JSBsim() {
361 _set_Inertias( MassBalance->GetMass(),
362 MassBalance->GetIxx(),
363 MassBalance->GetIyy(),
364 MassBalance->GetIzz(),
365 MassBalance->GetIxz() );
367 _set_CG_Position( MassBalance->GetXYZcg(1),
368 MassBalance->GetXYZcg(2),
369 MassBalance->GetXYZcg(3) );
371 _set_Accels_Body( Aircraft->GetBodyAccel()(1),
372 Aircraft->GetBodyAccel()(2),
373 Aircraft->GetBodyAccel()(3) );
375 //_set_Accels_CG_Body( Aircraft->GetBodyAccel()(1),
376 // Aircraft->GetBodyAccel()(2),
377 // Aircraft->GetBodyAccel()(3) );
379 _set_Accels_CG_Body_N ( Aircraft->GetNcg()(1),
380 Aircraft->GetNcg()(2),
381 Aircraft->GetNcg()(3) );
383 _set_Accels_Pilot_Body( Auxiliary->GetPilotAccel()(1),
384 Auxiliary->GetPilotAccel()(2),
385 Auxiliary->GetPilotAccel()(3) );
387 // _set_Accels_Pilot_Body_N( Auxiliary->GetPilotAccel()(1)/32.1739,
388 // Auxiliary->GetNpilot(2)/32.1739,
389 // Auxiliary->GetNpilot(3)/32.1739 );
391 _set_Nlf( Aircraft->GetNlf() );
395 _set_Velocities_Local( Position->GetVn(),
399 _set_Velocities_Wind_Body( Translation->GetUVW(1),
400 Translation->GetUVW(2),
401 Translation->GetUVW(3) );
403 _set_V_rel_wind( Translation->GetVt() );
405 _set_V_equiv_kts( Auxiliary->GetVequivalentKTS() );
407 // _set_V_calibrated( Auxiliary->GetVcalibratedFPS() );
409 _set_V_calibrated_kts( Auxiliary->GetVcalibratedKTS() );
411 _set_V_ground_speed( Position->GetVground() );
413 _set_Omega_Body( Rotation->GetPQR(1),
415 Rotation->GetPQR(3) );
417 _set_Euler_Rates( Rotation->GetEulerRates(1),
418 Rotation->GetEulerRates(2),
419 Rotation->GetEulerRates(3) );
421 _set_Geocentric_Rates(Position->GetLatitudeDot(),
422 Position->GetLongitudeDot(),
423 Position->Gethdot() );
425 _set_Mach_number( Translation->GetMach() );
428 _updateGeocentricPosition( Position->GetLatitude(),
429 Position->GetLongitude(),
432 _set_Altitude_AGL( Position->GetDistanceAGL() );
434 _set_Euler_Angles( Rotation->Getphi(),
436 Rotation->Getpsi() );
438 _set_Alpha( Translation->Getalpha() );
439 _set_Beta( Translation->Getbeta() );
442 _set_Gamma_vert_rad( Position->GetGamma() );
443 // set_Gamma_horiz_rad( Gamma_horiz_rad );
445 _set_Earth_position_angle( Auxiliary->GetEarthPositionAngle() );
447 _set_Climb_Rate( Position->Gethdot() );
450 for ( i = 1; i <= 3; i++ ) {
451 for ( j = 1; j <= 3; j++ ) {
452 _set_T_Local_to_Body( i, j, State->GetTl2b(i,j) );
456 // Copy the engine values from JSBSim.
457 for( i=0; i < Propulsion->GetNumEngines(); i++ ) {
458 SGPropertyNode * node = fgGetNode("engines/engine", i, true);
459 FGEngine * eng = Propulsion->GetEngine(i);
460 FGThruster * thrust = Propulsion->GetThruster(i);
462 node->setDoubleValue("mp-osi", eng->getManifoldPressure_inHg());
463 node->setDoubleValue("rpm", thrust->GetRPM());
464 node->setDoubleValue("egt-degf", eng->getExhaustGasTemp_degF());
465 node->setDoubleValue("fuel-flow-gph", eng->getFuelFlow_gph());
466 node->setDoubleValue("cht-degf", eng->getCylinderHeadTemp_degF());
467 node->setDoubleValue("oil-temperature-degf", eng->getOilTemp_degF());
468 node->setDoubleValue("oil-pressure-psi", eng->getOilPressure_psi());
469 node->setBoolValue("running", eng->GetRunning());
470 node->setBoolValue("cranking", eng->GetCranking());
473 static const SGPropertyNode *fuel_freeze
474 = fgGetNode("/sim/freeze/fuel");
476 // Copy the fuel levels from JSBSim if fuel
477 // freeze not enabled.
478 if ( ! fuel_freeze->getBoolValue() ) {
479 for (i = 0; i < Propulsion->GetNumTanks(); i++) {
480 SGPropertyNode * node
481 = fgGetNode("/consumables/fuel/tank", i, true);
482 double contents = Propulsion->GetTank(i)->GetContents();
483 node->setDoubleValue("level-gal_us", contents/6.6);
484 // node->setDoubleValue("level-lb", contents);
490 stall_warning->setDoubleValue( Aircraft->GetStallWarn() );
495 bool FGJSBsim::ToggleDataLogging(void) {
496 return fdmex->GetOutput()->Toggle();
500 bool FGJSBsim::ToggleDataLogging(bool state) {
502 fdmex->GetOutput()->Enable();
505 fdmex->GetOutput()->Disable();
512 void FGJSBsim::set_Latitude(double lat) {
513 static const SGPropertyNode *altitude = fgGetNode("/position/altitude-ft");
515 double sea_level_radius_meters, lat_geoc;
517 if ( altitude->getDoubleValue() > -9990 ) {
518 alt = altitude->getDoubleValue();
524 SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Latitude: " << lat );
525 SG_LOG(SG_FLIGHT,SG_INFO," cur alt (ft) = " << alt );
527 sgGeodToGeoc( lat, alt * SG_FEET_TO_METER,
528 &sea_level_radius_meters, &lat_geoc );
529 _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET );
530 fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
531 _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET );
532 fgic->SetTerrainAltitudeFtIC( scenery.get_cur_elev() * SG_METER_TO_FEET );
533 fgic->SetLatitudeRadIC( lat_geoc );
537 void FGJSBsim::set_Longitude(double lon) {
539 SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Longitude: " << lon );
541 fgic->SetLongitudeRadIC( lon );
542 _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET );
543 fgic->SetTerrainAltitudeFtIC( scenery.get_cur_elev() * SG_METER_TO_FEET );
547 void FGJSBsim::set_Altitude(double alt) {
548 static const SGPropertyNode *latitude = fgGetNode("/position/latitude-deg");
550 double sea_level_radius_meters,lat_geoc;
552 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Altitude: " << alt );
553 SG_LOG(SG_FLIGHT,SG_INFO, " lat (deg) = " << latitude->getDoubleValue() );
556 sgGeodToGeoc( latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS, alt,
557 &sea_level_radius_meters, &lat_geoc);
558 _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET );
559 fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
560 _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET );
561 fgic->SetTerrainAltitudeFtIC( scenery.get_cur_elev() * SG_METER_TO_FEET );
562 SG_LOG(SG_FLIGHT, SG_INFO,
563 "Terrain altitude: " << scenery.get_cur_elev() * SG_METER_TO_FEET );
564 SG_LOG( SG_FLIGHT, SG_INFO, "position = "
565 << fgGetDouble("/position/longitude-deg") << ", "
566 << fgGetDouble("/position/latitude-deg") );
567 fgic->SetLatitudeRadIC( lat_geoc );
568 fgic->SetAltitudeFtIC(alt);
572 void FGJSBsim::set_V_calibrated_kts(double vc) {
573 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_V_calibrated_kts: " << vc );
576 fgic->SetVcalibratedKtsIC(vc);
580 void FGJSBsim::set_Mach_number(double mach) {
581 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Mach_number: " << mach );
584 fgic->SetMachIC(mach);
588 void FGJSBsim::set_Velocities_Local( double north, double east, double down ){
589 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local: "
590 << north << ", " << east << ", " << down );
593 fgic->SetVnorthFpsIC(north);
594 fgic->SetVeastFpsIC(east);
595 fgic->SetVdownFpsIC(down);
599 void FGJSBsim::set_Velocities_Wind_Body( double u, double v, double w){
600 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Wind_Body: "
601 << u << ", " << v << ", " << w );
604 fgic->SetUBodyFpsIC(u);
605 fgic->SetVBodyFpsIC(v);
606 fgic->SetWBodyFpsIC(w);
611 void FGJSBsim::set_Euler_Angles( double phi, double theta, double psi ) {
612 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Euler_Angles: "
613 << phi << ", " << theta << ", " << psi );
616 fgic->SetPitchAngleRadIC(theta);
617 fgic->SetRollAngleRadIC(phi);
618 fgic->SetTrueHeadingRadIC(psi);
623 void FGJSBsim::set_Climb_Rate( double roc) {
624 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Climb_Rate: " << roc );
627 //since both climb rate and flight path angle are set in the FG
628 //startup sequence, something is needed to keep one from cancelling
630 if( !(fabs(roc) > 1 && fabs(fgic->GetFlightPathAngleRadIC()) < 0.01) ) {
631 fgic->SetClimbRateFpsIC(roc);
636 void FGJSBsim::set_Gamma_vert_rad( double gamma) {
637 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Gamma_vert_rad: " << gamma );
640 if( !(fabs(gamma) < 0.01 && fabs(fgic->GetClimbRateFpsIC()) > 1) ) {
641 fgic->SetFlightPathAngleRadIC(gamma);
646 void FGJSBsim::set_Static_pressure(double p) {
647 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_pressure: " << p );
650 Atmosphere->SetExPressure(p);
651 if(Atmosphere->External() == true)
655 void FGJSBsim::set_Static_temperature(double T) {
656 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_temperature: " << T );
658 Atmosphere->SetExTemperature(T);
659 if(Atmosphere->External() == true)
664 void FGJSBsim::set_Density(double rho) {
665 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Density: " << rho );
667 Atmosphere->SetExDensity(rho);
668 if(Atmosphere->External() == true)
672 void FGJSBsim::set_Velocities_Local_Airmass (double wnorth,
675 SG_LOG(SG_FLIGHT,SG_DEBUG, "FGJSBsim::set_Velocities_Local_Airmass: "
676 << wnorth << ", " << weast << ", " << wdown );
678 _set_Velocities_Local_Airmass( wnorth, weast, wdown );
679 fgic->SetWindNEDFpsIC( wnorth, weast, wdown );
680 if(Atmosphere->External() == true)
684 void FGJSBsim::init_gear(void ) {
686 FGGroundReactions* gr=fdmex->GetGroundReactions();
687 int Ngear=GroundReactions->GetNumGearUnits();
688 for (int i=0;i<Ngear;i++) {
689 SGPropertyNode * node = fgGetNode("gear/gear", i, true);
690 node->setDoubleValue("xoffset-in",
691 gr->GetGearUnit(i)->GetBodyLocation()(1));
692 node->setDoubleValue("yoffset-in",
693 gr->GetGearUnit(i)->GetBodyLocation()(2));
694 node->setDoubleValue("zoffset-in",
695 gr->GetGearUnit(i)->GetBodyLocation()(3));
696 node->setBoolValue("wow", gr->GetGearUnit(i)->GetWOW());
697 node->setBoolValue("has-brake", gr->GetGearUnit(i)->GetBrakeGroup() > 0);
698 node->setDoubleValue("position", FCS->GetGearPos());
702 void FGJSBsim::update_gear(void) {
704 FGGroundReactions* gr=fdmex->GetGroundReactions();
705 int Ngear=GroundReactions->GetNumGearUnits();
706 for (int i=0;i<Ngear;i++) {
707 SGPropertyNode * node = fgGetNode("gear/gear", i, true);
708 node->getChild("wow", 0, true)
709 ->setBoolValue(gr->GetGearUnit(i)->GetWOW());
710 node->getChild("position", 0, true)
711 ->setDoubleValue(FCS->GetGearPos());
715 void FGJSBsim::do_trim(void) {
718 if(fgic->GetVcalibratedKtsIC() < 10 ) {
719 fgic->SetVcalibratedKtsIC(0.0);
720 fgtrim=new FGTrim(fdmex,fgic,tGround);
722 fgtrim=new FGTrim(fdmex,fgic,tLongitudinal);
724 if( !fgtrim->DoTrim() ) {
728 trimmed->setBoolValue(true);
730 State->ReportState();
732 pitch_trim->setDoubleValue( FCS->GetPitchTrimCmd() );
733 throttle_trim->setDoubleValue( FCS->GetThrottleCmd(0) );
734 aileron_trim->setDoubleValue( FCS->GetDaCmd() );
735 rudder_trim->setDoubleValue( FCS->GetDrCmd() );
737 globals->get_controls()->set_elevator_trim(FCS->GetPitchTrimCmd());
738 globals->get_controls()->set_elevator(FCS->GetDeCmd());
739 globals->get_controls()->set_throttle(FGControls::ALL_ENGINES,
740 FCS->GetThrottleCmd(0));
742 globals->get_controls()->set_aileron(FCS->GetDaCmd());
743 globals->get_controls()->set_rudder( FCS->GetDrCmd());
745 SG_LOG( SG_FLIGHT, SG_INFO, " Trim complete" );
748 void FGJSBsim::update_ic(void) {
750 fgic->SetLatitudeRadIC(get_Lat_geocentric() );
751 fgic->SetLongitudeRadIC( get_Longitude() );
752 fgic->SetAltitudeFtIC( get_Altitude() );
753 fgic->SetVcalibratedKtsIC( get_V_calibrated_kts() );
754 fgic->SetPitchAngleRadIC( get_Theta() );
755 fgic->SetRollAngleRadIC( get_Phi() );
756 fgic->SetTrueHeadingRadIC( get_Psi() );
757 fgic->SetClimbRateFpsIC( get_Climb_Rate() );