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();
761 * Return the current engine0 CHT.
766 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
767 return current_aircraft.fdm_state->get_engine(0)->get_CHT();
773 * Return the current engine0 CHT.
778 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
779 return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
785 ////////////////////////////////////////////////////////////////////////
787 ////////////////////////////////////////////////////////////////////////
791 * Return the current airspeed in knots.
794 FGBFI::getAirspeed ()
796 // FIXME: should we add speed-up?
797 return current_aircraft.fdm_state->get_V_calibrated_kts();
802 * Set the calibrated airspeed in knots.
805 FGBFI::setAirspeed (double speed)
807 current_aircraft.fdm_state->set_V_calibrated_kts(speed);
812 * Return the current sideslip (FIXME: units unknown).
815 FGBFI::getSideSlip ()
817 return current_aircraft.fdm_state->get_Beta();
822 * Return the current climb rate in feet/minute
825 FGBFI::getVerticalSpeed ()
827 // What about meters?
828 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
833 * Get the current north velocity (units??).
836 FGBFI::getSpeedNorth ()
838 return current_aircraft.fdm_state->get_V_north();
843 // * Set the current north velocity (units??).
846 // FGBFI::setSpeedNorth (double speed)
848 // FGInterface * fdm = current_aircraft.fdm_state;
849 // // fdm->set_Velocities_Local(speed, fdm->get_V_east(), fdm->get_V_down());
854 * Get the current east velocity (units??).
857 FGBFI::getSpeedEast ()
859 return current_aircraft.fdm_state->get_V_east();
864 // * Set the current east velocity (units??).
867 // FGBFI::setSpeedEast (double speed)
869 // FGInterface * fdm = current_aircraft.fdm_state;
870 // // fdm->set_Velocities_Local(fdm->get_V_north(), speed, fdm->get_V_down());
875 * Get the current down velocity (units??).
878 FGBFI::getSpeedDown ()
880 return current_aircraft.fdm_state->get_V_down();
885 // * Set the current down velocity (units??).
888 // FGBFI::setSpeedDown (double speed)
890 // FGInterface * fdm = current_aircraft.fdm_state;
891 // // fdm->set_Velocities_Local(fdm->get_V_north(), fdm->get_V_east(), speed);
896 ////////////////////////////////////////////////////////////////////////
898 ////////////////////////////////////////////////////////////////////////
902 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
905 FGBFI::getThrottle ()
907 // FIXME: add engine selector
908 return controls.get_throttle(0);
913 * Set the throttle, from 0.0 (none) to 1.0 (full).
916 FGBFI::setThrottle (double throttle)
918 // FIXME: allow engine selection
919 controls.set_throttle(0, throttle);
924 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
929 // FIXME: add engine selector
930 return controls.get_mixture(0);
935 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
938 FGBFI::setMixture (double mixture)
940 // FIXME: allow engine selection
941 controls.set_mixture(0, mixture);
946 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
949 FGBFI::getPropAdvance ()
951 // FIXME: add engine selector
952 return controls.get_prop_advance(0);
957 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
960 FGBFI::setPropAdvance (double pitch)
962 // FIXME: allow engine selection
963 controls.set_prop_advance(0, pitch);
968 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
973 return controls.get_flaps();
978 * Set the flaps, from 0.0 (none) to 1.0 (full).
981 FGBFI::setFlaps (double flaps)
984 controls.set_flaps(flaps);
989 * Get the aileron, from -1.0 (left) to 1.0 (right).
994 return controls.get_aileron();
999 * Set the aileron, from -1.0 (left) to 1.0 (right).
1002 FGBFI::setAileron (double aileron)
1005 controls.set_aileron(aileron);
1010 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
1015 return controls.get_rudder();
1020 * Set the rudder, from -1.0 (left) to 1.0 (right).
1023 FGBFI::setRudder (double rudder)
1026 controls.set_rudder(rudder);
1031 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
1034 FGBFI::getElevator ()
1036 return controls.get_elevator();
1041 * Set the elevator, from -1.0 (down) to 1.0 (up).
1044 FGBFI::setElevator (double elevator)
1047 controls.set_elevator(elevator);
1052 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
1055 FGBFI::getElevatorTrim ()
1057 return controls.get_elevator_trim();
1062 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
1065 FGBFI::setElevatorTrim (double trim)
1068 controls.set_elevator_trim(trim);
1073 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1078 double b1 = getCenterBrake();
1079 double b2 = getLeftBrake();
1080 double b3 = getRightBrake();
1081 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1086 * Set all brakes, from 0.0 (none) to 1.0 (full).
1089 FGBFI::setBrakes (double brake)
1091 setCenterBrake(brake);
1092 setLeftBrake(brake);
1093 setRightBrake(brake);
1098 * Get the center brake, from 0.0 (none) to 1.0 (full).
1101 FGBFI::getCenterBrake ()
1103 return controls.get_brake(2);
1108 * Set the center brake, from 0.0 (none) to 1.0 (full).
1111 FGBFI::setCenterBrake (double brake)
1113 controls.set_brake(2, brake);
1118 * Get the left brake, from 0.0 (none) to 1.0 (full).
1121 FGBFI::getLeftBrake ()
1123 return controls.get_brake(0);
1128 * Set the left brake, from 0.0 (none) to 1.0 (full).
1131 FGBFI::setLeftBrake (double brake)
1133 controls.set_brake(0, brake);
1138 * Get the right brake, from 0.0 (none) to 1.0 (full).
1141 FGBFI::getRightBrake ()
1143 return controls.get_brake(1);
1148 * Set the right brake, from 0.0 (none) to 1.0 (full).
1151 FGBFI::setRightBrake (double brake)
1153 controls.set_brake(1, brake);
1160 ////////////////////////////////////////////////////////////////////////
1162 ////////////////////////////////////////////////////////////////////////
1166 * Get the autopilot altitude lock (true=on).
1169 FGBFI::getAPAltitudeLock ()
1171 return current_autopilot->get_AltitudeEnabled();
1176 * Set the autopilot altitude lock (true=on).
1179 FGBFI::setAPAltitudeLock (bool lock)
1181 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1182 current_autopilot->set_AltitudeEnabled(lock);
1187 * Get the autopilot target altitude in feet.
1190 FGBFI::getAPAltitude ()
1192 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1197 * Set the autopilot target altitude in feet.
1200 FGBFI::setAPAltitude (double altitude)
1202 current_autopilot->set_TargetAltitude( altitude );
1207 * Get the autopilot heading lock (true=on).
1210 FGBFI::getAPHeadingLock ()
1213 (current_autopilot->get_HeadingEnabled() &&
1214 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1219 * Set the autopilot heading lock (true=on).
1222 FGBFI::setAPHeadingLock (bool lock)
1225 // We need to do this so that
1226 // it's possible to lock onto a
1227 // heading other than the current
1229 double heading = getAPHeadingMag();
1230 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1231 current_autopilot->set_HeadingEnabled(true);
1232 setAPHeadingMag(heading);
1233 } else if (current_autopilot->get_HeadingMode() ==
1234 FGAutopilot::FG_HEADING_LOCK) {
1235 current_autopilot->set_HeadingEnabled(false);
1241 * Get the autopilot target heading in degrees.
1244 FGBFI::getAPHeading ()
1246 return current_autopilot->get_TargetHeading();
1251 * Set the autopilot target heading in degrees.
1254 FGBFI::setAPHeading (double heading)
1256 current_autopilot->set_TargetHeading( heading );
1261 * Get the autopilot target heading in degrees.
1264 FGBFI::getAPHeadingMag ()
1266 return current_autopilot->get_TargetHeading() - getMagVar();
1271 * Set the autopilot target heading in degrees.
1274 FGBFI::setAPHeadingMag (double heading)
1276 current_autopilot->set_TargetHeading( heading + getMagVar() );
1281 * Return true if the autopilot is locked to NAV1.
1284 FGBFI::getAPNAV1Lock ()
1287 (current_autopilot->get_HeadingEnabled() &&
1288 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1293 * Set the autopilot NAV1 lock.
1296 FGBFI::setAPNAV1Lock (bool lock)
1299 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1300 current_autopilot->set_HeadingEnabled(true);
1301 } else if (current_autopilot->get_HeadingMode() ==
1302 FGAutopilot::FG_HEADING_NAV1) {
1303 current_autopilot->set_HeadingEnabled(false);
1309 ////////////////////////////////////////////////////////////////////////
1310 // Radio navigation.
1311 ////////////////////////////////////////////////////////////////////////
1314 FGBFI::getNAV1Freq ()
1316 return current_radiostack->get_nav1_freq();
1320 FGBFI::getNAV1AltFreq ()
1322 return current_radiostack->get_nav1_alt_freq();
1326 FGBFI::getNAV1Radial ()
1328 return current_radiostack->get_nav1_radial();
1332 FGBFI::getNAV1SelRadial ()
1334 return current_radiostack->get_nav1_sel_radial();
1338 FGBFI::getNAV1DistDME ()
1340 return current_radiostack->get_nav1_dme_dist();
1346 if (current_radiostack->get_nav1_inrange()) {
1347 double heading = current_radiostack->get_nav1_heading();
1348 double radial = current_radiostack->get_nav1_radial();
1349 double var = FGBFI::getMagVar();
1350 if (current_radiostack->get_nav1_loc()) {
1351 double offset = fabs(heading - radial);
1352 return (offset<= 8.0 || offset >= 352.0);
1355 fabs(heading - var - radial);
1356 return (offset <= 20.0 || offset >= 340.0);
1364 FGBFI::getNAV1FROM ()
1366 if (current_radiostack->get_nav1_inrange()) {
1367 double heading = current_radiostack->get_nav1_heading();
1368 double radial = current_radiostack->get_nav1_radial();
1369 double var = FGBFI::getMagVar();
1370 if (current_radiostack->get_nav1_loc()) {
1371 double offset = fabs(heading - radial);
1372 return (offset >= 172.0 && offset<= 188.0);
1375 fabs(heading - var - radial);
1376 return (offset >= 160.0 && offset <= 200.0);
1384 FGBFI::getNAV1InRange ()
1386 return current_radiostack->get_nav1_inrange();
1390 FGBFI::getNAV1DMEInRange ()
1392 return (current_radiostack->get_nav1_inrange() &&
1393 current_radiostack->get_nav1_has_dme());
1397 FGBFI::getNAV2Freq ()
1399 return current_radiostack->get_nav2_freq();
1403 FGBFI::getNAV2AltFreq ()
1405 return current_radiostack->get_nav2_alt_freq();
1409 FGBFI::getNAV2Radial ()
1411 return current_radiostack->get_nav2_radial();
1415 FGBFI::getNAV2SelRadial ()
1417 return current_radiostack->get_nav2_sel_radial();
1421 FGBFI::getNAV2DistDME ()
1423 return current_radiostack->get_nav2_dme_dist();
1429 if (current_radiostack->get_nav2_inrange()) {
1430 double heading = current_radiostack->get_nav2_heading();
1431 double radial = current_radiostack->get_nav2_radial();
1432 double var = FGBFI::getMagVar();
1433 if (current_radiostack->get_nav2_loc()) {
1434 double offset = fabs(heading - radial);
1435 return (offset<= 8.0 || offset >= 352.0);
1438 fabs(heading - var - radial);
1439 return (offset <= 20.0 || offset >= 340.0);
1447 FGBFI::getNAV2FROM ()
1449 if (current_radiostack->get_nav2_inrange()) {
1450 double heading = current_radiostack->get_nav2_heading();
1451 double radial = current_radiostack->get_nav2_radial();
1452 double var = FGBFI::getMagVar();
1453 if (current_radiostack->get_nav2_loc()) {
1454 double offset = fabs(heading - radial);
1455 return (offset >= 172.0 && offset<= 188.0);
1458 fabs(heading - var - radial);
1459 return (offset >= 160.0 && offset <= 200.0);
1468 FGBFI::getNAV2InRange ()
1470 return current_radiostack->get_nav2_inrange();
1474 FGBFI::getNAV2DMEInRange ()
1476 return (current_radiostack->get_nav2_inrange() &&
1477 current_radiostack->get_nav2_has_dme());
1481 FGBFI::getADFFreq ()
1483 return current_radiostack->get_adf_freq();
1487 FGBFI::getADFAltFreq ()
1489 return current_radiostack->get_adf_alt_freq();
1493 FGBFI::getADFRotation ()
1495 return current_radiostack->get_adf_rotation();
1499 FGBFI::setNAV1Freq (double freq)
1501 current_radiostack->set_nav1_freq(freq);
1505 FGBFI::setNAV1AltFreq (double freq)
1507 current_radiostack->set_nav1_alt_freq(freq);
1511 FGBFI::setNAV1SelRadial (double radial)
1513 current_radiostack->set_nav1_sel_radial(radial);
1517 FGBFI::setNAV2Freq (double freq)
1519 current_radiostack->set_nav2_freq(freq);
1523 FGBFI::setNAV2AltFreq (double freq)
1525 current_radiostack->set_nav2_alt_freq(freq);
1529 FGBFI::setNAV2SelRadial (double radial)
1531 current_radiostack->set_nav2_sel_radial(radial);
1535 FGBFI::setADFFreq (double freq)
1537 current_radiostack->set_adf_freq(freq);
1541 FGBFI::setADFAltFreq (double freq)
1543 current_radiostack->set_adf_alt_freq(freq);
1547 FGBFI::setADFRotation (double rot)
1549 current_radiostack->set_adf_rotation(rot);
1554 ////////////////////////////////////////////////////////////////////////
1556 ////////////////////////////////////////////////////////////////////////
1560 * Get the autopilot GPS lock (true=on).
1563 FGBFI::getGPSLock ()
1565 return (current_autopilot->get_HeadingEnabled() &&
1566 (current_autopilot->get_HeadingMode() ==
1567 FGAutopilot::FG_HEADING_WAYPOINT ));
1572 * Set the autopilot GPS lock (true=on).
1575 FGBFI::setGPSLock (bool lock)
1578 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1579 current_autopilot->set_HeadingEnabled(true);
1580 } else if (current_autopilot->get_HeadingMode() ==
1581 FGAutopilot::FG_HEADING_WAYPOINT) {
1582 current_autopilot->set_HeadingEnabled(false);
1588 * Get the GPS target airport code.
1591 FGBFI::getTargetAirport ()
1593 // FIXME: not thread-safe
1595 out = globals->get_options()->get_airport_id();
1602 * Set the GPS target airport code.
1605 FGBFI::setTargetAirport (const string &airportId)
1607 // cout << "setting target airport id = " << airportId << endl;
1608 globals->get_options()->set_airport_id(airportId);
1613 * Get the GPS target latitude in degrees (negative for south).
1616 FGBFI::getGPSTargetLatitude ()
1618 return current_autopilot->get_TargetLatitude();
1623 * Get the GPS target longitude in degrees (negative for west).
1626 FGBFI::getGPSTargetLongitude ()
1628 return current_autopilot->get_TargetLongitude();
1633 * Set the GPS target longitude in degrees (negative for west).
1636 FGBFI::setGPSTargetLongitude (double longitude)
1638 current_autopilot->set_TargetLongitude( longitude );
1644 ////////////////////////////////////////////////////////////////////////
1646 ////////////////////////////////////////////////////////////////////////
1650 * Get the current visible (units??).
1653 FGBFI::getVisibility ()
1655 #ifndef FG_OLD_WEATHER
1656 return WeatherDatabase->getWeatherVisibility();
1658 return current_weather.get_visibility();
1664 * Set the current visibility (units??).
1667 FGBFI::setVisibility (double visibility)
1669 #ifndef FG_OLD_WEATHER
1670 WeatherDatabase->setWeatherVisibility(visibility);
1672 current_weather.set_visibility(visibility);
1678 ////////////////////////////////////////////////////////////////////////
1680 ////////////////////////////////////////////////////////////////////////
1683 * Return the magnetic variation
1688 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1693 * Return the magnetic variation
1698 return globals->get_mag()->get_magdip() * RAD_TO_DEG;