1
0
Fork 0

Merge branch 'jmt/gps' into next

Conflicts:
	src/Instrumentation/gps.cxx
This commit is contained in:
Tim Moore 2010-03-28 00:34:51 +01:00
commit 70ebde4488
4 changed files with 115 additions and 124 deletions

View file

@ -188,75 +188,27 @@ GPS::Config::Config() :
_turnRate(3.0), // degrees-per-second, so 180 degree turn takes 60 seconds
_overflightArmDistance(1.0),
_waypointAlertTime(30.0),
_tuneRadio1ToRefVor(false),
_minRunwayLengthFt(0.0),
_requireHardSurface(true),
_cdiMaxDeflectionNm(3.0), // linear mode, 3nm at the peg
_driveAutopilot(true)
_driveAutopilot(true),
_courseSelectable(false)
{
_enableTurnAnticipation = false;
_extCourseSource = fgGetNode("/instrumentation/nav[0]/radials/selected-deg", true);
}
void GPS::Config::bind(GPS* aOwner, SGPropertyNode* aCfg)
{
aOwner->tie(aCfg, "turn-rate-deg-sec", SGRawValuePointer<double>(&_turnRate));
aOwner->tie(aCfg, "turn-anticipation", SGRawValuePointer<bool>(&_enableTurnAnticipation));
aOwner->tie(aCfg, "wpt-alert-time", SGRawValuePointer<double>(&_waypointAlertTime));
aOwner->tie(aCfg, "tune-nav-radio-to-ref-vor", SGRawValuePointer<bool>(&_tuneRadio1ToRefVor));
aOwner->tie(aCfg, "min-runway-length-ft", SGRawValuePointer<double>(&_minRunwayLengthFt));
aOwner->tie(aCfg, "hard-surface-runways-only", SGRawValuePointer<bool>(&_requireHardSurface));
aOwner->tie(aCfg, "course-source", SGRawValueMethods<GPS::Config, const char*>
(*this, &GPS::Config::getCourseSource, &GPS::Config::setCourseSource));
aOwner->tie(aCfg, "cdi-max-deflection-nm", SGRawValuePointer<double>(&_cdiMaxDeflectionNm));
aOwner->tie(aCfg, "drive-autopilot", SGRawValuePointer<bool>(&_driveAutopilot));
aOwner->tie(aCfg, "course-selectable", SGRawValuePointer<bool>(&_courseSelectable));
}
const char*
GPS::Config::getCourseSource() const
{
if (!_extCourseSource) {
return "";
}
return _extCourseSource->getPath(true).c_str();
}
void
GPS::Config::setCourseSource(const char* aPath)
{
SGPropertyNode* nd = fgGetNode(aPath, false);
if (!nd) {
SG_LOG(SG_INSTR, SG_WARN, "couldn't find course source at:" << aPath);
_extCourseSource = NULL;
}
_extCourseSource = nd;
}
double
GPS::Config::getExternalCourse() const
{
if (!_extCourseSource) {
return 0.0;
}
return _extCourseSource->getDoubleValue();
}
void
GPS::Config::setExternalCourse(double aCourseDeg)
{
if (!_extCourseSource) {
return;
}
_extCourseSource->setDoubleValue(aCourseDeg);
}
////////////////////////////////////////////////////////////////////////////
GPS::GPS ( SGPropertyNode *node) :
@ -297,6 +249,8 @@ GPS::init ()
_trip_odometer_node = _gpsNode->getChild("trip-odometer", 0, true);
_true_bug_error_node = _gpsNode->getChild("true-bug-error-deg", 0, true);
_magnetic_bug_error_node = _gpsNode->getChild("magnetic-bug-error-deg", 0, true);
_eastWestVelocity = _gpsNode->getChild("ew-velocity-msec", 0, true);
_northSouthVelocity = _gpsNode->getChild("ns-velocity-msec", 0, true);
// waypoints
SGPropertyNode *wp_node = _gpsNode->getChild("wp", 0, true);
@ -304,7 +258,7 @@ GPS::init ()
// for compatability, alias selected course down to wp/wp[1]/desired-course-deg
SGPropertyNode* wp1Crs = wp1_node->getChild("desired-course-deg", 0, true);
wp1Crs->alias(_gpsNode->getChild("selected-course-deg"));
wp1Crs->alias(_gpsNode->getChild("desired-course-deg", 0, true));
// _true_wp1_bearing_error_node =
// wp1_node->getChild("true-bearing-error-deg", 0, true);
@ -371,9 +325,12 @@ GPS::bind()
_config.bind(this, _gpsNode->getChild("config", 0, true));
// basic GPS outputs
tie(_gpsNode, "selected-course-deg", SGRawValueMethods<GPS, double>
(*this, &GPS::getSelectedCourse, NULL));
(*this, &GPS::getSelectedCourse, &GPS::setSelectedCourse));
tie(_gpsNode, "desired-course-deg", SGRawValueMethods<GPS, double>
(*this, &GPS::getDesiredCourse, NULL));
_desiredCourseNode = _gpsNode->getChild("desired-course-deg");
tieSGGeodReadOnly(_gpsNode, _indicated_pos, "indicated-longitude-deg",
"indicated-latitude-deg", "indicated-altitude-ft");
@ -465,6 +422,7 @@ GPS::clearOutput()
_indicated_pos = SGGeod();
_last_vertical_speed = 0.0;
_last_true_track = 0.0;
_lastEWVelocity = _lastNSVelocity = 0.0;
_raim_node->setDoubleValue(0.0);
_indicated_pos = SGGeod();
@ -476,6 +434,8 @@ GPS::clearOutput()
_tracking_bug_node->setDoubleValue(0);
_true_bug_error_node->setDoubleValue(0);
_magnetic_bug_error_node->setDoubleValue(0);
_northSouthVelocity->setDoubleValue(0.0);
_eastWestVelocity->setDoubleValue(0.0);
}
void
@ -539,9 +499,7 @@ GPS::update (double delta_time_sec)
updateBasicData(delta_time_sec);
if (_dataValid) {
if (_mode == "obs") {
_selectedCourse = _config.getExternalCourse();
} else {
if (_mode != "obs") {
updateTurn();
}
@ -555,9 +513,7 @@ GPS::update (double delta_time_sec)
if (_dataValid && (_mode == "init")) {
// allow a realistic delay in the future, here
SG_LOG(SG_INSTR, SG_INFO, "GPS initialisation complete");
_selectedCourse = _config.getExternalCourse();
if (_route_active_node->getBoolValue()) {
// GPS init with active route
SG_LOG(SG_INSTR, SG_INFO, "GPS init with active route");
@ -594,9 +550,28 @@ GPS::updateBasicData(double dt)
double vertical_speed_mpm = ((_indicated_pos.getElevationM() - _last_pos.getElevationM()) * 60 / dt);
_last_vertical_speed = vertical_speed_mpm * SG_METER_TO_FEET;
speed_kt = fgGetLowPass(_last_speed_kts, speed_kt, dt/20.0);
speed_kt = fgGetLowPass(_last_speed_kts, speed_kt, dt/10.0);
_last_speed_kts = speed_kt;
SGGeod g = _indicated_pos;
g.setLongitudeDeg(_last_pos.getLongitudeDeg());
double northSouthM = SGGeodesy::distanceM(_last_pos, g);
northSouthM = copysign(northSouthM, _indicated_pos.getLatitudeDeg() - _last_pos.getLatitudeDeg());
double nsMSec = fgGetLowPass(_lastNSVelocity, northSouthM / dt, dt/2.0);
_lastNSVelocity = nsMSec;
_northSouthVelocity->setDoubleValue(nsMSec);
g = _indicated_pos;
g.setLatitudeDeg(_last_pos.getLatitudeDeg());
double eastWestM = SGGeodesy::distanceM(_last_pos, g);
eastWestM = copysign(eastWestM, _indicated_pos.getLongitudeDeg() - _last_pos.getLongitudeDeg());
double ewMSec = fgGetLowPass(_lastEWVelocity, eastWestM / dt, dt/2.0);
_lastEWVelocity = ewMSec;
_eastWestVelocity->setDoubleValue(ewMSec);
double odometer = _odometer_node->getDoubleValue();
_odometer_node->setDoubleValue(odometer + distance_m * SG_METER_TO_NM);
odometer = _trip_odometer_node->getDoubleValue();
@ -655,7 +630,6 @@ void GPS::updateReferenceNavaid(double dt)
FGNavRecord* vor = (FGNavRecord*) nav.ptr();
_ref_navaid_frequency_node->setDoubleValue(vor->get_freq() / 100.0);
_listener->setGuard(false);
tuneNavRadios();
} else {
// SG_LOG(SG_INSTR, SG_ALERT, "matched existing");
}
@ -694,29 +668,12 @@ void GPS::referenceNavaidSet(const std::string& aNavaid)
_ref_navaid_name_node->setStringValue(_ref_navaid->name().c_str());
FGNavRecord* vor = (FGNavRecord*) _ref_navaid.ptr();
_ref_navaid_frequency_node->setDoubleValue(vor->get_freq() / 100.0);
tuneNavRadios();
} else {
_ref_navaid_set = false;
_ref_navaid_elapsed = 9999.0; // update next tick
}
}
void GPS::tuneNavRadios()
{
if (!_ref_navaid || !_config.tuneNavRadioToRefVor()) {
return;
}
SGPropertyNode_ptr navRadio1 = fgGetNode("/instrumentation/nav", false);
if (!navRadio1) {
return;
}
FGNavRecord* vor = (FGNavRecord*) _ref_navaid.ptr();
SGPropertyNode_ptr freqs = navRadio1->getChild("frequencies");
freqs->setDoubleValue("selected-mhz", vor->get_freq() / 100.0);
}
void GPS::routeActivated()
{
if (_route_active_node->getBoolValue()) {
@ -763,7 +720,8 @@ void GPS::routeManagerSequenced()
_wp1Name = wp1.get_name();
_wp1_position = wp1.get_target();
_selectedCourse = getLegMagCourse();
_desiredCourse = getLegMagCourse();
_desiredCourseNode->fireValueChanged();
wp1Changed();
}
@ -917,7 +875,7 @@ void GPS::computeTurnData()
return;
}
_turnStartBearing = _selectedCourse;
_turnStartBearing = _desiredCourse;
// compute next leg course
SGWayPoint wp1(_routeMgr->get_waypoint(curIndex)),
wp2(_routeMgr->get_waypoint(curIndex + 1));
@ -1013,9 +971,6 @@ void GPS::driveAutopilot()
void GPS::wp1Changed()
{
// update external HSI/CDI/NavDisplay/PFD/etc
_config.setExternalCourse(getLegMagCourse());
if (!_config.driveAutopilot()) {
return;
}
@ -1029,6 +984,19 @@ void GPS::wp1Changed()
/////////////////////////////////////////////////////////////////////////////
// property getter/setters
void GPS::setSelectedCourse(double crs)
{
if (_selectedCourse == crs) {
return;
}
_selectedCourse = crs;
if ((_mode == "obs") || _config.courseSelectable()) {
_desiredCourse = _selectedCourse;
_desiredCourseNode->fireValueChanged();
}
}
double GPS::getLegDistance() const
{
if (!_dataValid || (_mode == "obs")) {
@ -1197,7 +1165,7 @@ double GPS::getWP1CourseDeviation() const
return 0.0;
}
double dev = getWP1MagBearing() - _selectedCourse;
double dev = getWP1MagBearing() - _desiredCourse;
SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
if (fabs(dev) > 90.0) {
@ -1227,7 +1195,7 @@ bool GPS::getWP1ToFlag() const
return false;
}
double dev = getWP1MagBearing() - _selectedCourse;
double dev = getWP1MagBearing() - _desiredCourse;
SG_NORMALIZE_RANGE(dev, -180.0, 180.0);
return (fabs(dev) < 90.0);
@ -1357,20 +1325,18 @@ bool GPS::isScratchPositionValid() const
void GPS::directTo()
{
if (!isScratchPositionValid()) {
SG_LOG(SG_INSTR, SG_WARN, "invalid DTO lat/lon");
return;
_wp0_position = _indicated_pos;
if (isScratchPositionValid()) {
_wp1Ident = _scratchNode->getStringValue("ident");
_wp1Name = _scratchNode->getStringValue("name");
_wp1_position = _scratchPos;
}
_wp0_position = _indicated_pos;
_wp1Ident = _scratchNode->getStringValue("ident");
_wp1Name = _scratchNode->getStringValue("name");
_wp1_position = _scratchPos;
_mode = "dto";
_selectedCourse = getLegMagCourse();
_desiredCourse = getLegMagCourse();
_desiredCourseNode->fireValueChanged();
clearScratch();
wp1Changed();
}
@ -1640,17 +1606,14 @@ void GPS::addAirportToScratch(FGAirport* aAirport)
void GPS::selectOBSMode()
{
if (!isScratchPositionValid()) {
SG_LOG(SG_INSTR, SG_WARN, "invalid OBS lat/lon");
return;
if (isScratchPositionValid()) {
_wp1Ident = _scratchNode->getStringValue("ident");
_wp1Name = _scratchNode->getStringValue("name");
_wp1_position = _scratchPos;
}
SG_LOG(SG_INSTR, SG_INFO, "GPS switching to OBS mode");
_mode = "obs";
_wp1Ident = _scratchNode->getStringValue("ident");
_wp1Name = _scratchNode->getStringValue("name");
_wp1_position = _scratchPos;
_wp0_position = _indicated_pos;
wp1Changed();
}

View file

@ -123,19 +123,12 @@ private:
double waypointAlertTime() const
{ return _waypointAlertTime; }
bool tuneNavRadioToRefVor() const
{ return _tuneRadio1ToRefVor; }
bool requireHardSurface() const
{ return _requireHardSurface; }
double minRunwayLengthFt() const
{ return _minRunwayLengthFt; }
double getExternalCourse() const;
void setExternalCourse(double aCourseDeg);
bool cdiDeflectionIsAngular() const
{ return (_cdiMaxDeflectionNm <= 0.0); }
@ -147,6 +140,9 @@ private:
bool driveAutopilot() const
{ return _driveAutopilot; }
bool courseSelectable() const
{ return _courseSelectable; }
private:
bool _enableTurnAnticipation;
@ -160,25 +156,19 @@ private:
// (in seconds)
double _waypointAlertTime;
// should GPS automatically tune NAV1 to the reference VOR?
bool _tuneRadio1ToRefVor;
// minimum runway length to require when filtering
double _minRunwayLengthFt;
// should we require a hard-surfaced runway when filtering?
bool _requireHardSurface;
// helpers to tie course-source property
const char* getCourseSource() const;
void setCourseSource(const char* aPropPath);
// property to retrieve the external course from
SGPropertyNode_ptr _extCourseSource;
double _cdiMaxDeflectionNm;
// should we drive the autopilot directly or not?
bool _driveAutopilot;
// is selected-course-deg read to set desired-course or not?
bool _courseSelectable;
};
class SearchFilter : public FGPositioned::Filter
@ -201,7 +191,6 @@ private:
void updateTrackingBug();
void updateReferenceNavaid(double dt);
void referenceNavaidSet(const std::string& aNavaid);
void tuneNavRadios();
void updateRouteData();
void driveAutopilot();
@ -276,6 +265,9 @@ private:
bool getScratchHasNext() const { return _searchHasNext; }
double getSelectedCourse() const { return _selectedCourse; }
void setSelectedCourse(double crs);
double getDesiredCourse() const { return _desiredCourse; }
double getCDIDeflection() const;
double getLegDistance() const;
@ -341,6 +333,8 @@ private:
SGPropertyNode_ptr _trip_odometer_node;
SGPropertyNode_ptr _true_bug_error_node;
SGPropertyNode_ptr _magnetic_bug_error_node;
SGPropertyNode_ptr _eastWestVelocity;
SGPropertyNode_ptr _northSouthVelocity;
SGPropertyNode_ptr _ref_navaid_id_node;
SGPropertyNode_ptr _ref_navaid_bearing_node;
@ -355,8 +349,10 @@ private:
SGPropertyNode_ptr _routeETE;
SGPropertyNode_ptr _routeEditedSignal;
SGPropertyNode_ptr _routeFinishedSignal;
SGPropertyNode_ptr _desiredCourseNode;
double _selectedCourse;
double _desiredCourse;
bool _dataValid;
SGGeod _last_pos;
@ -364,6 +360,8 @@ private:
double _last_speed_kts;
double _last_true_track;
double _last_vertical_speed;
double _lastEWVelocity;
double _lastNSVelocity;
std::string _mode;
GPSListener* _listener;

View file

@ -129,6 +129,9 @@ FGNavRadio::FGNavRadio(SGPropertyNode *node) :
// Destructor
FGNavRadio::~FGNavRadio()
{
gps_course_node->removeChangeListener(this);
nav_slaved_to_gps_node->removeChangeListener(this);
delete term_tbl;
delete low_tbl;
delete high_tbl;
@ -220,11 +223,15 @@ FGNavRadio::init ()
// gps slaving support
nav_slaved_to_gps_node = node->getChild("slaved-to-gps", 0, true);
nav_slaved_to_gps_node->addChangeListener(this);
gps_cdi_deflection_node = fgGetNode("/instrumentation/gps/cdi-deflection", true);
gps_to_flag_node = fgGetNode("/instrumentation/gps/to-flag", true);
gps_from_flag_node = fgGetNode("/instrumentation/gps/from-flag", true);
gps_has_gs_node = fgGetNode("/instrumentation/gps/has-gs", true);
gps_course_node = fgGetNode("/instrumentation/gps/selected-course-deg", true);
gps_course_node = fgGetNode("/instrumentation/gps/desired-course-deg", true);
gps_course_node->addChangeListener(this);
gps_xtrack_error_nm_node = fgGetNode("/instrumentation/gps/wp/wp[1]/course-error-nm", true);
_magvarNode = fgGetNode("/environment/magnetic-variation-deg", true);
@ -625,6 +632,26 @@ void FGNavRadio::updateDME(const SGVec3d& aircraft)
_dmeInRange = (dme_distance < _dme->get_range() * SG_NM_TO_METER);
}
void FGNavRadio::valueChanged (SGPropertyNode* prop)
{
if (prop == gps_course_node) {
if (!nav_slaved_to_gps_node->getBoolValue()) {
return;
}
// GPS desired course has changed, sync up our selected-course
double v = prop->getDoubleValue();
if (v != sel_radial_node->getDoubleValue()) {
sel_radial_node->setDoubleValue(v);
}
} else if (prop == nav_slaved_to_gps_node) {
if (prop->getBoolValue()) {
// slaved-to-GPS activated, sync up selected course
sel_radial_node->setDoubleValue(gps_course_node->getDoubleValue());
}
}
}
void FGNavRadio::updateGPSSlaved()
{
has_gs_node->setBoolValue(gps_has_gs_node->getBoolValue());

View file

@ -39,7 +39,7 @@ class SGSampleGroup;
class FGNavRecord;
typedef SGSharedPtr<FGNavRecord> FGNavRecordPtr;
class FGNavRadio : public SGSubsystem
class FGNavRadio : public SGSubsystem, public SGPropertyChangeListener
{
FGMorse morse;
@ -212,6 +212,9 @@ class FGNavRadio : public SGSubsystem
_tiedNodes.push_back(nd);
nd->tie(aRawValue);
}
// implement SGPropertyChangeListener
virtual void valueChanged (SGPropertyNode * prop);
public:
FGNavRadio(SGPropertyNode *node);