]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/navradio.hxx
Merge branch 'jmt/navradio' into next
[flightgear.git] / src / Instrumentation / navradio.hxx
1 // navradio.hxx -- class to manage a nav radio instance
2 //
3 // Written by Curtis Olson, started April 2000.
4 //
5 // Copyright (C) 2000 - 2002  Curtis L. Olson - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifndef _FG_NAVRADIO_HXX
25 #define _FG_NAVRADIO_HXX
26
27
28 #include <Main/fg_props.hxx>
29 #include "Sound/morse.hxx"
30
31 #include <simgear/compiler.h>
32 #include <simgear/structure/subsystem_mgr.hxx>
33 #include <simgear/timing/timestamp.hxx>
34
35 // forward decls
36 class SGInterpTable;
37
38 class FGNavRecord;
39 typedef SGSharedPtr<FGNavRecord> FGNavRecordPtr;
40
41 class FGNavRadio : public SGSubsystem
42 {
43     FGMorse morse;
44
45     SGInterpTable *term_tbl;
46     SGInterpTable *low_tbl;
47     SGInterpTable *high_tbl;
48
49     SGPropertyNode_ptr lon_node;
50     SGPropertyNode_ptr lat_node;
51     SGPropertyNode_ptr alt_node;
52     SGPropertyNode_ptr bus_power_node;
53
54     // property inputs
55     SGPropertyNode_ptr is_valid_node;   // is station data valid (may be way out
56                                         // of range.)
57     SGPropertyNode_ptr power_btn_node;
58     SGPropertyNode_ptr freq_node;       // primary freq
59     SGPropertyNode_ptr alt_freq_node;   // standby freq
60     SGPropertyNode_ptr sel_radial_node; // selected radial
61     SGPropertyNode_ptr vol_btn_node;
62     SGPropertyNode_ptr ident_btn_node;
63     SGPropertyNode_ptr audio_btn_node;
64     SGPropertyNode_ptr backcourse_node;
65     SGPropertyNode_ptr nav_serviceable_node;
66     SGPropertyNode_ptr cdi_serviceable_node;
67     SGPropertyNode_ptr gs_serviceable_node;
68     SGPropertyNode_ptr tofrom_serviceable_node;
69     SGPropertyNode_ptr dme_serviceable_node;
70     
71     // property outputs
72     SGPropertyNode_ptr fmt_freq_node;     // formated frequency
73     SGPropertyNode_ptr fmt_alt_freq_node; // formated alternate frequency
74     SGPropertyNode_ptr heading_node;      // true heading to nav station
75     SGPropertyNode_ptr radial_node;       // current radial we are on (taking
76                                        // into consideration the vor station
77                                        // alignment which likely doesn't
78                                        // match the magnetic alignment
79                                        // exactly.)
80     SGPropertyNode_ptr recip_radial_node; // radial_node(val) + 180 (for
81                                        // convenience)
82     SGPropertyNode_ptr target_radial_true_node;
83                                        // true heading of selected radial
84     SGPropertyNode_ptr target_auto_hdg_node;
85                                        // suggested autopilot heading
86                                        // to intercept selected radial
87     SGPropertyNode_ptr time_to_intercept; // estimated time to intecept selected
88                                        // radial at current speed and heading
89     SGPropertyNode_ptr to_flag_node;
90     SGPropertyNode_ptr from_flag_node;
91     SGPropertyNode_ptr inrange_node;
92     SGPropertyNode_ptr signal_quality_norm_node;
93     SGPropertyNode_ptr cdi_deflection_node;
94     SGPropertyNode_ptr cdi_deflection_norm_node;
95     SGPropertyNode_ptr cdi_xtrack_error_node;
96     SGPropertyNode_ptr cdi_xtrack_hdg_err_node;
97     SGPropertyNode_ptr has_gs_node;
98     SGPropertyNode_ptr loc_node;
99     SGPropertyNode_ptr loc_dist_node;
100     SGPropertyNode_ptr gs_deflection_node;
101     SGPropertyNode_ptr gs_deflection_deg_node;
102     SGPropertyNode_ptr gs_deflection_norm_node;
103     SGPropertyNode_ptr gs_rate_of_climb_node;
104     SGPropertyNode_ptr gs_dist_node;
105     SGPropertyNode_ptr gs_inrange_node;
106     SGPropertyNode_ptr nav_id_node;
107     SGPropertyNode_ptr id_c1_node;
108     SGPropertyNode_ptr id_c2_node;
109     SGPropertyNode_ptr id_c3_node;
110     SGPropertyNode_ptr id_c4_node;
111
112     // gps slaving support
113     SGPropertyNode_ptr nav_slaved_to_gps_node;
114     SGPropertyNode_ptr gps_cdi_deflection_node;
115     SGPropertyNode_ptr gps_to_flag_node;
116     SGPropertyNode_ptr gps_from_flag_node;
117     SGPropertyNode_ptr gps_has_gs_node;
118
119     // internal (private) values
120
121     int play_count;
122     time_t last_time;
123     FGNavRecordPtr _navaid;
124     FGNavRecordPtr _gs;
125     
126     string nav_fx_name;
127     string dme_fx_name;
128
129     double target_radial;
130     SGTimeStamp prev_time;
131     SGTimeStamp curr_time;
132     double effective_range;
133     double target_gs;
134     double twist;
135     double horiz_vel;
136     double last_x;
137     double last_loc_dist;
138     double last_xtrack_error;
139     double _localizerWidth; // cached localizer width in degrees
140     
141     string _name;
142     int _num;
143
144     // internal periodic station search timer
145     double _time_before_search_sec;
146
147     SGVec3d _gsCart, _gsAxis, _gsVertical;
148
149     FGNavRecordPtr _dme;
150     bool _dmeInRange;
151     
152     // CDI properties
153     bool _toFlag, _fromFlag;
154     double _cdiDeflection;
155     double _cdiCrossTrackErrorM;
156     double _gsNeedleDeflection;
157     double _gsNeedleDeflectionNorm;
158     
159     bool updateWithPower(double aDt);
160
161     // model standard VOR/DME/TACAN service volumes as per AIM 1-1-8
162     double adjustNavRange( double stationElev, double aircraftElev,
163                            double nominalRange );
164
165     // model standard ILS service volumes as per AIM 1-1-9
166     double adjustILSRange( double stationElev, double aircraftElev,
167                            double offsetDegrees, double distance );
168
169     void updateAudio();
170     void audioNavidChanged();
171
172     void updateReceiver(double dt);
173     void updateDME(const SGVec3d& aircraft);
174     void updateGlideSlope(double dt, const SGVec3d& aircraft, double signal_quality_norm);
175     void updateGPSSlaved();
176     void updateCDI(double dt);
177     
178     void clearOutputs();
179
180     /**
181      * Compute the localizer width in degrees - see implementation for 
182      * more information on the relevant standards and formulae.
183      */
184     double localizerWidth(FGNavRecord* aLOC);
185     FGNavRecord* findPrimaryNavaid(const SGGeod& aPos, double aFreqMHz);
186 public:
187
188     FGNavRadio(SGPropertyNode *node);
189     ~FGNavRadio();
190
191     void init ();
192     void bind ();
193     void unbind ();
194     void update (double dt);
195
196     // Update nav/adf radios based on current postition
197     void search ();
198 };
199
200
201 #endif // _FG_NAVRADIO_HXX