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",
131 current_properties.tieDouble("/velocities/airspeed",
133 current_properties.tieDouble("/velocities/side-slip",
135 current_properties.tieDouble("/velocities/vertical-speed",
136 getVerticalSpeed, 0);
137 current_properties.tieDouble("/velocities/speed-north",
138 getSpeedNorth, setSpeedNorth);
139 current_properties.tieDouble("/velocities/speed-east",
140 getSpeedEast, setSpeedEast);
141 current_properties.tieDouble("/velocities/speed-down",
142 getSpeedDown, setSpeedDown);
145 current_properties.tieDouble("/controls/throttle",
146 getThrottle, setThrottle);
147 current_properties.tieDouble("/controls/flaps",
149 current_properties.tieDouble("/controls/aileron",
150 getAileron, setAileron);
151 current_properties.tieDouble("/controls/rudder",
152 getRudder, setRudder);
153 current_properties.tieDouble("/controls/elevator",
154 getElevator, setElevator);
155 current_properties.tieDouble("/controls/elevator-trim",
156 getElevatorTrim, setElevatorTrim);
157 current_properties.tieDouble("/controls/brakes/all",
158 getBrakes, setBrakes);
159 current_properties.tieDouble("/controls/brakes/left",
160 getLeftBrake, setLeftBrake);
161 current_properties.tieDouble("/controls/brakes/right",
162 getRightBrake, setRightBrake);
163 current_properties.tieDouble("/controls/brakes/center",
164 getRightBrake, setCenterBrake);
167 current_properties.tieBool("/autopilot/locks/altitude",
168 getAPAltitudeLock, setAPAltitudeLock);
169 current_properties.tieDouble("/autopilot/settings/altitude",
170 getAPAltitude, setAPAltitude);
171 current_properties.tieBool("/autopilot/locks/heading",
172 getAPHeadingLock, setAPHeadingLock);
173 current_properties.tieDouble("/autopilot/settings/heading",
174 getAPHeading, setAPHeading);
175 current_properties.tieDouble("/autopilot/settings/heading-magnetic",
176 getAPHeadingMag, setAPHeadingMag);
177 current_properties.tieBool("/autopilot/locks/nav1",
178 getAPNAV1Lock, setAPNAV1Lock);
181 current_properties.tieDouble("/radios/nav1/frequencies/selected",
182 getNAV1Freq, setNAV1Freq);
183 current_properties.tieDouble("/radios/nav1/frequencies/standby",
184 getNAV1AltFreq, setNAV1AltFreq);
185 current_properties.tieDouble("/radios/nav1/radials/actual",
187 current_properties.tieDouble("/radios/nav1/radials/selected",
188 getNAV1SelRadial, setNAV1SelRadial);
189 current_properties.tieDouble("/radios/nav1/dme/distance",
191 current_properties.tieBool("/radios/nav1/to-flag",
193 current_properties.tieBool("/radios/nav1/from-flag",
195 current_properties.tieBool("/radios/nav1/in-range",
197 current_properties.tieBool("/radios/nav1/dme/in-range",
198 getNAV1DMEInRange, 0);
200 current_properties.tieDouble("/radios/nav2/frequencies/selected",
201 getNAV2Freq, setNAV2Freq);
202 current_properties.tieDouble("/radios/nav2/frequencies/standby",
203 getNAV2AltFreq, setNAV2AltFreq);
204 current_properties.tieDouble("/radios/nav2/radials/actual",
206 current_properties.tieDouble("/radios/nav2/radials/selected",
207 getNAV2SelRadial, setNAV2SelRadial);
208 current_properties.tieDouble("/radios/nav2/dme/distance",
210 current_properties.tieBool("/radios/nav2/to-flag",
212 current_properties.tieBool("/radios/nav2/from-flag",
214 current_properties.tieBool("/radios/nav2/in-range",
216 current_properties.tieBool("/radios/nav2/dme/in-range",
217 getNAV2DMEInRange, 0);
219 current_properties.tieDouble("/radios/adf/frequencies/selected",
220 getADFFreq, setADFFreq);
221 current_properties.tieDouble("/radios/adf/frequencies/standby",
222 getADFAltFreq, setADFAltFreq);
223 current_properties.tieDouble("/radios/adf/rotation",
224 getADFRotation, setADFRotation);
226 current_properties.tieDouble("/environment/visibility",
227 getVisibility, setVisibility);
229 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
234 * Reinitialize FGFS if required.
236 * Some changes (especially those in aircraft position) require that
237 * FGFS be reinitialized afterwards. Rather than reinitialize after
238 * every change, the setter methods simply set a flag so that there
239 * can be a single reinit at the end of the frame.
251 * Reinitialize FGFS to use the new BFI settings.
256 // Save the state of everything
257 // that's going to get clobbered
258 // when we reinit the subsystems.
260 cout << "BFI: start reinit\n";
262 // setHeading(getHeading());
263 // setPitch(getPitch());
264 // setRoll(getRoll());
265 // setSpeedNorth(getSpeedNorth());
266 // setSpeedEast(getSpeedEast());
267 // setSpeedDown(getSpeedDown());
268 // setLatitude(getLatitude());
269 // setLongitude(getLongitude());
270 // setAltitude(getAltitude());
272 // TODO: add more AP stuff
273 double elevator = getElevator();
274 double aileron = getAileron();
275 double rudder = getRudder();
276 double throttle = getThrottle();
277 double elevator_trim = getElevatorTrim();
278 double flaps = getFlaps();
279 double brake = getBrakes();
280 bool apHeadingLock = getAPHeadingLock();
281 double apHeadingMag = getAPHeadingMag();
282 bool apAltitudeLock = getAPAltitudeLock();
283 double apAltitude = getAPAltitude();
284 const string &targetAirport = getTargetAirport();
285 bool gpsLock = getGPSLock();
286 double gpsLatitude = getGPSTargetLatitude();
287 double gpsLongitude = getGPSTargetLongitude();
289 setTargetAirport("");
290 cout << "Target airport is " << current_options.get_airport_id() << endl;
292 fgReInitSubsystems();
294 // FIXME: this is wrong.
295 // All of these are scheduled events,
296 // and it should be possible to force
297 // them all to run once.
300 cur_light_params.Update();
302 fgUpdateWeatherDatabase();
305 // Restore all of the old states.
306 setElevator(elevator);
309 setThrottle(throttle);
310 setElevatorTrim(elevator_trim);
313 setAPHeadingLock(apHeadingLock);
314 setAPHeadingMag(apHeadingMag);
315 setAPAltitudeLock(apAltitudeLock);
316 setAPAltitude(apAltitude);
317 setTargetAirport(targetAirport);
319 setGPSTargetLatitude(gpsLatitude);
320 setGPSTargetLongitude(gpsLongitude);
324 cout << "BFI: end reinit\n";
329 ////////////////////////////////////////////////////////////////////////
331 ////////////////////////////////////////////////////////////////////////
335 * Return the flight model as an integer.
337 * TODO: use a string instead.
340 FGBFI::getFlightModel ()
342 return current_options.get_flight_model();
347 * Return the current aircraft as a string.
350 FGBFI::getAircraft ()
352 return current_options.get_aircraft();
357 * Return the current aircraft directory (UIUC) as a string.
360 FGBFI::getAircraftDir ()
367 * Set the flight model as an integer.
369 * TODO: use a string instead.
372 FGBFI::setFlightModel (int model)
374 current_options.set_flight_model(model);
380 * Set the current aircraft.
383 FGBFI::setAircraft (const string &aircraft)
385 current_options.set_aircraft(aircraft);
391 * Set the current aircraft directory (UIUC).
394 FGBFI::setAircraftDir (const string &dir)
402 * Return the current Zulu time.
407 return globals->get_time_params()->get_cur_time();
412 * Set the current Zulu time.
415 FGBFI::setTimeGMT (time_t time)
417 // FIXME: need to update lighting
419 current_options.set_time_offset(time);
420 current_options.set_time_offset_type(fgOPTIONS::FG_TIME_GMT_ABSOLUTE);
421 globals->get_time_params()->update( cur_fdm_state->get_Longitude(),
422 cur_fdm_state->get_Latitude(),
423 globals->get_warp() );
429 * Return the GMT as a string.
432 FGBFI::getGMTString ()
434 static string out; // FIXME: not thread-safe
436 struct tm * t = globals->get_time_params()->getGmt();
437 sprintf(buf, " %.2d:%.2d:%.2d",
438 t->tm_hour, t->tm_min, t->tm_sec);
445 * Return true if the HUD is visible.
448 FGBFI::getHUDVisible ()
450 return current_options.get_hud_status();
455 * Ensure that the HUD is visible or hidden.
458 FGBFI::setHUDVisible (bool visible)
460 current_options.set_hud_status(visible);
465 * Return true if the 2D panel is visible.
468 FGBFI::getPanelVisible ()
470 return current_options.get_panel_status();
475 * Ensure that the 2D panel is visible or hidden.
478 FGBFI::setPanelVisible (bool visible)
480 if (current_options.get_panel_status() != visible) {
481 current_options.toggle_panel();
487 ////////////////////////////////////////////////////////////////////////
489 ////////////////////////////////////////////////////////////////////////
493 * Return the current latitude in degrees (negative for south).
496 FGBFI::getLatitude ()
498 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
503 * Set the current latitude in degrees (negative for south).
506 FGBFI::setLatitude (double latitude)
508 current_options.set_lat(latitude);
509 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
515 * Return the current longitude in degrees (negative for west).
518 FGBFI::getLongitude ()
520 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
525 * Set the current longitude in degrees (negative for west).
528 FGBFI::setLongitude (double longitude)
530 current_options.set_lon(longitude);
531 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
537 * Return the current altitude in feet.
540 FGBFI::getAltitude ()
542 return current_aircraft.fdm_state->get_Altitude();
548 * Return the current altitude in above the terrain.
553 return current_aircraft.fdm_state->get_Altitude()
554 - (scenery.cur_elev * METER_TO_FEET);
559 * Set the current altitude in feet.
562 FGBFI::setAltitude (double altitude)
564 fgFDMForceAltitude(getFlightModel(), altitude * FEET_TO_METER);
565 current_options.set_altitude(altitude * FEET_TO_METER);
566 current_aircraft.fdm_state->set_Altitude(altitude);
572 ////////////////////////////////////////////////////////////////////////
574 ////////////////////////////////////////////////////////////////////////
578 * Return the current heading in degrees.
583 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
588 * Return the current heading in degrees.
591 FGBFI::getHeadingMag ()
593 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
598 * Set the current heading in degrees.
601 FGBFI::setHeading (double heading)
603 current_options.set_heading(heading);
604 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
605 getPitch() * DEG_TO_RAD,
606 heading * DEG_TO_RAD);
612 * Return the current pitch in degrees.
617 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
622 * Set the current pitch in degrees.
625 FGBFI::setPitch (double pitch)
628 current_options.set_pitch(pitch);
629 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
631 getHeading() * DEG_TO_RAD);
637 * Return the current roll in degrees.
642 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
647 * Set the current roll in degrees.
650 FGBFI::setRoll (double roll)
652 current_options.set_roll(roll);
653 current_aircraft.fdm_state->set_Euler_Angles(roll * DEG_TO_RAD,
654 getPitch() * DEG_TO_RAD,
655 getHeading() * DEG_TO_RAD);
661 * Return the current engine0 rpm
666 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
671 * Set the current engine0 rpm
674 FGBFI::setRPM (double rpm)
676 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
681 ////////////////////////////////////////////////////////////////////////
683 ////////////////////////////////////////////////////////////////////////
687 * Return the current airspeed in knots.
690 FGBFI::getAirspeed ()
692 // FIXME: should we add speed-up?
693 return current_aircraft.fdm_state->get_V_calibrated_kts();
698 * Return the current sideslip (FIXME: units unknown).
701 FGBFI::getSideSlip ()
703 return current_aircraft.fdm_state->get_Beta();
708 * Return the current climb rate in feet/minute
711 FGBFI::getVerticalSpeed ()
713 // What about meters?
714 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
719 * Get the current north velocity (units??).
722 FGBFI::getSpeedNorth ()
724 return current_aircraft.fdm_state->get_V_north();
729 * Set the current north velocity (units??).
732 FGBFI::setSpeedNorth (double speed)
734 current_options.set_uBody(speed);
735 current_aircraft.fdm_state->set_Velocities_Local(speed,
743 * Get the current east velocity (units??).
746 FGBFI::getSpeedEast ()
748 return current_aircraft.fdm_state->get_V_east();
753 * Set the current east velocity (units??).
756 FGBFI::setSpeedEast (double speed)
758 current_options.set_vBody(speed);
759 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
767 * Get the current down velocity (units??).
770 FGBFI::getSpeedDown ()
772 return current_aircraft.fdm_state->get_V_down();
777 * Set the current down velocity (units??).
780 FGBFI::setSpeedDown (double speed)
782 current_options.set_wBody(speed);
783 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
791 ////////////////////////////////////////////////////////////////////////
793 ////////////////////////////////////////////////////////////////////////
797 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
800 FGBFI::getThrottle ()
802 // FIXME: add throttle selector
803 return controls.get_throttle(0);
808 * Set the throttle, from 0.0 (none) to 1.0 (full).
811 FGBFI::setThrottle (double throttle)
813 // FIXME: allow throttle selection
815 controls.set_throttle(0, throttle);
820 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
825 return controls.get_flaps();
830 * Set the flaps, from 0.0 (none) to 1.0 (full).
833 FGBFI::setFlaps (double flaps)
836 controls.set_flaps(flaps);
841 * Get the aileron, from -1.0 (left) to 1.0 (right).
846 return controls.get_aileron();
851 * Set the aileron, from -1.0 (left) to 1.0 (right).
854 FGBFI::setAileron (double aileron)
857 controls.set_aileron(aileron);
862 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
867 return controls.get_rudder();
872 * Set the rudder, from -1.0 (left) to 1.0 (right).
875 FGBFI::setRudder (double rudder)
878 controls.set_rudder(rudder);
883 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
886 FGBFI::getElevator ()
888 return controls.get_elevator();
893 * Set the elevator, from -1.0 (down) to 1.0 (up).
896 FGBFI::setElevator (double elevator)
899 controls.set_elevator(elevator);
904 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
907 FGBFI::getElevatorTrim ()
909 return controls.get_elevator_trim();
914 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
917 FGBFI::setElevatorTrim (double trim)
920 controls.set_elevator_trim(trim);
925 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
930 double b1 = getCenterBrake();
931 double b2 = getLeftBrake();
932 double b3 = getRightBrake();
933 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
938 * Set all brakes, from 0.0 (none) to 1.0 (full).
941 FGBFI::setBrakes (double brake)
943 setCenterBrake(brake);
945 setRightBrake(brake);
950 * Get the center brake, from 0.0 (none) to 1.0 (full).
953 FGBFI::getCenterBrake ()
955 return controls.get_brake(2);
960 * Set the center brake, from 0.0 (none) to 1.0 (full).
963 FGBFI::setCenterBrake (double brake)
965 controls.set_brake(2, brake);
970 * Get the left brake, from 0.0 (none) to 1.0 (full).
973 FGBFI::getLeftBrake ()
975 return controls.get_brake(0);
980 * Set the left brake, from 0.0 (none) to 1.0 (full).
983 FGBFI::setLeftBrake (double brake)
985 controls.set_brake(0, brake);
990 * Get the right brake, from 0.0 (none) to 1.0 (full).
993 FGBFI::getRightBrake ()
995 return controls.get_brake(1);
1000 * Set the right brake, from 0.0 (none) to 1.0 (full).
1003 FGBFI::setRightBrake (double brake)
1005 controls.set_brake(1, brake);
1012 ////////////////////////////////////////////////////////////////////////
1014 ////////////////////////////////////////////////////////////////////////
1018 * Get the autopilot altitude lock (true=on).
1021 FGBFI::getAPAltitudeLock ()
1023 return current_autopilot->get_AltitudeEnabled();
1028 * Set the autopilot altitude lock (true=on).
1031 FGBFI::setAPAltitudeLock (bool lock)
1033 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1034 current_autopilot->set_AltitudeEnabled(lock);
1039 * Get the autopilot target altitude in feet.
1042 FGBFI::getAPAltitude ()
1044 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1049 * Set the autopilot target altitude in feet.
1052 FGBFI::setAPAltitude (double altitude)
1054 current_autopilot->set_TargetAltitude( altitude );
1059 * Get the autopilot heading lock (true=on).
1062 FGBFI::getAPHeadingLock ()
1065 (current_autopilot->get_HeadingEnabled() &&
1066 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1071 * Set the autopilot heading lock (true=on).
1074 FGBFI::setAPHeadingLock (bool lock)
1077 // We need to do this so that
1078 // it's possible to lock onto a
1079 // heading other than the current
1081 double heading = getAPHeadingMag();
1082 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1083 current_autopilot->set_HeadingEnabled(true);
1084 setAPHeadingMag(heading);
1085 } else if (current_autopilot->get_HeadingMode() ==
1086 FGAutopilot::FG_HEADING_LOCK) {
1087 current_autopilot->set_HeadingEnabled(false);
1093 * Get the autopilot target heading in degrees.
1096 FGBFI::getAPHeading ()
1098 return current_autopilot->get_TargetHeading();
1103 * Set the autopilot target heading in degrees.
1106 FGBFI::setAPHeading (double heading)
1108 current_autopilot->set_TargetHeading( heading );
1113 * Get the autopilot target heading in degrees.
1116 FGBFI::getAPHeadingMag ()
1118 return current_autopilot->get_TargetHeading() - getMagVar();
1123 * Set the autopilot target heading in degrees.
1126 FGBFI::setAPHeadingMag (double heading)
1128 current_autopilot->set_TargetHeading( heading + getMagVar() );
1133 * Return true if the autopilot is locked to NAV1.
1136 FGBFI::getAPNAV1Lock ()
1139 (current_autopilot->get_HeadingEnabled() &&
1140 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1145 * Set the autopilot NAV1 lock.
1148 FGBFI::setAPNAV1Lock (bool lock)
1151 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1152 current_autopilot->set_HeadingEnabled(true);
1153 } else if (current_autopilot->get_HeadingMode() ==
1154 FGAutopilot::FG_HEADING_NAV1) {
1155 current_autopilot->set_HeadingEnabled(false);
1161 ////////////////////////////////////////////////////////////////////////
1162 // Radio navigation.
1163 ////////////////////////////////////////////////////////////////////////
1166 FGBFI::getNAV1Freq ()
1168 return current_radiostack->get_nav1_freq();
1172 FGBFI::getNAV1AltFreq ()
1174 return current_radiostack->get_nav1_alt_freq();
1178 FGBFI::getNAV1Radial ()
1180 return current_radiostack->get_nav1_radial();
1184 FGBFI::getNAV1SelRadial ()
1186 return current_radiostack->get_nav1_sel_radial();
1190 FGBFI::getNAV1DistDME ()
1192 return current_radiostack->get_nav1_dme_dist();
1198 if (current_radiostack->get_nav1_inrange()) {
1199 double heading = current_radiostack->get_nav1_heading();
1200 double radial = current_radiostack->get_nav1_radial();
1201 double var = FGBFI::getMagVar();
1202 if (current_radiostack->get_nav1_loc()) {
1203 double offset = fabs(heading - radial);
1204 return (offset<= 8.0 || offset >= 352.0);
1207 fabs(heading - var - radial);
1208 return (offset <= 20.0 || offset >= 340.0);
1216 FGBFI::getNAV1FROM ()
1218 if (current_radiostack->get_nav1_inrange()) {
1219 double heading = current_radiostack->get_nav1_heading();
1220 double radial = current_radiostack->get_nav1_radial();
1221 double var = FGBFI::getMagVar();
1222 if (current_radiostack->get_nav1_loc()) {
1223 double offset = fabs(heading - radial);
1224 return (offset >= 172.0 && offset<= 188.0);
1227 fabs(heading - var - radial);
1228 return (offset >= 160.0 && offset <= 200.0);
1236 FGBFI::getNAV1InRange ()
1238 return current_radiostack->get_nav1_inrange();
1242 FGBFI::getNAV1DMEInRange ()
1244 return (current_radiostack->get_nav1_inrange() &&
1245 current_radiostack->get_nav1_has_dme());
1249 FGBFI::getNAV2Freq ()
1251 return current_radiostack->get_nav2_freq();
1255 FGBFI::getNAV2AltFreq ()
1257 return current_radiostack->get_nav2_alt_freq();
1261 FGBFI::getNAV2Radial ()
1263 return current_radiostack->get_nav2_radial();
1267 FGBFI::getNAV2SelRadial ()
1269 return current_radiostack->get_nav2_sel_radial();
1273 FGBFI::getNAV2DistDME ()
1275 return current_radiostack->get_nav2_dme_dist();
1281 if (current_radiostack->get_nav2_inrange()) {
1282 double heading = current_radiostack->get_nav2_heading();
1283 double radial = current_radiostack->get_nav2_radial();
1284 double var = FGBFI::getMagVar();
1285 if (current_radiostack->get_nav2_loc()) {
1286 double offset = fabs(heading - radial);
1287 return (offset<= 8.0 || offset >= 352.0);
1290 fabs(heading - var - radial);
1291 return (offset <= 20.0 || offset >= 340.0);
1299 FGBFI::getNAV2FROM ()
1301 if (current_radiostack->get_nav2_inrange()) {
1302 double heading = current_radiostack->get_nav2_heading();
1303 double radial = current_radiostack->get_nav2_radial();
1304 double var = FGBFI::getMagVar();
1305 if (current_radiostack->get_nav2_loc()) {
1306 double offset = fabs(heading - radial);
1307 return (offset >= 172.0 && offset<= 188.0);
1310 fabs(heading - var - radial);
1311 return (offset >= 160.0 && offset <= 200.0);
1320 FGBFI::getNAV2InRange ()
1322 return current_radiostack->get_nav2_inrange();
1326 FGBFI::getNAV2DMEInRange ()
1328 return (current_radiostack->get_nav2_inrange() &&
1329 current_radiostack->get_nav2_has_dme());
1333 FGBFI::getADFFreq ()
1335 return current_radiostack->get_adf_freq();
1339 FGBFI::getADFAltFreq ()
1341 return current_radiostack->get_adf_alt_freq();
1345 FGBFI::getADFRotation ()
1347 return current_radiostack->get_adf_rotation();
1351 FGBFI::setNAV1Freq (double freq)
1353 current_radiostack->set_nav1_freq(freq);
1357 FGBFI::setNAV1AltFreq (double freq)
1359 current_radiostack->set_nav1_alt_freq(freq);
1363 FGBFI::setNAV1SelRadial (double radial)
1365 current_radiostack->set_nav1_sel_radial(radial);
1369 FGBFI::setNAV2Freq (double freq)
1371 current_radiostack->set_nav2_freq(freq);
1375 FGBFI::setNAV2AltFreq (double freq)
1377 current_radiostack->set_nav2_alt_freq(freq);
1381 FGBFI::setNAV2SelRadial (double radial)
1383 current_radiostack->set_nav2_sel_radial(radial);
1387 FGBFI::setADFFreq (double freq)
1389 current_radiostack->set_adf_freq(freq);
1393 FGBFI::setADFAltFreq (double freq)
1395 current_radiostack->set_adf_alt_freq(freq);
1399 FGBFI::setADFRotation (double rot)
1401 current_radiostack->set_adf_rotation(rot);
1406 ////////////////////////////////////////////////////////////////////////
1408 ////////////////////////////////////////////////////////////////////////
1412 * Get the autopilot GPS lock (true=on).
1415 FGBFI::getGPSLock ()
1417 return (current_autopilot->get_HeadingEnabled() &&
1418 (current_autopilot->get_HeadingMode() ==
1419 FGAutopilot::FG_HEADING_WAYPOINT ));
1424 * Set the autopilot GPS lock (true=on).
1427 FGBFI::setGPSLock (bool lock)
1430 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1431 current_autopilot->set_HeadingEnabled(true);
1432 } else if (current_autopilot->get_HeadingMode() ==
1433 FGAutopilot::FG_HEADING_WAYPOINT) {
1434 current_autopilot->set_HeadingEnabled(false);
1440 * Get the GPS target airport code.
1443 FGBFI::getTargetAirport ()
1445 return current_options.get_airport_id();
1450 * Set the GPS target airport code.
1453 FGBFI::setTargetAirport (const string &airportId)
1455 current_options.set_airport_id(airportId);
1460 * Get the GPS target latitude in degrees (negative for south).
1463 FGBFI::getGPSTargetLatitude ()
1465 return current_autopilot->get_TargetLatitude();
1470 * Set the GPS target latitude in degrees (negative for south).
1473 FGBFI::setGPSTargetLatitude (double latitude)
1475 current_autopilot->set_TargetLatitude( latitude );
1480 * Get the GPS target longitude in degrees (negative for west).
1483 FGBFI::getGPSTargetLongitude ()
1485 return current_autopilot->get_TargetLongitude();
1490 * Set the GPS target longitude in degrees (negative for west).
1493 FGBFI::setGPSTargetLongitude (double longitude)
1495 current_autopilot->set_TargetLongitude( longitude );
1500 ////////////////////////////////////////////////////////////////////////
1502 ////////////////////////////////////////////////////////////////////////
1506 * Get the current visible (units??).
1509 FGBFI::getVisibility ()
1511 #ifndef FG_OLD_WEATHER
1512 return WeatherDatabase->getWeatherVisibility();
1514 return current_weather.get_visibility();
1520 * Check whether clouds are enabled.
1525 return current_options.get_clouds();
1530 * Check the height of the clouds ASL (units?).
1533 FGBFI::getCloudsASL ()
1535 return current_options.get_clouds_asl();
1540 * Set the current visibility (units??).
1543 FGBFI::setVisibility (double visibility)
1545 #ifndef FG_OLD_WEATHER
1546 WeatherDatabase->setWeatherVisibility(visibility);
1548 current_weather.set_visibility(visibility);
1554 * Switch clouds on or off.
1557 FGBFI::setClouds (bool clouds)
1559 cout << "Set clouds to " << clouds << endl;
1560 current_options.set_clouds(clouds);
1566 * Set the cloud height.
1569 FGBFI::setCloudsASL (double cloudsASL)
1571 current_options.set_clouds_asl(cloudsASL);
1577 ////////////////////////////////////////////////////////////////////////
1579 ////////////////////////////////////////////////////////////////////////
1582 * Return the magnetic variation
1587 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1592 * Return the magnetic variation
1597 return globals->get_mag()->get_magdip() * RAD_TO_DEG;