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 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
667 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
675 * Set the current engine0 rpm
678 FGBFI::setRPM (double rpm)
680 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
681 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
687 ////////////////////////////////////////////////////////////////////////
689 ////////////////////////////////////////////////////////////////////////
693 * Return the current airspeed in knots.
696 FGBFI::getAirspeed ()
698 // FIXME: should we add speed-up?
699 return current_aircraft.fdm_state->get_V_calibrated_kts();
704 * Return the current sideslip (FIXME: units unknown).
707 FGBFI::getSideSlip ()
709 return current_aircraft.fdm_state->get_Beta();
714 * Return the current climb rate in feet/minute
717 FGBFI::getVerticalSpeed ()
719 // What about meters?
720 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
725 * Get the current north velocity (units??).
728 FGBFI::getSpeedNorth ()
730 return current_aircraft.fdm_state->get_V_north();
735 * Set the current north velocity (units??).
738 FGBFI::setSpeedNorth (double speed)
740 current_options.set_uBody(speed);
741 current_aircraft.fdm_state->set_Velocities_Local(speed,
749 * Get the current east velocity (units??).
752 FGBFI::getSpeedEast ()
754 return current_aircraft.fdm_state->get_V_east();
759 * Set the current east velocity (units??).
762 FGBFI::setSpeedEast (double speed)
764 current_options.set_vBody(speed);
765 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
773 * Get the current down velocity (units??).
776 FGBFI::getSpeedDown ()
778 return current_aircraft.fdm_state->get_V_down();
783 * Set the current down velocity (units??).
786 FGBFI::setSpeedDown (double speed)
788 current_options.set_wBody(speed);
789 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
797 ////////////////////////////////////////////////////////////////////////
799 ////////////////////////////////////////////////////////////////////////
803 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
806 FGBFI::getThrottle ()
808 // FIXME: add throttle selector
809 return controls.get_throttle(0);
814 * Set the throttle, from 0.0 (none) to 1.0 (full).
817 FGBFI::setThrottle (double throttle)
819 // FIXME: allow throttle selection
821 controls.set_throttle(0, throttle);
826 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
831 return controls.get_flaps();
836 * Set the flaps, from 0.0 (none) to 1.0 (full).
839 FGBFI::setFlaps (double flaps)
842 controls.set_flaps(flaps);
847 * Get the aileron, from -1.0 (left) to 1.0 (right).
852 return controls.get_aileron();
857 * Set the aileron, from -1.0 (left) to 1.0 (right).
860 FGBFI::setAileron (double aileron)
863 controls.set_aileron(aileron);
868 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
873 return controls.get_rudder();
878 * Set the rudder, from -1.0 (left) to 1.0 (right).
881 FGBFI::setRudder (double rudder)
884 controls.set_rudder(rudder);
889 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
892 FGBFI::getElevator ()
894 return controls.get_elevator();
899 * Set the elevator, from -1.0 (down) to 1.0 (up).
902 FGBFI::setElevator (double elevator)
905 controls.set_elevator(elevator);
910 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
913 FGBFI::getElevatorTrim ()
915 return controls.get_elevator_trim();
920 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
923 FGBFI::setElevatorTrim (double trim)
926 controls.set_elevator_trim(trim);
931 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
936 double b1 = getCenterBrake();
937 double b2 = getLeftBrake();
938 double b3 = getRightBrake();
939 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
944 * Set all brakes, from 0.0 (none) to 1.0 (full).
947 FGBFI::setBrakes (double brake)
949 setCenterBrake(brake);
951 setRightBrake(brake);
956 * Get the center brake, from 0.0 (none) to 1.0 (full).
959 FGBFI::getCenterBrake ()
961 return controls.get_brake(2);
966 * Set the center brake, from 0.0 (none) to 1.0 (full).
969 FGBFI::setCenterBrake (double brake)
971 controls.set_brake(2, brake);
976 * Get the left brake, from 0.0 (none) to 1.0 (full).
979 FGBFI::getLeftBrake ()
981 return controls.get_brake(0);
986 * Set the left brake, from 0.0 (none) to 1.0 (full).
989 FGBFI::setLeftBrake (double brake)
991 controls.set_brake(0, brake);
996 * Get the right brake, from 0.0 (none) to 1.0 (full).
999 FGBFI::getRightBrake ()
1001 return controls.get_brake(1);
1006 * Set the right brake, from 0.0 (none) to 1.0 (full).
1009 FGBFI::setRightBrake (double brake)
1011 controls.set_brake(1, brake);
1018 ////////////////////////////////////////////////////////////////////////
1020 ////////////////////////////////////////////////////////////////////////
1024 * Get the autopilot altitude lock (true=on).
1027 FGBFI::getAPAltitudeLock ()
1029 return current_autopilot->get_AltitudeEnabled();
1034 * Set the autopilot altitude lock (true=on).
1037 FGBFI::setAPAltitudeLock (bool lock)
1039 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1040 current_autopilot->set_AltitudeEnabled(lock);
1045 * Get the autopilot target altitude in feet.
1048 FGBFI::getAPAltitude ()
1050 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1055 * Set the autopilot target altitude in feet.
1058 FGBFI::setAPAltitude (double altitude)
1060 current_autopilot->set_TargetAltitude( altitude );
1065 * Get the autopilot heading lock (true=on).
1068 FGBFI::getAPHeadingLock ()
1071 (current_autopilot->get_HeadingEnabled() &&
1072 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1077 * Set the autopilot heading lock (true=on).
1080 FGBFI::setAPHeadingLock (bool lock)
1083 // We need to do this so that
1084 // it's possible to lock onto a
1085 // heading other than the current
1087 double heading = getAPHeadingMag();
1088 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1089 current_autopilot->set_HeadingEnabled(true);
1090 setAPHeadingMag(heading);
1091 } else if (current_autopilot->get_HeadingMode() ==
1092 FGAutopilot::FG_HEADING_LOCK) {
1093 current_autopilot->set_HeadingEnabled(false);
1099 * Get the autopilot target heading in degrees.
1102 FGBFI::getAPHeading ()
1104 return current_autopilot->get_TargetHeading();
1109 * Set the autopilot target heading in degrees.
1112 FGBFI::setAPHeading (double heading)
1114 current_autopilot->set_TargetHeading( heading );
1119 * Get the autopilot target heading in degrees.
1122 FGBFI::getAPHeadingMag ()
1124 return current_autopilot->get_TargetHeading() - getMagVar();
1129 * Set the autopilot target heading in degrees.
1132 FGBFI::setAPHeadingMag (double heading)
1134 current_autopilot->set_TargetHeading( heading + getMagVar() );
1139 * Return true if the autopilot is locked to NAV1.
1142 FGBFI::getAPNAV1Lock ()
1145 (current_autopilot->get_HeadingEnabled() &&
1146 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1151 * Set the autopilot NAV1 lock.
1154 FGBFI::setAPNAV1Lock (bool lock)
1157 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1158 current_autopilot->set_HeadingEnabled(true);
1159 } else if (current_autopilot->get_HeadingMode() ==
1160 FGAutopilot::FG_HEADING_NAV1) {
1161 current_autopilot->set_HeadingEnabled(false);
1167 ////////////////////////////////////////////////////////////////////////
1168 // Radio navigation.
1169 ////////////////////////////////////////////////////////////////////////
1172 FGBFI::getNAV1Freq ()
1174 return current_radiostack->get_nav1_freq();
1178 FGBFI::getNAV1AltFreq ()
1180 return current_radiostack->get_nav1_alt_freq();
1184 FGBFI::getNAV1Radial ()
1186 return current_radiostack->get_nav1_radial();
1190 FGBFI::getNAV1SelRadial ()
1192 return current_radiostack->get_nav1_sel_radial();
1196 FGBFI::getNAV1DistDME ()
1198 return current_radiostack->get_nav1_dme_dist();
1204 if (current_radiostack->get_nav1_inrange()) {
1205 double heading = current_radiostack->get_nav1_heading();
1206 double radial = current_radiostack->get_nav1_radial();
1207 double var = FGBFI::getMagVar();
1208 if (current_radiostack->get_nav1_loc()) {
1209 double offset = fabs(heading - radial);
1210 return (offset<= 8.0 || offset >= 352.0);
1213 fabs(heading - var - radial);
1214 return (offset <= 20.0 || offset >= 340.0);
1222 FGBFI::getNAV1FROM ()
1224 if (current_radiostack->get_nav1_inrange()) {
1225 double heading = current_radiostack->get_nav1_heading();
1226 double radial = current_radiostack->get_nav1_radial();
1227 double var = FGBFI::getMagVar();
1228 if (current_radiostack->get_nav1_loc()) {
1229 double offset = fabs(heading - radial);
1230 return (offset >= 172.0 && offset<= 188.0);
1233 fabs(heading - var - radial);
1234 return (offset >= 160.0 && offset <= 200.0);
1242 FGBFI::getNAV1InRange ()
1244 return current_radiostack->get_nav1_inrange();
1248 FGBFI::getNAV1DMEInRange ()
1250 return (current_radiostack->get_nav1_inrange() &&
1251 current_radiostack->get_nav1_has_dme());
1255 FGBFI::getNAV2Freq ()
1257 return current_radiostack->get_nav2_freq();
1261 FGBFI::getNAV2AltFreq ()
1263 return current_radiostack->get_nav2_alt_freq();
1267 FGBFI::getNAV2Radial ()
1269 return current_radiostack->get_nav2_radial();
1273 FGBFI::getNAV2SelRadial ()
1275 return current_radiostack->get_nav2_sel_radial();
1279 FGBFI::getNAV2DistDME ()
1281 return current_radiostack->get_nav2_dme_dist();
1287 if (current_radiostack->get_nav2_inrange()) {
1288 double heading = current_radiostack->get_nav2_heading();
1289 double radial = current_radiostack->get_nav2_radial();
1290 double var = FGBFI::getMagVar();
1291 if (current_radiostack->get_nav2_loc()) {
1292 double offset = fabs(heading - radial);
1293 return (offset<= 8.0 || offset >= 352.0);
1296 fabs(heading - var - radial);
1297 return (offset <= 20.0 || offset >= 340.0);
1305 FGBFI::getNAV2FROM ()
1307 if (current_radiostack->get_nav2_inrange()) {
1308 double heading = current_radiostack->get_nav2_heading();
1309 double radial = current_radiostack->get_nav2_radial();
1310 double var = FGBFI::getMagVar();
1311 if (current_radiostack->get_nav2_loc()) {
1312 double offset = fabs(heading - radial);
1313 return (offset >= 172.0 && offset<= 188.0);
1316 fabs(heading - var - radial);
1317 return (offset >= 160.0 && offset <= 200.0);
1326 FGBFI::getNAV2InRange ()
1328 return current_radiostack->get_nav2_inrange();
1332 FGBFI::getNAV2DMEInRange ()
1334 return (current_radiostack->get_nav2_inrange() &&
1335 current_radiostack->get_nav2_has_dme());
1339 FGBFI::getADFFreq ()
1341 return current_radiostack->get_adf_freq();
1345 FGBFI::getADFAltFreq ()
1347 return current_radiostack->get_adf_alt_freq();
1351 FGBFI::getADFRotation ()
1353 return current_radiostack->get_adf_rotation();
1357 FGBFI::setNAV1Freq (double freq)
1359 current_radiostack->set_nav1_freq(freq);
1363 FGBFI::setNAV1AltFreq (double freq)
1365 current_radiostack->set_nav1_alt_freq(freq);
1369 FGBFI::setNAV1SelRadial (double radial)
1371 current_radiostack->set_nav1_sel_radial(radial);
1375 FGBFI::setNAV2Freq (double freq)
1377 current_radiostack->set_nav2_freq(freq);
1381 FGBFI::setNAV2AltFreq (double freq)
1383 current_radiostack->set_nav2_alt_freq(freq);
1387 FGBFI::setNAV2SelRadial (double radial)
1389 current_radiostack->set_nav2_sel_radial(radial);
1393 FGBFI::setADFFreq (double freq)
1395 current_radiostack->set_adf_freq(freq);
1399 FGBFI::setADFAltFreq (double freq)
1401 current_radiostack->set_adf_alt_freq(freq);
1405 FGBFI::setADFRotation (double rot)
1407 current_radiostack->set_adf_rotation(rot);
1412 ////////////////////////////////////////////////////////////////////////
1414 ////////////////////////////////////////////////////////////////////////
1418 * Get the autopilot GPS lock (true=on).
1421 FGBFI::getGPSLock ()
1423 return (current_autopilot->get_HeadingEnabled() &&
1424 (current_autopilot->get_HeadingMode() ==
1425 FGAutopilot::FG_HEADING_WAYPOINT ));
1430 * Set the autopilot GPS lock (true=on).
1433 FGBFI::setGPSLock (bool lock)
1436 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1437 current_autopilot->set_HeadingEnabled(true);
1438 } else if (current_autopilot->get_HeadingMode() ==
1439 FGAutopilot::FG_HEADING_WAYPOINT) {
1440 current_autopilot->set_HeadingEnabled(false);
1446 * Get the GPS target airport code.
1449 FGBFI::getTargetAirport ()
1451 return current_options.get_airport_id();
1456 * Set the GPS target airport code.
1459 FGBFI::setTargetAirport (const string &airportId)
1461 current_options.set_airport_id(airportId);
1466 * Get the GPS target latitude in degrees (negative for south).
1469 FGBFI::getGPSTargetLatitude ()
1471 return current_autopilot->get_TargetLatitude();
1476 * Set the GPS target latitude in degrees (negative for south).
1479 FGBFI::setGPSTargetLatitude (double latitude)
1481 current_autopilot->set_TargetLatitude( latitude );
1486 * Get the GPS target longitude in degrees (negative for west).
1489 FGBFI::getGPSTargetLongitude ()
1491 return current_autopilot->get_TargetLongitude();
1496 * Set the GPS target longitude in degrees (negative for west).
1499 FGBFI::setGPSTargetLongitude (double longitude)
1501 current_autopilot->set_TargetLongitude( longitude );
1506 ////////////////////////////////////////////////////////////////////////
1508 ////////////////////////////////////////////////////////////////////////
1512 * Get the current visible (units??).
1515 FGBFI::getVisibility ()
1517 #ifndef FG_OLD_WEATHER
1518 return WeatherDatabase->getWeatherVisibility();
1520 return current_weather.get_visibility();
1526 * Check whether clouds are enabled.
1531 return current_options.get_clouds();
1536 * Check the height of the clouds ASL (units?).
1539 FGBFI::getCloudsASL ()
1541 return current_options.get_clouds_asl();
1546 * Set the current visibility (units??).
1549 FGBFI::setVisibility (double visibility)
1551 #ifndef FG_OLD_WEATHER
1552 WeatherDatabase->setWeatherVisibility(visibility);
1554 current_weather.set_visibility(visibility);
1560 * Switch clouds on or off.
1563 FGBFI::setClouds (bool clouds)
1565 cout << "Set clouds to " << clouds << endl;
1566 current_options.set_clouds(clouds);
1572 * Set the cloud height.
1575 FGBFI::setCloudsASL (double cloudsASL)
1577 current_options.set_clouds_asl(cloudsASL);
1583 ////////////////////////////////////////////////////////////////////////
1585 ////////////////////////////////////////////////////////////////////////
1588 * Return the magnetic variation
1593 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1598 * Return the magnetic variation
1603 return globals->get_mag()->get_magdip() * RAD_TO_DEG;