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 #include <Cockpit/panel.hxx>
52 #ifndef FG_OLD_WEATHER
53 # include <WeatherCM/FGLocalWeatherDatabase.h>
55 # include <Weather/weather.hxx>
58 #include "globals.hxx"
60 #include "fg_init.hxx"
61 #include <simgear/misc/props.hxx>
63 FG_USING_NAMESPACE(std);
70 ////////////////////////////////////////////////////////////////////////
72 ////////////////////////////////////////////////////////////////////////
74 // Yech -- not thread-safe, etc. etc.
75 static bool _needReinit = false;
78 static inline void needReinit ()
85 * Reinitialize FGFS to use the new BFI settings.
90 // Save the state of everything
91 // that's going to get clobbered
92 // when we reinit the subsystems.
94 cout << "BFI: start reinit\n";
96 // TODO: add more AP stuff
97 double elevator = FGBFI::getElevator();
98 double aileron = FGBFI::getAileron();
99 double rudder = FGBFI::getRudder();
100 double throttle = FGBFI::getThrottle();
101 double elevator_trim = FGBFI::getElevatorTrim();
102 double flaps = FGBFI::getFlaps();
103 double brake = FGBFI::getBrakes();
104 bool apHeadingLock = FGBFI::getAPHeadingLock();
105 double apHeadingMag = FGBFI::getAPHeadingMag();
106 bool apAltitudeLock = FGBFI::getAPAltitudeLock();
107 double apAltitude = FGBFI::getAPAltitude();
108 const string &targetAirport = FGBFI::getTargetAirport();
109 bool gpsLock = FGBFI::getGPSLock();
110 // double gpsLatitude = FGBFI::getGPSTargetLatitude();
111 // double gpsLongitude = FGBFI::getGPSTargetLongitude();
113 FGBFI::setTargetAirport("");
114 cout << "Target airport is " << globals->get_options()->get_airport_id() << endl;
116 fgReInitSubsystems();
118 // FIXME: this is wrong.
119 // All of these are scheduled events,
120 // and it should be possible to force
121 // them all to run once.
124 cur_light_params.Update();
126 fgUpdateWeatherDatabase();
129 // Restore all of the old states.
130 FGBFI::setElevator(elevator);
131 FGBFI::setAileron(aileron);
132 FGBFI::setRudder(rudder);
133 FGBFI::setThrottle(throttle);
134 FGBFI::setElevatorTrim(elevator_trim);
135 FGBFI::setFlaps(flaps);
136 FGBFI::setBrakes(brake);
137 FGBFI::setAPHeadingLock(apHeadingLock);
138 FGBFI::setAPHeadingMag(apHeadingMag);
139 FGBFI::setAPAltitudeLock(apAltitudeLock);
140 FGBFI::setAPAltitude(apAltitude);
141 FGBFI::setTargetAirport(targetAirport);
142 FGBFI::setGPSLock(gpsLock);
146 cout << "BFI: end reinit\n";
151 ////////////////////////////////////////////////////////////////////////
153 ////////////////////////////////////////////////////////////////////////
157 * Initialize the BFI by binding its functions to properties.
159 * TODO: perhaps these should migrate into the individual modules
160 * (i.e. they should register themselves).
165 FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init");
167 current_properties.tieInt("/sim/flight-model",
168 getFlightModel, setFlightModel);
169 current_properties.tieString("/sim/aircraft",
170 getAircraft, setAircraft);
171 current_properties.tieString("/sim/aircraft-dir",
172 getAircraftDir, setAircraftDir);
174 current_properties.tieString("/sim/time/gmt",
175 getDateString, setDateString);
176 current_properties.tieString("/sim/time/gmt-string",
178 current_properties.tieBool("/sim/hud/visibility",
179 getHUDVisible, setHUDVisible);
180 current_properties.tieBool("/sim/panel/visibility",
181 getPanelVisible, setPanelVisible);
182 current_properties.tieInt("/sim/panel/x-offset",
183 getPanelXOffset, setPanelXOffset);
184 current_properties.tieInt("/sim/panel/y-offset",
185 getPanelYOffset, setPanelYOffset);
188 current_properties.tieString("/position/airport-id",
189 getTargetAirport, setTargetAirport);
190 current_properties.tieDouble("/position/latitude",
191 getLatitude, setLatitude);
192 current_properties.tieDouble("/position/longitude",
193 getLongitude, setLongitude);
194 current_properties.tieDouble("/position/altitude",
195 getAltitude, setAltitude);
196 // getAltitude, setAltitude, false);
197 current_properties.tieDouble("/position/altitude-agl",
201 current_properties.tieDouble("/orientation/heading",
202 getHeading, setHeading);
203 current_properties.tieDouble("/orientation/heading-magnetic",
205 current_properties.tieDouble("/orientation/pitch",
207 current_properties.tieDouble("/orientation/roll",
211 current_properties.tieDouble("/engines/engine0/rpm",
213 current_properties.tieDouble("/engines/engine0/egt",
215 current_properties.tieDouble("/engines/engine0/cht",
217 current_properties.tieDouble("/engines/engine0/mp",
221 current_properties.tieDouble("/velocities/airspeed",
222 getAirspeed, setAirspeed);
223 current_properties.tieDouble("/velocities/side-slip",
225 current_properties.tieDouble("/velocities/vertical-speed",
226 getVerticalSpeed, 0);
227 current_properties.tieDouble("/velocities/speed-north",
229 current_properties.tieDouble("/velocities/speed-east",
231 current_properties.tieDouble("/velocities/speed-down",
235 current_properties.tieDouble("/controls/throttle",
236 getThrottle, setThrottle);
237 current_properties.tieDouble("/controls/mixture",
238 getMixture, setMixture);
239 current_properties.tieDouble("/controls/propellor-pitch",
240 getPropAdvance, setPropAdvance);
241 current_properties.tieDouble("/controls/flaps",
243 current_properties.tieDouble("/controls/aileron",
244 getAileron, setAileron);
245 current_properties.tieDouble("/controls/rudder",
246 getRudder, setRudder);
247 current_properties.tieDouble("/controls/elevator",
248 getElevator, setElevator);
249 current_properties.tieDouble("/controls/elevator-trim",
250 getElevatorTrim, setElevatorTrim);
251 current_properties.tieDouble("/controls/brakes/all",
252 getBrakes, setBrakes);
253 current_properties.tieDouble("/controls/brakes/left",
254 getLeftBrake, setLeftBrake);
255 current_properties.tieDouble("/controls/brakes/right",
256 getRightBrake, setRightBrake);
257 current_properties.tieDouble("/controls/brakes/center",
258 getRightBrake, setCenterBrake);
261 current_properties.tieBool("/autopilot/locks/altitude",
262 getAPAltitudeLock, setAPAltitudeLock);
263 current_properties.tieDouble("/autopilot/settings/altitude",
264 getAPAltitude, setAPAltitude);
265 current_properties.tieBool("/autopilot/locks/heading",
266 getAPHeadingLock, setAPHeadingLock);
267 current_properties.tieDouble("/autopilot/settings/heading",
268 getAPHeading, setAPHeading);
269 current_properties.tieDouble("/autopilot/settings/heading-magnetic",
270 getAPHeadingMag, setAPHeadingMag);
271 current_properties.tieBool("/autopilot/locks/nav1",
272 getAPNAV1Lock, setAPNAV1Lock);
275 current_properties.tieDouble("/radios/nav1/frequencies/selected",
276 getNAV1Freq, setNAV1Freq);
277 current_properties.tieDouble("/radios/nav1/frequencies/standby",
278 getNAV1AltFreq, setNAV1AltFreq);
279 current_properties.tieDouble("/radios/nav1/radials/actual",
281 current_properties.tieDouble("/radios/nav1/radials/selected",
282 getNAV1SelRadial, setNAV1SelRadial);
283 current_properties.tieDouble("/radios/nav1/dme/distance",
285 current_properties.tieBool("/radios/nav1/to-flag",
287 current_properties.tieBool("/radios/nav1/from-flag",
289 current_properties.tieBool("/radios/nav1/in-range",
291 current_properties.tieBool("/radios/nav1/dme/in-range",
292 getNAV1DMEInRange, 0);
294 current_properties.tieDouble("/radios/nav2/frequencies/selected",
295 getNAV2Freq, setNAV2Freq);
296 current_properties.tieDouble("/radios/nav2/frequencies/standby",
297 getNAV2AltFreq, setNAV2AltFreq);
298 current_properties.tieDouble("/radios/nav2/radials/actual",
300 current_properties.tieDouble("/radios/nav2/radials/selected",
301 getNAV2SelRadial, setNAV2SelRadial);
302 current_properties.tieDouble("/radios/nav2/dme/distance",
304 current_properties.tieBool("/radios/nav2/to-flag",
306 current_properties.tieBool("/radios/nav2/from-flag",
308 current_properties.tieBool("/radios/nav2/in-range",
310 current_properties.tieBool("/radios/nav2/dme/in-range",
311 getNAV2DMEInRange, 0);
313 current_properties.tieDouble("/radios/adf/frequencies/selected",
314 getADFFreq, setADFFreq);
315 current_properties.tieDouble("/radios/adf/frequencies/standby",
316 getADFAltFreq, setADFAltFreq);
317 current_properties.tieDouble("/radios/adf/rotation",
318 getADFRotation, setADFRotation);
320 current_properties.tieDouble("/environment/visibility",
321 getVisibility, setVisibility);
325 FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
330 * Reinitialize FGFS if required.
332 * Some changes (especially those in aircraft position) require that
333 * FGFS be reinitialized afterwards. Rather than reinitialize after
334 * every change, the setter methods simply set a flag so that there
335 * can be a single reinit at the end of the frame.
347 ////////////////////////////////////////////////////////////////////////
349 ////////////////////////////////////////////////////////////////////////
353 * Return the flight model as an integer.
355 * TODO: use a string instead.
358 FGBFI::getFlightModel ()
360 return globals->get_options()->get_flight_model();
365 * Return the current aircraft as a string.
368 FGBFI::getAircraft ()
370 _temp = globals->get_options()->get_aircraft();
376 * Return the current aircraft directory (UIUC) as a string.
379 FGBFI::getAircraftDir ()
381 _temp = aircraft_dir;
387 * Set the flight model as an integer.
389 * TODO: use a string instead.
392 FGBFI::setFlightModel (int model)
394 if (getFlightModel() != model) {
395 globals->get_options()->set_flight_model(model);
402 * Set the current aircraft.
405 FGBFI::setAircraft (const string &aircraft)
407 if (getAircraft() != aircraft) {
408 globals->get_options()->set_aircraft(aircraft);
415 * Set the current aircraft directory (UIUC).
418 FGBFI::setAircraftDir (const string &dir)
420 if (getAircraftDir() != dir) {
428 * Return the current Zulu time.
431 FGBFI::getDateString ()
433 static string out; // FIXME: not thread-safe
435 struct tm * t = globals->get_time_params()->getGmt();
436 sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
437 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
438 t->tm_hour, t->tm_min, t->tm_sec);
445 * Set the current Zulu time.
448 FGBFI::setDateString (const string &date_string)
449 // FGBFI::setTimeGMT (time_t time)
451 SGTime * st = globals->get_time_params();
452 struct tm * current_time = st->getGmt();
455 // Scan for basic ISO format
456 // YYYY-MM-DDTHH:MM:SS
457 int ret = sscanf(date_string.c_str(), "%d-%d-%dT%d:%d:%d",
458 &(new_time.tm_year), &(new_time.tm_mon),
459 &(new_time.tm_mday), &(new_time.tm_hour),
460 &(new_time.tm_min), &(new_time.tm_sec));
462 // Be pretty picky about this, so
463 // that strange things don't happen
464 // if the save file has been edited
467 FG_LOG(FG_INPUT, FG_ALERT, "Date/time string " << date_string
468 << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
472 // OK, it looks like we got six
473 // values, one way or another.
474 new_time.tm_year -= 1900;
475 new_time.tm_mon -= 1;
477 // Now, tell flight gear to use
478 // the new time. This was far
479 // too difficult, by the way.
481 mktime(&new_time) - mktime(current_time) + globals->get_warp();
482 double lon = current_aircraft.fdm_state->get_Longitude();
483 double lat = current_aircraft.fdm_state->get_Latitude();
484 double alt = current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER;
485 globals->set_warp(warp);
486 st->update(lon, lat, warp);
487 fgUpdateSkyAndLightingParams();
492 * Return the GMT as a string.
495 FGBFI::getGMTString ()
497 static string out; // FIXME: not thread-safe
499 struct tm * t = globals->get_time_params()->getGmt();
500 sprintf(buf, " %.2d:%.2d:%.2d",
501 t->tm_hour, t->tm_min, t->tm_sec);
508 * Return true if the HUD is visible.
511 FGBFI::getHUDVisible ()
513 return globals->get_options()->get_hud_status();
518 * Ensure that the HUD is visible or hidden.
521 FGBFI::setHUDVisible (bool visible)
523 globals->get_options()->set_hud_status(visible);
528 * Return true if the 2D panel is visible.
531 FGBFI::getPanelVisible ()
533 return globals->get_options()->get_panel_status();
538 * Ensure that the 2D panel is visible or hidden.
541 FGBFI::setPanelVisible (bool visible)
543 if (globals->get_options()->get_panel_status() != visible) {
544 globals->get_options()->toggle_panel();
550 * Get the panel's current x-shift.
553 FGBFI::getPanelXOffset ()
555 if (current_panel != 0)
556 return current_panel->getXOffset();
563 * Set the panel's current x-shift.
566 FGBFI::setPanelXOffset (int offset)
568 if (current_panel != 0)
569 current_panel->setXOffset(offset);
574 * Get the panel's current y-shift.
577 FGBFI::getPanelYOffset ()
579 if (current_panel != 0)
580 return current_panel->getYOffset();
587 * Set the panel's current y-shift.
590 FGBFI::setPanelYOffset (int offset)
592 if (current_panel != 0)
593 current_panel->setYOffset(offset);
600 ////////////////////////////////////////////////////////////////////////
602 ////////////////////////////////////////////////////////////////////////
606 * Return the current latitude in degrees (negative for south).
609 FGBFI::getLatitude ()
611 return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
616 * Set the current latitude in degrees (negative for south).
619 FGBFI::setLatitude (double latitude)
621 current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
622 fgUpdateSkyAndLightingParams();
627 * Return the current longitude in degrees (negative for west).
630 FGBFI::getLongitude ()
632 return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
637 * Set the current longitude in degrees (negative for west).
640 FGBFI::setLongitude (double longitude)
642 current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
643 fgUpdateSkyAndLightingParams();
648 * Return the current altitude in feet.
651 FGBFI::getAltitude ()
653 return current_aircraft.fdm_state->get_Altitude();
659 * Return the current altitude in above the terrain.
664 return current_aircraft.fdm_state->get_Altitude()
665 - (scenery.cur_elev * METER_TO_FEET);
670 * Set the current altitude in feet.
673 FGBFI::setAltitude (double altitude)
675 current_aircraft.fdm_state->set_Altitude(altitude);
676 fgUpdateSkyAndLightingParams();
681 ////////////////////////////////////////////////////////////////////////
683 ////////////////////////////////////////////////////////////////////////
687 * Return the current heading in degrees.
692 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
697 * Return the current heading in degrees.
700 FGBFI::getHeadingMag ()
702 return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
707 * Set the current heading in degrees.
710 FGBFI::setHeading (double heading)
712 FGInterface * fdm = current_aircraft.fdm_state;
713 fdm->set_Euler_Angles(fdm->get_Phi(), fdm->get_Theta(),
714 heading * DEG_TO_RAD);
719 * Return the current pitch in degrees.
724 return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
729 * Set the current pitch in degrees.
732 FGBFI::setPitch (double pitch)
734 FGInterface * fdm = current_aircraft.fdm_state;
735 fdm->set_Euler_Angles(fdm->get_Phi(), pitch * DEG_TO_RAD, fdm->get_Psi());
740 * Return the current roll in degrees.
745 return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
750 * Set the current roll in degrees.
753 FGBFI::setRoll (double roll)
755 FGInterface * fdm = current_aircraft.fdm_state;
756 fdm->set_Euler_Angles(roll * DEG_TO_RAD, fdm->get_Theta(), fdm->get_Psi());
761 * Return the current engine0 rpm
766 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
767 return current_aircraft.fdm_state->get_engine(0)->get_RPM();
775 * Set the current engine0 rpm
778 FGBFI::setRPM (double rpm)
780 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
781 if (getRPM() != rpm) {
782 current_aircraft.fdm_state->get_engine(0)->set_RPM( rpm );
789 * Return the current engine0 EGT.
794 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
795 return current_aircraft.fdm_state->get_engine(0)->get_EGT();
803 * Return the current engine0 CHT.
808 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
809 return current_aircraft.fdm_state->get_engine(0)->get_CHT();
817 * Return the current engine0 CHT.
822 if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
823 return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
831 ////////////////////////////////////////////////////////////////////////
833 ////////////////////////////////////////////////////////////////////////
837 * Return the current airspeed in knots.
840 FGBFI::getAirspeed ()
842 // FIXME: should we add speed-up?
843 return current_aircraft.fdm_state->get_V_calibrated_kts();
848 * Set the calibrated airspeed in knots.
851 FGBFI::setAirspeed (double speed)
853 current_aircraft.fdm_state->set_V_calibrated_kts(speed);
858 * Return the current sideslip (FIXME: units unknown).
861 FGBFI::getSideSlip ()
863 return current_aircraft.fdm_state->get_Beta();
868 * Return the current climb rate in feet/minute
871 FGBFI::getVerticalSpeed ()
873 // What about meters?
874 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
879 * Get the current north velocity (units??).
882 FGBFI::getSpeedNorth ()
884 return current_aircraft.fdm_state->get_V_north();
889 // * Set the current north velocity (units??).
892 // FGBFI::setSpeedNorth (double speed)
894 // FGInterface * fdm = current_aircraft.fdm_state;
895 // // fdm->set_Velocities_Local(speed, fdm->get_V_east(), fdm->get_V_down());
900 * Get the current east velocity (units??).
903 FGBFI::getSpeedEast ()
905 return current_aircraft.fdm_state->get_V_east();
910 // * Set the current east velocity (units??).
913 // FGBFI::setSpeedEast (double speed)
915 // FGInterface * fdm = current_aircraft.fdm_state;
916 // // fdm->set_Velocities_Local(fdm->get_V_north(), speed, fdm->get_V_down());
921 * Get the current down velocity (units??).
924 FGBFI::getSpeedDown ()
926 return current_aircraft.fdm_state->get_V_down();
931 // * Set the current down velocity (units??).
934 // FGBFI::setSpeedDown (double speed)
936 // FGInterface * fdm = current_aircraft.fdm_state;
937 // // fdm->set_Velocities_Local(fdm->get_V_north(), fdm->get_V_east(), speed);
942 ////////////////////////////////////////////////////////////////////////
944 ////////////////////////////////////////////////////////////////////////
948 * Get the throttle setting, from 0.0 (none) to 1.0 (full).
951 FGBFI::getThrottle ()
953 // FIXME: add engine selector
954 return controls.get_throttle(0);
959 * Set the throttle, from 0.0 (none) to 1.0 (full).
962 FGBFI::setThrottle (double throttle)
964 // FIXME: allow engine selection
965 controls.set_throttle(0, throttle);
970 * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
975 // FIXME: add engine selector
976 return controls.get_mixture(0);
981 * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
984 FGBFI::setMixture (double mixture)
986 // FIXME: allow engine selection
987 controls.set_mixture(0, mixture);
992 * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
995 FGBFI::getPropAdvance ()
997 // FIXME: add engine selector
998 return controls.get_prop_advance(0);
1003 * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
1006 FGBFI::setPropAdvance (double pitch)
1008 // FIXME: allow engine selection
1009 controls.set_prop_advance(0, pitch);
1014 * Get the flaps setting, from 0.0 (none) to 1.0 (full).
1019 return controls.get_flaps();
1024 * Set the flaps, from 0.0 (none) to 1.0 (full).
1027 FGBFI::setFlaps (double flaps)
1030 controls.set_flaps(flaps);
1035 * Get the aileron, from -1.0 (left) to 1.0 (right).
1038 FGBFI::getAileron ()
1040 return controls.get_aileron();
1045 * Set the aileron, from -1.0 (left) to 1.0 (right).
1048 FGBFI::setAileron (double aileron)
1051 controls.set_aileron(aileron);
1056 * Get the rudder setting, from -1.0 (left) to 1.0 (right).
1061 return controls.get_rudder();
1066 * Set the rudder, from -1.0 (left) to 1.0 (right).
1069 FGBFI::setRudder (double rudder)
1072 controls.set_rudder(rudder);
1077 * Get the elevator setting, from -1.0 (down) to 1.0 (up).
1080 FGBFI::getElevator ()
1082 return controls.get_elevator();
1087 * Set the elevator, from -1.0 (down) to 1.0 (up).
1090 FGBFI::setElevator (double elevator)
1093 controls.set_elevator(elevator);
1098 * Get the elevator trim, from -1.0 (down) to 1.0 (up).
1101 FGBFI::getElevatorTrim ()
1103 return controls.get_elevator_trim();
1108 * Set the elevator trim, from -1.0 (down) to 1.0 (up).
1111 FGBFI::setElevatorTrim (double trim)
1114 controls.set_elevator_trim(trim);
1119 * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
1124 double b1 = getCenterBrake();
1125 double b2 = getLeftBrake();
1126 double b3 = getRightBrake();
1127 return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
1132 * Set all brakes, from 0.0 (none) to 1.0 (full).
1135 FGBFI::setBrakes (double brake)
1137 setCenterBrake(brake);
1138 setLeftBrake(brake);
1139 setRightBrake(brake);
1144 * Get the center brake, from 0.0 (none) to 1.0 (full).
1147 FGBFI::getCenterBrake ()
1149 return controls.get_brake(2);
1154 * Set the center brake, from 0.0 (none) to 1.0 (full).
1157 FGBFI::setCenterBrake (double brake)
1159 controls.set_brake(2, brake);
1164 * Get the left brake, from 0.0 (none) to 1.0 (full).
1167 FGBFI::getLeftBrake ()
1169 return controls.get_brake(0);
1174 * Set the left brake, from 0.0 (none) to 1.0 (full).
1177 FGBFI::setLeftBrake (double brake)
1179 controls.set_brake(0, brake);
1184 * Get the right brake, from 0.0 (none) to 1.0 (full).
1187 FGBFI::getRightBrake ()
1189 return controls.get_brake(1);
1194 * Set the right brake, from 0.0 (none) to 1.0 (full).
1197 FGBFI::setRightBrake (double brake)
1199 controls.set_brake(1, brake);
1206 ////////////////////////////////////////////////////////////////////////
1208 ////////////////////////////////////////////////////////////////////////
1212 * Get the autopilot altitude lock (true=on).
1215 FGBFI::getAPAltitudeLock ()
1217 return current_autopilot->get_AltitudeEnabled();
1222 * Set the autopilot altitude lock (true=on).
1225 FGBFI::setAPAltitudeLock (bool lock)
1227 current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
1228 current_autopilot->set_AltitudeEnabled(lock);
1233 * Get the autopilot target altitude in feet.
1236 FGBFI::getAPAltitude ()
1238 return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
1243 * Set the autopilot target altitude in feet.
1246 FGBFI::setAPAltitude (double altitude)
1248 current_autopilot->set_TargetAltitude( altitude );
1253 * Get the autopilot heading lock (true=on).
1256 FGBFI::getAPHeadingLock ()
1259 (current_autopilot->get_HeadingEnabled() &&
1260 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
1265 * Set the autopilot heading lock (true=on).
1268 FGBFI::setAPHeadingLock (bool lock)
1271 // We need to do this so that
1272 // it's possible to lock onto a
1273 // heading other than the current
1275 double heading = getAPHeadingMag();
1276 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
1277 current_autopilot->set_HeadingEnabled(true);
1278 setAPHeadingMag(heading);
1279 } else if (current_autopilot->get_HeadingMode() ==
1280 FGAutopilot::FG_HEADING_LOCK) {
1281 current_autopilot->set_HeadingEnabled(false);
1287 * Get the autopilot target heading in degrees.
1290 FGBFI::getAPHeading ()
1292 return current_autopilot->get_TargetHeading();
1297 * Set the autopilot target heading in degrees.
1300 FGBFI::setAPHeading (double heading)
1302 current_autopilot->set_TargetHeading( heading );
1307 * Get the autopilot target heading in degrees.
1310 FGBFI::getAPHeadingMag ()
1312 return current_autopilot->get_TargetHeading() - getMagVar();
1317 * Set the autopilot target heading in degrees.
1320 FGBFI::setAPHeadingMag (double heading)
1322 current_autopilot->set_TargetHeading( heading + getMagVar() );
1327 * Return true if the autopilot is locked to NAV1.
1330 FGBFI::getAPNAV1Lock ()
1333 (current_autopilot->get_HeadingEnabled() &&
1334 current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
1339 * Set the autopilot NAV1 lock.
1342 FGBFI::setAPNAV1Lock (bool lock)
1345 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
1346 current_autopilot->set_HeadingEnabled(true);
1347 } else if (current_autopilot->get_HeadingMode() ==
1348 FGAutopilot::FG_HEADING_NAV1) {
1349 current_autopilot->set_HeadingEnabled(false);
1355 ////////////////////////////////////////////////////////////////////////
1356 // Radio navigation.
1357 ////////////////////////////////////////////////////////////////////////
1360 FGBFI::getNAV1Freq ()
1362 return current_radiostack->get_nav1_freq();
1366 FGBFI::getNAV1AltFreq ()
1368 return current_radiostack->get_nav1_alt_freq();
1372 FGBFI::getNAV1Radial ()
1374 return current_radiostack->get_nav1_radial();
1378 FGBFI::getNAV1SelRadial ()
1380 return current_radiostack->get_nav1_sel_radial();
1384 FGBFI::getNAV1DistDME ()
1386 return current_radiostack->get_nav1_dme_dist();
1392 if (current_radiostack->get_nav1_inrange()) {
1393 double heading = current_radiostack->get_nav1_heading();
1394 double radial = current_radiostack->get_nav1_radial();
1395 double var = FGBFI::getMagVar();
1396 if (current_radiostack->get_nav1_loc()) {
1397 double offset = fabs(heading - radial);
1398 return (offset<= 8.0 || offset >= 352.0);
1401 fabs(heading - var - radial);
1402 return (offset <= 20.0 || offset >= 340.0);
1410 FGBFI::getNAV1FROM ()
1412 if (current_radiostack->get_nav1_inrange()) {
1413 double heading = current_radiostack->get_nav1_heading();
1414 double radial = current_radiostack->get_nav1_radial();
1415 double var = FGBFI::getMagVar();
1416 if (current_radiostack->get_nav1_loc()) {
1417 double offset = fabs(heading - radial);
1418 return (offset >= 172.0 && offset<= 188.0);
1421 fabs(heading - var - radial);
1422 return (offset >= 160.0 && offset <= 200.0);
1430 FGBFI::getNAV1InRange ()
1432 return current_radiostack->get_nav1_inrange();
1436 FGBFI::getNAV1DMEInRange ()
1438 return (current_radiostack->get_nav1_inrange() &&
1439 current_radiostack->get_nav1_has_dme());
1443 FGBFI::getNAV2Freq ()
1445 return current_radiostack->get_nav2_freq();
1449 FGBFI::getNAV2AltFreq ()
1451 return current_radiostack->get_nav2_alt_freq();
1455 FGBFI::getNAV2Radial ()
1457 return current_radiostack->get_nav2_radial();
1461 FGBFI::getNAV2SelRadial ()
1463 return current_radiostack->get_nav2_sel_radial();
1467 FGBFI::getNAV2DistDME ()
1469 return current_radiostack->get_nav2_dme_dist();
1475 if (current_radiostack->get_nav2_inrange()) {
1476 double heading = current_radiostack->get_nav2_heading();
1477 double radial = current_radiostack->get_nav2_radial();
1478 double var = FGBFI::getMagVar();
1479 if (current_radiostack->get_nav2_loc()) {
1480 double offset = fabs(heading - radial);
1481 return (offset<= 8.0 || offset >= 352.0);
1484 fabs(heading - var - radial);
1485 return (offset <= 20.0 || offset >= 340.0);
1493 FGBFI::getNAV2FROM ()
1495 if (current_radiostack->get_nav2_inrange()) {
1496 double heading = current_radiostack->get_nav2_heading();
1497 double radial = current_radiostack->get_nav2_radial();
1498 double var = FGBFI::getMagVar();
1499 if (current_radiostack->get_nav2_loc()) {
1500 double offset = fabs(heading - radial);
1501 return (offset >= 172.0 && offset<= 188.0);
1504 fabs(heading - var - radial);
1505 return (offset >= 160.0 && offset <= 200.0);
1514 FGBFI::getNAV2InRange ()
1516 return current_radiostack->get_nav2_inrange();
1520 FGBFI::getNAV2DMEInRange ()
1522 return (current_radiostack->get_nav2_inrange() &&
1523 current_radiostack->get_nav2_has_dme());
1527 FGBFI::getADFFreq ()
1529 return current_radiostack->get_adf_freq();
1533 FGBFI::getADFAltFreq ()
1535 return current_radiostack->get_adf_alt_freq();
1539 FGBFI::getADFRotation ()
1541 return current_radiostack->get_adf_rotation();
1545 FGBFI::setNAV1Freq (double freq)
1547 current_radiostack->set_nav1_freq(freq);
1551 FGBFI::setNAV1AltFreq (double freq)
1553 current_radiostack->set_nav1_alt_freq(freq);
1557 FGBFI::setNAV1SelRadial (double radial)
1559 current_radiostack->set_nav1_sel_radial(radial);
1563 FGBFI::setNAV2Freq (double freq)
1565 current_radiostack->set_nav2_freq(freq);
1569 FGBFI::setNAV2AltFreq (double freq)
1571 current_radiostack->set_nav2_alt_freq(freq);
1575 FGBFI::setNAV2SelRadial (double radial)
1577 current_radiostack->set_nav2_sel_radial(radial);
1581 FGBFI::setADFFreq (double freq)
1583 current_radiostack->set_adf_freq(freq);
1587 FGBFI::setADFAltFreq (double freq)
1589 current_radiostack->set_adf_alt_freq(freq);
1593 FGBFI::setADFRotation (double rot)
1595 current_radiostack->set_adf_rotation(rot);
1600 ////////////////////////////////////////////////////////////////////////
1602 ////////////////////////////////////////////////////////////////////////
1606 * Get the autopilot GPS lock (true=on).
1609 FGBFI::getGPSLock ()
1611 return (current_autopilot->get_HeadingEnabled() &&
1612 (current_autopilot->get_HeadingMode() ==
1613 FGAutopilot::FG_HEADING_WAYPOINT ));
1618 * Set the autopilot GPS lock (true=on).
1621 FGBFI::setGPSLock (bool lock)
1624 current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
1625 current_autopilot->set_HeadingEnabled(true);
1626 } else if (current_autopilot->get_HeadingMode() ==
1627 FGAutopilot::FG_HEADING_WAYPOINT) {
1628 current_autopilot->set_HeadingEnabled(false);
1634 * Get the GPS target airport code.
1637 FGBFI::getTargetAirport ()
1639 // FIXME: not thread-safe
1641 out = globals->get_options()->get_airport_id();
1648 * Set the GPS target airport code.
1651 FGBFI::setTargetAirport (const string &airportId)
1653 // cout << "setting target airport id = " << airportId << endl;
1654 globals->get_options()->set_airport_id(airportId);
1659 * Get the GPS target latitude in degrees (negative for south).
1662 FGBFI::getGPSTargetLatitude ()
1664 return current_autopilot->get_TargetLatitude();
1669 * Get the GPS target longitude in degrees (negative for west).
1672 FGBFI::getGPSTargetLongitude ()
1674 return current_autopilot->get_TargetLongitude();
1679 * Set the GPS target longitude in degrees (negative for west).
1682 FGBFI::setGPSTargetLongitude (double longitude)
1684 current_autopilot->set_TargetLongitude( longitude );
1690 ////////////////////////////////////////////////////////////////////////
1692 ////////////////////////////////////////////////////////////////////////
1696 * Get the current visible (units??).
1699 FGBFI::getVisibility ()
1701 #ifndef FG_OLD_WEATHER
1702 return WeatherDatabase->getWeatherVisibility();
1704 return current_weather.get_visibility();
1710 * Set the current visibility (units??).
1713 FGBFI::setVisibility (double visibility)
1715 #ifndef FG_OLD_WEATHER
1716 WeatherDatabase->setWeatherVisibility(visibility);
1718 current_weather.set_visibility(visibility);
1724 ////////////////////////////////////////////////////////////////////////
1726 ////////////////////////////////////////////////////////////////////////
1729 * Return the magnetic variation
1734 return globals->get_mag()->get_magvar() * RAD_TO_DEG;
1739 * Return the magnetic variation
1744 return globals->get_mag()->get_magdip() * RAD_TO_DEG;