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>
58 #include <FDM/JSBSim/FGPropertyManager.h>
62 FMAX (double a, double b)
68 /******************************************************************************/
70 FGJSBsim::FGJSBsim( double dt )
75 fdmex = new FGFDMExec( (FGPropertyManager*)globals->get_props() );
77 State = fdmex->GetState();
78 Atmosphere = fdmex->GetAtmosphere();
79 FCS = fdmex->GetFCS();
80 MassBalance = fdmex->GetMassBalance();
81 Propulsion = fdmex->GetPropulsion();
82 Aircraft = fdmex->GetAircraft();
83 Translation = fdmex->GetTranslation();
84 Rotation = fdmex->GetRotation();
85 Position = fdmex->GetPosition();
86 Auxiliary = fdmex->GetAuxiliary();
87 Aerodynamics = fdmex->GetAerodynamics();
88 GroundReactions = fdmex->GetGroundReactions();
91 Atmosphere->UseInternal();
93 if (fgGetBool("/environment/params/control-fdm-atmosphere")) {
94 Atmosphere->UseExternal();
95 Atmosphere->SetExTemperature(get_Static_temperature());
96 Atmosphere->SetExPressure(get_Static_pressure());
97 Atmosphere->SetExDensity(get_Density());
99 Atmosphere->UseInternal();
103 fgic=new FGInitialCondition(fdmex);
106 SGPath aircraft_path( globals->get_fg_root() );
107 aircraft_path.append( "Aircraft" );
109 SGPath engine_path( globals->get_fg_root() );
110 engine_path.append( "Engine" );
113 result = fdmex->LoadModel( aircraft_path.str(),
115 fgGetString("/sim/aero") );
118 SG_LOG( SG_FLIGHT, SG_INFO, " loaded aero.");
120 SG_LOG( SG_FLIGHT, SG_INFO,
121 " aero does not exist (you may have mis-typed the name).");
125 SG_LOG( SG_FLIGHT, SG_INFO, "" );
126 SG_LOG( SG_FLIGHT, SG_INFO, "" );
127 SG_LOG( SG_FLIGHT, SG_INFO, "After loading aero definition file ..." );
129 int Neng = Propulsion->GetNumEngines();
130 SG_LOG( SG_FLIGHT, SG_INFO, "num engines = " << Neng );
132 if ( GroundReactions->GetNumGearUnits() <= 0 ) {
133 SG_LOG( SG_FLIGHT, SG_ALERT, "num gear units = "
134 << GroundReactions->GetNumGearUnits() );
135 SG_LOG( SG_FLIGHT, SG_ALERT, "This is a very bad thing because with 0 gear units, the ground trimming");
136 SG_LOG( SG_FLIGHT, SG_ALERT, "routine (coming up later in the code) will core dump.");
137 SG_LOG( SG_FLIGHT, SG_ALERT, "Halting the sim now, and hoping a solution will present itself soon!");
144 // Set initial fuel levels if provided.
145 for (unsigned int i = 0; i < Propulsion->GetNumTanks(); i++) {
146 SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
147 if (node->getChild("level-gal_us", 0, false) != 0)
148 Propulsion->GetTank(i)
149 ->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
152 fgSetDouble("/fdm/trim/pitch-trim", FCS->GetPitchTrimCmd());
153 fgSetDouble("/fdm/trim/throttle", FCS->GetThrottleCmd(0));
154 fgSetDouble("/fdm/trim/aileron", FCS->GetDaCmd());
155 fgSetDouble("/fdm/trim/rudder", FCS->GetDrCmd());
157 startup_trim = fgGetNode("/sim/startup/trim", true);
159 trimmed = fgGetNode("/fdm/trim/trimmed", true);
160 trimmed->setBoolValue(false);
162 pitch_trim = fgGetNode("/fdm/trim/pitch-trim", true );
163 throttle_trim = fgGetNode("/fdm/trim/throttle", true );
164 aileron_trim = fgGetNode("/fdm/trim/aileron", true );
165 rudder_trim = fgGetNode("/fdm/trim/rudder", true );
168 stall_warning = fgGetNode("/sim/aero/alarms/stall-warning",true);
169 stall_warning->setDoubleValue(0);
172 flap_pos_pct=fgGetNode("/surface-positions/flap-pos-norm",true);
173 elevator_pos_pct=fgGetNode("/surface-positions/elevator-pos-norm",true);
175 =fgGetNode("/surface-positions/left-aileron-pos-norm",true);
176 right_aileron_pos_pct
177 =fgGetNode("/surface-positions/right-aileron-pos-norm",true);
178 rudder_pos_pct=fgGetNode("/surface-positions/rudder-pos-norm",true);
182 elevator_pos_pct->setDoubleValue(0);
183 left_aileron_pos_pct->setDoubleValue(0);
184 right_aileron_pos_pct->setDoubleValue(0);
185 rudder_pos_pct->setDoubleValue(0);
186 flap_pos_pct->setDoubleValue(0);
190 /******************************************************************************/
191 FGJSBsim::~FGJSBsim(void) {
193 delete fdmex; fdmex=NULL;
194 delete fgic; fgic=NULL;
198 /******************************************************************************/
200 // Initialize the JSBsim flight model, dt is the time increment for
201 // each subsequent iteration through the EOM
203 void FGJSBsim::init() {
205 SG_LOG( SG_FLIGHT, SG_INFO, "Starting and initializing JSBsim" );
207 // Explicitly call the superclass's
208 // init method first.
212 fdmex->RunIC(fgic); //loop JSBSim once w/o integrating
213 copy_from_JSBsim(); //update the bus
215 SG_LOG( SG_FLIGHT, SG_INFO, " Initialized JSBSim with:" );
217 switch(fgic->GetSpeedSet()) {
219 SG_LOG(SG_FLIGHT,SG_INFO, " Vn,Ve,Vd= "
220 << Position->GetVn() << ", "
221 << Position->GetVe() << ", "
222 << Position->GetVd() << " ft/s");
225 SG_LOG(SG_FLIGHT,SG_INFO, " U,V,W= "
226 << Translation->GetUVW(1) << ", "
227 << Translation->GetUVW(2) << ", "
228 << Translation->GetUVW(3) << " ft/s");
231 SG_LOG(SG_FLIGHT,SG_INFO, " Mach: "
232 << Translation->GetMach() );
236 SG_LOG(SG_FLIGHT,SG_INFO, " Indicated Airspeed: "
237 << Auxiliary->GetVcalibratedKTS() << " knots" );
241 stall_warning->setDoubleValue(0);
243 SG_LOG( SG_FLIGHT, SG_INFO, " Bank Angle: "
244 << Rotation->Getphi()*RADTODEG << " deg" );
245 SG_LOG( SG_FLIGHT, SG_INFO, " Pitch Angle: "
246 << Rotation->Gettht()*RADTODEG << " deg" );
247 SG_LOG( SG_FLIGHT, SG_INFO, " True Heading: "
248 << Rotation->Getpsi()*RADTODEG << " deg" );
249 SG_LOG( SG_FLIGHT, SG_INFO, " Latitude: "
250 << Position->GetLatitude() << " deg" );
251 SG_LOG( SG_FLIGHT, SG_INFO, " Longitude: "
252 << Position->GetLongitude() << " deg" );
253 SG_LOG( SG_FLIGHT, SG_INFO, " Altitude: "
254 << Position->Geth() << " feet" );
255 SG_LOG( SG_FLIGHT, SG_INFO, " loaded initial conditions" );
257 SG_LOG( SG_FLIGHT, SG_INFO, " set dt" );
259 SG_LOG( SG_FLIGHT, SG_INFO, "Finished initializing JSBSim" );
261 SG_LOG( SG_FLIGHT, SG_INFO, "FGControls::get_gear_down()= " <<
262 globals->get_controls()->get_gear_down() );
268 /******************************************************************************/
270 // Run an iteration of the EOM (equations of motion)
273 FGJSBsim::update( double dt ) {
278 int multiloop = _calc_multiloop(dt);
282 // double save_alt = 0.0;
286 trimmed->setBoolValue(false);
291 if ( startup_trim->getBoolValue() ) {
292 SG_LOG(SG_FLIGHT, SG_INFO,
293 "Ready to trim, terrain altitude is: "
294 << globals->get_scenery()->get_cur_elev() * SG_METER_TO_FEET );
295 fgic->SetTerrainAltitudeFtIC( globals->get_scenery()->get_cur_elev()
296 * SG_METER_TO_FEET );
299 fdmex->RunIC(fgic); //apply any changes made through the set_ functions
304 for ( i=0; i < multiloop; i++ ) {
308 FGJSBBase::Message* msg;
309 while (fdmex->ReadMessage()) {
310 msg = fdmex->ProcessMessage();
312 case FGJSBBase::Message::eText:
313 SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text );
315 case FGJSBBase::Message::eBool:
316 SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text << " " << msg->bVal );
318 case FGJSBBase::Message::eInteger:
319 SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text << " " << msg->iVal );
321 case FGJSBBase::Message::eDouble:
322 SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text << " " << msg->dVal );
325 SG_LOG( SG_FLIGHT, SG_INFO, "Unrecognized message type." );
330 // translate JSBsim back to FG structure so that the
331 // autopilot (and the rest of the sim can use the updated values
335 /******************************************************************************/
337 // Convert from the FGInterface struct to the JSBsim generic_ struct
339 bool FGJSBsim::copy_to_JSBsim() {
342 // copy control positions into the JSBsim structure
344 FCS->SetDaCmd( globals->get_controls()->get_aileron());
345 FCS->SetRollTrimCmd( globals->get_controls()->get_aileron_trim() );
346 FCS->SetDeCmd( globals->get_controls()->get_elevator());
347 FCS->SetPitchTrimCmd( globals->get_controls()->get_elevator_trim() );
348 FCS->SetDrCmd( -globals->get_controls()->get_rudder() );
349 FCS->SetYawTrimCmd( -globals->get_controls()->get_rudder_trim() );
350 FCS->SetDfCmd( globals->get_controls()->get_flaps() );
351 FCS->SetDsbCmd( 0.0 ); //speedbrakes
352 FCS->SetDspCmd( 0.0 ); //spoilers
354 // Parking brake sets minimum braking
356 double parking_brake = globals->get_controls()->get_parking_brake();
357 FCS->SetLBrake(FMAX(globals->get_controls()->get_brake(0), parking_brake));
358 FCS->SetRBrake(FMAX(globals->get_controls()->get_brake(1), parking_brake));
359 FCS->SetCBrake( globals->get_controls()->get_brake( 2 ) );
361 FCS->SetGearCmd( globals->get_controls()->get_gear_down());
362 for (i = 0; i < Propulsion->GetNumEngines(); i++) {
363 FGEngine * eng = Propulsion->GetEngine(i);
364 SGPropertyNode * node = fgGetNode("engines/engine", i, true);
365 FCS->SetThrottleCmd(i, globals->get_controls()->get_throttle(i));
366 FCS->SetMixtureCmd(i, globals->get_controls()->get_mixture(i));
367 FCS->SetPropAdvanceCmd(i, globals->get_controls()->get_prop_advance(i));
368 Propulsion->GetThruster(i)->SetRPM(node->getDoubleValue("rpm"));
369 eng->SetMagnetos( globals->get_controls()->get_magnetos(i) );
370 eng->SetStarter( globals->get_controls()->get_starter(i) );
373 _set_Runway_altitude( globals->get_scenery()->get_cur_elev()
374 * SG_METER_TO_FEET );
375 Position->SetSeaLevelRadius( get_Sea_level_radius() );
376 Position->SetRunwayRadius( get_Runway_altitude()
377 + get_Sea_level_radius() );
379 Atmosphere->SetExTemperature(get_Static_temperature());
380 Atmosphere->SetExPressure(get_Static_pressure());
381 Atmosphere->SetExDensity(get_Density());
382 Atmosphere->SetWindNED(get_V_north_airmass(),
383 get_V_east_airmass(),
384 get_V_down_airmass());
385 // SG_LOG(SG_FLIGHT,SG_INFO, "Wind NED: "
386 // << get_V_north_airmass() << ", "
387 // << get_V_east_airmass() << ", "
388 // << get_V_down_airmass() );
390 for (i = 0; i < Propulsion->GetNumTanks(); i++) {
391 SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
392 FGTank * tank = Propulsion->GetTank(i);
393 tank->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
394 // tank->SetContents(node->getDoubleValue("level-lb"));
400 /******************************************************************************/
402 // Convert from the JSBsim generic_ struct to the FGInterface struct
404 bool FGJSBsim::copy_from_JSBsim() {
407 _set_Inertias( MassBalance->GetMass(),
408 MassBalance->GetIxx(),
409 MassBalance->GetIyy(),
410 MassBalance->GetIzz(),
411 MassBalance->GetIxz() );
413 _set_CG_Position( MassBalance->GetXYZcg(1),
414 MassBalance->GetXYZcg(2),
415 MassBalance->GetXYZcg(3) );
417 _set_Accels_Body( Aircraft->GetBodyAccel()(1),
418 Aircraft->GetBodyAccel()(2),
419 Aircraft->GetBodyAccel()(3) );
421 //_set_Accels_CG_Body( Aircraft->GetBodyAccel()(1),
422 // Aircraft->GetBodyAccel()(2),
423 // Aircraft->GetBodyAccel()(3) );
425 _set_Accels_CG_Body_N ( Aircraft->GetNcg()(1),
426 Aircraft->GetNcg()(2),
427 Aircraft->GetNcg()(3) );
429 _set_Accels_Pilot_Body( Auxiliary->GetPilotAccel()(1),
430 Auxiliary->GetPilotAccel()(2),
431 Auxiliary->GetPilotAccel()(3) );
433 // _set_Accels_Pilot_Body_N( Auxiliary->GetPilotAccel()(1)/32.1739,
434 // Auxiliary->GetNpilot(2)/32.1739,
435 // Auxiliary->GetNpilot(3)/32.1739 );
437 _set_Nlf( Aircraft->GetNlf() );
441 _set_Velocities_Local( Position->GetVn(),
445 _set_Velocities_Wind_Body( Translation->GetUVW(1),
446 Translation->GetUVW(2),
447 Translation->GetUVW(3) );
449 _set_V_rel_wind( Translation->GetVt() );
451 _set_V_equiv_kts( Auxiliary->GetVequivalentKTS() );
453 // _set_V_calibrated( Auxiliary->GetVcalibratedFPS() );
455 _set_V_calibrated_kts( Auxiliary->GetVcalibratedKTS() );
457 _set_V_ground_speed( Position->GetVground() );
459 _set_Omega_Body( Rotation->GetPQR(1),
461 Rotation->GetPQR(3) );
463 _set_Euler_Rates( Rotation->GetEulerRates(1),
464 Rotation->GetEulerRates(2),
465 Rotation->GetEulerRates(3) );
467 _set_Geocentric_Rates(Position->GetLatitudeDot(),
468 Position->GetLongitudeDot(),
469 Position->Gethdot() );
471 _set_Mach_number( Translation->GetMach() );
474 _updateGeocentricPosition( Position->GetLatitude(),
475 Position->GetLongitude(),
478 _set_Altitude_AGL( Position->GetDistanceAGL() );
480 _set_Euler_Angles( Rotation->Getphi(),
482 Rotation->Getpsi() );
484 _set_Alpha( Translation->Getalpha() );
485 _set_Beta( Translation->Getbeta() );
488 _set_Gamma_vert_rad( Position->GetGamma() );
489 // set_Gamma_horiz_rad( Gamma_horiz_rad );
491 _set_Earth_position_angle( Auxiliary->GetEarthPositionAngle() );
493 _set_Climb_Rate( Position->Gethdot() );
496 for ( i = 1; i <= 3; i++ ) {
497 for ( j = 1; j <= 3; j++ ) {
498 _set_T_Local_to_Body( i, j, State->GetTl2b(i,j) );
502 // Copy the engine values from JSBSim.
503 for( i=0; i < Propulsion->GetNumEngines(); i++ ) {
504 SGPropertyNode * node = fgGetNode("engines/engine", i, true);
505 FGEngine * eng = Propulsion->GetEngine(i);
506 FGThruster * thrust = Propulsion->GetThruster(i);
508 node->setDoubleValue("mp-osi", eng->getManifoldPressure_inHg());
509 node->setDoubleValue("rpm", thrust->GetRPM());
510 node->setDoubleValue("egt-degf", eng->getExhaustGasTemp_degF());
511 node->setDoubleValue("fuel-flow-gph", eng->getFuelFlow_gph());
512 node->setDoubleValue("cht-degf", eng->getCylinderHeadTemp_degF());
513 node->setDoubleValue("oil-temperature-degf", eng->getOilTemp_degF());
514 node->setDoubleValue("oil-pressure-psi", eng->getOilPressure_psi());
515 node->setBoolValue("running", eng->GetRunning());
516 node->setBoolValue("cranking", eng->GetCranking());
519 static const SGPropertyNode *fuel_freeze
520 = fgGetNode("/sim/freeze/fuel");
522 // Copy the fuel levels from JSBSim if fuel
523 // freeze not enabled.
524 if ( ! fuel_freeze->getBoolValue() ) {
525 for (i = 0; i < Propulsion->GetNumTanks(); i++) {
526 SGPropertyNode * node
527 = fgGetNode("/consumables/fuel/tank", i, true);
528 double contents = Propulsion->GetTank(i)->GetContents();
529 node->setDoubleValue("level-gal_us", contents/6.6);
530 // node->setDoubleValue("level-lb", contents);
536 stall_warning->setDoubleValue( Aircraft->GetStallWarn() );
538 /* elevator_pos_deg->setDoubleValue( FCS->GetDePos()*SG_RADIANS_TO_DEGREES );
539 left_aileron_pos_deg->setDoubleValue( FCS->GetDaLPos()*SG_RADIANS_TO_DEGREES );
540 right_aileron_pos_deg->setDoubleValue( FCS->GetDaRPos()*SG_RADIANS_TO_DEGREES );
541 rudder_pos_deg->setDoubleValue( -1*FCS->GetDrPos()*SG_RADIANS_TO_DEGREES );
542 flap_pos_deg->setDoubleValue( FCS->GetDfPos() ); */
545 elevator_pos_pct->setDoubleValue( FCS->GetDePos(ofNorm) );
546 left_aileron_pos_pct->setDoubleValue( FCS->GetDaLPos(ofNorm) );
547 right_aileron_pos_pct->setDoubleValue( -1*FCS->GetDaLPos(ofNorm) );
548 rudder_pos_pct->setDoubleValue( FCS->GetDrPos(ofNorm) );
549 flap_pos_pct->setDoubleValue( FCS->GetDfPos(ofNorm) );
555 bool FGJSBsim::ToggleDataLogging(void) {
556 return fdmex->GetOutput()->Toggle();
560 bool FGJSBsim::ToggleDataLogging(bool state) {
562 fdmex->GetOutput()->Enable();
565 fdmex->GetOutput()->Disable();
572 void FGJSBsim::set_Latitude(double lat) {
573 static const SGPropertyNode *altitude = fgGetNode("/position/altitude-ft");
575 double sea_level_radius_meters, lat_geoc;
577 if ( altitude->getDoubleValue() > -9990 ) {
578 alt = altitude->getDoubleValue();
584 SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Latitude: " << lat );
585 SG_LOG(SG_FLIGHT,SG_INFO," cur alt (ft) = " << alt );
587 sgGeodToGeoc( lat, alt * SG_FEET_TO_METER,
588 &sea_level_radius_meters, &lat_geoc );
589 _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET );
590 fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
591 _set_Runway_altitude( globals->get_scenery()->get_cur_elev()
592 * SG_METER_TO_FEET );
593 fgic->SetTerrainAltitudeFtIC( globals->get_scenery()->get_cur_elev()
594 * SG_METER_TO_FEET );
595 fgic->SetLatitudeRadIC( lat_geoc );
599 void FGJSBsim::set_Longitude(double lon) {
601 SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Longitude: " << lon );
603 fgic->SetLongitudeRadIC( lon );
604 _set_Runway_altitude( globals->get_scenery()->get_cur_elev()
605 * SG_METER_TO_FEET );
606 fgic->SetTerrainAltitudeFtIC( globals->get_scenery()->get_cur_elev()
607 * SG_METER_TO_FEET );
611 void FGJSBsim::set_Altitude(double alt) {
612 static const SGPropertyNode *latitude = fgGetNode("/position/latitude-deg");
614 double sea_level_radius_meters,lat_geoc;
616 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Altitude: " << alt );
617 SG_LOG(SG_FLIGHT,SG_INFO, " lat (deg) = " << latitude->getDoubleValue() );
620 sgGeodToGeoc( latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS, alt,
621 &sea_level_radius_meters, &lat_geoc);
622 _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET );
623 fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
624 _set_Runway_altitude( globals->get_scenery()->get_cur_elev()
625 * SG_METER_TO_FEET );
626 fgic->SetTerrainAltitudeFtIC( globals->get_scenery()->get_cur_elev()
627 * SG_METER_TO_FEET );
628 SG_LOG(SG_FLIGHT, SG_INFO,
629 "Terrain altitude: " << globals->get_scenery()->get_cur_elev()
630 * SG_METER_TO_FEET );
631 fgic->SetLatitudeRadIC( lat_geoc );
632 fgic->SetAltitudeFtIC(alt);
636 void FGJSBsim::set_V_calibrated_kts(double vc) {
637 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_V_calibrated_kts: " << vc );
640 fgic->SetVcalibratedKtsIC(vc);
644 void FGJSBsim::set_Mach_number(double mach) {
645 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Mach_number: " << mach );
648 fgic->SetMachIC(mach);
652 void FGJSBsim::set_Velocities_Local( double north, double east, double down ){
653 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local: "
654 << north << ", " << east << ", " << down );
657 fgic->SetVnorthFpsIC(north);
658 fgic->SetVeastFpsIC(east);
659 fgic->SetVdownFpsIC(down);
663 void FGJSBsim::set_Velocities_Wind_Body( double u, double v, double w){
664 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Wind_Body: "
665 << u << ", " << v << ", " << w );
668 fgic->SetUBodyFpsIC(u);
669 fgic->SetVBodyFpsIC(v);
670 fgic->SetWBodyFpsIC(w);
675 void FGJSBsim::set_Euler_Angles( double phi, double theta, double psi ) {
676 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Euler_Angles: "
677 << phi << ", " << theta << ", " << psi );
680 fgic->SetPitchAngleRadIC(theta);
681 fgic->SetRollAngleRadIC(phi);
682 fgic->SetTrueHeadingRadIC(psi);
687 void FGJSBsim::set_Climb_Rate( double roc) {
688 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Climb_Rate: " << roc );
691 //since both climb rate and flight path angle are set in the FG
692 //startup sequence, something is needed to keep one from cancelling
694 if( !(fabs(roc) > 1 && fabs(fgic->GetFlightPathAngleRadIC()) < 0.01) ) {
695 fgic->SetClimbRateFpsIC(roc);
700 void FGJSBsim::set_Gamma_vert_rad( double gamma) {
701 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Gamma_vert_rad: " << gamma );
704 if( !(fabs(gamma) < 0.01 && fabs(fgic->GetClimbRateFpsIC()) > 1) ) {
705 fgic->SetFlightPathAngleRadIC(gamma);
710 // void FGJSBsim::set_Static_pressure(double p) {
711 // SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_pressure: " << p );
714 // Atmosphere->SetExPressure(p);
715 // if(Atmosphere->External() == true)
719 // void FGJSBsim::set_Static_temperature(double T) {
720 // SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_temperature: " << T );
722 // Atmosphere->SetExTemperature(T);
723 // if(Atmosphere->External() == true)
728 // void FGJSBsim::set_Density(double rho) {
729 // SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Density: " << rho );
731 // Atmosphere->SetExDensity(rho);
732 // if(Atmosphere->External() == true)
736 void FGJSBsim::set_Velocities_Local_Airmass (double wnorth,
739 //SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local_Airmass: "
740 // << wnorth << ", " << weast << ", " << wdown );
742 _set_Velocities_Local_Airmass( wnorth, weast, wdown );
743 fgic->SetWindNEDFpsIC( wnorth, weast, wdown );
744 if(Atmosphere->External() == true)
748 void FGJSBsim::init_gear(void ) {
750 FGGroundReactions* gr=fdmex->GetGroundReactions();
751 int Ngear=GroundReactions->GetNumGearUnits();
752 for (int i=0;i<Ngear;i++) {
753 SGPropertyNode * node = fgGetNode("gear/gear", i, true);
754 node->setDoubleValue("xoffset-in",
755 gr->GetGearUnit(i)->GetBodyLocation()(1));
756 node->setDoubleValue("yoffset-in",
757 gr->GetGearUnit(i)->GetBodyLocation()(2));
758 node->setDoubleValue("zoffset-in",
759 gr->GetGearUnit(i)->GetBodyLocation()(3));
760 node->setBoolValue("wow", gr->GetGearUnit(i)->GetWOW());
761 node->setBoolValue("has-brake", gr->GetGearUnit(i)->GetBrakeGroup() > 0);
762 node->setDoubleValue("position-norm", FCS->GetGearPos());
766 void FGJSBsim::update_gear(void) {
768 FGGroundReactions* gr=fdmex->GetGroundReactions();
769 int Ngear=GroundReactions->GetNumGearUnits();
770 for (int i=0;i<Ngear;i++) {
771 SGPropertyNode * node = fgGetNode("gear/gear", i, true);
772 node->getChild("wow", 0, true)
773 ->setBoolValue(gr->GetGearUnit(i)->GetWOW());
774 node->getChild("position-norm", 0, true)
775 ->setDoubleValue(FCS->GetGearPos());
779 void FGJSBsim::do_trim(void) {
782 if(fgic->GetVcalibratedKtsIC() < 10 ) {
783 fgic->SetVcalibratedKtsIC(0.0);
784 fgtrim=new FGTrim(fdmex,fgic,tGround);
786 fgtrim=new FGTrim(fdmex,fgic,tLongitudinal);
788 if( !fgtrim->DoTrim() ) {
792 trimmed->setBoolValue(true);
794 State->ReportState();
796 pitch_trim->setDoubleValue( FCS->GetPitchTrimCmd() );
797 throttle_trim->setDoubleValue( FCS->GetThrottleCmd(0) );
798 aileron_trim->setDoubleValue( FCS->GetDaCmd() );
799 rudder_trim->setDoubleValue( FCS->GetDrCmd() );
801 globals->get_controls()->set_elevator_trim(FCS->GetPitchTrimCmd());
802 globals->get_controls()->set_elevator(FCS->GetDeCmd());
803 globals->get_controls()->set_throttle(FGControls::ALL_ENGINES,
804 FCS->GetThrottleCmd(0));
806 globals->get_controls()->set_aileron(FCS->GetDaCmd());
807 globals->get_controls()->set_rudder( FCS->GetDrCmd());
809 SG_LOG( SG_FLIGHT, SG_INFO, " Trim complete" );
812 void FGJSBsim::update_ic(void) {
814 fgic->SetLatitudeRadIC(get_Lat_geocentric() );
815 fgic->SetLongitudeRadIC( get_Longitude() );
816 fgic->SetAltitudeFtIC( get_Altitude() );
817 fgic->SetVcalibratedKtsIC( get_V_calibrated_kts() );
818 fgic->SetPitchAngleRadIC( get_Theta() );
819 fgic->SetRollAngleRadIC( get_Phi() );
820 fgic->SetTrueHeadingRadIC( get_Psi() );
821 fgic->SetClimbRateFpsIC( get_Climb_Rate() );