]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/gps.hxx
Merge branch 'maint2' into next
[flightgear.git] / src / Instrumentation / gps.hxx
1 // gps.hxx - distance-measuring equipment.
2 // Written by David Megginson, started 2003.
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6
7 #ifndef __INSTRUMENTS_GPS_HXX
8 #define __INSTRUMENTS_GPS_HXX 1
9
10 #include <simgear/props/props.hxx>
11 #include <simgear/structure/subsystem_mgr.hxx>
12 #include <simgear/math/SGMath.hxx>
13
14 // forward decls
15 class SGRoute;
16
17 class SGGeodProperty
18 {
19 public:
20     SGGeodProperty()
21     {
22     }
23         
24     void init(SGPropertyNode* base, const char* lonStr, const char* latStr, const char* altStr = NULL);    
25     void init(const char* lonStr, const char* latStr, const char* altStr = NULL);    
26     void clear();    
27     void operator=(const SGGeod& geod);    
28     SGGeod get() const;
29 private:
30     SGPropertyNode_ptr _lon, _lat, _alt;
31 };
32
33 /**
34  * Model a GPS radio.
35  *
36  * Input properties:
37  *
38  * /position/longitude-deg
39  * /position/latitude-deg
40  * /position/altitude-ft
41  * /environment/magnetic-variation-deg
42  * /systems/electrical/outputs/gps
43  * /instrumentation/gps/serviceable
44  * 
45  * /instrumentation/gps/wp-longitude-deg
46  * /instrumentation/gps/wp-latitude-deg
47  * /instrumentation/gps/wp-altitude-ft
48  * /instrumentation/gps/wp-ID
49  * /instrumentation/gps/wp-name
50  * /instrumentation/gps/desired-course-deg
51  * /instrumentation/gps/get-nearest-airport
52  * /instrumentation/gps/waypoint-type
53  * /instrumentation/gps/tracking-bug
54  *
55  * Output properties:
56  *
57  * /instrumentation/gps/indicated-longitude-deg
58  * /instrumentation/gps/indicated-latitude-deg
59  * /instrumentation/gps/indicated-altitude-ft
60  * /instrumentation/gps/indicated-vertical-speed-fpm
61  * /instrumentation/gps/indicated-track-true-deg
62  * /instrumentation/gps/indicated-track-magnetic-deg
63  * /instrumentation/gps/indicated-ground-speed-kt
64  *
65  * /instrumentation/gps/wp-distance-nm
66  * /instrumentation/gps/wp-bearing-deg
67  * /instrumentation/gps/wp-bearing-mag-deg
68  * /instrumentation/gps/TTW
69  * /instrumentation/gps/course-deviation-deg
70  * /instrumentation/gps/course-error-nm
71  * /instrumentation/gps/to-flag
72  * /instrumentation/gps/odometer
73  * /instrumentation/gps/trip-odometer
74  * /instrumentation/gps/true-bug-error-deg
75  * /instrumentation/gps/magnetic-bug-error-deg
76  * /instrumentation/gps/true-bearing-error-deg
77  * /instrumentation/gps/magnetic-bearing-error-deg
78  */
79 class GPS : public SGSubsystem
80 {
81
82 public:
83
84     GPS (SGPropertyNode *node);
85     GPS ();
86     virtual ~GPS ();
87
88     virtual void init ();
89     virtual void update (double delta_time_sec);
90
91 private:
92     typedef struct {
93         double dt;
94         SGGeod pos;
95         SGGeod wp0_pos;
96         SGGeod wp1_pos;
97         bool waypoint_changed;
98         double speed_kt;
99         double track1_deg;
100         double track2_deg;
101         double magvar_deg;
102         double wp0_distance;
103         double wp0_course_deg;
104         double wp0_bearing_deg;
105         double wp1_distance;
106         double wp1_course_deg;
107         double wp1_bearing_deg;
108     } UpdateContext;
109     
110     void search (double frequency, const SGGeod& pos);
111
112     /**
113      * reset all output properties to default / non-service values
114      */
115     void clearOutput();
116
117     void updateWithValid(UpdateContext& ctx);
118     
119     void updateNearestAirport(UpdateContext& ctx);
120     void updateWaypoint0(UpdateContext& ctx);
121     void updateWaypoint1(UpdateContext& ctx);
122
123     void updateLegCourse(UpdateContext& ctx);
124     void updateWaypoint0Course(UpdateContext& ctx);
125     void updateWaypoint1Course(UpdateContext& ctx);
126
127     void waypointChanged(UpdateContext& ctx);
128     void updateTTWNode(UpdateContext& ctx, double distance_m, SGPropertyNode_ptr node);
129     void updateTrackingBug(UpdateContext& ctx);
130     
131     SGPropertyNode_ptr _magvar_node;
132     SGPropertyNode_ptr _serviceable_node;
133     SGPropertyNode_ptr _electrical_node;
134     SGPropertyNode_ptr _wp0_ID_node;
135     SGPropertyNode_ptr _wp0_name_node;
136     SGPropertyNode_ptr _wp0_course_node;
137     SGPropertyNode_ptr _get_nearest_airport_node;
138     SGPropertyNode_ptr _wp1_ID_node;
139     SGPropertyNode_ptr _wp1_name_node;
140     SGPropertyNode_ptr _wp1_course_node;
141     SGPropertyNode_ptr _tracking_bug_node;
142
143     SGPropertyNode_ptr _raim_node;
144     SGPropertyNode_ptr _indicated_vertical_speed_node;
145     SGPropertyNode_ptr _true_track_node;
146     SGPropertyNode_ptr _magnetic_track_node;
147     SGPropertyNode_ptr _speed_node;
148     SGPropertyNode_ptr _wp0_distance_node;
149     SGPropertyNode_ptr _wp0_ttw_node;
150     SGPropertyNode_ptr _wp0_bearing_node;
151     SGPropertyNode_ptr _wp0_mag_bearing_node;
152     SGPropertyNode_ptr _wp0_course_deviation_node;
153     SGPropertyNode_ptr _wp0_course_error_nm_node;
154     SGPropertyNode_ptr _wp0_to_flag_node;
155     SGPropertyNode_ptr _wp1_distance_node;
156     SGPropertyNode_ptr _wp1_ttw_node;
157     SGPropertyNode_ptr _wp1_bearing_node;
158     SGPropertyNode_ptr _wp1_mag_bearing_node;
159     SGPropertyNode_ptr _wp1_course_deviation_node;
160     SGPropertyNode_ptr _wp1_course_error_nm_node;
161     SGPropertyNode_ptr _wp1_to_flag_node;
162     SGPropertyNode_ptr _odometer_node;
163     SGPropertyNode_ptr _trip_odometer_node;
164     SGPropertyNode_ptr _true_bug_error_node;
165     SGPropertyNode_ptr _magnetic_bug_error_node;
166     SGPropertyNode_ptr _true_wp0_bearing_error_node;
167     SGPropertyNode_ptr _magnetic_wp0_bearing_error_node;
168     SGPropertyNode_ptr _true_wp1_bearing_error_node;
169     SGPropertyNode_ptr _magnetic_wp1_bearing_error_node;
170     SGPropertyNode_ptr _leg_distance_node;
171     SGPropertyNode_ptr _leg_course_node;
172     SGPropertyNode_ptr _leg_magnetic_course_node;
173     SGPropertyNode_ptr _alt_dist_ratio_node;
174     SGPropertyNode_ptr _leg_course_deviation_node;
175     SGPropertyNode_ptr _leg_course_error_nm_node;
176     SGPropertyNode_ptr _leg_to_flag_node;
177     SGPropertyNode_ptr _alt_deviation_node;
178
179     bool _last_valid;
180     SGGeod _last_pos;
181     double _last_speed_kts;
182
183     std::string _last_wp0_ID;
184     std::string _last_wp1_ID;
185
186     double _alt_dist_ratio;
187     double _distance_m;
188     double _course_deg;
189
190     double _bias_length;
191     double _bias_angle;
192     double _azimuth_error;
193     double _range_error;
194     double _elapsed_time;
195
196     std::string _name;
197     int _num;
198
199     SGGeodProperty _position;
200     SGGeodProperty _wp0_position;
201     SGGeodProperty _wp1_position;
202     SGGeodProperty _indicated_pos;
203 };
204
205
206 #endif // __INSTRUMENTS_GPS_HXX