X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Fbfi.cxx;h=1137c0359c2bfe4d174d4ebf0b846ae89d4f9785;hb=a6e0a696376ba2d426eb534bb83ec42038a501e7;hp=3707f4e8ed96f64905e783a3242804cc0de199bc;hpb=2aca8ca2cf9ecef0f28cdc4f3f7882de0d042e33;p=flightgear.git diff --git a/src/Main/bfi.cxx b/src/Main/bfi.cxx index 3707f4e8e..1137c0359 100644 --- a/src/Main/bfi.cxx +++ b/src/Main/bfi.cxx @@ -181,6 +181,8 @@ FGBFI::init () // Simulation fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir); + fgTie("/sim/view/offset", getViewOffset, setViewOffset); + fgTie("/sim/view/goal-offset", getGoalViewOffset, setGoalViewOffset); fgTie("/sim/time/gmt", getDateString, setDateString); fgTie("/sim/time/gmt-string", getGMTString); @@ -201,12 +203,21 @@ FGBFI::init () // Autopilot fgTie("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock); fgTie("/autopilot/settings/altitude", getAPAltitude, setAPAltitude); + fgTie("/autopilot/locks/glide-slope", getAPGSLock, setAPGSLock); fgTie("/autopilot/settings/climb-rate", getAPClimb, setAPClimb, false); fgTie("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock); fgTie("/autopilot/settings/heading-bug", getAPHeadingBug, setAPHeadingBug, false); fgTie("/autopilot/locks/wing-leveler", getAPWingLeveler, setAPWingLeveler); fgTie("/autopilot/locks/nav1", getAPNAV1Lock, setAPNAV1Lock); + fgTie("/autopilot/locks/auto-throttle", + getAPAutoThrottleLock, setAPAutoThrottleLock); + fgTie("/autopilot/control-overrides/rudder", + getAPRudderControl, setAPRudderControl); + fgTie("/autopilot/control-overrides/elevator", + getAPElevatorControl, setAPElevatorControl); + fgTie("/autopilot/control-overrides/throttle", + getAPThrottleControl, setAPThrottleControl); // Weather fgTie("/environment/visibility", getVisibility, setVisibility); @@ -272,6 +283,39 @@ FGBFI::setAircraftDir (string dir) } +/** + * Get the current view offset in degrees. + */ +double +FGBFI::getViewOffset () +{ + return (globals->get_current_view() + ->get_view_offset() * SGD_RADIANS_TO_DEGREES); +} + +void +FGBFI::setViewOffset (double offset) +{ + globals->get_current_view()->set_view_offset(offset * SGD_DEGREES_TO_RADIANS); +} + +double +FGBFI::getGoalViewOffset () +{ + return (globals->get_current_view() + ->get_goal_view_offset() * SGD_RADIANS_TO_DEGREES); +} + +void +FGBFI::setGoalViewOffset (double offset) +{ + globals->get_current_view() + ->set_goal_view_offset(offset * SGD_DEGREES_TO_RADIANS); +} + + + + /** * Return the current Zulu time. */ @@ -739,280 +783,36 @@ FGBFI::getSpeedDown () //////////////////////////////////////////////////////////////////////// -// Controls +// Autopilot //////////////////////////////////////////////////////////////////////// -#if 0 - -/** - * Get the throttle setting, from 0.0 (none) to 1.0 (full). - */ -double -FGBFI::getThrottle () -{ - // FIXME: add engine selector - return controls.get_throttle(0); -} - - -/** - * Set the throttle, from 0.0 (none) to 1.0 (full). - */ -void -FGBFI::setThrottle (double throttle) -{ - // FIXME: allow engine selection - controls.set_throttle(0, throttle); -} - - -/** - * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full). - */ -double -FGBFI::getMixture () -{ - // FIXME: add engine selector - return controls.get_mixture(0); -} - - -/** - * Set the fuel mixture, from 0.0 (none) to 1.0 (full). - */ -void -FGBFI::setMixture (double mixture) -{ - // FIXME: allow engine selection - controls.set_mixture(0, mixture); -} - - -/** - * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full). - */ -double -FGBFI::getPropAdvance () -{ - // FIXME: add engine selector - return controls.get_prop_advance(0); -} - - -/** - * Set the propellor pitch, from 0.0 (none) to 1.0 (full). - */ -void -FGBFI::setPropAdvance (double pitch) -{ - // FIXME: allow engine selection - controls.set_prop_advance(0, pitch); -} - - -/** - * Get the flaps setting, from 0.0 (none) to 1.0 (full). - */ -double -FGBFI::getFlaps () -{ - return controls.get_flaps(); -} - - -/** - * Set the flaps, from 0.0 (none) to 1.0 (full). - */ -void -FGBFI::setFlaps (double flaps) -{ - // FIXME: clamp? - controls.set_flaps(flaps); -} - - -/** - * Get the aileron, from -1.0 (left) to 1.0 (right). - */ -double -FGBFI::getAileron () -{ - return controls.get_aileron(); -} - - -/** - * Set the aileron, from -1.0 (left) to 1.0 (right). - */ -void -FGBFI::setAileron (double aileron) -{ - // FIXME: clamp? - controls.set_aileron(aileron); -} - - -/** - * Get the rudder setting, from -1.0 (left) to 1.0 (right). - */ -double -FGBFI::getRudder () -{ - return controls.get_rudder(); -} - - -/** - * Set the rudder, from -1.0 (left) to 1.0 (right). - */ -void -FGBFI::setRudder (double rudder) -{ - // FIXME: clamp? - controls.set_rudder(rudder); -} - - -/** - * Get the elevator setting, from -1.0 (down) to 1.0 (up). - */ -double -FGBFI::getElevator () -{ - return controls.get_elevator(); -} - - -/** - * Set the elevator, from -1.0 (down) to 1.0 (up). - */ -void -FGBFI::setElevator (double elevator) -{ - // FIXME: clamp? - controls.set_elevator(elevator); -} - - -/** - * Get the elevator trim, from -1.0 (down) to 1.0 (up). - */ -double -FGBFI::getElevatorTrim () -{ - return controls.get_elevator_trim(); -} - - -/** - * Set the elevator trim, from -1.0 (down) to 1.0 (up). - */ -void -FGBFI::setElevatorTrim (double trim) -{ - // FIXME: clamp? - controls.set_elevator_trim(trim); -} - - -/** - * Get the highest brake setting, from 0.0 (none) to 1.0 (full). - */ -double -FGBFI::getBrakes () -{ - double b1 = getCenterBrake(); - double b2 = getLeftBrake(); - double b3 = getRightBrake(); - return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3)); -} - - -/** - * Set all brakes, from 0.0 (none) to 1.0 (full). - */ -void -FGBFI::setBrakes (double brake) -{ - setCenterBrake(brake); - setLeftBrake(brake); - setRightBrake(brake); -} - - -/** - * Get the center brake, from 0.0 (none) to 1.0 (full). - */ -double -FGBFI::getCenterBrake () -{ - return controls.get_brake(2); -} - - -/** - * Set the center brake, from 0.0 (none) to 1.0 (full). - */ -void -FGBFI::setCenterBrake (double brake) -{ - controls.set_brake(2, brake); -} - /** - * Get the left brake, from 0.0 (none) to 1.0 (full). + * Get the autopilot altitude lock (true=on). */ -double -FGBFI::getLeftBrake () +bool +FGBFI::getAPAltitudeLock () { - return controls.get_brake(0); + return current_autopilot->get_AltitudeEnabled(); } /** - * Set the left brake, from 0.0 (none) to 1.0 (full). + * Set the autopilot altitude lock (true=on). */ void -FGBFI::setLeftBrake (double brake) -{ - controls.set_brake(0, brake); -} - - -/** - * Get the right brake, from 0.0 (none) to 1.0 (full). - */ -double -FGBFI::getRightBrake () +FGBFI::setAPAltitudeLock (bool lock) { - return controls.get_brake(1); + current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK); + current_autopilot->set_AltitudeEnabled(lock); } -/** - * Set the right brake, from 0.0 (none) to 1.0 (full). - */ -void -FGBFI::setRightBrake (double brake) -{ - controls.set_brake(1, brake); -} - - -#endif - - -//////////////////////////////////////////////////////////////////////// -// Autopilot -//////////////////////////////////////////////////////////////////////// - - /** * Get the autopilot altitude lock (true=on). */ bool -FGBFI::getAPAltitudeLock () +FGBFI::getAPGSLock () { return current_autopilot->get_AltitudeEnabled(); } @@ -1022,9 +822,9 @@ FGBFI::getAPAltitudeLock () * Set the autopilot altitude lock (true=on). */ void -FGBFI::setAPAltitudeLock (bool lock) +FGBFI::setAPGSLock (bool lock) { - current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK); + current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_GS1); current_autopilot->set_AltitudeEnabled(lock); } @@ -1077,7 +877,7 @@ FGBFI::getAPHeadingLock () { return (current_autopilot->get_HeadingEnabled() && - current_autopilot->get_HeadingMode() == FGAutopilot::FG_DG_HEADING_LOCK); + current_autopilot->get_HeadingMode() == DEFAULT_AP_HEADING_LOCK); } @@ -1088,7 +888,7 @@ void FGBFI::setAPHeadingLock (bool lock) { if (lock) { - current_autopilot->set_HeadingMode(FGAutopilot::FG_DG_HEADING_LOCK); + current_autopilot->set_HeadingMode(DEFAULT_AP_HEADING_LOCK); current_autopilot->set_HeadingEnabled(true); } else { current_autopilot->set_HeadingEnabled(false); @@ -1170,6 +970,92 @@ FGBFI::setAPNAV1Lock (bool lock) } } +/** + * Get the autopilot autothrottle lock. + */ +bool +FGBFI::getAPAutoThrottleLock () +{ + return current_autopilot->get_AutoThrottleEnabled(); +} + + +/** + * Set the autothrottle lock. + */ +void +FGBFI::setAPAutoThrottleLock (bool lock) +{ + current_autopilot->set_AutoThrottleEnabled(lock); +} + + +// kludge +double +FGBFI::getAPRudderControl () +{ + if (getAPHeadingLock()) + return current_autopilot->get_TargetHeading(); + else + return controls.get_rudder(); +} + +// kludge +void +FGBFI::setAPRudderControl (double value) +{ + if (getAPHeadingLock()) { + SG_LOG(SG_GENERAL, SG_DEBUG, "setAPRudderControl " << value ); + value -= current_autopilot->get_TargetHeading(); + current_autopilot->HeadingAdjust(value < 0.0 ? -1.0 : 1.0); + } else { + controls.set_rudder(value); + } +} + +// kludge +double +FGBFI::getAPElevatorControl () +{ + if (getAPAltitudeLock()) + return current_autopilot->get_TargetAltitude(); + else + return controls.get_elevator(); +} + +// kludge +void +FGBFI::setAPElevatorControl (double value) +{ + if (getAPAltitudeLock()) { + SG_LOG(SG_GENERAL, SG_DEBUG, "setAPElevatorControl " << value ); + value -= current_autopilot->get_TargetAltitude(); + current_autopilot->AltitudeAdjust(value < 0.0 ? 100.0 : -100.0); + } else { + controls.set_elevator(value); + } +} + +// kludge +double +FGBFI::getAPThrottleControl () +{ + if (getAPAutoThrottleLock()) + return 0.0; // always resets + else + return controls.get_throttle(0); +} + +// kludge +void +FGBFI::setAPThrottleControl (double value) +{ + if (getAPAutoThrottleLock()) + current_autopilot->AutoThrottleAdjust(value < 0.0 ? -0.01 : 0.01); + else + controls.set_throttle(0, value); +} + //////////////////////////////////////////////////////////////////////// @@ -1224,17 +1110,6 @@ FGBFI::getGPSTargetLongitude () return current_autopilot->get_TargetLongitude(); } -#if 0 -/** - * Set the GPS target longitude in degrees (negative for west). - */ -void -FGBFI::setGPSTargetLongitude (double longitude) -{ - current_autopilot->set_TargetLongitude( longitude ); -} -#endif - ////////////////////////////////////////////////////////////////////////