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>
61 /******************************************************************************/
63 FGJSBsim::FGJSBsim( double dt )
68 fdmex = new FGFDMExec( (FGPropertyManager*)globals->get_props() );
70 State = fdmex->GetState();
71 Atmosphere = fdmex->GetAtmosphere();
72 FCS = fdmex->GetFCS();
73 MassBalance = fdmex->GetMassBalance();
74 Propulsion = fdmex->GetPropulsion();
75 Aircraft = fdmex->GetAircraft();
76 Translation = fdmex->GetTranslation();
77 Rotation = fdmex->GetRotation();
78 Position = fdmex->GetPosition();
79 Auxiliary = fdmex->GetAuxiliary();
80 Aerodynamics = fdmex->GetAerodynamics();
81 GroundReactions = fdmex->GetGroundReactions();
84 Atmosphere->UseInternal();
86 fgic=new FGInitialCondition(fdmex);
89 SGPath aircraft_path( globals->get_fg_root() );
90 aircraft_path.append( "Aircraft" );
92 SGPath engine_path( globals->get_fg_root() );
93 engine_path.append( "Engine" );
97 result = fdmex->LoadModel( aircraft_path.str(),
99 fgGetString("/sim/aero") );
102 SG_LOG( SG_FLIGHT, SG_INFO, " loaded aero.");
104 SG_LOG( SG_FLIGHT, SG_INFO,
105 " aero does not exist (you may have mis-typed the name).");
109 SG_LOG( SG_FLIGHT, SG_INFO, "" );
110 SG_LOG( SG_FLIGHT, SG_INFO, "" );
111 SG_LOG( SG_FLIGHT, SG_INFO, "After loading aero definition file ..." );
113 int Neng = Propulsion->GetNumEngines();
114 SG_LOG( SG_FLIGHT, SG_INFO, "num engines = " << Neng );
116 if ( GroundReactions->GetNumGearUnits() <= 0 ) {
117 SG_LOG( SG_FLIGHT, SG_ALERT, "num gear units = "
118 << GroundReactions->GetNumGearUnits() );
119 SG_LOG( SG_FLIGHT, SG_ALERT, "This is a very bad thing because with 0 gear units, the ground trimming");
120 SG_LOG( SG_FLIGHT, SG_ALERT, "routine (coming up later in the code) will core dump.");
121 SG_LOG( SG_FLIGHT, SG_ALERT, "Halting the sim now, and hoping a solution will present itself soon!");
128 // Set initial fuel levels if provided.
129 for (unsigned int i = 0; i < Propulsion->GetNumTanks(); i++) {
130 SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
131 if (node->getChild("level-gal_us", 0, false) != 0)
132 Propulsion->GetTank(i)
133 ->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
136 fgSetDouble("/fdm/trim/pitch-trim", FCS->GetPitchTrimCmd());
137 fgSetDouble("/fdm/trim/throttle", FCS->GetThrottleCmd(0));
138 fgSetDouble("/fdm/trim/aileron", FCS->GetDaCmd());
139 fgSetDouble("/fdm/trim/rudder", FCS->GetDrCmd());
141 startup_trim = fgGetNode("/sim/startup/trim", true);
143 trimmed = fgGetNode("/fdm/trim/trimmed", true);
144 trimmed->setBoolValue(false);
146 pitch_trim = fgGetNode("/fdm/trim/pitch-trim", true );
147 throttle_trim = fgGetNode("/fdm/trim/throttle", true );
148 aileron_trim = fgGetNode("/fdm/trim/aileron", true );
149 rudder_trim = fgGetNode("/fdm/trim/rudder", true );
152 stall_warning = fgGetNode("/sim/aero/alarms/stall-warning",true);
153 stall_warning->setDoubleValue(0);
156 flap_pos_pct=fgGetNode("/surface-positions/flap-pos-norm",true);
157 elevator_pos_pct=fgGetNode("/surface-positions/elevator-pos-norm",true);
159 =fgGetNode("/surface-positions/left-aileron-pos-norm",true);
160 right_aileron_pos_pct
161 =fgGetNode("/surface-positions/right-aileron-pos-norm",true);
162 rudder_pos_pct=fgGetNode("/surface-positions/rudder-pos-norm",true);
166 elevator_pos_pct->setDoubleValue(0);
167 left_aileron_pos_pct->setDoubleValue(0);
168 right_aileron_pos_pct->setDoubleValue(0);
169 rudder_pos_pct->setDoubleValue(0);
170 flap_pos_pct->setDoubleValue(0);
174 /******************************************************************************/
175 FGJSBsim::~FGJSBsim(void) {
177 delete fdmex; fdmex=NULL;
178 delete fgic; fgic=NULL;
182 /******************************************************************************/
184 // Initialize the JSBsim flight model, dt is the time increment for
185 // each subsequent iteration through the EOM
187 void FGJSBsim::init() {
189 SG_LOG( SG_FLIGHT, SG_INFO, "Starting and initializing JSBsim" );
191 // Explicitly call the superclass's
192 // init method first.
196 fdmex->RunIC(fgic); //loop JSBSim once w/o integrating
197 copy_from_JSBsim(); //update the bus
199 SG_LOG( SG_FLIGHT, SG_INFO, " Initialized JSBSim with:" );
201 switch(fgic->GetSpeedSet()) {
203 SG_LOG(SG_FLIGHT,SG_INFO, " Vn,Ve,Vd= "
204 << Position->GetVn() << ", "
205 << Position->GetVe() << ", "
206 << Position->GetVd() << " ft/s");
209 SG_LOG(SG_FLIGHT,SG_INFO, " U,V,W= "
210 << Translation->GetUVW(1) << ", "
211 << Translation->GetUVW(2) << ", "
212 << Translation->GetUVW(3) << " ft/s");
215 SG_LOG(SG_FLIGHT,SG_INFO, " Mach: "
216 << Translation->GetMach() );
220 SG_LOG(SG_FLIGHT,SG_INFO, " Indicated Airspeed: "
221 << Auxiliary->GetVcalibratedKTS() << " knots" );
225 stall_warning->setDoubleValue(0);
227 SG_LOG( SG_FLIGHT, SG_INFO, " Bank Angle: "
228 << Rotation->Getphi()*RADTODEG << " deg" );
229 SG_LOG( SG_FLIGHT, SG_INFO, " Pitch Angle: "
230 << Rotation->Gettht()*RADTODEG << " deg" );
231 SG_LOG( SG_FLIGHT, SG_INFO, " True Heading: "
232 << Rotation->Getpsi()*RADTODEG << " deg" );
233 SG_LOG( SG_FLIGHT, SG_INFO, " Latitude: "
234 << Position->GetLatitude() << " deg" );
235 SG_LOG( SG_FLIGHT, SG_INFO, " Longitude: "
236 << Position->GetLongitude() << " deg" );
237 SG_LOG( SG_FLIGHT, SG_INFO, " Altitude: "
238 << Position->Geth() << " feet" );
239 SG_LOG( SG_FLIGHT, SG_INFO, " loaded initial conditions" );
241 SG_LOG( SG_FLIGHT, SG_INFO, " set dt" );
243 SG_LOG( SG_FLIGHT, SG_INFO, "Finished initializing JSBSim" );
245 SG_LOG( SG_FLIGHT, SG_INFO, "FGControls::get_gear_down()= " <<
246 globals->get_controls()->get_gear_down() );
252 /******************************************************************************/
254 // Run an iteration of the EOM (equations of motion)
257 FGJSBsim::update( int multiloop ) {
261 // double save_alt = 0.0;
265 trimmed->setBoolValue(false);
270 if ( startup_trim->getBoolValue() ) {
271 SG_LOG(SG_FLIGHT, SG_INFO,
272 "Ready to trim, terrain altitude is: "
273 << scenery.get_cur_elev() * SG_METER_TO_FEET );
274 fgic->SetTerrainAltitudeFtIC( scenery.get_cur_elev() * SG_METER_TO_FEET );
277 fdmex->RunIC(fgic); //apply any changes made through the set_ functions
282 for ( i=0; i < multiloop; i++ ) {
286 FGJSBBase::Message* msg;
287 while (fdmex->ReadMessage()) {
288 msg = fdmex->ProcessMessage();
290 case FGJSBBase::Message::eText:
291 SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text );
293 case FGJSBBase::Message::eBool:
294 SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text << " " << msg->bVal );
296 case FGJSBBase::Message::eInteger:
297 SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text << " " << msg->iVal );
299 case FGJSBBase::Message::eDouble:
300 SG_LOG( SG_FLIGHT, SG_INFO, msg->messageId << ": " << msg->text << " " << msg->dVal );
303 SG_LOG( SG_FLIGHT, SG_INFO, "Unrecognized message type." );
308 // translate JSBsim back to FG structure so that the
309 // autopilot (and the rest of the sim can use the updated values
313 /******************************************************************************/
315 // Convert from the FGInterface struct to the JSBsim generic_ struct
317 bool FGJSBsim::copy_to_JSBsim() {
320 // copy control positions into the JSBsim structure
322 FCS->SetDaCmd( globals->get_controls()->get_aileron());
323 FCS->SetRollTrimCmd( globals->get_controls()->get_aileron_trim() );
324 FCS->SetDeCmd( globals->get_controls()->get_elevator());
325 FCS->SetPitchTrimCmd( globals->get_controls()->get_elevator_trim() );
326 FCS->SetDrCmd( -globals->get_controls()->get_rudder() );
327 FCS->SetYawTrimCmd( -globals->get_controls()->get_rudder_trim() );
328 FCS->SetDfCmd( globals->get_controls()->get_flaps() );
329 FCS->SetDsbCmd( 0.0 ); //speedbrakes
330 FCS->SetDspCmd( 0.0 ); //spoilers
332 // Parking brake sets minimum braking
334 double parking_brake = globals->get_controls()->get_parking_brake();
335 FCS->SetLBrake(fmax(globals->get_controls()->get_brake(0), parking_brake));
336 FCS->SetRBrake(fmax(globals->get_controls()->get_brake(1), parking_brake));
337 FCS->SetCBrake( globals->get_controls()->get_brake( 2 ) );
339 FCS->SetGearCmd( globals->get_controls()->get_gear_down());
340 for (i = 0; i < Propulsion->GetNumEngines(); i++) {
341 FGEngine * eng = Propulsion->GetEngine(i);
342 SGPropertyNode * node = fgGetNode("engines/engine", i, true);
343 FCS->SetThrottleCmd(i, globals->get_controls()->get_throttle(i));
344 FCS->SetMixtureCmd(i, globals->get_controls()->get_mixture(i));
345 FCS->SetPropAdvanceCmd(i, globals->get_controls()->get_prop_advance(i));
346 Propulsion->GetThruster(i)->SetRPM(node->getDoubleValue("rpm"));
347 eng->SetMagnetos( globals->get_controls()->get_magnetos(i) );
348 eng->SetStarter( globals->get_controls()->get_starter(i) );
351 _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET );
352 Position->SetSeaLevelRadius( get_Sea_level_radius() );
353 Position->SetRunwayRadius( get_Runway_altitude()
354 + get_Sea_level_radius() );
356 Atmosphere->SetExTemperature(get_Static_temperature());
357 Atmosphere->SetExPressure(get_Static_pressure());
358 Atmosphere->SetExDensity(get_Density());
359 Atmosphere->SetWindNED(get_V_north_airmass(),
360 get_V_east_airmass(),
361 get_V_down_airmass());
362 // SG_LOG(SG_FLIGHT,SG_INFO, "Wind NED: "
363 // << get_V_north_airmass() << ", "
364 // << get_V_east_airmass() << ", "
365 // << get_V_down_airmass() );
367 for (i = 0; i < Propulsion->GetNumTanks(); i++) {
368 SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
369 FGTank * tank = Propulsion->GetTank(i);
370 tank->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
371 // tank->SetContents(node->getDoubleValue("level-lb"));
377 /******************************************************************************/
379 // Convert from the JSBsim generic_ struct to the FGInterface struct
381 bool FGJSBsim::copy_from_JSBsim() {
384 _set_Inertias( MassBalance->GetMass(),
385 MassBalance->GetIxx(),
386 MassBalance->GetIyy(),
387 MassBalance->GetIzz(),
388 MassBalance->GetIxz() );
390 _set_CG_Position( MassBalance->GetXYZcg(1),
391 MassBalance->GetXYZcg(2),
392 MassBalance->GetXYZcg(3) );
394 _set_Accels_Body( Aircraft->GetBodyAccel()(1),
395 Aircraft->GetBodyAccel()(2),
396 Aircraft->GetBodyAccel()(3) );
398 //_set_Accels_CG_Body( Aircraft->GetBodyAccel()(1),
399 // Aircraft->GetBodyAccel()(2),
400 // Aircraft->GetBodyAccel()(3) );
402 _set_Accels_CG_Body_N ( Aircraft->GetNcg()(1),
403 Aircraft->GetNcg()(2),
404 Aircraft->GetNcg()(3) );
406 _set_Accels_Pilot_Body( Auxiliary->GetPilotAccel()(1),
407 Auxiliary->GetPilotAccel()(2),
408 Auxiliary->GetPilotAccel()(3) );
410 // _set_Accels_Pilot_Body_N( Auxiliary->GetPilotAccel()(1)/32.1739,
411 // Auxiliary->GetNpilot(2)/32.1739,
412 // Auxiliary->GetNpilot(3)/32.1739 );
414 _set_Nlf( Aircraft->GetNlf() );
418 _set_Velocities_Local( Position->GetVn(),
422 _set_Velocities_Wind_Body( Translation->GetUVW(1),
423 Translation->GetUVW(2),
424 Translation->GetUVW(3) );
426 _set_V_rel_wind( Translation->GetVt() );
428 _set_V_equiv_kts( Auxiliary->GetVequivalentKTS() );
430 // _set_V_calibrated( Auxiliary->GetVcalibratedFPS() );
432 _set_V_calibrated_kts( Auxiliary->GetVcalibratedKTS() );
434 _set_V_ground_speed( Position->GetVground() );
436 _set_Omega_Body( Rotation->GetPQR(1),
438 Rotation->GetPQR(3) );
440 _set_Euler_Rates( Rotation->GetEulerRates(1),
441 Rotation->GetEulerRates(2),
442 Rotation->GetEulerRates(3) );
444 _set_Geocentric_Rates(Position->GetLatitudeDot(),
445 Position->GetLongitudeDot(),
446 Position->Gethdot() );
448 _set_Mach_number( Translation->GetMach() );
451 _updateGeocentricPosition( Position->GetLatitude(),
452 Position->GetLongitude(),
455 _set_Altitude_AGL( Position->GetDistanceAGL() );
457 _set_Euler_Angles( Rotation->Getphi(),
459 Rotation->Getpsi() );
461 _set_Alpha( Translation->Getalpha() );
462 _set_Beta( Translation->Getbeta() );
465 _set_Gamma_vert_rad( Position->GetGamma() );
466 // set_Gamma_horiz_rad( Gamma_horiz_rad );
468 _set_Earth_position_angle( Auxiliary->GetEarthPositionAngle() );
470 _set_Climb_Rate( Position->Gethdot() );
473 for ( i = 1; i <= 3; i++ ) {
474 for ( j = 1; j <= 3; j++ ) {
475 _set_T_Local_to_Body( i, j, State->GetTl2b(i,j) );
479 // Copy the engine values from JSBSim.
480 for( i=0; i < Propulsion->GetNumEngines(); i++ ) {
481 SGPropertyNode * node = fgGetNode("engines/engine", i, true);
482 FGEngine * eng = Propulsion->GetEngine(i);
483 FGThruster * thrust = Propulsion->GetThruster(i);
485 node->setDoubleValue("mp-osi", eng->getManifoldPressure_inHg());
486 node->setDoubleValue("rpm", thrust->GetRPM());
487 node->setDoubleValue("egt-degf", eng->getExhaustGasTemp_degF());
488 node->setDoubleValue("fuel-flow-gph", eng->getFuelFlow_gph());
489 node->setDoubleValue("cht-degf", eng->getCylinderHeadTemp_degF());
490 node->setDoubleValue("oil-temperature-degf", eng->getOilTemp_degF());
491 node->setDoubleValue("oil-pressure-psi", eng->getOilPressure_psi());
492 node->setBoolValue("running", eng->GetRunning());
493 node->setBoolValue("cranking", eng->GetCranking());
496 static const SGPropertyNode *fuel_freeze
497 = fgGetNode("/sim/freeze/fuel");
499 // Copy the fuel levels from JSBSim if fuel
500 // freeze not enabled.
501 if ( ! fuel_freeze->getBoolValue() ) {
502 for (i = 0; i < Propulsion->GetNumTanks(); i++) {
503 SGPropertyNode * node
504 = fgGetNode("/consumables/fuel/tank", i, true);
505 double contents = Propulsion->GetTank(i)->GetContents();
506 node->setDoubleValue("level-gal_us", contents/6.6);
507 // node->setDoubleValue("level-lb", contents);
513 stall_warning->setDoubleValue( Aircraft->GetStallWarn() );
515 /* elevator_pos_deg->setDoubleValue( FCS->GetDePos()*SG_RADIANS_TO_DEGREES );
516 left_aileron_pos_deg->setDoubleValue( FCS->GetDaLPos()*SG_RADIANS_TO_DEGREES );
517 right_aileron_pos_deg->setDoubleValue( FCS->GetDaRPos()*SG_RADIANS_TO_DEGREES );
518 rudder_pos_deg->setDoubleValue( -1*FCS->GetDrPos()*SG_RADIANS_TO_DEGREES );
519 flap_pos_deg->setDoubleValue( FCS->GetDfPos() ); */
522 elevator_pos_pct->setDoubleValue( FCS->GetDePos(ofNorm) );
523 left_aileron_pos_pct->setDoubleValue( FCS->GetDaLPos(ofNorm) );
524 right_aileron_pos_pct->setDoubleValue( -1*FCS->GetDaLPos(ofNorm) );
525 rudder_pos_pct->setDoubleValue( FCS->GetDrPos(ofNorm) );
526 flap_pos_pct->setDoubleValue( FCS->GetDfPos(ofNorm) );
532 bool FGJSBsim::ToggleDataLogging(void) {
533 return fdmex->GetOutput()->Toggle();
537 bool FGJSBsim::ToggleDataLogging(bool state) {
539 fdmex->GetOutput()->Enable();
542 fdmex->GetOutput()->Disable();
549 void FGJSBsim::set_Latitude(double lat) {
550 static const SGPropertyNode *altitude = fgGetNode("/position/altitude-ft");
552 double sea_level_radius_meters, lat_geoc;
554 if ( altitude->getDoubleValue() > -9990 ) {
555 alt = altitude->getDoubleValue();
561 SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Latitude: " << lat );
562 SG_LOG(SG_FLIGHT,SG_INFO," cur alt (ft) = " << alt );
564 sgGeodToGeoc( lat, alt * SG_FEET_TO_METER,
565 &sea_level_radius_meters, &lat_geoc );
566 _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET );
567 fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
568 _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET );
569 fgic->SetTerrainAltitudeFtIC( scenery.get_cur_elev() * SG_METER_TO_FEET );
570 fgic->SetLatitudeRadIC( lat_geoc );
574 void FGJSBsim::set_Longitude(double lon) {
576 SG_LOG(SG_FLIGHT,SG_INFO,"FGJSBsim::set_Longitude: " << lon );
578 fgic->SetLongitudeRadIC( lon );
579 _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET );
580 fgic->SetTerrainAltitudeFtIC( scenery.get_cur_elev() * SG_METER_TO_FEET );
584 void FGJSBsim::set_Altitude(double alt) {
585 static const SGPropertyNode *latitude = fgGetNode("/position/latitude-deg");
587 double sea_level_radius_meters,lat_geoc;
589 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Altitude: " << alt );
590 SG_LOG(SG_FLIGHT,SG_INFO, " lat (deg) = " << latitude->getDoubleValue() );
593 sgGeodToGeoc( latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS, alt,
594 &sea_level_radius_meters, &lat_geoc);
595 _set_Sea_level_radius( sea_level_radius_meters * SG_METER_TO_FEET );
596 fgic->SetSeaLevelRadiusFtIC( sea_level_radius_meters * SG_METER_TO_FEET );
597 _set_Runway_altitude( scenery.get_cur_elev() * SG_METER_TO_FEET );
598 fgic->SetTerrainAltitudeFtIC( scenery.get_cur_elev() * SG_METER_TO_FEET );
599 SG_LOG(SG_FLIGHT, SG_INFO,
600 "Terrain altitude: " << scenery.get_cur_elev() * SG_METER_TO_FEET );
601 fgic->SetLatitudeRadIC( lat_geoc );
602 fgic->SetAltitudeFtIC(alt);
606 void FGJSBsim::set_V_calibrated_kts(double vc) {
607 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_V_calibrated_kts: " << vc );
610 fgic->SetVcalibratedKtsIC(vc);
614 void FGJSBsim::set_Mach_number(double mach) {
615 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Mach_number: " << mach );
618 fgic->SetMachIC(mach);
622 void FGJSBsim::set_Velocities_Local( double north, double east, double down ){
623 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local: "
624 << north << ", " << east << ", " << down );
627 fgic->SetVnorthFpsIC(north);
628 fgic->SetVeastFpsIC(east);
629 fgic->SetVdownFpsIC(down);
633 void FGJSBsim::set_Velocities_Wind_Body( double u, double v, double w){
634 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Wind_Body: "
635 << u << ", " << v << ", " << w );
638 fgic->SetUBodyFpsIC(u);
639 fgic->SetVBodyFpsIC(v);
640 fgic->SetWBodyFpsIC(w);
645 void FGJSBsim::set_Euler_Angles( double phi, double theta, double psi ) {
646 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Euler_Angles: "
647 << phi << ", " << theta << ", " << psi );
650 fgic->SetPitchAngleRadIC(theta);
651 fgic->SetRollAngleRadIC(phi);
652 fgic->SetTrueHeadingRadIC(psi);
657 void FGJSBsim::set_Climb_Rate( double roc) {
658 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Climb_Rate: " << roc );
661 //since both climb rate and flight path angle are set in the FG
662 //startup sequence, something is needed to keep one from cancelling
664 if( !(fabs(roc) > 1 && fabs(fgic->GetFlightPathAngleRadIC()) < 0.01) ) {
665 fgic->SetClimbRateFpsIC(roc);
670 void FGJSBsim::set_Gamma_vert_rad( double gamma) {
671 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Gamma_vert_rad: " << gamma );
674 if( !(fabs(gamma) < 0.01 && fabs(fgic->GetClimbRateFpsIC()) > 1) ) {
675 fgic->SetFlightPathAngleRadIC(gamma);
680 void FGJSBsim::set_Static_pressure(double p) {
681 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_pressure: " << p );
684 Atmosphere->SetExPressure(p);
685 if(Atmosphere->External() == true)
689 void FGJSBsim::set_Static_temperature(double T) {
690 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_temperature: " << T );
692 Atmosphere->SetExTemperature(T);
693 if(Atmosphere->External() == true)
698 void FGJSBsim::set_Density(double rho) {
699 SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Density: " << rho );
701 Atmosphere->SetExDensity(rho);
702 if(Atmosphere->External() == true)
706 void FGJSBsim::set_Velocities_Local_Airmass (double wnorth,
709 //SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local_Airmass: "
710 // << wnorth << ", " << weast << ", " << wdown );
712 _set_Velocities_Local_Airmass( wnorth, weast, wdown );
713 fgic->SetWindNEDFpsIC( wnorth, weast, wdown );
714 if(Atmosphere->External() == true)
718 void FGJSBsim::init_gear(void ) {
720 FGGroundReactions* gr=fdmex->GetGroundReactions();
721 int Ngear=GroundReactions->GetNumGearUnits();
722 for (int i=0;i<Ngear;i++) {
723 SGPropertyNode * node = fgGetNode("gear/gear", i, true);
724 node->setDoubleValue("xoffset-in",
725 gr->GetGearUnit(i)->GetBodyLocation()(1));
726 node->setDoubleValue("yoffset-in",
727 gr->GetGearUnit(i)->GetBodyLocation()(2));
728 node->setDoubleValue("zoffset-in",
729 gr->GetGearUnit(i)->GetBodyLocation()(3));
730 node->setBoolValue("wow", gr->GetGearUnit(i)->GetWOW());
731 node->setBoolValue("has-brake", gr->GetGearUnit(i)->GetBrakeGroup() > 0);
732 node->setDoubleValue("position-norm", FCS->GetGearPos());
736 void FGJSBsim::update_gear(void) {
738 FGGroundReactions* gr=fdmex->GetGroundReactions();
739 int Ngear=GroundReactions->GetNumGearUnits();
740 for (int i=0;i<Ngear;i++) {
741 SGPropertyNode * node = fgGetNode("gear/gear", i, true);
742 node->getChild("wow", 0, true)
743 ->setBoolValue(gr->GetGearUnit(i)->GetWOW());
744 node->getChild("position-norm", 0, true)
745 ->setDoubleValue(FCS->GetGearPos());
749 void FGJSBsim::do_trim(void) {
752 if(fgic->GetVcalibratedKtsIC() < 10 ) {
753 fgic->SetVcalibratedKtsIC(0.0);
754 fgtrim=new FGTrim(fdmex,fgic,tGround);
756 fgtrim=new FGTrim(fdmex,fgic,tLongitudinal);
758 if( !fgtrim->DoTrim() ) {
762 trimmed->setBoolValue(true);
764 State->ReportState();
766 pitch_trim->setDoubleValue( FCS->GetPitchTrimCmd() );
767 throttle_trim->setDoubleValue( FCS->GetThrottleCmd(0) );
768 aileron_trim->setDoubleValue( FCS->GetDaCmd() );
769 rudder_trim->setDoubleValue( FCS->GetDrCmd() );
771 globals->get_controls()->set_elevator_trim(FCS->GetPitchTrimCmd());
772 globals->get_controls()->set_elevator(FCS->GetDeCmd());
773 globals->get_controls()->set_throttle(FGControls::ALL_ENGINES,
774 FCS->GetThrottleCmd(0));
776 globals->get_controls()->set_aileron(FCS->GetDaCmd());
777 globals->get_controls()->set_rudder( FCS->GetDrCmd());
779 SG_LOG( SG_FLIGHT, SG_INFO, " Trim complete" );
782 void FGJSBsim::update_ic(void) {
784 fgic->SetLatitudeRadIC(get_Lat_geocentric() );
785 fgic->SetLongitudeRadIC( get_Longitude() );
786 fgic->SetAltitudeFtIC( get_Altitude() );
787 fgic->SetVcalibratedKtsIC( get_V_calibrated_kts() );
788 fgic->SetPitchAngleRadIC( get_Theta() );
789 fgic->SetRollAngleRadIC( get_Phi() );
790 fgic->SetTrueHeadingRadIC( get_Psi() );
791 fgic->SetClimbRateFpsIC( get_Climb_Rate() );