]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/gps.hxx
Fix two bugs in the new autopilot code
[flightgear.git] / src / Instrumentation / gps.hxx
index 15d9a8b148556097a9709ab62d27d2eb2e7fc102..f1a1b43967ffc7659cd50ae3376dea7100ac80c0 100644 (file)
@@ -82,7 +82,9 @@ public:
 
     virtual void init ();
     virtual void update (double delta_time_sec);
-
+    
+    virtual void bind();
+    virtual void unbind();
 private:
     friend class GPSListener;
     friend class SearchFilter;
@@ -94,8 +96,8 @@ private:
     {
     public:
       Config();
-      
-      void init(SGPropertyNode*);
+            
+      void bind(GPS* aOwner, SGPropertyNode* aCfg);
       
       bool turnAnticipationEnabled() const
       { return _enableTurnAnticipation; }
@@ -121,17 +123,12 @@ private:
       double waypointAlertTime() const
       { return _waypointAlertTime; }
             
-      bool tuneNavRadioToRefVor() const
-      { return _tuneRadio1ToRefVor; }
-      
       bool requireHardSurface() const
       { return _requireHardSurface; }
       
       double minRunwayLengthFt() const
       { return _minRunwayLengthFt; }
       
-      double getOBSCourse() const;
-      
       bool cdiDeflectionIsAngular() const
       { return (_cdiMaxDeflectionNm <= 0.0); }
       
@@ -140,6 +137,12 @@ private:
         assert(_cdiMaxDeflectionNm > 0.0);
         return _cdiMaxDeflectionNm;
       }
+      
+      bool driveAutopilot() const
+      { return _driveAutopilot; }
+      
+      bool courseSelectable() const
+      { return _courseSelectable; }
     private:
       bool _enableTurnAnticipation;
       
@@ -153,23 +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 obs-course-source property
-      const char* getOBSCourseSource() const;
-      void setOBSCourseSource(const char* aPropPath);
+      double _cdiMaxDeflectionNm;
       
-      // property to retrieve the OBS course from
-      SGPropertyNode_ptr _obsCourseSource;
+      // should we drive the autopilot directly or not?
+      bool _driveAutopilot;
       
-      double _cdiMaxDeflectionNm;
+      // is selected-course-deg read to set desired-course or not?
+      bool _courseSelectable;
     };
     
     class SearchFilter : public FGPositioned::Filter
@@ -186,18 +185,19 @@ private:
      */
     void clearOutput();
 
-    void updateWithValid(double dt);
     void updateBasicData(double dt);
     void updateWaypoints();
 
     void updateTrackingBug();
     void updateReferenceNavaid(double dt);
     void referenceNavaidSet(const std::string& aNavaid);
-    void tuneNavRadios();
     void updateRouteData();
+    void driveAutopilot();
     
     void routeActivated();
     void routeManagerSequenced();
+    void routeEdited();
+    void routeFinished();
     
     void updateTurn();  
     void updateOverflight();    
@@ -208,8 +208,12 @@ private:
     void computeTurnData();
     void updateTurnData();
     double computeTurnRadiusNm(double aGroundSpeedKts) const;
-    
-
+  
+  /**
+   * Update one-shot things when WP1 / leg data change
+   */
+  void wp1Changed();
+  
 // scratch maintenence utilities
   void setScratchFromPositioned(FGPositioned* aPos, int aIndex);
   void setScratchFromCachedSearchResult();
@@ -245,6 +249,8 @@ private:
   void nextResult();
   void previousResult();
   void defineWaypoint();
+  void insertWaypointAtIndex(int aIndex);
+  void removeWaypointAtIndex(int aIndex);
   
 // tied-property getter/setters
   void setCommand(const char* aCmd);
@@ -259,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;
@@ -288,11 +297,32 @@ private:
   double getWP1CourseDeviation() const;
   double getWP1CourseErrorNm() const;
   bool getWP1ToFlag() const;
-  // true-bearing-error and mag-bearing-error
+  bool getWP1FromFlag() const;
   
+  // true-bearing-error and mag-bearing-error
   
+
+  /**
+   * Tied-properties helper, record nodes which are tied for easy un-tie-ing
+   */
+  template <typename T>
+  void tie(SGPropertyNode* aNode, const char* aRelPath, const SGRawValue<T>& aRawValue)
+  {
+    SGPropertyNode* nd = aNode->getNode(aRelPath, true);
+    _tiedNodes.push_back(nd);
+    nd->tie(aRawValue);
+  }
+
+  /// helper, tie the lat/lon/elev of a SGGeod to the named children of aNode
+  void tieSGGeod(SGPropertyNode* aNode, SGGeod& aRef, 
+    const char* lonStr, const char* latStr, const char* altStr);
   
+  /// helper, tie a SGGeod to proeprties, but read-only
+  void tieSGGeodReadOnly(SGPropertyNode* aNode, SGGeod& aRef, 
+    const char* lonStr, const char* latStr, const char* altStr);
+
 // members
+  SGPropertyNode_ptr _gpsNode;
   SGPropertyNode_ptr _magvar_node;
   SGPropertyNode_ptr _serviceable_node;
   SGPropertyNode_ptr _electrical_node;
@@ -303,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;
@@ -315,16 +347,21 @@ private:
     SGPropertyNode_ptr _route_current_wp_node;
     SGPropertyNode_ptr _routeDistanceNm;
     SGPropertyNode_ptr _routeETE;
-    
-    SGPropertyNode_ptr _fromFlagNode;
-    
+  SGPropertyNode_ptr _routeEditedSignal;
+  SGPropertyNode_ptr _routeFinishedSignal;
+  SGPropertyNode_ptr _desiredCourseNode;
+  
     double _selectedCourse;
+    double _desiredCourse;
     
-    bool _last_valid;
+    bool _dataValid;
     SGGeod _last_pos;
+    bool _lastPosValid;
     double _last_speed_kts;
     double _last_true_track;
     double _last_vertical_speed;
+    double _lastEWVelocity;
+    double _lastNSVelocity;
     
     std::string _mode;
     GPSListener* _listener;
@@ -372,6 +409,16 @@ private:
     double _turnRadius; // radius of turn in nm
     SGGeod _turnPt;
     SGGeod _turnCentre;
+  
+  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;
+  
+  std::vector<SGPropertyNode_ptr> _tiedNodes;
 };