1 // bfi.cxx - Big Friendly Interface implementation
3 // Written by David Megginson, started February, 2000.
5 // Copyright (C) 2000 David Megginson - david@megginson.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.
28 #if defined( FG_HAVE_NATIVE_SGI_COMPILERS )
29 # include <iostream.h>
34 #include <simgear/constants.h>
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/ephemeris/ephemeris.hxx>
37 #include <simgear/math/sg_types.hxx>
38 #include <simgear/misc/props.hxx>
39 #include <simgear/timing/sg_time.hxx>
41 #include <Aircraft/aircraft.hxx>
42 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
43 #include <Controls/controls.hxx>
44 #include <Autopilot/newauto.hxx>
45 #include <Scenery/scenery.hxx>
46 #include <Time/light.hxx>
47 #include <Time/event.hxx>
48 #include <Time/sunpos.hxx>
49 #include <Time/tmp.hxx>
50 #include <Cockpit/radiostack.hxx>
51 #include <Cockpit/panel.hxx>
52 #ifndef FG_OLD_WEATHER
53 # include <WeatherCM/FGLocalWeatherDatabase.h>
55 # include <Weather/weather.hxx>
58 #include "globals.hxx"
60 #include "fg_init.hxx"
61 #include <simgear/misc/props.hxx>
63 FG_USING_NAMESPACE(std);
70 ////////////////////////////////////////////////////////////////////////
72 ////////////////////////////////////////////////////////////////////////
74 // Yech -- not thread-safe, etc. etc.
75 static bool _needReinit = false;
78 static inline void needReinit ()
85 * Reinitialize FGFS to use the new BFI settings.
90 // Save the state of everything
91 // that's going to get clobbered
92 // when we reinit the subsystems.
94 cout << "BFI: start reinit\n";
96 // TODO: add more AP stuff
97 double elevator = FGBFI::getElevator();
98 double aileron = FGBFI::getAileron();
99 double rudder = FGBFI::getRudder();
100 double throttle = FGBFI::getThrottle();
101 double elevator_trim = FGBFI::getElevatorTrim();
102 double flaps = FGBFI::getFlaps();
103 double brake = FGBFI::getBrakes();
104 bool apHeadingLock = FGBFI::getAPHeadingLock();
105 double apHeadingMag = FGBFI::getAPHeadingMag();
106 bool apAltitudeLock = FGBFI::getAPAltitudeLock();
107 double apAltitude = FGBFI::getAPAltitude();
108 const string &targetAirport = FGBFI::getTargetAirport();
109 bool gpsLock = FGBFI::getGPSLock();
110 // double gpsLatitude = FGBFI::getGPSTargetLatitude();
111 // double gpsLongitude = FGBFI::getGPSTargetLongitude();
113 FGBFI::setTargetAirport("");
114 cout << "Target airport is " << globals->get_options()->get_airport_id() << endl;
116 fgReInitSubsystems();
118 // FIXME: this is wrong.
119 // All of these are scheduled events,
120 // and it should be possible to force
121 // them all to run once.
124 cur_light_params.Update();
126 fgUpdateWeatherDatabase();
129 // Restore all of the old states.
130 FGBFI::setElevator(elevator);
131 FGBFI::setAileron(aileron);
132 FGBFI::setRudder(rudder);
133 FGBFI::setThrottle(throttle);
134 FGBFI::setElevatorTrim(elevator_trim);
135 FGBFI::setFlaps(flaps);
136 FGBFI::setBrakes(brake);
137 FGBFI::setAPHeadingLock(apHeadingLock);
138 FGBFI::setAPHeadingMag(apHeadingMag);
139 FGBFI::setAPAltitudeLock(apAltitudeLock);
140 FGBFI::setAPAltitude(apAltitude);
141 FGBFI::setTargetAirport(targetAirport);
142 FGBFI::setGPSLock(gpsLock);
146 cout << "BFI: end reinit\n";
149 // BEGIN: kludge 2000-12-07
150 // This is a kludge around a LaRCsim problem; see setAltitude()
152 static int _altitude_countdown = 0;
153 static double _requested_altitude = -9999;
154 static bool _saved_freeze = false;
155 static inline void _check_altitude ()
157 if (_altitude_countdown > 0) {
158 _altitude_countdown--;
159 if (_altitude_countdown == 0) {
160 current_aircraft.fdm_state->set_Altitude(_requested_altitude);
161 globals->set_freeze(_saved_freeze);
166 static int _lighting_countdown = 0;
167 static inline void _check_lighting ()
169 if (_lighting_countdown > 0) {
170 _lighting_countdown--;
171 if (_lighting_countdown == 0)
172 fgUpdateSkyAndLightingParams();
179 ////////////////////////////////////////////////////////////////////////
181 ////////////////////////////////////////////////////////////////////////
185 * Initialize the BFI by binding its functions to properties.
187 * TODO: perhaps these should migrate into the individual modules
188 * (i.e. they should register themselves).
193 FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init");
195 current_properties.tieInt("/sim/flight-model",
196 getFlightModel, setFlightModel);
197 current_properties.tieString("/sim/aircraft",
198 getAircraft, setAircraft);
199 current_properties.tieString("/sim/aircraft-dir",
200 getAircraftDir, setAircraftDir);
202 current_properties.tieString("/sim/time/gmt",
203 getDateString, setDateString);
204 current_properties.tieString("/sim/time/gmt-string",
206 current_properties.tieBool("/sim/hud/visibility",
207 getHUDVisible, setHUDVisible);
208 current_properties.tieBool("/sim/panel/visibility",
209 getPanelVisible, setPanelVisible);
210 current_properties.tieInt("/sim/panel/x-offset",
211 getPanelXOffset, setPanelXOffset);
212 current_properties.tieInt("/sim/panel/y-offset",
213 getPanelYOffset, setPanelYOffset);
216 current_properties.tieString("/position/airport-id",
217 getTargetAirport, setTargetAirport);
218 current_properties.tieDouble("/position/latitude",
219 getLatitude, setLatitude);
220 current_properties.tieDouble("/position/longitude",
221 getLongitude, setLongitude);
222 current_properties.tieDouble("/position/altitude",
223 getAltitude, setAltitude);
224 // getAltitude, setAltitude, false);
225 current_properties.tieDouble("/position/altitude-agl",
229 current_properties.tieDouble("/orientation/heading",
230 getHeading, setHeading);
231 current_properties.tieDouble("/orientation/heading-magnetic",
233 current_properties.tieDouble("/orientation/pitch",
235 current_properties.tieDouble("/orientation/roll",
239 current_properties.tieDouble("/engines/engine0/rpm",
241 current_properties.tieDouble("/engines/engine0/egt",
243 current_properties.tieDouble("/engines/engine0/cht",
245 current_properties.tieDouble("/engines/engine0/mp",
249 current_properties.tieDouble("/velocities/airspeed",
250 getAirspeed, setAirspeed);
251 current_properties.tieDouble("/velocities/side-slip",
253 current_properties.tieDouble("/velocities/vertical-speed",
254 getVerticalSpeed, 0);
255 current_properties.tieDouble("/velocities/speed-north",
257 current_properties.tieDouble("/velocities/speed-east",
259 current_properties.tieDouble("/velocities/speed-down",
263 current_properties.tieDouble("/controls/throttle",
264 getThrottle, setThrottle);
265 current_properties.tieDouble("/controls/mixture",
266 getMixture, setMixture);
267 current_properties.tieDouble("/controls/propellor-pitch",
268 getPropAdvance, setPropAdvance);
269 current_properties.tieDouble("/controls/flaps",
271 current_properties.tieDouble("/controls/aileron",
272 getAileron, setAileron);
273 current_properties.tieDouble("/controls/rudder",
274 getRudder, setRudder);
275 current_properties.tieDouble("/controls/elevator",
276 getElevator, setElevator);
277 current_properties.tieDouble("/controls/elevator-trim",
278 getElevatorTrim, setElevatorTrim);
279 current_properties.tieDouble("/controls/brakes/all",
280 getBrakes, setBrakes);
281 current_properties.tieDouble("/controls/brakes/left",
282 getLeftBrake, setLeftBrake);
283 current_properties.tieDouble("/controls/brakes/right",
284 getRightBrake, setRightBrake);
285 current_properties.tieDouble("/controls/brakes/center",
286 getRightBrake, setCenterBrake);
289 current_properties.tieBool("/autopilot/locks/altitude",
290 getAPAltitudeLock, setAPAltitudeLock);
291 current_properties.tieDouble("/autopilot/settings/altitude",
292 getAPAltitude, setAPAltitude);
293 current_properties.tieBool("/autopilot/locks/heading",
294 getAPHeadingLock, setAPHeadingLock);
295 current_properties.tieDouble("/autopilot/settings/heading",
296 getAPHeading, setAPHeading);
297 current_properties.tieDouble("/autopilot/settings/heading-magnetic",
298 getAPHeadingMag, setAPHeadingMag);
299 current_properties.tieBool("/autopilot/locks/nav1",
300 getAPNAV1Lock, setAPNAV1Lock);
303 current_properties.tieDouble("/radios/nav1/frequencies/selected",
304 getNAV1Freq, setNAV1Freq);
305 current_properties.tieDouble("/radios/nav1/frequencies/standby",
306 getNAV1AltFreq, setNAV1AltFreq);
307 current_properties.tieDouble("/radios/nav1/radials/actual",
309 current_properties.tieDouble("/radios/nav1/radials/selected",
310 getNAV1SelRadial, setNAV1SelRadial);
311 current_properties.tieDouble("/radios/nav1/dme/distance",
313 current_properties.tieBool("/radios/nav1/to-flag",
315 current_properties.tieBool("/radios/nav1/from-flag",
317 current_properties.tieBool("/radios/nav1/in-range",
319 current_properties.tieBool("/radios/nav1/dme/in-range",
320 getNAV1DMEInRange, 0);
322 current_properties.tieDouble("/radios/nav2/frequencies/selected",
323 getNAV2Freq, setNAV2Freq);
324 current_properties.tieDouble("/radios/nav2/frequencies/standby",
325 getNAV2AltFreq, setNAV2AltFreq);
326 current_properties.tieDouble("/radios/nav2/radials/actual",
328 current_properties.tieDouble("/radios/nav2/radials/selected",
329 getNAV2SelRadial, setNAV2SelRadial);
330 current_properties.tieDouble("/radios/nav2/dme/distance",
332 current_properties.tieBool("/radios/nav2/to-flag",
334 current_properties.tieBool("/radios/nav2/from-flag",
336 current_properties.tieBool("/radios/nav2/in-range",
338 current_properties.tieBool("/radios/nav2/dme/in-range",
339 getNAV2DMEInRange, 0);
341 current_properties.tieDouble("/radios/adf/frequencies/selected",
342 getADFFreq, setADFFreq);
343 current_properties.tieDouble("/radios/adf/frequencies/standby",
344 getADFAltFreq, setADFAltFreq);
345 current_properties.tieDouble("/radios/adf/rotation",
346 getADFRotation, setADFRotation);
348 current_properties.tieDouble("/environment/visibility",
349 getVisibility, setVisibility);
353 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
358 * Reinitialize FGFS if required.
360 * Some changes (especially those in aircraft position) require that
361 * FGFS be reinitialized afterwards. Rather than reinitialize after
362 * every change, the setter methods simply set a flag so that there
363 * can be a single reinit at the end of the frame.
377 ////////////////////////////////////////////////////////////////////////
379 ////////////////////////////////////////////////////////////////////////
383 * Return the flight model as an integer.
385 * TODO: use a string instead.
388 FGBFI::getFlightModel ()
390 return globals->get_options()->get_flight_model();
395 * Return the current aircraft as a string.
398 FGBFI::getAircraft ()
400 _temp = globals->get_options()->get_aircraft();
406 * Return the current aircraft directory (UIUC) as a string.
409 FGBFI::getAircraftDir ()
411 _temp = aircraft_dir;
417 * Set the flight model as an integer.
419 * TODO: use a string instead.
422 FGBFI::setFlightModel (int model)
424 if (getFlightModel() != model) {
425 globals->get_options()->set_flight_model(model);
432 * Set the current aircraft.
435 FGBFI::setAircraft (const string &aircraft)
437 if (getAircraft() != aircraft) {
438 globals->get_options()->set_aircraft(aircraft);
445 * Set the current aircraft directory (UIUC).
448 FGBFI::setAircraftDir (const string &dir)
450 if (getAircraftDir() != dir) {
458 * Return the current Zulu time.
461 FGBFI::getDateString ()
463 static string out; // FIXME: not thread-safe
465 struct tm * t = globals->get_time_params()->getGmt();
466 sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
467 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
468 t->tm_hour, t->tm_min, t->tm_sec);
475 * Set the current Zulu time.
478 FGBFI::setDateString (const string &date_string)
479 // FGBFI::setTimeGMT (time_t time)
481 SGTime * st = globals->get_time_params();
482 struct tm * current_time = st->getGmt();
485 // Scan for basic ISO format
486 // YYYY-MM-DDTHH:MM:SS
487 int ret = sscanf(date_string.c_str(), "%d-%d-%dT%d:%d:%d",
488 &(new_time.tm_year), &(new_time.tm_mon),
489 &(new_time.tm_mday), &(new_time.tm_hour),
490 &(new_time.tm_min), &(new_time.tm_sec));
492 // Be pretty picky about this, so
493 // that strange things don't happen
494 // if the save file has been edited
497 FG_LOG(FG_INPUT, FG_ALERT, "Date/time string " << date_string
498 << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
502 // OK, it looks like we got six
503 // values, one way or another.
504 new_time.tm_year -= 1900;
505 new_time.tm_mon -= 1;
507 // Now, tell flight gear to use
508 // the new time. This was far
509 // too difficult, by the way.
511 mktime(&new_time) - mktime(current_time) + globals->get_warp();
512 double lon = current_aircraft.fdm_state->get_Longitude();
513 double lat = current_aircraft.fdm_state->get_Latitude();
514 double alt = current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER;
515 globals->set_warp(warp);
516 st->update(lon, lat, warp);
517 fgUpdateSkyAndLightingParams();
522 * Return the GMT as a string.
525 FGBFI::getGMTString ()
527 static string out; // FIXME: not thread-safe
529 struct tm * t = globals->get_time_params()->getGmt();
530 sprintf(buf, " %.2d:%.2d:%.2d",
531 t->tm_hour, t->tm_min, t->tm_sec);
538 * Return true if the HUD is visible.
541 FGBFI::getHUDVisible ()
543 return globals->get_options()->get_hud_status();
548 * Ensure that the HUD is visible or hidden.
551 FGBFI::setHUDVisible (bool visible)
553 globals->get_options()->set_hud_status(visible);
558 * Return true if the 2D panel is visible.
561 FGBFI::getPanelVisible ()
563 return globals->get_options()->get_panel_status();
568 * Ensure that the 2D panel is visible or hidden.
571 FGBFI::setPanelVisible (bool visible)
573 if (globals->get_options()->get_panel_status() != visible) {
574 globals->get_options()->toggle_panel();
580 * Get the panel's current x-shift.
583 FGBFI::getPanelXOffset ()
585 if (current_panel != 0)
586 return current_panel->getXOffset();
593 * Set the panel's current x-shift.
596 FGBFI::setPanelXOffset (int offset)
598 if (current_panel != 0)
599 current_panel->setXOffset(offset);
604 * Get the panel's current y-shift.
607 FGBFI::getPanelYOffset ()
609 if (current_panel != 0)
610 return current_panel->getYOffset();
617 * Set the panel's current y-shift.
620 FGBFI::setPanelYOffset (int offset)
622 if (current_panel != 0)
623 current_panel->setYOffset(offset);
630 ////////////////////////////////////////////////////////////////////////
632 ////////////////////////////////////////////////////////////////////////
636 * Return the current latitude in degrees (negative for south).
639 FGBFI::getLatitude ()
641 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
646 * Set the current latitude in degrees (negative for south).
649 FGBFI::setLatitude (double latitude)
651 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
652 fgUpdateSkyAndLightingParams();
653 if (_lighting_countdown <= 0)
654 _lighting_countdown = 5;
659 * Return the current longitude in degrees (negative for west).
662 FGBFI::getLongitude ()
664 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
669 * Set the current longitude in degrees (negative for west).
672 FGBFI::setLongitude (double longitude)
674 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
675 fgUpdateSkyAndLightingParams();
676 if (_lighting_countdown <= 0)
677 _lighting_countdown = 5;
682 * Return the current altitude in feet.
685 FGBFI::getAltitude ()
687 return current_aircraft.fdm_state->get_Altitude();
693 * Return the current altitude in above the terrain.
698 return current_aircraft.fdm_state->get_Altitude()
699 - (scenery.cur_elev * METER_TO_FEET);
704 * Set the current altitude in feet.
707 FGBFI::setAltitude (double altitude)
709 current_aircraft.fdm_state->set_Altitude(altitude);
712 // This is an ugly kludge around a
713 // LaRCsim problem; if the
714 // requested altitude cannot be
715 // set right away (because it's
716 // below the last-calculated ground
717 // level), pause FGFS, wait for
718 // five frames, and then try again.
719 if (_altitude_countdown <= 0 &&
720 fabs(getAltitude() - altitude) > 5.0) {
721 _altitude_countdown = 5;
722 _requested_altitude = altitude;
723 _saved_freeze = globals->get_freeze();
724 globals->set_freeze(true);
730 ////////////////////////////////////////////////////////////////////////
732 ////////////////////////////////////////////////////////////////////////
736 * Return the current heading in degrees.
741 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
746 * Return the current heading in degrees.
749 FGBFI::getHeadingMag ()
751 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
756 * Set the current heading in degrees.
759 FGBFI::setHeading (double heading)
761 FGInterface * fdm = current_aircraft.fdm_state;
762 fdm->set_Euler_Angles(fdm->get_Phi(), fdm->get_Theta(),
763 heading * DEG_TO_RAD);
768 * Return the current pitch in degrees.
773 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
778 * Set the current pitch in degrees.
781 FGBFI::setPitch (double pitch)
783 FGInterface * fdm = current_aircraft.fdm_state;
784 fdm->set_Euler_Angles(fdm->get_Phi(), pitch * DEG_TO_RAD, fdm->get_Psi());
789 * Return the current roll in degrees.
794 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
799 * Set the current roll in degrees.
802 FGBFI::setRoll (double roll)
804 FGInterface * fdm = current_aircraft.fdm_state;
805 fdm->set_Euler_Angles(roll * DEG_TO_RAD, fdm->get_Theta(), fdm->get_Psi());
810 * Return the current engine0 rpm
815 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
816 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
824 * Set the current engine0 rpm
827 FGBFI::setRPM (double rpm)
829 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
830 if (getRPM() != rpm) {
831 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
838 * Return the current engine0 EGT.
843 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
844 return current_aircraft.fdm_state->get_engine(0)->get_EGT();
852 * Return the current engine0 CHT.
857 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
858 return current_aircraft.fdm_state->get_engine(0)->get_CHT();
866 * Return the current engine0 CHT.
871 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
872 return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
880 ////////////////////////////////////////////////////////////////////////
882 ////////////////////////////////////////////////////////////////////////
886 * Return the current airspeed in knots.
889 FGBFI::getAirspeed ()
891 // FIXME: should we add speed-up?
892 return current_aircraft.fdm_state->get_V_calibrated_kts();
897 * Set the calibrated airspeed in knots.
900 FGBFI::setAirspeed (double speed)
902 current_aircraft.fdm_state->set_V_calibrated_kts(speed);
907 * Return the current sideslip (FIXME: units unknown).
910 FGBFI::getSideSlip ()
912 return current_aircraft.fdm_state->get_Beta();
917 * Return the current climb rate in feet/minute
920 FGBFI::getVerticalSpeed ()
922 // What about meters?
923 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
928 * Get the current north velocity (units??).
931 FGBFI::getSpeedNorth ()
933 return current_aircraft.fdm_state->get_V_north();
938 // * Set the current north velocity (units??).
941 // FGBFI::setSpeedNorth (double speed)
943 // FGInterface * fdm = current_aircraft.fdm_state;
944 // // fdm->set_Velocities_Local(speed, fdm->get_V_east(), fdm->get_V_down());
949 * Get the current east velocity (units??).
952 FGBFI::getSpeedEast ()
954 return current_aircraft.fdm_state->get_V_east();
959 // * Set the current east velocity (units??).
962 // FGBFI::setSpeedEast (double speed)
964 // FGInterface * fdm = current_aircraft.fdm_state;
965 // // fdm->set_Velocities_Local(fdm->get_V_north(), speed, fdm->get_V_down());
970 * Get the current down velocity (units??).
973 FGBFI::getSpeedDown ()
975 return current_aircraft.fdm_state->get_V_down();
980 // * Set the current down velocity (units??).
983 // FGBFI::setSpeedDown (double speed)
985 // FGInterface * fdm = current_aircraft.fdm_state;
986 // // fdm->set_Velocities_Local(fdm->get_V_north(), fdm->get_V_east(), speed);
991 ////////////////////////////////////////////////////////////////////////
993 ////////////////////////////////////////////////////////////////////////
997 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
1000 FGBFI::getThrottle ()
1002 // FIXME: add engine selector
1003 return controls.get_throttle(0);
1008 * Set the throttle, from 0.0 (none) to 1.0 (full).
1011 FGBFI::setThrottle (double throttle)
1013 // FIXME: allow engine selection
1014 controls.set_throttle(0, throttle);
1019 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
1022 FGBFI::getMixture ()
1024 // FIXME: add engine selector
1025 return controls.get_mixture(0);
1030 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
1033 FGBFI::setMixture (double mixture)
1035 // FIXME: allow engine selection
1036 controls.set_mixture(0, mixture);
1041 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
1044 FGBFI::getPropAdvance ()
1046 // FIXME: add engine selector
1047 return controls.get_prop_advance(0);
1052 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
1055 FGBFI::setPropAdvance (double pitch)
1057 // FIXME: allow engine selection
1058 controls.set_prop_advance(0, pitch);
1063 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
1068 return controls.get_flaps();
1073 * Set the flaps, from 0.0 (none) to 1.0 (full).
1076 FGBFI::setFlaps (double flaps)
1079 controls.set_flaps(flaps);
1084 * Get the aileron, from -1.0 (left) to 1.0 (right).
1087 FGBFI::getAileron ()
1089 return controls.get_aileron();
1094 * Set the aileron, from -1.0 (left) to 1.0 (right).
1097 FGBFI::setAileron (double aileron)
1100 controls.set_aileron(aileron);
1105 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
1110 return controls.get_rudder();
1115 * Set the rudder, from -1.0 (left) to 1.0 (right).
1118 FGBFI::setRudder (double rudder)
1121 controls.set_rudder(rudder);
1126 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
1129 FGBFI::getElevator ()
1131 return controls.get_elevator();
1136 * Set the elevator, from -1.0 (down) to 1.0 (up).
1139 FGBFI::setElevator (double elevator)
1142 controls.set_elevator(elevator);
1147 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
1150 FGBFI::getElevatorTrim ()
1152 return controls.get_elevator_trim();
1157 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
1160 FGBFI::setElevatorTrim (double trim)
1163 controls.set_elevator_trim(trim);
1168 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1173 double b1 = getCenterBrake();
1174 double b2 = getLeftBrake();
1175 double b3 = getRightBrake();
1176 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1181 * Set all brakes, from 0.0 (none) to 1.0 (full).
1184 FGBFI::setBrakes (double brake)
1186 setCenterBrake(brake);
1187 setLeftBrake(brake);
1188 setRightBrake(brake);
1193 * Get the center brake, from 0.0 (none) to 1.0 (full).
1196 FGBFI::getCenterBrake ()
1198 return controls.get_brake(2);
1203 * Set the center brake, from 0.0 (none) to 1.0 (full).
1206 FGBFI::setCenterBrake (double brake)
1208 controls.set_brake(2, brake);
1213 * Get the left brake, from 0.0 (none) to 1.0 (full).
1216 FGBFI::getLeftBrake ()
1218 return controls.get_brake(0);
1223 * Set the left brake, from 0.0 (none) to 1.0 (full).
1226 FGBFI::setLeftBrake (double brake)
1228 controls.set_brake(0, brake);
1233 * Get the right brake, from 0.0 (none) to 1.0 (full).
1236 FGBFI::getRightBrake ()
1238 return controls.get_brake(1);
1243 * Set the right brake, from 0.0 (none) to 1.0 (full).
1246 FGBFI::setRightBrake (double brake)
1248 controls.set_brake(1, brake);
1255 ////////////////////////////////////////////////////////////////////////
1257 ////////////////////////////////////////////////////////////////////////
1261 * Get the autopilot altitude lock (true=on).
1264 FGBFI::getAPAltitudeLock ()
1266 return current_autopilot->get_AltitudeEnabled();
1271 * Set the autopilot altitude lock (true=on).
1274 FGBFI::setAPAltitudeLock (bool lock)
1276 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1277 current_autopilot->set_AltitudeEnabled(lock);
1282 * Get the autopilot target altitude in feet.
1285 FGBFI::getAPAltitude ()
1287 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1292 * Set the autopilot target altitude in feet.
1295 FGBFI::setAPAltitude (double altitude)
1297 current_autopilot->set_TargetAltitude( altitude );
1302 * Get the autopilot heading lock (true=on).
1305 FGBFI::getAPHeadingLock ()
1308 (current_autopilot->get_HeadingEnabled() &&
1309 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1314 * Set the autopilot heading lock (true=on).
1317 FGBFI::setAPHeadingLock (bool lock)
1320 // We need to do this so that
1321 // it's possible to lock onto a
1322 // heading other than the current
1324 double heading = getAPHeadingMag();
1325 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1326 current_autopilot->set_HeadingEnabled(true);
1327 setAPHeadingMag(heading);
1328 } else if (current_autopilot->get_HeadingMode() ==
1329 FGAutopilot::FG_HEADING_LOCK) {
1330 current_autopilot->set_HeadingEnabled(false);
1336 * Get the autopilot target heading in degrees.
1339 FGBFI::getAPHeading ()
1341 return current_autopilot->get_TargetHeading();
1346 * Set the autopilot target heading in degrees.
1349 FGBFI::setAPHeading (double heading)
1351 current_autopilot->set_TargetHeading( heading );
1356 * Get the autopilot target heading in degrees.
1359 FGBFI::getAPHeadingMag ()
1361 return current_autopilot->get_TargetHeading() - getMagVar();
1366 * Set the autopilot target heading in degrees.
1369 FGBFI::setAPHeadingMag (double heading)
1371 current_autopilot->set_TargetHeading( heading + getMagVar() );
1376 * Return true if the autopilot is locked to NAV1.
1379 FGBFI::getAPNAV1Lock ()
1382 (current_autopilot->get_HeadingEnabled() &&
1383 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1388 * Set the autopilot NAV1 lock.
1391 FGBFI::setAPNAV1Lock (bool lock)
1394 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1395 current_autopilot->set_HeadingEnabled(true);
1396 } else if (current_autopilot->get_HeadingMode() ==
1397 FGAutopilot::FG_HEADING_NAV1) {
1398 current_autopilot->set_HeadingEnabled(false);
1404 ////////////////////////////////////////////////////////////////////////
1405 // Radio navigation.
1406 ////////////////////////////////////////////////////////////////////////
1409 FGBFI::getNAV1Freq ()
1411 return current_radiostack->get_nav1_freq();
1415 FGBFI::getNAV1AltFreq ()
1417 return current_radiostack->get_nav1_alt_freq();
1421 FGBFI::getNAV1Radial ()
1423 return current_radiostack->get_nav1_radial();
1427 FGBFI::getNAV1SelRadial ()
1429 return current_radiostack->get_nav1_sel_radial();
1433 FGBFI::getNAV1DistDME ()
1435 return current_radiostack->get_nav1_dme_dist();
1441 if (current_radiostack->get_nav1_inrange()) {
1442 double heading = current_radiostack->get_nav1_heading();
1443 double radial = current_radiostack->get_nav1_radial();
1444 double var = FGBFI::getMagVar();
1445 if (current_radiostack->get_nav1_loc()) {
1446 double offset = fabs(heading - radial);
1447 return (offset<= 8.0 || offset >= 352.0);
1450 fabs(heading - var - radial);
1451 return (offset <= 20.0 || offset >= 340.0);
1459 FGBFI::getNAV1FROM ()
1461 if (current_radiostack->get_nav1_inrange()) {
1462 double heading = current_radiostack->get_nav1_heading();
1463 double radial = current_radiostack->get_nav1_radial();
1464 double var = FGBFI::getMagVar();
1465 if (current_radiostack->get_nav1_loc()) {
1466 double offset = fabs(heading - radial);
1467 return (offset >= 172.0 && offset<= 188.0);
1470 fabs(heading - var - radial);
1471 return (offset >= 160.0 && offset <= 200.0);
1479 FGBFI::getNAV1InRange ()
1481 return current_radiostack->get_nav1_inrange();
1485 FGBFI::getNAV1DMEInRange ()
1487 return (current_radiostack->get_nav1_inrange() &&
1488 current_radiostack->get_nav1_has_dme());
1492 FGBFI::getNAV2Freq ()
1494 return current_radiostack->get_nav2_freq();
1498 FGBFI::getNAV2AltFreq ()
1500 return current_radiostack->get_nav2_alt_freq();
1504 FGBFI::getNAV2Radial ()
1506 return current_radiostack->get_nav2_radial();
1510 FGBFI::getNAV2SelRadial ()
1512 return current_radiostack->get_nav2_sel_radial();
1516 FGBFI::getNAV2DistDME ()
1518 return current_radiostack->get_nav2_dme_dist();
1524 if (current_radiostack->get_nav2_inrange()) {
1525 double heading = current_radiostack->get_nav2_heading();
1526 double radial = current_radiostack->get_nav2_radial();
1527 double var = FGBFI::getMagVar();
1528 if (current_radiostack->get_nav2_loc()) {
1529 double offset = fabs(heading - radial);
1530 return (offset<= 8.0 || offset >= 352.0);
1533 fabs(heading - var - radial);
1534 return (offset <= 20.0 || offset >= 340.0);
1542 FGBFI::getNAV2FROM ()
1544 if (current_radiostack->get_nav2_inrange()) {
1545 double heading = current_radiostack->get_nav2_heading();
1546 double radial = current_radiostack->get_nav2_radial();
1547 double var = FGBFI::getMagVar();
1548 if (current_radiostack->get_nav2_loc()) {
1549 double offset = fabs(heading - radial);
1550 return (offset >= 172.0 && offset<= 188.0);
1553 fabs(heading - var - radial);
1554 return (offset >= 160.0 && offset <= 200.0);
1563 FGBFI::getNAV2InRange ()
1565 return current_radiostack->get_nav2_inrange();
1569 FGBFI::getNAV2DMEInRange ()
1571 return (current_radiostack->get_nav2_inrange() &&
1572 current_radiostack->get_nav2_has_dme());
1576 FGBFI::getADFFreq ()
1578 return current_radiostack->get_adf_freq();
1582 FGBFI::getADFAltFreq ()
1584 return current_radiostack->get_adf_alt_freq();
1588 FGBFI::getADFRotation ()
1590 return current_radiostack->get_adf_rotation();
1594 FGBFI::setNAV1Freq (double freq)
1596 current_radiostack->set_nav1_freq(freq);
1600 FGBFI::setNAV1AltFreq (double freq)
1602 current_radiostack->set_nav1_alt_freq(freq);
1606 FGBFI::setNAV1SelRadial (double radial)
1608 current_radiostack->set_nav1_sel_radial(radial);
1612 FGBFI::setNAV2Freq (double freq)
1614 current_radiostack->set_nav2_freq(freq);
1618 FGBFI::setNAV2AltFreq (double freq)
1620 current_radiostack->set_nav2_alt_freq(freq);
1624 FGBFI::setNAV2SelRadial (double radial)
1626 current_radiostack->set_nav2_sel_radial(radial);
1630 FGBFI::setADFFreq (double freq)
1632 current_radiostack->set_adf_freq(freq);
1636 FGBFI::setADFAltFreq (double freq)
1638 current_radiostack->set_adf_alt_freq(freq);
1642 FGBFI::setADFRotation (double rot)
1644 current_radiostack->set_adf_rotation(rot);
1649 ////////////////////////////////////////////////////////////////////////
1651 ////////////////////////////////////////////////////////////////////////
1655 * Get the autopilot GPS lock (true=on).
1658 FGBFI::getGPSLock ()
1660 return (current_autopilot->get_HeadingEnabled() &&
1661 (current_autopilot->get_HeadingMode() ==
1662 FGAutopilot::FG_HEADING_WAYPOINT ));
1667 * Set the autopilot GPS lock (true=on).
1670 FGBFI::setGPSLock (bool lock)
1673 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1674 current_autopilot->set_HeadingEnabled(true);
1675 } else if (current_autopilot->get_HeadingMode() ==
1676 FGAutopilot::FG_HEADING_WAYPOINT) {
1677 current_autopilot->set_HeadingEnabled(false);
1683 * Get the GPS target airport code.
1686 FGBFI::getTargetAirport ()
1688 // FIXME: not thread-safe
1690 out = globals->get_options()->get_airport_id();
1697 * Set the GPS target airport code.
1700 FGBFI::setTargetAirport (const string &airportId)
1702 // cout << "setting target airport id = " << airportId << endl;
1703 globals->get_options()->set_airport_id(airportId);
1708 * Get the GPS target latitude in degrees (negative for south).
1711 FGBFI::getGPSTargetLatitude ()
1713 return current_autopilot->get_TargetLatitude();
1718 * Get the GPS target longitude in degrees (negative for west).
1721 FGBFI::getGPSTargetLongitude ()
1723 return current_autopilot->get_TargetLongitude();
1728 * Set the GPS target longitude in degrees (negative for west).
1731 FGBFI::setGPSTargetLongitude (double longitude)
1733 current_autopilot->set_TargetLongitude( longitude );
1739 ////////////////////////////////////////////////////////////////////////
1741 ////////////////////////////////////////////////////////////////////////
1745 * Get the current visible (units??).
1748 FGBFI::getVisibility ()
1750 #ifndef FG_OLD_WEATHER
1751 return WeatherDatabase->getWeatherVisibility();
1753 return current_weather.get_visibility();
1759 * Set the current visibility (units??).
1762 FGBFI::setVisibility (double visibility)
1764 #ifndef FG_OLD_WEATHER
1765 WeatherDatabase->setWeatherVisibility(visibility);
1767 current_weather.set_visibility(visibility);
1773 ////////////////////////////////////////////////////////////////////////
1775 ////////////////////////////////////////////////////////////////////////
1778 * Return the magnetic variation
1783 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1788 * Return the magnetic variation
1793 return globals->get_mag()->get_magdip() * RAD_TO_DEG;