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;
268 globals->set_freeze(_saved_freeze);
271 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
276 * Reinitialize FGFS if required.
278 * Some changes (especially those in aircraft position) require that
279 * FGFS be reinitialized afterwards. Rather than reinitialize after
280 * every change, the setter methods simply set a flag so that there
281 * can be a single reinit at the end of the frame.
288 _set_view_from_axes();
296 ////////////////////////////////////////////////////////////////////////
298 ////////////////////////////////////////////////////////////////////////
302 * Return the flight model as an integer.
304 * TODO: use a string instead.
307 FGBFI::getFlightModel ()
309 return globals->get_options()->get_flight_model();
314 * Return the current aircraft as a string.
317 FGBFI::getAircraft ()
319 _temp = globals->get_options()->get_aircraft();
325 * Return the current aircraft directory (UIUC) as a string.
328 FGBFI::getAircraftDir ()
330 _temp = aircraft_dir;
336 * Set the flight model as an integer.
338 * TODO: use a string instead.
341 FGBFI::setFlightModel (int model)
343 if (getFlightModel() != model) {
344 globals->get_options()->set_flight_model(model);
351 * Set the current aircraft.
354 FGBFI::setAircraft (string aircraft)
356 if (getAircraft() != aircraft) {
357 globals->get_options()->set_aircraft(aircraft);
364 * Set the current aircraft directory (UIUC).
367 FGBFI::setAircraftDir (string dir)
369 if (getAircraftDir() != dir) {
377 * Return the current Zulu time.
380 FGBFI::getDateString ()
384 struct tm * t = globals->get_time_params()->getGmt();
385 sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
386 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
387 t->tm_hour, t->tm_min, t->tm_sec);
394 * Set the current Zulu time.
397 FGBFI::setDateString (string date_string)
398 // FGBFI::setTimeGMT (time_t time)
400 SGTime * st = globals->get_time_params();
401 struct tm * current_time = st->getGmt();
404 // Scan for basic ISO format
405 // YYYY-MM-DDTHH:MM:SS
406 int ret = sscanf(date_string.c_str(), "%d-%d-%dT%d:%d:%d",
407 &(new_time.tm_year), &(new_time.tm_mon),
408 &(new_time.tm_mday), &(new_time.tm_hour),
409 &(new_time.tm_min), &(new_time.tm_sec));
411 // Be pretty picky about this, so
412 // that strange things don't happen
413 // if the save file has been edited
416 FG_LOG(FG_INPUT, FG_ALERT, "Date/time string " << date_string
417 << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
421 // OK, it looks like we got six
422 // values, one way or another.
423 new_time.tm_year -= 1900;
424 new_time.tm_mon -= 1;
426 // Now, tell flight gear to use
427 // the new time. This was far
428 // too difficult, by the way.
430 mktime(&new_time) - mktime(current_time) + globals->get_warp();
431 double lon = current_aircraft.fdm_state->get_Longitude();
432 double lat = current_aircraft.fdm_state->get_Latitude();
433 double alt = current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER;
434 globals->set_warp(warp);
435 st->update(lon, lat, warp);
436 fgUpdateSkyAndLightingParams();
441 * Return the GMT as a string.
444 FGBFI::getGMTString ()
448 struct tm * t = globals->get_time_params()->getGmt();
449 sprintf(buf, " %.2d:%.2d:%.2d",
450 t->tm_hour, t->tm_min, t->tm_sec);
457 * Return true if the HUD is visible.
460 FGBFI::getHUDVisible ()
462 return globals->get_options()->get_hud_status();
467 * Ensure that the HUD is visible or hidden.
470 FGBFI::setHUDVisible (bool visible)
472 globals->get_options()->set_hud_status(visible);
477 ////////////////////////////////////////////////////////////////////////
479 ////////////////////////////////////////////////////////////////////////
483 * Return the current latitude in degrees (negative for south).
486 FGBFI::getLatitude ()
488 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
493 * Set the current latitude in degrees (negative for south).
496 FGBFI::setLatitude (double latitude)
498 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
499 fgUpdateSkyAndLightingParams();
500 if (_lighting_countdown <= 0)
501 _lighting_countdown = 5;
506 * Return the current longitude in degrees (negative for west).
509 FGBFI::getLongitude ()
511 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
516 * Set the current longitude in degrees (negative for west).
519 FGBFI::setLongitude (double longitude)
521 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
522 fgUpdateSkyAndLightingParams();
523 if (_lighting_countdown <= 0)
524 _lighting_countdown = 5;
529 * Return the current altitude in feet.
532 FGBFI::getAltitude ()
534 return current_aircraft.fdm_state->get_Altitude();
540 * Return the current altitude in above the terrain.
545 return current_aircraft.fdm_state->get_Altitude()
546 - (scenery.cur_elev * METER_TO_FEET);
551 * Set the current altitude in feet.
554 FGBFI::setAltitude (double altitude)
556 current_aircraft.fdm_state->set_Altitude(altitude);
559 // This is an ugly kludge around a
560 // LaRCsim problem; if the
561 // requested altitude cannot be
562 // set right away (because it's
563 // below the last-calculated ground
564 // level), pause FGFS, wait for
565 // five frames, and then try again.
566 if (_altitude_countdown <= 0 &&
567 fabs(getAltitude() - altitude) > 5.0) {
568 _altitude_countdown = 5;
569 _requested_altitude = altitude;
570 _saved_freeze = globals->get_freeze();
571 globals->set_freeze(true);
577 ////////////////////////////////////////////////////////////////////////
579 ////////////////////////////////////////////////////////////////////////
583 * Return the current heading in degrees.
588 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
593 * Return the current heading in degrees.
596 FGBFI::getHeadingMag ()
598 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
603 * Set the current heading in degrees.
606 FGBFI::setHeading (double heading)
608 FGInterface * fdm = current_aircraft.fdm_state;
609 fdm->set_Euler_Angles(fdm->get_Phi(), fdm->get_Theta(),
610 heading * DEG_TO_RAD);
615 * Return the current pitch in degrees.
620 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
625 * Set the current pitch in degrees.
628 FGBFI::setPitch (double pitch)
630 FGInterface * fdm = current_aircraft.fdm_state;
631 fdm->set_Euler_Angles(fdm->get_Phi(), pitch * DEG_TO_RAD, fdm->get_Psi());
636 * Return the current roll in degrees.
641 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
646 * Set the current roll in degrees.
649 FGBFI::setRoll (double roll)
651 FGInterface * fdm = current_aircraft.fdm_state;
652 fdm->set_Euler_Angles(roll * DEG_TO_RAD, fdm->get_Theta(), fdm->get_Psi());
657 * Return the current engine0 rpm
662 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
663 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
671 * Set the current engine0 rpm
674 FGBFI::setRPM (double rpm)
676 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
677 if (getRPM() != rpm) {
678 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
685 * Return the current engine0 EGT.
690 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
691 return current_aircraft.fdm_state->get_engine(0)->get_EGT();
699 * Return the current engine0 CHT.
704 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
705 return current_aircraft.fdm_state->get_engine(0)->get_CHT();
713 * Return the current engine0 CHT.
718 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
719 return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
727 ////////////////////////////////////////////////////////////////////////
729 ////////////////////////////////////////////////////////////////////////
733 * Return the current airspeed in knots.
736 FGBFI::getAirspeed ()
738 // FIXME: should we add speed-up?
739 return current_aircraft.fdm_state->get_V_calibrated_kts();
744 * Set the calibrated airspeed in knots.
747 FGBFI::setAirspeed (double speed)
749 current_aircraft.fdm_state->set_V_calibrated_kts(speed);
754 * Return the current sideslip (FIXME: units unknown).
757 FGBFI::getSideSlip ()
759 return current_aircraft.fdm_state->get_Beta();
764 * Return the current climb rate in feet/minute
767 FGBFI::getVerticalSpeed ()
769 // What about meters?
770 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
775 * Get the current north velocity (units??).
778 FGBFI::getSpeedNorth ()
780 return current_aircraft.fdm_state->get_V_north();
785 // * Set the current north velocity (units??).
788 // FGBFI::setSpeedNorth (double speed)
790 // FGInterface * fdm = current_aircraft.fdm_state;
791 // // fdm->set_Velocities_Local(speed, fdm->get_V_east(), fdm->get_V_down());
796 * Get the current east velocity (units??).
799 FGBFI::getSpeedEast ()
801 return current_aircraft.fdm_state->get_V_east();
806 // * Set the current east velocity (units??).
809 // FGBFI::setSpeedEast (double speed)
811 // FGInterface * fdm = current_aircraft.fdm_state;
812 // // fdm->set_Velocities_Local(fdm->get_V_north(), speed, fdm->get_V_down());
817 * Get the current down velocity (units??).
820 FGBFI::getSpeedDown ()
822 return current_aircraft.fdm_state->get_V_down();
827 // * Set the current down velocity (units??).
830 // FGBFI::setSpeedDown (double speed)
832 // FGInterface * fdm = current_aircraft.fdm_state;
833 // // fdm->set_Velocities_Local(fdm->get_V_north(), fdm->get_V_east(), speed);
838 ////////////////////////////////////////////////////////////////////////
840 ////////////////////////////////////////////////////////////////////////
845 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
848 FGBFI::getThrottle ()
850 // FIXME: add engine selector
851 return controls.get_throttle(0);
856 * Set the throttle, from 0.0 (none) to 1.0 (full).
859 FGBFI::setThrottle (double throttle)
861 // FIXME: allow engine selection
862 controls.set_throttle(0, throttle);
867 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
872 // FIXME: add engine selector
873 return controls.get_mixture(0);
878 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
881 FGBFI::setMixture (double mixture)
883 // FIXME: allow engine selection
884 controls.set_mixture(0, mixture);
889 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
892 FGBFI::getPropAdvance ()
894 // FIXME: add engine selector
895 return controls.get_prop_advance(0);
900 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
903 FGBFI::setPropAdvance (double pitch)
905 // FIXME: allow engine selection
906 controls.set_prop_advance(0, pitch);
911 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
916 return controls.get_flaps();
921 * Set the flaps, from 0.0 (none) to 1.0 (full).
924 FGBFI::setFlaps (double flaps)
927 controls.set_flaps(flaps);
932 * Get the aileron, from -1.0 (left) to 1.0 (right).
937 return controls.get_aileron();
942 * Set the aileron, from -1.0 (left) to 1.0 (right).
945 FGBFI::setAileron (double aileron)
948 controls.set_aileron(aileron);
953 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
958 return controls.get_rudder();
963 * Set the rudder, from -1.0 (left) to 1.0 (right).
966 FGBFI::setRudder (double rudder)
969 controls.set_rudder(rudder);
974 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
977 FGBFI::getElevator ()
979 return controls.get_elevator();
984 * Set the elevator, from -1.0 (down) to 1.0 (up).
987 FGBFI::setElevator (double elevator)
990 controls.set_elevator(elevator);
995 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
998 FGBFI::getElevatorTrim ()
1000 return controls.get_elevator_trim();
1005 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
1008 FGBFI::setElevatorTrim (double trim)
1011 controls.set_elevator_trim(trim);
1016 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1021 double b1 = getCenterBrake();
1022 double b2 = getLeftBrake();
1023 double b3 = getRightBrake();
1024 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1029 * Set all brakes, from 0.0 (none) to 1.0 (full).
1032 FGBFI::setBrakes (double brake)
1034 setCenterBrake(brake);
1035 setLeftBrake(brake);
1036 setRightBrake(brake);
1041 * Get the center brake, from 0.0 (none) to 1.0 (full).
1044 FGBFI::getCenterBrake ()
1046 return controls.get_brake(2);
1051 * Set the center brake, from 0.0 (none) to 1.0 (full).
1054 FGBFI::setCenterBrake (double brake)
1056 controls.set_brake(2, brake);
1061 * Get the left brake, from 0.0 (none) to 1.0 (full).
1064 FGBFI::getLeftBrake ()
1066 return controls.get_brake(0);
1071 * Set the left brake, from 0.0 (none) to 1.0 (full).
1074 FGBFI::setLeftBrake (double brake)
1076 controls.set_brake(0, brake);
1081 * Get the right brake, from 0.0 (none) to 1.0 (full).
1084 FGBFI::getRightBrake ()
1086 return controls.get_brake(1);
1091 * Set the right brake, from 0.0 (none) to 1.0 (full).
1094 FGBFI::setRightBrake (double brake)
1096 controls.set_brake(1, brake);
1103 ////////////////////////////////////////////////////////////////////////
1105 ////////////////////////////////////////////////////////////////////////
1109 * Get the autopilot altitude lock (true=on).
1112 FGBFI::getAPAltitudeLock ()
1114 return current_autopilot->get_AltitudeEnabled();
1119 * Set the autopilot altitude lock (true=on).
1122 FGBFI::setAPAltitudeLock (bool lock)
1124 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1125 current_autopilot->set_AltitudeEnabled(lock);
1130 * Get the autopilot target altitude in feet.
1133 FGBFI::getAPAltitude ()
1135 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1140 * Set the autopilot target altitude in feet.
1143 FGBFI::setAPAltitude (double altitude)
1145 current_autopilot->set_TargetAltitude( altitude );
1150 * Get the autopilot heading lock (true=on).
1153 FGBFI::getAPHeadingLock ()
1156 (current_autopilot->get_HeadingEnabled() &&
1157 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1162 * Set the autopilot heading lock (true=on).
1165 FGBFI::setAPHeadingLock (bool lock)
1168 // We need to do this so that
1169 // it's possible to lock onto a
1170 // heading other than the current
1172 double heading = getAPHeadingMag();
1173 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1174 current_autopilot->set_HeadingEnabled(true);
1175 setAPHeadingMag(heading);
1176 } else if (current_autopilot->get_HeadingMode() ==
1177 FGAutopilot::FG_HEADING_LOCK) {
1178 current_autopilot->set_HeadingEnabled(false);
1184 * Get the autopilot target heading in degrees.
1187 FGBFI::getAPHeading ()
1189 return current_autopilot->get_TargetHeading();
1194 * Set the autopilot target heading in degrees.
1197 FGBFI::setAPHeading (double heading)
1199 current_autopilot->set_TargetHeading( heading );
1204 * Get the autopilot target heading in degrees.
1207 FGBFI::getAPHeadingMag ()
1209 return current_autopilot->get_TargetHeading() - getMagVar();
1214 * Set the autopilot target heading in degrees.
1217 FGBFI::setAPHeadingMag (double heading)
1219 current_autopilot->set_TargetHeading( heading + getMagVar() );
1224 * Return true if the autopilot is locked to NAV1.
1227 FGBFI::getAPNAV1Lock ()
1230 (current_autopilot->get_HeadingEnabled() &&
1231 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1236 * Set the autopilot NAV1 lock.
1239 FGBFI::setAPNAV1Lock (bool lock)
1242 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1243 current_autopilot->set_HeadingEnabled(true);
1244 } else if (current_autopilot->get_HeadingMode() ==
1245 FGAutopilot::FG_HEADING_NAV1) {
1246 current_autopilot->set_HeadingEnabled(false);
1252 ////////////////////////////////////////////////////////////////////////
1254 ////////////////////////////////////////////////////////////////////////
1258 * Get the autopilot GPS lock (true=on).
1261 FGBFI::getGPSLock ()
1263 return (current_autopilot->get_HeadingEnabled() &&
1264 (current_autopilot->get_HeadingMode() ==
1265 FGAutopilot::FG_HEADING_WAYPOINT ));
1270 * Set the autopilot GPS lock (true=on).
1273 FGBFI::setGPSLock (bool lock)
1276 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1277 current_autopilot->set_HeadingEnabled(true);
1278 } else if (current_autopilot->get_HeadingMode() ==
1279 FGAutopilot::FG_HEADING_WAYPOINT) {
1280 current_autopilot->set_HeadingEnabled(false);
1286 * Get the GPS target airport code.
1289 FGBFI::getTargetAirport ()
1291 // FIXME: not thread-safe
1293 out = globals->get_options()->get_airport_id();
1300 * Set the GPS target airport code.
1303 FGBFI::setTargetAirport (string airportId)
1305 globals->get_options()->set_airport_id(airportId);
1310 * Get the GPS target latitude in degrees (negative for south).
1313 FGBFI::getGPSTargetLatitude ()
1315 return current_autopilot->get_TargetLatitude();
1320 * Get the GPS target longitude in degrees (negative for west).
1323 FGBFI::getGPSTargetLongitude ()
1325 return current_autopilot->get_TargetLongitude();
1330 * Set the GPS target longitude in degrees (negative for west).
1333 FGBFI::setGPSTargetLongitude (double longitude)
1335 current_autopilot->set_TargetLongitude( longitude );
1341 ////////////////////////////////////////////////////////////////////////
1343 ////////////////////////////////////////////////////////////////////////
1347 * Get the current visibility (meters).
1350 FGBFI::getVisibility ()
1352 #ifndef FG_OLD_WEATHER
1353 return WeatherDatabase->getWeatherVisibility();
1355 return current_weather.get_visibility();
1361 * Set the current visibility (meters).
1364 FGBFI::setVisibility (double visibility)
1366 #ifndef FG_OLD_WEATHER
1367 WeatherDatabase->setWeatherVisibility(visibility);
1369 current_weather.set_visibility(visibility);
1375 * Get the current wind north velocity (feet/second).
1378 FGBFI::getWindNorth ()
1380 return current_aircraft.fdm_state->get_V_north_airmass();
1385 * Set the current wind north velocity (feet/second).
1388 FGBFI::setWindNorth (double speed)
1390 current_aircraft.fdm_state->set_Velocities_Local_Airmass(speed,
1397 * Get the current wind east velocity (feet/second).
1400 FGBFI::getWindEast ()
1402 return current_aircraft.fdm_state->get_V_east_airmass();
1407 * Set the current wind east velocity (feet/second).
1410 FGBFI::setWindEast (double speed)
1412 cout << "Set wind-east to " << speed << endl;
1413 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
1420 * Get the current wind down velocity (feet/second).
1423 FGBFI::getWindDown ()
1425 return current_aircraft.fdm_state->get_V_down_airmass();
1430 * Set the current wind down velocity (feet/second).
1433 FGBFI::setWindDown (double speed)
1435 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
1442 ////////////////////////////////////////////////////////////////////////
1444 ////////////////////////////////////////////////////////////////////////
1447 FGBFI::setViewAxisLong (double axis)
1453 FGBFI::setViewAxisLat (double axis)
1459 ////////////////////////////////////////////////////////////////////////
1461 ////////////////////////////////////////////////////////////////////////
1464 * Return the magnetic variation
1469 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1474 * Return the magnetic variation
1479 return globals->get_mag()->get_magdip() * RAD_TO_DEG;