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"
59 #include "fg_init.hxx"
60 #include <simgear/misc/props.hxx>
62 FG_USING_NAMESPACE(std);
69 ////////////////////////////////////////////////////////////////////////
71 ////////////////////////////////////////////////////////////////////////
73 bool FGBFI::_needReinit = false;
77 ////////////////////////////////////////////////////////////////////////
79 ////////////////////////////////////////////////////////////////////////
83 * Initialize the BFI by binding its functions to properties.
85 * TODO: perhaps these should migrate into the individual modules
86 * (i.e. they should register themselves).
91 FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init");
93 current_properties.tieInt("/sim/flight-model",
94 getFlightModel, setFlightModel);
95 // current_properties.tieString("/sim/aircraft",
96 // getAircraft, setAircraft);
98 current_properties.tieString("/sim/time/gmt-string",
100 current_properties.tieBool("/sim/hud/visibility",
101 getHUDVisible, setHUDVisible);
102 current_properties.tieBool("/sim/panel/visibility",
103 getPanelVisible, setPanelVisible);
106 current_properties.tieString("/position/airport-id",
107 getTargetAirport, setTargetAirport);
108 current_properties.tieDouble("/position/latitude",
109 getLatitude, setLatitude);
110 current_properties.tieDouble("/position/longitude",
111 getLongitude, setLongitude);
112 current_properties.tieDouble("/position/altitude",
113 // getAltitude, setAltitude);
114 getAltitude, setAltitude, false);
115 current_properties.tieDouble("/position/altitude-agl",
119 current_properties.tieDouble("/orientation/heading",
120 getHeading, setHeading);
121 current_properties.tieDouble("/orientation/heading-magnetic",
123 current_properties.tieDouble("/orientation/pitch",
125 current_properties.tieDouble("/orientation/roll",
129 current_properties.tieDouble("/engines/engine0/rpm",
131 current_properties.tieDouble("/engines/engine0/egt",
133 current_properties.tieDouble("/engines/engine0/cht",
135 current_properties.tieDouble("/engines/engine0/mp",
139 current_properties.tieDouble("/velocities/airspeed",
141 current_properties.tieDouble("/velocities/side-slip",
143 current_properties.tieDouble("/velocities/vertical-speed",
144 getVerticalSpeed, 0);
145 current_properties.tieDouble("/velocities/speed-north",
146 getSpeedNorth, setSpeedNorth);
147 current_properties.tieDouble("/velocities/speed-east",
148 getSpeedEast, setSpeedEast);
149 current_properties.tieDouble("/velocities/speed-down",
150 getSpeedDown, setSpeedDown);
153 current_properties.tieDouble("/controls/throttle",
154 getThrottle, setThrottle);
155 current_properties.tieDouble("/controls/mixture",
156 getMixture, setMixture);
157 current_properties.tieDouble("/controls/propellor-pitch",
158 getPropAdvance, setPropAdvance);
159 current_properties.tieDouble("/controls/flaps",
161 current_properties.tieDouble("/controls/aileron",
162 getAileron, setAileron);
163 current_properties.tieDouble("/controls/rudder",
164 getRudder, setRudder);
165 current_properties.tieDouble("/controls/elevator",
166 getElevator, setElevator);
167 current_properties.tieDouble("/controls/elevator-trim",
168 getElevatorTrim, setElevatorTrim);
169 current_properties.tieDouble("/controls/brakes/all",
170 getBrakes, setBrakes);
171 current_properties.tieDouble("/controls/brakes/left",
172 getLeftBrake, setLeftBrake);
173 current_properties.tieDouble("/controls/brakes/right",
174 getRightBrake, setRightBrake);
175 current_properties.tieDouble("/controls/brakes/center",
176 getRightBrake, setCenterBrake);
179 current_properties.tieBool("/autopilot/locks/altitude",
180 getAPAltitudeLock, setAPAltitudeLock);
181 current_properties.tieDouble("/autopilot/settings/altitude",
182 getAPAltitude, setAPAltitude);
183 current_properties.tieBool("/autopilot/locks/heading",
184 getAPHeadingLock, setAPHeadingLock);
185 current_properties.tieDouble("/autopilot/settings/heading",
186 getAPHeading, setAPHeading);
187 current_properties.tieDouble("/autopilot/settings/heading-magnetic",
188 getAPHeadingMag, setAPHeadingMag);
189 current_properties.tieBool("/autopilot/locks/nav1",
190 getAPNAV1Lock, setAPNAV1Lock);
193 current_properties.tieDouble("/radios/nav1/frequencies/selected",
194 getNAV1Freq, setNAV1Freq);
195 current_properties.tieDouble("/radios/nav1/frequencies/standby",
196 getNAV1AltFreq, setNAV1AltFreq);
197 current_properties.tieDouble("/radios/nav1/radials/actual",
199 current_properties.tieDouble("/radios/nav1/radials/selected",
200 getNAV1SelRadial, setNAV1SelRadial);
201 current_properties.tieDouble("/radios/nav1/dme/distance",
203 current_properties.tieBool("/radios/nav1/to-flag",
205 current_properties.tieBool("/radios/nav1/from-flag",
207 current_properties.tieBool("/radios/nav1/in-range",
209 current_properties.tieBool("/radios/nav1/dme/in-range",
210 getNAV1DMEInRange, 0);
212 current_properties.tieDouble("/radios/nav2/frequencies/selected",
213 getNAV2Freq, setNAV2Freq);
214 current_properties.tieDouble("/radios/nav2/frequencies/standby",
215 getNAV2AltFreq, setNAV2AltFreq);
216 current_properties.tieDouble("/radios/nav2/radials/actual",
218 current_properties.tieDouble("/radios/nav2/radials/selected",
219 getNAV2SelRadial, setNAV2SelRadial);
220 current_properties.tieDouble("/radios/nav2/dme/distance",
222 current_properties.tieBool("/radios/nav2/to-flag",
224 current_properties.tieBool("/radios/nav2/from-flag",
226 current_properties.tieBool("/radios/nav2/in-range",
228 current_properties.tieBool("/radios/nav2/dme/in-range",
229 getNAV2DMEInRange, 0);
231 current_properties.tieDouble("/radios/adf/frequencies/selected",
232 getADFFreq, setADFFreq);
233 current_properties.tieDouble("/radios/adf/frequencies/standby",
234 getADFAltFreq, setADFAltFreq);
235 current_properties.tieDouble("/radios/adf/rotation",
236 getADFRotation, setADFRotation);
238 current_properties.tieDouble("/environment/visibility",
239 getVisibility, setVisibility);
243 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
248 * Reinitialize FGFS if required.
250 * Some changes (especially those in aircraft position) require that
251 * FGFS be reinitialized afterwards. Rather than reinitialize after
252 * every change, the setter methods simply set a flag so that there
253 * can be a single reinit at the end of the frame.
265 * Reinitialize FGFS to use the new BFI settings.
270 // Save the state of everything
271 // that's going to get clobbered
272 // when we reinit the subsystems.
274 cout << "BFI: start reinit\n";
276 // TODO: add more AP stuff
277 double elevator = getElevator();
278 double aileron = getAileron();
279 double rudder = getRudder();
280 double throttle = getThrottle();
281 double elevator_trim = getElevatorTrim();
282 double flaps = getFlaps();
283 double brake = getBrakes();
284 bool apHeadingLock = getAPHeadingLock();
285 double apHeadingMag = getAPHeadingMag();
286 bool apAltitudeLock = getAPAltitudeLock();
287 double apAltitude = getAPAltitude();
288 const string &targetAirport = getTargetAirport();
289 bool gpsLock = getGPSLock();
290 double gpsLatitude = getGPSTargetLatitude();
291 double gpsLongitude = getGPSTargetLongitude();
293 setTargetAirport("");
294 cout << "Target airport is " << globals->get_options()->get_airport_id() << endl;
296 fgReInitSubsystems();
298 // FIXME: this is wrong.
299 // All of these are scheduled events,
300 // and it should be possible to force
301 // them all to run once.
304 cur_light_params.Update();
306 fgUpdateWeatherDatabase();
309 // Restore all of the old states.
310 setElevator(elevator);
313 setThrottle(throttle);
314 setElevatorTrim(elevator_trim);
317 setAPHeadingLock(apHeadingLock);
318 setAPHeadingMag(apHeadingMag);
319 setAPAltitudeLock(apAltitudeLock);
320 setAPAltitude(apAltitude);
321 setTargetAirport(targetAirport);
326 cout << "BFI: end reinit\n";
331 ////////////////////////////////////////////////////////////////////////
333 ////////////////////////////////////////////////////////////////////////
337 * Return the flight model as an integer.
339 * TODO: use a string instead.
342 FGBFI::getFlightModel ()
344 return globals->get_options()->get_flight_model();
349 * Return the current aircraft as a string.
352 FGBFI::getAircraft ()
354 return globals->get_options()->get_aircraft();
359 * Return the current aircraft directory (UIUC) as a string.
362 FGBFI::getAircraftDir ()
369 * Set the flight model as an integer.
371 * TODO: use a string instead.
374 FGBFI::setFlightModel (int model)
376 if (getFlightModel() != model) {
377 globals->get_options()->set_flight_model(model);
384 * Set the current aircraft.
387 FGBFI::setAircraft (const string &aircraft)
389 if (getAircraft() != aircraft) {
390 globals->get_options()->set_aircraft(aircraft);
397 * Set the current aircraft directory (UIUC).
400 FGBFI::setAircraftDir (const string &dir)
402 if (getAircraftDir() != dir) {
410 * Return the current Zulu time.
415 return globals->get_time_params()->get_cur_time();
420 * Set the current Zulu time.
423 FGBFI::setTimeGMT (time_t time)
425 if (getTimeGMT() != time) {
426 // FIXME: need to update lighting
428 globals->get_options()->set_time_offset(time);
429 globals->get_options()->set_time_offset_type(FGOptions::FG_TIME_GMT_ABSOLUTE);
430 globals->get_time_params()->update( cur_fdm_state->get_Longitude(),
431 cur_fdm_state->get_Latitude(),
432 globals->get_warp() );
439 * Return the GMT as a string.
442 FGBFI::getGMTString ()
444 static string out; // FIXME: not thread-safe
446 struct tm * t = globals->get_time_params()->getGmt();
447 sprintf(buf, " %.2d:%.2d:%.2d",
448 t->tm_hour, t->tm_min, t->tm_sec);
455 * Return true if the HUD is visible.
458 FGBFI::getHUDVisible ()
460 return globals->get_options()->get_hud_status();
465 * Ensure that the HUD is visible or hidden.
468 FGBFI::setHUDVisible (bool visible)
470 globals->get_options()->set_hud_status(visible);
475 * Return true if the 2D panel is visible.
478 FGBFI::getPanelVisible ()
480 return globals->get_options()->get_panel_status();
485 * Ensure that the 2D panel is visible or hidden.
488 FGBFI::setPanelVisible (bool visible)
490 if (globals->get_options()->get_panel_status() != visible) {
491 globals->get_options()->toggle_panel();
497 ////////////////////////////////////////////////////////////////////////
499 ////////////////////////////////////////////////////////////////////////
503 * Return the current latitude in degrees (negative for south).
506 FGBFI::getLatitude ()
508 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
513 * Set the current latitude in degrees (negative for south).
516 FGBFI::setLatitude (double latitude)
518 if (getLatitude() != latitude) {
519 globals->get_options()->set_lat(latitude);
520 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
527 * Return the current longitude in degrees (negative for west).
530 FGBFI::getLongitude ()
532 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
537 * Set the current longitude in degrees (negative for west).
540 FGBFI::setLongitude (double longitude)
542 if (getLongitude() != longitude) {
543 globals->get_options()->set_lon(longitude);
544 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
551 * Return the current altitude in feet.
554 FGBFI::getAltitude ()
556 return current_aircraft.fdm_state->get_Altitude();
562 * Return the current altitude in above the terrain.
567 return current_aircraft.fdm_state->get_Altitude()
568 - (scenery.cur_elev * METER_TO_FEET);
573 * Set the current altitude in feet.
576 FGBFI::setAltitude (double altitude)
578 if (getAltitude() != altitude) {
579 fgFDMForceAltitude(getFlightModel(), altitude);
580 globals->get_options()->set_altitude(altitude);
581 current_aircraft.fdm_state->set_Altitude(altitude);
587 ////////////////////////////////////////////////////////////////////////
589 ////////////////////////////////////////////////////////////////////////
593 * Return the current heading in degrees.
598 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
603 * Return the current heading in degrees.
606 FGBFI::getHeadingMag ()
608 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
613 * Set the current heading in degrees.
616 FGBFI::setHeading (double heading)
618 if (getHeading() != heading) {
619 globals->get_options()->set_heading(heading);
620 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
621 getPitch() * DEG_TO_RAD,
622 heading * DEG_TO_RAD);
629 * Return the current pitch in degrees.
634 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
639 * Set the current pitch in degrees.
642 FGBFI::setPitch (double pitch)
644 if (getPitch() != pitch) {
645 globals->get_options()->set_pitch(pitch);
646 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
648 getHeading() * DEG_TO_RAD);
655 * Return the current roll in degrees.
660 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
665 * Set the current roll in degrees.
668 FGBFI::setRoll (double roll)
670 if (getRoll() != roll) {
671 globals->get_options()->set_roll(roll);
672 current_aircraft.fdm_state->set_Euler_Angles(roll * DEG_TO_RAD,
673 getPitch() * DEG_TO_RAD,
674 getHeading() * DEG_TO_RAD);
681 * Return the current engine0 rpm
686 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
687 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
695 * Set the current engine0 rpm
698 FGBFI::setRPM (double rpm)
700 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
701 if (getRPM() != rpm) {
702 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
709 * Return the current engine0 EGT.
714 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
715 return current_aircraft.fdm_state->get_engine(0)->get_EGT();
721 * Return the current engine0 CHT.
726 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
727 return current_aircraft.fdm_state->get_engine(0)->get_CHT();
733 * Return the current engine0 CHT.
738 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
739 return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
745 ////////////////////////////////////////////////////////////////////////
747 ////////////////////////////////////////////////////////////////////////
751 * Return the current airspeed in knots.
754 FGBFI::getAirspeed ()
756 // FIXME: should we add speed-up?
757 return current_aircraft.fdm_state->get_V_calibrated_kts();
762 * Return the current sideslip (FIXME: units unknown).
765 FGBFI::getSideSlip ()
767 return current_aircraft.fdm_state->get_Beta();
772 * Return the current climb rate in feet/minute
775 FGBFI::getVerticalSpeed ()
777 // What about meters?
778 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
783 * Get the current north velocity (units??).
786 FGBFI::getSpeedNorth ()
788 return current_aircraft.fdm_state->get_V_north();
793 * Set the current north velocity (units??).
796 FGBFI::setSpeedNorth (double speed)
798 if (getSpeedNorth() != speed) {
799 current_aircraft.fdm_state->set_Velocities_Local(speed,
808 * Get the current east velocity (units??).
811 FGBFI::getSpeedEast ()
813 return current_aircraft.fdm_state->get_V_east();
818 * Set the current east velocity (units??).
821 FGBFI::setSpeedEast (double speed)
823 if (getSpeedEast() != speed) {
824 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
833 * Get the current down velocity (units??).
836 FGBFI::getSpeedDown ()
838 return current_aircraft.fdm_state->get_V_down();
843 * Set the current down velocity (units??).
846 FGBFI::setSpeedDown (double speed)
848 if (getSpeedDown() != speed) {
849 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
858 ////////////////////////////////////////////////////////////////////////
860 ////////////////////////////////////////////////////////////////////////
864 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
867 FGBFI::getThrottle ()
869 // FIXME: add engine selector
870 return controls.get_throttle(0);
875 * Set the throttle, from 0.0 (none) to 1.0 (full).
878 FGBFI::setThrottle (double throttle)
880 // FIXME: allow engine selection
881 controls.set_throttle(0, throttle);
886 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
891 // FIXME: add engine selector
892 return controls.get_mixture(0);
897 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
900 FGBFI::setMixture (double mixture)
902 // FIXME: allow engine selection
903 controls.set_mixture(0, mixture);
908 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
911 FGBFI::getPropAdvance ()
913 // FIXME: add engine selector
914 return controls.get_prop_advance(0);
919 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
922 FGBFI::setPropAdvance (double pitch)
924 // FIXME: allow engine selection
925 controls.set_prop_advance(0, pitch);
930 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
935 return controls.get_flaps();
940 * Set the flaps, from 0.0 (none) to 1.0 (full).
943 FGBFI::setFlaps (double flaps)
946 controls.set_flaps(flaps);
951 * Get the aileron, from -1.0 (left) to 1.0 (right).
956 return controls.get_aileron();
961 * Set the aileron, from -1.0 (left) to 1.0 (right).
964 FGBFI::setAileron (double aileron)
967 controls.set_aileron(aileron);
972 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
977 return controls.get_rudder();
982 * Set the rudder, from -1.0 (left) to 1.0 (right).
985 FGBFI::setRudder (double rudder)
988 controls.set_rudder(rudder);
993 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
996 FGBFI::getElevator ()
998 return controls.get_elevator();
1003 * Set the elevator, from -1.0 (down) to 1.0 (up).
1006 FGBFI::setElevator (double elevator)
1009 controls.set_elevator(elevator);
1014 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
1017 FGBFI::getElevatorTrim ()
1019 return controls.get_elevator_trim();
1024 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
1027 FGBFI::setElevatorTrim (double trim)
1030 controls.set_elevator_trim(trim);
1035 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1040 double b1 = getCenterBrake();
1041 double b2 = getLeftBrake();
1042 double b3 = getRightBrake();
1043 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1048 * Set all brakes, from 0.0 (none) to 1.0 (full).
1051 FGBFI::setBrakes (double brake)
1053 setCenterBrake(brake);
1054 setLeftBrake(brake);
1055 setRightBrake(brake);
1060 * Get the center brake, from 0.0 (none) to 1.0 (full).
1063 FGBFI::getCenterBrake ()
1065 return controls.get_brake(2);
1070 * Set the center brake, from 0.0 (none) to 1.0 (full).
1073 FGBFI::setCenterBrake (double brake)
1075 controls.set_brake(2, brake);
1080 * Get the left brake, from 0.0 (none) to 1.0 (full).
1083 FGBFI::getLeftBrake ()
1085 return controls.get_brake(0);
1090 * Set the left brake, from 0.0 (none) to 1.0 (full).
1093 FGBFI::setLeftBrake (double brake)
1095 controls.set_brake(0, brake);
1100 * Get the right brake, from 0.0 (none) to 1.0 (full).
1103 FGBFI::getRightBrake ()
1105 return controls.get_brake(1);
1110 * Set the right brake, from 0.0 (none) to 1.0 (full).
1113 FGBFI::setRightBrake (double brake)
1115 controls.set_brake(1, brake);
1122 ////////////////////////////////////////////////////////////////////////
1124 ////////////////////////////////////////////////////////////////////////
1128 * Get the autopilot altitude lock (true=on).
1131 FGBFI::getAPAltitudeLock ()
1133 return current_autopilot->get_AltitudeEnabled();
1138 * Set the autopilot altitude lock (true=on).
1141 FGBFI::setAPAltitudeLock (bool lock)
1143 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1144 current_autopilot->set_AltitudeEnabled(lock);
1149 * Get the autopilot target altitude in feet.
1152 FGBFI::getAPAltitude ()
1154 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1159 * Set the autopilot target altitude in feet.
1162 FGBFI::setAPAltitude (double altitude)
1164 current_autopilot->set_TargetAltitude( altitude );
1169 * Get the autopilot heading lock (true=on).
1172 FGBFI::getAPHeadingLock ()
1175 (current_autopilot->get_HeadingEnabled() &&
1176 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1181 * Set the autopilot heading lock (true=on).
1184 FGBFI::setAPHeadingLock (bool lock)
1187 // We need to do this so that
1188 // it's possible to lock onto a
1189 // heading other than the current
1191 double heading = getAPHeadingMag();
1192 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1193 current_autopilot->set_HeadingEnabled(true);
1194 setAPHeadingMag(heading);
1195 } else if (current_autopilot->get_HeadingMode() ==
1196 FGAutopilot::FG_HEADING_LOCK) {
1197 current_autopilot->set_HeadingEnabled(false);
1203 * Get the autopilot target heading in degrees.
1206 FGBFI::getAPHeading ()
1208 return current_autopilot->get_TargetHeading();
1213 * Set the autopilot target heading in degrees.
1216 FGBFI::setAPHeading (double heading)
1218 current_autopilot->set_TargetHeading( heading );
1223 * Get the autopilot target heading in degrees.
1226 FGBFI::getAPHeadingMag ()
1228 return current_autopilot->get_TargetHeading() - getMagVar();
1233 * Set the autopilot target heading in degrees.
1236 FGBFI::setAPHeadingMag (double heading)
1238 current_autopilot->set_TargetHeading( heading + getMagVar() );
1243 * Return true if the autopilot is locked to NAV1.
1246 FGBFI::getAPNAV1Lock ()
1249 (current_autopilot->get_HeadingEnabled() &&
1250 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1255 * Set the autopilot NAV1 lock.
1258 FGBFI::setAPNAV1Lock (bool lock)
1261 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1262 current_autopilot->set_HeadingEnabled(true);
1263 } else if (current_autopilot->get_HeadingMode() ==
1264 FGAutopilot::FG_HEADING_NAV1) {
1265 current_autopilot->set_HeadingEnabled(false);
1271 ////////////////////////////////////////////////////////////////////////
1272 // Radio navigation.
1273 ////////////////////////////////////////////////////////////////////////
1276 FGBFI::getNAV1Freq ()
1278 return current_radiostack->get_nav1_freq();
1282 FGBFI::getNAV1AltFreq ()
1284 return current_radiostack->get_nav1_alt_freq();
1288 FGBFI::getNAV1Radial ()
1290 return current_radiostack->get_nav1_radial();
1294 FGBFI::getNAV1SelRadial ()
1296 return current_radiostack->get_nav1_sel_radial();
1300 FGBFI::getNAV1DistDME ()
1302 return current_radiostack->get_nav1_dme_dist();
1308 if (current_radiostack->get_nav1_inrange()) {
1309 double heading = current_radiostack->get_nav1_heading();
1310 double radial = current_radiostack->get_nav1_radial();
1311 double var = FGBFI::getMagVar();
1312 if (current_radiostack->get_nav1_loc()) {
1313 double offset = fabs(heading - radial);
1314 return (offset<= 8.0 || offset >= 352.0);
1317 fabs(heading - var - radial);
1318 return (offset <= 20.0 || offset >= 340.0);
1326 FGBFI::getNAV1FROM ()
1328 if (current_radiostack->get_nav1_inrange()) {
1329 double heading = current_radiostack->get_nav1_heading();
1330 double radial = current_radiostack->get_nav1_radial();
1331 double var = FGBFI::getMagVar();
1332 if (current_radiostack->get_nav1_loc()) {
1333 double offset = fabs(heading - radial);
1334 return (offset >= 172.0 && offset<= 188.0);
1337 fabs(heading - var - radial);
1338 return (offset >= 160.0 && offset <= 200.0);
1346 FGBFI::getNAV1InRange ()
1348 return current_radiostack->get_nav1_inrange();
1352 FGBFI::getNAV1DMEInRange ()
1354 return (current_radiostack->get_nav1_inrange() &&
1355 current_radiostack->get_nav1_has_dme());
1359 FGBFI::getNAV2Freq ()
1361 return current_radiostack->get_nav2_freq();
1365 FGBFI::getNAV2AltFreq ()
1367 return current_radiostack->get_nav2_alt_freq();
1371 FGBFI::getNAV2Radial ()
1373 return current_radiostack->get_nav2_radial();
1377 FGBFI::getNAV2SelRadial ()
1379 return current_radiostack->get_nav2_sel_radial();
1383 FGBFI::getNAV2DistDME ()
1385 return current_radiostack->get_nav2_dme_dist();
1391 if (current_radiostack->get_nav2_inrange()) {
1392 double heading = current_radiostack->get_nav2_heading();
1393 double radial = current_radiostack->get_nav2_radial();
1394 double var = FGBFI::getMagVar();
1395 if (current_radiostack->get_nav2_loc()) {
1396 double offset = fabs(heading - radial);
1397 return (offset<= 8.0 || offset >= 352.0);
1400 fabs(heading - var - radial);
1401 return (offset <= 20.0 || offset >= 340.0);
1409 FGBFI::getNAV2FROM ()
1411 if (current_radiostack->get_nav2_inrange()) {
1412 double heading = current_radiostack->get_nav2_heading();
1413 double radial = current_radiostack->get_nav2_radial();
1414 double var = FGBFI::getMagVar();
1415 if (current_radiostack->get_nav2_loc()) {
1416 double offset = fabs(heading - radial);
1417 return (offset >= 172.0 && offset<= 188.0);
1420 fabs(heading - var - radial);
1421 return (offset >= 160.0 && offset <= 200.0);
1430 FGBFI::getNAV2InRange ()
1432 return current_radiostack->get_nav2_inrange();
1436 FGBFI::getNAV2DMEInRange ()
1438 return (current_radiostack->get_nav2_inrange() &&
1439 current_radiostack->get_nav2_has_dme());
1443 FGBFI::getADFFreq ()
1445 return current_radiostack->get_adf_freq();
1449 FGBFI::getADFAltFreq ()
1451 return current_radiostack->get_adf_alt_freq();
1455 FGBFI::getADFRotation ()
1457 return current_radiostack->get_adf_rotation();
1461 FGBFI::setNAV1Freq (double freq)
1463 current_radiostack->set_nav1_freq(freq);
1467 FGBFI::setNAV1AltFreq (double freq)
1469 current_radiostack->set_nav1_alt_freq(freq);
1473 FGBFI::setNAV1SelRadial (double radial)
1475 current_radiostack->set_nav1_sel_radial(radial);
1479 FGBFI::setNAV2Freq (double freq)
1481 current_radiostack->set_nav2_freq(freq);
1485 FGBFI::setNAV2AltFreq (double freq)
1487 current_radiostack->set_nav2_alt_freq(freq);
1491 FGBFI::setNAV2SelRadial (double radial)
1493 current_radiostack->set_nav2_sel_radial(radial);
1497 FGBFI::setADFFreq (double freq)
1499 current_radiostack->set_adf_freq(freq);
1503 FGBFI::setADFAltFreq (double freq)
1505 current_radiostack->set_adf_alt_freq(freq);
1509 FGBFI::setADFRotation (double rot)
1511 current_radiostack->set_adf_rotation(rot);
1516 ////////////////////////////////////////////////////////////////////////
1518 ////////////////////////////////////////////////////////////////////////
1522 * Get the autopilot GPS lock (true=on).
1525 FGBFI::getGPSLock ()
1527 return (current_autopilot->get_HeadingEnabled() &&
1528 (current_autopilot->get_HeadingMode() ==
1529 FGAutopilot::FG_HEADING_WAYPOINT ));
1534 * Set the autopilot GPS lock (true=on).
1537 FGBFI::setGPSLock (bool lock)
1540 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1541 current_autopilot->set_HeadingEnabled(true);
1542 } else if (current_autopilot->get_HeadingMode() ==
1543 FGAutopilot::FG_HEADING_WAYPOINT) {
1544 current_autopilot->set_HeadingEnabled(false);
1550 * Get the GPS target airport code.
1553 FGBFI::getTargetAirport ()
1555 // FIXME: not thread-safe
1557 out = globals->get_options()->get_airport_id();
1564 * Set the GPS target airport code.
1567 FGBFI::setTargetAirport (const string &airportId)
1569 // cout << "setting target airport id = " << airportId << endl;
1570 globals->get_options()->set_airport_id(airportId);
1575 * Get the GPS target latitude in degrees (negative for south).
1578 FGBFI::getGPSTargetLatitude ()
1580 return current_autopilot->get_TargetLatitude();
1585 * Get the GPS target longitude in degrees (negative for west).
1588 FGBFI::getGPSTargetLongitude ()
1590 return current_autopilot->get_TargetLongitude();
1595 * Set the GPS target longitude in degrees (negative for west).
1598 FGBFI::setGPSTargetLongitude (double longitude)
1600 current_autopilot->set_TargetLongitude( longitude );
1606 ////////////////////////////////////////////////////////////////////////
1608 ////////////////////////////////////////////////////////////////////////
1612 * Get the current visible (units??).
1615 FGBFI::getVisibility ()
1617 #ifndef FG_OLD_WEATHER
1618 return WeatherDatabase->getWeatherVisibility();
1620 return current_weather.get_visibility();
1626 * Check whether clouds are enabled.
1631 return globals->get_options()->get_clouds();
1636 * Check the height of the clouds ASL (units?).
1639 FGBFI::getCloudsASL ()
1641 return globals->get_options()->get_clouds_asl();
1646 * Set the current visibility (units??).
1649 FGBFI::setVisibility (double visibility)
1651 #ifndef FG_OLD_WEATHER
1652 WeatherDatabase->setWeatherVisibility(visibility);
1654 current_weather.set_visibility(visibility);
1660 * Switch clouds on or off.
1663 FGBFI::setClouds (bool clouds)
1665 if (getClouds() != clouds) {
1666 cout << "Set clouds to " << clouds << endl;
1667 globals->get_options()->set_clouds(clouds);
1674 * Set the cloud height.
1677 FGBFI::setCloudsASL (double cloudsASL)
1679 if (getCloudsASL() != cloudsASL) {
1680 globals->get_options()->set_clouds_asl(cloudsASL);
1687 ////////////////////////////////////////////////////////////////////////
1689 ////////////////////////////////////////////////////////////////////////
1692 * Return the magnetic variation
1697 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1702 * Return the magnetic variation
1707 return globals->get_mag()->get_magdip() * RAD_TO_DEG;