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 #ifndef FG_OLD_WEATHER
52 # include <WeatherCM/FGLocalWeatherDatabase.h>
54 # include <Weather/weather.hxx>
57 #include "globals.hxx"
58 #include "options.hxx"
60 #include "fg_init.hxx"
61 #include <simgear/misc/props.hxx>
63 FG_USING_NAMESPACE(std);
70 ////////////////////////////////////////////////////////////////////////
72 ////////////////////////////////////////////////////////////////////////
74 bool FGBFI::_needReinit = false;
78 ////////////////////////////////////////////////////////////////////////
80 ////////////////////////////////////////////////////////////////////////
84 * Initialize the BFI by binding its functions to properties.
86 * TODO: perhaps these should migrate into the individual modules
87 * (i.e. they should register themselves).
92 FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init");
94 current_properties.tieInt("/sim/flight-model",
95 getFlightModel, setFlightModel);
96 // current_properties.tieString("/sim/aircraft",
97 // getAircraft, setAircraft);
99 current_properties.tieString("/sim/time/gmt-string",
101 current_properties.tieBool("/sim/hud/visibility",
102 getHUDVisible, setHUDVisible);
103 current_properties.tieBool("/sim/panel/visibility",
104 getPanelVisible, setPanelVisible);
107 current_properties.tieDouble("/position/latitude",
108 getLatitude, setLatitude);
109 current_properties.tieDouble("/position/longitude",
110 getLongitude, setLongitude);
111 current_properties.tieDouble("/position/altitude",
112 getAltitude, setAltitude);
113 current_properties.tieDouble("/position/altitude-agl",
117 current_properties.tieDouble("/orientation/heading",
118 getHeading, setHeading);
119 current_properties.tieDouble("/orientation/heading-magnetic",
121 current_properties.tieDouble("/orientation/pitch",
123 current_properties.tieDouble("/orientation/roll",
127 current_properties.tieDouble("/engines/engine0/rpm",
129 current_properties.tieDouble("/engines/engine0/egt",
133 current_properties.tieDouble("/velocities/airspeed",
135 current_properties.tieDouble("/velocities/side-slip",
137 current_properties.tieDouble("/velocities/vertical-speed",
138 getVerticalSpeed, 0);
139 current_properties.tieDouble("/velocities/speed-north",
140 getSpeedNorth, setSpeedNorth);
141 current_properties.tieDouble("/velocities/speed-east",
142 getSpeedEast, setSpeedEast);
143 current_properties.tieDouble("/velocities/speed-down",
144 getSpeedDown, setSpeedDown);
147 current_properties.tieDouble("/controls/throttle",
148 getThrottle, setThrottle);
149 current_properties.tieDouble("/controls/mixture",
150 getMixture, setMixture);
151 current_properties.tieDouble("/controls/propellor-pitch",
152 getPropAdvance, setPropAdvance);
153 current_properties.tieDouble("/controls/flaps",
155 current_properties.tieDouble("/controls/aileron",
156 getAileron, setAileron);
157 current_properties.tieDouble("/controls/rudder",
158 getRudder, setRudder);
159 current_properties.tieDouble("/controls/elevator",
160 getElevator, setElevator);
161 current_properties.tieDouble("/controls/elevator-trim",
162 getElevatorTrim, setElevatorTrim);
163 current_properties.tieDouble("/controls/brakes/all",
164 getBrakes, setBrakes);
165 current_properties.tieDouble("/controls/brakes/left",
166 getLeftBrake, setLeftBrake);
167 current_properties.tieDouble("/controls/brakes/right",
168 getRightBrake, setRightBrake);
169 current_properties.tieDouble("/controls/brakes/center",
170 getRightBrake, setCenterBrake);
173 current_properties.tieBool("/autopilot/locks/altitude",
174 getAPAltitudeLock, setAPAltitudeLock);
175 current_properties.tieDouble("/autopilot/settings/altitude",
176 getAPAltitude, setAPAltitude);
177 current_properties.tieBool("/autopilot/locks/heading",
178 getAPHeadingLock, setAPHeadingLock);
179 current_properties.tieDouble("/autopilot/settings/heading",
180 getAPHeading, setAPHeading);
181 current_properties.tieDouble("/autopilot/settings/heading-magnetic",
182 getAPHeadingMag, setAPHeadingMag);
183 current_properties.tieBool("/autopilot/locks/nav1",
184 getAPNAV1Lock, setAPNAV1Lock);
187 current_properties.tieDouble("/radios/nav1/frequencies/selected",
188 getNAV1Freq, setNAV1Freq);
189 current_properties.tieDouble("/radios/nav1/frequencies/standby",
190 getNAV1AltFreq, setNAV1AltFreq);
191 current_properties.tieDouble("/radios/nav1/radials/actual",
193 current_properties.tieDouble("/radios/nav1/radials/selected",
194 getNAV1SelRadial, setNAV1SelRadial);
195 current_properties.tieDouble("/radios/nav1/dme/distance",
197 current_properties.tieBool("/radios/nav1/to-flag",
199 current_properties.tieBool("/radios/nav1/from-flag",
201 current_properties.tieBool("/radios/nav1/in-range",
203 current_properties.tieBool("/radios/nav1/dme/in-range",
204 getNAV1DMEInRange, 0);
206 current_properties.tieDouble("/radios/nav2/frequencies/selected",
207 getNAV2Freq, setNAV2Freq);
208 current_properties.tieDouble("/radios/nav2/frequencies/standby",
209 getNAV2AltFreq, setNAV2AltFreq);
210 current_properties.tieDouble("/radios/nav2/radials/actual",
212 current_properties.tieDouble("/radios/nav2/radials/selected",
213 getNAV2SelRadial, setNAV2SelRadial);
214 current_properties.tieDouble("/radios/nav2/dme/distance",
216 current_properties.tieBool("/radios/nav2/to-flag",
218 current_properties.tieBool("/radios/nav2/from-flag",
220 current_properties.tieBool("/radios/nav2/in-range",
222 current_properties.tieBool("/radios/nav2/dme/in-range",
223 getNAV2DMEInRange, 0);
225 current_properties.tieDouble("/radios/adf/frequencies/selected",
226 getADFFreq, setADFFreq);
227 current_properties.tieDouble("/radios/adf/frequencies/standby",
228 getADFAltFreq, setADFAltFreq);
229 current_properties.tieDouble("/radios/adf/rotation",
230 getADFRotation, setADFRotation);
232 current_properties.tieDouble("/environment/visibility",
233 getVisibility, setVisibility);
235 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
240 * Reinitialize FGFS if required.
242 * Some changes (especially those in aircraft position) require that
243 * FGFS be reinitialized afterwards. Rather than reinitialize after
244 * every change, the setter methods simply set a flag so that there
245 * can be a single reinit at the end of the frame.
257 * Reinitialize FGFS to use the new BFI settings.
262 // Save the state of everything
263 // that's going to get clobbered
264 // when we reinit the subsystems.
266 cout << "BFI: start reinit\n";
268 // TODO: add more AP stuff
269 double elevator = getElevator();
270 double aileron = getAileron();
271 double rudder = getRudder();
272 double throttle = getThrottle();
273 double elevator_trim = getElevatorTrim();
274 double flaps = getFlaps();
275 double brake = getBrakes();
276 bool apHeadingLock = getAPHeadingLock();
277 double apHeadingMag = getAPHeadingMag();
278 bool apAltitudeLock = getAPAltitudeLock();
279 double apAltitude = getAPAltitude();
280 const string &targetAirport = getTargetAirport();
281 bool gpsLock = getGPSLock();
282 double gpsLatitude = getGPSTargetLatitude();
283 double gpsLongitude = getGPSTargetLongitude();
285 setTargetAirport("");
286 cout << "Target airport is " << current_options.get_airport_id() << endl;
288 fgReInitSubsystems();
290 // FIXME: this is wrong.
291 // All of these are scheduled events,
292 // and it should be possible to force
293 // them all to run once.
296 cur_light_params.Update();
298 fgUpdateWeatherDatabase();
301 // Restore all of the old states.
302 setElevator(elevator);
305 setThrottle(throttle);
306 setElevatorTrim(elevator_trim);
309 setAPHeadingLock(apHeadingLock);
310 setAPHeadingMag(apHeadingMag);
311 setAPAltitudeLock(apAltitudeLock);
312 setAPAltitude(apAltitude);
313 setTargetAirport(targetAirport);
315 setGPSTargetLatitude(gpsLatitude);
316 setGPSTargetLongitude(gpsLongitude);
320 cout << "BFI: end reinit\n";
325 ////////////////////////////////////////////////////////////////////////
327 ////////////////////////////////////////////////////////////////////////
331 * Return the flight model as an integer.
333 * TODO: use a string instead.
336 FGBFI::getFlightModel ()
338 return current_options.get_flight_model();
343 * Return the current aircraft as a string.
346 FGBFI::getAircraft ()
348 return current_options.get_aircraft();
353 * Return the current aircraft directory (UIUC) as a string.
356 FGBFI::getAircraftDir ()
363 * Set the flight model as an integer.
365 * TODO: use a string instead.
368 FGBFI::setFlightModel (int model)
370 if (getFlightModel() != model) {
371 current_options.set_flight_model(model);
378 * Set the current aircraft.
381 FGBFI::setAircraft (const string &aircraft)
383 if (getAircraft() != aircraft) {
384 current_options.set_aircraft(aircraft);
391 * Set the current aircraft directory (UIUC).
394 FGBFI::setAircraftDir (const string &dir)
396 if (getAircraftDir() != dir) {
404 * Return the current Zulu time.
409 return globals->get_time_params()->get_cur_time();
414 * Set the current Zulu time.
417 FGBFI::setTimeGMT (time_t time)
419 if (getTimeGMT() != time) {
420 // FIXME: need to update lighting
422 current_options.set_time_offset(time);
423 current_options.set_time_offset_type(fgOPTIONS::FG_TIME_GMT_ABSOLUTE);
424 globals->get_time_params()->update( cur_fdm_state->get_Longitude(),
425 cur_fdm_state->get_Latitude(),
426 globals->get_warp() );
433 * Return the GMT as a string.
436 FGBFI::getGMTString ()
438 static string out; // FIXME: not thread-safe
440 struct tm * t = globals->get_time_params()->getGmt();
441 sprintf(buf, " %.2d:%.2d:%.2d",
442 t->tm_hour, t->tm_min, t->tm_sec);
449 * Return true if the HUD is visible.
452 FGBFI::getHUDVisible ()
454 return current_options.get_hud_status();
459 * Ensure that the HUD is visible or hidden.
462 FGBFI::setHUDVisible (bool visible)
464 current_options.set_hud_status(visible);
469 * Return true if the 2D panel is visible.
472 FGBFI::getPanelVisible ()
474 return current_options.get_panel_status();
479 * Ensure that the 2D panel is visible or hidden.
482 FGBFI::setPanelVisible (bool visible)
484 if (current_options.get_panel_status() != visible) {
485 current_options.toggle_panel();
491 ////////////////////////////////////////////////////////////////////////
493 ////////////////////////////////////////////////////////////////////////
497 * Return the current latitude in degrees (negative for south).
500 FGBFI::getLatitude ()
502 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
507 * Set the current latitude in degrees (negative for south).
510 FGBFI::setLatitude (double latitude)
512 if (getLatitude() != latitude) {
513 current_options.set_lat(latitude);
514 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
521 * Return the current longitude in degrees (negative for west).
524 FGBFI::getLongitude ()
526 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
531 * Set the current longitude in degrees (negative for west).
534 FGBFI::setLongitude (double longitude)
536 if (getLongitude() != longitude) {
537 current_options.set_lon(longitude);
538 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
545 * Return the current altitude in feet.
548 FGBFI::getAltitude ()
550 return current_aircraft.fdm_state->get_Altitude();
556 * Return the current altitude in above the terrain.
561 return current_aircraft.fdm_state->get_Altitude()
562 - (scenery.cur_elev * METER_TO_FEET);
567 * Set the current altitude in feet.
570 FGBFI::setAltitude (double altitude)
572 if (getAltitude() != altitude) {
573 fgFDMForceAltitude(getFlightModel(), altitude);
574 current_options.set_altitude(altitude);
575 current_aircraft.fdm_state->set_Altitude(altitude);
581 ////////////////////////////////////////////////////////////////////////
583 ////////////////////////////////////////////////////////////////////////
587 * Return the current heading in degrees.
592 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
597 * Return the current heading in degrees.
600 FGBFI::getHeadingMag ()
602 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
607 * Set the current heading in degrees.
610 FGBFI::setHeading (double heading)
612 if (getHeading() != heading) {
613 current_options.set_heading(heading);
614 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
615 getPitch() * DEG_TO_RAD,
616 heading * DEG_TO_RAD);
623 * Return the current pitch in degrees.
628 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
633 * Set the current pitch in degrees.
636 FGBFI::setPitch (double pitch)
638 if (getPitch() != pitch) {
639 current_options.set_pitch(pitch);
640 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
642 getHeading() * DEG_TO_RAD);
649 * Return the current roll in degrees.
654 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
659 * Set the current roll in degrees.
662 FGBFI::setRoll (double roll)
664 if (getRoll() != roll) {
665 current_options.set_roll(roll);
666 current_aircraft.fdm_state->set_Euler_Angles(roll * DEG_TO_RAD,
667 getPitch() * DEG_TO_RAD,
668 getHeading() * DEG_TO_RAD);
675 * Return the current engine0 rpm
680 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
681 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
689 * Set the current engine0 rpm
692 FGBFI::setRPM (double rpm)
695 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
700 * Return the current engine0 EGT.
705 return current_aircraft.fdm_state->get_engine(0)->get_EGT();
710 ////////////////////////////////////////////////////////////////////////
712 ////////////////////////////////////////////////////////////////////////
716 * Return the current airspeed in knots.
719 FGBFI::getAirspeed ()
721 // FIXME: should we add speed-up?
722 return current_aircraft.fdm_state->get_V_calibrated_kts();
727 * Return the current sideslip (FIXME: units unknown).
730 FGBFI::getSideSlip ()
732 return current_aircraft.fdm_state->get_Beta();
737 * Return the current climb rate in feet/minute
740 FGBFI::getVerticalSpeed ()
742 // What about meters?
743 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
748 * Get the current north velocity (units??).
751 FGBFI::getSpeedNorth ()
753 return current_aircraft.fdm_state->get_V_north();
758 * Set the current north velocity (units??).
761 FGBFI::setSpeedNorth (double speed)
763 if (getSpeedNorth() != speed) {
764 current_options.set_uBody(speed);
765 current_aircraft.fdm_state->set_Velocities_Local(speed,
774 * Get the current east velocity (units??).
777 FGBFI::getSpeedEast ()
779 return current_aircraft.fdm_state->get_V_east();
784 * Set the current east velocity (units??).
787 FGBFI::setSpeedEast (double speed)
789 if (getSpeedEast() != speed) {
790 current_options.set_vBody(speed);
791 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
800 * Get the current down velocity (units??).
803 FGBFI::getSpeedDown ()
805 return current_aircraft.fdm_state->get_V_down();
810 * Set the current down velocity (units??).
813 FGBFI::setSpeedDown (double speed)
815 if (getSpeedDown() != speed) {
816 current_options.set_wBody(speed);
817 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
826 ////////////////////////////////////////////////////////////////////////
828 ////////////////////////////////////////////////////////////////////////
832 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
835 FGBFI::getThrottle ()
837 // FIXME: add engine selector
838 return controls.get_throttle(0);
843 * Set the throttle, from 0.0 (none) to 1.0 (full).
846 FGBFI::setThrottle (double throttle)
848 // FIXME: allow engine selection
849 controls.set_throttle(0, throttle);
854 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
859 // FIXME: add engine selector
860 return controls.get_mixture(0);
865 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
868 FGBFI::setMixture (double mixture)
870 // FIXME: allow engine selection
871 controls.set_mixture(0, mixture);
876 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
879 FGBFI::getPropAdvance ()
881 // FIXME: add engine selector
882 return controls.get_prop_advance(0);
887 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
890 FGBFI::setPropAdvance (double pitch)
892 // FIXME: allow engine selection
893 controls.set_prop_advance(0, pitch);
898 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
903 return controls.get_flaps();
908 * Set the flaps, from 0.0 (none) to 1.0 (full).
911 FGBFI::setFlaps (double flaps)
914 controls.set_flaps(flaps);
919 * Get the aileron, from -1.0 (left) to 1.0 (right).
924 return controls.get_aileron();
929 * Set the aileron, from -1.0 (left) to 1.0 (right).
932 FGBFI::setAileron (double aileron)
935 controls.set_aileron(aileron);
940 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
945 return controls.get_rudder();
950 * Set the rudder, from -1.0 (left) to 1.0 (right).
953 FGBFI::setRudder (double rudder)
956 controls.set_rudder(rudder);
961 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
964 FGBFI::getElevator ()
966 return controls.get_elevator();
971 * Set the elevator, from -1.0 (down) to 1.0 (up).
974 FGBFI::setElevator (double elevator)
977 controls.set_elevator(elevator);
982 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
985 FGBFI::getElevatorTrim ()
987 return controls.get_elevator_trim();
992 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
995 FGBFI::setElevatorTrim (double trim)
998 controls.set_elevator_trim(trim);
1003 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1008 double b1 = getCenterBrake();
1009 double b2 = getLeftBrake();
1010 double b3 = getRightBrake();
1011 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1016 * Set all brakes, from 0.0 (none) to 1.0 (full).
1019 FGBFI::setBrakes (double brake)
1021 setCenterBrake(brake);
1022 setLeftBrake(brake);
1023 setRightBrake(brake);
1028 * Get the center brake, from 0.0 (none) to 1.0 (full).
1031 FGBFI::getCenterBrake ()
1033 return controls.get_brake(2);
1038 * Set the center brake, from 0.0 (none) to 1.0 (full).
1041 FGBFI::setCenterBrake (double brake)
1043 controls.set_brake(2, brake);
1048 * Get the left brake, from 0.0 (none) to 1.0 (full).
1051 FGBFI::getLeftBrake ()
1053 return controls.get_brake(0);
1058 * Set the left brake, from 0.0 (none) to 1.0 (full).
1061 FGBFI::setLeftBrake (double brake)
1063 controls.set_brake(0, brake);
1068 * Get the right brake, from 0.0 (none) to 1.0 (full).
1071 FGBFI::getRightBrake ()
1073 return controls.get_brake(1);
1078 * Set the right brake, from 0.0 (none) to 1.0 (full).
1081 FGBFI::setRightBrake (double brake)
1083 controls.set_brake(1, brake);
1090 ////////////////////////////////////////////////////////////////////////
1092 ////////////////////////////////////////////////////////////////////////
1096 * Get the autopilot altitude lock (true=on).
1099 FGBFI::getAPAltitudeLock ()
1101 return current_autopilot->get_AltitudeEnabled();
1106 * Set the autopilot altitude lock (true=on).
1109 FGBFI::setAPAltitudeLock (bool lock)
1111 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1112 current_autopilot->set_AltitudeEnabled(lock);
1117 * Get the autopilot target altitude in feet.
1120 FGBFI::getAPAltitude ()
1122 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1127 * Set the autopilot target altitude in feet.
1130 FGBFI::setAPAltitude (double altitude)
1132 current_autopilot->set_TargetAltitude( altitude );
1137 * Get the autopilot heading lock (true=on).
1140 FGBFI::getAPHeadingLock ()
1143 (current_autopilot->get_HeadingEnabled() &&
1144 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1149 * Set the autopilot heading lock (true=on).
1152 FGBFI::setAPHeadingLock (bool lock)
1155 // We need to do this so that
1156 // it's possible to lock onto a
1157 // heading other than the current
1159 double heading = getAPHeadingMag();
1160 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1161 current_autopilot->set_HeadingEnabled(true);
1162 setAPHeadingMag(heading);
1163 } else if (current_autopilot->get_HeadingMode() ==
1164 FGAutopilot::FG_HEADING_LOCK) {
1165 current_autopilot->set_HeadingEnabled(false);
1171 * Get the autopilot target heading in degrees.
1174 FGBFI::getAPHeading ()
1176 return current_autopilot->get_TargetHeading();
1181 * Set the autopilot target heading in degrees.
1184 FGBFI::setAPHeading (double heading)
1186 current_autopilot->set_TargetHeading( heading );
1191 * Get the autopilot target heading in degrees.
1194 FGBFI::getAPHeadingMag ()
1196 return current_autopilot->get_TargetHeading() - getMagVar();
1201 * Set the autopilot target heading in degrees.
1204 FGBFI::setAPHeadingMag (double heading)
1206 current_autopilot->set_TargetHeading( heading + getMagVar() );
1211 * Return true if the autopilot is locked to NAV1.
1214 FGBFI::getAPNAV1Lock ()
1217 (current_autopilot->get_HeadingEnabled() &&
1218 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1223 * Set the autopilot NAV1 lock.
1226 FGBFI::setAPNAV1Lock (bool lock)
1229 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1230 current_autopilot->set_HeadingEnabled(true);
1231 } else if (current_autopilot->get_HeadingMode() ==
1232 FGAutopilot::FG_HEADING_NAV1) {
1233 current_autopilot->set_HeadingEnabled(false);
1239 ////////////////////////////////////////////////////////////////////////
1240 // Radio navigation.
1241 ////////////////////////////////////////////////////////////////////////
1244 FGBFI::getNAV1Freq ()
1246 return current_radiostack->get_nav1_freq();
1250 FGBFI::getNAV1AltFreq ()
1252 return current_radiostack->get_nav1_alt_freq();
1256 FGBFI::getNAV1Radial ()
1258 return current_radiostack->get_nav1_radial();
1262 FGBFI::getNAV1SelRadial ()
1264 return current_radiostack->get_nav1_sel_radial();
1268 FGBFI::getNAV1DistDME ()
1270 return current_radiostack->get_nav1_dme_dist();
1276 if (current_radiostack->get_nav1_inrange()) {
1277 double heading = current_radiostack->get_nav1_heading();
1278 double radial = current_radiostack->get_nav1_radial();
1279 double var = FGBFI::getMagVar();
1280 if (current_radiostack->get_nav1_loc()) {
1281 double offset = fabs(heading - radial);
1282 return (offset<= 8.0 || offset >= 352.0);
1285 fabs(heading - var - radial);
1286 return (offset <= 20.0 || offset >= 340.0);
1294 FGBFI::getNAV1FROM ()
1296 if (current_radiostack->get_nav1_inrange()) {
1297 double heading = current_radiostack->get_nav1_heading();
1298 double radial = current_radiostack->get_nav1_radial();
1299 double var = FGBFI::getMagVar();
1300 if (current_radiostack->get_nav1_loc()) {
1301 double offset = fabs(heading - radial);
1302 return (offset >= 172.0 && offset<= 188.0);
1305 fabs(heading - var - radial);
1306 return (offset >= 160.0 && offset <= 200.0);
1314 FGBFI::getNAV1InRange ()
1316 return current_radiostack->get_nav1_inrange();
1320 FGBFI::getNAV1DMEInRange ()
1322 return (current_radiostack->get_nav1_inrange() &&
1323 current_radiostack->get_nav1_has_dme());
1327 FGBFI::getNAV2Freq ()
1329 return current_radiostack->get_nav2_freq();
1333 FGBFI::getNAV2AltFreq ()
1335 return current_radiostack->get_nav2_alt_freq();
1339 FGBFI::getNAV2Radial ()
1341 return current_radiostack->get_nav2_radial();
1345 FGBFI::getNAV2SelRadial ()
1347 return current_radiostack->get_nav2_sel_radial();
1351 FGBFI::getNAV2DistDME ()
1353 return current_radiostack->get_nav2_dme_dist();
1359 if (current_radiostack->get_nav2_inrange()) {
1360 double heading = current_radiostack->get_nav2_heading();
1361 double radial = current_radiostack->get_nav2_radial();
1362 double var = FGBFI::getMagVar();
1363 if (current_radiostack->get_nav2_loc()) {
1364 double offset = fabs(heading - radial);
1365 return (offset<= 8.0 || offset >= 352.0);
1368 fabs(heading - var - radial);
1369 return (offset <= 20.0 || offset >= 340.0);
1377 FGBFI::getNAV2FROM ()
1379 if (current_radiostack->get_nav2_inrange()) {
1380 double heading = current_radiostack->get_nav2_heading();
1381 double radial = current_radiostack->get_nav2_radial();
1382 double var = FGBFI::getMagVar();
1383 if (current_radiostack->get_nav2_loc()) {
1384 double offset = fabs(heading - radial);
1385 return (offset >= 172.0 && offset<= 188.0);
1388 fabs(heading - var - radial);
1389 return (offset >= 160.0 && offset <= 200.0);
1398 FGBFI::getNAV2InRange ()
1400 return current_radiostack->get_nav2_inrange();
1404 FGBFI::getNAV2DMEInRange ()
1406 return (current_radiostack->get_nav2_inrange() &&
1407 current_radiostack->get_nav2_has_dme());
1411 FGBFI::getADFFreq ()
1413 return current_radiostack->get_adf_freq();
1417 FGBFI::getADFAltFreq ()
1419 return current_radiostack->get_adf_alt_freq();
1423 FGBFI::getADFRotation ()
1425 return current_radiostack->get_adf_rotation();
1429 FGBFI::setNAV1Freq (double freq)
1431 current_radiostack->set_nav1_freq(freq);
1435 FGBFI::setNAV1AltFreq (double freq)
1437 current_radiostack->set_nav1_alt_freq(freq);
1441 FGBFI::setNAV1SelRadial (double radial)
1443 current_radiostack->set_nav1_sel_radial(radial);
1447 FGBFI::setNAV2Freq (double freq)
1449 current_radiostack->set_nav2_freq(freq);
1453 FGBFI::setNAV2AltFreq (double freq)
1455 current_radiostack->set_nav2_alt_freq(freq);
1459 FGBFI::setNAV2SelRadial (double radial)
1461 current_radiostack->set_nav2_sel_radial(radial);
1465 FGBFI::setADFFreq (double freq)
1467 current_radiostack->set_adf_freq(freq);
1471 FGBFI::setADFAltFreq (double freq)
1473 current_radiostack->set_adf_alt_freq(freq);
1477 FGBFI::setADFRotation (double rot)
1479 current_radiostack->set_adf_rotation(rot);
1484 ////////////////////////////////////////////////////////////////////////
1486 ////////////////////////////////////////////////////////////////////////
1490 * Get the autopilot GPS lock (true=on).
1493 FGBFI::getGPSLock ()
1495 return (current_autopilot->get_HeadingEnabled() &&
1496 (current_autopilot->get_HeadingMode() ==
1497 FGAutopilot::FG_HEADING_WAYPOINT ));
1502 * Set the autopilot GPS lock (true=on).
1505 FGBFI::setGPSLock (bool lock)
1508 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1509 current_autopilot->set_HeadingEnabled(true);
1510 } else if (current_autopilot->get_HeadingMode() ==
1511 FGAutopilot::FG_HEADING_WAYPOINT) {
1512 current_autopilot->set_HeadingEnabled(false);
1518 * Get the GPS target airport code.
1521 FGBFI::getTargetAirport ()
1523 return current_options.get_airport_id();
1528 * Set the GPS target airport code.
1531 FGBFI::setTargetAirport (const string &airportId)
1533 current_options.set_airport_id(airportId);
1538 * Get the GPS target latitude in degrees (negative for south).
1541 FGBFI::getGPSTargetLatitude ()
1543 return current_autopilot->get_TargetLatitude();
1548 * Set the GPS target latitude in degrees (negative for south).
1551 FGBFI::setGPSTargetLatitude (double latitude)
1553 current_autopilot->set_TargetLatitude( latitude );
1558 * Get the GPS target longitude in degrees (negative for west).
1561 FGBFI::getGPSTargetLongitude ()
1563 return current_autopilot->get_TargetLongitude();
1568 * Set the GPS target longitude in degrees (negative for west).
1571 FGBFI::setGPSTargetLongitude (double longitude)
1573 current_autopilot->set_TargetLongitude( longitude );
1578 ////////////////////////////////////////////////////////////////////////
1580 ////////////////////////////////////////////////////////////////////////
1584 * Get the current visible (units??).
1587 FGBFI::getVisibility ()
1589 #ifndef FG_OLD_WEATHER
1590 return WeatherDatabase->getWeatherVisibility();
1592 return current_weather.get_visibility();
1598 * Check whether clouds are enabled.
1603 return current_options.get_clouds();
1608 * Check the height of the clouds ASL (units?).
1611 FGBFI::getCloudsASL ()
1613 return current_options.get_clouds_asl();
1618 * Set the current visibility (units??).
1621 FGBFI::setVisibility (double visibility)
1623 #ifndef FG_OLD_WEATHER
1624 WeatherDatabase->setWeatherVisibility(visibility);
1626 current_weather.set_visibility(visibility);
1632 * Switch clouds on or off.
1635 FGBFI::setClouds (bool clouds)
1637 if (getClouds() != clouds) {
1638 cout << "Set clouds to " << clouds << endl;
1639 current_options.set_clouds(clouds);
1646 * Set the cloud height.
1649 FGBFI::setCloudsASL (double cloudsASL)
1651 if (getCloudsASL() != cloudsASL) {
1652 current_options.set_clouds_asl(cloudsASL);
1659 ////////////////////////////////////////////////////////////////////////
1661 ////////////////////////////////////////////////////////////////////////
1664 * Return the magnetic variation
1669 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1674 * Return the magnetic variation
1679 return globals->get_mag()->get_magdip() * RAD_TO_DEG;