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";
151 ////////////////////////////////////////////////////////////////////////
153 ////////////////////////////////////////////////////////////////////////
157 * Initialize the BFI by binding its functions to properties.
159 * TODO: perhaps these should migrate into the individual modules
160 * (i.e. they should register themselves).
165 FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init");
167 current_properties.tieInt("/sim/flight-model",
168 getFlightModel, setFlightModel);
169 current_properties.tieString("/sim/aircraft",
170 getAircraft, setAircraft);
171 current_properties.tieString("/sim/aircraft-dir",
172 getAircraftDir, setAircraftDir);
174 current_properties.tieString("/sim/time/gmt-string",
176 current_properties.tieBool("/sim/hud/visibility",
177 getHUDVisible, setHUDVisible);
178 current_properties.tieBool("/sim/panel/visibility",
179 getPanelVisible, setPanelVisible);
180 current_properties.tieInt("/sim/panel/x-offset",
181 getPanelXOffset, setPanelXOffset);
182 current_properties.tieInt("/sim/panel/y-offset",
183 getPanelYOffset, setPanelYOffset);
186 current_properties.tieString("/position/airport-id",
187 getTargetAirport, setTargetAirport);
188 current_properties.tieDouble("/position/latitude",
189 getLatitude, setLatitude);
190 current_properties.tieDouble("/position/longitude",
191 getLongitude, setLongitude);
192 current_properties.tieDouble("/position/altitude",
193 // getAltitude, setAltitude);
194 getAltitude, setAltitude, false);
195 current_properties.tieDouble("/position/altitude-agl",
199 current_properties.tieDouble("/orientation/heading",
200 getHeading, setHeading);
201 current_properties.tieDouble("/orientation/heading-magnetic",
203 current_properties.tieDouble("/orientation/pitch",
205 current_properties.tieDouble("/orientation/roll",
209 current_properties.tieDouble("/engines/engine0/rpm",
211 current_properties.tieDouble("/engines/engine0/egt",
213 current_properties.tieDouble("/engines/engine0/cht",
215 current_properties.tieDouble("/engines/engine0/mp",
219 current_properties.tieDouble("/velocities/airspeed",
220 getAirspeed, setAirspeed);
221 current_properties.tieDouble("/velocities/side-slip",
223 current_properties.tieDouble("/velocities/vertical-speed",
224 getVerticalSpeed, 0);
225 current_properties.tieDouble("/velocities/speed-north",
227 current_properties.tieDouble("/velocities/speed-east",
229 current_properties.tieDouble("/velocities/speed-down",
233 current_properties.tieDouble("/controls/throttle",
234 getThrottle, setThrottle);
235 current_properties.tieDouble("/controls/mixture",
236 getMixture, setMixture);
237 current_properties.tieDouble("/controls/propellor-pitch",
238 getPropAdvance, setPropAdvance);
239 current_properties.tieDouble("/controls/flaps",
241 current_properties.tieDouble("/controls/aileron",
242 getAileron, setAileron);
243 current_properties.tieDouble("/controls/rudder",
244 getRudder, setRudder);
245 current_properties.tieDouble("/controls/elevator",
246 getElevator, setElevator);
247 current_properties.tieDouble("/controls/elevator-trim",
248 getElevatorTrim, setElevatorTrim);
249 current_properties.tieDouble("/controls/brakes/all",
250 getBrakes, setBrakes);
251 current_properties.tieDouble("/controls/brakes/left",
252 getLeftBrake, setLeftBrake);
253 current_properties.tieDouble("/controls/brakes/right",
254 getRightBrake, setRightBrake);
255 current_properties.tieDouble("/controls/brakes/center",
256 getRightBrake, setCenterBrake);
259 current_properties.tieBool("/autopilot/locks/altitude",
260 getAPAltitudeLock, setAPAltitudeLock);
261 current_properties.tieDouble("/autopilot/settings/altitude",
262 getAPAltitude, setAPAltitude);
263 current_properties.tieBool("/autopilot/locks/heading",
264 getAPHeadingLock, setAPHeadingLock);
265 current_properties.tieDouble("/autopilot/settings/heading",
266 getAPHeading, setAPHeading);
267 current_properties.tieDouble("/autopilot/settings/heading-magnetic",
268 getAPHeadingMag, setAPHeadingMag);
269 current_properties.tieBool("/autopilot/locks/nav1",
270 getAPNAV1Lock, setAPNAV1Lock);
273 current_properties.tieDouble("/radios/nav1/frequencies/selected",
274 getNAV1Freq, setNAV1Freq);
275 current_properties.tieDouble("/radios/nav1/frequencies/standby",
276 getNAV1AltFreq, setNAV1AltFreq);
277 current_properties.tieDouble("/radios/nav1/radials/actual",
279 current_properties.tieDouble("/radios/nav1/radials/selected",
280 getNAV1SelRadial, setNAV1SelRadial);
281 current_properties.tieDouble("/radios/nav1/dme/distance",
283 current_properties.tieBool("/radios/nav1/to-flag",
285 current_properties.tieBool("/radios/nav1/from-flag",
287 current_properties.tieBool("/radios/nav1/in-range",
289 current_properties.tieBool("/radios/nav1/dme/in-range",
290 getNAV1DMEInRange, 0);
292 current_properties.tieDouble("/radios/nav2/frequencies/selected",
293 getNAV2Freq, setNAV2Freq);
294 current_properties.tieDouble("/radios/nav2/frequencies/standby",
295 getNAV2AltFreq, setNAV2AltFreq);
296 current_properties.tieDouble("/radios/nav2/radials/actual",
298 current_properties.tieDouble("/radios/nav2/radials/selected",
299 getNAV2SelRadial, setNAV2SelRadial);
300 current_properties.tieDouble("/radios/nav2/dme/distance",
302 current_properties.tieBool("/radios/nav2/to-flag",
304 current_properties.tieBool("/radios/nav2/from-flag",
306 current_properties.tieBool("/radios/nav2/in-range",
308 current_properties.tieBool("/radios/nav2/dme/in-range",
309 getNAV2DMEInRange, 0);
311 current_properties.tieDouble("/radios/adf/frequencies/selected",
312 getADFFreq, setADFFreq);
313 current_properties.tieDouble("/radios/adf/frequencies/standby",
314 getADFAltFreq, setADFAltFreq);
315 current_properties.tieDouble("/radios/adf/rotation",
316 getADFRotation, setADFRotation);
318 current_properties.tieDouble("/environment/visibility",
319 getVisibility, setVisibility);
323 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
328 * Reinitialize FGFS if required.
330 * Some changes (especially those in aircraft position) require that
331 * FGFS be reinitialized afterwards. Rather than reinitialize after
332 * every change, the setter methods simply set a flag so that there
333 * can be a single reinit at the end of the frame.
345 ////////////////////////////////////////////////////////////////////////
347 ////////////////////////////////////////////////////////////////////////
351 * Return the flight model as an integer.
353 * TODO: use a string instead.
356 FGBFI::getFlightModel ()
358 return globals->get_options()->get_flight_model();
363 * Return the current aircraft as a string.
366 FGBFI::getAircraft ()
368 _temp = globals->get_options()->get_aircraft();
374 * Return the current aircraft directory (UIUC) as a string.
377 FGBFI::getAircraftDir ()
379 _temp = aircraft_dir;
385 * Set the flight model as an integer.
387 * TODO: use a string instead.
390 FGBFI::setFlightModel (int model)
392 if (getFlightModel() != model) {
393 globals->get_options()->set_flight_model(model);
400 * Set the current aircraft.
403 FGBFI::setAircraft (const string &aircraft)
405 if (getAircraft() != aircraft) {
406 globals->get_options()->set_aircraft(aircraft);
413 * Set the current aircraft directory (UIUC).
416 FGBFI::setAircraftDir (const string &dir)
418 if (getAircraftDir() != dir) {
426 * Return the current Zulu time.
431 return globals->get_time_params()->get_cur_time();
436 * Set the current Zulu time.
439 FGBFI::setTimeGMT (time_t time)
441 if (getTimeGMT() != time) {
442 // FIXME: need to update lighting
444 globals->get_options()->set_time_offset(time);
445 globals->get_options()->set_time_offset_type(FGOptions::FG_TIME_GMT_ABSOLUTE);
446 globals->get_time_params()->update( cur_fdm_state->get_Longitude(),
447 cur_fdm_state->get_Latitude(),
448 globals->get_warp() );
455 * Return the GMT as a string.
458 FGBFI::getGMTString ()
460 static string out; // FIXME: not thread-safe
462 struct tm * t = globals->get_time_params()->getGmt();
463 sprintf(buf, " %.2d:%.2d:%.2d",
464 t->tm_hour, t->tm_min, t->tm_sec);
471 * Return true if the HUD is visible.
474 FGBFI::getHUDVisible ()
476 return globals->get_options()->get_hud_status();
481 * Ensure that the HUD is visible or hidden.
484 FGBFI::setHUDVisible (bool visible)
486 globals->get_options()->set_hud_status(visible);
491 * Return true if the 2D panel is visible.
494 FGBFI::getPanelVisible ()
496 return globals->get_options()->get_panel_status();
501 * Ensure that the 2D panel is visible or hidden.
504 FGBFI::setPanelVisible (bool visible)
506 if (globals->get_options()->get_panel_status() != visible) {
507 globals->get_options()->toggle_panel();
513 * Get the panel's current x-shift.
516 FGBFI::getPanelXOffset ()
518 if (current_panel != 0)
519 return current_panel->getXOffset();
526 * Set the panel's current x-shift.
529 FGBFI::setPanelXOffset (int offset)
531 if (current_panel != 0)
532 current_panel->setXOffset(offset);
537 * Get the panel's current y-shift.
540 FGBFI::getPanelYOffset ()
542 if (current_panel != 0)
543 return current_panel->getYOffset();
550 * Set the panel's current y-shift.
553 FGBFI::setPanelYOffset (int offset)
555 if (current_panel != 0)
556 current_panel->setYOffset(offset);
563 ////////////////////////////////////////////////////////////////////////
565 ////////////////////////////////////////////////////////////////////////
569 * Return the current latitude in degrees (negative for south).
572 FGBFI::getLatitude ()
574 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
579 * Set the current latitude in degrees (negative for south).
582 FGBFI::setLatitude (double latitude)
584 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
589 * Return the current longitude in degrees (negative for west).
592 FGBFI::getLongitude ()
594 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
599 * Set the current longitude in degrees (negative for west).
602 FGBFI::setLongitude (double longitude)
604 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
609 * Return the current altitude in feet.
612 FGBFI::getAltitude ()
614 return current_aircraft.fdm_state->get_Altitude();
620 * Return the current altitude in above the terrain.
625 return current_aircraft.fdm_state->get_Altitude()
626 - (scenery.cur_elev * METER_TO_FEET);
631 * Set the current altitude in feet.
634 FGBFI::setAltitude (double altitude)
636 current_aircraft.fdm_state->set_Altitude(altitude);
641 ////////////////////////////////////////////////////////////////////////
643 ////////////////////////////////////////////////////////////////////////
647 * Return the current heading in degrees.
652 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
657 * Return the current heading in degrees.
660 FGBFI::getHeadingMag ()
662 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
667 * Set the current heading in degrees.
670 FGBFI::setHeading (double heading)
672 FGInterface * fdm = current_aircraft.fdm_state;
673 fdm->set_Euler_Angles(fdm->get_Phi(), fdm->get_Theta(),
674 heading * DEG_TO_RAD);
679 * Return the current pitch in degrees.
684 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
689 * Set the current pitch in degrees.
692 FGBFI::setPitch (double pitch)
694 FGInterface * fdm = current_aircraft.fdm_state;
695 fdm->set_Euler_Angles(fdm->get_Phi(), pitch * DEG_TO_RAD, fdm->get_Psi());
700 * Return the current roll in degrees.
705 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
710 * Set the current roll in degrees.
713 FGBFI::setRoll (double roll)
715 FGInterface * fdm = current_aircraft.fdm_state;
716 fdm->set_Euler_Angles(roll * DEG_TO_RAD, fdm->get_Theta(), fdm->get_Psi());
721 * Return the current engine0 rpm
726 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
727 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
735 * Set the current engine0 rpm
738 FGBFI::setRPM (double rpm)
740 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
741 if (getRPM() != rpm) {
742 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
749 * Return the current engine0 EGT.
754 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
755 return current_aircraft.fdm_state->get_engine(0)->get_EGT();
763 * Return the current engine0 CHT.
768 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
769 return current_aircraft.fdm_state->get_engine(0)->get_CHT();
777 * Return the current engine0 CHT.
782 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
783 return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
791 ////////////////////////////////////////////////////////////////////////
793 ////////////////////////////////////////////////////////////////////////
797 * Return the current airspeed in knots.
800 FGBFI::getAirspeed ()
802 // FIXME: should we add speed-up?
803 return current_aircraft.fdm_state->get_V_calibrated_kts();
808 * Set the calibrated airspeed in knots.
811 FGBFI::setAirspeed (double speed)
813 current_aircraft.fdm_state->set_V_calibrated_kts(speed);
818 * Return the current sideslip (FIXME: units unknown).
821 FGBFI::getSideSlip ()
823 return current_aircraft.fdm_state->get_Beta();
828 * Return the current climb rate in feet/minute
831 FGBFI::getVerticalSpeed ()
833 // What about meters?
834 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
839 * Get the current north velocity (units??).
842 FGBFI::getSpeedNorth ()
844 return current_aircraft.fdm_state->get_V_north();
849 // * Set the current north velocity (units??).
852 // FGBFI::setSpeedNorth (double speed)
854 // FGInterface * fdm = current_aircraft.fdm_state;
855 // // fdm->set_Velocities_Local(speed, fdm->get_V_east(), fdm->get_V_down());
860 * Get the current east velocity (units??).
863 FGBFI::getSpeedEast ()
865 return current_aircraft.fdm_state->get_V_east();
870 // * Set the current east velocity (units??).
873 // FGBFI::setSpeedEast (double speed)
875 // FGInterface * fdm = current_aircraft.fdm_state;
876 // // fdm->set_Velocities_Local(fdm->get_V_north(), speed, fdm->get_V_down());
881 * Get the current down velocity (units??).
884 FGBFI::getSpeedDown ()
886 return current_aircraft.fdm_state->get_V_down();
891 // * Set the current down velocity (units??).
894 // FGBFI::setSpeedDown (double speed)
896 // FGInterface * fdm = current_aircraft.fdm_state;
897 // // fdm->set_Velocities_Local(fdm->get_V_north(), fdm->get_V_east(), speed);
902 ////////////////////////////////////////////////////////////////////////
904 ////////////////////////////////////////////////////////////////////////
908 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
911 FGBFI::getThrottle ()
913 // FIXME: add engine selector
914 return controls.get_throttle(0);
919 * Set the throttle, from 0.0 (none) to 1.0 (full).
922 FGBFI::setThrottle (double throttle)
924 // FIXME: allow engine selection
925 controls.set_throttle(0, throttle);
930 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
935 // FIXME: add engine selector
936 return controls.get_mixture(0);
941 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
944 FGBFI::setMixture (double mixture)
946 // FIXME: allow engine selection
947 controls.set_mixture(0, mixture);
952 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
955 FGBFI::getPropAdvance ()
957 // FIXME: add engine selector
958 return controls.get_prop_advance(0);
963 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
966 FGBFI::setPropAdvance (double pitch)
968 // FIXME: allow engine selection
969 controls.set_prop_advance(0, pitch);
974 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
979 return controls.get_flaps();
984 * Set the flaps, from 0.0 (none) to 1.0 (full).
987 FGBFI::setFlaps (double flaps)
990 controls.set_flaps(flaps);
995 * Get the aileron, from -1.0 (left) to 1.0 (right).
1000 return controls.get_aileron();
1005 * Set the aileron, from -1.0 (left) to 1.0 (right).
1008 FGBFI::setAileron (double aileron)
1011 controls.set_aileron(aileron);
1016 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
1021 return controls.get_rudder();
1026 * Set the rudder, from -1.0 (left) to 1.0 (right).
1029 FGBFI::setRudder (double rudder)
1032 controls.set_rudder(rudder);
1037 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
1040 FGBFI::getElevator ()
1042 return controls.get_elevator();
1047 * Set the elevator, from -1.0 (down) to 1.0 (up).
1050 FGBFI::setElevator (double elevator)
1053 controls.set_elevator(elevator);
1058 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
1061 FGBFI::getElevatorTrim ()
1063 return controls.get_elevator_trim();
1068 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
1071 FGBFI::setElevatorTrim (double trim)
1074 controls.set_elevator_trim(trim);
1079 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1084 double b1 = getCenterBrake();
1085 double b2 = getLeftBrake();
1086 double b3 = getRightBrake();
1087 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1092 * Set all brakes, from 0.0 (none) to 1.0 (full).
1095 FGBFI::setBrakes (double brake)
1097 setCenterBrake(brake);
1098 setLeftBrake(brake);
1099 setRightBrake(brake);
1104 * Get the center brake, from 0.0 (none) to 1.0 (full).
1107 FGBFI::getCenterBrake ()
1109 return controls.get_brake(2);
1114 * Set the center brake, from 0.0 (none) to 1.0 (full).
1117 FGBFI::setCenterBrake (double brake)
1119 controls.set_brake(2, brake);
1124 * Get the left brake, from 0.0 (none) to 1.0 (full).
1127 FGBFI::getLeftBrake ()
1129 return controls.get_brake(0);
1134 * Set the left brake, from 0.0 (none) to 1.0 (full).
1137 FGBFI::setLeftBrake (double brake)
1139 controls.set_brake(0, brake);
1144 * Get the right brake, from 0.0 (none) to 1.0 (full).
1147 FGBFI::getRightBrake ()
1149 return controls.get_brake(1);
1154 * Set the right brake, from 0.0 (none) to 1.0 (full).
1157 FGBFI::setRightBrake (double brake)
1159 controls.set_brake(1, brake);
1166 ////////////////////////////////////////////////////////////////////////
1168 ////////////////////////////////////////////////////////////////////////
1172 * Get the autopilot altitude lock (true=on).
1175 FGBFI::getAPAltitudeLock ()
1177 return current_autopilot->get_AltitudeEnabled();
1182 * Set the autopilot altitude lock (true=on).
1185 FGBFI::setAPAltitudeLock (bool lock)
1187 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1188 current_autopilot->set_AltitudeEnabled(lock);
1193 * Get the autopilot target altitude in feet.
1196 FGBFI::getAPAltitude ()
1198 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1203 * Set the autopilot target altitude in feet.
1206 FGBFI::setAPAltitude (double altitude)
1208 current_autopilot->set_TargetAltitude( altitude );
1213 * Get the autopilot heading lock (true=on).
1216 FGBFI::getAPHeadingLock ()
1219 (current_autopilot->get_HeadingEnabled() &&
1220 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1225 * Set the autopilot heading lock (true=on).
1228 FGBFI::setAPHeadingLock (bool lock)
1231 // We need to do this so that
1232 // it's possible to lock onto a
1233 // heading other than the current
1235 double heading = getAPHeadingMag();
1236 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1237 current_autopilot->set_HeadingEnabled(true);
1238 setAPHeadingMag(heading);
1239 } else if (current_autopilot->get_HeadingMode() ==
1240 FGAutopilot::FG_HEADING_LOCK) {
1241 current_autopilot->set_HeadingEnabled(false);
1247 * Get the autopilot target heading in degrees.
1250 FGBFI::getAPHeading ()
1252 return current_autopilot->get_TargetHeading();
1257 * Set the autopilot target heading in degrees.
1260 FGBFI::setAPHeading (double heading)
1262 current_autopilot->set_TargetHeading( heading );
1267 * Get the autopilot target heading in degrees.
1270 FGBFI::getAPHeadingMag ()
1272 return current_autopilot->get_TargetHeading() - getMagVar();
1277 * Set the autopilot target heading in degrees.
1280 FGBFI::setAPHeadingMag (double heading)
1282 current_autopilot->set_TargetHeading( heading + getMagVar() );
1287 * Return true if the autopilot is locked to NAV1.
1290 FGBFI::getAPNAV1Lock ()
1293 (current_autopilot->get_HeadingEnabled() &&
1294 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1299 * Set the autopilot NAV1 lock.
1302 FGBFI::setAPNAV1Lock (bool lock)
1305 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1306 current_autopilot->set_HeadingEnabled(true);
1307 } else if (current_autopilot->get_HeadingMode() ==
1308 FGAutopilot::FG_HEADING_NAV1) {
1309 current_autopilot->set_HeadingEnabled(false);
1315 ////////////////////////////////////////////////////////////////////////
1316 // Radio navigation.
1317 ////////////////////////////////////////////////////////////////////////
1320 FGBFI::getNAV1Freq ()
1322 return current_radiostack->get_nav1_freq();
1326 FGBFI::getNAV1AltFreq ()
1328 return current_radiostack->get_nav1_alt_freq();
1332 FGBFI::getNAV1Radial ()
1334 return current_radiostack->get_nav1_radial();
1338 FGBFI::getNAV1SelRadial ()
1340 return current_radiostack->get_nav1_sel_radial();
1344 FGBFI::getNAV1DistDME ()
1346 return current_radiostack->get_nav1_dme_dist();
1352 if (current_radiostack->get_nav1_inrange()) {
1353 double heading = current_radiostack->get_nav1_heading();
1354 double radial = current_radiostack->get_nav1_radial();
1355 double var = FGBFI::getMagVar();
1356 if (current_radiostack->get_nav1_loc()) {
1357 double offset = fabs(heading - radial);
1358 return (offset<= 8.0 || offset >= 352.0);
1361 fabs(heading - var - radial);
1362 return (offset <= 20.0 || offset >= 340.0);
1370 FGBFI::getNAV1FROM ()
1372 if (current_radiostack->get_nav1_inrange()) {
1373 double heading = current_radiostack->get_nav1_heading();
1374 double radial = current_radiostack->get_nav1_radial();
1375 double var = FGBFI::getMagVar();
1376 if (current_radiostack->get_nav1_loc()) {
1377 double offset = fabs(heading - radial);
1378 return (offset >= 172.0 && offset<= 188.0);
1381 fabs(heading - var - radial);
1382 return (offset >= 160.0 && offset <= 200.0);
1390 FGBFI::getNAV1InRange ()
1392 return current_radiostack->get_nav1_inrange();
1396 FGBFI::getNAV1DMEInRange ()
1398 return (current_radiostack->get_nav1_inrange() &&
1399 current_radiostack->get_nav1_has_dme());
1403 FGBFI::getNAV2Freq ()
1405 return current_radiostack->get_nav2_freq();
1409 FGBFI::getNAV2AltFreq ()
1411 return current_radiostack->get_nav2_alt_freq();
1415 FGBFI::getNAV2Radial ()
1417 return current_radiostack->get_nav2_radial();
1421 FGBFI::getNAV2SelRadial ()
1423 return current_radiostack->get_nav2_sel_radial();
1427 FGBFI::getNAV2DistDME ()
1429 return current_radiostack->get_nav2_dme_dist();
1435 if (current_radiostack->get_nav2_inrange()) {
1436 double heading = current_radiostack->get_nav2_heading();
1437 double radial = current_radiostack->get_nav2_radial();
1438 double var = FGBFI::getMagVar();
1439 if (current_radiostack->get_nav2_loc()) {
1440 double offset = fabs(heading - radial);
1441 return (offset<= 8.0 || offset >= 352.0);
1444 fabs(heading - var - radial);
1445 return (offset <= 20.0 || offset >= 340.0);
1453 FGBFI::getNAV2FROM ()
1455 if (current_radiostack->get_nav2_inrange()) {
1456 double heading = current_radiostack->get_nav2_heading();
1457 double radial = current_radiostack->get_nav2_radial();
1458 double var = FGBFI::getMagVar();
1459 if (current_radiostack->get_nav2_loc()) {
1460 double offset = fabs(heading - radial);
1461 return (offset >= 172.0 && offset<= 188.0);
1464 fabs(heading - var - radial);
1465 return (offset >= 160.0 && offset <= 200.0);
1474 FGBFI::getNAV2InRange ()
1476 return current_radiostack->get_nav2_inrange();
1480 FGBFI::getNAV2DMEInRange ()
1482 return (current_radiostack->get_nav2_inrange() &&
1483 current_radiostack->get_nav2_has_dme());
1487 FGBFI::getADFFreq ()
1489 return current_radiostack->get_adf_freq();
1493 FGBFI::getADFAltFreq ()
1495 return current_radiostack->get_adf_alt_freq();
1499 FGBFI::getADFRotation ()
1501 return current_radiostack->get_adf_rotation();
1505 FGBFI::setNAV1Freq (double freq)
1507 current_radiostack->set_nav1_freq(freq);
1511 FGBFI::setNAV1AltFreq (double freq)
1513 current_radiostack->set_nav1_alt_freq(freq);
1517 FGBFI::setNAV1SelRadial (double radial)
1519 current_radiostack->set_nav1_sel_radial(radial);
1523 FGBFI::setNAV2Freq (double freq)
1525 current_radiostack->set_nav2_freq(freq);
1529 FGBFI::setNAV2AltFreq (double freq)
1531 current_radiostack->set_nav2_alt_freq(freq);
1535 FGBFI::setNAV2SelRadial (double radial)
1537 current_radiostack->set_nav2_sel_radial(radial);
1541 FGBFI::setADFFreq (double freq)
1543 current_radiostack->set_adf_freq(freq);
1547 FGBFI::setADFAltFreq (double freq)
1549 current_radiostack->set_adf_alt_freq(freq);
1553 FGBFI::setADFRotation (double rot)
1555 current_radiostack->set_adf_rotation(rot);
1560 ////////////////////////////////////////////////////////////////////////
1562 ////////////////////////////////////////////////////////////////////////
1566 * Get the autopilot GPS lock (true=on).
1569 FGBFI::getGPSLock ()
1571 return (current_autopilot->get_HeadingEnabled() &&
1572 (current_autopilot->get_HeadingMode() ==
1573 FGAutopilot::FG_HEADING_WAYPOINT ));
1578 * Set the autopilot GPS lock (true=on).
1581 FGBFI::setGPSLock (bool lock)
1584 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1585 current_autopilot->set_HeadingEnabled(true);
1586 } else if (current_autopilot->get_HeadingMode() ==
1587 FGAutopilot::FG_HEADING_WAYPOINT) {
1588 current_autopilot->set_HeadingEnabled(false);
1594 * Get the GPS target airport code.
1597 FGBFI::getTargetAirport ()
1599 // FIXME: not thread-safe
1601 out = globals->get_options()->get_airport_id();
1608 * Set the GPS target airport code.
1611 FGBFI::setTargetAirport (const string &airportId)
1613 // cout << "setting target airport id = " << airportId << endl;
1614 globals->get_options()->set_airport_id(airportId);
1619 * Get the GPS target latitude in degrees (negative for south).
1622 FGBFI::getGPSTargetLatitude ()
1624 return current_autopilot->get_TargetLatitude();
1629 * Get the GPS target longitude in degrees (negative for west).
1632 FGBFI::getGPSTargetLongitude ()
1634 return current_autopilot->get_TargetLongitude();
1639 * Set the GPS target longitude in degrees (negative for west).
1642 FGBFI::setGPSTargetLongitude (double longitude)
1644 current_autopilot->set_TargetLongitude( longitude );
1650 ////////////////////////////////////////////////////////////////////////
1652 ////////////////////////////////////////////////////////////////////////
1656 * Get the current visible (units??).
1659 FGBFI::getVisibility ()
1661 #ifndef FG_OLD_WEATHER
1662 return WeatherDatabase->getWeatherVisibility();
1664 return current_weather.get_visibility();
1670 * Set the current visibility (units??).
1673 FGBFI::setVisibility (double visibility)
1675 #ifndef FG_OLD_WEATHER
1676 WeatherDatabase->setWeatherVisibility(visibility);
1678 current_weather.set_visibility(visibility);
1684 ////////////////////////////////////////////////////////////////////////
1686 ////////////////////////////////////////////////////////////////////////
1689 * Return the magnetic variation
1694 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1699 * Return the magnetic variation
1704 return globals->get_mag()->get_magdip() * RAD_TO_DEG;