1 // gps.hxx - distance-measuring equipment.
2 // Written by David Megginson, started 2003.
4 // This file is in the Public Domain and comes with no warranty.
7 #ifndef __INSTRUMENTS_GPS_HXX
8 #define __INSTRUMENTS_GPS_HXX 1
10 #include <simgear/props/props.hxx>
11 #include <simgear/structure/subsystem_mgr.hxx>
12 #include <simgear/math/SGMath.hxx>
14 #include "Navaids/positioned.hxx"
29 void init(SGPropertyNode* base, const char* lonStr, const char* latStr, const char* altStr = NULL);
30 void init(const char* lonStr, const char* latStr, const char* altStr = NULL);
32 void operator=(const SGGeod& geod);
35 SGPropertyNode_ptr _lon, _lat, _alt;
43 * /position/longitude-deg
44 * /position/latitude-deg
45 * /position/altitude-ft
46 * /environment/magnetic-variation-deg
47 * /systems/electrical/outputs/gps
48 * /instrumentation/gps/serviceable
53 * /instrumentation/gps/indicated-longitude-deg
54 * /instrumentation/gps/indicated-latitude-deg
55 * /instrumentation/gps/indicated-altitude-ft
56 * /instrumentation/gps/indicated-vertical-speed-fpm
57 * /instrumentation/gps/indicated-track-true-deg
58 * /instrumentation/gps/indicated-track-magnetic-deg
59 * /instrumentation/gps/indicated-ground-speed-kt
61 * /instrumentation/gps/wp-distance-nm
62 * /instrumentation/gps/wp-bearing-deg
63 * /instrumentation/gps/wp-bearing-mag-deg
64 * /instrumentation/gps/TTW
65 * /instrumentation/gps/course-deviation-deg
66 * /instrumentation/gps/course-error-nm
67 * /instrumentation/gps/to-flag
68 * /instrumentation/gps/odometer
69 * /instrumentation/gps/trip-odometer
70 * /instrumentation/gps/true-bug-error-deg
71 * /instrumentation/gps/magnetic-bug-error-deg
74 class GPS : public SGSubsystem
79 GPS (SGPropertyNode *node);
84 virtual void update (double delta_time_sec);
87 friend class GPSListener;
88 friend class SearchFilter;
91 * Configuration manager, track data relating to aircraft installation
98 void init(SGPropertyNode*);
100 bool turnAnticipationEnabled() const
101 { return _enableTurnAnticipation; }
104 * Desired turn rate in degrees/second. From this we derive the turn
105 * radius and hence how early we need to anticipate it.
107 double turnRateDegSec() const
108 { return _turnRate; }
111 * Distance at which we arm overflight sequencing. Once inside this
112 * distance, a change of the wp1 'TO' flag to false will be considered
113 * overlight of the wp.
115 double overflightArmDistanceNm() const
116 { return _overflightArmDistance; }
119 * Time before the next WP to activate an external annunciator
121 double waypointAlertTime() const
122 { return _waypointAlertTime; }
124 bool tuneNavRadioToRefVor() const
125 { return _tuneRadio1ToRefVor; }
127 bool requireHardSurface() const
128 { return _requireHardSurface; }
130 double minRunwayLengthFt() const
131 { return _minRunwayLengthFt; }
133 double getExternalCourse() const;
135 void setExternalCourse(double aCourseDeg);
137 bool cdiDeflectionIsAngular() const
138 { return (_cdiMaxDeflectionNm <= 0.0); }
140 double cdiDeflectionLinearPeg() const
142 assert(_cdiMaxDeflectionNm > 0.0);
143 return _cdiMaxDeflectionNm;
146 bool driveAutopilot() const
147 { return _driveAutopilot; }
149 bool _enableTurnAnticipation;
151 // desired turn rate in degrees per second
154 // distance from waypoint to arm overflight sequencing (in nm)
155 double _overflightArmDistance;
157 // time before reaching a waypoint to trigger annunicator light/sound
159 double _waypointAlertTime;
161 // should GPS automatically tune NAV1 to the reference VOR?
162 bool _tuneRadio1ToRefVor;
164 // minimum runway length to require when filtering
165 double _minRunwayLengthFt;
167 // should we require a hard-surfaced runway when filtering?
168 bool _requireHardSurface;
170 // helpers to tie course-source property
171 const char* getCourseSource() const;
172 void setCourseSource(const char* aPropPath);
174 // property to retrieve the external course from
175 SGPropertyNode_ptr _extCourseSource;
177 double _cdiMaxDeflectionNm;
179 bool _driveAutopilot;
182 class SearchFilter : public FGPositioned::Filter
185 virtual bool pass(FGPositioned* aPos) const;
187 virtual FGPositioned::Type minType() const;
188 virtual FGPositioned::Type maxType() const;
192 * reset all output properties to default / non-service values
196 void updateBasicData(double dt);
197 void updateWaypoints();
199 void updateTrackingBug();
200 void updateReferenceNavaid(double dt);
201 void referenceNavaidSet(const std::string& aNavaid);
202 void tuneNavRadios();
203 void updateRouteData();
204 void driveAutopilot();
206 void routeActivated();
207 void routeManagerSequenced();
209 void routeFinished();
212 void updateOverflight();
216 double computeTurnProgress(double aBearing) const;
217 void computeTurnData();
218 void updateTurnData();
219 double computeTurnRadiusNm(double aGroundSpeedKts) const;
222 * Update one-shot things when WP1 / leg data change
226 // scratch maintenence utilities
227 void setScratchFromPositioned(FGPositioned* aPos, int aIndex);
228 void setScratchFromCachedSearchResult();
229 void setScratchFromRouteWaypoint(int aIndex);
232 * Add airport-specific information to a scratch result
234 void addAirportToScratch(FGAirport* aAirport);
239 * Predicate, determine if the lon/lat position in the scratch is
242 bool isScratchPositionValid() const;
244 FGPositioned::Filter* createFilter(FGPositioned::Type aTy);
247 * Search kernel - called each time we step through a result
249 void performSearch();
252 void selectLegMode();
253 void selectOBSMode();
255 void loadRouteWaypoint();
259 void previousResult();
260 void defineWaypoint();
261 void insertWaypointAtIndex(int aIndex);
262 void removeWaypointAtIndex(int aIndex);
264 // tied-property getter/setters
265 void setCommand(const char* aCmd);
266 const char* getCommand() const { return ""; }
268 const char* getMode() const { return _mode.c_str(); }
270 bool getScratchValid() const { return _scratchValid; }
271 double getScratchDistance() const;
272 double getScratchMagBearing() const;
273 double getScratchTrueBearing() const;
274 bool getScratchHasNext() const { return _searchHasNext; }
276 double getSelectedCourse() const { return _selectedCourse; }
277 double getCDIDeflection() const;
279 double getLegDistance() const;
280 double getLegCourse() const;
281 double getLegMagCourse() const;
282 double getAltDistanceRatio() const;
284 double getTrueTrack() const { return _last_true_track; }
285 double getMagTrack() const;
286 double getGroundspeedKts() const { return _last_speed_kts; }
287 double getVerticalSpeed() const { return _last_vertical_speed; }
289 //bool getLegMode() const { return _mode == "leg"; }
290 //bool getObsMode() const { return _mode == "obs"; }
292 const char* getWP0Ident() const;
293 const char* getWP0Name() const;
295 const char* getWP1Ident() const;
296 const char* getWP1Name() const;
298 double getWP1Distance() const;
299 double getWP1TTW() const;
300 const char* getWP1TTWString() const;
301 double getWP1Bearing() const;
302 double getWP1MagBearing() const;
303 double getWP1CourseDeviation() const;
304 double getWP1CourseErrorNm() const;
305 bool getWP1ToFlag() const;
306 bool getWP1FromFlag() const;
308 // true-bearing-error and mag-bearing-error
313 SGPropertyNode_ptr _magvar_node;
314 SGPropertyNode_ptr _serviceable_node;
315 SGPropertyNode_ptr _electrical_node;
316 SGPropertyNode_ptr _tracking_bug_node;
317 SGPropertyNode_ptr _raim_node;
319 SGPropertyNode_ptr _odometer_node;
320 SGPropertyNode_ptr _trip_odometer_node;
321 SGPropertyNode_ptr _true_bug_error_node;
322 SGPropertyNode_ptr _magnetic_bug_error_node;
324 SGPropertyNode_ptr _ref_navaid_id_node;
325 SGPropertyNode_ptr _ref_navaid_bearing_node;
326 SGPropertyNode_ptr _ref_navaid_distance_node;
327 SGPropertyNode_ptr _ref_navaid_mag_bearing_node;
328 SGPropertyNode_ptr _ref_navaid_frequency_node;
329 SGPropertyNode_ptr _ref_navaid_name_node;
331 SGPropertyNode_ptr _route_active_node;
332 SGPropertyNode_ptr _route_current_wp_node;
333 SGPropertyNode_ptr _routeDistanceNm;
334 SGPropertyNode_ptr _routeETE;
335 SGPropertyNode_ptr _routeEditedSignal;
336 SGPropertyNode_ptr _routeFinishedSignal;
338 double _selectedCourse;
343 double _last_speed_kts;
344 double _last_true_track;
345 double _last_vertical_speed;
348 GPSListener* _listener;
350 FGRouteMgr* _routeMgr;
352 bool _ref_navaid_set;
353 double _ref_navaid_elapsed;
354 FGPositionedRef _ref_navaid;
359 SGGeodProperty _position;
360 SGGeod _wp0_position;
361 SGGeod _wp1_position;
362 SGGeod _indicated_pos;
363 std::string _wp0Ident, _wp0Name, _wp1Ident, _wp1Name;
364 double _wp1DistanceM, _wp1TrueBearing;
368 SGPropertyNode_ptr _scratchNode;
372 int _searchResultIndex;
373 std::string _searchQuery;
374 FGPositioned::Type _searchType;
376 bool _searchOrderByRange;
377 bool _searchResultsCached;
378 FGPositioned::List _searchResults;
379 bool _searchIsRoute; ///< set if 'search' is actually the current route
380 bool _searchHasNext; ///< is there a result after this one?
381 bool _searchNames; ///< set if we're searching names instead of idents
384 bool _computeTurnData; ///< do we need to update the turn data?
385 bool _anticipateTurn; ///< are we anticipating the next turn or not?
386 bool _inTurn; // is a turn in progress?
387 bool _turnSequenced; // have we sequenced the new leg?
388 double _turnAngle; // angle to turn through, in degrees
389 double _turnStartBearing; // bearing of inbound leg
390 double _turnRadius; // radius of turn in nm
394 SGPropertyNode_ptr _realismSimpleGps; ///< should the GPS be simple or realistic?
396 // autopilot drive properties
397 SGPropertyNode_ptr _apTrueHeading;
398 SGPropertyNode_ptr _apTargetAltitudeFt;
399 SGPropertyNode_ptr _apAltitudeLock;
403 #endif // __INSTRUMENTS_GPS_HXX