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.tieString("/position/airport-id",
108 getTargetAirport, setTargetAirport);
109 current_properties.tieDouble("/position/latitude",
110 getLatitude, setLatitude);
111 current_properties.tieDouble("/position/longitude",
112 getLongitude, setLongitude);
113 current_properties.tieDouble("/position/altitude",
114 getAltitude, setAltitude);
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",
135 current_properties.tieDouble("/velocities/airspeed",
137 current_properties.tieDouble("/velocities/side-slip",
139 current_properties.tieDouble("/velocities/vertical-speed",
140 getVerticalSpeed, 0);
141 current_properties.tieDouble("/velocities/speed-north",
142 getSpeedNorth, setSpeedNorth);
143 current_properties.tieDouble("/velocities/speed-east",
144 getSpeedEast, setSpeedEast);
145 current_properties.tieDouble("/velocities/speed-down",
146 getSpeedDown, setSpeedDown);
149 current_properties.tieDouble("/controls/throttle",
150 getThrottle, setThrottle);
151 current_properties.tieDouble("/controls/mixture",
152 getMixture, setMixture);
153 current_properties.tieDouble("/controls/propellor-pitch",
154 getPropAdvance, setPropAdvance);
155 current_properties.tieDouble("/controls/flaps",
157 current_properties.tieDouble("/controls/aileron",
158 getAileron, setAileron);
159 current_properties.tieDouble("/controls/rudder",
160 getRudder, setRudder);
161 current_properties.tieDouble("/controls/elevator",
162 getElevator, setElevator);
163 current_properties.tieDouble("/controls/elevator-trim",
164 getElevatorTrim, setElevatorTrim);
165 current_properties.tieDouble("/controls/brakes/all",
166 getBrakes, setBrakes);
167 current_properties.tieDouble("/controls/brakes/left",
168 getLeftBrake, setLeftBrake);
169 current_properties.tieDouble("/controls/brakes/right",
170 getRightBrake, setRightBrake);
171 current_properties.tieDouble("/controls/brakes/center",
172 getRightBrake, setCenterBrake);
175 current_properties.tieBool("/autopilot/locks/altitude",
176 getAPAltitudeLock, setAPAltitudeLock);
177 current_properties.tieDouble("/autopilot/settings/altitude",
178 getAPAltitude, setAPAltitude);
179 current_properties.tieBool("/autopilot/locks/heading",
180 getAPHeadingLock, setAPHeadingLock);
181 current_properties.tieDouble("/autopilot/settings/heading",
182 getAPHeading, setAPHeading);
183 current_properties.tieDouble("/autopilot/settings/heading-magnetic",
184 getAPHeadingMag, setAPHeadingMag);
185 current_properties.tieBool("/autopilot/locks/nav1",
186 getAPNAV1Lock, setAPNAV1Lock);
189 current_properties.tieDouble("/radios/nav1/frequencies/selected",
190 getNAV1Freq, setNAV1Freq);
191 current_properties.tieDouble("/radios/nav1/frequencies/standby",
192 getNAV1AltFreq, setNAV1AltFreq);
193 current_properties.tieDouble("/radios/nav1/radials/actual",
195 current_properties.tieDouble("/radios/nav1/radials/selected",
196 getNAV1SelRadial, setNAV1SelRadial);
197 current_properties.tieDouble("/radios/nav1/dme/distance",
199 current_properties.tieBool("/radios/nav1/to-flag",
201 current_properties.tieBool("/radios/nav1/from-flag",
203 current_properties.tieBool("/radios/nav1/in-range",
205 current_properties.tieBool("/radios/nav1/dme/in-range",
206 getNAV1DMEInRange, 0);
208 current_properties.tieDouble("/radios/nav2/frequencies/selected",
209 getNAV2Freq, setNAV2Freq);
210 current_properties.tieDouble("/radios/nav2/frequencies/standby",
211 getNAV2AltFreq, setNAV2AltFreq);
212 current_properties.tieDouble("/radios/nav2/radials/actual",
214 current_properties.tieDouble("/radios/nav2/radials/selected",
215 getNAV2SelRadial, setNAV2SelRadial);
216 current_properties.tieDouble("/radios/nav2/dme/distance",
218 current_properties.tieBool("/radios/nav2/to-flag",
220 current_properties.tieBool("/radios/nav2/from-flag",
222 current_properties.tieBool("/radios/nav2/in-range",
224 current_properties.tieBool("/radios/nav2/dme/in-range",
225 getNAV2DMEInRange, 0);
227 current_properties.tieDouble("/radios/adf/frequencies/selected",
228 getADFFreq, setADFFreq);
229 current_properties.tieDouble("/radios/adf/frequencies/standby",
230 getADFAltFreq, setADFAltFreq);
231 current_properties.tieDouble("/radios/adf/rotation",
232 getADFRotation, setADFRotation);
234 current_properties.tieDouble("/environment/visibility",
235 getVisibility, setVisibility);
237 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
242 * Reinitialize FGFS if required.
244 * Some changes (especially those in aircraft position) require that
245 * FGFS be reinitialized afterwards. Rather than reinitialize after
246 * every change, the setter methods simply set a flag so that there
247 * can be a single reinit at the end of the frame.
259 * Reinitialize FGFS to use the new BFI settings.
264 // Save the state of everything
265 // that's going to get clobbered
266 // when we reinit the subsystems.
268 cout << "BFI: start reinit\n";
270 // TODO: add more AP stuff
271 double elevator = getElevator();
272 double aileron = getAileron();
273 double rudder = getRudder();
274 double throttle = getThrottle();
275 double elevator_trim = getElevatorTrim();
276 double flaps = getFlaps();
277 double brake = getBrakes();
278 bool apHeadingLock = getAPHeadingLock();
279 double apHeadingMag = getAPHeadingMag();
280 bool apAltitudeLock = getAPAltitudeLock();
281 double apAltitude = getAPAltitude();
282 const string &targetAirport = getTargetAirport();
283 bool gpsLock = getGPSLock();
284 double gpsLatitude = getGPSTargetLatitude();
285 double gpsLongitude = getGPSTargetLongitude();
287 setTargetAirport("");
288 cout << "Target airport is " << current_options.get_airport_id() << endl;
290 fgReInitSubsystems();
292 // FIXME: this is wrong.
293 // All of these are scheduled events,
294 // and it should be possible to force
295 // them all to run once.
298 cur_light_params.Update();
300 fgUpdateWeatherDatabase();
303 // Restore all of the old states.
304 setElevator(elevator);
307 setThrottle(throttle);
308 setElevatorTrim(elevator_trim);
311 setAPHeadingLock(apHeadingLock);
312 setAPHeadingMag(apHeadingMag);
313 setAPAltitudeLock(apAltitudeLock);
314 setAPAltitude(apAltitude);
315 setTargetAirport(targetAirport);
317 setGPSTargetLatitude(gpsLatitude);
318 setGPSTargetLongitude(gpsLongitude);
322 cout << "BFI: end reinit\n";
327 ////////////////////////////////////////////////////////////////////////
329 ////////////////////////////////////////////////////////////////////////
333 * Return the flight model as an integer.
335 * TODO: use a string instead.
338 FGBFI::getFlightModel ()
340 return current_options.get_flight_model();
345 * Return the current aircraft as a string.
348 FGBFI::getAircraft ()
350 return current_options.get_aircraft();
355 * Return the current aircraft directory (UIUC) as a string.
358 FGBFI::getAircraftDir ()
365 * Set the flight model as an integer.
367 * TODO: use a string instead.
370 FGBFI::setFlightModel (int model)
372 if (getFlightModel() != model) {
373 current_options.set_flight_model(model);
380 * Set the current aircraft.
383 FGBFI::setAircraft (const string &aircraft)
385 if (getAircraft() != aircraft) {
386 current_options.set_aircraft(aircraft);
393 * Set the current aircraft directory (UIUC).
396 FGBFI::setAircraftDir (const string &dir)
398 if (getAircraftDir() != dir) {
406 * Return the current Zulu time.
411 return globals->get_time_params()->get_cur_time();
416 * Set the current Zulu time.
419 FGBFI::setTimeGMT (time_t time)
421 if (getTimeGMT() != time) {
422 // FIXME: need to update lighting
424 current_options.set_time_offset(time);
425 current_options.set_time_offset_type(fgOPTIONS::FG_TIME_GMT_ABSOLUTE);
426 globals->get_time_params()->update( cur_fdm_state->get_Longitude(),
427 cur_fdm_state->get_Latitude(),
428 globals->get_warp() );
435 * Return the GMT as a string.
438 FGBFI::getGMTString ()
440 static string out; // FIXME: not thread-safe
442 struct tm * t = globals->get_time_params()->getGmt();
443 sprintf(buf, " %.2d:%.2d:%.2d",
444 t->tm_hour, t->tm_min, t->tm_sec);
451 * Return true if the HUD is visible.
454 FGBFI::getHUDVisible ()
456 return current_options.get_hud_status();
461 * Ensure that the HUD is visible or hidden.
464 FGBFI::setHUDVisible (bool visible)
466 current_options.set_hud_status(visible);
471 * Return true if the 2D panel is visible.
474 FGBFI::getPanelVisible ()
476 return current_options.get_panel_status();
481 * Ensure that the 2D panel is visible or hidden.
484 FGBFI::setPanelVisible (bool visible)
486 if (current_options.get_panel_status() != visible) {
487 current_options.toggle_panel();
493 ////////////////////////////////////////////////////////////////////////
495 ////////////////////////////////////////////////////////////////////////
499 * Return the current latitude in degrees (negative for south).
502 FGBFI::getLatitude ()
504 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
509 * Set the current latitude in degrees (negative for south).
512 FGBFI::setLatitude (double latitude)
514 if (getLatitude() != latitude) {
515 current_options.set_lat(latitude);
516 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
523 * Return the current longitude in degrees (negative for west).
526 FGBFI::getLongitude ()
528 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
533 * Set the current longitude in degrees (negative for west).
536 FGBFI::setLongitude (double longitude)
538 if (getLongitude() != longitude) {
539 current_options.set_lon(longitude);
540 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
547 * Return the current altitude in feet.
550 FGBFI::getAltitude ()
552 return current_aircraft.fdm_state->get_Altitude();
558 * Return the current altitude in above the terrain.
563 return current_aircraft.fdm_state->get_Altitude()
564 - (scenery.cur_elev * METER_TO_FEET);
569 * Set the current altitude in feet.
572 FGBFI::setAltitude (double altitude)
574 if (getAltitude() != altitude) {
575 fgFDMForceAltitude(getFlightModel(), altitude);
576 current_options.set_altitude(altitude);
577 current_aircraft.fdm_state->set_Altitude(altitude);
583 ////////////////////////////////////////////////////////////////////////
585 ////////////////////////////////////////////////////////////////////////
589 * Return the current heading in degrees.
594 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
599 * Return the current heading in degrees.
602 FGBFI::getHeadingMag ()
604 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
609 * Set the current heading in degrees.
612 FGBFI::setHeading (double heading)
614 if (getHeading() != heading) {
615 current_options.set_heading(heading);
616 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
617 getPitch() * DEG_TO_RAD,
618 heading * DEG_TO_RAD);
625 * Return the current pitch in degrees.
630 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
635 * Set the current pitch in degrees.
638 FGBFI::setPitch (double pitch)
640 if (getPitch() != pitch) {
641 current_options.set_pitch(pitch);
642 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
644 getHeading() * DEG_TO_RAD);
651 * Return the current roll in degrees.
656 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
661 * Set the current roll in degrees.
664 FGBFI::setRoll (double roll)
666 if (getRoll() != roll) {
667 current_options.set_roll(roll);
668 current_aircraft.fdm_state->set_Euler_Angles(roll * DEG_TO_RAD,
669 getPitch() * DEG_TO_RAD,
670 getHeading() * DEG_TO_RAD);
677 * Return the current engine0 rpm
682 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
683 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
691 * Set the current engine0 rpm
694 FGBFI::setRPM (double rpm)
696 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
697 if (getRPM() != rpm) {
698 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
705 * Return the current engine0 EGT.
710 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
711 return current_aircraft.fdm_state->get_engine(0)->get_EGT();
717 ////////////////////////////////////////////////////////////////////////
719 ////////////////////////////////////////////////////////////////////////
723 * Return the current airspeed in knots.
726 FGBFI::getAirspeed ()
728 // FIXME: should we add speed-up?
729 return current_aircraft.fdm_state->get_V_calibrated_kts();
734 * Return the current sideslip (FIXME: units unknown).
737 FGBFI::getSideSlip ()
739 return current_aircraft.fdm_state->get_Beta();
744 * Return the current climb rate in feet/minute
747 FGBFI::getVerticalSpeed ()
749 // What about meters?
750 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
755 * Get the current north velocity (units??).
758 FGBFI::getSpeedNorth ()
760 return current_aircraft.fdm_state->get_V_north();
765 * Set the current north velocity (units??).
768 FGBFI::setSpeedNorth (double speed)
770 if (getSpeedNorth() != speed) {
771 current_options.set_uBody(speed);
772 current_aircraft.fdm_state->set_Velocities_Local(speed,
781 * Get the current east velocity (units??).
784 FGBFI::getSpeedEast ()
786 return current_aircraft.fdm_state->get_V_east();
791 * Set the current east velocity (units??).
794 FGBFI::setSpeedEast (double speed)
796 if (getSpeedEast() != speed) {
797 current_options.set_vBody(speed);
798 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
807 * Get the current down velocity (units??).
810 FGBFI::getSpeedDown ()
812 return current_aircraft.fdm_state->get_V_down();
817 * Set the current down velocity (units??).
820 FGBFI::setSpeedDown (double speed)
822 if (getSpeedDown() != speed) {
823 current_options.set_wBody(speed);
824 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
833 ////////////////////////////////////////////////////////////////////////
835 ////////////////////////////////////////////////////////////////////////
839 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
842 FGBFI::getThrottle ()
844 // FIXME: add engine selector
845 return controls.get_throttle(0);
850 * Set the throttle, from 0.0 (none) to 1.0 (full).
853 FGBFI::setThrottle (double throttle)
855 // FIXME: allow engine selection
856 controls.set_throttle(0, throttle);
861 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
866 // FIXME: add engine selector
867 return controls.get_mixture(0);
872 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
875 FGBFI::setMixture (double mixture)
877 // FIXME: allow engine selection
878 controls.set_mixture(0, mixture);
883 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
886 FGBFI::getPropAdvance ()
888 // FIXME: add engine selector
889 return controls.get_prop_advance(0);
894 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
897 FGBFI::setPropAdvance (double pitch)
899 // FIXME: allow engine selection
900 controls.set_prop_advance(0, pitch);
905 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
910 return controls.get_flaps();
915 * Set the flaps, from 0.0 (none) to 1.0 (full).
918 FGBFI::setFlaps (double flaps)
921 controls.set_flaps(flaps);
926 * Get the aileron, from -1.0 (left) to 1.0 (right).
931 return controls.get_aileron();
936 * Set the aileron, from -1.0 (left) to 1.0 (right).
939 FGBFI::setAileron (double aileron)
942 controls.set_aileron(aileron);
947 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
952 return controls.get_rudder();
957 * Set the rudder, from -1.0 (left) to 1.0 (right).
960 FGBFI::setRudder (double rudder)
963 controls.set_rudder(rudder);
968 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
971 FGBFI::getElevator ()
973 return controls.get_elevator();
978 * Set the elevator, from -1.0 (down) to 1.0 (up).
981 FGBFI::setElevator (double elevator)
984 controls.set_elevator(elevator);
989 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
992 FGBFI::getElevatorTrim ()
994 return controls.get_elevator_trim();
999 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
1002 FGBFI::setElevatorTrim (double trim)
1005 controls.set_elevator_trim(trim);
1010 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1015 double b1 = getCenterBrake();
1016 double b2 = getLeftBrake();
1017 double b3 = getRightBrake();
1018 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1023 * Set all brakes, from 0.0 (none) to 1.0 (full).
1026 FGBFI::setBrakes (double brake)
1028 setCenterBrake(brake);
1029 setLeftBrake(brake);
1030 setRightBrake(brake);
1035 * Get the center brake, from 0.0 (none) to 1.0 (full).
1038 FGBFI::getCenterBrake ()
1040 return controls.get_brake(2);
1045 * Set the center brake, from 0.0 (none) to 1.0 (full).
1048 FGBFI::setCenterBrake (double brake)
1050 controls.set_brake(2, brake);
1055 * Get the left brake, from 0.0 (none) to 1.0 (full).
1058 FGBFI::getLeftBrake ()
1060 return controls.get_brake(0);
1065 * Set the left brake, from 0.0 (none) to 1.0 (full).
1068 FGBFI::setLeftBrake (double brake)
1070 controls.set_brake(0, brake);
1075 * Get the right brake, from 0.0 (none) to 1.0 (full).
1078 FGBFI::getRightBrake ()
1080 return controls.get_brake(1);
1085 * Set the right brake, from 0.0 (none) to 1.0 (full).
1088 FGBFI::setRightBrake (double brake)
1090 controls.set_brake(1, brake);
1097 ////////////////////////////////////////////////////////////////////////
1099 ////////////////////////////////////////////////////////////////////////
1103 * Get the autopilot altitude lock (true=on).
1106 FGBFI::getAPAltitudeLock ()
1108 return current_autopilot->get_AltitudeEnabled();
1113 * Set the autopilot altitude lock (true=on).
1116 FGBFI::setAPAltitudeLock (bool lock)
1118 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1119 current_autopilot->set_AltitudeEnabled(lock);
1124 * Get the autopilot target altitude in feet.
1127 FGBFI::getAPAltitude ()
1129 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1134 * Set the autopilot target altitude in feet.
1137 FGBFI::setAPAltitude (double altitude)
1139 current_autopilot->set_TargetAltitude( altitude );
1144 * Get the autopilot heading lock (true=on).
1147 FGBFI::getAPHeadingLock ()
1150 (current_autopilot->get_HeadingEnabled() &&
1151 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1156 * Set the autopilot heading lock (true=on).
1159 FGBFI::setAPHeadingLock (bool lock)
1162 // We need to do this so that
1163 // it's possible to lock onto a
1164 // heading other than the current
1166 double heading = getAPHeadingMag();
1167 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1168 current_autopilot->set_HeadingEnabled(true);
1169 setAPHeadingMag(heading);
1170 } else if (current_autopilot->get_HeadingMode() ==
1171 FGAutopilot::FG_HEADING_LOCK) {
1172 current_autopilot->set_HeadingEnabled(false);
1178 * Get the autopilot target heading in degrees.
1181 FGBFI::getAPHeading ()
1183 return current_autopilot->get_TargetHeading();
1188 * Set the autopilot target heading in degrees.
1191 FGBFI::setAPHeading (double heading)
1193 current_autopilot->set_TargetHeading( heading );
1198 * Get the autopilot target heading in degrees.
1201 FGBFI::getAPHeadingMag ()
1203 return current_autopilot->get_TargetHeading() - getMagVar();
1208 * Set the autopilot target heading in degrees.
1211 FGBFI::setAPHeadingMag (double heading)
1213 current_autopilot->set_TargetHeading( heading + getMagVar() );
1218 * Return true if the autopilot is locked to NAV1.
1221 FGBFI::getAPNAV1Lock ()
1224 (current_autopilot->get_HeadingEnabled() &&
1225 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1230 * Set the autopilot NAV1 lock.
1233 FGBFI::setAPNAV1Lock (bool lock)
1236 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1237 current_autopilot->set_HeadingEnabled(true);
1238 } else if (current_autopilot->get_HeadingMode() ==
1239 FGAutopilot::FG_HEADING_NAV1) {
1240 current_autopilot->set_HeadingEnabled(false);
1246 ////////////////////////////////////////////////////////////////////////
1247 // Radio navigation.
1248 ////////////////////////////////////////////////////////////////////////
1251 FGBFI::getNAV1Freq ()
1253 return current_radiostack->get_nav1_freq();
1257 FGBFI::getNAV1AltFreq ()
1259 return current_radiostack->get_nav1_alt_freq();
1263 FGBFI::getNAV1Radial ()
1265 return current_radiostack->get_nav1_radial();
1269 FGBFI::getNAV1SelRadial ()
1271 return current_radiostack->get_nav1_sel_radial();
1275 FGBFI::getNAV1DistDME ()
1277 return current_radiostack->get_nav1_dme_dist();
1283 if (current_radiostack->get_nav1_inrange()) {
1284 double heading = current_radiostack->get_nav1_heading();
1285 double radial = current_radiostack->get_nav1_radial();
1286 double var = FGBFI::getMagVar();
1287 if (current_radiostack->get_nav1_loc()) {
1288 double offset = fabs(heading - radial);
1289 return (offset<= 8.0 || offset >= 352.0);
1292 fabs(heading - var - radial);
1293 return (offset <= 20.0 || offset >= 340.0);
1301 FGBFI::getNAV1FROM ()
1303 if (current_radiostack->get_nav1_inrange()) {
1304 double heading = current_radiostack->get_nav1_heading();
1305 double radial = current_radiostack->get_nav1_radial();
1306 double var = FGBFI::getMagVar();
1307 if (current_radiostack->get_nav1_loc()) {
1308 double offset = fabs(heading - radial);
1309 return (offset >= 172.0 && offset<= 188.0);
1312 fabs(heading - var - radial);
1313 return (offset >= 160.0 && offset <= 200.0);
1321 FGBFI::getNAV1InRange ()
1323 return current_radiostack->get_nav1_inrange();
1327 FGBFI::getNAV1DMEInRange ()
1329 return (current_radiostack->get_nav1_inrange() &&
1330 current_radiostack->get_nav1_has_dme());
1334 FGBFI::getNAV2Freq ()
1336 return current_radiostack->get_nav2_freq();
1340 FGBFI::getNAV2AltFreq ()
1342 return current_radiostack->get_nav2_alt_freq();
1346 FGBFI::getNAV2Radial ()
1348 return current_radiostack->get_nav2_radial();
1352 FGBFI::getNAV2SelRadial ()
1354 return current_radiostack->get_nav2_sel_radial();
1358 FGBFI::getNAV2DistDME ()
1360 return current_radiostack->get_nav2_dme_dist();
1366 if (current_radiostack->get_nav2_inrange()) {
1367 double heading = current_radiostack->get_nav2_heading();
1368 double radial = current_radiostack->get_nav2_radial();
1369 double var = FGBFI::getMagVar();
1370 if (current_radiostack->get_nav2_loc()) {
1371 double offset = fabs(heading - radial);
1372 return (offset<= 8.0 || offset >= 352.0);
1375 fabs(heading - var - radial);
1376 return (offset <= 20.0 || offset >= 340.0);
1384 FGBFI::getNAV2FROM ()
1386 if (current_radiostack->get_nav2_inrange()) {
1387 double heading = current_radiostack->get_nav2_heading();
1388 double radial = current_radiostack->get_nav2_radial();
1389 double var = FGBFI::getMagVar();
1390 if (current_radiostack->get_nav2_loc()) {
1391 double offset = fabs(heading - radial);
1392 return (offset >= 172.0 && offset<= 188.0);
1395 fabs(heading - var - radial);
1396 return (offset >= 160.0 && offset <= 200.0);
1405 FGBFI::getNAV2InRange ()
1407 return current_radiostack->get_nav2_inrange();
1411 FGBFI::getNAV2DMEInRange ()
1413 return (current_radiostack->get_nav2_inrange() &&
1414 current_radiostack->get_nav2_has_dme());
1418 FGBFI::getADFFreq ()
1420 return current_radiostack->get_adf_freq();
1424 FGBFI::getADFAltFreq ()
1426 return current_radiostack->get_adf_alt_freq();
1430 FGBFI::getADFRotation ()
1432 return current_radiostack->get_adf_rotation();
1436 FGBFI::setNAV1Freq (double freq)
1438 current_radiostack->set_nav1_freq(freq);
1442 FGBFI::setNAV1AltFreq (double freq)
1444 current_radiostack->set_nav1_alt_freq(freq);
1448 FGBFI::setNAV1SelRadial (double radial)
1450 current_radiostack->set_nav1_sel_radial(radial);
1454 FGBFI::setNAV2Freq (double freq)
1456 current_radiostack->set_nav2_freq(freq);
1460 FGBFI::setNAV2AltFreq (double freq)
1462 current_radiostack->set_nav2_alt_freq(freq);
1466 FGBFI::setNAV2SelRadial (double radial)
1468 current_radiostack->set_nav2_sel_radial(radial);
1472 FGBFI::setADFFreq (double freq)
1474 current_radiostack->set_adf_freq(freq);
1478 FGBFI::setADFAltFreq (double freq)
1480 current_radiostack->set_adf_alt_freq(freq);
1484 FGBFI::setADFRotation (double rot)
1486 current_radiostack->set_adf_rotation(rot);
1491 ////////////////////////////////////////////////////////////////////////
1493 ////////////////////////////////////////////////////////////////////////
1497 * Get the autopilot GPS lock (true=on).
1500 FGBFI::getGPSLock ()
1502 return (current_autopilot->get_HeadingEnabled() &&
1503 (current_autopilot->get_HeadingMode() ==
1504 FGAutopilot::FG_HEADING_WAYPOINT ));
1509 * Set the autopilot GPS lock (true=on).
1512 FGBFI::setGPSLock (bool lock)
1515 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1516 current_autopilot->set_HeadingEnabled(true);
1517 } else if (current_autopilot->get_HeadingMode() ==
1518 FGAutopilot::FG_HEADING_WAYPOINT) {
1519 current_autopilot->set_HeadingEnabled(false);
1525 * Get the GPS target airport code.
1528 FGBFI::getTargetAirport ()
1530 // FIXME: not thread-safe
1532 out = current_options.get_airport_id();
1539 * Set the GPS target airport code.
1542 FGBFI::setTargetAirport (const string &airportId)
1544 // cout << "setting target airport id = " << airportId << endl;
1545 current_options.set_airport_id(airportId);
1550 * Get the GPS target latitude in degrees (negative for south).
1553 FGBFI::getGPSTargetLatitude ()
1555 return current_autopilot->get_TargetLatitude();
1560 * Set the GPS target latitude in degrees (negative for south).
1563 FGBFI::setGPSTargetLatitude (double latitude)
1565 current_autopilot->set_TargetLatitude( latitude );
1570 * Get the GPS target longitude in degrees (negative for west).
1573 FGBFI::getGPSTargetLongitude ()
1575 return current_autopilot->get_TargetLongitude();
1580 * Set the GPS target longitude in degrees (negative for west).
1583 FGBFI::setGPSTargetLongitude (double longitude)
1585 current_autopilot->set_TargetLongitude( longitude );
1590 ////////////////////////////////////////////////////////////////////////
1592 ////////////////////////////////////////////////////////////////////////
1596 * Get the current visible (units??).
1599 FGBFI::getVisibility ()
1601 #ifndef FG_OLD_WEATHER
1602 return WeatherDatabase->getWeatherVisibility();
1604 return current_weather.get_visibility();
1610 * Check whether clouds are enabled.
1615 return current_options.get_clouds();
1620 * Check the height of the clouds ASL (units?).
1623 FGBFI::getCloudsASL ()
1625 return current_options.get_clouds_asl();
1630 * Set the current visibility (units??).
1633 FGBFI::setVisibility (double visibility)
1635 #ifndef FG_OLD_WEATHER
1636 WeatherDatabase->setWeatherVisibility(visibility);
1638 current_weather.set_visibility(visibility);
1644 * Switch clouds on or off.
1647 FGBFI::setClouds (bool clouds)
1649 if (getClouds() != clouds) {
1650 cout << "Set clouds to " << clouds << endl;
1651 current_options.set_clouds(clouds);
1658 * Set the cloud height.
1661 FGBFI::setCloudsASL (double cloudsASL)
1663 if (getCloudsASL() != cloudsASL) {
1664 current_options.set_clouds_asl(cloudsASL);
1671 ////////////////////////////////////////////////////////////////////////
1673 ////////////////////////////////////////////////////////////////////////
1676 * Return the magnetic variation
1681 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1686 * Return the magnetic variation
1691 return globals->get_mag()->get_magdip() * RAD_TO_DEG;