Merge branch 'jmt/gps'
Conflicts: src/Instrumentation/gps.cxx src/Instrumentation/navradio.cxx
This commit is contained in:
commit
8f056da618
14 changed files with 1996 additions and 183 deletions
|
@ -1828,6 +1828,8 @@
|
|||
</File>
|
||||
<File RelativePath="..\..\..\src\GUI\WaypointList.cxx"></File>
|
||||
<File RelativePath="..\..\..\src\GUI\WaypointList.hxx"></File>
|
||||
<File RelativePath="..\..\..\src\GUI\MapWidget.cxx"></File>
|
||||
<File RelativePath="..\..\..\src\GUI\MapWidget.hxx"></File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Lib_Input"
|
||||
|
|
|
@ -2647,6 +2647,8 @@
|
|||
</File>
|
||||
<File RelativePath="..\..\..\src\GUI\WaypointList.cxx"></File>
|
||||
<File RelativePath="..\..\..\src\GUI\WaypointList.hxx"></File>
|
||||
<File RelativePath="..\..\..\src\GUI\MapWidget.cxx"></File>
|
||||
<File RelativePath="..\..\..\src\GUI\MapWidget.hxx"></File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Lib_Input"
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include <simgear/misc/strutils.hxx>
|
||||
#include <simgear/structure/exception.hxx>
|
||||
#include <simgear/misc/sgstream.hxx>
|
||||
|
||||
#include <simgear/props/props_io.hxx>
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
|
@ -597,6 +598,7 @@ void FGRouteMgr::jumpToIndex(int index)
|
|||
|
||||
_route->set_current(index);
|
||||
currentWaypointChanged();
|
||||
_currentWpt->fireValueChanged();
|
||||
}
|
||||
|
||||
void FGRouteMgr::currentWaypointChanged()
|
||||
|
@ -656,16 +658,49 @@ void FGRouteMgr::saveRoute()
|
|||
SGPath path(_pathNode->getStringValue());
|
||||
SG_LOG(SG_IO, SG_INFO, "Saving route to " << path.str());
|
||||
try {
|
||||
writeProperties(path.str(), mirror, false, SGPropertyNode::ARCHIVE);
|
||||
SGPropertyNode_ptr d(new SGPropertyNode);
|
||||
SGPath path(_pathNode->getStringValue());
|
||||
d->setIntValue("version", 1);
|
||||
|
||||
if (_departure) {
|
||||
d->setStringValue("departure/airport", _departure->ident());
|
||||
d->setStringValue("departure/sid", departure->getStringValue("sid"));
|
||||
d->setStringValue("departure/runway", departure->getStringValue("runway"));
|
||||
}
|
||||
|
||||
if (_destination) {
|
||||
d->setStringValue("destination/airport", _destination->ident());
|
||||
d->setStringValue("destination/star", destination->getStringValue("star"));
|
||||
d->setStringValue("destination/transition", destination->getStringValue("transition"));
|
||||
d->setStringValue("destination/runway", destination->getStringValue("runway"));
|
||||
}
|
||||
|
||||
// route nodes
|
||||
SGPropertyNode* routeNode = d->getChild("route", 0, true);
|
||||
for (int i=0; i<_route->size(); ++i) {
|
||||
SGPropertyNode* wpNode = routeNode->getChild("wp",i, true);
|
||||
SGWayPoint wp(_route->get_waypoint(i));
|
||||
|
||||
wpNode->setStringValue("ident", wp.get_id());
|
||||
wpNode->setStringValue("name", wp.get_name());
|
||||
SGGeod geod(wp.get_target());
|
||||
|
||||
wpNode->setDoubleValue("longitude-deg", geod.getLongitudeDeg());
|
||||
wpNode->setDoubleValue("latitude-deg", geod.getLatitudeDeg());
|
||||
|
||||
if (geod.getElevationFt() > -9990.0) {
|
||||
wpNode->setDoubleValue("altitude-ft", geod.getElevationFt());
|
||||
}
|
||||
} // of waypoint iteration
|
||||
|
||||
writeProperties(path.str(), d, true /* write-all */);
|
||||
} catch (const sg_exception &e) {
|
||||
SG_LOG(SG_IO, SG_WARN, "Error saving route:" << e.getMessage());
|
||||
//guiErrorMessage("Error writing autosave.xml: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
void FGRouteMgr::loadRoute()
|
||||
{
|
||||
try {
|
||||
// deactivate route first
|
||||
active->setBoolValue(false);
|
||||
|
||||
|
@ -673,8 +708,16 @@ void FGRouteMgr::loadRoute()
|
|||
SGPath path(_pathNode->getStringValue());
|
||||
|
||||
SG_LOG(SG_IO, SG_INFO, "going to read flight-plan from:" << path.str());
|
||||
readProperties(path.str(), routeData);
|
||||
|
||||
try {
|
||||
readProperties(path.str(), routeData);
|
||||
} catch (sg_exception& e) {
|
||||
// if XML parsing fails, the file might be simple textual list of waypoints
|
||||
loadPlainTextRoute(path);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// departure nodes
|
||||
SGPropertyNode* dep = routeData->getChild("departure");
|
||||
if (!dep) {
|
||||
|
@ -703,7 +746,9 @@ void FGRouteMgr::loadRoute()
|
|||
// cruise
|
||||
SGPropertyNode* crs = routeData->getChild("cruise");
|
||||
if (crs) {
|
||||
cruise->setDoubleValue(crs->getDoubleValue("speed"));
|
||||
cruise->setDoubleValue("speed-kts", crs->getDoubleValue("speed-kts"));
|
||||
cruise->setDoubleValue("mach", crs->getDoubleValue("mach"));
|
||||
cruise->setDoubleValue("altitude-ft", crs->getDoubleValue("altitude-ft"));
|
||||
} // of cruise data loading
|
||||
|
||||
// route nodes
|
||||
|
@ -734,7 +779,7 @@ void FGRouteMgr::parseRouteWaypoint(SGPropertyNode* aWP)
|
|||
}
|
||||
|
||||
SGPropertyNode_ptr altProp = aWP->getChild("altitude-ft");
|
||||
double altM = cruise->getDoubleValue("altitude-ft") * SG_FEET_TO_METER;
|
||||
double altM = -9999.0;
|
||||
if (altProp) {
|
||||
altM = altProp->getDoubleValue() * SG_FEET_TO_METER;
|
||||
}
|
||||
|
@ -780,6 +825,26 @@ void FGRouteMgr::parseRouteWaypoint(SGPropertyNode* aWP)
|
|||
}
|
||||
}
|
||||
|
||||
void FGRouteMgr::loadPlainTextRoute(const SGPath& path)
|
||||
{
|
||||
sg_gzifstream in(path.str().c_str());
|
||||
if (!in.is_open()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_route->clear();
|
||||
while (!in.eof()) {
|
||||
string line;
|
||||
getline(in, line, '\n');
|
||||
// trim CR from end of line, if found
|
||||
if (line[line.size() - 1] == '\r') {
|
||||
line.erase(line.size() - 1, 1);
|
||||
}
|
||||
|
||||
new_waypoint(line, -1);
|
||||
} // of line iteration
|
||||
}
|
||||
|
||||
const char* FGRouteMgr::getDepartureICAO() const
|
||||
{
|
||||
if (!_departure) {
|
||||
|
|
|
@ -135,6 +135,9 @@ private:
|
|||
*/
|
||||
bool checkFinished();
|
||||
|
||||
|
||||
void loadPlainTextRoute(const SGPath& path);
|
||||
|
||||
// tied getters and setters
|
||||
const char* getDepartureICAO() const;
|
||||
const char* getDepartureName() const;
|
||||
|
|
|
@ -23,7 +23,8 @@ libGUI_a_SOURCES = \
|
|||
property_list.cxx property_list.hxx \
|
||||
layout.cxx layout-props.cxx layout.hxx \
|
||||
SafeTexFont.cxx SafeTexFont.hxx \
|
||||
WaypointList.cxx WaypointList.hxx
|
||||
WaypointList.cxx WaypointList.hxx \
|
||||
MapWidget.cxx MapWidget.hxx
|
||||
|
||||
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src
|
||||
|
||||
|
|
1613
src/GUI/MapWidget.cxx
Normal file
1613
src/GUI/MapWidget.cxx
Normal file
File diff suppressed because it is too large
Load diff
109
src/GUI/MapWidget.hxx
Normal file
109
src/GUI/MapWidget.hxx
Normal file
|
@ -0,0 +1,109 @@
|
|||
#ifndef GUI_MAPWIDGET_HXX
|
||||
#define GUI_MAPWIDGET_HXX
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
#include <simgear/props/props.hxx>
|
||||
|
||||
#include <plib/pu.h>
|
||||
|
||||
#include "dialog.hxx" // for GUI_ID
|
||||
|
||||
// forward decls
|
||||
class FGRouteMgr;
|
||||
class FGRunway;
|
||||
class FGAirport;
|
||||
class FGNavRecord;
|
||||
class FGFix;
|
||||
class MapData;
|
||||
class SGMagVar;
|
||||
|
||||
class MapWidget : public puObject
|
||||
{
|
||||
public:
|
||||
MapWidget(int x, int y, int width, int height);
|
||||
virtual ~MapWidget();
|
||||
|
||||
virtual void setSize(int width, int height);
|
||||
virtual void doHit( int button, int updown, int x, int y ) ;
|
||||
virtual void draw( int dx, int dy ) ;
|
||||
virtual int checkKey(int key, int updown);
|
||||
|
||||
void setProperty(SGPropertyNode_ptr prop);
|
||||
private:
|
||||
void handlePan(int x, int y);
|
||||
|
||||
void pan(const SGVec2d& delta);
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
|
||||
void paintAircraftLocation(const SGGeod& aircraftPos);
|
||||
void paintRoute();
|
||||
void paintRuler();
|
||||
|
||||
void drawGPSData();
|
||||
void drawNavRadio(SGPropertyNode_ptr radio);
|
||||
void drawTunedLocalizer(SGPropertyNode_ptr radio);
|
||||
|
||||
void drawLatLonGrid();
|
||||
SGVec2d gridPoint(int ix, int iy);
|
||||
bool drawLineClipped(const SGVec2d& a, const SGVec2d& b);
|
||||
|
||||
void drawAirports();
|
||||
void drawAirport(FGAirport* apt);
|
||||
int scoreAirportRunways(FGAirport* apt);
|
||||
void drawRunwayPre(FGRunway* rwy);
|
||||
void drawRunway(FGRunway* rwy);
|
||||
void drawILS(bool tuned, FGRunway* rwy);
|
||||
|
||||
void drawNavaids();
|
||||
void drawNDB(bool tuned, FGNavRecord* nav);
|
||||
void drawVOR(bool tuned, FGNavRecord* nav);
|
||||
void drawFix(FGFix* fix);
|
||||
|
||||
void drawTraffic();
|
||||
void drawAIAircraft(const SGPropertyNode* model, const SGGeod& pos, double hdg);
|
||||
void drawAIShip(const SGPropertyNode* model, const SGGeod& pos, double hdg);
|
||||
|
||||
void drawData();
|
||||
bool validDataForKey(void* key);
|
||||
MapData* getOrCreateDataForKey(void* key);
|
||||
MapData* createDataForKey(void* key);
|
||||
void setAnchorForKey(void* key, const SGVec2d& anchor);
|
||||
|
||||
SGVec2d project(const SGGeod& geod) const;
|
||||
SGGeod unproject(const SGVec2d& p) const;
|
||||
double currentScale() const;
|
||||
|
||||
void circleAt(const SGVec2d& center, int nSides, double r);
|
||||
void circleAtAlt(const SGVec2d& center, int nSides, double r, double r2);
|
||||
void drawLine(const SGVec2d& p1, const SGVec2d& p2);
|
||||
void drawLegendBox(const SGVec2d& pos, const std::string& t);
|
||||
|
||||
int _width, _height;
|
||||
int _zoom;
|
||||
double _drawRangeNm;
|
||||
double _upHeading; // true heading corresponding to +ve y-axis
|
||||
bool _magneticHeadings;
|
||||
|
||||
SGGeod _projectionCenter;
|
||||
SGGeod _aircraft;
|
||||
SGGeod _clickGeod;
|
||||
SGVec2d _hitLocation;
|
||||
FGRouteMgr* _route;
|
||||
SGPropertyNode_ptr _root;
|
||||
SGPropertyNode_ptr _gps;
|
||||
|
||||
typedef std::map<void*, MapData*> KeyDataMap;
|
||||
KeyDataMap _mapData;
|
||||
std::vector<MapData*> _dataQueue;
|
||||
|
||||
SGMagVar* _magVar;
|
||||
|
||||
typedef std::map<int, SGVec2d> GridPointCache;
|
||||
GridPointCache _gridCache;
|
||||
double _gridSpacing;
|
||||
SGGeod _gridCenter;
|
||||
};
|
||||
|
||||
#endif // of GUI_MAPWIDGET_HXX
|
|
@ -14,6 +14,7 @@
|
|||
#include "property_list.hxx"
|
||||
#include "layout.hxx"
|
||||
#include "WaypointList.hxx"
|
||||
#include "MapWidget.hxx"
|
||||
|
||||
enum format_type { f_INVALID, f_INT, f_LONG, f_FLOAT, f_DOUBLE, f_STRING };
|
||||
static const int FORMAT_BUFSIZE = 255;
|
||||
|
@ -815,7 +816,10 @@ FGDialog::makeObject (SGPropertyNode *props, int parentWidth, int parentHeight)
|
|||
setupObject(obj, props);
|
||||
setColor(obj, props);
|
||||
return obj;
|
||||
|
||||
} else if (type == "map") {
|
||||
MapWidget* mapWidget = new MapWidget(x, y, x + width, y + height);
|
||||
setupObject(mapWidget, props);
|
||||
return mapWidget;
|
||||
} else if (type == "combo") {
|
||||
fgComboBox *obj = new fgComboBox(x, y, x + width, y + height, props,
|
||||
props->getBoolValue("editable", false));
|
||||
|
@ -953,14 +957,23 @@ FGDialog::setupObject (puObject *object, SGPropertyNode *props)
|
|||
name = "";
|
||||
const char *propname = props->getStringValue("property");
|
||||
SGPropertyNode_ptr node = fgGetNode(propname, true);
|
||||
if (type == "map") {
|
||||
// mapWidget binds to a sub-tree of properties, and
|
||||
// ignroes the puValue mechanism, so special case things here
|
||||
MapWidget* mw = static_cast<MapWidget*>(object);
|
||||
mw->setProperty(node);
|
||||
} else {
|
||||
// normal widget, creating PropertyObject
|
||||
copy_to_pui(node, object);
|
||||
|
||||
PropertyObject *po = new PropertyObject(name, object, node);
|
||||
_propertyObjects.push_back(po);
|
||||
if (props->getBoolValue("live"))
|
||||
_liveObjects.push_back(po);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
SGPropertyNode *dest = fgGetNode("/sim/bindings/gui", true);
|
||||
vector<SGPropertyNode_ptr> bindings = props->getChildren("binding");
|
||||
if (bindings.size() > 0) {
|
||||
|
|
|
@ -188,79 +188,32 @@ 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));
|
||||
}
|
||||
|
||||
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);
|
||||
aOwner->tie(aCfg, "course-selectable", SGRawValuePointer<bool>(&_courseSelectable));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GPS::GPS ( SGPropertyNode *node) :
|
||||
_selectedCourse(0.0),
|
||||
_desiredCourse(0.0),
|
||||
_dataValid(false),
|
||||
_lastPosValid(false),
|
||||
_mode("init"),
|
||||
|
@ -297,6 +250,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 +259,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);
|
||||
|
@ -349,6 +304,7 @@ GPS::init ()
|
|||
fromFlag->alias(wp1_node->getChild("from-flag"));
|
||||
|
||||
// autopilot drive properties
|
||||
_apDrivingFlag = fgGetNode("/autopilot/settings/gps-driving-true-heading", true);
|
||||
_apTrueHeading = fgGetNode("/autopilot/settings/true-heading-deg",true);
|
||||
_apTargetAltitudeFt = fgGetNode("/autopilot/settings/target-altitude-ft", true);
|
||||
_apAltitudeLock = fgGetNode("/autopilot/locks/altitude", true);
|
||||
|
@ -371,8 +327,11 @@ 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 +424,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 +436,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 +501,7 @@ GPS::update (double delta_time_sec)
|
|||
updateBasicData(delta_time_sec);
|
||||
|
||||
if (_dataValid) {
|
||||
if (_mode == "obs") {
|
||||
_selectedCourse = _config.getExternalCourse();
|
||||
} else {
|
||||
if (_mode != "obs") {
|
||||
updateTurn();
|
||||
}
|
||||
|
||||
|
@ -556,8 +516,6 @@ GPS::update (double delta_time_sec)
|
|||
// 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 +552,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 +632,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 +670,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 +722,8 @@ void GPS::routeManagerSequenced()
|
|||
_wp1Name = wp1.get_name();
|
||||
_wp1_position = wp1.get_target();
|
||||
|
||||
_selectedCourse = getLegMagCourse();
|
||||
_desiredCourse = getLegMagCourse();
|
||||
_desiredCourseNode->fireValueChanged();
|
||||
wp1Changed();
|
||||
}
|
||||
|
||||
|
@ -917,7 +877,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));
|
||||
|
@ -1000,12 +960,17 @@ void GPS::updateRouteData()
|
|||
void GPS::driveAutopilot()
|
||||
{
|
||||
if (!_config.driveAutopilot() || !_realismSimpleGps->getBoolValue()) {
|
||||
_apDrivingFlag->setBoolValue(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// compatability feature - allow the route-manager / GPS to drive the
|
||||
// generic autopilot heading hold *in leg mode only*
|
||||
if (_mode == "leg") {
|
||||
|
||||
bool drive = _mode == "leg";
|
||||
_apDrivingFlag->setBoolValue(drive);
|
||||
|
||||
if (drive) {
|
||||
// FIXME: we want to set desired track, not heading, here
|
||||
_apTrueHeading->setDoubleValue(getWP1Bearing());
|
||||
}
|
||||
|
@ -1013,9 +978,6 @@ void GPS::driveAutopilot()
|
|||
|
||||
void GPS::wp1Changed()
|
||||
{
|
||||
// update external HSI/CDI/NavDisplay/PFD/etc
|
||||
_config.setExternalCourse(getLegMagCourse());
|
||||
|
||||
if (!_config.driveAutopilot()) {
|
||||
return;
|
||||
}
|
||||
|
@ -1029,6 +991,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 +1172,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 +1202,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 +1332,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;
|
||||
}
|
||||
|
||||
_mode = "dto";
|
||||
_selectedCourse = getLegMagCourse();
|
||||
_desiredCourse = getLegMagCourse();
|
||||
_desiredCourseNode->fireValueChanged();
|
||||
clearScratch();
|
||||
|
||||
wp1Changed();
|
||||
}
|
||||
|
||||
|
@ -1640,17 +1613,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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -415,6 +413,7 @@ private:
|
|||
SGPropertyNode_ptr _realismSimpleGps; ///< should the GPS be simple or realistic?
|
||||
|
||||
// autopilot drive properties
|
||||
SGPropertyNode_ptr _apDrivingFlag;
|
||||
SGPropertyNode_ptr _apTrueHeading;
|
||||
SGPropertyNode_ptr _apTargetAltitudeFt;
|
||||
SGPropertyNode_ptr _apAltitudeLock;
|
||||
|
|
|
@ -129,6 +129,14 @@ FGNavRadio::FGNavRadio(SGPropertyNode *node) :
|
|||
// Destructor
|
||||
FGNavRadio::~FGNavRadio()
|
||||
{
|
||||
if (gps_course_node) {
|
||||
gps_course_node->removeChangeListener(this);
|
||||
}
|
||||
|
||||
if (nav_slaved_to_gps_node) {
|
||||
nav_slaved_to_gps_node->removeChangeListener(this);
|
||||
}
|
||||
|
||||
delete term_tbl;
|
||||
delete low_tbl;
|
||||
delete high_tbl;
|
||||
|
@ -220,11 +228,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 +637,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());
|
||||
|
@ -864,7 +896,7 @@ void FGNavRadio::search()
|
|||
} else { // ILS or LOC
|
||||
_gs = globals->get_gslist()->findByFreq(freq, pos);
|
||||
has_gs_node->setBoolValue(_gs != NULL);
|
||||
_localizerWidth = localizerWidth(nav);
|
||||
_localizerWidth = nav->localizerWidth();
|
||||
twist = 0.0;
|
||||
effective_range = nav->get_range();
|
||||
|
||||
|
@ -914,39 +946,6 @@ void FGNavRadio::search()
|
|||
id_c4_node->setIntValue( (int)identBuffer[3] );
|
||||
}
|
||||
|
||||
double FGNavRadio::localizerWidth(FGNavRecord* aLOC)
|
||||
{
|
||||
FGRunway* rwy = aLOC->runway();
|
||||
if (!rwy) {
|
||||
return 6.0; // no runway associated, return default value
|
||||
}
|
||||
|
||||
|
||||
SGVec3d thresholdCart(SGVec3d::fromGeod(rwy->threshold()));
|
||||
double axisLength = dist(aLOC->cart(), thresholdCart);
|
||||
double landingLength = dist(thresholdCart, SGVec3d::fromGeod(rwy->end()));
|
||||
|
||||
// Reference: http://dcaa.slv.dk:8000/icaodocs/
|
||||
// ICAO standard width at threshold is 210 m = 689 feet = approx 700 feet.
|
||||
// ICAO 3.1.1 half course = DDM = 0.0775
|
||||
// ICAO 3.1.3.7.1 Sensitivity 0.00145 DDM/m at threshold
|
||||
// implies peg-to-peg of 214 m ... we will stick with 210.
|
||||
// ICAO 3.1.3.7.1 "Course sector angle shall not exceed 6 degrees."
|
||||
|
||||
// Very short runway: less than 1200 m (4000 ft) landing length:
|
||||
if (landingLength < 1200.0) {
|
||||
// ICAO fudges localizer sensitivity for very short runways.
|
||||
// This produces a non-monotonic sensitivity-versus length relation.
|
||||
axisLength += 1050.0;
|
||||
}
|
||||
|
||||
// Example: very short: San Diego KMYF (Montgomery Field) ILS RWY 28R
|
||||
// Example: short: Tom's River KMJX (Robert J. Miller) ILS RWY 6
|
||||
// Example: very long: Denver KDEN (Denver) ILS RWY 16R
|
||||
double raw_width = 210.0 / axisLength * SGD_RADIANS_TO_DEGREES;
|
||||
return raw_width < 6.0? raw_width : 6.0;
|
||||
}
|
||||
|
||||
void FGNavRadio::audioNavidChanged()
|
||||
{
|
||||
if (_sgr->exists(nav_fx_name)) {
|
||||
|
|
|
@ -39,7 +39,7 @@ class SGSampleGroup;
|
|||
class FGNavRecord;
|
||||
typedef SGSharedPtr<FGNavRecord> FGNavRecordPtr;
|
||||
|
||||
class FGNavRadio : public SGSubsystem
|
||||
class FGNavRadio : public SGSubsystem, public SGPropertyChangeListener
|
||||
{
|
||||
FGMorse morse;
|
||||
|
||||
|
@ -191,11 +191,6 @@ class FGNavRadio : public SGSubsystem
|
|||
|
||||
void clearOutputs();
|
||||
|
||||
/**
|
||||
* Compute the localizer width in degrees - see implementation for
|
||||
* more information on the relevant standards and formulae.
|
||||
*/
|
||||
double localizerWidth(FGNavRecord* aLOC);
|
||||
FGNavRecord* findPrimaryNavaid(const SGGeod& aPos, double aFreqMHz);
|
||||
|
||||
/// accessor for tied, read-only 'operable' property
|
||||
|
@ -212,6 +207,9 @@ class FGNavRadio : public SGSubsystem
|
|||
_tiedNodes.push_back(nd);
|
||||
nd->tie(aRawValue);
|
||||
}
|
||||
|
||||
// implement SGPropertyChangeListener
|
||||
virtual void valueChanged (SGPropertyNode * prop);
|
||||
public:
|
||||
|
||||
FGNavRadio(SGPropertyNode *node);
|
||||
|
|
|
@ -181,6 +181,38 @@ void FGNavRecord::alignLocaliserWithRunway(double aThreshold)
|
|||
}
|
||||
}
|
||||
|
||||
double FGNavRecord::localizerWidth() const
|
||||
{
|
||||
if (!mRunway) {
|
||||
return 6.0;
|
||||
}
|
||||
|
||||
SGVec3d thresholdCart(SGVec3d::fromGeod(mRunway->threshold()));
|
||||
double axisLength = dist(cart(), thresholdCart);
|
||||
double landingLength = dist(thresholdCart, SGVec3d::fromGeod(mRunway->end()));
|
||||
|
||||
// Reference: http://dcaa.slv.dk:8000/icaodocs/
|
||||
// ICAO standard width at threshold is 210 m = 689 feet = approx 700 feet.
|
||||
// ICAO 3.1.1 half course = DDM = 0.0775
|
||||
// ICAO 3.1.3.7.1 Sensitivity 0.00145 DDM/m at threshold
|
||||
// implies peg-to-peg of 214 m ... we will stick with 210.
|
||||
// ICAO 3.1.3.7.1 "Course sector angle shall not exceed 6 degrees."
|
||||
|
||||
// Very short runway: less than 1200 m (4000 ft) landing length:
|
||||
if (landingLength < 1200.0) {
|
||||
// ICAO fudges localizer sensitivity for very short runways.
|
||||
// This produces a non-monotonic sensitivity-versus length relation.
|
||||
axisLength += 1050.0;
|
||||
}
|
||||
|
||||
// Example: very short: San Diego KMYF (Montgomery Field) ILS RWY 28R
|
||||
// Example: short: Tom's River KMJX (Robert J. Miller) ILS RWY 6
|
||||
// Example: very long: Denver KDEN (Denver) ILS RWY 16R
|
||||
double raw_width = 210.0 / axisLength * SGD_RADIANS_TO_DEGREES;
|
||||
return raw_width < 6.0? raw_width : 6.0;
|
||||
|
||||
}
|
||||
|
||||
FGTACANRecord::FGTACANRecord(void) :
|
||||
channel(""),
|
||||
freq(0)
|
||||
|
|
|
@ -96,6 +96,13 @@ public:
|
|||
* Retrieve the runway this navaid is associated with (for ILS/LOC/GS)
|
||||
*/
|
||||
FGRunway* runway() const { return mRunway; }
|
||||
|
||||
/**
|
||||
* return the localizer width, in degrees
|
||||
* computation is based up ICAO stdandard width at the runway threshold
|
||||
* see implementation for further details.
|
||||
*/
|
||||
double localizerWidth() const;
|
||||
};
|
||||
|
||||
class FGTACANRecord : public SGReferenced {
|
||||
|
|
Loading…
Reference in a new issue