1 // route_mgr.cxx - manage a route (i.e. a collection of waypoints)
3 // Written by Curtis Olson, started January 2004.
7 // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <simgear/compiler.h>
32 #include "route_mgr.hxx"
34 #include <simgear/misc/strutils.hxx>
35 #include <simgear/structure/exception.hxx>
37 #include <simgear/props/props_io.hxx>
38 #include <simgear/misc/sg_path.hxx>
39 #include <simgear/route/route.hxx>
40 #include <simgear/sg_inlines.h>
42 #include "Main/fg_props.hxx"
43 #include "Navaids/positioned.hxx"
44 #include "Airports/simple.hxx"
45 #include "Airports/runways.hxx"
47 #include "FDM/flight.hxx" // for getting ground speed
49 #define RM "/autopilot/route-manager/"
51 static double get_ground_speed() {
52 // starts in ft/s so we convert to kts
53 static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
55 double ft_s = cur_fdm_state->get_V_ground_speed()
56 * speedup_node->getIntValue();
57 double kts = ft_s * SG_FEET_TO_METER * 3600 * SG_METER_TO_NM;
61 FGRouteMgr::FGRouteMgr() :
62 _route( new SGRoute ),
67 target_altitude_ft( NULL ),
68 altitude_lock( NULL ),
69 input(fgGetNode( RM "input", true )),
70 mirror(fgGetNode( RM "route", true )),
73 listener = new InputListener(this);
74 input->setStringValue("");
75 input->addChangeListener(listener);
79 FGRouteMgr::~FGRouteMgr() {
80 input->removeChangeListener(listener);
87 void FGRouteMgr::init() {
88 SGPropertyNode_ptr rm(fgGetNode(RM));
90 lon = fgGetNode( "/position/longitude-deg", true );
91 lat = fgGetNode( "/position/latitude-deg", true );
92 alt = fgGetNode( "/position/altitude-ft", true );
93 magvar = fgGetNode("/environment/magnetic-variation-deg", true);
95 target_altitude_ft = fgGetNode( "/autopilot/settings/target-altitude-ft", true );
96 altitude_lock = fgGetNode( "/autopilot/locks/altitude", true );
98 departure = fgGetNode(RM "departure", true);
99 // init departure information from current location
100 SGGeod pos = SGGeod::fromDegFt(lon->getDoubleValue(), lat->getDoubleValue(), alt->getDoubleValue());
101 FGAirport* apt = FGAirport::findClosest(pos, 10.0);
103 departure->setStringValue("airport", apt->ident().c_str());
104 FGRunway* active = apt->getActiveRunwayForUsage();
105 departure->setStringValue("runway", active->ident().c_str());
107 departure->setStringValue("airport", "");
108 departure->setStringValue("runway", "");
111 departure->getChild("etd", 0, true);
112 departure->getChild("takeoff-time", 0, true);
114 destination = fgGetNode(RM "destination", true);
115 destination->getChild("airport", 0, true);
116 destination->getChild("runway", 0, true);
117 destination->getChild("eta", 0, true);
118 destination->getChild("touchdown-time", 0, true);
120 alternate = fgGetNode(RM "alternate", true);
121 alternate->getChild("airport", 0, true);
122 alternate->getChild("runway", 0, true);
124 cruise = fgGetNode(RM "cruise", true);
125 cruise->getChild("altitude", 0, true);
126 cruise->getChild("flight-level", 0, true);
127 cruise->getChild("speed", 0, true);
129 totalDistance = fgGetNode(RM "total-distance", true);
130 totalDistance->setDoubleValue(0.0);
132 ete = fgGetNode(RM "ete", true);
133 ete->setDoubleValue(0.0);
135 elapsedFlightTime = fgGetNode(RM "flight-time", true);
136 elapsedFlightTime->setDoubleValue(0.0);
138 active = fgGetNode(RM "active", true);
139 active->setBoolValue(false);
141 airborne = fgGetNode(RM "airborne", true);
142 airborne->setBoolValue(false);
144 rm->tie("auto-sequence", SGRawValuePointer<bool>(&_autoSequence));
146 currentWp = fgGetNode(RM "current-wp", true);
147 currentWp->setIntValue(_route->current_index());
149 // temporary distance / eta calculations, for backward-compatability
150 wp0 = fgGetNode(RM "wp", 0, true);
151 wp0->getChild("id", 0, true);
152 wp0->getChild("dist", 0, true);
153 wp0->getChild("eta", 0, true);
154 wp0->getChild("bearing-deg", 0, true);
156 wp1 = fgGetNode(RM "wp", 1, true);
157 wp1->getChild("id", 0, true);
158 wp1->getChild("dist", 0, true);
159 wp1->getChild("eta", 0, true);
161 wpn = fgGetNode(RM "wp-last", 0, true);
162 wpn->getChild("dist", 0, true);
163 wpn->getChild("eta", 0, true);
168 _pathNode = fgGetNode(RM "file-path", 0, true);
172 void FGRouteMgr::postinit() {
173 string_list *waypoints = globals->get_initial_waypoints();
175 vector<string>::iterator it;
176 for (it = waypoints->begin(); it != waypoints->end(); ++it)
180 weightOnWheels = fgGetNode("/gear/gear[0]/wow", false);
181 // check airbone flag agrees with presets
186 void FGRouteMgr::bind() { }
187 void FGRouteMgr::unbind() { }
189 void FGRouteMgr::updateTargetAltitude() {
190 if (_route->current_index() == _route->size()) {
191 altitude_set = false;
195 SGWayPoint wp = _route->get_current();
196 if (wp.get_target().getElevationM() < -9990.0) {
197 altitude_set = false;
202 target_altitude_ft->setDoubleValue(wp.get_target().getElevationFt());
204 if ( !near_ground() ) {
205 // James Turner [zakalawe]: there's no explanation for this logic,
206 // it feels like the autopilot should pull the target altitude out of
207 // wp0 instead of us pushing it through here. Hmmm.
208 altitude_lock->setStringValue( "altitude-hold" );
212 bool FGRouteMgr::isRouteActive() const
214 return active->getBoolValue();
217 void FGRouteMgr::update( double dt ) {
218 if (!active->getBoolValue()) {
222 double groundSpeed = get_ground_speed();
223 if (!airborne->getBoolValue()) {
224 if (weightOnWheels->getBoolValue() || (groundSpeed < 40)) {
228 airborne->setBoolValue(true);
229 _takeoffTime = time(NULL); // start the clock
230 departure->setIntValue("takeoff-time", _takeoffTime);
233 time_t now = time(NULL);
234 elapsedFlightTime->setDoubleValue(difftime(now, _takeoffTime));
236 double inboundCourse, dummy, wp_course, wp_distance;
237 SGWayPoint wp = _route->get_current();
239 wp.CourseAndDistance(_route->get_waypoint(_route->current_index() - 1),
240 &inboundCourse, &dummy);
242 wp.CourseAndDistance( lon->getDoubleValue(), lat->getDoubleValue(),
243 alt->getDoubleValue(), &wp_course, &wp_distance );
245 if (_autoSequence && (wp_distance < 2000.0)) {
246 double courseDeviation = inboundCourse - wp_course;
247 SG_NORMALIZE_RANGE(courseDeviation, -180.0, 180.0);
248 if (fabs(courseDeviation) < 90.0) {
249 SG_LOG( SG_AUTOPILOT, SG_INFO, "route manager doing sequencing");
254 wp0->setDoubleValue("dist", wp_distance * SG_METER_TO_NM);
255 wp_course -= magvar->getDoubleValue(); // expose magnetic bearing
256 wp0->setDoubleValue("bearing-deg", wp_course);
257 setETAPropertyFromDistance(wp0->getChild("eta"), wp_distance);
259 if ((_route->current_index() + 1) < _route->size()) {
260 wp = _route->get_waypoint(_route->current_index() + 1);
261 double wp1_course, wp1_distance;
262 wp.CourseAndDistance(lon->getDoubleValue(), lat->getDoubleValue(),
263 alt->getDoubleValue(), &wp1_course, &wp1_distance);
265 wp1->setDoubleValue("dist", wp1_distance * SG_METER_TO_NM);
266 setETAPropertyFromDistance(wp1->getChild("eta"), wp1_distance);
269 double totalDistanceRemaining = wp_distance; // distance to current waypoint
270 for (int i=_route->current_index() + 1; i<_route->size(); ++i) {
271 totalDistanceRemaining += _route->get_waypoint(i).get_distance();
274 wpn->setDoubleValue("dist", totalDistanceRemaining * SG_METER_TO_NM);
275 ete->setDoubleValue(totalDistanceRemaining * SG_METER_TO_NM / groundSpeed * 3600.0);
276 setETAPropertyFromDistance(wpn->getChild("eta"), totalDistanceRemaining);
278 // get time now at destination tz as tm struct
280 // convert to string ... and stash in property
281 //destination->setDoubleValue("eta", eta);
285 void FGRouteMgr::setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance) {
287 double eta = aDistance * SG_METER_TO_NM / get_ground_speed();
288 if ( eta >= 100.0 ) {
289 eta = 99.999; // clamp
292 if ( eta < (1.0/6.0) ) {
293 eta *= 60.0; // within 10 minutes, bump up to min/secs
296 int major = (int)eta,
297 minor = (int)((eta - (int)eta) * 60.0);
298 snprintf( eta_str, 64, "%d:%02d", major, minor );
299 aProp->setStringValue( eta_str );
302 void FGRouteMgr::add_waypoint( const SGWayPoint& wp, int n ) {
303 _route->add_waypoint( wp, n );
305 if ((n==0) || (_route->size() == 1)) {
306 updateTargetAltitude();
311 SGWayPoint FGRouteMgr::pop_waypoint( int n ) {
314 if ( _route->size() > 0 ) {
316 n = _route->size() - 1;
317 wp = _route->get_waypoint(n);
318 _route->delete_waypoint(n);
321 updateTargetAltitude();
327 bool FGRouteMgr::build() {
332 void FGRouteMgr::new_waypoint( const string& target, int n ) {
333 SGWayPoint* wp = make_waypoint( target );
338 add_waypoint( *wp, n );
341 if ( !near_ground() ) {
342 fgSetString( "/autopilot/locks/heading", "true-heading-hold" );
347 SGWayPoint* FGRouteMgr::make_waypoint(const string& tgt ) {
351 for (unsigned int i = 0; i < target.size(); i++) {
352 target[i] = toupper(target[i]);
356 double alt = -9999.0;
357 size_t pos = target.find( '@' );
358 if ( pos != string::npos ) {
359 alt = atof( target.c_str() + pos + 1 );
360 target = target.substr( 0, pos );
361 if ( !strcmp(fgGetString("/sim/startup/units"), "feet") )
362 alt *= SG_FEET_TO_METER;
366 pos = target.find( ',' );
367 if ( pos != string::npos ) {
368 double lon = atof( target.substr(0, pos).c_str());
369 double lat = atof( target.c_str() + pos + 1);
370 return new SGWayPoint( lon, lat, alt, SGWayPoint::WGS84, target );
374 if (_route->size() > 0) {
375 SGWayPoint wp = get_waypoint(_route->size()-1);
376 basePosition = wp.get_target();
378 // route is empty, use current position
379 basePosition = SGGeod::fromDeg(
380 fgGetNode("/position/longitude-deg")->getDoubleValue(),
381 fgGetNode("/position/latitude-deg")->getDoubleValue());
384 vector<string> pieces(simgear::strutils::split(target, "/"));
387 FGPositionedRef p = FGPositioned::findClosestWithIdent(pieces.front(), basePosition);
389 SG_LOG( SG_AUTOPILOT, SG_INFO, "Unable to find FGPositioned with ident:" << pieces.front());
393 if (pieces.size() == 1) {
395 return new SGWayPoint(p->geod(), target, p->name());
398 if (pieces.size() == 3) {
399 // navaid/radial/distance-nm notation
400 double radial = atof(pieces[1].c_str()),
401 distanceNm = atof(pieces[2].c_str()),
403 radial += magvar->getDoubleValue(); // convert to true bearing
405 SGGeodesy::direct(p->geod(), radial, distanceNm * SG_NM_TO_METER, offsetPos, az2);
407 SG_LOG(SG_AUTOPILOT, SG_INFO, "final offset radial is " << radial);
410 offsetPos.setElevationM(alt);
411 } // otherwise use the elevation of navid
412 return new SGWayPoint(offsetPos, p->ident() + pieces[2], target);
415 if (pieces.size() == 2) {
416 FGAirport* apt = dynamic_cast<FGAirport*>(p.ptr());
418 SG_LOG(SG_AUTOPILOT, SG_INFO, "Waypoint is not an airport:" << pieces.front());
422 if (!apt->hasRunwayWithIdent(pieces[1])) {
423 SG_LOG(SG_AUTOPILOT, SG_INFO, "No runway: " << pieces[1] << " at " << pieces[0]);
427 FGRunway* runway = apt->getRunwayByIdent(pieces[1]);
428 SGGeod t = runway->threshold();
429 return new SGWayPoint(t.getLongitudeDeg(), t.getLatitudeDeg(), alt, SGWayPoint::WGS84, pieces[1]);
432 SG_LOG(SG_AUTOPILOT, SG_INFO, "Unable to parse waypoint:" << target);
437 // mirror internal route to the property system for inspection by other subsystems
438 void FGRouteMgr::update_mirror() {
439 mirror->removeChildren("wp");
440 for (int i = 0; i < _route->size(); i++) {
441 SGWayPoint wp = _route->get_waypoint(i);
442 SGPropertyNode *prop = mirror->getChild("wp", i, 1);
444 const SGGeod& pos(wp.get_target());
445 prop->setStringValue("id", wp.get_id().c_str());
446 prop->setStringValue("name", wp.get_name().c_str());
447 prop->setDoubleValue("longitude-deg", pos.getLongitudeDeg());
448 prop->setDoubleValue("latitude-deg",pos.getLatitudeDeg());
449 prop->setDoubleValue("altitude-m", pos.getElevationM());
450 prop->setDoubleValue("altitude-ft", pos.getElevationFt());
452 // set number as listener attachment point
453 mirror->setIntValue("num", _route->size());
457 bool FGRouteMgr::near_ground() {
458 SGPropertyNode *gear = fgGetNode( "/gear/gear/wow", false );
459 if ( !gear || gear->getType() == simgear::props::NONE )
460 return fgGetBool( "/sim/presets/onground", true );
462 if ( fgGetDouble("/position/altitude-agl-ft", 300.0)
463 < fgGetDouble("/autopilot/route-manager/min-lock-altitude-agl-ft") )
466 return gear->getBoolValue();
470 // command interface /autopilot/route-manager/input:
472 // @CLEAR ... clear route
473 // @POP ... remove first entry
474 // @DELETE3 ... delete 4th entry
475 // @INSERT2:KSFO@900 ... insert "KSFO@900" as 3rd entry
476 // KSFO@900 ... append "KSFO@900"
478 void FGRouteMgr::InputListener::valueChanged(SGPropertyNode *prop)
480 const char *s = prop->getStringValue();
481 if (!strcmp(s, "@CLEAR"))
483 else if (!strcmp(s, "@ACTIVATE"))
485 else if (!strcmp(s, "@LOAD")) {
487 } else if (!strcmp(s, "@SAVE")) {
489 } else if (!strcmp(s, "@POP"))
490 mgr->pop_waypoint(0);
491 else if (!strncmp(s, "@DELETE", 7))
492 mgr->pop_waypoint(atoi(s + 7));
493 else if (!strncmp(s, "@INSERT", 7)) {
495 int pos = strtol(s + 7, &r, 10);
501 mgr->new_waypoint(r, pos);
503 mgr->new_waypoint(s);
506 // SGWayPoint( const double lon = 0.0, const double lat = 0.0,
507 // const double alt = 0.0, const modetype m = WGS84,
508 // const string& s = "", const string& n = "" );
510 bool FGRouteMgr::activate()
512 const FGAirport* depApt = fgFindAirportID(departure->getStringValue("airport"));
514 SG_LOG(SG_AUTOPILOT, SG_ALERT,
515 "unable to activate route: departure airport is invalid:"
516 << departure->getStringValue("airport") );
520 string runwayId(departure->getStringValue("runway"));
521 FGRunway* runway = NULL;
522 if (depApt->hasRunwayWithIdent(runwayId)) {
523 runway = depApt->getRunwayByIdent(runwayId);
525 SG_LOG(SG_AUTOPILOT, SG_INFO,
526 "route-manager, departure runway not found:" << runwayId);
527 runway = depApt->getActiveRunwayForUsage();
530 SGWayPoint swp(runway->threshold(),
531 depApt->ident() + "-" + runway->ident(), runway->name());
532 add_waypoint(swp, 0);
534 const FGAirport* destApt = fgFindAirportID(destination->getStringValue("airport"));
536 SG_LOG(SG_AUTOPILOT, SG_ALERT,
537 "unable to activate route: destination airport is invalid:"
538 << destination->getStringValue("airport") );
542 runwayId = (destination->getStringValue("runway"));
543 if (destApt->hasRunwayWithIdent(runwayId)) {
544 FGRunway* runway = depApt->getRunwayByIdent(runwayId);
545 SGWayPoint swp(runway->end(),
546 destApt->ident() + "-" + runway->ident(), runway->name());
549 // quite likely, since destination runway may not be known until enroute
550 // probably want a listener on the 'destination' node to allow an enroute
552 add_waypoint(SGWayPoint(destApt->geod(), destApt->ident(), destApt->name()));
555 _route->set_current(0);
557 double routeDistanceNm = _route->total_distance() * SG_METER_TO_NM;
558 totalDistance->setDoubleValue(routeDistanceNm);
559 double cruiseSpeedKts = cruise->getDoubleValue("speed", 0.0);
560 if (cruiseSpeedKts > 1.0) {
561 // very very crude approximation, doesn't allow for climb / descent
562 // performance or anything else at all
563 ete->setDoubleValue(routeDistanceNm / cruiseSpeedKts * (60.0 * 60.0));
566 active->setBoolValue(true);
567 sequence(); // sequence will sync up wp0, wp1 and current-wp
568 SG_LOG(SG_AUTOPILOT, SG_INFO, "route-manager, activate route ok");
573 void FGRouteMgr::sequence()
575 if (!active->getBoolValue()) {
576 SG_LOG(SG_AUTOPILOT, SG_ALERT, "trying to sequence waypoints with no active route");
580 if (_route->current_index() == _route->size()) {
581 SG_LOG(SG_AUTOPILOT, SG_INFO, "reached end of active route");
583 active->setBoolValue(false);
587 _route->increment_current();
588 currentWaypointChanged();
591 void FGRouteMgr::jumpToIndex(int index)
593 if (!active->getBoolValue()) {
594 SG_LOG(SG_AUTOPILOT, SG_ALERT, "trying to sequence waypoints with no active route");
598 if ((index < 0) || (index >= _route->size())) {
599 SG_LOG(SG_AUTOPILOT, SG_ALERT, "passed invalid index (" <<
600 index << ") to FGRouteMgr::jumpToIndex");
604 if (_route->current_index() == index) {
608 _route->set_current(index);
609 currentWaypointChanged();
612 void FGRouteMgr::currentWaypointChanged()
614 SGWayPoint previous = _route->get_previous();
615 SGWayPoint cur = _route->get_current();
617 wp0->getChild("id")->setStringValue(cur.get_id());
618 if ((_route->current_index() + 1) < _route->size()) {
619 wp1->getChild("id")->setStringValue(_route->get_next().get_id());
621 wp1->getChild("id")->setStringValue("");
624 currentWp->setIntValue(_route->current_index());
625 SG_LOG(SG_AUTOPILOT, SG_INFO, "route manager, current-wp is now " << _route->current_index());
628 int FGRouteMgr::findWaypoint(const SGGeod& aPos) const
630 for (int i=0; i<_route->size(); ++i) {
631 double d = SGGeodesy::distanceM(aPos, _route->get_waypoint(i).get_target());
632 if (d < 200.0) { // 200 metres seems close enough
640 SGWayPoint FGRouteMgr::get_waypoint( int i ) const
642 return _route->get_waypoint(i);
645 int FGRouteMgr::size() const
647 return _route->size();
650 int FGRouteMgr::currentWaypoint() const
652 return _route->current_index();
655 void FGRouteMgr::saveRoute()
657 SGPath path(_pathNode->getStringValue());
658 SG_LOG(SG_IO, SG_INFO, "Saving route to " << path.str());
660 writeProperties(path.str(), mirror, false, SGPropertyNode::ARCHIVE);
661 } catch (const sg_exception &e) {
662 SG_LOG(SG_IO, SG_WARN, "Error saving route:" << e.getMessage());
663 //guiErrorMessage("Error writing autosave.xml: ", e);
667 void FGRouteMgr::loadRoute()
670 // deactivate route first
671 active->setBoolValue(false);
673 SGPropertyNode_ptr routeData(new SGPropertyNode);
674 SGPath path(_pathNode->getStringValue());
676 SG_LOG(SG_IO, SG_INFO, "going to read flight-plan from:" << path.str());
677 readProperties(path.str(), routeData);
680 SGPropertyNode* dep = routeData->getChild("departure");
682 throw sg_io_exception("malformed route file, no departure node");
685 string depIdent = dep->getStringValue("airport");
686 const FGAirport* depApt = fgFindAirportID(depIdent);
688 throw sg_io_exception("bad route file, unknown airport:" + depIdent);
691 departure->setStringValue("runway", dep->getStringValue("runway"));
694 SGPropertyNode* dst = routeData->getChild("destination");
696 throw sg_io_exception("malformed route file, no destination node");
699 destination->setStringValue("airport", dst->getStringValue("airport"));
700 destination->setStringValue("runay", dst->getStringValue("runway"));
703 SGPropertyNode* alt = routeData->getChild("alternate");
705 alternate->setStringValue(alt->getStringValue("airport"));
706 } // of cruise data loading
709 SGPropertyNode* crs = routeData->getChild("cruise");
711 cruise->setDoubleValue(crs->getDoubleValue("speed"));
712 } // of cruise data loading
716 SGPropertyNode_ptr _route = routeData->getChild("route", 0);
717 SGGeod lastPos(depApt->geod());
719 for (int i=0; i<_route->nChildren(); ++i) {
720 SGPropertyNode_ptr wp = _route->getChild("wp", i);
721 parseRouteWaypoint(wp);
722 } // of route iteration
723 } catch (sg_exception& e) {
724 SG_LOG(SG_IO, SG_WARN, "failed to load flight-plan (from '" << e.getOrigin()
725 << "'):" << e.getMessage());
729 void FGRouteMgr::parseRouteWaypoint(SGPropertyNode* aWP)
732 if (_route->size() > 0) {
733 lastPos = get_waypoint(_route->size()-1).get_target();
735 // route is empty, use departure airport position
736 const FGAirport* apt = fgFindAirportID(departure->getStringValue("airport"));
737 assert(apt); // shouldn't have got this far with an invalid airport
738 lastPos = apt->geod();
741 SGPropertyNode_ptr altProp = aWP->getChild("altitude-ft");
742 double alt = -9999.0;
744 alt = altProp->getDoubleValue();
747 string ident(aWP->getStringValue("ident"));
748 if (aWP->hasChild("longitude-deg")) {
749 // explicit longitude/latitude
751 alt = 0.0; // don't export wyapoints with invalid altitude
754 SGWayPoint swp(aWP->getDoubleValue("longitude-deg"),
755 aWP->getDoubleValue("latitude-deg"), alt,
756 SGWayPoint::WGS84, ident, aWP->getStringValue("name"));
758 } else if (aWP->hasChild("navid")) {
759 // lookup by navid (possibly with offset)
760 string nid(aWP->getStringValue("navid"));
761 FGPositionedRef p = FGPositioned::findClosestWithIdent(nid, lastPos);
763 throw sg_io_exception("bad route file, unknown navid:" + nid);
766 SGGeod pos(p->geod());
767 if (aWP->hasChild("offset-nm") && aWP->hasChild("offset-radial")) {
768 double radialDeg = aWP->getDoubleValue("offset-radial");
769 // convert magnetic radial to a true radial!
770 radialDeg += magvar->getDoubleValue();
771 double offsetNm = aWP->getDoubleValue("offset-nm");
773 SGGeodesy::direct(p->geod(), radialDeg, offsetNm * SG_NM_TO_METER, pos, az2);
777 alt = p->elevation();
780 SGWayPoint swp(pos.getLongitudeDeg(), pos.getLatitudeDeg(), alt,
781 SGWayPoint::WGS84, ident, "");
784 // lookup by ident (symbolic waypoint)
785 FGPositionedRef p = FGPositioned::findClosestWithIdent(ident, lastPos);
787 throw sg_io_exception("bad route file, unknown waypoint:" + ident);
791 alt = p->elevation();
794 SGWayPoint swp(p->longitude(), p->latitude(), alt,
795 SGWayPoint::WGS84, p->ident(), p->name());