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.
25 #include <simgear/constants.h>
26 #include <simgear/debug/logstream.hxx>
27 #include <simgear/ephemeris/ephemeris.hxx>
28 #include <simgear/math/sg_types.hxx>
29 #include <simgear/misc/props.hxx>
30 #include <simgear/timing/sg_time.hxx>
32 #include <Aircraft/aircraft.hxx>
33 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
34 #include <Controls/controls.hxx>
35 #include <Autopilot/newauto.hxx>
36 #include <Scenery/scenery.hxx>
37 #include <Time/light.hxx>
38 #include <Time/event.hxx>
39 #include <Time/sunpos.hxx>
40 #include <Time/tmp.hxx>
41 #include <Cockpit/radiostack.hxx>
42 #include <Cockpit/panel.hxx>
43 #ifndef FG_OLD_WEATHER
44 # include <WeatherCM/FGLocalWeatherDatabase.h>
46 # include <Weather/weather.hxx>
49 #include "globals.hxx"
50 #include "fg_init.hxx"
51 #include "fg_props.hxx"
53 FG_USING_NAMESPACE(std);
60 ////////////////////////////////////////////////////////////////////////
62 ////////////////////////////////////////////////////////////////////////
64 // Yech -- not thread-safe, etc. etc.
65 static bool _needReinit = false;
68 static inline void needReinit ()
75 * Reinitialize FGFS to use the new BFI settings.
80 // Save the state of everything
81 // that's going to get clobbered
82 // when we reinit the subsystems.
84 FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI reinit");
86 // TODO: add more AP stuff
87 double elevator = FGBFI::getElevator();
88 double aileron = FGBFI::getAileron();
89 double rudder = FGBFI::getRudder();
90 double throttle = FGBFI::getThrottle();
91 double elevator_trim = FGBFI::getElevatorTrim();
92 double flaps = FGBFI::getFlaps();
93 double brake = FGBFI::getBrakes();
94 bool apHeadingLock = FGBFI::getAPHeadingLock();
95 double apHeadingMag = FGBFI::getAPHeadingMag();
96 bool apAltitudeLock = FGBFI::getAPAltitudeLock();
97 double apAltitude = FGBFI::getAPAltitude();
98 const string &targetAirport = FGBFI::getTargetAirport();
99 bool gpsLock = FGBFI::getGPSLock();
100 // double gpsLatitude = FGBFI::getGPSTargetLatitude();
101 // double gpsLongitude = FGBFI::getGPSTargetLongitude();
103 FGBFI::setTargetAirport("");
105 fgReInitSubsystems();
107 // FIXME: this is wrong.
108 // All of these are scheduled events,
109 // and it should be possible to force
110 // them all to run once.
113 cur_light_params.Update();
115 fgUpdateWeatherDatabase();
118 // Restore all of the old states.
119 FGBFI::setElevator(elevator);
120 FGBFI::setAileron(aileron);
121 FGBFI::setRudder(rudder);
122 FGBFI::setThrottle(throttle);
123 FGBFI::setElevatorTrim(elevator_trim);
124 FGBFI::setFlaps(flaps);
125 FGBFI::setBrakes(brake);
126 FGBFI::setAPHeadingLock(apHeadingLock);
127 FGBFI::setAPHeadingMag(apHeadingMag);
128 FGBFI::setAPAltitudeLock(apAltitudeLock);
129 FGBFI::setAPAltitude(apAltitude);
130 FGBFI::setTargetAirport(targetAirport);
131 FGBFI::setGPSLock(gpsLock);
135 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI reinit");
138 // BEGIN: kludge 2000-12-07
139 // This is a kludge around a LaRCsim problem; see setAltitude()
141 static int _altitude_countdown = 0;
142 static double _requested_altitude = -9999;
143 static bool _saved_freeze = false;
144 static inline void _check_altitude ()
146 if (_altitude_countdown > 0) {
147 _altitude_countdown--;
148 if (_altitude_countdown == 0) {
149 current_aircraft.fdm_state->set_Altitude(_requested_altitude);
150 globals->set_freeze(_saved_freeze);
155 static int _lighting_countdown = 0;
156 static inline void _check_lighting ()
158 if (_lighting_countdown > 0) {
159 _lighting_countdown--;
160 if (_lighting_countdown == 0)
161 fgUpdateSkyAndLightingParams();
168 // Allow the view to be set from two axes (i.e. a joystick hat)
169 // This needs to be in FGViewer itself, somehow.
170 static double axisLong = 0.0;
171 static double axisLat = 0.0;
174 _set_view_from_axes ()
176 // Take no action when hat is centered
177 if (axisLong == 0 && axisLat == 0)
182 if (axisLong < 0) { // Longitudinal axis forward
185 else if (axisLat > 0)
189 } else if (axisLong > 0) { // Longitudinal axis backward
192 else if (axisLat > 0)
196 } else { // Longitudinal axis neutral
203 globals->get_current_view()->set_goal_view_offset(viewDir*DEG_TO_RAD);
204 // globals->get_current_view()->set_view_offset(viewDir*DEG_TO_RAD);
211 ////////////////////////////////////////////////////////////////////////
213 ////////////////////////////////////////////////////////////////////////
216 * Initialize the BFI by binding its functions to properties.
218 * TODO: perhaps these should migrate into the individual modules
219 * (i.e. they should register themselves).
224 FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init");
226 fgTie("/sim/flight-model", getFlightModel, setFlightModel);
227 fgTie("/sim/aircraft", getAircraft, setAircraft);
228 fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
229 fgTie("/sim/time/gmt", getDateString, setDateString);
230 fgTie("/sim/time/gmt-string", getGMTString);
231 fgTie("/sim/hud/visibility", getHUDVisible, setHUDVisible);
232 fgTie("/sim/panel/visibility", getPanelVisible, setPanelVisible);
233 fgTie("/sim/panel/x-offset", getPanelXOffset, setPanelXOffset);
234 fgTie("/sim/panel/y-offset", getPanelYOffset, setPanelYOffset);
237 fgTie("/position/airport-id", getTargetAirport, setTargetAirport);
238 fgTie("/position/latitude", getLatitude, setLatitude);
239 fgTie("/position/longitude", getLongitude, setLongitude);
240 fgTie("/position/altitude", getAltitude, setAltitude);
241 fgTie("/position/altitude-agl", getAGL);
244 fgTie("/orientation/heading", getHeading, setHeading);
245 fgTie("/orientation/heading-magnetic", getHeadingMag);
246 fgTie("/orientation/pitch", getPitch, setPitch);
247 fgTie("/orientation/roll", getRoll, setRoll);
250 fgTie("/engines/engine0/rpm", getRPM);
251 fgTie("/engines/engine0/egt", getEGT);
252 fgTie("/engines/engine0/cht", getCHT);
253 fgTie("/engines/engine0/mp", getMP);
256 fgTie("/velocities/airspeed", getAirspeed, setAirspeed);
257 fgTie("/velocities/side-slip", getSideSlip);
258 fgTie("/velocities/vertical-speed", getVerticalSpeed);
259 fgTie("/velocities/speed-north", getSpeedNorth);
260 fgTie("/velocities/speed-east", getSpeedEast);
261 fgTie("/velocities/speed-down", getSpeedDown);
265 fgTie("/controls/throttle", getThrottle, setThrottle);
266 fgTie("/controls/mixture", getMixture, setMixture);
267 fgTie("/controls/propellor-pitch", getPropAdvance, setPropAdvance);
268 fgTie("/controls/flaps", getFlaps, setFlaps);
269 fgTie("/controls/aileron", getAileron, setAileron);
270 fgTie("/controls/rudder", getRudder, setRudder);
271 fgTie("/controls/elevator", getElevator, setElevator);
272 fgTie("/controls/elevator-trim", getElevatorTrim, setElevatorTrim);
273 fgTie("/controls/brakes/all", getBrakes, setBrakes);
274 fgTie("/controls/brakes/left", getLeftBrake, setLeftBrake);
275 fgTie("/controls/brakes/right", getRightBrake, setRightBrake);
276 fgTie("/controls/brakes/center", getRightBrake, setCenterBrake);
280 fgTie("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock);
281 fgTie("/autopilot/settings/altitude", getAPAltitude, setAPAltitude);
282 fgTie("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock);
283 fgTie("/autopilot/settings/heading", getAPHeading, setAPHeading);
284 fgTie("/autopilot/settings/heading-magnetic",
285 getAPHeadingMag, setAPHeadingMag);
286 fgTie("/autopilot/locks/nav1", getAPNAV1Lock, setAPNAV1Lock);
289 fgTie("/radios/nav1/frequencies/selected", getNAV1Freq, setNAV1Freq);
290 fgTie("/radios/nav1/frequencies/standby", getNAV1AltFreq, setNAV1AltFreq);
291 fgTie("/radios/nav1/radials/actual", getNAV1Radial);
292 fgTie("/radios/nav1/radials/selected",
293 getNAV1SelRadial, setNAV1SelRadial);
294 fgTie("/radios/nav1/dme/distance", getNAV1DistDME);
295 fgTie("/radios/nav1/to-flag", getNAV1TO);
296 fgTie("/radios/nav1/from-flag", getNAV1FROM);
297 fgTie("/radios/nav1/in-range", getNAV1InRange);
298 fgTie("/radios/nav1/dme/in-range", getNAV1DMEInRange);
300 fgTie("/radios/nav2/frequencies/selected", getNAV2Freq, setNAV2Freq);
301 fgTie("/radios/nav2/frequencies/standby",
302 getNAV2AltFreq, setNAV2AltFreq);
303 fgTie("/radios/nav2/radials/actual", getNAV2Radial);
304 fgTie("/radios/nav2/radials/selected",
305 getNAV2SelRadial, setNAV2SelRadial);
306 fgTie("/radios/nav2/dme/distance", getNAV2DistDME);
307 fgTie("/radios/nav2/to-flag", getNAV2TO);
308 fgTie("/radios/nav2/from-flag", getNAV2FROM);
309 fgTie("/radios/nav2/in-range", getNAV2InRange);
310 fgTie("/radios/nav2/dme/in-range", getNAV2DMEInRange);
312 fgTie("/radios/adf/frequencies/selected", getADFFreq, setADFFreq);
313 fgTie("/radios/adf/frequencies/standby", getADFAltFreq, setADFAltFreq);
314 fgTie("/radios/adf/rotation", getADFRotation, setADFRotation);
317 fgTie("/environment/visibility", getVisibility, setVisibility);
318 fgTie("/environment/wind-north", getWindNorth, setWindNorth);
319 fgTie("/environment/wind-east", getWindEast, setWindEast);
320 fgTie("/environment/wind-down", getWindDown, setWindDown);
323 fgTie("/sim/view/axes/long", (double(*)())0, setViewAxisLong);
324 fgTie("/sim/view/axes/lat", (double(*)())0, setViewAxisLat);
328 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
333 * Reinitialize FGFS if required.
335 * Some changes (especially those in aircraft position) require that
336 * FGFS be reinitialized afterwards. Rather than reinitialize after
337 * every change, the setter methods simply set a flag so that there
338 * can be a single reinit at the end of the frame.
345 _set_view_from_axes();
353 ////////////////////////////////////////////////////////////////////////
355 ////////////////////////////////////////////////////////////////////////
359 * Return the flight model as an integer.
361 * TODO: use a string instead.
364 FGBFI::getFlightModel ()
366 return globals->get_options()->get_flight_model();
371 * Return the current aircraft as a string.
374 FGBFI::getAircraft ()
376 _temp = globals->get_options()->get_aircraft();
382 * Return the current aircraft directory (UIUC) as a string.
385 FGBFI::getAircraftDir ()
387 _temp = aircraft_dir;
393 * Set the flight model as an integer.
395 * TODO: use a string instead.
398 FGBFI::setFlightModel (int model)
400 if (getFlightModel() != model) {
401 globals->get_options()->set_flight_model(model);
408 * Set the current aircraft.
411 FGBFI::setAircraft (string aircraft)
413 if (getAircraft() != aircraft) {
414 globals->get_options()->set_aircraft(aircraft);
421 * Set the current aircraft directory (UIUC).
424 FGBFI::setAircraftDir (string dir)
426 if (getAircraftDir() != dir) {
434 * Return the current Zulu time.
437 FGBFI::getDateString ()
441 struct tm * t = globals->get_time_params()->getGmt();
442 sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
443 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
444 t->tm_hour, t->tm_min, t->tm_sec);
451 * Set the current Zulu time.
454 FGBFI::setDateString (string date_string)
455 // FGBFI::setTimeGMT (time_t time)
457 SGTime * st = globals->get_time_params();
458 struct tm * current_time = st->getGmt();
461 // Scan for basic ISO format
462 // YYYY-MM-DDTHH:MM:SS
463 int ret = sscanf(date_string.c_str(), "%d-%d-%dT%d:%d:%d",
464 &(new_time.tm_year), &(new_time.tm_mon),
465 &(new_time.tm_mday), &(new_time.tm_hour),
466 &(new_time.tm_min), &(new_time.tm_sec));
468 // Be pretty picky about this, so
469 // that strange things don't happen
470 // if the save file has been edited
473 FG_LOG(FG_INPUT, FG_ALERT, "Date/time string " << date_string
474 << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
478 // OK, it looks like we got six
479 // values, one way or another.
480 new_time.tm_year -= 1900;
481 new_time.tm_mon -= 1;
483 // Now, tell flight gear to use
484 // the new time. This was far
485 // too difficult, by the way.
487 mktime(&new_time) - mktime(current_time) + globals->get_warp();
488 double lon = current_aircraft.fdm_state->get_Longitude();
489 double lat = current_aircraft.fdm_state->get_Latitude();
490 double alt = current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER;
491 globals->set_warp(warp);
492 st->update(lon, lat, warp);
493 fgUpdateSkyAndLightingParams();
498 * Return the GMT as a string.
501 FGBFI::getGMTString ()
505 struct tm * t = globals->get_time_params()->getGmt();
506 sprintf(buf, " %.2d:%.2d:%.2d",
507 t->tm_hour, t->tm_min, t->tm_sec);
514 * Return true if the HUD is visible.
517 FGBFI::getHUDVisible ()
519 return globals->get_options()->get_hud_status();
524 * Ensure that the HUD is visible or hidden.
527 FGBFI::setHUDVisible (bool visible)
529 globals->get_options()->set_hud_status(visible);
534 * Return true if the 2D panel is visible.
537 FGBFI::getPanelVisible ()
539 return globals->get_options()->get_panel_status();
544 * Ensure that the 2D panel is visible or hidden.
547 FGBFI::setPanelVisible (bool visible)
549 if (globals->get_options()->get_panel_status() != visible) {
550 globals->get_options()->toggle_panel();
556 * Get the panel's current x-shift.
559 FGBFI::getPanelXOffset ()
561 if (current_panel != 0)
562 return current_panel->getXOffset();
569 * Set the panel's current x-shift.
572 FGBFI::setPanelXOffset (int offset)
574 if (current_panel != 0)
575 current_panel->setXOffset(offset);
580 * Get the panel's current y-shift.
583 FGBFI::getPanelYOffset ()
585 if (current_panel != 0)
586 return current_panel->getYOffset();
593 * Set the panel's current y-shift.
596 FGBFI::setPanelYOffset (int offset)
598 if (current_panel != 0)
599 current_panel->setYOffset(offset);
606 ////////////////////////////////////////////////////////////////////////
608 ////////////////////////////////////////////////////////////////////////
612 * Return the current latitude in degrees (negative for south).
615 FGBFI::getLatitude ()
617 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
622 * Set the current latitude in degrees (negative for south).
625 FGBFI::setLatitude (double latitude)
627 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
628 fgUpdateSkyAndLightingParams();
629 if (_lighting_countdown <= 0)
630 _lighting_countdown = 5;
635 * Return the current longitude in degrees (negative for west).
638 FGBFI::getLongitude ()
640 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
645 * Set the current longitude in degrees (negative for west).
648 FGBFI::setLongitude (double longitude)
650 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
651 fgUpdateSkyAndLightingParams();
652 if (_lighting_countdown <= 0)
653 _lighting_countdown = 5;
658 * Return the current altitude in feet.
661 FGBFI::getAltitude ()
663 return current_aircraft.fdm_state->get_Altitude();
669 * Return the current altitude in above the terrain.
674 return current_aircraft.fdm_state->get_Altitude()
675 - (scenery.cur_elev * METER_TO_FEET);
680 * Set the current altitude in feet.
683 FGBFI::setAltitude (double altitude)
685 current_aircraft.fdm_state->set_Altitude(altitude);
688 // This is an ugly kludge around a
689 // LaRCsim problem; if the
690 // requested altitude cannot be
691 // set right away (because it's
692 // below the last-calculated ground
693 // level), pause FGFS, wait for
694 // five frames, and then try again.
695 if (_altitude_countdown <= 0 &&
696 fabs(getAltitude() - altitude) > 5.0) {
697 _altitude_countdown = 5;
698 _requested_altitude = altitude;
699 _saved_freeze = globals->get_freeze();
700 globals->set_freeze(true);
706 ////////////////////////////////////////////////////////////////////////
708 ////////////////////////////////////////////////////////////////////////
712 * Return the current heading in degrees.
717 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
722 * Return the current heading in degrees.
725 FGBFI::getHeadingMag ()
727 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
732 * Set the current heading in degrees.
735 FGBFI::setHeading (double heading)
737 FGInterface * fdm = current_aircraft.fdm_state;
738 fdm->set_Euler_Angles(fdm->get_Phi(), fdm->get_Theta(),
739 heading * DEG_TO_RAD);
744 * Return the current pitch in degrees.
749 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
754 * Set the current pitch in degrees.
757 FGBFI::setPitch (double pitch)
759 FGInterface * fdm = current_aircraft.fdm_state;
760 fdm->set_Euler_Angles(fdm->get_Phi(), pitch * DEG_TO_RAD, fdm->get_Psi());
765 * Return the current roll in degrees.
770 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
775 * Set the current roll in degrees.
778 FGBFI::setRoll (double roll)
780 FGInterface * fdm = current_aircraft.fdm_state;
781 fdm->set_Euler_Angles(roll * DEG_TO_RAD, fdm->get_Theta(), fdm->get_Psi());
786 * Return the current engine0 rpm
791 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
792 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
800 * Set the current engine0 rpm
803 FGBFI::setRPM (double rpm)
805 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
806 if (getRPM() != rpm) {
807 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
814 * Return the current engine0 EGT.
819 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
820 return current_aircraft.fdm_state->get_engine(0)->get_EGT();
828 * Return the current engine0 CHT.
833 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
834 return current_aircraft.fdm_state->get_engine(0)->get_CHT();
842 * Return the current engine0 CHT.
847 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
848 return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
856 ////////////////////////////////////////////////////////////////////////
858 ////////////////////////////////////////////////////////////////////////
862 * Return the current airspeed in knots.
865 FGBFI::getAirspeed ()
867 // FIXME: should we add speed-up?
868 return current_aircraft.fdm_state->get_V_calibrated_kts();
873 * Set the calibrated airspeed in knots.
876 FGBFI::setAirspeed (double speed)
878 current_aircraft.fdm_state->set_V_calibrated_kts(speed);
883 * Return the current sideslip (FIXME: units unknown).
886 FGBFI::getSideSlip ()
888 return current_aircraft.fdm_state->get_Beta();
893 * Return the current climb rate in feet/minute
896 FGBFI::getVerticalSpeed ()
898 // What about meters?
899 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
904 * Get the current north velocity (units??).
907 FGBFI::getSpeedNorth ()
909 return current_aircraft.fdm_state->get_V_north();
914 // * Set the current north velocity (units??).
917 // FGBFI::setSpeedNorth (double speed)
919 // FGInterface * fdm = current_aircraft.fdm_state;
920 // // fdm->set_Velocities_Local(speed, fdm->get_V_east(), fdm->get_V_down());
925 * Get the current east velocity (units??).
928 FGBFI::getSpeedEast ()
930 return current_aircraft.fdm_state->get_V_east();
935 // * Set the current east velocity (units??).
938 // FGBFI::setSpeedEast (double speed)
940 // FGInterface * fdm = current_aircraft.fdm_state;
941 // // fdm->set_Velocities_Local(fdm->get_V_north(), speed, fdm->get_V_down());
946 * Get the current down velocity (units??).
949 FGBFI::getSpeedDown ()
951 return current_aircraft.fdm_state->get_V_down();
956 // * Set the current down velocity (units??).
959 // FGBFI::setSpeedDown (double speed)
961 // FGInterface * fdm = current_aircraft.fdm_state;
962 // // fdm->set_Velocities_Local(fdm->get_V_north(), fdm->get_V_east(), speed);
967 ////////////////////////////////////////////////////////////////////////
969 ////////////////////////////////////////////////////////////////////////
973 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
976 FGBFI::getThrottle ()
978 // FIXME: add engine selector
979 return controls.get_throttle(0);
984 * Set the throttle, from 0.0 (none) to 1.0 (full).
987 FGBFI::setThrottle (double throttle)
989 // FIXME: allow engine selection
990 controls.set_throttle(0, throttle);
995 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
1000 // FIXME: add engine selector
1001 return controls.get_mixture(0);
1006 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
1009 FGBFI::setMixture (double mixture)
1011 // FIXME: allow engine selection
1012 controls.set_mixture(0, mixture);
1017 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
1020 FGBFI::getPropAdvance ()
1022 // FIXME: add engine selector
1023 return controls.get_prop_advance(0);
1028 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
1031 FGBFI::setPropAdvance (double pitch)
1033 // FIXME: allow engine selection
1034 controls.set_prop_advance(0, pitch);
1039 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
1044 return controls.get_flaps();
1049 * Set the flaps, from 0.0 (none) to 1.0 (full).
1052 FGBFI::setFlaps (double flaps)
1055 controls.set_flaps(flaps);
1060 * Get the aileron, from -1.0 (left) to 1.0 (right).
1063 FGBFI::getAileron ()
1065 return controls.get_aileron();
1070 * Set the aileron, from -1.0 (left) to 1.0 (right).
1073 FGBFI::setAileron (double aileron)
1076 controls.set_aileron(aileron);
1081 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
1086 return controls.get_rudder();
1091 * Set the rudder, from -1.0 (left) to 1.0 (right).
1094 FGBFI::setRudder (double rudder)
1097 controls.set_rudder(rudder);
1102 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
1105 FGBFI::getElevator ()
1107 return controls.get_elevator();
1112 * Set the elevator, from -1.0 (down) to 1.0 (up).
1115 FGBFI::setElevator (double elevator)
1118 controls.set_elevator(elevator);
1123 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
1126 FGBFI::getElevatorTrim ()
1128 return controls.get_elevator_trim();
1133 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
1136 FGBFI::setElevatorTrim (double trim)
1139 controls.set_elevator_trim(trim);
1144 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1149 double b1 = getCenterBrake();
1150 double b2 = getLeftBrake();
1151 double b3 = getRightBrake();
1152 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1157 * Set all brakes, from 0.0 (none) to 1.0 (full).
1160 FGBFI::setBrakes (double brake)
1162 setCenterBrake(brake);
1163 setLeftBrake(brake);
1164 setRightBrake(brake);
1169 * Get the center brake, from 0.0 (none) to 1.0 (full).
1172 FGBFI::getCenterBrake ()
1174 return controls.get_brake(2);
1179 * Set the center brake, from 0.0 (none) to 1.0 (full).
1182 FGBFI::setCenterBrake (double brake)
1184 controls.set_brake(2, brake);
1189 * Get the left brake, from 0.0 (none) to 1.0 (full).
1192 FGBFI::getLeftBrake ()
1194 return controls.get_brake(0);
1199 * Set the left brake, from 0.0 (none) to 1.0 (full).
1202 FGBFI::setLeftBrake (double brake)
1204 controls.set_brake(0, brake);
1209 * Get the right brake, from 0.0 (none) to 1.0 (full).
1212 FGBFI::getRightBrake ()
1214 return controls.get_brake(1);
1219 * Set the right brake, from 0.0 (none) to 1.0 (full).
1222 FGBFI::setRightBrake (double brake)
1224 controls.set_brake(1, brake);
1231 ////////////////////////////////////////////////////////////////////////
1233 ////////////////////////////////////////////////////////////////////////
1237 * Get the autopilot altitude lock (true=on).
1240 FGBFI::getAPAltitudeLock ()
1242 return current_autopilot->get_AltitudeEnabled();
1247 * Set the autopilot altitude lock (true=on).
1250 FGBFI::setAPAltitudeLock (bool lock)
1252 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1253 current_autopilot->set_AltitudeEnabled(lock);
1258 * Get the autopilot target altitude in feet.
1261 FGBFI::getAPAltitude ()
1263 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1268 * Set the autopilot target altitude in feet.
1271 FGBFI::setAPAltitude (double altitude)
1273 current_autopilot->set_TargetAltitude( altitude );
1278 * Get the autopilot heading lock (true=on).
1281 FGBFI::getAPHeadingLock ()
1284 (current_autopilot->get_HeadingEnabled() &&
1285 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1290 * Set the autopilot heading lock (true=on).
1293 FGBFI::setAPHeadingLock (bool lock)
1296 // We need to do this so that
1297 // it's possible to lock onto a
1298 // heading other than the current
1300 double heading = getAPHeadingMag();
1301 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1302 current_autopilot->set_HeadingEnabled(true);
1303 setAPHeadingMag(heading);
1304 } else if (current_autopilot->get_HeadingMode() ==
1305 FGAutopilot::FG_HEADING_LOCK) {
1306 current_autopilot->set_HeadingEnabled(false);
1312 * Get the autopilot target heading in degrees.
1315 FGBFI::getAPHeading ()
1317 return current_autopilot->get_TargetHeading();
1322 * Set the autopilot target heading in degrees.
1325 FGBFI::setAPHeading (double heading)
1327 current_autopilot->set_TargetHeading( heading );
1332 * Get the autopilot target heading in degrees.
1335 FGBFI::getAPHeadingMag ()
1337 return current_autopilot->get_TargetHeading() - getMagVar();
1342 * Set the autopilot target heading in degrees.
1345 FGBFI::setAPHeadingMag (double heading)
1347 current_autopilot->set_TargetHeading( heading + getMagVar() );
1352 * Return true if the autopilot is locked to NAV1.
1355 FGBFI::getAPNAV1Lock ()
1358 (current_autopilot->get_HeadingEnabled() &&
1359 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1364 * Set the autopilot NAV1 lock.
1367 FGBFI::setAPNAV1Lock (bool lock)
1370 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1371 current_autopilot->set_HeadingEnabled(true);
1372 } else if (current_autopilot->get_HeadingMode() ==
1373 FGAutopilot::FG_HEADING_NAV1) {
1374 current_autopilot->set_HeadingEnabled(false);
1380 ////////////////////////////////////////////////////////////////////////
1381 // Radio navigation.
1382 ////////////////////////////////////////////////////////////////////////
1385 FGBFI::getNAV1Freq ()
1387 return current_radiostack->get_nav1_freq();
1391 FGBFI::getNAV1AltFreq ()
1393 return current_radiostack->get_nav1_alt_freq();
1397 FGBFI::getNAV1Radial ()
1399 return current_radiostack->get_nav1_radial();
1403 FGBFI::getNAV1SelRadial ()
1405 return current_radiostack->get_nav1_sel_radial();
1409 FGBFI::getNAV1DistDME ()
1411 return current_radiostack->get_nav1_dme_dist();
1417 if (current_radiostack->get_nav1_inrange()) {
1418 double heading = current_radiostack->get_nav1_heading();
1419 double radial = current_radiostack->get_nav1_radial();
1420 // double var = FGBFI::getMagVar();
1421 if (current_radiostack->get_nav1_loc()) {
1422 double offset = fabs(heading - radial);
1423 return (offset<= 8.0 || offset >= 352.0);
1426 // fabs(heading - var - radial);
1427 double offset = fabs(heading - radial);
1428 return (offset <= 20.0 || offset >= 340.0);
1436 FGBFI::getNAV1FROM ()
1438 if (current_radiostack->get_nav1_inrange()) {
1439 double heading = current_radiostack->get_nav1_heading();
1440 double radial = current_radiostack->get_nav1_radial();
1441 // double var = FGBFI::getMagVar();
1442 if (current_radiostack->get_nav1_loc()) {
1443 double offset = fabs(heading - radial);
1444 return (offset >= 172.0 && offset<= 188.0);
1447 // fabs(heading - var - radial);
1448 double offset = fabs(heading - radial);
1449 return (offset >= 160.0 && offset <= 200.0);
1457 FGBFI::getNAV1InRange ()
1459 return current_radiostack->get_nav1_inrange();
1463 FGBFI::getNAV1DMEInRange ()
1465 return (current_radiostack->get_nav1_inrange() &&
1466 current_radiostack->get_nav1_has_dme());
1470 FGBFI::getNAV2Freq ()
1472 return current_radiostack->get_nav2_freq();
1476 FGBFI::getNAV2AltFreq ()
1478 return current_radiostack->get_nav2_alt_freq();
1482 FGBFI::getNAV2Radial ()
1484 return current_radiostack->get_nav2_radial();
1488 FGBFI::getNAV2SelRadial ()
1490 return current_radiostack->get_nav2_sel_radial();
1494 FGBFI::getNAV2DistDME ()
1496 return current_radiostack->get_nav2_dme_dist();
1502 if (current_radiostack->get_nav2_inrange()) {
1503 double heading = current_radiostack->get_nav2_heading();
1504 double radial = current_radiostack->get_nav2_radial();
1505 // double var = FGBFI::getMagVar();
1506 if (current_radiostack->get_nav2_loc()) {
1507 double offset = fabs(heading - radial);
1508 return (offset<= 8.0 || offset >= 352.0);
1511 // fabs(heading - var - radial);
1512 double offset = fabs(heading - radial);
1513 return (offset <= 20.0 || offset >= 340.0);
1521 FGBFI::getNAV2FROM ()
1523 if (current_radiostack->get_nav2_inrange()) {
1524 double heading = current_radiostack->get_nav2_heading();
1525 double radial = current_radiostack->get_nav2_radial();
1526 // double var = FGBFI::getMagVar();
1527 if (current_radiostack->get_nav2_loc()) {
1528 double offset = fabs(heading - radial);
1529 return (offset >= 172.0 && offset<= 188.0);
1532 // fabs(heading - var - radial);
1533 double offset = fabs(heading - radial);
1534 return (offset >= 160.0 && offset <= 200.0);
1543 FGBFI::getNAV2InRange ()
1545 return current_radiostack->get_nav2_inrange();
1549 FGBFI::getNAV2DMEInRange ()
1551 return (current_radiostack->get_nav2_inrange() &&
1552 current_radiostack->get_nav2_has_dme());
1556 FGBFI::getADFFreq ()
1558 return current_radiostack->get_adf_freq();
1562 FGBFI::getADFAltFreq ()
1564 return current_radiostack->get_adf_alt_freq();
1568 FGBFI::getADFRotation ()
1570 return current_radiostack->get_adf_rotation();
1574 FGBFI::setNAV1Freq (double freq)
1576 current_radiostack->set_nav1_freq(freq);
1580 FGBFI::setNAV1AltFreq (double freq)
1582 current_radiostack->set_nav1_alt_freq(freq);
1586 FGBFI::setNAV1SelRadial (double radial)
1588 current_radiostack->set_nav1_sel_radial(radial);
1592 FGBFI::setNAV2Freq (double freq)
1594 current_radiostack->set_nav2_freq(freq);
1598 FGBFI::setNAV2AltFreq (double freq)
1600 current_radiostack->set_nav2_alt_freq(freq);
1604 FGBFI::setNAV2SelRadial (double radial)
1606 current_radiostack->set_nav2_sel_radial(radial);
1610 FGBFI::setADFFreq (double freq)
1612 current_radiostack->set_adf_freq(freq);
1616 FGBFI::setADFAltFreq (double freq)
1618 current_radiostack->set_adf_alt_freq(freq);
1622 FGBFI::setADFRotation (double rot)
1624 current_radiostack->set_adf_rotation(rot);
1629 ////////////////////////////////////////////////////////////////////////
1631 ////////////////////////////////////////////////////////////////////////
1635 * Get the autopilot GPS lock (true=on).
1638 FGBFI::getGPSLock ()
1640 return (current_autopilot->get_HeadingEnabled() &&
1641 (current_autopilot->get_HeadingMode() ==
1642 FGAutopilot::FG_HEADING_WAYPOINT ));
1647 * Set the autopilot GPS lock (true=on).
1650 FGBFI::setGPSLock (bool lock)
1653 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1654 current_autopilot->set_HeadingEnabled(true);
1655 } else if (current_autopilot->get_HeadingMode() ==
1656 FGAutopilot::FG_HEADING_WAYPOINT) {
1657 current_autopilot->set_HeadingEnabled(false);
1663 * Get the GPS target airport code.
1666 FGBFI::getTargetAirport ()
1668 // FIXME: not thread-safe
1670 out = globals->get_options()->get_airport_id();
1677 * Set the GPS target airport code.
1680 FGBFI::setTargetAirport (string airportId)
1682 globals->get_options()->set_airport_id(airportId);
1687 * Get the GPS target latitude in degrees (negative for south).
1690 FGBFI::getGPSTargetLatitude ()
1692 return current_autopilot->get_TargetLatitude();
1697 * Get the GPS target longitude in degrees (negative for west).
1700 FGBFI::getGPSTargetLongitude ()
1702 return current_autopilot->get_TargetLongitude();
1707 * Set the GPS target longitude in degrees (negative for west).
1710 FGBFI::setGPSTargetLongitude (double longitude)
1712 current_autopilot->set_TargetLongitude( longitude );
1718 ////////////////////////////////////////////////////////////////////////
1720 ////////////////////////////////////////////////////////////////////////
1724 * Get the current visibility (meters).
1727 FGBFI::getVisibility ()
1729 #ifndef FG_OLD_WEATHER
1730 return WeatherDatabase->getWeatherVisibility();
1732 return current_weather.get_visibility();
1738 * Set the current visibility (meters).
1741 FGBFI::setVisibility (double visibility)
1743 #ifndef FG_OLD_WEATHER
1744 WeatherDatabase->setWeatherVisibility(visibility);
1746 current_weather.set_visibility(visibility);
1752 * Get the current wind north velocity (feet/second).
1755 FGBFI::getWindNorth ()
1757 return current_aircraft.fdm_state->get_V_north_airmass();
1762 * Set the current wind north velocity (feet/second).
1765 FGBFI::setWindNorth (double speed)
1767 current_aircraft.fdm_state->set_Velocities_Local_Airmass(speed,
1774 * Get the current wind east velocity (feet/second).
1777 FGBFI::getWindEast ()
1779 return current_aircraft.fdm_state->get_V_east_airmass();
1784 * Set the current wind east velocity (feet/second).
1787 FGBFI::setWindEast (double speed)
1789 cout << "Set wind-east to " << speed << endl;
1790 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
1797 * Get the current wind down velocity (feet/second).
1800 FGBFI::getWindDown ()
1802 return current_aircraft.fdm_state->get_V_down_airmass();
1807 * Set the current wind down velocity (feet/second).
1810 FGBFI::setWindDown (double speed)
1812 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
1819 ////////////////////////////////////////////////////////////////////////
1821 ////////////////////////////////////////////////////////////////////////
1824 FGBFI::setViewAxisLong (double axis)
1830 FGBFI::setViewAxisLat (double axis)
1836 ////////////////////////////////////////////////////////////////////////
1838 ////////////////////////////////////////////////////////////////////////
1841 * Return the magnetic variation
1846 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1851 * Return the magnetic variation
1856 return globals->get_mag()->get_magdip() * RAD_TO_DEG;