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 CLASS IS DEPRECATED; USE THE PROPERTY MANAGER INSTEAD.
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <simgear/constants.h>
28 #include <simgear/debug/logstream.hxx>
29 #include <simgear/ephemeris/ephemeris.hxx>
30 #include <simgear/math/sg_types.hxx>
31 #include <simgear/misc/props.hxx>
32 #include <simgear/timing/sg_time.hxx>
34 #include <Aircraft/aircraft.hxx>
35 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
36 #include <Controls/controls.hxx>
37 #include <Autopilot/newauto.hxx>
38 #include <Scenery/scenery.hxx>
39 #include <Time/light.hxx>
40 #include <Time/event.hxx>
41 #include <Time/sunpos.hxx>
42 #include <Time/tmp.hxx>
43 #include <Cockpit/radiostack.hxx>
44 #include <Cockpit/panel.hxx>
45 #ifndef FG_OLD_WEATHER
46 # include <WeatherCM/FGLocalWeatherDatabase.h>
48 # include <Weather/weather.hxx>
51 #include "globals.hxx"
52 #include "fg_init.hxx"
53 #include "fg_props.hxx"
55 FG_USING_NAMESPACE(std);
62 ////////////////////////////////////////////////////////////////////////
64 ////////////////////////////////////////////////////////////////////////
66 // Yech -- not thread-safe, etc. etc.
67 static bool _needReinit = false;
70 static inline void needReinit ()
77 * Reinitialize FGFS to use the new BFI settings.
82 // Save the state of everything
83 // that's going to get clobbered
84 // when we reinit the subsystems.
86 FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI reinit");
88 // TODO: add more AP stuff
89 bool apHeadingLock = FGBFI::getAPHeadingLock();
90 double apHeadingMag = FGBFI::getAPHeadingMag();
91 bool apAltitudeLock = FGBFI::getAPAltitudeLock();
92 double apAltitude = FGBFI::getAPAltitude();
93 const string &targetAirport = FGBFI::getTargetAirport();
94 bool gpsLock = FGBFI::getGPSLock();
95 // double gpsLatitude = FGBFI::getGPSTargetLatitude();
96 // double gpsLongitude = FGBFI::getGPSTargetLongitude();
98 FGBFI::setTargetAirport("");
100 fgReInitSubsystems();
102 // FIXME: this is wrong.
103 // All of these are scheduled events,
104 // and it should be possible to force
105 // them all to run once.
108 cur_light_params.Update();
110 fgUpdateWeatherDatabase();
111 current_radiostack->search();
113 // Restore all of the old states.
114 FGBFI::setAPHeadingLock(apHeadingLock);
115 FGBFI::setAPHeadingMag(apHeadingMag);
116 FGBFI::setAPAltitudeLock(apAltitudeLock);
117 FGBFI::setAPAltitude(apAltitude);
118 FGBFI::setTargetAirport(targetAirport);
119 FGBFI::setGPSLock(gpsLock);
123 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI reinit");
126 // BEGIN: kludge 2000-12-07
127 // This is a kludge around a LaRCsim problem; see setAltitude()
129 static int _altitude_countdown = 0;
130 static double _requested_altitude = -9999;
131 static bool _saved_freeze = false;
132 static inline void _check_altitude ()
134 if (_altitude_countdown > 0) {
135 _altitude_countdown--;
136 if (_altitude_countdown == 0) {
137 current_aircraft.fdm_state->set_Altitude(_requested_altitude);
138 globals->set_freeze(_saved_freeze);
143 static int _lighting_countdown = 0;
144 static inline void _check_lighting ()
146 if (_lighting_countdown > 0) {
147 _lighting_countdown--;
148 if (_lighting_countdown == 0)
149 fgUpdateSkyAndLightingParams();
156 // Allow the view to be set from two axes (i.e. a joystick hat)
157 // This needs to be in FGViewer itself, somehow.
158 static double axisLong = 0.0;
159 static double axisLat = 0.0;
162 _set_view_from_axes ()
164 // Take no action when hat is centered
165 if (axisLong == 0 && axisLat == 0)
170 if (axisLong < 0) { // Longitudinal axis forward
173 else if (axisLat > 0)
177 } else if (axisLong > 0) { // Longitudinal axis backward
180 else if (axisLat > 0)
184 } else { // Longitudinal axis neutral
191 globals->get_current_view()->set_goal_view_offset(viewDir*DEG_TO_RAD);
192 // globals->get_current_view()->set_view_offset(viewDir*DEG_TO_RAD);
199 ////////////////////////////////////////////////////////////////////////
201 ////////////////////////////////////////////////////////////////////////
204 * Initialize the BFI by binding its functions to properties.
206 * TODO: perhaps these should migrate into the individual modules
207 * (i.e. they should register themselves).
212 FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init");
214 fgTie("/sim/flight-model", getFlightModel, setFlightModel);
215 fgTie("/sim/aircraft", getAircraft, setAircraft);
216 fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
217 fgTie("/sim/time/gmt", getDateString, setDateString);
218 fgTie("/sim/time/gmt-string", getGMTString);
219 fgTie("/sim/hud/visibility", getHUDVisible, setHUDVisible);
222 fgTie("/position/airport-id", getTargetAirport, setTargetAirport);
223 fgTie("/position/latitude", getLatitude, setLatitude);
224 fgTie("/position/longitude", getLongitude, setLongitude);
225 fgTie("/position/altitude", getAltitude, setAltitude);
226 fgTie("/position/altitude-agl", getAGL);
229 fgTie("/orientation/heading", getHeading, setHeading);
230 fgTie("/orientation/heading-magnetic", getHeadingMag);
231 fgTie("/orientation/pitch", getPitch, setPitch);
232 fgTie("/orientation/roll", getRoll, setRoll);
235 fgTie("/engines/engine0/rpm", getRPM);
236 fgTie("/engines/engine0/egt", getEGT);
237 fgTie("/engines/engine0/cht", getCHT);
238 fgTie("/engines/engine0/mp", getMP);
241 fgTie("/velocities/airspeed", getAirspeed, setAirspeed);
242 fgTie("/velocities/side-slip", getSideSlip);
243 fgTie("/velocities/vertical-speed", getVerticalSpeed);
244 fgTie("/velocities/speed-north", getSpeedNorth);
245 fgTie("/velocities/speed-east", getSpeedEast);
246 fgTie("/velocities/speed-down", getSpeedDown);
249 fgTie("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock);
250 fgTie("/autopilot/settings/altitude", getAPAltitude, setAPAltitude);
251 fgTie("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock);
252 fgTie("/autopilot/settings/heading", getAPHeading, setAPHeading);
253 fgTie("/autopilot/settings/heading-magnetic",
254 getAPHeadingMag, setAPHeadingMag);
255 fgTie("/autopilot/locks/nav1", getAPNAV1Lock, setAPNAV1Lock);
258 fgTie("/environment/visibility", getVisibility, setVisibility);
259 fgTie("/environment/wind-north", getWindNorth, setWindNorth);
260 fgTie("/environment/wind-east", getWindEast, setWindEast);
261 fgTie("/environment/wind-down", getWindDown, setWindDown);
264 fgTie("/sim/view/axes/long", (double(*)())0, setViewAxisLong);
265 fgTie("/sim/view/axes/lat", (double(*)())0, setViewAxisLat);
267 _altitude_countdown = 0;
270 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
275 * Reinitialize FGFS if required.
277 * Some changes (especially those in aircraft position) require that
278 * FGFS be reinitialized afterwards. Rather than reinitialize after
279 * every change, the setter methods simply set a flag so that there
280 * can be a single reinit at the end of the frame.
287 _set_view_from_axes();
295 ////////////////////////////////////////////////////////////////////////
297 ////////////////////////////////////////////////////////////////////////
301 * Return the flight model as an integer.
303 * TODO: use a string instead.
306 FGBFI::getFlightModel ()
308 return globals->get_options()->get_flight_model();
313 * Return the current aircraft as a string.
316 FGBFI::getAircraft ()
318 _temp = globals->get_options()->get_aircraft();
324 * Return the current aircraft directory (UIUC) as a string.
327 FGBFI::getAircraftDir ()
329 _temp = aircraft_dir;
335 * Set the flight model as an integer.
337 * TODO: use a string instead.
340 FGBFI::setFlightModel (int model)
342 if (getFlightModel() != model) {
343 globals->get_options()->set_flight_model(model);
350 * Set the current aircraft.
353 FGBFI::setAircraft (string aircraft)
355 if (getAircraft() != aircraft) {
356 globals->get_options()->set_aircraft(aircraft);
363 * Set the current aircraft directory (UIUC).
366 FGBFI::setAircraftDir (string dir)
368 if (getAircraftDir() != dir) {
376 * Return the current Zulu time.
379 FGBFI::getDateString ()
383 struct tm * t = globals->get_time_params()->getGmt();
384 sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
385 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
386 t->tm_hour, t->tm_min, t->tm_sec);
393 * Set the current Zulu time.
396 FGBFI::setDateString (string date_string)
397 // FGBFI::setTimeGMT (time_t time)
399 SGTime * st = globals->get_time_params();
400 struct tm * current_time = st->getGmt();
403 // Scan for basic ISO format
404 // YYYY-MM-DDTHH:MM:SS
405 int ret = sscanf(date_string.c_str(), "%d-%d-%dT%d:%d:%d",
406 &(new_time.tm_year), &(new_time.tm_mon),
407 &(new_time.tm_mday), &(new_time.tm_hour),
408 &(new_time.tm_min), &(new_time.tm_sec));
410 // Be pretty picky about this, so
411 // that strange things don't happen
412 // if the save file has been edited
415 FG_LOG(FG_INPUT, FG_ALERT, "Date/time string " << date_string
416 << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
420 // OK, it looks like we got six
421 // values, one way or another.
422 new_time.tm_year -= 1900;
423 new_time.tm_mon -= 1;
425 // Now, tell flight gear to use
426 // the new time. This was far
427 // too difficult, by the way.
429 mktime(&new_time) - mktime(current_time) + globals->get_warp();
430 double lon = current_aircraft.fdm_state->get_Longitude();
431 double lat = current_aircraft.fdm_state->get_Latitude();
432 double alt = current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER;
433 globals->set_warp(warp);
434 st->update(lon, lat, warp);
435 fgUpdateSkyAndLightingParams();
440 * Return the GMT as a string.
443 FGBFI::getGMTString ()
447 struct tm * t = globals->get_time_params()->getGmt();
448 sprintf(buf, " %.2d:%.2d:%.2d",
449 t->tm_hour, t->tm_min, t->tm_sec);
456 * Return true if the HUD is visible.
459 FGBFI::getHUDVisible ()
461 return globals->get_options()->get_hud_status();
466 * Ensure that the HUD is visible or hidden.
469 FGBFI::setHUDVisible (bool visible)
471 globals->get_options()->set_hud_status(visible);
476 ////////////////////////////////////////////////////////////////////////
478 ////////////////////////////////////////////////////////////////////////
482 * Return the current latitude in degrees (negative for south).
485 FGBFI::getLatitude ()
487 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
492 * Set the current latitude in degrees (negative for south).
495 FGBFI::setLatitude (double latitude)
497 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
498 fgUpdateSkyAndLightingParams();
499 if (_lighting_countdown <= 0)
500 _lighting_countdown = 5;
505 * Return the current longitude in degrees (negative for west).
508 FGBFI::getLongitude ()
510 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
515 * Set the current longitude in degrees (negative for west).
518 FGBFI::setLongitude (double longitude)
520 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
521 fgUpdateSkyAndLightingParams();
522 if (_lighting_countdown <= 0)
523 _lighting_countdown = 5;
528 * Return the current altitude in feet.
531 FGBFI::getAltitude ()
533 return current_aircraft.fdm_state->get_Altitude();
539 * Return the current altitude in above the terrain.
544 return current_aircraft.fdm_state->get_Altitude()
545 - (scenery.cur_elev * METER_TO_FEET);
550 * Set the current altitude in feet.
553 FGBFI::setAltitude (double altitude)
555 current_aircraft.fdm_state->set_Altitude(altitude);
558 // This is an ugly kludge around a
559 // LaRCsim problem; if the
560 // requested altitude cannot be
561 // set right away (because it's
562 // below the last-calculated ground
563 // level), pause FGFS, wait for
564 // five frames, and then try again.
565 if (_altitude_countdown <= 0 &&
566 fabs(getAltitude() - altitude) > 5.0) {
567 _altitude_countdown = 5;
568 _requested_altitude = altitude;
569 _saved_freeze = globals->get_freeze();
570 globals->set_freeze(true);
576 ////////////////////////////////////////////////////////////////////////
578 ////////////////////////////////////////////////////////////////////////
582 * Return the current heading in degrees.
587 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
592 * Return the current heading in degrees.
595 FGBFI::getHeadingMag ()
597 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
602 * Set the current heading in degrees.
605 FGBFI::setHeading (double heading)
607 FGInterface * fdm = current_aircraft.fdm_state;
608 fdm->set_Euler_Angles(fdm->get_Phi(), fdm->get_Theta(),
609 heading * DEG_TO_RAD);
614 * Return the current pitch in degrees.
619 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
624 * Set the current pitch in degrees.
627 FGBFI::setPitch (double pitch)
629 FGInterface * fdm = current_aircraft.fdm_state;
630 fdm->set_Euler_Angles(fdm->get_Phi(), pitch * DEG_TO_RAD, fdm->get_Psi());
635 * Return the current roll in degrees.
640 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
645 * Set the current roll in degrees.
648 FGBFI::setRoll (double roll)
650 FGInterface * fdm = current_aircraft.fdm_state;
651 fdm->set_Euler_Angles(roll * DEG_TO_RAD, fdm->get_Theta(), fdm->get_Psi());
656 * Return the current engine0 rpm
661 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
662 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
670 * Set the current engine0 rpm
673 FGBFI::setRPM (double rpm)
675 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
676 if (getRPM() != rpm) {
677 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
684 * Return the current engine0 EGT.
689 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
690 return current_aircraft.fdm_state->get_engine(0)->get_EGT();
698 * Return the current engine0 CHT.
703 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
704 return current_aircraft.fdm_state->get_engine(0)->get_CHT();
712 * Return the current engine0 CHT.
717 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
718 return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
726 ////////////////////////////////////////////////////////////////////////
728 ////////////////////////////////////////////////////////////////////////
732 * Return the current airspeed in knots.
735 FGBFI::getAirspeed ()
737 // FIXME: should we add speed-up?
738 return current_aircraft.fdm_state->get_V_calibrated_kts();
743 * Set the calibrated airspeed in knots.
746 FGBFI::setAirspeed (double speed)
748 current_aircraft.fdm_state->set_V_calibrated_kts(speed);
753 * Return the current sideslip (FIXME: units unknown).
756 FGBFI::getSideSlip ()
758 return current_aircraft.fdm_state->get_Beta();
763 * Return the current climb rate in feet/minute
766 FGBFI::getVerticalSpeed ()
768 // What about meters?
769 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
774 * Get the current north velocity (units??).
777 FGBFI::getSpeedNorth ()
779 return current_aircraft.fdm_state->get_V_north();
784 // * Set the current north velocity (units??).
787 // FGBFI::setSpeedNorth (double speed)
789 // FGInterface * fdm = current_aircraft.fdm_state;
790 // // fdm->set_Velocities_Local(speed, fdm->get_V_east(), fdm->get_V_down());
795 * Get the current east velocity (units??).
798 FGBFI::getSpeedEast ()
800 return current_aircraft.fdm_state->get_V_east();
805 // * Set the current east velocity (units??).
808 // FGBFI::setSpeedEast (double speed)
810 // FGInterface * fdm = current_aircraft.fdm_state;
811 // // fdm->set_Velocities_Local(fdm->get_V_north(), speed, fdm->get_V_down());
816 * Get the current down velocity (units??).
819 FGBFI::getSpeedDown ()
821 return current_aircraft.fdm_state->get_V_down();
826 // * Set the current down velocity (units??).
829 // FGBFI::setSpeedDown (double speed)
831 // FGInterface * fdm = current_aircraft.fdm_state;
832 // // fdm->set_Velocities_Local(fdm->get_V_north(), fdm->get_V_east(), speed);
837 ////////////////////////////////////////////////////////////////////////
839 ////////////////////////////////////////////////////////////////////////
844 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
847 FGBFI::getThrottle ()
849 // FIXME: add engine selector
850 return controls.get_throttle(0);
855 * Set the throttle, from 0.0 (none) to 1.0 (full).
858 FGBFI::setThrottle (double throttle)
860 // FIXME: allow engine selection
861 controls.set_throttle(0, throttle);
866 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
871 // FIXME: add engine selector
872 return controls.get_mixture(0);
877 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
880 FGBFI::setMixture (double mixture)
882 // FIXME: allow engine selection
883 controls.set_mixture(0, mixture);
888 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
891 FGBFI::getPropAdvance ()
893 // FIXME: add engine selector
894 return controls.get_prop_advance(0);
899 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
902 FGBFI::setPropAdvance (double pitch)
904 // FIXME: allow engine selection
905 controls.set_prop_advance(0, pitch);
910 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
915 return controls.get_flaps();
920 * Set the flaps, from 0.0 (none) to 1.0 (full).
923 FGBFI::setFlaps (double flaps)
926 controls.set_flaps(flaps);
931 * Get the aileron, from -1.0 (left) to 1.0 (right).
936 return controls.get_aileron();
941 * Set the aileron, from -1.0 (left) to 1.0 (right).
944 FGBFI::setAileron (double aileron)
947 controls.set_aileron(aileron);
952 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
957 return controls.get_rudder();
962 * Set the rudder, from -1.0 (left) to 1.0 (right).
965 FGBFI::setRudder (double rudder)
968 controls.set_rudder(rudder);
973 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
976 FGBFI::getElevator ()
978 return controls.get_elevator();
983 * Set the elevator, from -1.0 (down) to 1.0 (up).
986 FGBFI::setElevator (double elevator)
989 controls.set_elevator(elevator);
994 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
997 FGBFI::getElevatorTrim ()
999 return controls.get_elevator_trim();
1004 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
1007 FGBFI::setElevatorTrim (double trim)
1010 controls.set_elevator_trim(trim);
1015 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1020 double b1 = getCenterBrake();
1021 double b2 = getLeftBrake();
1022 double b3 = getRightBrake();
1023 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1028 * Set all brakes, from 0.0 (none) to 1.0 (full).
1031 FGBFI::setBrakes (double brake)
1033 setCenterBrake(brake);
1034 setLeftBrake(brake);
1035 setRightBrake(brake);
1040 * Get the center brake, from 0.0 (none) to 1.0 (full).
1043 FGBFI::getCenterBrake ()
1045 return controls.get_brake(2);
1050 * Set the center brake, from 0.0 (none) to 1.0 (full).
1053 FGBFI::setCenterBrake (double brake)
1055 controls.set_brake(2, brake);
1060 * Get the left brake, from 0.0 (none) to 1.0 (full).
1063 FGBFI::getLeftBrake ()
1065 return controls.get_brake(0);
1070 * Set the left brake, from 0.0 (none) to 1.0 (full).
1073 FGBFI::setLeftBrake (double brake)
1075 controls.set_brake(0, brake);
1080 * Get the right brake, from 0.0 (none) to 1.0 (full).
1083 FGBFI::getRightBrake ()
1085 return controls.get_brake(1);
1090 * Set the right brake, from 0.0 (none) to 1.0 (full).
1093 FGBFI::setRightBrake (double brake)
1095 controls.set_brake(1, brake);
1102 ////////////////////////////////////////////////////////////////////////
1104 ////////////////////////////////////////////////////////////////////////
1108 * Get the autopilot altitude lock (true=on).
1111 FGBFI::getAPAltitudeLock ()
1113 return current_autopilot->get_AltitudeEnabled();
1118 * Set the autopilot altitude lock (true=on).
1121 FGBFI::setAPAltitudeLock (bool lock)
1123 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1124 current_autopilot->set_AltitudeEnabled(lock);
1129 * Get the autopilot target altitude in feet.
1132 FGBFI::getAPAltitude ()
1134 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1139 * Set the autopilot target altitude in feet.
1142 FGBFI::setAPAltitude (double altitude)
1144 current_autopilot->set_TargetAltitude( altitude );
1149 * Get the autopilot heading lock (true=on).
1152 FGBFI::getAPHeadingLock ()
1155 (current_autopilot->get_HeadingEnabled() &&
1156 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1161 * Set the autopilot heading lock (true=on).
1164 FGBFI::setAPHeadingLock (bool lock)
1167 // We need to do this so that
1168 // it's possible to lock onto a
1169 // heading other than the current
1171 double heading = getAPHeadingMag();
1172 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1173 current_autopilot->set_HeadingEnabled(true);
1174 setAPHeadingMag(heading);
1175 } else if (current_autopilot->get_HeadingMode() ==
1176 FGAutopilot::FG_HEADING_LOCK) {
1177 current_autopilot->set_HeadingEnabled(false);
1183 * Get the autopilot target heading in degrees.
1186 FGBFI::getAPHeading ()
1188 return current_autopilot->get_TargetHeading();
1193 * Set the autopilot target heading in degrees.
1196 FGBFI::setAPHeading (double heading)
1198 current_autopilot->set_TargetHeading( heading );
1203 * Get the autopilot target heading in degrees.
1206 FGBFI::getAPHeadingMag ()
1208 return current_autopilot->get_TargetHeading() - getMagVar();
1213 * Set the autopilot target heading in degrees.
1216 FGBFI::setAPHeadingMag (double heading)
1218 current_autopilot->set_TargetHeading( heading + getMagVar() );
1223 * Return true if the autopilot is locked to NAV1.
1226 FGBFI::getAPNAV1Lock ()
1229 (current_autopilot->get_HeadingEnabled() &&
1230 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1235 * Set the autopilot NAV1 lock.
1238 FGBFI::setAPNAV1Lock (bool lock)
1241 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1242 current_autopilot->set_HeadingEnabled(true);
1243 } else if (current_autopilot->get_HeadingMode() ==
1244 FGAutopilot::FG_HEADING_NAV1) {
1245 current_autopilot->set_HeadingEnabled(false);
1251 ////////////////////////////////////////////////////////////////////////
1253 ////////////////////////////////////////////////////////////////////////
1257 * Get the autopilot GPS lock (true=on).
1260 FGBFI::getGPSLock ()
1262 return (current_autopilot->get_HeadingEnabled() &&
1263 (current_autopilot->get_HeadingMode() ==
1264 FGAutopilot::FG_HEADING_WAYPOINT ));
1269 * Set the autopilot GPS lock (true=on).
1272 FGBFI::setGPSLock (bool lock)
1275 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1276 current_autopilot->set_HeadingEnabled(true);
1277 } else if (current_autopilot->get_HeadingMode() ==
1278 FGAutopilot::FG_HEADING_WAYPOINT) {
1279 current_autopilot->set_HeadingEnabled(false);
1285 * Get the GPS target airport code.
1288 FGBFI::getTargetAirport ()
1290 // FIXME: not thread-safe
1292 out = globals->get_options()->get_airport_id();
1299 * Set the GPS target airport code.
1302 FGBFI::setTargetAirport (string airportId)
1304 globals->get_options()->set_airport_id(airportId);
1309 * Get the GPS target latitude in degrees (negative for south).
1312 FGBFI::getGPSTargetLatitude ()
1314 return current_autopilot->get_TargetLatitude();
1319 * Get the GPS target longitude in degrees (negative for west).
1322 FGBFI::getGPSTargetLongitude ()
1324 return current_autopilot->get_TargetLongitude();
1329 * Set the GPS target longitude in degrees (negative for west).
1332 FGBFI::setGPSTargetLongitude (double longitude)
1334 current_autopilot->set_TargetLongitude( longitude );
1340 ////////////////////////////////////////////////////////////////////////
1342 ////////////////////////////////////////////////////////////////////////
1346 * Get the current visibility (meters).
1349 FGBFI::getVisibility ()
1351 #ifndef FG_OLD_WEATHER
1352 return WeatherDatabase->getWeatherVisibility();
1354 return current_weather.get_visibility();
1360 * Set the current visibility (meters).
1363 FGBFI::setVisibility (double visibility)
1365 #ifndef FG_OLD_WEATHER
1366 WeatherDatabase->setWeatherVisibility(visibility);
1368 current_weather.set_visibility(visibility);
1374 * Get the current wind north velocity (feet/second).
1377 FGBFI::getWindNorth ()
1379 return current_aircraft.fdm_state->get_V_north_airmass();
1384 * Set the current wind north velocity (feet/second).
1387 FGBFI::setWindNorth (double speed)
1389 current_aircraft.fdm_state->set_Velocities_Local_Airmass(speed,
1396 * Get the current wind east velocity (feet/second).
1399 FGBFI::getWindEast ()
1401 return current_aircraft.fdm_state->get_V_east_airmass();
1406 * Set the current wind east velocity (feet/second).
1409 FGBFI::setWindEast (double speed)
1411 cout << "Set wind-east to " << speed << endl;
1412 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
1419 * Get the current wind down velocity (feet/second).
1422 FGBFI::getWindDown ()
1424 return current_aircraft.fdm_state->get_V_down_airmass();
1429 * Set the current wind down velocity (feet/second).
1432 FGBFI::setWindDown (double speed)
1434 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
1441 ////////////////////////////////////////////////////////////////////////
1443 ////////////////////////////////////////////////////////////////////////
1446 FGBFI::setViewAxisLong (double axis)
1452 FGBFI::setViewAxisLat (double axis)
1458 ////////////////////////////////////////////////////////////////////////
1460 ////////////////////////////////////////////////////////////////////////
1463 * Return the magnetic variation
1468 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1473 * Return the magnetic variation
1478 return globals->get_mag()->get_magdip() * RAD_TO_DEG;