1 // fg_init.cxx -- Flight Gear top level initialization routines
3 // Written by Curtis Olson, started August 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
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.
29 // For BC 5.01 this must be included before OpenGL includes.
30 #ifdef FG_MATH_EXCEPTION_CLASH
35 #include <simgear/xgl/xgl.h>
40 // work around a stdc++ lib bug in some versions of linux, but doesn't
41 // seem to hurt to have this here for all versions of Linux.
43 # define _G_NO_EXTERN_TEMPLATES
46 #include <simgear/compiler.h>
50 #include <simgear/constants.h>
51 #include <simgear/debug/logstream.hxx>
52 #include <simgear/math/point3d.hxx>
53 #include <simgear/math/polar3d.hxx>
54 #include <simgear/math/sg_geodesy.hxx>
55 #include <simgear/misc/fgpath.hxx>
56 #include <simgear/timing/sg_time.hxx>
58 #include <Aircraft/aircraft.hxx>
59 #include <Airports/runways.hxx>
60 #include <Airports/simple.hxx>
61 #include <Autopilot/auto_gui.hxx>
62 #include <Autopilot/newauto.hxx>
63 #include <Cockpit/cockpit.hxx>
64 #include <Cockpit/radiostack.hxx>
65 #include <Cockpit/panel.hxx>
66 #include <Cockpit/panel_io.hxx>
67 #include <FDM/Balloon.h>
68 #include <FDM/External.hxx>
69 #include <FDM/JSBSim.hxx>
70 #include <FDM/LaRCsim.hxx>
71 #include <FDM/MagicCarpet.hxx>
72 #include <Include/general.hxx>
73 #include <Joystick/joystick.hxx>
74 #include <Objects/matlib.hxx>
75 #include <Navaids/fixlist.hxx>
76 #include <Navaids/ilslist.hxx>
77 #include <Navaids/navlist.hxx>
78 #include <Scenery/scenery.hxx>
79 #include <Scenery/tilemgr.hxx>
80 #include <Time/event.hxx>
81 #include <Time/light.hxx>
82 #include <Time/sunpos.hxx>
83 #include <Time/moonpos.hxx>
84 #include <Time/tmp.hxx>
86 #ifndef FG_OLD_WEATHER
87 # include <WeatherCM/FGLocalWeatherDatabase.h>
89 # include <Weather/weather.hxx>
92 #include "fg_init.hxx"
94 #include "globals.hxx"
95 #include "options.hxx"
99 #if defined(FX) && defined(XMESA)
100 #include <GL/xmesa.h>
103 FG_USING_STD(string);
105 extern const char *default_root;
108 // Read in configuration (file and command line)
109 bool fgInitConfig ( int argc, char **argv ) {
110 // Attempt to locate and parse a config file
111 // First check fg_root
112 FGPath config( current_options.get_fg_root() );
113 config.append( "system.fgfsrc" );
114 current_options.parse_config_file( config.str() );
116 // Next check home directory
117 char* envp = ::getenv( "HOME" );
118 if ( envp != NULL ) {
120 config.append( ".fgfsrc" );
121 current_options.parse_config_file( config.str() );
124 // Parse remaining command line options
125 // These will override anything specified in a config file
126 if ( current_options.parse_command_line(argc, argv) !=
127 fgOPTIONS::FG_OPTIONS_OK )
129 // Something must have gone horribly wrong with the command
130 // line parsing or maybe the user just requested help ... :-)
131 current_options.usage();
132 FG_LOG( FG_GENERAL, FG_ALERT, "\nExiting ...");
140 // Set current_options lon/lat given an airport id
141 bool fgSetPosFromAirportID( const string& id ) {
146 // set initial position from airport id
148 FGPath path( current_options.get_fg_root() );
149 path.append( "Airports" );
150 path.append( "simple.mk4" );
151 FGAirports airports( path.c_str() );
153 FG_LOG( FG_GENERAL, FG_INFO,
154 "Attempting to set starting position from airport code "
157 // FGPath inpath( current_options.get_fg_root() );
158 // inpath.append( "Airports" );
159 // inpath.append( "apt_simple" );
160 // airports.load( inpath.c_str() );
162 // FGPath outpath( current_options.get_fg_root() );
163 // outpath.append( "Airports" );
164 // outpath.append( "simple.gdbm" );
165 // airports.dump_gdbm( outpath.c_str() );
167 if ( ! airports.search( id, &a ) ) {
168 FG_LOG( FG_GENERAL, FG_ALERT,
169 "Failed to find " << id << " in database." );
172 current_options.set_lon( a.longitude );
173 current_options.set_lat( a.latitude );
174 current_properties.setDoubleValue("/position/longitude",
176 current_properties.setDoubleValue("/position/latitude",
183 FG_LOG( FG_GENERAL, FG_INFO,
184 "Position for " << id << " is ("
185 << a.longitude << ", "
186 << a.latitude << ")" );
192 // Set current_options lon/lat given an airport id and heading (degrees)
193 bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
199 // set initial position from runway and heading
201 FGPath path( current_options.get_fg_root() );
202 path.append( "Airports" );
203 path.append( "runways.mk4" );
204 FGRunways runways( path.c_str() );
206 FG_LOG( FG_GENERAL, FG_INFO,
207 "Attempting to set starting position from runway code "
208 << id << " heading " << tgt_hdg );
210 // FGPath inpath( current_options.get_fg_root() );
211 // inpath.append( "Airports" );
212 // inpath.append( "apt_simple" );
213 // airports.load( inpath.c_str() );
215 // FGPath outpath( current_options.get_fg_root() );
216 // outpath.append( "Airports" );
217 // outpath.append( "simple.gdbm" );
218 // airports.dump_gdbm( outpath.c_str() );
220 if ( ! runways.search( id, &r ) ) {
221 FG_LOG( FG_GENERAL, FG_ALERT,
222 "Failed to find " << id << " in database." );
227 double min_diff = 360.0;
229 while ( r.id == id ) {
231 diff = tgt_hdg - r.heading;
232 while ( diff < -180.0 ) { diff += 360.0; }
233 while ( diff > 180.0 ) { diff -= 360.0; }
235 FG_LOG( FG_GENERAL, FG_INFO,
236 "Runway " << r.rwy_no << " heading = " << r.heading <<
237 " diff = " << diff );
238 if ( diff < min_diff ) {
245 diff = tgt_hdg - r.heading - 180.0;
246 while ( diff < -180.0 ) { diff += 360.0; }
247 while ( diff > 180.0 ) { diff -= 360.0; }
249 FG_LOG( FG_GENERAL, FG_INFO,
250 "Runway -" << r.rwy_no << " heading = " <<
252 " diff = " << diff );
253 if ( diff < min_diff ) {
262 FG_LOG( FG_GENERAL, FG_INFO, "closest runway = " << found_r.rwy_no
263 << " + " << found_dir );
269 double heading = found_r.heading + found_dir;
270 while ( heading >= 360.0 ) { heading -= 360.0; }
272 double lat2, lon2, az2;
273 double azimuth = found_r.heading + found_dir + 180.0;
274 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
276 FG_LOG( FG_GENERAL, FG_INFO,
277 "runway = " << found_r.lon << ", " << found_r.lat
278 << " length = " << found_r.length * FEET_TO_METER * 0.5
279 << " heading = " << azimuth );
280 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
281 azimuth, found_r.length * FEET_TO_METER * 0.5 - 5.0,
282 &lat2, &lon2, &az2 );
283 current_options.set_lon( lon2 );
284 current_options.set_lat( lat2 );
285 current_options.set_heading( heading );
286 current_properties.setDoubleValue("/position/longitude", lon2);
287 current_properties.setDoubleValue("/position/latitude", lat2);
288 current_properties.setDoubleValue("/orientation/heading", heading);
290 FG_LOG( FG_GENERAL, FG_INFO,
291 "Position for " << id << " is ("
293 << lat2 << ") new heading is "
300 // Set initial position and orientation
301 bool fgInitPosition( void ) {
302 FGInterface *f = current_aircraft.fdm_state;
303 string id = current_options.get_airport_id();
305 // set initial position from default or command line coordinates
306 f->set_Longitude( current_options.get_lon() * DEG_TO_RAD );
307 f->set_Latitude( current_options.get_lat() * DEG_TO_RAD );
309 if ( scenery.cur_elev > current_options.get_altitude() - 1) {
310 current_options.set_altitude( scenery.cur_elev + 1 );
313 FG_LOG( FG_GENERAL, FG_INFO,
314 "starting altitude is = " << current_options.get_altitude() );
316 f->set_Altitude( current_options.get_altitude() * METER_TO_FEET );
317 fgFDMSetGroundElevation( current_options.get_flight_model(),
318 f->get_Altitude() * FEET_TO_METER );
320 FG_LOG( FG_GENERAL, FG_INFO,
321 "Initial position is: ("
322 << (f->get_Longitude() * RAD_TO_DEG) << ", "
323 << (f->get_Latitude() * RAD_TO_DEG) << ", "
324 << (f->get_Altitude() * FEET_TO_METER) << ")" );
330 // General house keeping initializations
331 bool fgInitGeneral( void ) {
334 #if defined(FX) && defined(XMESA)
335 char *mesa_win_state;
338 FG_LOG( FG_GENERAL, FG_INFO, "General Initialization" );
339 FG_LOG( FG_GENERAL, FG_INFO, "======= ==============" );
341 root = current_options.get_fg_root();
342 if ( ! root.length() ) {
343 // No root path set? Then bail ...
344 FG_LOG( FG_GENERAL, FG_ALERT,
345 "Cannot continue without environment variable FG_ROOT"
346 << "being defined." );
349 FG_LOG( FG_GENERAL, FG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
351 #if defined(FX) && defined(XMESA)
352 // initialize full screen flag
353 global_fullscreen = false;
354 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
355 // Test for the MESA_GLX_FX env variable
356 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
357 // test if we are fullscreen mesa/glide
358 if ( (mesa_win_state[0] == 'f') ||
359 (mesa_win_state[0] == 'F') ) {
360 global_fullscreen = true;
370 // This is the top level init routine which calls all the other
371 // initialization routines. If you are adding a subsystem to flight
372 // gear, its initialization call should located in this routine.
373 // Returns non-zero if a problem encountered.
374 bool fgInitSubsystems( void ) {
375 fgLIGHT *l = &cur_light_params;
377 FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems");
378 FG_LOG( FG_GENERAL, FG_INFO, "========== ==========");
380 // Initialize the material property lib
381 FGPath mpath( current_options.get_fg_root() );
382 mpath.append( "materials" );
383 if ( material_lib.load( mpath.str() ) ) {
385 FG_LOG( FG_GENERAL, FG_ALERT, "Error loading material lib!" );
389 // Initialize the Scenery Management subsystem
390 if ( fgSceneryInit() ) {
391 // Material lib initialized ok.
393 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Scenery initialization!" );
397 if ( global_tile_mgr.init() ) {
398 // Load the local scenery data
399 global_tile_mgr.update( current_options.get_lon(),
400 current_options.get_lat() );
402 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
406 FG_LOG( FG_GENERAL, FG_DEBUG,
407 "Current terrain elevation after tile mgr init " <<
410 if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) {
411 cur_fdm_state = new FGLaRCsim;
412 } else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) {
413 cur_fdm_state = new FGJSBsim;
414 } else if ( current_options.get_flight_model() ==
415 FGInterface::FG_BALLOONSIM ) {
416 cur_fdm_state = new FGBalloonSim;
417 } else if ( current_options.get_flight_model() ==
418 FGInterface::FG_MAGICCARPET ) {
419 cur_fdm_state = new FGMagicCarpet;
420 } else if ( current_options.get_flight_model() ==
421 FGInterface::FG_EXTERNAL ) {
422 cur_fdm_state = new FGExternal;
424 FG_LOG( FG_GENERAL, FG_ALERT,
425 "No flight model, can't init aircraft" );
429 // allocates structures so must happen before any of the flight
430 // model or control parameters are set
431 fgAircraftInit(); // In the future this might not be the case.
433 // set the initial position
436 // Calculate ground elevation at starting point (we didn't have
437 // tmp_abs_view_pos calculated when fgTileMgrUpdate() was called above
439 // calculalate a cartesian point somewhere along the line between
440 // the center of the earth and our view position. Doesn't have to
441 // be the exact elevation (this is good because we don't know it
444 // now handled inside of the fgTileMgrUpdate()
447 geod_pos = Point3D( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(), 0.0);
448 tmp_abs_view_pos = sgGeodToCart(geod_pos);
450 FG_LOG( FG_GENERAL, FG_DEBUG,
451 "Initial abs_view_pos = " << tmp_abs_view_pos );
453 fgTileMgrCurElev( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(),
455 FG_LOG( FG_GENERAL, FG_DEBUG,
456 "Altitude after update " << scenery.cur_elev );
459 fgFDMSetGroundElevation( current_options.get_flight_model(),
462 // Reset our altitude if we are below ground
463 FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
464 FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
465 cur_fdm_state->get_Runway_altitude() );
467 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
468 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
471 FG_LOG( FG_GENERAL, FG_INFO,
472 "Updated position (after elevation adj): ("
473 << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
474 << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
475 << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
477 // We need to calculate a few more values here that would normally
478 // be calculated by the FDM so that the current_view.UpdateViewMath()
479 // routine doesn't get hosed.
481 double sea_level_radius_meters;
483 // Set the FG variables first
484 sgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
485 &sea_level_radius_meters, &lat_geoc);
486 cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(),
487 cur_fdm_state->get_Altitude() +
488 (sea_level_radius_meters * METER_TO_FEET) );
489 cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
491 cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
492 cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
494 cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
495 cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
497 // The following section sets up the flight model EOM parameters
498 // and should really be read in from one or more files.
501 cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
502 current_options.get_vBody(),
503 current_options.get_wBody());
505 // Initial Orientation
506 cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
507 current_options.get_pitch() * DEG_TO_RAD,
508 current_options.get_heading() * DEG_TO_RAD );
510 // Initial Angular Body rates
511 cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
513 cur_fdm_state->set_Earth_position_angle( 0.0 );
515 // Mass properties and geometry values
516 cur_fdm_state->set_Inertias( 8.547270E+01,
517 1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
519 // CG position w.r.t. ref. point
520 cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
522 // Initialize the event manager
523 global_events.Init();
525 // Output event stats every 60 seconds
526 global_events.Register( "fgEVENT_MGR::PrintStats()",
527 fgMethodCallback<fgEVENT_MGR>( &global_events,
528 &fgEVENT_MGR::PrintStats),
529 fgEVENT::FG_EVENT_READY, 60000 );
531 // Initialize view parameters
532 FG_LOG( FG_GENERAL, FG_DEBUG, "Before current_view.init()");
535 FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
536 current_view.UpdateViewMath(*cur_fdm_state);
537 pilot_view.UpdateViewMath(*cur_fdm_state);
538 FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << current_view.get_abs_view_pos());
539 // current_view.UpdateWorldToEye(f);
541 // Initialize the planetary subsystem
542 // global_events.Register( "fgPlanetsInit()", fgPlanetsInit,
543 // fgEVENT::FG_EVENT_READY, 600000);
545 // Initialize the sun's position
546 // global_events.Register( "fgSunInit()", fgSunInit,
547 // fgEVENT::FG_EVENT_READY, 30000 );
549 // Intialize the moon's position
550 // global_events.Register( "fgMoonInit()", fgMoonInit,
551 // fgEVENT::FG_EVENT_READY, 600000 );
553 // fgUpdateSunPos() needs a few position and view parameters set
554 // so it can calculate local relative sun angle and a few other
555 // things for correctly orienting the sky.
558 global_events.Register( "fgUpdateSunPos()", fgUpdateSunPos,
559 fgEVENT::FG_EVENT_READY, 60000);
560 global_events.Register( "fgUpdateMoonPos()", fgUpdateMoonPos,
561 fgEVENT::FG_EVENT_READY, 60000);
563 // Initialize Lighting interpolation tables
566 // update the lighting parameters (based on sun angle)
567 global_events.Register( "fgLight::Update()",
568 fgMethodCallback<fgLIGHT>( &cur_light_params,
570 fgEVENT::FG_EVENT_READY, 30000 );
571 // update the current timezone each 30 minutes
572 global_events.Register( "fgUpdateLocalTime()", fgUpdateLocalTime,
573 fgEVENT::FG_EVENT_READY, 1800000);
575 // Initialize the weather modeling subsystem
576 #ifndef FG_OLD_WEATHER
577 // Initialize the WeatherDatabase
578 FG_LOG(FG_GENERAL, FG_INFO, "Creating LocalWeatherDatabase");
580 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
581 current_aircraft.fdm_state->get_Longitude(),
582 current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER );
583 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
584 new FGLocalWeatherDatabase( position, current_options.get_fg_root() );
585 // cout << theFGLocalWeatherDatabase << endl;
586 // cout << "visibility = "
587 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
589 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
591 // register the periodic update of the weather
592 global_events.Register( "weather update", fgUpdateWeatherDatabase,
593 fgEVENT::FG_EVENT_READY, 30000);
595 current_weather.Init();
598 // Initialize vor/ndb/ils/fix list management and query systems
599 FG_LOG(FG_GENERAL, FG_INFO, "Loading Navaids");
601 FG_LOG(FG_GENERAL, FG_INFO, " VOR/NDB");
602 current_navlist = new FGNavList;
603 FGPath p_nav( current_options.get_fg_root() );
604 p_nav.append( "Navaids/default.nav" );
605 current_navlist->init( p_nav );
607 FG_LOG(FG_GENERAL, FG_INFO, " ILS");
608 current_ilslist = new FGILSList;
609 FGPath p_ils( current_options.get_fg_root() );
610 p_ils.append( "Navaids/default.ils" );
611 current_ilslist->init( p_ils );
613 FG_LOG(FG_GENERAL, FG_INFO, " Fixes");
614 current_fixlist = new FGFixList;
615 FGPath p_fix( current_options.get_fg_root() );
616 p_fix.append( "Navaids/default.fix" );
617 current_fixlist->init( p_fix );
619 // Initialize the underlying radio stack model
620 current_radiostack = new FGRadioStack;
622 // current_radiostack->set_nav1_freq( 117.30 );
623 // current_radiostack->set_nav1_alt_freq( 110.30 );
624 // current_radiostack->set_nav1_sel_radial( 119.0 );
626 // current_radiostack->set_nav2_freq( 111.80 );
627 // current_radiostack->set_nav2_alt_freq( 115.70 );
628 // current_radiostack->set_nav2_sel_radial( 029.0 );
630 // current_radiostack->set_adf_freq( 266.0 );
633 // This block of settings are Alex's defaults for San Diego
634 current_radiostack->set_nav1_freq( 111.70 );
635 current_radiostack->set_nav1_alt_freq( 115.30 );
636 current_radiostack->set_nav1_sel_radial( 280.0 );
637 current_radiostack->set_nav2_freq( 117.80 );
638 current_radiostack->set_nav2_alt_freq( 114.00 );
639 current_radiostack->set_nav2_sel_radial( 68.0 );
640 current_radiostack->set_adf_freq( 210.0 );
641 // End of Alex's custom settings
644 current_radiostack->search( cur_fdm_state->get_Longitude(),
645 cur_fdm_state->get_Latitude(),
646 cur_fdm_state->get_Altitude() * FEET_TO_METER );
648 current_radiostack->update( cur_fdm_state->get_Longitude(),
649 cur_fdm_state->get_Latitude(),
650 cur_fdm_state->get_Altitude() * FEET_TO_METER );
652 // Search radio database once per second
653 global_events.Register( "fgRadioSearch()", fgRadioSearch,
654 fgEVENT::FG_EVENT_READY, 1000);
657 // Initialize the Cockpit subsystem
658 if( fgCockpitInit( ¤t_aircraft )) {
659 // Cockpit initialized ok.
661 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Cockpit initialization!" );
665 // Initialize the flight model subsystem data structures base on
668 // fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
669 // 1.0 / current_options.get_model_hz() );
670 cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
672 // I'm just sticking this here for now, it should probably move
674 scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
676 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
677 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
680 FG_LOG( FG_GENERAL, FG_INFO,
681 "Updated position (after elevation adj): ("
682 << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
683 << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
684 << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
685 // end of thing that I just stuck in that I should probably move
688 if ( fgJoystickInit() ) {
689 // Joystick initialized ok.
691 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Joystick initialization!" );
695 current_autopilot = new FGAutopilot;
696 current_autopilot->init();
698 // initialize the gui parts of the autopilot
704 // Initialize I/O channels
705 #if ! defined( macintosh )
709 // Initialize the 2D panel.
711 current_properties.getStringValue("/sim/panel/path",
712 "Panels/Default/default.xml");
713 current_panel = fgReadPanel(panel_path);
714 if (current_panel == 0) {
715 FG_LOG(FG_INPUT, FG_ALERT,
716 "Error reading new panel from " << panel_path);
718 FG_LOG(FG_INPUT, FG_INFO, "Loaded new panel from " << panel_path);
720 // Initialize the BFI
723 FG_LOG( FG_GENERAL, FG_INFO, endl);
729 void fgReInitSubsystems( void )
731 bool freeze = globals->get_freeze();
733 globals->set_freeze( true );
735 if( global_tile_mgr.init() ) {
736 // Load the local scenery data
737 global_tile_mgr.update( current_options.get_lon(),
738 current_options.get_lat() );
740 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
744 // cout << "current scenery elev = " << scenery.cur_elev << endl;
747 fgFDMSetGroundElevation( current_options.get_flight_model(),
750 // Reset our altitude if we are below ground
751 FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
752 FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
753 cur_fdm_state->get_Runway_altitude() );
755 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
756 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
758 double sea_level_radius_meters;
760 // Set the FG variables first
761 sgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
762 &sea_level_radius_meters, &lat_geoc);
763 cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(),
764 cur_fdm_state->get_Altitude() +
765 (sea_level_radius_meters * METER_TO_FEET) );
766 cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
768 cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
769 cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
771 cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
772 cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
774 // The following section sets up the flight model EOM parameters
775 // and should really be read in from one or more files.
778 cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
779 current_options.get_vBody(),
780 current_options.get_wBody());
782 // Initial Orientation
783 cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
784 current_options.get_pitch() * DEG_TO_RAD,
785 current_options.get_heading() * DEG_TO_RAD );
787 // Initial Angular Body rates
788 cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
790 cur_fdm_state->set_Earth_position_angle( 0.0 );
792 // Mass properties and geometry values
793 cur_fdm_state->set_Inertias( 8.547270E+01,
794 1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
796 // CG position w.r.t. ref. point
797 cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
799 // Initialize view parameters
800 current_view.set_view_offset( 0.0 );
801 current_view.set_goal_view_offset( 0.0 );
802 pilot_view.set_view_offset( 0.0 );
803 pilot_view.set_goal_view_offset( 0.0 );
805 FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
806 current_view.UpdateViewMath(*cur_fdm_state);
807 pilot_view.UpdateViewMath(*cur_fdm_state);
808 FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << current_view.get_abs_view_pos());
810 // fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
811 // 1.0 / current_options.get_model_hz() );
812 cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
814 scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
816 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
817 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
820 controls.reset_all();
821 current_autopilot->reset();
824 globals->set_freeze( false );