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 getAltitude, setAltitude, false);
116 current_properties.tieDouble("/position/altitude-agl",
120 current_properties.tieDouble("/orientation/heading",
121 getHeading, setHeading);
122 current_properties.tieDouble("/orientation/heading-magnetic",
124 current_properties.tieDouble("/orientation/pitch",
126 current_properties.tieDouble("/orientation/roll",
130 current_properties.tieDouble("/engines/engine0/rpm",
132 current_properties.tieDouble("/engines/engine0/egt",
136 current_properties.tieDouble("/velocities/airspeed",
138 current_properties.tieDouble("/velocities/side-slip",
140 current_properties.tieDouble("/velocities/vertical-speed",
141 getVerticalSpeed, 0);
142 current_properties.tieDouble("/velocities/speed-north",
143 getSpeedNorth, setSpeedNorth);
144 current_properties.tieDouble("/velocities/speed-east",
145 getSpeedEast, setSpeedEast);
146 current_properties.tieDouble("/velocities/speed-down",
147 getSpeedDown, setSpeedDown);
150 current_properties.tieDouble("/controls/throttle",
151 getThrottle, setThrottle);
152 current_properties.tieDouble("/controls/mixture",
153 getMixture, setMixture);
154 current_properties.tieDouble("/controls/propellor-pitch",
155 getPropAdvance, setPropAdvance);
156 current_properties.tieDouble("/controls/flaps",
158 current_properties.tieDouble("/controls/aileron",
159 getAileron, setAileron);
160 current_properties.tieDouble("/controls/rudder",
161 getRudder, setRudder);
162 current_properties.tieDouble("/controls/elevator",
163 getElevator, setElevator);
164 current_properties.tieDouble("/controls/elevator-trim",
165 getElevatorTrim, setElevatorTrim);
166 current_properties.tieDouble("/controls/brakes/all",
167 getBrakes, setBrakes);
168 current_properties.tieDouble("/controls/brakes/left",
169 getLeftBrake, setLeftBrake);
170 current_properties.tieDouble("/controls/brakes/right",
171 getRightBrake, setRightBrake);
172 current_properties.tieDouble("/controls/brakes/center",
173 getRightBrake, setCenterBrake);
176 current_properties.tieBool("/autopilot/locks/altitude",
177 getAPAltitudeLock, setAPAltitudeLock);
178 current_properties.tieDouble("/autopilot/settings/altitude",
179 getAPAltitude, setAPAltitude);
180 current_properties.tieBool("/autopilot/locks/heading",
181 getAPHeadingLock, setAPHeadingLock);
182 current_properties.tieDouble("/autopilot/settings/heading",
183 getAPHeading, setAPHeading);
184 current_properties.tieDouble("/autopilot/settings/heading-magnetic",
185 getAPHeadingMag, setAPHeadingMag);
186 current_properties.tieBool("/autopilot/locks/nav1",
187 getAPNAV1Lock, setAPNAV1Lock);
190 current_properties.tieDouble("/radios/nav1/frequencies/selected",
191 getNAV1Freq, setNAV1Freq);
192 current_properties.tieDouble("/radios/nav1/frequencies/standby",
193 getNAV1AltFreq, setNAV1AltFreq);
194 current_properties.tieDouble("/radios/nav1/radials/actual",
196 current_properties.tieDouble("/radios/nav1/radials/selected",
197 getNAV1SelRadial, setNAV1SelRadial);
198 current_properties.tieDouble("/radios/nav1/dme/distance",
200 current_properties.tieBool("/radios/nav1/to-flag",
202 current_properties.tieBool("/radios/nav1/from-flag",
204 current_properties.tieBool("/radios/nav1/in-range",
206 current_properties.tieBool("/radios/nav1/dme/in-range",
207 getNAV1DMEInRange, 0);
209 current_properties.tieDouble("/radios/nav2/frequencies/selected",
210 getNAV2Freq, setNAV2Freq);
211 current_properties.tieDouble("/radios/nav2/frequencies/standby",
212 getNAV2AltFreq, setNAV2AltFreq);
213 current_properties.tieDouble("/radios/nav2/radials/actual",
215 current_properties.tieDouble("/radios/nav2/radials/selected",
216 getNAV2SelRadial, setNAV2SelRadial);
217 current_properties.tieDouble("/radios/nav2/dme/distance",
219 current_properties.tieBool("/radios/nav2/to-flag",
221 current_properties.tieBool("/radios/nav2/from-flag",
223 current_properties.tieBool("/radios/nav2/in-range",
225 current_properties.tieBool("/radios/nav2/dme/in-range",
226 getNAV2DMEInRange, 0);
228 current_properties.tieDouble("/radios/adf/frequencies/selected",
229 getADFFreq, setADFFreq);
230 current_properties.tieDouble("/radios/adf/frequencies/standby",
231 getADFAltFreq, setADFAltFreq);
232 current_properties.tieDouble("/radios/adf/rotation",
233 getADFRotation, setADFRotation);
235 current_properties.tieDouble("/environment/visibility",
236 getVisibility, setVisibility);
240 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
245 * Reinitialize FGFS if required.
247 * Some changes (especially those in aircraft position) require that
248 * FGFS be reinitialized afterwards. Rather than reinitialize after
249 * every change, the setter methods simply set a flag so that there
250 * can be a single reinit at the end of the frame.
262 * Reinitialize FGFS to use the new BFI settings.
267 // Save the state of everything
268 // that's going to get clobbered
269 // when we reinit the subsystems.
271 cout << "BFI: start reinit\n";
273 // TODO: add more AP stuff
274 double elevator = getElevator();
275 double aileron = getAileron();
276 double rudder = getRudder();
277 double throttle = getThrottle();
278 double elevator_trim = getElevatorTrim();
279 double flaps = getFlaps();
280 double brake = getBrakes();
281 bool apHeadingLock = getAPHeadingLock();
282 double apHeadingMag = getAPHeadingMag();
283 bool apAltitudeLock = getAPAltitudeLock();
284 double apAltitude = getAPAltitude();
285 const string &targetAirport = getTargetAirport();
286 bool gpsLock = getGPSLock();
287 double gpsLatitude = getGPSTargetLatitude();
288 double gpsLongitude = getGPSTargetLongitude();
290 setTargetAirport("");
291 cout << "Target airport is " << current_options.get_airport_id() << endl;
293 fgReInitSubsystems();
295 // FIXME: this is wrong.
296 // All of these are scheduled events,
297 // and it should be possible to force
298 // them all to run once.
301 cur_light_params.Update();
303 fgUpdateWeatherDatabase();
306 // Restore all of the old states.
307 setElevator(elevator);
310 setThrottle(throttle);
311 setElevatorTrim(elevator_trim);
314 setAPHeadingLock(apHeadingLock);
315 setAPHeadingMag(apHeadingMag);
316 setAPAltitudeLock(apAltitudeLock);
317 setAPAltitude(apAltitude);
318 setTargetAirport(targetAirport);
323 cout << "BFI: end reinit\n";
328 ////////////////////////////////////////////////////////////////////////
330 ////////////////////////////////////////////////////////////////////////
334 * Return the flight model as an integer.
336 * TODO: use a string instead.
339 FGBFI::getFlightModel ()
341 return current_options.get_flight_model();
346 * Return the current aircraft as a string.
349 FGBFI::getAircraft ()
351 return current_options.get_aircraft();
356 * Return the current aircraft directory (UIUC) as a string.
359 FGBFI::getAircraftDir ()
366 * Set the flight model as an integer.
368 * TODO: use a string instead.
371 FGBFI::setFlightModel (int model)
373 if (getFlightModel() != model) {
374 current_options.set_flight_model(model);
381 * Set the current aircraft.
384 FGBFI::setAircraft (const string &aircraft)
386 if (getAircraft() != aircraft) {
387 current_options.set_aircraft(aircraft);
394 * Set the current aircraft directory (UIUC).
397 FGBFI::setAircraftDir (const string &dir)
399 if (getAircraftDir() != dir) {
407 * Return the current Zulu time.
412 return globals->get_time_params()->get_cur_time();
417 * Set the current Zulu time.
420 FGBFI::setTimeGMT (time_t time)
422 if (getTimeGMT() != time) {
423 // FIXME: need to update lighting
425 current_options.set_time_offset(time);
426 current_options.set_time_offset_type(fgOPTIONS::FG_TIME_GMT_ABSOLUTE);
427 globals->get_time_params()->update( cur_fdm_state->get_Longitude(),
428 cur_fdm_state->get_Latitude(),
429 globals->get_warp() );
436 * Return the GMT as a string.
439 FGBFI::getGMTString ()
441 static string out; // FIXME: not thread-safe
443 struct tm * t = globals->get_time_params()->getGmt();
444 sprintf(buf, " %.2d:%.2d:%.2d",
445 t->tm_hour, t->tm_min, t->tm_sec);
452 * Return true if the HUD is visible.
455 FGBFI::getHUDVisible ()
457 return current_options.get_hud_status();
462 * Ensure that the HUD is visible or hidden.
465 FGBFI::setHUDVisible (bool visible)
467 current_options.set_hud_status(visible);
472 * Return true if the 2D panel is visible.
475 FGBFI::getPanelVisible ()
477 return current_options.get_panel_status();
482 * Ensure that the 2D panel is visible or hidden.
485 FGBFI::setPanelVisible (bool visible)
487 if (current_options.get_panel_status() != visible) {
488 current_options.toggle_panel();
494 ////////////////////////////////////////////////////////////////////////
496 ////////////////////////////////////////////////////////////////////////
500 * Return the current latitude in degrees (negative for south).
503 FGBFI::getLatitude ()
505 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
510 * Set the current latitude in degrees (negative for south).
513 FGBFI::setLatitude (double latitude)
515 if (getLatitude() != latitude) {
516 current_options.set_lat(latitude);
517 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
524 * Return the current longitude in degrees (negative for west).
527 FGBFI::getLongitude ()
529 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
534 * Set the current longitude in degrees (negative for west).
537 FGBFI::setLongitude (double longitude)
539 if (getLongitude() != longitude) {
540 current_options.set_lon(longitude);
541 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
548 * Return the current altitude in feet.
551 FGBFI::getAltitude ()
553 return current_aircraft.fdm_state->get_Altitude();
559 * Return the current altitude in above the terrain.
564 return current_aircraft.fdm_state->get_Altitude()
565 - (scenery.cur_elev * METER_TO_FEET);
570 * Set the current altitude in feet.
573 FGBFI::setAltitude (double altitude)
575 if (getAltitude() != altitude) {
576 fgFDMForceAltitude(getFlightModel(), altitude);
577 current_options.set_altitude(altitude);
578 current_aircraft.fdm_state->set_Altitude(altitude);
584 ////////////////////////////////////////////////////////////////////////
586 ////////////////////////////////////////////////////////////////////////
590 * Return the current heading in degrees.
595 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
600 * Return the current heading in degrees.
603 FGBFI::getHeadingMag ()
605 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
610 * Set the current heading in degrees.
613 FGBFI::setHeading (double heading)
615 if (getHeading() != heading) {
616 current_options.set_heading(heading);
617 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
618 getPitch() * DEG_TO_RAD,
619 heading * DEG_TO_RAD);
626 * Return the current pitch in degrees.
631 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
636 * Set the current pitch in degrees.
639 FGBFI::setPitch (double pitch)
641 if (getPitch() != pitch) {
642 current_options.set_pitch(pitch);
643 current_aircraft.fdm_state->set_Euler_Angles(getRoll() * DEG_TO_RAD,
645 getHeading() * DEG_TO_RAD);
652 * Return the current roll in degrees.
657 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
662 * Set the current roll in degrees.
665 FGBFI::setRoll (double roll)
667 if (getRoll() != roll) {
668 current_options.set_roll(roll);
669 current_aircraft.fdm_state->set_Euler_Angles(roll * DEG_TO_RAD,
670 getPitch() * DEG_TO_RAD,
671 getHeading() * DEG_TO_RAD);
678 * Return the current engine0 rpm
683 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
684 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
692 * Set the current engine0 rpm
695 FGBFI::setRPM (double rpm)
697 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
698 if (getRPM() != rpm) {
699 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
706 * Return the current engine0 EGT.
711 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
712 return current_aircraft.fdm_state->get_engine(0)->get_EGT();
718 ////////////////////////////////////////////////////////////////////////
720 ////////////////////////////////////////////////////////////////////////
724 * Return the current airspeed in knots.
727 FGBFI::getAirspeed ()
729 // FIXME: should we add speed-up?
730 return current_aircraft.fdm_state->get_V_calibrated_kts();
735 * Return the current sideslip (FIXME: units unknown).
738 FGBFI::getSideSlip ()
740 return current_aircraft.fdm_state->get_Beta();
745 * Return the current climb rate in feet/minute
748 FGBFI::getVerticalSpeed ()
750 // What about meters?
751 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
756 * Get the current north velocity (units??).
759 FGBFI::getSpeedNorth ()
761 return current_aircraft.fdm_state->get_V_north();
766 * Set the current north velocity (units??).
769 FGBFI::setSpeedNorth (double speed)
771 if (getSpeedNorth() != speed) {
772 current_options.set_uBody(speed);
773 current_aircraft.fdm_state->set_Velocities_Local(speed,
782 * Get the current east velocity (units??).
785 FGBFI::getSpeedEast ()
787 return current_aircraft.fdm_state->get_V_east();
792 * Set the current east velocity (units??).
795 FGBFI::setSpeedEast (double speed)
797 if (getSpeedEast() != speed) {
798 current_options.set_vBody(speed);
799 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
808 * Get the current down velocity (units??).
811 FGBFI::getSpeedDown ()
813 return current_aircraft.fdm_state->get_V_down();
818 * Set the current down velocity (units??).
821 FGBFI::setSpeedDown (double speed)
823 if (getSpeedDown() != speed) {
824 current_options.set_wBody(speed);
825 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
834 ////////////////////////////////////////////////////////////////////////
836 ////////////////////////////////////////////////////////////////////////
840 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
843 FGBFI::getThrottle ()
845 // FIXME: add engine selector
846 return controls.get_throttle(0);
851 * Set the throttle, from 0.0 (none) to 1.0 (full).
854 FGBFI::setThrottle (double throttle)
856 // FIXME: allow engine selection
857 controls.set_throttle(0, throttle);
862 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
867 // FIXME: add engine selector
868 return controls.get_mixture(0);
873 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
876 FGBFI::setMixture (double mixture)
878 // FIXME: allow engine selection
879 controls.set_mixture(0, mixture);
884 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
887 FGBFI::getPropAdvance ()
889 // FIXME: add engine selector
890 return controls.get_prop_advance(0);
895 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
898 FGBFI::setPropAdvance (double pitch)
900 // FIXME: allow engine selection
901 controls.set_prop_advance(0, pitch);
906 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
911 return controls.get_flaps();
916 * Set the flaps, from 0.0 (none) to 1.0 (full).
919 FGBFI::setFlaps (double flaps)
922 controls.set_flaps(flaps);
927 * Get the aileron, from -1.0 (left) to 1.0 (right).
932 return controls.get_aileron();
937 * Set the aileron, from -1.0 (left) to 1.0 (right).
940 FGBFI::setAileron (double aileron)
943 controls.set_aileron(aileron);
948 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
953 return controls.get_rudder();
958 * Set the rudder, from -1.0 (left) to 1.0 (right).
961 FGBFI::setRudder (double rudder)
964 controls.set_rudder(rudder);
969 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
972 FGBFI::getElevator ()
974 return controls.get_elevator();
979 * Set the elevator, from -1.0 (down) to 1.0 (up).
982 FGBFI::setElevator (double elevator)
985 controls.set_elevator(elevator);
990 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
993 FGBFI::getElevatorTrim ()
995 return controls.get_elevator_trim();
1000 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
1003 FGBFI::setElevatorTrim (double trim)
1006 controls.set_elevator_trim(trim);
1011 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1016 double b1 = getCenterBrake();
1017 double b2 = getLeftBrake();
1018 double b3 = getRightBrake();
1019 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1024 * Set all brakes, from 0.0 (none) to 1.0 (full).
1027 FGBFI::setBrakes (double brake)
1029 setCenterBrake(brake);
1030 setLeftBrake(brake);
1031 setRightBrake(brake);
1036 * Get the center brake, from 0.0 (none) to 1.0 (full).
1039 FGBFI::getCenterBrake ()
1041 return controls.get_brake(2);
1046 * Set the center brake, from 0.0 (none) to 1.0 (full).
1049 FGBFI::setCenterBrake (double brake)
1051 controls.set_brake(2, brake);
1056 * Get the left brake, from 0.0 (none) to 1.0 (full).
1059 FGBFI::getLeftBrake ()
1061 return controls.get_brake(0);
1066 * Set the left brake, from 0.0 (none) to 1.0 (full).
1069 FGBFI::setLeftBrake (double brake)
1071 controls.set_brake(0, brake);
1076 * Get the right brake, from 0.0 (none) to 1.0 (full).
1079 FGBFI::getRightBrake ()
1081 return controls.get_brake(1);
1086 * Set the right brake, from 0.0 (none) to 1.0 (full).
1089 FGBFI::setRightBrake (double brake)
1091 controls.set_brake(1, brake);
1098 ////////////////////////////////////////////////////////////////////////
1100 ////////////////////////////////////////////////////////////////////////
1104 * Get the autopilot altitude lock (true=on).
1107 FGBFI::getAPAltitudeLock ()
1109 return current_autopilot->get_AltitudeEnabled();
1114 * Set the autopilot altitude lock (true=on).
1117 FGBFI::setAPAltitudeLock (bool lock)
1119 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1120 current_autopilot->set_AltitudeEnabled(lock);
1125 * Get the autopilot target altitude in feet.
1128 FGBFI::getAPAltitude ()
1130 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1135 * Set the autopilot target altitude in feet.
1138 FGBFI::setAPAltitude (double altitude)
1140 current_autopilot->set_TargetAltitude( altitude );
1145 * Get the autopilot heading lock (true=on).
1148 FGBFI::getAPHeadingLock ()
1151 (current_autopilot->get_HeadingEnabled() &&
1152 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1157 * Set the autopilot heading lock (true=on).
1160 FGBFI::setAPHeadingLock (bool lock)
1163 // We need to do this so that
1164 // it's possible to lock onto a
1165 // heading other than the current
1167 double heading = getAPHeadingMag();
1168 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1169 current_autopilot->set_HeadingEnabled(true);
1170 setAPHeadingMag(heading);
1171 } else if (current_autopilot->get_HeadingMode() ==
1172 FGAutopilot::FG_HEADING_LOCK) {
1173 current_autopilot->set_HeadingEnabled(false);
1179 * Get the autopilot target heading in degrees.
1182 FGBFI::getAPHeading ()
1184 return current_autopilot->get_TargetHeading();
1189 * Set the autopilot target heading in degrees.
1192 FGBFI::setAPHeading (double heading)
1194 current_autopilot->set_TargetHeading( heading );
1199 * Get the autopilot target heading in degrees.
1202 FGBFI::getAPHeadingMag ()
1204 return current_autopilot->get_TargetHeading() - getMagVar();
1209 * Set the autopilot target heading in degrees.
1212 FGBFI::setAPHeadingMag (double heading)
1214 current_autopilot->set_TargetHeading( heading + getMagVar() );
1219 * Return true if the autopilot is locked to NAV1.
1222 FGBFI::getAPNAV1Lock ()
1225 (current_autopilot->get_HeadingEnabled() &&
1226 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1231 * Set the autopilot NAV1 lock.
1234 FGBFI::setAPNAV1Lock (bool lock)
1237 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1238 current_autopilot->set_HeadingEnabled(true);
1239 } else if (current_autopilot->get_HeadingMode() ==
1240 FGAutopilot::FG_HEADING_NAV1) {
1241 current_autopilot->set_HeadingEnabled(false);
1247 ////////////////////////////////////////////////////////////////////////
1248 // Radio navigation.
1249 ////////////////////////////////////////////////////////////////////////
1252 FGBFI::getNAV1Freq ()
1254 return current_radiostack->get_nav1_freq();
1258 FGBFI::getNAV1AltFreq ()
1260 return current_radiostack->get_nav1_alt_freq();
1264 FGBFI::getNAV1Radial ()
1266 return current_radiostack->get_nav1_radial();
1270 FGBFI::getNAV1SelRadial ()
1272 return current_radiostack->get_nav1_sel_radial();
1276 FGBFI::getNAV1DistDME ()
1278 return current_radiostack->get_nav1_dme_dist();
1284 if (current_radiostack->get_nav1_inrange()) {
1285 double heading = current_radiostack->get_nav1_heading();
1286 double radial = current_radiostack->get_nav1_radial();
1287 double var = FGBFI::getMagVar();
1288 if (current_radiostack->get_nav1_loc()) {
1289 double offset = fabs(heading - radial);
1290 return (offset<= 8.0 || offset >= 352.0);
1293 fabs(heading - var - radial);
1294 return (offset <= 20.0 || offset >= 340.0);
1302 FGBFI::getNAV1FROM ()
1304 if (current_radiostack->get_nav1_inrange()) {
1305 double heading = current_radiostack->get_nav1_heading();
1306 double radial = current_radiostack->get_nav1_radial();
1307 double var = FGBFI::getMagVar();
1308 if (current_radiostack->get_nav1_loc()) {
1309 double offset = fabs(heading - radial);
1310 return (offset >= 172.0 && offset<= 188.0);
1313 fabs(heading - var - radial);
1314 return (offset >= 160.0 && offset <= 200.0);
1322 FGBFI::getNAV1InRange ()
1324 return current_radiostack->get_nav1_inrange();
1328 FGBFI::getNAV1DMEInRange ()
1330 return (current_radiostack->get_nav1_inrange() &&
1331 current_radiostack->get_nav1_has_dme());
1335 FGBFI::getNAV2Freq ()
1337 return current_radiostack->get_nav2_freq();
1341 FGBFI::getNAV2AltFreq ()
1343 return current_radiostack->get_nav2_alt_freq();
1347 FGBFI::getNAV2Radial ()
1349 return current_radiostack->get_nav2_radial();
1353 FGBFI::getNAV2SelRadial ()
1355 return current_radiostack->get_nav2_sel_radial();
1359 FGBFI::getNAV2DistDME ()
1361 return current_radiostack->get_nav2_dme_dist();
1367 if (current_radiostack->get_nav2_inrange()) {
1368 double heading = current_radiostack->get_nav2_heading();
1369 double radial = current_radiostack->get_nav2_radial();
1370 double var = FGBFI::getMagVar();
1371 if (current_radiostack->get_nav2_loc()) {
1372 double offset = fabs(heading - radial);
1373 return (offset<= 8.0 || offset >= 352.0);
1376 fabs(heading - var - radial);
1377 return (offset <= 20.0 || offset >= 340.0);
1385 FGBFI::getNAV2FROM ()
1387 if (current_radiostack->get_nav2_inrange()) {
1388 double heading = current_radiostack->get_nav2_heading();
1389 double radial = current_radiostack->get_nav2_radial();
1390 double var = FGBFI::getMagVar();
1391 if (current_radiostack->get_nav2_loc()) {
1392 double offset = fabs(heading - radial);
1393 return (offset >= 172.0 && offset<= 188.0);
1396 fabs(heading - var - radial);
1397 return (offset >= 160.0 && offset <= 200.0);
1406 FGBFI::getNAV2InRange ()
1408 return current_radiostack->get_nav2_inrange();
1412 FGBFI::getNAV2DMEInRange ()
1414 return (current_radiostack->get_nav2_inrange() &&
1415 current_radiostack->get_nav2_has_dme());
1419 FGBFI::getADFFreq ()
1421 return current_radiostack->get_adf_freq();
1425 FGBFI::getADFAltFreq ()
1427 return current_radiostack->get_adf_alt_freq();
1431 FGBFI::getADFRotation ()
1433 return current_radiostack->get_adf_rotation();
1437 FGBFI::setNAV1Freq (double freq)
1439 current_radiostack->set_nav1_freq(freq);
1443 FGBFI::setNAV1AltFreq (double freq)
1445 current_radiostack->set_nav1_alt_freq(freq);
1449 FGBFI::setNAV1SelRadial (double radial)
1451 current_radiostack->set_nav1_sel_radial(radial);
1455 FGBFI::setNAV2Freq (double freq)
1457 current_radiostack->set_nav2_freq(freq);
1461 FGBFI::setNAV2AltFreq (double freq)
1463 current_radiostack->set_nav2_alt_freq(freq);
1467 FGBFI::setNAV2SelRadial (double radial)
1469 current_radiostack->set_nav2_sel_radial(radial);
1473 FGBFI::setADFFreq (double freq)
1475 current_radiostack->set_adf_freq(freq);
1479 FGBFI::setADFAltFreq (double freq)
1481 current_radiostack->set_adf_alt_freq(freq);
1485 FGBFI::setADFRotation (double rot)
1487 current_radiostack->set_adf_rotation(rot);
1492 ////////////////////////////////////////////////////////////////////////
1494 ////////////////////////////////////////////////////////////////////////
1498 * Get the autopilot GPS lock (true=on).
1501 FGBFI::getGPSLock ()
1503 return (current_autopilot->get_HeadingEnabled() &&
1504 (current_autopilot->get_HeadingMode() ==
1505 FGAutopilot::FG_HEADING_WAYPOINT ));
1510 * Set the autopilot GPS lock (true=on).
1513 FGBFI::setGPSLock (bool lock)
1516 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1517 current_autopilot->set_HeadingEnabled(true);
1518 } else if (current_autopilot->get_HeadingMode() ==
1519 FGAutopilot::FG_HEADING_WAYPOINT) {
1520 current_autopilot->set_HeadingEnabled(false);
1526 * Get the GPS target airport code.
1529 FGBFI::getTargetAirport ()
1531 // FIXME: not thread-safe
1533 out = current_options.get_airport_id();
1540 * Set the GPS target airport code.
1543 FGBFI::setTargetAirport (const string &airportId)
1545 // cout << "setting target airport id = " << airportId << endl;
1546 current_options.set_airport_id(airportId);
1551 * Get the GPS target latitude in degrees (negative for south).
1554 FGBFI::getGPSTargetLatitude ()
1556 return current_autopilot->get_TargetLatitude();
1561 * Get the GPS target longitude in degrees (negative for west).
1564 FGBFI::getGPSTargetLongitude ()
1566 return current_autopilot->get_TargetLongitude();
1571 * Set the GPS target longitude in degrees (negative for west).
1574 FGBFI::setGPSTargetLongitude (double longitude)
1576 current_autopilot->set_TargetLongitude( longitude );
1582 ////////////////////////////////////////////////////////////////////////
1584 ////////////////////////////////////////////////////////////////////////
1588 * Get the current visible (units??).
1591 FGBFI::getVisibility ()
1593 #ifndef FG_OLD_WEATHER
1594 return WeatherDatabase->getWeatherVisibility();
1596 return current_weather.get_visibility();
1602 * Check whether clouds are enabled.
1607 return current_options.get_clouds();
1612 * Check the height of the clouds ASL (units?).
1615 FGBFI::getCloudsASL ()
1617 return current_options.get_clouds_asl();
1622 * Set the current visibility (units??).
1625 FGBFI::setVisibility (double visibility)
1627 #ifndef FG_OLD_WEATHER
1628 WeatherDatabase->setWeatherVisibility(visibility);
1630 current_weather.set_visibility(visibility);
1636 * Switch clouds on or off.
1639 FGBFI::setClouds (bool clouds)
1641 if (getClouds() != clouds) {
1642 cout << "Set clouds to " << clouds << endl;
1643 current_options.set_clouds(clouds);
1650 * Set the cloud height.
1653 FGBFI::setCloudsASL (double cloudsASL)
1655 if (getCloudsASL() != cloudsASL) {
1656 current_options.set_clouds_asl(cloudsASL);
1663 ////////////////////////////////////////////////////////////////////////
1665 ////////////////////////////////////////////////////////////////////////
1668 * Return the magnetic variation
1673 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1678 * Return the magnetic variation
1683 return globals->get_mag()->get_magdip() * RAD_TO_DEG;