_gps->routeActivated();
} else if (prop == _gps->_ref_navaid_id_node) {
_gps->referenceNavaidSet(prop->getStringValue(""));
+ } else if (prop == _gps->_routeEditedSignal) {
+ _gps->routeEdited();
+ } else if (prop == _gps->_routeFinishedSignal) {
+ _gps->routeFinished();
}
_guard = false;
////////////////////////////////////////////////////////////////////////////
GPS::GPS ( SGPropertyNode *node) :
- _last_valid(false),
+ _dataValid(false),
+ _lastPosValid(false),
+ _mode("init"),
_name(node->getStringValue("name", "gps")),
_num(node->getIntValue("number", 0)),
_computeTurnData(false),
_magnetic_bug_error_node = node->getChild("magnetic-bug-error-deg", 0, true);
// command system
- _mode = "obs";
node->tie("mode", SGRawValueMethods<GPS, const char*>(*this, &GPS::getMode, NULL));
node->tie("command", SGRawValueMethods<GPS, const char*>(*this, &GPS::getCommand, &GPS::setCommand));
// should these move to the route manager?
_routeDistanceNm = node->getChild("route-distance-nm", 0, true);
_routeETE = node->getChild("ETE", 0, true);
-
- // disable auto-sequencing in the route manager; we'll deal with it
- // ourselves using turn anticipation
- SGPropertyNode_ptr autoSeq = fgGetNode("/autopilot/route-manager/auto-sequence", true);
- autoSeq->setBoolValue(false);
-
+ _routeEditedSignal = fgGetNode("/autopilot/route-manager/signals/edited", true);
+ _routeFinishedSignal = fgGetNode("/autopilot/route-manager/signals/finished", true);
+
// add listener to various things
_listener = new GPSListener(this);
_route_current_wp_node = fgGetNode("/autopilot/route-manager/current-wp", true);
_route_active_node = fgGetNode("/autopilot/route-manager/active", true);
_route_active_node->addChangeListener(_listener);
_ref_navaid_id_node->addChangeListener(_listener);
-
+ _routeEditedSignal->addChangeListener(_listener);
+ _routeFinishedSignal->addChangeListener(_listener);
+
// navradio slaving properties
node->tie("cdi-deflection", SGRawValueMethods<GPS,double>
(*this, &GPS::getCDIDeflection));
SGPropertyNode* toFlag = node->getChild("to-flag", 0, true);
toFlag->alias(wp1_node->getChild("to-flag"));
+
+ SGPropertyNode* fromFlag = node->getChild("from-flag", 0, true);
+ fromFlag->alias(wp1_node->getChild("from-flag"));
+
// autopilot drive properties
_apTrueHeading = fgGetNode("/autopilot/settings/true-heading-deg",true);
_apTargetAltitudeFt = fgGetNode("/autopilot/settings/target-altitude-ft", true);
// last thing, add the deprecated prop watcher
new DeprecatedPropListener(node);
- // initialise in OBS mode, with waypt set to the nearest airport.
- // keep in mind at this point, _last_valid is not set
-
- auto_ptr<FGPositioned::Filter> f(createFilter(FGPositioned::AIRPORT));
- FGPositionedRef apt = FGPositioned::findClosest(_position.get(), 20.0, f.get());
- if (apt) {
- setScratchFromPositioned(apt, 0);
- selectOBSMode();
- }
+ clearOutput();
}
void
GPS::clearOutput()
{
- _last_valid = false;
+ _dataValid = false;
_last_speed_kts = 0.0;
_last_pos = SGGeod();
+ _lastPosValid = false;
_indicated_pos = SGGeod();
_last_vertical_speed = 0.0;
_last_true_track = 0.0;
printf("%f %f \n", error_length, error_angle);
*/
- _raim_node->setDoubleValue(1.0);
- _indicated_pos = _position.get();
+ _raim_node->setDoubleValue(1.0);
+ _indicated_pos = _position.get();
+ updateBasicData(delta_time_sec);
- if (_last_valid) {
- updateWithValid(delta_time_sec);
+ if (_dataValid) {
+ if (_mode == "obs") {
+ _selectedCourse = _config.getExternalCourse();
} else {
- _last_valid = true;
-
- if (_route_active_node->getBoolValue()) {
- // GPS init with active route
- SG_LOG(SG_INSTR, SG_INFO, "GPS init with active route");
- _listener->setGuard(true);
- routeActivated();
- routeManagerSequenced();
- _listener->setGuard(false);
- }
+ updateTurn();
}
-
- _last_pos = _indicated_pos;
-}
-
-void
-GPS::updateWithValid(double dt)
-{
- assert(_last_valid);
+
+ updateWaypoints();
+ updateTrackingBug();
+ updateReferenceNavaid(delta_time_sec);
+ updateRouteData();
+ driveAutopilot();
+ }
+
+ if (_dataValid && (_mode == "init")) {
+ // allow a realistic delay in the future, here
+ SG_LOG(SG_INSTR, SG_INFO, "GPS initialisation complete");
+ if (_route_active_node->getBoolValue()) {
+ // GPS init with active route
+ SG_LOG(SG_INSTR, SG_INFO, "GPS init with active route");
+ selectLegMode();
+ } else {
+ // initialise in OBS mode, with waypt set to the nearest airport.
+ // keep in mind at this point, _dataValid is not set
- updateBasicData(dt);
+ auto_ptr<FGPositioned::Filter> f(createFilter(FGPositioned::AIRPORT));
+ FGPositionedRef apt = FGPositioned::findClosest(_position.get(), 20.0, f.get());
+ if (apt) {
+ setScratchFromPositioned(apt, 0);
+ selectOBSMode();
+ }
+ }
+ } // of init mode check
- if (_mode == "obs") {
- _selectedCourse = _config.getExternalCourse();
- } else {
- updateTurn();
- }
-
- updateWaypoints();
- updateTrackingBug();
- updateReferenceNavaid(dt);
- updateRouteData();
- driveAutopilot();
+ _last_pos = _indicated_pos;
+ _lastPosValid = true;
}
void
GPS::updateBasicData(double dt)
{
+ if (!_lastPosValid) {
+ return;
+ }
+
double distance_m;
double track2_deg;
SGGeodesy::inverse(_last_pos, _indicated_pos, _last_true_track, track2_deg, distance_m );
_odometer_node->setDoubleValue(odometer + distance_m * SG_METER_TO_NM);
odometer = _trip_odometer_node->getDoubleValue();
_trip_odometer_node->setDoubleValue(odometer + distance_m * SG_METER_TO_NM);
+
+ if (!_dataValid) {
+ SG_LOG(SG_INSTR, SG_INFO, "GPS setting data valid");
+ _dataValid = true;
+ }
}
void
wp1Changed();
}
+void GPS::routeEdited()
+{
+ if (_mode != "leg") {
+ return;
+ }
+
+ SG_LOG(SG_INSTR, SG_INFO, "GPS route edited while in LEG mode, updating waypoints");
+ routeManagerSequenced();
+}
+
+void GPS::routeFinished()
+{
+ if (_mode != "leg") {
+ return;
+ }
+
+ SG_LOG(SG_INSTR, SG_INFO, "GPS route finished, reverting to OBS");
+ _mode = "obs";
+ _wp0_position = _indicated_pos;
+ wp1Changed();
+}
+
void GPS::updateTurn()
{
bool printProgress = false;
double altFt = _wp1_position.getElevationFt();
if (altFt < -9990.0) {
_apTargetAltitudeFt->setDoubleValue(0.0);
- _apAltitudeLock->setBoolValue(false);
} else {
_apTargetAltitudeFt->setDoubleValue(altFt);
- _apAltitudeLock->setBoolValue(true);
}
}
double GPS::getLegDistance() const
{
- if (!_last_valid || (_mode == "obs")) {
+ if (!_dataValid || (_mode == "obs")) {
return -1;
}
double GPS::getLegCourse() const
{
- if (!_last_valid || (_mode == "obs")) {
+ if (!_dataValid || (_mode == "obs")) {
return -9999.0;
}
double GPS::getLegMagCourse() const
{
- if (!_last_valid || (_mode == "obs")) {
+ if (!_dataValid || (_mode == "obs")) {
return 0.0;
}
double GPS::getAltDistanceRatio() const
{
- if (!_last_valid || (_mode == "obs")) {
+ if (!_dataValid || (_mode == "obs")) {
return 0.0;
}
double GPS::getMagTrack() const
{
- if (!_last_valid) {
+ if (!_dataValid) {
return 0.0;
}
double GPS::getCDIDeflection() const
{
- if (!_last_valid) {
+ if (!_dataValid) {
return 0.0;
}
const char* GPS::getWP0Ident() const
{
- if (!_last_valid || (_mode != "leg")) {
+ if (!_dataValid || (_mode != "leg")) {
return "";
}
const char* GPS::getWP0Name() const
{
- if (!_last_valid || (_mode != "leg")) {
+ if (!_dataValid || (_mode != "leg")) {
return "";
}
const char* GPS::getWP1Ident() const
{
- if (!_last_valid) {
+ if (!_dataValid) {
return "";
}
const char* GPS::getWP1Name() const
{
- if (!_last_valid) {
+ if (!_dataValid) {
return "";
}
double GPS::getWP1Distance() const
{
- if (!_last_valid) {
+ if (!_dataValid) {
return -1.0;
}
double GPS::getWP1TTW() const
{
- if (!_last_valid) {
+ if (!_dataValid) {
return -1.0;
}
const char* GPS::getWP1TTWString() const
{
- if (!_last_valid) {
+ if (!_dataValid) {
return "";
}
double GPS::getWP1Bearing() const
{
- if (!_last_valid) {
+ if (!_dataValid) {
return -9999.0;
}
double GPS::getWP1MagBearing() const
{
- if (!_last_valid) {
+ if (!_dataValid) {
return -9999.0;
}
double GPS::getWP1CourseDeviation() const
{
- if (!_last_valid) {
+ if (!_dataValid) {
return 0.0;
}
double GPS::getWP1CourseErrorNm() const
{
- if (!_last_valid) {
+ if (!_dataValid) {
return 0.0;
}
bool GPS::getWP1ToFlag() const
{
- if (!_last_valid) {
+ if (!_dataValid) {
return false;
}
bool GPS::getWP1FromFlag() const
{
- if (!_last_valid) {
+ if (!_dataValid) {
return false;
}