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",
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);
239 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
244 * Reinitialize FGFS if required.
246 * Some changes (especially those in aircraft position) require that
247 * FGFS be reinitialized afterwards. Rather than reinitialize after
248 * every change, the setter methods simply set a flag so that there
249 * can be a single reinit at the end of the frame.
261 * Reinitialize FGFS to use the new BFI settings.
266 // Save the state of everything
267 // that's going to get clobbered
268 // when we reinit the subsystems.
270 cout << "BFI: start reinit\n";
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 " << globals->get_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);
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 globals->get_options()->get_flight_model();
345 * Return the current aircraft as a string.
348 FGBFI::getAircraft ()
350 return globals->get_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 globals->get_options()->set_flight_model(model);
380 * Set the current aircraft.
383 FGBFI::setAircraft (const string &aircraft)
385 if (getAircraft() != aircraft) {
386 globals->get_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 globals->get_options()->set_time_offset(time);
425 globals->get_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 globals->get_options()->get_hud_status();
461 * Ensure that the HUD is visible or hidden.
464 FGBFI::setHUDVisible (bool visible)
466 globals->get_options()->set_hud_status(visible);
471 * Return true if the 2D panel is visible.
474 FGBFI::getPanelVisible ()
476 return globals->get_options()->get_panel_status();
481 * Ensure that the 2D panel is visible or hidden.
484 FGBFI::setPanelVisible (bool visible)
486 if (globals->get_options()->get_panel_status() != visible) {
487 globals->get_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 globals->get_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 globals->get_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 globals->get_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 globals->get_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 globals->get_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 globals->get_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_aircraft.fdm_state->set_Velocities_Local(speed,
780 * Get the current east velocity (units??).
783 FGBFI::getSpeedEast ()
785 return current_aircraft.fdm_state->get_V_east();
790 * Set the current east velocity (units??).
793 FGBFI::setSpeedEast (double speed)
795 if (getSpeedEast() != speed) {
796 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
805 * Get the current down velocity (units??).
808 FGBFI::getSpeedDown ()
810 return current_aircraft.fdm_state->get_V_down();
815 * Set the current down velocity (units??).
818 FGBFI::setSpeedDown (double speed)
820 if (getSpeedDown() != speed) {
821 current_aircraft.fdm_state->set_Velocities_Local(getSpeedNorth(),
830 ////////////////////////////////////////////////////////////////////////
832 ////////////////////////////////////////////////////////////////////////
836 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
839 FGBFI::getThrottle ()
841 // FIXME: add engine selector
842 return controls.get_throttle(0);
847 * Set the throttle, from 0.0 (none) to 1.0 (full).
850 FGBFI::setThrottle (double throttle)
852 // FIXME: allow engine selection
853 controls.set_throttle(0, throttle);
858 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
863 // FIXME: add engine selector
864 return controls.get_mixture(0);
869 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
872 FGBFI::setMixture (double mixture)
874 // FIXME: allow engine selection
875 controls.set_mixture(0, mixture);
880 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
883 FGBFI::getPropAdvance ()
885 // FIXME: add engine selector
886 return controls.get_prop_advance(0);
891 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
894 FGBFI::setPropAdvance (double pitch)
896 // FIXME: allow engine selection
897 controls.set_prop_advance(0, pitch);
902 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
907 return controls.get_flaps();
912 * Set the flaps, from 0.0 (none) to 1.0 (full).
915 FGBFI::setFlaps (double flaps)
918 controls.set_flaps(flaps);
923 * Get the aileron, from -1.0 (left) to 1.0 (right).
928 return controls.get_aileron();
933 * Set the aileron, from -1.0 (left) to 1.0 (right).
936 FGBFI::setAileron (double aileron)
939 controls.set_aileron(aileron);
944 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
949 return controls.get_rudder();
954 * Set the rudder, from -1.0 (left) to 1.0 (right).
957 FGBFI::setRudder (double rudder)
960 controls.set_rudder(rudder);
965 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
968 FGBFI::getElevator ()
970 return controls.get_elevator();
975 * Set the elevator, from -1.0 (down) to 1.0 (up).
978 FGBFI::setElevator (double elevator)
981 controls.set_elevator(elevator);
986 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
989 FGBFI::getElevatorTrim ()
991 return controls.get_elevator_trim();
996 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
999 FGBFI::setElevatorTrim (double trim)
1002 controls.set_elevator_trim(trim);
1007 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1012 double b1 = getCenterBrake();
1013 double b2 = getLeftBrake();
1014 double b3 = getRightBrake();
1015 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1020 * Set all brakes, from 0.0 (none) to 1.0 (full).
1023 FGBFI::setBrakes (double brake)
1025 setCenterBrake(brake);
1026 setLeftBrake(brake);
1027 setRightBrake(brake);
1032 * Get the center brake, from 0.0 (none) to 1.0 (full).
1035 FGBFI::getCenterBrake ()
1037 return controls.get_brake(2);
1042 * Set the center brake, from 0.0 (none) to 1.0 (full).
1045 FGBFI::setCenterBrake (double brake)
1047 controls.set_brake(2, brake);
1052 * Get the left brake, from 0.0 (none) to 1.0 (full).
1055 FGBFI::getLeftBrake ()
1057 return controls.get_brake(0);
1062 * Set the left brake, from 0.0 (none) to 1.0 (full).
1065 FGBFI::setLeftBrake (double brake)
1067 controls.set_brake(0, brake);
1072 * Get the right brake, from 0.0 (none) to 1.0 (full).
1075 FGBFI::getRightBrake ()
1077 return controls.get_brake(1);
1082 * Set the right brake, from 0.0 (none) to 1.0 (full).
1085 FGBFI::setRightBrake (double brake)
1087 controls.set_brake(1, brake);
1094 ////////////////////////////////////////////////////////////////////////
1096 ////////////////////////////////////////////////////////////////////////
1100 * Get the autopilot altitude lock (true=on).
1103 FGBFI::getAPAltitudeLock ()
1105 return current_autopilot->get_AltitudeEnabled();
1110 * Set the autopilot altitude lock (true=on).
1113 FGBFI::setAPAltitudeLock (bool lock)
1115 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1116 current_autopilot->set_AltitudeEnabled(lock);
1121 * Get the autopilot target altitude in feet.
1124 FGBFI::getAPAltitude ()
1126 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1131 * Set the autopilot target altitude in feet.
1134 FGBFI::setAPAltitude (double altitude)
1136 current_autopilot->set_TargetAltitude( altitude );
1141 * Get the autopilot heading lock (true=on).
1144 FGBFI::getAPHeadingLock ()
1147 (current_autopilot->get_HeadingEnabled() &&
1148 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1153 * Set the autopilot heading lock (true=on).
1156 FGBFI::setAPHeadingLock (bool lock)
1159 // We need to do this so that
1160 // it's possible to lock onto a
1161 // heading other than the current
1163 double heading = getAPHeadingMag();
1164 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1165 current_autopilot->set_HeadingEnabled(true);
1166 setAPHeadingMag(heading);
1167 } else if (current_autopilot->get_HeadingMode() ==
1168 FGAutopilot::FG_HEADING_LOCK) {
1169 current_autopilot->set_HeadingEnabled(false);
1175 * Get the autopilot target heading in degrees.
1178 FGBFI::getAPHeading ()
1180 return current_autopilot->get_TargetHeading();
1185 * Set the autopilot target heading in degrees.
1188 FGBFI::setAPHeading (double heading)
1190 current_autopilot->set_TargetHeading( heading );
1195 * Get the autopilot target heading in degrees.
1198 FGBFI::getAPHeadingMag ()
1200 return current_autopilot->get_TargetHeading() - getMagVar();
1205 * Set the autopilot target heading in degrees.
1208 FGBFI::setAPHeadingMag (double heading)
1210 current_autopilot->set_TargetHeading( heading + getMagVar() );
1215 * Return true if the autopilot is locked to NAV1.
1218 FGBFI::getAPNAV1Lock ()
1221 (current_autopilot->get_HeadingEnabled() &&
1222 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1227 * Set the autopilot NAV1 lock.
1230 FGBFI::setAPNAV1Lock (bool lock)
1233 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1234 current_autopilot->set_HeadingEnabled(true);
1235 } else if (current_autopilot->get_HeadingMode() ==
1236 FGAutopilot::FG_HEADING_NAV1) {
1237 current_autopilot->set_HeadingEnabled(false);
1243 ////////////////////////////////////////////////////////////////////////
1244 // Radio navigation.
1245 ////////////////////////////////////////////////////////////////////////
1248 FGBFI::getNAV1Freq ()
1250 return current_radiostack->get_nav1_freq();
1254 FGBFI::getNAV1AltFreq ()
1256 return current_radiostack->get_nav1_alt_freq();
1260 FGBFI::getNAV1Radial ()
1262 return current_radiostack->get_nav1_radial();
1266 FGBFI::getNAV1SelRadial ()
1268 return current_radiostack->get_nav1_sel_radial();
1272 FGBFI::getNAV1DistDME ()
1274 return current_radiostack->get_nav1_dme_dist();
1280 if (current_radiostack->get_nav1_inrange()) {
1281 double heading = current_radiostack->get_nav1_heading();
1282 double radial = current_radiostack->get_nav1_radial();
1283 double var = FGBFI::getMagVar();
1284 if (current_radiostack->get_nav1_loc()) {
1285 double offset = fabs(heading - radial);
1286 return (offset<= 8.0 || offset >= 352.0);
1289 fabs(heading - var - radial);
1290 return (offset <= 20.0 || offset >= 340.0);
1298 FGBFI::getNAV1FROM ()
1300 if (current_radiostack->get_nav1_inrange()) {
1301 double heading = current_radiostack->get_nav1_heading();
1302 double radial = current_radiostack->get_nav1_radial();
1303 double var = FGBFI::getMagVar();
1304 if (current_radiostack->get_nav1_loc()) {
1305 double offset = fabs(heading - radial);
1306 return (offset >= 172.0 && offset<= 188.0);
1309 fabs(heading - var - radial);
1310 return (offset >= 160.0 && offset <= 200.0);
1318 FGBFI::getNAV1InRange ()
1320 return current_radiostack->get_nav1_inrange();
1324 FGBFI::getNAV1DMEInRange ()
1326 return (current_radiostack->get_nav1_inrange() &&
1327 current_radiostack->get_nav1_has_dme());
1331 FGBFI::getNAV2Freq ()
1333 return current_radiostack->get_nav2_freq();
1337 FGBFI::getNAV2AltFreq ()
1339 return current_radiostack->get_nav2_alt_freq();
1343 FGBFI::getNAV2Radial ()
1345 return current_radiostack->get_nav2_radial();
1349 FGBFI::getNAV2SelRadial ()
1351 return current_radiostack->get_nav2_sel_radial();
1355 FGBFI::getNAV2DistDME ()
1357 return current_radiostack->get_nav2_dme_dist();
1363 if (current_radiostack->get_nav2_inrange()) {
1364 double heading = current_radiostack->get_nav2_heading();
1365 double radial = current_radiostack->get_nav2_radial();
1366 double var = FGBFI::getMagVar();
1367 if (current_radiostack->get_nav2_loc()) {
1368 double offset = fabs(heading - radial);
1369 return (offset<= 8.0 || offset >= 352.0);
1372 fabs(heading - var - radial);
1373 return (offset <= 20.0 || offset >= 340.0);
1381 FGBFI::getNAV2FROM ()
1383 if (current_radiostack->get_nav2_inrange()) {
1384 double heading = current_radiostack->get_nav2_heading();
1385 double radial = current_radiostack->get_nav2_radial();
1386 double var = FGBFI::getMagVar();
1387 if (current_radiostack->get_nav2_loc()) {
1388 double offset = fabs(heading - radial);
1389 return (offset >= 172.0 && offset<= 188.0);
1392 fabs(heading - var - radial);
1393 return (offset >= 160.0 && offset <= 200.0);
1402 FGBFI::getNAV2InRange ()
1404 return current_radiostack->get_nav2_inrange();
1408 FGBFI::getNAV2DMEInRange ()
1410 return (current_radiostack->get_nav2_inrange() &&
1411 current_radiostack->get_nav2_has_dme());
1415 FGBFI::getADFFreq ()
1417 return current_radiostack->get_adf_freq();
1421 FGBFI::getADFAltFreq ()
1423 return current_radiostack->get_adf_alt_freq();
1427 FGBFI::getADFRotation ()
1429 return current_radiostack->get_adf_rotation();
1433 FGBFI::setNAV1Freq (double freq)
1435 current_radiostack->set_nav1_freq(freq);
1439 FGBFI::setNAV1AltFreq (double freq)
1441 current_radiostack->set_nav1_alt_freq(freq);
1445 FGBFI::setNAV1SelRadial (double radial)
1447 current_radiostack->set_nav1_sel_radial(radial);
1451 FGBFI::setNAV2Freq (double freq)
1453 current_radiostack->set_nav2_freq(freq);
1457 FGBFI::setNAV2AltFreq (double freq)
1459 current_radiostack->set_nav2_alt_freq(freq);
1463 FGBFI::setNAV2SelRadial (double radial)
1465 current_radiostack->set_nav2_sel_radial(radial);
1469 FGBFI::setADFFreq (double freq)
1471 current_radiostack->set_adf_freq(freq);
1475 FGBFI::setADFAltFreq (double freq)
1477 current_radiostack->set_adf_alt_freq(freq);
1481 FGBFI::setADFRotation (double rot)
1483 current_radiostack->set_adf_rotation(rot);
1488 ////////////////////////////////////////////////////////////////////////
1490 ////////////////////////////////////////////////////////////////////////
1494 * Get the autopilot GPS lock (true=on).
1497 FGBFI::getGPSLock ()
1499 return (current_autopilot->get_HeadingEnabled() &&
1500 (current_autopilot->get_HeadingMode() ==
1501 FGAutopilot::FG_HEADING_WAYPOINT ));
1506 * Set the autopilot GPS lock (true=on).
1509 FGBFI::setGPSLock (bool lock)
1512 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1513 current_autopilot->set_HeadingEnabled(true);
1514 } else if (current_autopilot->get_HeadingMode() ==
1515 FGAutopilot::FG_HEADING_WAYPOINT) {
1516 current_autopilot->set_HeadingEnabled(false);
1522 * Get the GPS target airport code.
1525 FGBFI::getTargetAirport ()
1527 // FIXME: not thread-safe
1529 out = globals->get_options()->get_airport_id();
1536 * Set the GPS target airport code.
1539 FGBFI::setTargetAirport (const string &airportId)
1541 // cout << "setting target airport id = " << airportId << endl;
1542 globals->get_options()->set_airport_id(airportId);
1547 * Get the GPS target latitude in degrees (negative for south).
1550 FGBFI::getGPSTargetLatitude ()
1552 return current_autopilot->get_TargetLatitude();
1557 * Get the GPS target longitude in degrees (negative for west).
1560 FGBFI::getGPSTargetLongitude ()
1562 return current_autopilot->get_TargetLongitude();
1567 * Set the GPS target longitude in degrees (negative for west).
1570 FGBFI::setGPSTargetLongitude (double longitude)
1572 current_autopilot->set_TargetLongitude( longitude );
1578 ////////////////////////////////////////////////////////////////////////
1580 ////////////////////////////////////////////////////////////////////////
1584 * Get the current visible (units??).
1587 FGBFI::getVisibility ()
1589 #ifndef FG_OLD_WEATHER
1590 return WeatherDatabase->getWeatherVisibility();
1592 return current_weather.get_visibility();
1598 * Check whether clouds are enabled.
1603 return globals->get_options()->get_clouds();
1608 * Check the height of the clouds ASL (units?).
1611 FGBFI::getCloudsASL ()
1613 return globals->get_options()->get_clouds_asl();
1618 * Set the current visibility (units??).
1621 FGBFI::setVisibility (double visibility)
1623 #ifndef FG_OLD_WEATHER
1624 WeatherDatabase->setWeatherVisibility(visibility);
1626 current_weather.set_visibility(visibility);
1632 * Switch clouds on or off.
1635 FGBFI::setClouds (bool clouds)
1637 if (getClouds() != clouds) {
1638 cout << "Set clouds to " << clouds << endl;
1639 globals->get_options()->set_clouds(clouds);
1646 * Set the cloud height.
1649 FGBFI::setCloudsASL (double cloudsASL)
1651 if (getCloudsASL() != cloudsASL) {
1652 globals->get_options()->set_clouds_asl(cloudsASL);
1659 ////////////////////////////////////////////////////////////////////////
1661 ////////////////////////////////////////////////////////////////////////
1664 * Return the magnetic variation
1669 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1674 * Return the magnetic variation
1679 return globals->get_mag()->get_magdip() * RAD_TO_DEG;