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",
137 current_properties.tieDouble("/velocities/airspeed",
139 current_properties.tieDouble("/velocities/side-slip",
141 current_properties.tieDouble("/velocities/vertical-speed",
142 getVerticalSpeed, 0);
143 current_properties.tieDouble("/velocities/speed-north",
144 getSpeedNorth, setSpeedNorth);
145 current_properties.tieDouble("/velocities/speed-east",
146 getSpeedEast, setSpeedEast);
147 current_properties.tieDouble("/velocities/speed-down",
148 getSpeedDown, setSpeedDown);
151 current_properties.tieDouble("/controls/throttle",
152 getThrottle, setThrottle);
153 current_properties.tieDouble("/controls/mixture",
154 getMixture, setMixture);
155 current_properties.tieDouble("/controls/propellor-pitch",
156 getPropAdvance, setPropAdvance);
157 current_properties.tieDouble("/controls/flaps",
159 current_properties.tieDouble("/controls/aileron",
160 getAileron, setAileron);
161 current_properties.tieDouble("/controls/rudder",
162 getRudder, setRudder);
163 current_properties.tieDouble("/controls/elevator",
164 getElevator, setElevator);
165 current_properties.tieDouble("/controls/elevator-trim",
166 getElevatorTrim, setElevatorTrim);
167 current_properties.tieDouble("/controls/brakes/all",
168 getBrakes, setBrakes);
169 current_properties.tieDouble("/controls/brakes/left",
170 getLeftBrake, setLeftBrake);
171 current_properties.tieDouble("/controls/brakes/right",
172 getRightBrake, setRightBrake);
173 current_properties.tieDouble("/controls/brakes/center",
174 getRightBrake, setCenterBrake);
177 current_properties.tieBool("/autopilot/locks/altitude",
178 getAPAltitudeLock, setAPAltitudeLock);
179 current_properties.tieDouble("/autopilot/settings/altitude",
180 getAPAltitude, setAPAltitude);
181 current_properties.tieBool("/autopilot/locks/heading",
182 getAPHeadingLock, setAPHeadingLock);
183 current_properties.tieDouble("/autopilot/settings/heading",
184 getAPHeading, setAPHeading);
185 current_properties.tieDouble("/autopilot/settings/heading-magnetic",
186 getAPHeadingMag, setAPHeadingMag);
187 current_properties.tieBool("/autopilot/locks/nav1",
188 getAPNAV1Lock, setAPNAV1Lock);
191 current_properties.tieDouble("/radios/nav1/frequencies/selected",
192 getNAV1Freq, setNAV1Freq);
193 current_properties.tieDouble("/radios/nav1/frequencies/standby",
194 getNAV1AltFreq, setNAV1AltFreq);
195 current_properties.tieDouble("/radios/nav1/radials/actual",
197 current_properties.tieDouble("/radios/nav1/radials/selected",
198 getNAV1SelRadial, setNAV1SelRadial);
199 current_properties.tieDouble("/radios/nav1/dme/distance",
201 current_properties.tieBool("/radios/nav1/to-flag",
203 current_properties.tieBool("/radios/nav1/from-flag",
205 current_properties.tieBool("/radios/nav1/in-range",
207 current_properties.tieBool("/radios/nav1/dme/in-range",
208 getNAV1DMEInRange, 0);
210 current_properties.tieDouble("/radios/nav2/frequencies/selected",
211 getNAV2Freq, setNAV2Freq);
212 current_properties.tieDouble("/radios/nav2/frequencies/standby",
213 getNAV2AltFreq, setNAV2AltFreq);
214 current_properties.tieDouble("/radios/nav2/radials/actual",
216 current_properties.tieDouble("/radios/nav2/radials/selected",
217 getNAV2SelRadial, setNAV2SelRadial);
218 current_properties.tieDouble("/radios/nav2/dme/distance",
220 current_properties.tieBool("/radios/nav2/to-flag",
222 current_properties.tieBool("/radios/nav2/from-flag",
224 current_properties.tieBool("/radios/nav2/in-range",
226 current_properties.tieBool("/radios/nav2/dme/in-range",
227 getNAV2DMEInRange, 0);
229 current_properties.tieDouble("/radios/adf/frequencies/selected",
230 getADFFreq, setADFFreq);
231 current_properties.tieDouble("/radios/adf/frequencies/standby",
232 getADFAltFreq, setADFAltFreq);
233 current_properties.tieDouble("/radios/adf/rotation",
234 getADFRotation, setADFRotation);
236 current_properties.tieDouble("/environment/visibility",
237 getVisibility, setVisibility);
241 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
246 * Reinitialize FGFS if required.
248 * Some changes (especially those in aircraft position) require that
249 * FGFS be reinitialized afterwards. Rather than reinitialize after
250 * every change, the setter methods simply set a flag so that there
251 * can be a single reinit at the end of the frame.
263 * Reinitialize FGFS to use the new BFI settings.
268 // Save the state of everything
269 // that's going to get clobbered
270 // when we reinit the subsystems.
272 cout << "BFI: start reinit\n";
274 // TODO: add more AP stuff
275 double elevator = getElevator();
276 double aileron = getAileron();
277 double rudder = getRudder();
278 double throttle = getThrottle();
279 double elevator_trim = getElevatorTrim();
280 double flaps = getFlaps();
281 double brake = getBrakes();
282 bool apHeadingLock = getAPHeadingLock();
283 double apHeadingMag = getAPHeadingMag();
284 bool apAltitudeLock = getAPAltitudeLock();
285 double apAltitude = getAPAltitude();
286 const string &targetAirport = getTargetAirport();
287 bool gpsLock = getGPSLock();
288 double gpsLatitude = getGPSTargetLatitude();
289 double gpsLongitude = getGPSTargetLongitude();
291 setTargetAirport("");
292 cout << "Target airport is " << globals->get_options()->get_airport_id() << endl;
294 fgReInitSubsystems();
296 // FIXME: this is wrong.
297 // All of these are scheduled events,
298 // and it should be possible to force
299 // them all to run once.
302 cur_light_params.Update();
304 fgUpdateWeatherDatabase();
307 // Restore all of the old states.
308 setElevator(elevator);
311 setThrottle(throttle);
312 setElevatorTrim(elevator_trim);
315 setAPHeadingLock(apHeadingLock);
316 setAPHeadingMag(apHeadingMag);
317 setAPAltitudeLock(apAltitudeLock);
318 setAPAltitude(apAltitude);
319 setTargetAirport(targetAirport);
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 globals->get_options()->get_flight_model();
347 * Return the current aircraft as a string.
350 FGBFI::getAircraft ()
352 return globals->get_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 if (getFlightModel() != model) {
375 globals->get_options()->set_flight_model(model);
382 * Set the current aircraft.
385 FGBFI::setAircraft (const string &aircraft)
387 if (getAircraft() != aircraft) {
388 globals->get_options()->set_aircraft(aircraft);
395 * Set the current aircraft directory (UIUC).
398 FGBFI::setAircraftDir (const string &dir)
400 if (getAircraftDir() != dir) {
408 * Return the current Zulu time.
413 return globals->get_time_params()->get_cur_time();
418 * Set the current Zulu time.
421 FGBFI::setTimeGMT (time_t time)
423 if (getTimeGMT() != time) {
424 // FIXME: need to update lighting
426 globals->get_options()->set_time_offset(time);
427 globals->get_options()->set_time_offset_type(FGOptions::FG_TIME_GMT_ABSOLUTE);
428 globals->get_time_params()->update( cur_fdm_state->get_Longitude(),
429 cur_fdm_state->get_Latitude(),
430 globals->get_warp() );
437 * Return the GMT as a string.
440 FGBFI::getGMTString ()
442 static string out; // FIXME: not thread-safe
444 struct tm * t = globals->get_time_params()->getGmt();
445 sprintf(buf, " %.2d:%.2d:%.2d",
446 t->tm_hour, t->tm_min, t->tm_sec);
453 * Return true if the HUD is visible.
456 FGBFI::getHUDVisible ()
458 return globals->get_options()->get_hud_status();
463 * Ensure that the HUD is visible or hidden.
466 FGBFI::setHUDVisible (bool visible)
468 globals->get_options()->set_hud_status(visible);
473 * Return true if the 2D panel is visible.
476 FGBFI::getPanelVisible ()
478 return globals->get_options()->get_panel_status();
483 * Ensure that the 2D panel is visible or hidden.
486 FGBFI::setPanelVisible (bool visible)
488 if (globals->get_options()->get_panel_status() != visible) {
489 globals->get_options()->toggle_panel();
495 ////////////////////////////////////////////////////////////////////////
497 ////////////////////////////////////////////////////////////////////////
501 * Return the current latitude in degrees (negative for south).
504 FGBFI::getLatitude ()
506 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
511 * Set the current latitude in degrees (negative for south).
514 FGBFI::setLatitude (double latitude)
516 if (getLatitude() != latitude) {
517 globals->get_options()->set_lat(latitude);
518 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
525 * Return the current longitude in degrees (negative for west).
528 FGBFI::getLongitude ()
530 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
535 * Set the current longitude in degrees (negative for west).
538 FGBFI::setLongitude (double longitude)
540 if (getLongitude() != longitude) {
541 globals->get_options()->set_lon(longitude);
542 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
549 * Return the current altitude in feet.
552 FGBFI::getAltitude ()
554 return current_aircraft.fdm_state->get_Altitude();
560 * Return the current altitude in above the terrain.
565 return current_aircraft.fdm_state->get_Altitude()
566 - (scenery.cur_elev * METER_TO_FEET);
571 * Set the current altitude in feet.
574 FGBFI::setAltitude (double altitude)
576 if (getAltitude() != altitude) {
577 fgFDMForceAltitude(getFlightModel(), altitude);
578 globals->get_options()->set_altitude(altitude);
579 current_aircraft.fdm_state->set_Altitude(altitude);
585 ////////////////////////////////////////////////////////////////////////
587 ////////////////////////////////////////////////////////////////////////
591 * Return the current heading in degrees.
596 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
601 * Return the current heading in degrees.
604 FGBFI::getHeadingMag ()
606 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
611 * Set the current heading in degrees.
614 FGBFI::setHeading (double heading)
616 if (getHeading() != heading) {
617 globals->get_options()->set_heading(heading);
618 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
619 getPitch() * DEG_TO_RAD,
620 heading * DEG_TO_RAD);
627 * Return the current pitch in degrees.
632 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
637 * Set the current pitch in degrees.
640 FGBFI::setPitch (double pitch)
642 if (getPitch() != pitch) {
643 globals->get_options()->set_pitch(pitch);
644 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
646 getHeading() * DEG_TO_RAD);
653 * Return the current roll in degrees.
658 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
663 * Set the current roll in degrees.
666 FGBFI::setRoll (double roll)
668 if (getRoll() != roll) {
669 globals->get_options()->set_roll(roll);
670 current_aircraft.fdm_state->set_Euler_Angles(roll * DEG_TO_RAD,
671 getPitch() * DEG_TO_RAD,
672 getHeading() * DEG_TO_RAD);
679 * Return the current engine0 rpm
684 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
685 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
693 * Set the current engine0 rpm
696 FGBFI::setRPM (double rpm)
698 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
699 if (getRPM() != rpm) {
700 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
707 * Return the current engine0 EGT.
712 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
713 return current_aircraft.fdm_state->get_engine(0)->get_EGT();
719 * Return the current engine0 CHT.
724 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
725 return current_aircraft.fdm_state->get_engine(0)->get_CHT();
731 ////////////////////////////////////////////////////////////////////////
733 ////////////////////////////////////////////////////////////////////////
737 * Return the current airspeed in knots.
740 FGBFI::getAirspeed ()
742 // FIXME: should we add speed-up?
743 return current_aircraft.fdm_state->get_V_calibrated_kts();
748 * Return the current sideslip (FIXME: units unknown).
751 FGBFI::getSideSlip ()
753 return current_aircraft.fdm_state->get_Beta();
758 * Return the current climb rate in feet/minute
761 FGBFI::getVerticalSpeed ()
763 // What about meters?
764 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
769 * Get the current north velocity (units??).
772 FGBFI::getSpeedNorth ()
774 return current_aircraft.fdm_state->get_V_north();
779 * Set the current north velocity (units??).
782 FGBFI::setSpeedNorth (double speed)
784 if (getSpeedNorth() != speed) {
785 current_aircraft.fdm_state->set_Velocities_Local(speed,
794 * Get the current east velocity (units??).
797 FGBFI::getSpeedEast ()
799 return current_aircraft.fdm_state->get_V_east();
804 * Set the current east velocity (units??).
807 FGBFI::setSpeedEast (double speed)
809 if (getSpeedEast() != speed) {
810 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
819 * Get the current down velocity (units??).
822 FGBFI::getSpeedDown ()
824 return current_aircraft.fdm_state->get_V_down();
829 * Set the current down velocity (units??).
832 FGBFI::setSpeedDown (double speed)
834 if (getSpeedDown() != speed) {
835 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
844 ////////////////////////////////////////////////////////////////////////
846 ////////////////////////////////////////////////////////////////////////
850 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
853 FGBFI::getThrottle ()
855 // FIXME: add engine selector
856 return controls.get_throttle(0);
861 * Set the throttle, from 0.0 (none) to 1.0 (full).
864 FGBFI::setThrottle (double throttle)
866 // FIXME: allow engine selection
867 controls.set_throttle(0, throttle);
872 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
877 // FIXME: add engine selector
878 return controls.get_mixture(0);
883 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
886 FGBFI::setMixture (double mixture)
888 // FIXME: allow engine selection
889 controls.set_mixture(0, mixture);
894 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
897 FGBFI::getPropAdvance ()
899 // FIXME: add engine selector
900 return controls.get_prop_advance(0);
905 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
908 FGBFI::setPropAdvance (double pitch)
910 // FIXME: allow engine selection
911 controls.set_prop_advance(0, pitch);
916 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
921 return controls.get_flaps();
926 * Set the flaps, from 0.0 (none) to 1.0 (full).
929 FGBFI::setFlaps (double flaps)
932 controls.set_flaps(flaps);
937 * Get the aileron, from -1.0 (left) to 1.0 (right).
942 return controls.get_aileron();
947 * Set the aileron, from -1.0 (left) to 1.0 (right).
950 FGBFI::setAileron (double aileron)
953 controls.set_aileron(aileron);
958 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
963 return controls.get_rudder();
968 * Set the rudder, from -1.0 (left) to 1.0 (right).
971 FGBFI::setRudder (double rudder)
974 controls.set_rudder(rudder);
979 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
982 FGBFI::getElevator ()
984 return controls.get_elevator();
989 * Set the elevator, from -1.0 (down) to 1.0 (up).
992 FGBFI::setElevator (double elevator)
995 controls.set_elevator(elevator);
1000 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
1003 FGBFI::getElevatorTrim ()
1005 return controls.get_elevator_trim();
1010 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
1013 FGBFI::setElevatorTrim (double trim)
1016 controls.set_elevator_trim(trim);
1021 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1026 double b1 = getCenterBrake();
1027 double b2 = getLeftBrake();
1028 double b3 = getRightBrake();
1029 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1034 * Set all brakes, from 0.0 (none) to 1.0 (full).
1037 FGBFI::setBrakes (double brake)
1039 setCenterBrake(brake);
1040 setLeftBrake(brake);
1041 setRightBrake(brake);
1046 * Get the center brake, from 0.0 (none) to 1.0 (full).
1049 FGBFI::getCenterBrake ()
1051 return controls.get_brake(2);
1056 * Set the center brake, from 0.0 (none) to 1.0 (full).
1059 FGBFI::setCenterBrake (double brake)
1061 controls.set_brake(2, brake);
1066 * Get the left brake, from 0.0 (none) to 1.0 (full).
1069 FGBFI::getLeftBrake ()
1071 return controls.get_brake(0);
1076 * Set the left brake, from 0.0 (none) to 1.0 (full).
1079 FGBFI::setLeftBrake (double brake)
1081 controls.set_brake(0, brake);
1086 * Get the right brake, from 0.0 (none) to 1.0 (full).
1089 FGBFI::getRightBrake ()
1091 return controls.get_brake(1);
1096 * Set the right brake, from 0.0 (none) to 1.0 (full).
1099 FGBFI::setRightBrake (double brake)
1101 controls.set_brake(1, brake);
1108 ////////////////////////////////////////////////////////////////////////
1110 ////////////////////////////////////////////////////////////////////////
1114 * Get the autopilot altitude lock (true=on).
1117 FGBFI::getAPAltitudeLock ()
1119 return current_autopilot->get_AltitudeEnabled();
1124 * Set the autopilot altitude lock (true=on).
1127 FGBFI::setAPAltitudeLock (bool lock)
1129 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1130 current_autopilot->set_AltitudeEnabled(lock);
1135 * Get the autopilot target altitude in feet.
1138 FGBFI::getAPAltitude ()
1140 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1145 * Set the autopilot target altitude in feet.
1148 FGBFI::setAPAltitude (double altitude)
1150 current_autopilot->set_TargetAltitude( altitude );
1155 * Get the autopilot heading lock (true=on).
1158 FGBFI::getAPHeadingLock ()
1161 (current_autopilot->get_HeadingEnabled() &&
1162 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1167 * Set the autopilot heading lock (true=on).
1170 FGBFI::setAPHeadingLock (bool lock)
1173 // We need to do this so that
1174 // it's possible to lock onto a
1175 // heading other than the current
1177 double heading = getAPHeadingMag();
1178 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1179 current_autopilot->set_HeadingEnabled(true);
1180 setAPHeadingMag(heading);
1181 } else if (current_autopilot->get_HeadingMode() ==
1182 FGAutopilot::FG_HEADING_LOCK) {
1183 current_autopilot->set_HeadingEnabled(false);
1189 * Get the autopilot target heading in degrees.
1192 FGBFI::getAPHeading ()
1194 return current_autopilot->get_TargetHeading();
1199 * Set the autopilot target heading in degrees.
1202 FGBFI::setAPHeading (double heading)
1204 current_autopilot->set_TargetHeading( heading );
1209 * Get the autopilot target heading in degrees.
1212 FGBFI::getAPHeadingMag ()
1214 return current_autopilot->get_TargetHeading() - getMagVar();
1219 * Set the autopilot target heading in degrees.
1222 FGBFI::setAPHeadingMag (double heading)
1224 current_autopilot->set_TargetHeading( heading + getMagVar() );
1229 * Return true if the autopilot is locked to NAV1.
1232 FGBFI::getAPNAV1Lock ()
1235 (current_autopilot->get_HeadingEnabled() &&
1236 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1241 * Set the autopilot NAV1 lock.
1244 FGBFI::setAPNAV1Lock (bool lock)
1247 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1248 current_autopilot->set_HeadingEnabled(true);
1249 } else if (current_autopilot->get_HeadingMode() ==
1250 FGAutopilot::FG_HEADING_NAV1) {
1251 current_autopilot->set_HeadingEnabled(false);
1257 ////////////////////////////////////////////////////////////////////////
1258 // Radio navigation.
1259 ////////////////////////////////////////////////////////////////////////
1262 FGBFI::getNAV1Freq ()
1264 return current_radiostack->get_nav1_freq();
1268 FGBFI::getNAV1AltFreq ()
1270 return current_radiostack->get_nav1_alt_freq();
1274 FGBFI::getNAV1Radial ()
1276 return current_radiostack->get_nav1_radial();
1280 FGBFI::getNAV1SelRadial ()
1282 return current_radiostack->get_nav1_sel_radial();
1286 FGBFI::getNAV1DistDME ()
1288 return current_radiostack->get_nav1_dme_dist();
1294 if (current_radiostack->get_nav1_inrange()) {
1295 double heading = current_radiostack->get_nav1_heading();
1296 double radial = current_radiostack->get_nav1_radial();
1297 double var = FGBFI::getMagVar();
1298 if (current_radiostack->get_nav1_loc()) {
1299 double offset = fabs(heading - radial);
1300 return (offset<= 8.0 || offset >= 352.0);
1303 fabs(heading - var - radial);
1304 return (offset <= 20.0 || offset >= 340.0);
1312 FGBFI::getNAV1FROM ()
1314 if (current_radiostack->get_nav1_inrange()) {
1315 double heading = current_radiostack->get_nav1_heading();
1316 double radial = current_radiostack->get_nav1_radial();
1317 double var = FGBFI::getMagVar();
1318 if (current_radiostack->get_nav1_loc()) {
1319 double offset = fabs(heading - radial);
1320 return (offset >= 172.0 && offset<= 188.0);
1323 fabs(heading - var - radial);
1324 return (offset >= 160.0 && offset <= 200.0);
1332 FGBFI::getNAV1InRange ()
1334 return current_radiostack->get_nav1_inrange();
1338 FGBFI::getNAV1DMEInRange ()
1340 return (current_radiostack->get_nav1_inrange() &&
1341 current_radiostack->get_nav1_has_dme());
1345 FGBFI::getNAV2Freq ()
1347 return current_radiostack->get_nav2_freq();
1351 FGBFI::getNAV2AltFreq ()
1353 return current_radiostack->get_nav2_alt_freq();
1357 FGBFI::getNAV2Radial ()
1359 return current_radiostack->get_nav2_radial();
1363 FGBFI::getNAV2SelRadial ()
1365 return current_radiostack->get_nav2_sel_radial();
1369 FGBFI::getNAV2DistDME ()
1371 return current_radiostack->get_nav2_dme_dist();
1377 if (current_radiostack->get_nav2_inrange()) {
1378 double heading = current_radiostack->get_nav2_heading();
1379 double radial = current_radiostack->get_nav2_radial();
1380 double var = FGBFI::getMagVar();
1381 if (current_radiostack->get_nav2_loc()) {
1382 double offset = fabs(heading - radial);
1383 return (offset<= 8.0 || offset >= 352.0);
1386 fabs(heading - var - radial);
1387 return (offset <= 20.0 || offset >= 340.0);
1395 FGBFI::getNAV2FROM ()
1397 if (current_radiostack->get_nav2_inrange()) {
1398 double heading = current_radiostack->get_nav2_heading();
1399 double radial = current_radiostack->get_nav2_radial();
1400 double var = FGBFI::getMagVar();
1401 if (current_radiostack->get_nav2_loc()) {
1402 double offset = fabs(heading - radial);
1403 return (offset >= 172.0 && offset<= 188.0);
1406 fabs(heading - var - radial);
1407 return (offset >= 160.0 && offset <= 200.0);
1416 FGBFI::getNAV2InRange ()
1418 return current_radiostack->get_nav2_inrange();
1422 FGBFI::getNAV2DMEInRange ()
1424 return (current_radiostack->get_nav2_inrange() &&
1425 current_radiostack->get_nav2_has_dme());
1429 FGBFI::getADFFreq ()
1431 return current_radiostack->get_adf_freq();
1435 FGBFI::getADFAltFreq ()
1437 return current_radiostack->get_adf_alt_freq();
1441 FGBFI::getADFRotation ()
1443 return current_radiostack->get_adf_rotation();
1447 FGBFI::setNAV1Freq (double freq)
1449 current_radiostack->set_nav1_freq(freq);
1453 FGBFI::setNAV1AltFreq (double freq)
1455 current_radiostack->set_nav1_alt_freq(freq);
1459 FGBFI::setNAV1SelRadial (double radial)
1461 current_radiostack->set_nav1_sel_radial(radial);
1465 FGBFI::setNAV2Freq (double freq)
1467 current_radiostack->set_nav2_freq(freq);
1471 FGBFI::setNAV2AltFreq (double freq)
1473 current_radiostack->set_nav2_alt_freq(freq);
1477 FGBFI::setNAV2SelRadial (double radial)
1479 current_radiostack->set_nav2_sel_radial(radial);
1483 FGBFI::setADFFreq (double freq)
1485 current_radiostack->set_adf_freq(freq);
1489 FGBFI::setADFAltFreq (double freq)
1491 current_radiostack->set_adf_alt_freq(freq);
1495 FGBFI::setADFRotation (double rot)
1497 current_radiostack->set_adf_rotation(rot);
1502 ////////////////////////////////////////////////////////////////////////
1504 ////////////////////////////////////////////////////////////////////////
1508 * Get the autopilot GPS lock (true=on).
1511 FGBFI::getGPSLock ()
1513 return (current_autopilot->get_HeadingEnabled() &&
1514 (current_autopilot->get_HeadingMode() ==
1515 FGAutopilot::FG_HEADING_WAYPOINT ));
1520 * Set the autopilot GPS lock (true=on).
1523 FGBFI::setGPSLock (bool lock)
1526 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1527 current_autopilot->set_HeadingEnabled(true);
1528 } else if (current_autopilot->get_HeadingMode() ==
1529 FGAutopilot::FG_HEADING_WAYPOINT) {
1530 current_autopilot->set_HeadingEnabled(false);
1536 * Get the GPS target airport code.
1539 FGBFI::getTargetAirport ()
1541 // FIXME: not thread-safe
1543 out = globals->get_options()->get_airport_id();
1550 * Set the GPS target airport code.
1553 FGBFI::setTargetAirport (const string &airportId)
1555 // cout << "setting target airport id = " << airportId << endl;
1556 globals->get_options()->set_airport_id(airportId);
1561 * Get the GPS target latitude in degrees (negative for south).
1564 FGBFI::getGPSTargetLatitude ()
1566 return current_autopilot->get_TargetLatitude();
1571 * Get the GPS target longitude in degrees (negative for west).
1574 FGBFI::getGPSTargetLongitude ()
1576 return current_autopilot->get_TargetLongitude();
1581 * Set the GPS target longitude in degrees (negative for west).
1584 FGBFI::setGPSTargetLongitude (double longitude)
1586 current_autopilot->set_TargetLongitude( longitude );
1592 ////////////////////////////////////////////////////////////////////////
1594 ////////////////////////////////////////////////////////////////////////
1598 * Get the current visible (units??).
1601 FGBFI::getVisibility ()
1603 #ifndef FG_OLD_WEATHER
1604 return WeatherDatabase->getWeatherVisibility();
1606 return current_weather.get_visibility();
1612 * Check whether clouds are enabled.
1617 return globals->get_options()->get_clouds();
1622 * Check the height of the clouds ASL (units?).
1625 FGBFI::getCloudsASL ()
1627 return globals->get_options()->get_clouds_asl();
1632 * Set the current visibility (units??).
1635 FGBFI::setVisibility (double visibility)
1637 #ifndef FG_OLD_WEATHER
1638 WeatherDatabase->setWeatherVisibility(visibility);
1640 current_weather.set_visibility(visibility);
1646 * Switch clouds on or off.
1649 FGBFI::setClouds (bool clouds)
1651 if (getClouds() != clouds) {
1652 cout << "Set clouds to " << clouds << endl;
1653 globals->get_options()->set_clouds(clouds);
1660 * Set the cloud height.
1663 FGBFI::setCloudsASL (double cloudsASL)
1665 if (getCloudsASL() != cloudsASL) {
1666 globals->get_options()->set_clouds_asl(cloudsASL);
1673 ////////////////////////////////////////////////////////////////////////
1675 ////////////////////////////////////////////////////////////////////////
1678 * Return the magnetic variation
1683 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1688 * Return the magnetic variation
1693 return globals->get_mag()->get_magdip() * RAD_TO_DEG;