From 110dd605a0aa4437fad8222d6e2bca539dd0aa39 Mon Sep 17 00:00:00 2001 From: jmt Date: Sun, 11 Oct 2009 21:29:24 +0000 Subject: [PATCH] Fix unrealistic-but-convenient direct-drive from the route-manager to the autopilot code. A new boolean config prop, 'drive-autopilot' exists, to disable this behaviour. --- src/Autopilot/route_mgr.cxx | 32 +++++++++++++++++++------------- src/Autopilot/route_mgr.hxx | 8 +++++--- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index b8903685f..7fb4ac12d 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -65,11 +65,7 @@ static double get_ground_speed() { FGRouteMgr::FGRouteMgr() : _route( new SGRoute ), _autoSequence(true), - lon( NULL ), - lat( NULL ), - alt( NULL ), - target_altitude_ft( NULL ), - altitude_lock( NULL ), + _driveAutopilot(true), input(fgGetNode( RM "input", true )), mirror(fgGetNode( RM "route", true )), altitude_set( false ) @@ -96,9 +92,12 @@ void FGRouteMgr::init() { alt = fgGetNode( "/position/altitude-ft", true ); magvar = fgGetNode("/environment/magnetic-variation-deg", true); - target_altitude_ft = fgGetNode( "/autopilot/settings/target-altitude-ft", true ); - altitude_lock = fgGetNode( "/autopilot/locks/altitude", true ); - +// autopilot drive properties + _apTargetAltitudeFt = fgGetNode( "/autopilot/settings/target-altitude-ft", true ); + _apAltitudeLock = fgGetNode( "/autopilot/locks/altitude", true ); + _apTrueHeading = fgGetNode( "/autopilot/settings/true-heading-deg", true ); + rm->tie("drive-autopilot", SGRawValuePointer(&_driveAutopilot)); + departure = fgGetNode(RM "departure", true); // init departure information from current location SGGeod pos = SGGeod::fromDegFt(lon->getDoubleValue(), lat->getDoubleValue(), alt->getDoubleValue()); @@ -203,13 +202,15 @@ void FGRouteMgr::updateTargetAltitude() { } altitude_set = true; - target_altitude_ft->setDoubleValue(wp.get_target().getElevationFt()); + + if (!_driveAutopilot) { + return; + } + + _apTargetAltitudeFt->setDoubleValue(wp.get_target().getElevationFt()); if ( !near_ground() ) { - // James Turner [zakalawe]: there's no explanation for this logic, - // it feels like the autopilot should pull the target altitude out of - // wp0 instead of us pushing it through here. Hmmm. - altitude_lock->setStringValue( "altitude-hold" ); + _apAltitudeLock->setStringValue( "altitude-hold" ); } } @@ -261,6 +262,10 @@ void FGRouteMgr::update( double dt ) { } } + if (_driveAutopilot) { + _apTrueHeading->setDoubleValue(wp_course); + } + // update wp0 / wp1 / wp-last for legacy users wp0->setDoubleValue("dist", wp_distance * SG_METER_TO_NM); wp_course -= magvar->getDoubleValue(); // expose magnetic bearing @@ -639,6 +644,7 @@ void FGRouteMgr::currentWaypointChanged() } currentWp->setIntValue(_route->current_index()); + updateTargetAltitude(); SG_LOG(SG_AUTOPILOT, SG_INFO, "route manager, current-wp is now " << _route->current_index()); } diff --git a/src/Autopilot/route_mgr.hxx b/src/Autopilot/route_mgr.hxx index dbbe4577d..8799ce160 100644 --- a/src/Autopilot/route_mgr.hxx +++ b/src/Autopilot/route_mgr.hxx @@ -54,9 +54,11 @@ private: SGPropertyNode_ptr magvar; // automatic outputs - SGPropertyNode_ptr target_altitude_ft; - SGPropertyNode_ptr altitude_lock; - + bool _driveAutopilot; + SGPropertyNode_ptr _apTargetAltitudeFt; + SGPropertyNode_ptr _apAltitudeLock; + SGPropertyNode_ptr _apTrueHeading; + SGPropertyNode_ptr departure; ///< departure airport information SGPropertyNode_ptr destination; ///< destination airport information SGPropertyNode_ptr alternate; ///< alternate airport information -- 2.39.5