1
0
Fork 0

Route tweaks, especially in-flight activation and deactivation

* Don't require a valid departure and destination airport
* Handle in-air route activation cleanly
* Handle end-of-route situation cleanly
This commit is contained in:
jmt 2009-10-21 22:42:24 +00:00 committed by Tim Moore
parent 08039f1fa5
commit 9495c2efdf
2 changed files with 52 additions and 52 deletions

View file

@ -216,12 +216,8 @@ void FGRouteMgr::update( double dt ) {
} }
// basic course/distance information // basic course/distance information
double inboundCourse, dummy, wp_course, wp_distance; double wp_course, wp_distance;
SGWayPoint wp = _route->get_current(); SGWayPoint wp = _route->get_current();
wp.CourseAndDistance(_route->get_waypoint(_route->current_index() - 1),
&inboundCourse, &dummy);
wp.CourseAndDistance( lon->getDoubleValue(), lat->getDoubleValue(), wp.CourseAndDistance( lon->getDoubleValue(), lat->getDoubleValue(),
alt->getDoubleValue(), &wp_course, &wp_distance ); alt->getDoubleValue(), &wp_course, &wp_distance );
@ -478,49 +474,39 @@ void FGRouteMgr::InputListener::valueChanged(SGPropertyNode *prop)
bool FGRouteMgr::activate() bool FGRouteMgr::activate()
{ {
const FGAirport* depApt = fgFindAirportID(departure->getStringValue("airport")); const FGAirport* depApt = fgFindAirportID(departure->getStringValue("airport"));
if (!depApt) { if (depApt) {
SG_LOG(SG_AUTOPILOT, SG_ALERT, string runwayId(departure->getStringValue("runway"));
"unable to activate route: departure airport is invalid:" FGRunway* runway = NULL;
<< departure->getStringValue("airport") ); if (depApt->hasRunwayWithIdent(runwayId)) {
return false; runway = depApt->getRunwayByIdent(runwayId);
} else {
SG_LOG(SG_AUTOPILOT, SG_INFO,
"route-manager, departure runway not found:" << runwayId);
runway = depApt->getActiveRunwayForUsage();
}
SGWayPoint swp(runway->threshold(),
depApt->ident() + "-" + runway->ident(), runway->name());
add_waypoint(swp, 0);
} }
string runwayId(departure->getStringValue("runway"));
FGRunway* runway = NULL;
if (depApt->hasRunwayWithIdent(runwayId)) {
runway = depApt->getRunwayByIdent(runwayId);
} else {
SG_LOG(SG_AUTOPILOT, SG_INFO,
"route-manager, departure runway not found:" << runwayId);
runway = depApt->getActiveRunwayForUsage();
}
SGWayPoint swp(runway->threshold(),
depApt->ident() + "-" + runway->ident(), runway->name());
add_waypoint(swp, 0);
const FGAirport* destApt = fgFindAirportID(destination->getStringValue("airport")); const FGAirport* destApt = fgFindAirportID(destination->getStringValue("airport"));
if (!destApt) { if (destApt) {
SG_LOG(SG_AUTOPILOT, SG_ALERT, string runwayId = (destination->getStringValue("runway"));
"unable to activate route: destination airport is invalid:" if (destApt->hasRunwayWithIdent(runwayId)) {
<< destination->getStringValue("airport") ); FGRunway* runway = destApt->getRunwayByIdent(runwayId);
return false; SGWayPoint swp(runway->end(),
destApt->ident() + "-" + runway->ident(), runway->name());
add_waypoint(swp);
} else {
// quite likely, since destination runway may not be known until enroute
// probably want a listener on the 'destination' node to allow an enroute
// update
add_waypoint(SGWayPoint(destApt->geod(), destApt->ident(), destApt->name()));
}
} }
runwayId = (destination->getStringValue("runway")); _route->set_current(0);
if (destApt->hasRunwayWithIdent(runwayId)) {
FGRunway* runway = destApt->getRunwayByIdent(runwayId);
SGWayPoint swp(runway->end(),
destApt->ident() + "-" + runway->ident(), runway->name());
add_waypoint(swp);
} else {
// quite likely, since destination runway may not be known until enroute
// probably want a listener on the 'destination' node to allow an enroute
// update
add_waypoint(SGWayPoint(destApt->geod(), destApt->ident(), destApt->name()));
}
_route->set_current(1);
double routeDistanceNm = _route->total_distance() * SG_METER_TO_NM; double routeDistanceNm = _route->total_distance() * SG_METER_TO_NM;
totalDistance->setDoubleValue(routeDistanceNm); totalDistance->setDoubleValue(routeDistanceNm);

View file

@ -723,6 +723,12 @@ void GPS::routeActivated()
if (_route_active_node->getBoolValue()) { if (_route_active_node->getBoolValue()) {
SG_LOG(SG_INSTR, SG_INFO, "GPS::route activated, switching to LEG mode"); SG_LOG(SG_INSTR, SG_INFO, "GPS::route activated, switching to LEG mode");
selectLegMode(); selectLegMode();
// if we've already passed the current waypoint, sequence.
if (_dataValid && getWP1FromFlag()) {
SG_LOG(SG_INSTR, SG_INFO, "GPS::route activated, FROM wp1, sequencing");
_routeMgr->sequence();
}
} else if (_mode == "leg") { } else if (_mode == "leg") {
SG_LOG(SG_INSTR, SG_INFO, "GPS::route deactivated, switching to OBS mode"); SG_LOG(SG_INSTR, SG_INFO, "GPS::route deactivated, switching to OBS mode");
selectOBSMode(); selectOBSMode();
@ -738,19 +744,22 @@ void GPS::routeManagerSequenced()
int index = _routeMgr->currentWaypoint(), int index = _routeMgr->currentWaypoint(),
count = _routeMgr->size(); count = _routeMgr->size();
if ((index < 1) || (index >= count)) { if ((index < 0) || (index >= count)) {
SG_LOG(SG_INSTR, SG_ALERT, "GPS: malformed route, index=" << index); SG_LOG(SG_INSTR, SG_ALERT, "GPS: malformed route, index=" << index);
return; return;
} }
SG_LOG(SG_INSTR, SG_INFO, "GPS waypoint index is now " << index); SG_LOG(SG_INSTR, SG_INFO, "GPS waypoint index is now " << index);
SGWayPoint wp0(_routeMgr->get_waypoint(index - 1));
SGWayPoint wp1(_routeMgr->get_waypoint(index)); if (index > 0) {
SGWayPoint wp0(_routeMgr->get_waypoint(index - 1));
_wp0Ident = wp0.get_id(); _wp0Ident = wp0.get_id();
_wp0Name = wp0.get_name(); _wp0Name = wp0.get_name();
_wp0_position = wp0.get_target(); _wp0_position = wp0.get_target();
}
SGWayPoint wp1(_routeMgr->get_waypoint(index));
_wp1Ident = wp1.get_id(); _wp1Ident = wp1.get_id();
_wp1Name = wp1.get_name(); _wp1Name = wp1.get_name();
_wp1_position = wp1.get_target(); _wp1_position = wp1.get_target();
@ -1030,7 +1039,7 @@ double GPS::getLegDistance() const
double GPS::getLegCourse() const double GPS::getLegCourse() const
{ {
if (!_dataValid || (_mode == "obs")) { if (!_dataValid) {
return -9999.0; return -9999.0;
} }
@ -1039,7 +1048,7 @@ double GPS::getLegCourse() const
double GPS::getLegMagCourse() const double GPS::getLegMagCourse() const
{ {
if (!_dataValid || (_mode == "obs")) { if (!_dataValid) {
return 0.0; return 0.0;
} }
@ -1646,6 +1655,11 @@ void GPS::selectLegMode()
SG_LOG(SG_INSTR, SG_INFO, "GPS switching to LEG mode"); SG_LOG(SG_INSTR, SG_INFO, "GPS switching to LEG mode");
_mode = "leg"; _mode = "leg";
// depending on the situation, this will either get over-written
// in routeManagerSequenced or not; either way it does no harm to
// set it here.
_wp0_position = _indicated_pos;
// not really sequenced, but does all the work of updating wp0/1 // not really sequenced, but does all the work of updating wp0/1
routeManagerSequenced(); routeManagerSequenced();
} }