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 ////////////////////////////////////////////////////////////////////////
184 TIE_BOOL(const char * name, bool (*getter)(), void (*setter)(bool)) {
185 globals->get_props()->tie(name, SGRawValueFunctions<bool>(getter, setter));
189 TIE_INT(const char * name, int (*getter)(), void (*setter)(int)) {
190 globals->get_props()->tie(name, SGRawValueFunctions<int>(getter, setter));
194 TIE_DOUBLE(const char * name, double (*getter)(), void (*setter)(double)) {
195 globals->get_props()->tie(name, SGRawValueFunctions<double>(getter, setter));
199 TIE_STRING(const char * name, string (*getter)(), void (*setter)(string)) {
200 globals->get_props()->tie(name, SGRawValueFunctions<string>(getter, setter));
204 * Initialize the BFI by binding its functions to properties.
206 * TODO: perhaps these should migrate into the individual modules
207 * (i.e. they should register themselves).
212 FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init");
214 TIE_INT("/sim/flight-model", getFlightModel, setFlightModel);
215 TIE_STRING("/sim/aircraft", getAircraft, setAircraft);
216 TIE_STRING("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
217 TIE_STRING("/sim/time/gmt", getDateString, setDateString);
218 TIE_STRING("/sim/time/gmt-string", getGMTString, 0);
219 TIE_BOOL("/sim/hud/visibility", getHUDVisible, setHUDVisible);
220 TIE_BOOL("/sim/panel/visibility", getPanelVisible, setPanelVisible);
221 TIE_INT("/sim/panel/x-offset", getPanelXOffset, setPanelXOffset);
222 TIE_INT("/sim/panel/y-offset", getPanelYOffset, setPanelYOffset);
225 TIE_STRING("/position/airport-id", getTargetAirport, setTargetAirport);
226 TIE_DOUBLE("/position/latitude", getLatitude, setLatitude);
227 TIE_DOUBLE("/position/longitude", getLongitude, setLongitude);
228 TIE_DOUBLE("/position/altitude", getAltitude, setAltitude);
229 TIE_DOUBLE("/position/altitude-agl", getAGL, 0);
232 TIE_DOUBLE("/orientation/heading", getHeading, setHeading);
233 TIE_DOUBLE("/orientation/heading-magnetic", getHeadingMag, 0);
234 TIE_DOUBLE("/orientation/pitch", getPitch, setPitch);
235 TIE_DOUBLE("/orientation/roll", getRoll, setRoll);
238 TIE_DOUBLE("/engines/engine0/rpm", getRPM, 0);
239 TIE_DOUBLE("/engines/engine0/egt", getEGT, 0);
240 TIE_DOUBLE("/engines/engine0/cht", getCHT, 0);
241 TIE_DOUBLE("/engines/engine0/mp", getMP, 0);
244 TIE_DOUBLE("/velocities/airspeed", getAirspeed, setAirspeed);
245 TIE_DOUBLE("/velocities/side-slip", getSideSlip, 0);
246 TIE_DOUBLE("/velocities/vertical-speed", getVerticalSpeed, 0);
247 TIE_DOUBLE("/velocities/speed-north", getSpeedNorth, 0);
248 TIE_DOUBLE("/velocities/speed-east", getSpeedEast, 0);
249 TIE_DOUBLE("/velocities/speed-down", getSpeedDown, 0);
252 TIE_DOUBLE("/controls/throttle", getThrottle, setThrottle);
253 TIE_DOUBLE("/controls/mixture", getMixture, setMixture);
254 TIE_DOUBLE("/controls/propellor-pitch", getPropAdvance, setPropAdvance);
255 TIE_DOUBLE("/controls/flaps", getFlaps, setFlaps);
256 TIE_DOUBLE("/controls/aileron", getAileron, setAileron);
257 TIE_DOUBLE("/controls/rudder", getRudder, setRudder);
258 TIE_DOUBLE("/controls/elevator", getElevator, setElevator);
259 TIE_DOUBLE("/controls/elevator-trim", getElevatorTrim, setElevatorTrim);
260 TIE_DOUBLE("/controls/brakes/all", getBrakes, setBrakes);
261 TIE_DOUBLE("/controls/brakes/left", getLeftBrake, setLeftBrake);
262 TIE_DOUBLE("/controls/brakes/right", getRightBrake, setRightBrake);
263 TIE_DOUBLE("/controls/brakes/center", getRightBrake, setCenterBrake);
266 TIE_BOOL("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock);
267 TIE_DOUBLE("/autopilot/settings/altitude", getAPAltitude, setAPAltitude);
268 TIE_BOOL("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock);
269 TIE_DOUBLE("/autopilot/settings/heading", getAPHeading, setAPHeading);
270 TIE_DOUBLE("/autopilot/settings/heading-magnetic",
271 getAPHeadingMag, setAPHeadingMag);
272 TIE_BOOL("/autopilot/locks/nav1", getAPNAV1Lock, setAPNAV1Lock);
275 TIE_DOUBLE("/radios/nav1/frequencies/selected", getNAV1Freq, setNAV1Freq);
276 TIE_DOUBLE("/radios/nav1/frequencies/standby", getNAV1AltFreq, setNAV1AltFreq);
277 TIE_DOUBLE("/radios/nav1/radials/actual", getNAV1Radial, 0);
278 TIE_DOUBLE("/radios/nav1/radials/selected",
279 getNAV1SelRadial, setNAV1SelRadial);
280 TIE_DOUBLE("/radios/nav1/dme/distance", getNAV1DistDME, 0);
281 TIE_BOOL("/radios/nav1/to-flag", getNAV1TO, 0);
282 TIE_BOOL("/radios/nav1/from-flag", getNAV1FROM, 0);
283 TIE_BOOL("/radios/nav1/in-range", getNAV1InRange, 0);
284 TIE_BOOL("/radios/nav1/dme/in-range", getNAV1DMEInRange, 0);
286 TIE_DOUBLE("/radios/nav2/frequencies/selected", getNAV2Freq, setNAV2Freq);
287 TIE_DOUBLE("/radios/nav2/frequencies/standby",
288 getNAV2AltFreq, setNAV2AltFreq);
289 TIE_DOUBLE("/radios/nav2/radials/actual", getNAV2Radial, 0);
290 TIE_DOUBLE("/radios/nav2/radials/selected",
291 getNAV2SelRadial, setNAV2SelRadial);
292 TIE_DOUBLE("/radios/nav2/dme/distance", getNAV2DistDME, 0);
293 TIE_BOOL("/radios/nav2/to-flag", getNAV2TO, 0);
294 TIE_BOOL("/radios/nav2/from-flag", getNAV2FROM, 0);
295 TIE_BOOL("/radios/nav2/in-range", getNAV2InRange, 0);
296 TIE_BOOL("/radios/nav2/dme/in-range", getNAV2DMEInRange, 0);
298 TIE_DOUBLE("/radios/adf/frequencies/selected", getADFFreq, setADFFreq);
299 TIE_DOUBLE("/radios/adf/frequencies/standby", getADFAltFreq, setADFAltFreq);
300 TIE_DOUBLE("/radios/adf/rotation", getADFRotation, setADFRotation);
302 TIE_DOUBLE("/environment/visibility", getVisibility, setVisibility);
306 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
311 * Reinitialize FGFS if required.
313 * Some changes (especially those in aircraft position) require that
314 * FGFS be reinitialized afterwards. Rather than reinitialize after
315 * every change, the setter methods simply set a flag so that there
316 * can be a single reinit at the end of the frame.
330 ////////////////////////////////////////////////////////////////////////
332 ////////////////////////////////////////////////////////////////////////
336 * Return the flight model as an integer.
338 * TODO: use a string instead.
341 FGBFI::getFlightModel ()
343 return globals->get_options()->get_flight_model();
348 * Return the current aircraft as a string.
351 FGBFI::getAircraft ()
353 _temp = globals->get_options()->get_aircraft();
359 * Return the current aircraft directory (UIUC) as a string.
362 FGBFI::getAircraftDir ()
364 _temp = aircraft_dir;
370 * Set the flight model as an integer.
372 * TODO: use a string instead.
375 FGBFI::setFlightModel (int model)
377 if (getFlightModel() != model) {
378 globals->get_options()->set_flight_model(model);
385 * Set the current aircraft.
388 FGBFI::setAircraft (string aircraft)
390 if (getAircraft() != aircraft) {
391 globals->get_options()->set_aircraft(aircraft);
398 * Set the current aircraft directory (UIUC).
401 FGBFI::setAircraftDir (string dir)
403 if (getAircraftDir() != dir) {
411 * Return the current Zulu time.
414 FGBFI::getDateString ()
418 struct tm * t = globals->get_time_params()->getGmt();
419 sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
420 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
421 t->tm_hour, t->tm_min, t->tm_sec);
428 * Set the current Zulu time.
431 FGBFI::setDateString (string date_string)
432 // FGBFI::setTimeGMT (time_t time)
434 SGTime * st = globals->get_time_params();
435 struct tm * current_time = st->getGmt();
438 // Scan for basic ISO format
439 // YYYY-MM-DDTHH:MM:SS
440 int ret = sscanf(date_string.c_str(), "%d-%d-%dT%d:%d:%d",
441 &(new_time.tm_year), &(new_time.tm_mon),
442 &(new_time.tm_mday), &(new_time.tm_hour),
443 &(new_time.tm_min), &(new_time.tm_sec));
445 // Be pretty picky about this, so
446 // that strange things don't happen
447 // if the save file has been edited
450 FG_LOG(FG_INPUT, FG_ALERT, "Date/time string " << date_string
451 << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
455 // OK, it looks like we got six
456 // values, one way or another.
457 new_time.tm_year -= 1900;
458 new_time.tm_mon -= 1;
460 // Now, tell flight gear to use
461 // the new time. This was far
462 // too difficult, by the way.
464 mktime(&new_time) - mktime(current_time) + globals->get_warp();
465 double lon = current_aircraft.fdm_state->get_Longitude();
466 double lat = current_aircraft.fdm_state->get_Latitude();
467 double alt = current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER;
468 globals->set_warp(warp);
469 st->update(lon, lat, warp);
470 fgUpdateSkyAndLightingParams();
475 * Return the GMT as a string.
478 FGBFI::getGMTString ()
482 struct tm * t = globals->get_time_params()->getGmt();
483 sprintf(buf, " %.2d:%.2d:%.2d",
484 t->tm_hour, t->tm_min, t->tm_sec);
491 * Return true if the HUD is visible.
494 FGBFI::getHUDVisible ()
496 return globals->get_options()->get_hud_status();
501 * Ensure that the HUD is visible or hidden.
504 FGBFI::setHUDVisible (bool visible)
506 globals->get_options()->set_hud_status(visible);
511 * Return true if the 2D panel is visible.
514 FGBFI::getPanelVisible ()
516 return globals->get_options()->get_panel_status();
521 * Ensure that the 2D panel is visible or hidden.
524 FGBFI::setPanelVisible (bool visible)
526 if (globals->get_options()->get_panel_status() != visible) {
527 globals->get_options()->toggle_panel();
533 * Get the panel's current x-shift.
536 FGBFI::getPanelXOffset ()
538 if (current_panel != 0)
539 return current_panel->getXOffset();
546 * Set the panel's current x-shift.
549 FGBFI::setPanelXOffset (int offset)
551 if (current_panel != 0)
552 current_panel->setXOffset(offset);
557 * Get the panel's current y-shift.
560 FGBFI::getPanelYOffset ()
562 if (current_panel != 0)
563 return current_panel->getYOffset();
570 * Set the panel's current y-shift.
573 FGBFI::setPanelYOffset (int offset)
575 if (current_panel != 0)
576 current_panel->setYOffset(offset);
583 ////////////////////////////////////////////////////////////////////////
585 ////////////////////////////////////////////////////////////////////////
589 * Return the current latitude in degrees (negative for south).
592 FGBFI::getLatitude ()
594 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
599 * Set the current latitude in degrees (negative for south).
602 FGBFI::setLatitude (double latitude)
604 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
605 fgUpdateSkyAndLightingParams();
606 if (_lighting_countdown <= 0)
607 _lighting_countdown = 5;
612 * Return the current longitude in degrees (negative for west).
615 FGBFI::getLongitude ()
617 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
622 * Set the current longitude in degrees (negative for west).
625 FGBFI::setLongitude (double longitude)
627 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
628 fgUpdateSkyAndLightingParams();
629 if (_lighting_countdown <= 0)
630 _lighting_countdown = 5;
635 * Return the current altitude in feet.
638 FGBFI::getAltitude ()
640 return current_aircraft.fdm_state->get_Altitude();
646 * Return the current altitude in above the terrain.
651 return current_aircraft.fdm_state->get_Altitude()
652 - (scenery.cur_elev * METER_TO_FEET);
657 * Set the current altitude in feet.
660 FGBFI::setAltitude (double altitude)
662 current_aircraft.fdm_state->set_Altitude(altitude);
665 // This is an ugly kludge around a
666 // LaRCsim problem; if the
667 // requested altitude cannot be
668 // set right away (because it's
669 // below the last-calculated ground
670 // level), pause FGFS, wait for
671 // five frames, and then try again.
672 if (_altitude_countdown <= 0 &&
673 fabs(getAltitude() - altitude) > 5.0) {
674 _altitude_countdown = 5;
675 _requested_altitude = altitude;
676 _saved_freeze = globals->get_freeze();
677 globals->set_freeze(true);
683 ////////////////////////////////////////////////////////////////////////
685 ////////////////////////////////////////////////////////////////////////
689 * Return the current heading in degrees.
694 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
699 * Return the current heading in degrees.
702 FGBFI::getHeadingMag ()
704 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
709 * Set the current heading in degrees.
712 FGBFI::setHeading (double heading)
714 FGInterface * fdm = current_aircraft.fdm_state;
715 fdm->set_Euler_Angles(fdm->get_Phi(), fdm->get_Theta(),
716 heading * DEG_TO_RAD);
721 * Return the current pitch in degrees.
726 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
731 * Set the current pitch in degrees.
734 FGBFI::setPitch (double pitch)
736 FGInterface * fdm = current_aircraft.fdm_state;
737 fdm->set_Euler_Angles(fdm->get_Phi(), pitch * DEG_TO_RAD, fdm->get_Psi());
742 * Return the current roll in degrees.
747 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
752 * Set the current roll in degrees.
755 FGBFI::setRoll (double roll)
757 FGInterface * fdm = current_aircraft.fdm_state;
758 fdm->set_Euler_Angles(roll * DEG_TO_RAD, fdm->get_Theta(), fdm->get_Psi());
763 * Return the current engine0 rpm
768 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
769 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
777 * Set the current engine0 rpm
780 FGBFI::setRPM (double rpm)
782 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
783 if (getRPM() != rpm) {
784 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
791 * Return the current engine0 EGT.
796 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
797 return current_aircraft.fdm_state->get_engine(0)->get_EGT();
805 * Return the current engine0 CHT.
810 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
811 return current_aircraft.fdm_state->get_engine(0)->get_CHT();
819 * Return the current engine0 CHT.
824 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
825 return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
833 ////////////////////////////////////////////////////////////////////////
835 ////////////////////////////////////////////////////////////////////////
839 * Return the current airspeed in knots.
842 FGBFI::getAirspeed ()
844 // FIXME: should we add speed-up?
845 return current_aircraft.fdm_state->get_V_calibrated_kts();
850 * Set the calibrated airspeed in knots.
853 FGBFI::setAirspeed (double speed)
855 current_aircraft.fdm_state->set_V_calibrated_kts(speed);
860 * Return the current sideslip (FIXME: units unknown).
863 FGBFI::getSideSlip ()
865 return current_aircraft.fdm_state->get_Beta();
870 * Return the current climb rate in feet/minute
873 FGBFI::getVerticalSpeed ()
875 // What about meters?
876 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
881 * Get the current north velocity (units??).
884 FGBFI::getSpeedNorth ()
886 return current_aircraft.fdm_state->get_V_north();
891 // * Set the current north velocity (units??).
894 // FGBFI::setSpeedNorth (double speed)
896 // FGInterface * fdm = current_aircraft.fdm_state;
897 // // fdm->set_Velocities_Local(speed, fdm->get_V_east(), fdm->get_V_down());
902 * Get the current east velocity (units??).
905 FGBFI::getSpeedEast ()
907 return current_aircraft.fdm_state->get_V_east();
912 // * Set the current east velocity (units??).
915 // FGBFI::setSpeedEast (double speed)
917 // FGInterface * fdm = current_aircraft.fdm_state;
918 // // fdm->set_Velocities_Local(fdm->get_V_north(), speed, fdm->get_V_down());
923 * Get the current down velocity (units??).
926 FGBFI::getSpeedDown ()
928 return current_aircraft.fdm_state->get_V_down();
933 // * Set the current down velocity (units??).
936 // FGBFI::setSpeedDown (double speed)
938 // FGInterface * fdm = current_aircraft.fdm_state;
939 // // fdm->set_Velocities_Local(fdm->get_V_north(), fdm->get_V_east(), speed);
944 ////////////////////////////////////////////////////////////////////////
946 ////////////////////////////////////////////////////////////////////////
950 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
953 FGBFI::getThrottle ()
955 // FIXME: add engine selector
956 return controls.get_throttle(0);
961 * Set the throttle, from 0.0 (none) to 1.0 (full).
964 FGBFI::setThrottle (double throttle)
966 // FIXME: allow engine selection
967 controls.set_throttle(0, throttle);
972 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
977 // FIXME: add engine selector
978 return controls.get_mixture(0);
983 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
986 FGBFI::setMixture (double mixture)
988 // FIXME: allow engine selection
989 controls.set_mixture(0, mixture);
994 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
997 FGBFI::getPropAdvance ()
999 // FIXME: add engine selector
1000 return controls.get_prop_advance(0);
1005 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
1008 FGBFI::setPropAdvance (double pitch)
1010 // FIXME: allow engine selection
1011 controls.set_prop_advance(0, pitch);
1016 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
1021 return controls.get_flaps();
1026 * Set the flaps, from 0.0 (none) to 1.0 (full).
1029 FGBFI::setFlaps (double flaps)
1032 controls.set_flaps(flaps);
1037 * Get the aileron, from -1.0 (left) to 1.0 (right).
1040 FGBFI::getAileron ()
1042 return controls.get_aileron();
1047 * Set the aileron, from -1.0 (left) to 1.0 (right).
1050 FGBFI::setAileron (double aileron)
1053 controls.set_aileron(aileron);
1058 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
1063 return controls.get_rudder();
1068 * Set the rudder, from -1.0 (left) to 1.0 (right).
1071 FGBFI::setRudder (double rudder)
1074 controls.set_rudder(rudder);
1079 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
1082 FGBFI::getElevator ()
1084 return controls.get_elevator();
1089 * Set the elevator, from -1.0 (down) to 1.0 (up).
1092 FGBFI::setElevator (double elevator)
1095 controls.set_elevator(elevator);
1100 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
1103 FGBFI::getElevatorTrim ()
1105 return controls.get_elevator_trim();
1110 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
1113 FGBFI::setElevatorTrim (double trim)
1116 controls.set_elevator_trim(trim);
1121 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1126 double b1 = getCenterBrake();
1127 double b2 = getLeftBrake();
1128 double b3 = getRightBrake();
1129 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1134 * Set all brakes, from 0.0 (none) to 1.0 (full).
1137 FGBFI::setBrakes (double brake)
1139 setCenterBrake(brake);
1140 setLeftBrake(brake);
1141 setRightBrake(brake);
1146 * Get the center brake, from 0.0 (none) to 1.0 (full).
1149 FGBFI::getCenterBrake ()
1151 return controls.get_brake(2);
1156 * Set the center brake, from 0.0 (none) to 1.0 (full).
1159 FGBFI::setCenterBrake (double brake)
1161 controls.set_brake(2, brake);
1166 * Get the left brake, from 0.0 (none) to 1.0 (full).
1169 FGBFI::getLeftBrake ()
1171 return controls.get_brake(0);
1176 * Set the left brake, from 0.0 (none) to 1.0 (full).
1179 FGBFI::setLeftBrake (double brake)
1181 controls.set_brake(0, brake);
1186 * Get the right brake, from 0.0 (none) to 1.0 (full).
1189 FGBFI::getRightBrake ()
1191 return controls.get_brake(1);
1196 * Set the right brake, from 0.0 (none) to 1.0 (full).
1199 FGBFI::setRightBrake (double brake)
1201 controls.set_brake(1, brake);
1208 ////////////////////////////////////////////////////////////////////////
1210 ////////////////////////////////////////////////////////////////////////
1214 * Get the autopilot altitude lock (true=on).
1217 FGBFI::getAPAltitudeLock ()
1219 return current_autopilot->get_AltitudeEnabled();
1224 * Set the autopilot altitude lock (true=on).
1227 FGBFI::setAPAltitudeLock (bool lock)
1229 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1230 current_autopilot->set_AltitudeEnabled(lock);
1235 * Get the autopilot target altitude in feet.
1238 FGBFI::getAPAltitude ()
1240 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1245 * Set the autopilot target altitude in feet.
1248 FGBFI::setAPAltitude (double altitude)
1250 current_autopilot->set_TargetAltitude( altitude );
1255 * Get the autopilot heading lock (true=on).
1258 FGBFI::getAPHeadingLock ()
1261 (current_autopilot->get_HeadingEnabled() &&
1262 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1267 * Set the autopilot heading lock (true=on).
1270 FGBFI::setAPHeadingLock (bool lock)
1273 // We need to do this so that
1274 // it's possible to lock onto a
1275 // heading other than the current
1277 double heading = getAPHeadingMag();
1278 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1279 current_autopilot->set_HeadingEnabled(true);
1280 setAPHeadingMag(heading);
1281 } else if (current_autopilot->get_HeadingMode() ==
1282 FGAutopilot::FG_HEADING_LOCK) {
1283 current_autopilot->set_HeadingEnabled(false);
1289 * Get the autopilot target heading in degrees.
1292 FGBFI::getAPHeading ()
1294 return current_autopilot->get_TargetHeading();
1299 * Set the autopilot target heading in degrees.
1302 FGBFI::setAPHeading (double heading)
1304 current_autopilot->set_TargetHeading( heading );
1309 * Get the autopilot target heading in degrees.
1312 FGBFI::getAPHeadingMag ()
1314 return current_autopilot->get_TargetHeading() - getMagVar();
1319 * Set the autopilot target heading in degrees.
1322 FGBFI::setAPHeadingMag (double heading)
1324 current_autopilot->set_TargetHeading( heading + getMagVar() );
1329 * Return true if the autopilot is locked to NAV1.
1332 FGBFI::getAPNAV1Lock ()
1335 (current_autopilot->get_HeadingEnabled() &&
1336 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1341 * Set the autopilot NAV1 lock.
1344 FGBFI::setAPNAV1Lock (bool lock)
1347 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1348 current_autopilot->set_HeadingEnabled(true);
1349 } else if (current_autopilot->get_HeadingMode() ==
1350 FGAutopilot::FG_HEADING_NAV1) {
1351 current_autopilot->set_HeadingEnabled(false);
1357 ////////////////////////////////////////////////////////////////////////
1358 // Radio navigation.
1359 ////////////////////////////////////////////////////////////////////////
1362 FGBFI::getNAV1Freq ()
1364 return current_radiostack->get_nav1_freq();
1368 FGBFI::getNAV1AltFreq ()
1370 return current_radiostack->get_nav1_alt_freq();
1374 FGBFI::getNAV1Radial ()
1376 return current_radiostack->get_nav1_radial();
1380 FGBFI::getNAV1SelRadial ()
1382 return current_radiostack->get_nav1_sel_radial();
1386 FGBFI::getNAV1DistDME ()
1388 return current_radiostack->get_nav1_dme_dist();
1394 if (current_radiostack->get_nav1_inrange()) {
1395 double heading = current_radiostack->get_nav1_heading();
1396 double radial = current_radiostack->get_nav1_radial();
1397 double var = FGBFI::getMagVar();
1398 if (current_radiostack->get_nav1_loc()) {
1399 double offset = fabs(heading - radial);
1400 return (offset<= 8.0 || offset >= 352.0);
1403 fabs(heading - var - radial);
1404 return (offset <= 20.0 || offset >= 340.0);
1412 FGBFI::getNAV1FROM ()
1414 if (current_radiostack->get_nav1_inrange()) {
1415 double heading = current_radiostack->get_nav1_heading();
1416 double radial = current_radiostack->get_nav1_radial();
1417 double var = FGBFI::getMagVar();
1418 if (current_radiostack->get_nav1_loc()) {
1419 double offset = fabs(heading - radial);
1420 return (offset >= 172.0 && offset<= 188.0);
1423 fabs(heading - var - radial);
1424 return (offset >= 160.0 && offset <= 200.0);
1432 FGBFI::getNAV1InRange ()
1434 return current_radiostack->get_nav1_inrange();
1438 FGBFI::getNAV1DMEInRange ()
1440 return (current_radiostack->get_nav1_inrange() &&
1441 current_radiostack->get_nav1_has_dme());
1445 FGBFI::getNAV2Freq ()
1447 return current_radiostack->get_nav2_freq();
1451 FGBFI::getNAV2AltFreq ()
1453 return current_radiostack->get_nav2_alt_freq();
1457 FGBFI::getNAV2Radial ()
1459 return current_radiostack->get_nav2_radial();
1463 FGBFI::getNAV2SelRadial ()
1465 return current_radiostack->get_nav2_sel_radial();
1469 FGBFI::getNAV2DistDME ()
1471 return current_radiostack->get_nav2_dme_dist();
1477 if (current_radiostack->get_nav2_inrange()) {
1478 double heading = current_radiostack->get_nav2_heading();
1479 double radial = current_radiostack->get_nav2_radial();
1480 double var = FGBFI::getMagVar();
1481 if (current_radiostack->get_nav2_loc()) {
1482 double offset = fabs(heading - radial);
1483 return (offset<= 8.0 || offset >= 352.0);
1486 fabs(heading - var - radial);
1487 return (offset <= 20.0 || offset >= 340.0);
1495 FGBFI::getNAV2FROM ()
1497 if (current_radiostack->get_nav2_inrange()) {
1498 double heading = current_radiostack->get_nav2_heading();
1499 double radial = current_radiostack->get_nav2_radial();
1500 double var = FGBFI::getMagVar();
1501 if (current_radiostack->get_nav2_loc()) {
1502 double offset = fabs(heading - radial);
1503 return (offset >= 172.0 && offset<= 188.0);
1506 fabs(heading - var - radial);
1507 return (offset >= 160.0 && offset <= 200.0);
1516 FGBFI::getNAV2InRange ()
1518 return current_radiostack->get_nav2_inrange();
1522 FGBFI::getNAV2DMEInRange ()
1524 return (current_radiostack->get_nav2_inrange() &&
1525 current_radiostack->get_nav2_has_dme());
1529 FGBFI::getADFFreq ()
1531 return current_radiostack->get_adf_freq();
1535 FGBFI::getADFAltFreq ()
1537 return current_radiostack->get_adf_alt_freq();
1541 FGBFI::getADFRotation ()
1543 return current_radiostack->get_adf_rotation();
1547 FGBFI::setNAV1Freq (double freq)
1549 current_radiostack->set_nav1_freq(freq);
1553 FGBFI::setNAV1AltFreq (double freq)
1555 current_radiostack->set_nav1_alt_freq(freq);
1559 FGBFI::setNAV1SelRadial (double radial)
1561 current_radiostack->set_nav1_sel_radial(radial);
1565 FGBFI::setNAV2Freq (double freq)
1567 current_radiostack->set_nav2_freq(freq);
1571 FGBFI::setNAV2AltFreq (double freq)
1573 current_radiostack->set_nav2_alt_freq(freq);
1577 FGBFI::setNAV2SelRadial (double radial)
1579 current_radiostack->set_nav2_sel_radial(radial);
1583 FGBFI::setADFFreq (double freq)
1585 current_radiostack->set_adf_freq(freq);
1589 FGBFI::setADFAltFreq (double freq)
1591 current_radiostack->set_adf_alt_freq(freq);
1595 FGBFI::setADFRotation (double rot)
1597 current_radiostack->set_adf_rotation(rot);
1602 ////////////////////////////////////////////////////////////////////////
1604 ////////////////////////////////////////////////////////////////////////
1608 * Get the autopilot GPS lock (true=on).
1611 FGBFI::getGPSLock ()
1613 return (current_autopilot->get_HeadingEnabled() &&
1614 (current_autopilot->get_HeadingMode() ==
1615 FGAutopilot::FG_HEADING_WAYPOINT ));
1620 * Set the autopilot GPS lock (true=on).
1623 FGBFI::setGPSLock (bool lock)
1626 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1627 current_autopilot->set_HeadingEnabled(true);
1628 } else if (current_autopilot->get_HeadingMode() ==
1629 FGAutopilot::FG_HEADING_WAYPOINT) {
1630 current_autopilot->set_HeadingEnabled(false);
1636 * Get the GPS target airport code.
1639 FGBFI::getTargetAirport ()
1641 // FIXME: not thread-safe
1643 out = globals->get_options()->get_airport_id();
1650 * Set the GPS target airport code.
1653 FGBFI::setTargetAirport (string airportId)
1655 // cout << "setting target airport id = " << airportId << endl;
1656 globals->get_options()->set_airport_id(airportId);
1661 * Get the GPS target latitude in degrees (negative for south).
1664 FGBFI::getGPSTargetLatitude ()
1666 return current_autopilot->get_TargetLatitude();
1671 * Get the GPS target longitude in degrees (negative for west).
1674 FGBFI::getGPSTargetLongitude ()
1676 return current_autopilot->get_TargetLongitude();
1681 * Set the GPS target longitude in degrees (negative for west).
1684 FGBFI::setGPSTargetLongitude (double longitude)
1686 current_autopilot->set_TargetLongitude( longitude );
1692 ////////////////////////////////////////////////////////////////////////
1694 ////////////////////////////////////////////////////////////////////////
1698 * Get the current visible (units??).
1701 FGBFI::getVisibility ()
1703 #ifndef FG_OLD_WEATHER
1704 return WeatherDatabase->getWeatherVisibility();
1706 return current_weather.get_visibility();
1712 * Set the current visibility (units??).
1715 FGBFI::setVisibility (double visibility)
1717 #ifndef FG_OLD_WEATHER
1718 WeatherDatabase->setWeatherVisibility(visibility);
1720 current_weather.set_visibility(visibility);
1726 ////////////////////////////////////////////////////////////////////////
1728 ////////////////////////////////////////////////////////////////////////
1731 * Return the magnetic variation
1736 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1741 * Return the magnetic variation
1746 return globals->get_mag()->get_magdip() * RAD_TO_DEG;