Debian Codegraph @

test_suite/unit_tests/Instrumentation/test_navRadio.cxx

raw symbols SCIP
1 #include "test_navRadio.hxx"
2
3 #include <algorithm>
4 #include <memory>
5 #include <cmath>
6 #include <cstring>
7
8 #include "test_suite/FGTestApi/testGlobals.hxx"
9 #include "test_suite/FGTestApi/NavDataCache.hxx"
10
11 #include <Main/fg_props.hxx>
12 #include <Navaids/NavDataCache.hxx>
13 #include <Navaids/navrecord.hxx>
14 #include <Navaids/navlist.hxx>
15
16 #include <Instrumentation/navradio.hxx>
17
18 // Set up function for each test.
19 void NavRadioTests::setUp()
20 {
21 FGTestApi::setUp::initTestGlobals("navradio");
22 FGTestApi::setUp::initNavDataCache();
23 }
24
25
26 // Clean up after each test.
27 void NavRadioTests::tearDown()
28 {
29 FGTestApi::tearDown::shutdownTestGlobals();
30 }
31
32 void NavRadioTests::setPositionAndStabilise(FGNavRadio* r, const SGGeod& g)
33 {
34 FGTestApi::setPosition(g);
35 for (int i=0; i<60; ++i) {
36 r->update(0.1);
37 }
38 }
39
40 std::string NavRadioTests::formatFrequency(double f)
41 {
42 char buf[16];
43 ::snprintf(buf, 16, "%3.2f", f);
44 return buf;
45 }
46
47 void NavRadioTests::testBasic()
48 {
49 SGPropertyNode_ptr configNode(new SGPropertyNode);
50 configNode->setStringValue("name", "navtest");
51 configNode->setIntValue("number", 2);
52 std::unique_ptr<FGNavRadio> r(new FGNavRadio(configNode));
53
54 r->bind();
55 r->init();
56
57 SGPropertyNode_ptr node = globals->get_props()->getNode("instrumentation/navtest[2]");
58 node->setBoolValue("serviceable", true);
59 // needed for the radio to power up
60 globals->get_props()->setDoubleValue("systems/electrical/outputs/nav", 6.0);
61 node->setDoubleValue("frequencies/selected-mhz", 113.8);
62
63 SGGeod pos = SGGeod::fromDegFt(-3.352780, 55.499199, 20000);
64 setPositionAndStabilise(r.get(), pos);
65
66 CPPUNIT_ASSERT_EQUAL(true, node->getBoolValue("operable"));
67 CPPUNIT_ASSERT(node->getStringValue("nav-id") == "TLA");
68 CPPUNIT_ASSERT_EQUAL(true, node->getBoolValue("in-range"));
69 }
70
71 static const struct {
72 int nvType;
73 double nvLat, nvLon, nvAlt, nvFreq, nvRnge, nvTwst;
74 const std::string nvIden;
75 double onRose, atDstNM, atAltFt, atHdg, rSele;
76 bool vOpnl, vToFlag;
77 double vSigNorm, vSigTolr, vHdgDefl, vDeflTolr, vHdgNorm, vDefnTolr, xtkTolr;
78 const std::string tDesc;
79 } CDITestRoll[] = {
80 //
81 // Test Items: Add test cases here:
82 // nv<= fields are copied direct from nav dat => <= Rx pos wrt navaid, Radial =><= v- Values expected / tested => <= Line / Desc for Mesg =>
83 //Type Lat Lon Alt Freq Rnge Twist Iden] onRose atNm atAlt atHdg rSele Op To sigN - Tolr Defl - Tolr DNrm -Tolr xtkTolr
84 //
85 { 3, 53.3, -2.26, 282, 113.55, 130, -5.0, "MCT", 25, 10.0, 4000, 200, 25, 1, 0, 1.0, 0.01, 0.0, 9.01, 0.0, 0.01, 50.0, "1: MCT EGCC On Radial" },
86 { 3, 53.3, -2.26, 282, 113.55, 130, -5.0, "MCT", 25, 10.0, 4000, 200, 25, 1, 0, 1.0, 0.01, 0.0, 9.01, 0.0, 0.01, 50.0, "2: MCT EGCC On Again " },
87 { 3, 53.3, -2.26, 282, 113.55, 130, -5.0, "MCT", 20, 20.0, 12000, 20, 25, 1, 0, 1.0, 0.01, 5.0, 0.1, 0.5, 0.01, 50.0, "3: MCT 5deg Off radial" },
88 { 3, 53.3, -2.26, 282, 113.55, 130, -5.0, "MCT", 33, 30.0, 16000, 100, 25, 1, 0, 1.0, 0.01, -8.0, 0.1, -0.8, 0.01, 50.0, "4: MCT 8deg Off radial" },
89 { 3, 53.3, -2.26, 282, 113.55, 130, -5.0, "MCT", 38, 40.0, 16000, 280, 25, 1, 0, 1.0, 0.01, -10.0, 0.1, -1.0, 0.01, 50.0, "5: MCT >10 Off radial" },
90 { 3, -31.9, 115.95, 87, 113.70, 130, -2.0, "PH", 222, 20.0, 12000, 220, 42, 1, 1, 1.0, 0.01, 0.0, 0.01, 0.0, 0.01, 50.0, "6: PH Perth W.Aus On Radial"},
91 { 3, -31.9, 115.95, 87, 113.70, 130, -2.0, "PH", 225, 20.0, 18000, 220, 42, 1, 1, 1.0, 0.01, 3.0, 0.01, 0.3, 0.01, 50.0, "7: PH +3deg Off radial" }
92 };
93
94 void NavRadioTests::callNavRadioCDI() {
95 //
96 //2021Ja15 set flag for newnavradio
97 //
98 fgSetBool("/instrumentation/use-new-navradio", true);
99 // setup
100 SGPropertyNode_ptr configNode(new SGPropertyNode);
101 configNode->setStringValue("name", "navtest");
102 configNode->setIntValue("number", 2);
103 std::unique_ptr<FGNavRadio> r(new FGNavRadio(configNode));
104 r->bind();
105 r->init();
106 SGPropertyNode_ptr node = globals->get_props()->getNode("instrumentation/navtest[2]");
107 node->setBoolValue("serviceable", true);
108 // needed for the radio to power up
109 globals->get_props()->setDoubleValue("systems/electrical/outputs/nav", 6.0);
110 //
111 int tale = sizeof(CDITestRoll) / sizeof(CDITestRoll[0]);
112 for (int i = 0; (i < tale); i++) {
113 // prep error message
114 const std::string itemDesc = " navradioCDI Item " + CDITestRoll[i].tDesc + " @ ";
115 // Txmitting navaid
116 node->setDoubleValue("frequencies/selected-mhz", CDITestRoll[i].nvFreq);
117 node->setDoubleValue("radials/selected-deg", CDITestRoll[i].rSele);
118 // tbd Filter on type as defined in nav dat
119 //FGPositioned::TypeFilter f{FGPositioned::VOR};
120 FGPositioned::TypeFilter f{{FGPositioned::VOR, FGPositioned::ILS, FGPositioned::LOC}};
121 FGNavRecordRef nav = fgpositioned_cast<FGNavRecord>(FGPositioned::findClosestWithIdent(CDITestRoll[i].nvIden,
122 SGGeod::fromDeg(CDITestRoll[i].nvLon, CDITestRoll[i].nvLat), &f));
123 //
124 // For VOR nav dat field 7: 'Twist' == Easterly rotation of Txmitter's 360 wrt True North c.f for Compass: 'Deviation West Rose is Best'
125 // Rx posn is specified according to navaid's radials as printed on chart: True Bng = ( Radial on Rose + Twist ( Deviation ))
126 // ( ftr: Both MCT -5 and PH -2 Are Negative Twists )
127 SGGeod posWrtRadial = SGGeodesy::direct(nav->geod(), (CDITestRoll[i].onRose + CDITestRoll[i].nvTwst),
128 (CDITestRoll[i].atDstNM * SG_NM_TO_METER));
129 posWrtRadial.setElevationFt(CDITestRoll[i].atAltFt);
130 setPositionAndStabilise(r.get(), posWrtRadial);
131 // heading-deg property below means bearing to txmitter; calc copied from navradio.cxx !!!
132 double bngToNavaid, az2, s;
133 SGGeodesy::inverse(posWrtRadial, (nav->geod()), bngToNavaid, az2, s);
134 // calc XTrack error
135 double xtkE = sin((CDITestRoll[i].rSele - CDITestRoll[i].onRose) * SG_DEGREES_TO_RADIANS) * (CDITestRoll[i].atDstNM * SG_NM_TO_METER);
136 // Verify expected vs Result
137 std::string tMesg = itemDesc + "VOR type";
138 CPPUNIT_ASSERT_MESSAGE(tMesg, nav->type() == FGPositioned::VOR);
139 tMesg = itemDesc + "Operable";
140 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, CDITestRoll[i].vOpnl, node->getBoolValue("operable"));
141 tMesg = itemDesc + "TO Flag";
142 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, CDITestRoll[i].vToFlag, node->getBoolValue("to-flag"));
143 tMesg = itemDesc + "FROM Flag";
144 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, CDITestRoll[i].vToFlag, !node->getBoolValue("from-flag"));
145 //
146 tMesg = itemDesc + "nav-id";
147 CPPUNIT_ASSERT_MESSAGE(tMesg, node->getStringValue("nav-id") == CDITestRoll[i].nvIden);
148 //tbd VOR seems to not set selected-mhz-fmt
149 // Converting nvFreq to string results in trailing zeros
150 tMesg = itemDesc + "selected-mhz-fmt";
151 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, formatFrequency(CDITestRoll[i].nvFreq), node->getStringValue("frequencies/selected-mhz-fmt"));
152 // actual-deg means: bearing seen on intstrument's dial: actual == onRose
153 tMesg = itemDesc + "actual-deg";
154 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, CDITestRoll[i].onRose, node->getDoubleValue("radials/actual-deg"), CDITestRoll[i].vDefnTolr);
155 // heading-deg means true bearing to navaid, not affected by plane's heading
156 tMesg = itemDesc + "heading-deg";
157 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, bngToNavaid, node->getDoubleValue("heading-deg"), 1);
158 //
159 tMesg = itemDesc + "Sig Norm";
160 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, CDITestRoll[i].vSigNorm, node->getDoubleValue("signal-quality-norm"), CDITestRoll[i].vSigTolr);
161 tMesg = itemDesc + "needle defl";
162 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, CDITestRoll[i].vHdgDefl, node->getDoubleValue("heading-needle-deflection"), CDITestRoll[i].vDeflTolr);
163 tMesg = itemDesc + "defl norm";
164 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, CDITestRoll[i].vHdgNorm, node->getDoubleValue("heading-needle-deflection-norm"), CDITestRoll[i].vDefnTolr);
165 tMesg = itemDesc + "xTrack error";
166 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, xtkE, node->getDoubleValue("crosstrack-error-m"), CDITestRoll[i].xtkTolr);
167 }
168 }
169
170 void NavRadioTests::callNewNavRadioCDI()
171 {
172 //
173 //2021Ja15 set flag for newnavradio
174 //
175 fgSetBool("/instrumentation/use-new-navradio", true);
176 // setup
177 SGPropertyNode_ptr configNode(new SGPropertyNode);
178 configNode->setStringValue("name", "navtest");
179 configNode->setIntValue("number", 2);
180 std::unique_ptr<FGNavRadio> r(new FGNavRadio(configNode));
181 r->bind();
182 r->init();
183 SGPropertyNode_ptr node = globals->get_props()->getNode("instrumentation/navtest[2]");
184 node->setBoolValue("serviceable", true);
185 // needed for the radio to power up
186 globals->get_props()->setDoubleValue("systems/electrical/outputs/nav", 6.0);
187 //
188 int tale = sizeof(CDITestRoll) / sizeof(CDITestRoll[0]);
189 for (int i = 0; (i < tale); i++) {
190 // prep error message
191 const std::string itemDesc = " navradioCDI Item " + CDITestRoll[i].tDesc + " @ ";
192 // Txmitting navaid
193 node->setDoubleValue("frequencies/selected-mhz", CDITestRoll[i].nvFreq);
194 node->setDoubleValue("radials/selected-deg", CDITestRoll[i].rSele);
195 // tbd Filter on type as defined in nav dat
196 //FGPositioned::TypeFilter f{FGPositioned::VOR};
197 FGPositioned::TypeFilter f{{FGPositioned::VOR, FGPositioned::ILS, FGPositioned::LOC}};
198 FGNavRecordRef nav = fgpositioned_cast<FGNavRecord>(FGPositioned::findClosestWithIdent(CDITestRoll[i].nvIden,
199 SGGeod::fromDeg(CDITestRoll[i].nvLon, CDITestRoll[i].nvLat), &f));
200 //
201 // For VOR nav dat field 7: 'Twist' == Easterly rotation of Txmitter's 360 wrt True North c.f for Compass: 'Deviation West Rose is Best'
202 // Rx posn is specified according to navaid's radials as printed on chart: True Bng = ( Radial on Rose + Twist ( Deviation ))
203 // ( ftr: Both MCT -5 and PH -2 Are Negative Twists )
204 SGGeod posWrtRadial = SGGeodesy::direct(nav->geod(), (CDITestRoll[i].onRose + CDITestRoll[i].nvTwst),
205 (CDITestRoll[i].atDstNM * SG_NM_TO_METER));
206 posWrtRadial.setElevationFt(CDITestRoll[i].atAltFt);
207 setPositionAndStabilise(r.get(), posWrtRadial);
208 // heading-deg property below means bearing to txmitter; calc copied from navradio.cxx !!!
209 double bngToNavaid, az2, s;
210 SGGeodesy::inverse(posWrtRadial, (nav->geod()), bngToNavaid, az2, s);
211 // calc XTrack error
212 double xtkE = sin((CDITestRoll[i].rSele - CDITestRoll[i].onRose) * SG_DEGREES_TO_RADIANS) * (CDITestRoll[i].atDstNM * SG_NM_TO_METER);
213 // Verify expected vs Result
214 std::string tMesg = itemDesc + "VOR type";
215 CPPUNIT_ASSERT_MESSAGE(tMesg, nav->type() == FGPositioned::VOR);
216 tMesg = itemDesc + "Operable";
217 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, CDITestRoll[i].vOpnl, node->getBoolValue("operable"));
218 tMesg = itemDesc + "TO Flag";
219 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, CDITestRoll[i].vToFlag, node->getBoolValue("to-flag"));
220 tMesg = itemDesc + "FROM Flag";
221 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, CDITestRoll[i].vToFlag, !node->getBoolValue("from-flag"));
222 //
223 tMesg = itemDesc + "nav-id";
224 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, CDITestRoll[i].nvIden, node->getStringValue("nav-id"));
225
226 // Converting nvFreq to string results in trailing zeros
227 tMesg = itemDesc + "selected-mhz-fmt";
228 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, formatFrequency(CDITestRoll[i].nvFreq), node->getStringValue("frequencies/selected-mhz-fmt"));
229
230 // actual-deg means: bearing seen on intstrument's dial: actual == onRose
231 tMesg = itemDesc + "actual-deg";
232 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, CDITestRoll[i].onRose, node->getDoubleValue("radials/actual-deg"), CDITestRoll[i].vDefnTolr);
233 // heading-deg means true bearing to navaid, not affected by plane's heading
234 tMesg = itemDesc + "heading-deg";
235 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, bngToNavaid, node->getDoubleValue("heading-deg"), 1);
236 //
237 tMesg = itemDesc + "Sig Norm";
238 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, CDITestRoll[i].vSigNorm, node->getDoubleValue("signal-quality-norm"), CDITestRoll[i].vSigTolr);
239 tMesg = itemDesc + "needle defl";
240 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, CDITestRoll[i].vHdgDefl, node->getDoubleValue("heading-needle-deflection"), CDITestRoll[i].vDeflTolr);
241 tMesg = itemDesc + "defl norm";
242 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, CDITestRoll[i].vHdgNorm, node->getDoubleValue("heading-needle-deflection-norm"), CDITestRoll[i].vDefnTolr);
243 tMesg = itemDesc + "xTrack error";
244 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, xtkE, node->getDoubleValue("crosstrack-error-m"), CDITestRoll[i].xtkTolr);
245 }
246 }
247
248 static const struct {
249 int nvType;
250 double nvLat, nvLon, nvAlt, nvFreq, nvRnge, nvTwst;
251 const std::string nvIden;
252 double onRose, atDstNM, atAltFt, atHdg, rSele;
253 bool vOpnl, vToFlag;
254 double vSigNorm, vSigTolr, vHdgDefl, vDeflTolr, vHdgNorm, vDefnTolr, xtkTolr;
255 const std::string tDesc;
256
257 } ILSTestRoll[] = {
258 //
259 // Ref pilotscafe.com ILS width: 700ft wide at thrsh. WIthin range, sensed at +-35dg @ 10NM +-10dg @ 18NM
260 //
261 // Test Items: Add test cases here:
262 // nv<= fields are copied direct from nav dat => <= Rx pos wrt navaid, Radial => <= v- Values expected / tested => <= Item - Desc =>
263 //Typ Lat Lon Alt Freq Rnge TruHdng Iden] onRose atNm atAlt atHdg rSele Op To sigN - Tolr Defl - Tolr DNrm -Tolr xtkTol ]
264 //
265 {4, 37.626, -122.394, 8, 109.55, 18, 297.932, "ISFO", 117.932, 2.5, 2500, 27, 297.932, 1, 1, 1.0, 0.01, 0.0, 0.01, 0.0, 0.01, 50.0, "1: ISFO On LOC"}, //
266 {4, 37.626, -122.394, 8, 109.55, 18, 297.932, "ISFO", 116.932, 6.0, 1500, 27, 297.932, 1, 1, 1.0, 0.01, -1.0, 0.10, -0.1, 0.01, 50.0, "2: ISFO -1 Deg"}, //
267 {4, 37.626, -122.394, 8, 109.55, 18, 297.932, "ISFO", 118.932, 6.0, 1500, 27, 297.932, 1, 1, 1.0, 0.01, 1.0, 0.01, -0.1, 0.01, 50.0, "3: ISFO +1 Deg"}, //
268 {4, 37.626, -122.394, 8, 109.55, 18, 297.932, "ISFO", 113.932, 3.0, 600, 27, 297.932, 1, 1, 1.0, 0.01, -3.0, 0.10, -0.1, 0.01, 50.0, "4: ISFO < MinDefl"}, //
269 {4, 37.626, -122.394, 8, 109.55, 18, 297.932, "ISFO", 121.932, 3.0, 600, 27, 297.932, 1, 1, 1.0, 0.01, 3.0, 0.01, -0.1, 0.01, 50.0, "5: ISFO > MzxDefl"}, //
270 {4, 37.626, -122.394, 8, 109.55, 18, 297.932, "ISFO", 297.932, 4.0, 1500, 27, 297.932, 1, 1, 1.0, 0.01, 0.0, 0.01, 0.0, 0.01, 50.0, "6: ISFO BC On LOC"}, //
271 {4, 37.626, -122.394, 8, 109.55, 18, 297.932, "ISFO", 296.932, 4.0, 1500, 27, 297.932, 1, 1, 1.0, 0.01, 1.0, 0.10, -0.1, 0.01, 50.0, "7: ISFO BC -1 Deg"}, //
272 {4, 37.626, -122.394, 8, 109.55, 18, 297.932, "ISFO", 298.932, 4.0, 1500, 27, 297.932, 1, 1, 1.0, 0.01, -1.0, 0.01, -0.1, 0.01, 50.0, "8: ISFO BC +1 Deg"}, //
273 {4, 37.626, -122.394, 8, 109.55, 18, 297.932, "ISFO", 293.932, 4.0, 1500, 27, 297.932, 1, 1, 1.0, 0.01, 3.0, 0.10, -0.1, 0.01, 50.0, "9: ISFO BC > MaxD"}, //
274 {4, 37.626, -122.394, 8, 109.55, 18, 297.932, "ISFO", 301.932, 4.0, 1500, 27, 297.932, 1, 1, 1.0, 0.01, -3.0, 0.01, -0.1, 0.01, 50.0, "10: ISFO BC < MinD"} //
275 };
276
277 void NavRadioTests::callNavRadioILS()
278 {
279 // set flag for newnavradio
280 fgSetBool("/instrumentation/use-new-navradio", false);
281 // setup
282 SGPropertyNode_ptr configNode(new SGPropertyNode);
283 configNode->setStringValue("name", "navtest");
284 configNode->setIntValue("number", 2);
285 std::unique_ptr<FGNavRadio> r(new FGNavRadio(configNode));
286 r->bind();
287 r->init();
288 SGPropertyNode_ptr node = globals->get_props()->getNode("instrumentation/navtest[2]");
289 node->setBoolValue("serviceable", true);
290 // needed for the radio to power up
291 globals->get_props()->setDoubleValue("systems/electrical/outputs/nav", 6.0);
292 //
293 int tale = sizeof(ILSTestRoll) / sizeof(ILSTestRoll[0]);
294 for (int i = 0; (i < tale); i++) {
295 // prep error message
296 const std::string itemDesc = " navRadioILS Item " + ILSTestRoll[i].tDesc + " @ ";
297 // Txmitting navaid
298 node->setDoubleValue("frequencies/selected-mhz", ILSTestRoll[i].nvFreq);
299 node->setDoubleValue("radials/selected-deg", ILSTestRoll[i].rSele);
300 FGPositioned::TypeFilter f{{FGPositioned::VOR, FGPositioned::ILS, FGPositioned::LOC}};
301 FGNavRecordRef nav = fgpositioned_cast<FGNavRecord>(FGPositioned::findClosestWithIdent(ILSTestRoll[i].nvIden,
302 SGGeod::fromDeg(ILSTestRoll[i].nvLon, ILSTestRoll[i].nvLat), &f));
303 SGGeod posWrtRadial = SGGeodesy::direct(nav->geod(), (ILSTestRoll[i].onRose), (ILSTestRoll[i].atDstNM * SG_NM_TO_METER));
304 posWrtRadial.setElevationFt(ILSTestRoll[i].atAltFt);
305 setPositionAndStabilise(r.get(), posWrtRadial);
306 // heading-deg property below means bearing to txmitter; calc copied from navradio.cxx !!!
307 double bngToNavaid, az2, s;
308 SGGeodesy::inverse(posWrtRadial, (nav->geod()), bngToNavaid, az2, s);
309 double xtkE = sin((ILSTestRoll[i].rSele - ILSTestRoll[i].onRose) * SG_DEGREES_TO_RADIANS) * (ILSTestRoll[i].atDstNM * SG_NM_TO_METER);
310 //
311 const double locWidth = nav->localizerWidth();
312 // Expected Defl / Scaling is hokey because ILS width varies ??
313 const double deflectionScale = 20.0 / locWidth; // 20 degrees is full VOR swing (-10 to +10 degrees)
314 double xpecDefl = (ILSTestRoll[i].vHdgDefl * deflectionScale);
315 xpecDefl = (xpecDefl > 10) ? 10 : xpecDefl;
316 xpecDefl = (xpecDefl < -10) ? -10 : xpecDefl;
317 //
318 // Verify expected: Operational and To flags
319 std::string tMesg = itemDesc + "ILS type";
320 CPPUNIT_ASSERT_MESSAGE(tMesg, nav->type() == FGPositioned::ILS);
321 tMesg = itemDesc + "Operable";
322 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, ILSTestRoll[i].vOpnl, node->getBoolValue("operable"));
323 tMesg = itemDesc + "TO Flag";
324 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, ILSTestRoll[i].vToFlag, node->getBoolValue("to-flag"));
325 tMesg = itemDesc + "FROM Flag";
326 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, ILSTestRoll[i].vToFlag, !node->getBoolValue("from-flag"));
327 //
328 tMesg = itemDesc + "heading-deg";
329 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, bngToNavaid, node->getDoubleValue("heading-deg"), 1);
330 tMesg = itemDesc + "nav-id";
331 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, ILSTestRoll[i].nvIden, node->getStringValue("nav-id"));
332 // Converting nvFreq to string results in trailing zeros
333 tMesg = itemDesc + "selected-mhz-fmt";
334 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, formatFrequency(ILSTestRoll[i].nvFreq), node->getStringValue("frequencies/selected-mhz-fmt"));
335
336 // actual-deg means: bearing seen on intstrument's dial: actual == onRose
337 tMesg = itemDesc + "actual-deg";
338 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, ILSTestRoll[i].onRose, node->getDoubleValue("radials/actual-deg"), ILSTestRoll[i].vDefnTolr);
339 tMesg = itemDesc + "Sig Norm";
340 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, ILSTestRoll[i].vSigNorm, node->getDoubleValue("signal-quality-norm"), ILSTestRoll[i].vSigTolr);
341 tMesg = itemDesc + "needle defl";
342 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, xpecDefl, node->getDoubleValue("heading-needle-deflection"), ILSTestRoll[i].vDeflTolr);
343 tMesg = itemDesc + "defl norm";
344 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, (xpecDefl * 0.1), node->getDoubleValue("heading-needle-deflection-norm"), ILSTestRoll[i].vDefnTolr);
345 tMesg = itemDesc + "xTrack error";
346 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, xtkE, node->getDoubleValue("crosstrack-error-m"), ILSTestRoll[i].xtkTolr);
347 }
348 }
349
350 void NavRadioTests::callNewNavRadioILS()
351 {
352 // set flag for newnavradio
353 fgSetBool("/instrumentation/use-new-navradio", true);
354 // setup
355 SGPropertyNode_ptr configNode(new SGPropertyNode);
356 configNode->setStringValue("name", "navtest");
357 configNode->setIntValue("number", 2);
358 std::unique_ptr<FGNavRadio> r(new FGNavRadio(configNode));
359 r->bind();
360 r->init();
361 SGPropertyNode_ptr node = globals->get_props()->getNode("instrumentation/navtest[2]");
362 node->setBoolValue("serviceable", true);
363 // needed for the radio to power up
364 globals->get_props()->setDoubleValue("systems/electrical/outputs/nav", 6.0);
365 //
366 int tale = sizeof(ILSTestRoll) / sizeof(ILSTestRoll[0]);
367 for (int i = 0; (i < tale); i++) {
368 // prep error message
369 const std::string itemDesc = "newNavRadioILS Item " + ILSTestRoll[i].tDesc + " @ ";
370 // Txmitting navaid
371 node->setDoubleValue("frequencies/selected-mhz", ILSTestRoll[i].nvFreq);
372 node->setDoubleValue("radials/selected-deg", ILSTestRoll[i].rSele);
373 FGPositioned::TypeFilter f{{FGPositioned::VOR, FGPositioned::ILS, FGPositioned::LOC}};
374 FGNavRecordRef nav = fgpositioned_cast<FGNavRecord>(FGPositioned::findClosestWithIdent(ILSTestRoll[i].nvIden, \
375 SGGeod::fromDeg( ILSTestRoll[i].nvLon, ILSTestRoll[i].nvLat), &f));
376 SGGeod posWrtRadial = SGGeodesy::direct(nav->geod(), (ILSTestRoll[i].onRose ), (ILSTestRoll[i].atDstNM * SG_NM_TO_METER));
377 posWrtRadial.setElevationFt(ILSTestRoll[i].atAltFt);
378 setPositionAndStabilise(r.get(), posWrtRadial);
379 // heading-deg property below means bearing to txmitter; calc copied from navradio.cxx !!!
380 double bngToNavaid, az2, s;
381 SGGeodesy::inverse(posWrtRadial, (nav->geod()), bngToNavaid, az2, s);
382 double xtkE = sin( (ILSTestRoll[i].rSele - ILSTestRoll[i].onRose) * SG_DEGREES_TO_RADIANS) \
383 * ( ILSTestRoll[i].atDstNM * SG_NM_TO_METER ) ;
384 //
385 const double locWidth = nav->localizerWidth();
386 // Expected Defl / Scaling is hokey because ILS width varies ??
387 const double deflectionScale = 20.0 / locWidth; // 20 degrees is full VOR swing (-10 to +10 degrees)
388 double xpecDefl = (ILSTestRoll[i].vHdgDefl * deflectionScale);
389 xpecDefl = ( xpecDefl > 10 ) ? 10 : xpecDefl;
390 xpecDefl = ( xpecDefl < -10 ) ? -10 : xpecDefl;
391 //
392 // Verify expected: Operational and To flags
393 std::string tMesg = itemDesc + "ILS type";
394 CPPUNIT_ASSERT_MESSAGE(tMesg, nav->type() == FGPositioned::ILS);
395 tMesg = itemDesc + "Operable";
396 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, ILSTestRoll[i].vOpnl, node->getBoolValue("operable"));
397 tMesg = itemDesc + "TO Flag";
398 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, ILSTestRoll[i].vToFlag, node->getBoolValue("to-flag"));
399 tMesg = itemDesc + "FROM Flag";
400 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, ILSTestRoll[i].vToFlag, !node->getBoolValue("from-flag"));
401 //
402 tMesg = itemDesc + "heading-deg";
403 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, bngToNavaid, node->getDoubleValue("heading-deg"), 1);
404 tMesg = itemDesc + "nav-id";
405 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, ILSTestRoll[i].nvIden, node->getStringValue("nav-id"));
406 // Converting nvFreq to string results in trailing zeros
407 tMesg = itemDesc + "selected-mhz-fmt";
408 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, formatFrequency(ILSTestRoll[i].nvFreq), node->getStringValue("frequencies/selected-mhz-fmt"));
409 // actual-deg means: bearing seen on intstrument's dial: actual == onRose
410 tMesg = itemDesc + "actual-deg";
411 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, ILSTestRoll[i].onRose, node->getDoubleValue("radials/actual-deg"), ILSTestRoll[i].vDefnTolr);
412 tMesg = itemDesc + "Sig Norm";
413 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, ILSTestRoll[i].vSigNorm, node->getDoubleValue("signal-quality-norm"), ILSTestRoll[i].vSigTolr);
414 tMesg = itemDesc + "needle defl";
415 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, xpecDefl, node->getDoubleValue("heading-needle-deflection"), ILSTestRoll[i].vDeflTolr);
416 tMesg = itemDesc + "defl norm";
417 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, (xpecDefl * 0.1), node->getDoubleValue("heading-needle-deflection-norm"), ILSTestRoll[i].vDefnTolr);
418 tMesg = itemDesc + "xTrack error";
419 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, xtkE, node->getDoubleValue("crosstrack-error-m"), ILSTestRoll[i].xtkTolr);
420 }
421 }
422
423 static const struct {
424 int nvType;
425 double nvLat, nvLon, nvAlt, nvFreq, nvRnge, nvAzim;
426 const std::string nvIden;
427 double onRose, atDstNM, atAltFt, plusDeg, atHdg, rTruDeg;
428 bool vInRnge, vFalse;
429 double vSigNorm, vSigTolr, vGSDefl, vDeflTolr, vGSDefn, vDefnTolr;
430 const std::string tDesc;
431 } GSTestRoll[] = {
432 //
433 // Test Items: Add test cases here:
434 // nv<= fields are copied direct from nav dat => <= Rx pos wrt navaid, Radial => <= v- Values expected / tested => <= Item - Desc =>
435 //Typ Lat Lon Alt Freq Rnge GSAzim Iden] onRose atNm atAlt or Deg atHdg TruDeg Rng Fls SgN - Tolr GSDefl-Tolr GSDefn-Tolr ]
436 //
437 { 4, 52.563, 13.305, 101, 110.10, 10, 3.000, "ITLW", 117.932, 8.0, 0, 0, 80.828, 260.857, 1, 0, 1.0, 0.01, 0.0, 0.1, 0.0, 0.01, "1: EDDT 26R +0 deg" }, //
438 { 4, 52.563, 13.305, 101, 110.10, 10, 3.000, "ITLW", 117.932, 4.0, 0, 0.50, 80.828, 260.857, 1, 0, 1.0, 0.01, 0.0, 0.1, 0.0, 0.01, "2: EDDT 26R +0.5 d" }, //
439 { 4, 52.563, 13.305, 101, 110.10, 10, 3.000, "ITLW", 117.932, 2.0, 0, -1.00, 80.828, 260.857, 1, 0, 1.0, 0.01, 0.0, 0.1, 0.0, 0.01, "3: EDDT 26R -1 deg" }, //
440 { 4, 52.563, 13.305, 101, 110.10, 10, 3.000, "ITLW", 117.932, 5.0, 0, 3.00, 80.828, 260.857, 1, 1, 1.0, 0.01, 0.0, 0.1, 0.0, 0.01, "4: EDDT 26R +3.0 Fls"}, //
441 { 4, 52.563, 13.305, 101, 110.10, 10, 3.000, "ITLW", 117.932, 3.0, 0, +2.65, 80.828, 260.857, 1, 1, 1.0, 0.01,-1.75, 0.1, -0.5, 0.01, "5: EDDT 26R +3.5 Fls"}, //
442 // { 4, 51.464, -0.439, 50, 109.50, 10, 3.000, "ILL", 89.690, 7.5, 2500, 0, 80.828, 269.690, 1, 0, 1.0, 0.01, 0.0, 0.1, 0.0, 0.01, "6: EGLL 27L 2K5 7M5"}, // Fail: Rx finds IBB
443 // { 4, 51.464, -0.439, 50, 109.50, 10, 3.000, "ILL", 89.690, 9.0, 3000, 0, 80.828, 269.690, 1, 0, 1.0, 0.01, 0.0, 0.1, 0.0, 0.01, "7: EGLL 27L 3K0 9M0"}, //
444 // { 4, 51.464, -0.439, 50, 109.50, 10, 3.000, "ILL", 89.690,17.5, 4000, 0, 80.828, 269.690, 1, 0, 1.0, 0.01, 0.0, 0.1, 0.0, 0.01, "8: EGLL 27L 4K 17M5"}, //
445 // { 4, 51.464, -0.439, 50, 109.50, 10, 3.000, "ILL", 89.690,25.0, 4000, 0, 80.828, 269.690, 1, 0, 1.0, 0.01, 0.0, 0.1, 0.0, 0.01, "9: EGLL 27L 4K 25M0"} //
446 };
447
448 void NavRadioTests::callNavRadioGS() {
449 //set flag for newnavradio
450 fgSetBool("/instrumentation/use-new-navradio", false);
451 // setup
452 SGPropertyNode_ptr configNode(new SGPropertyNode);
453 configNode->setStringValue("name", "navtest");
454 configNode->setIntValue("number", 2);
455 std::unique_ptr<FGNavRadio> r(new FGNavRadio(configNode));
456 r->bind();
457 r->init();
458 SGPropertyNode_ptr node = globals->get_props()->getNode("instrumentation/navtest[2]");
459 node->setBoolValue("serviceable", true);
460 // needed for the radio to power up
461 globals->get_props()->setDoubleValue("systems/electrical/outputs/nav", 6.0);
462 //
463 // GS beam depth +-0.7deg; needle deflection -+3.5; gs-direct: Rxvr elevation from GS Txmitter level
464 //
465 const double halfBeam = 0.700;
466 const double deflFact = 3.500;
467 //
468 int tale = sizeof(GSTestRoll) / sizeof(GSTestRoll[0]);
469 for (int i = 0; (i < tale); i++) {
470 // prep error message
471 const std::string itemDesc = " navRadioGS Item " + GSTestRoll[i].tDesc + " @ ";
472 // Txmitting navaid
473 node->setDoubleValue("frequencies/selected-mhz", GSTestRoll[i].nvFreq);
474 node->setDoubleValue("radials/selected-deg", GSTestRoll[i].rTruDeg);
475 FGPositioned::TypeFilter f{{FGPositioned::VOR, FGPositioned::GS, FGPositioned::LOC}};
476 FGNavRecordRef nav = fgpositioned_cast<FGNavRecord>(FGPositioned::findClosestWithIdent(GSTestRoll[i].nvIden,
477 SGGeod::fromDeg(GSTestRoll[i].nvLon, GSTestRoll[i].nvLat), &f));
478
479 // Check for proper nav type befor doing GS things
480 std::string tMesg = itemDesc + "GS Type ?";
481 CPPUNIT_ASSERT_MESSAGE(tMesg, nav->type() == FGPositioned::GS);
482 /////////////
483 // derive the GS geometry in cartesian vectors, to match what navradio.cxx does
484 SGGeod aboveGS = nav->geod();
485 aboveGS.setElevationM(nav->geod().getElevationM() + 100);
486 SGVec3d gsVerticalAxis = SGVec3d::fromGeod(aboveGS) - nav->cart();
487 // intentionally different approach to what navradio uses
488 gsVerticalAxis *= 0.01; // make it per meter, since we used 100m above
489 // derive the baseline
490 SGQuatd baseLineRot = SGQuatd::fromLonLat(nav->geod()) * SGQuatd::fromHeadAttBankDeg(GSTestRoll[i].atHdg, 0, 0);
491 SGVec3d gsAltAxis = baseLineRot.backTransform(SGVec3d(1.0, 0.0, 0.0));
492 const SGVec3d gsCart = nav->cart();
493 //////////////////
494 // expected deflection is calculated here if atAltFt is non-zero
495 double xpecAzim, xpecDefl, xpecDefn;
496 double bngToNavaid, az2, s;
497 if (GSTestRoll[i].atAltFt == 0) {
498 // Line item atAlt is zero so use degrees off GlideSlope for Rx position
499 double gsAngleRad = (nav->glideSlopeAngleDeg() + GSTestRoll[i].plusDeg) * SG_DEGREES_TO_RADIANS;
500 SGVec3d radioPos = gsCart;
501 radioPos += (gsVerticalAxis * tan(gsAngleRad) * GSTestRoll[i].atDstNM * SG_NM_TO_METER);
502 radioPos += (gsAltAxis * GSTestRoll[i].atDstNM * SG_NM_TO_METER);
503 setPositionAndStabilise(r.get(), SGGeod::fromCart(radioPos));
504 xpecAzim = (GSTestRoll[i].nvAzim + GSTestRoll[i].plusDeg);
505 } else {
506 // Line item atAlt is non zero so use altitude for Rx position
507 SGGeod p = SGGeodesy::direct(nav->geod(), GSTestRoll[i].atAltFt, GSTestRoll[i].atDstNM * SG_NM_TO_METER);
508 p.setElevationFt(GSTestRoll[i].atAltFt);
509 setPositionAndStabilise(r.get(), p);
510 //tbd calc Rx Azim from Tx for altitude case
511 SGGeodesy::inverse(p, nav->geod(), bngToNavaid, az2, s);
512 xpecAzim = SG_RADIANS_TO_DEGREES * (atan((GSTestRoll[i].atAltFt * SG_FEET_TO_METER) / s));
513 }
514 //
515 if (GSTestRoll[i].vFalse) {
516 // rxFlse indicates false signal, use deflections manually entered in Item
517 xpecDefl = GSTestRoll[i].vGSDefl;
518 xpecDefn = GSTestRoll[i].vGSDefn;
519 } else {
520 if (GSTestRoll[i].atAltFt == 0) {
521 // not rxFlse and atAltFt is zero : calculate needle deflections from Rx posn degrees wrt beam
522 xpecDefn = 0 - GSTestRoll[i].plusDeg / halfBeam; // Plane high: needle below
523 } else {
524 // not rxFlse and atAltFt non zero : calculate needle deflections from Rx posn azimuth wrt beam
525 xpecDefn = (GSTestRoll[i].nvAzim - az2) / halfBeam; // Plane high: needle below;
526 }
527 xpecDefn = (xpecDefn > 1) ? 1 : xpecDefn;
528 xpecDefn = (xpecDefn < -1) ? -1 : xpecDefn;
529 xpecDefl = xpecDefn * deflFact;
530 }
531 //
532 // Verify expected:
533 tMesg = itemDesc + "Operable";
534 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, GSTestRoll[i].vInRnge, node->getBoolValue("operable"));
535 tMesg = itemDesc + "nav-id";
536 auto dddbug = node->getStringValue("nav-id");
537 CPPUNIT_ASSERT_MESSAGE(tMesg, node->getStringValue("nav-id") == GSTestRoll[i].nvIden);
538 tMesg = itemDesc + "Sig Norm";
539 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, GSTestRoll[i].vSigNorm, node->getDoubleValue("signal-quality-norm"), GSTestRoll[i].vSigTolr);
540 tMesg = itemDesc + "gs-direct";
541 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, xpecAzim, node->getDoubleValue("gs-direct-deg"), 1);
542 tMesg = itemDesc + "needle defl";
543 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, xpecDefl, node->getDoubleValue("gs-needle-deflection"), GSTestRoll[i].vDeflTolr);
544 tMesg = itemDesc + "defl norm";
545 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, xpecDefn, node->getDoubleValue("gs-needle-deflection-norm"), GSTestRoll[i].vDefnTolr);
546 //
547 }
548 }
549
550 void NavRadioTests::callNewNavRadioGS()
551 {
552 //set flag for newnavradio
553 fgSetBool("/instrumentation/use-new-navradio", true);
554 // setup
555 SGPropertyNode_ptr configNode(new SGPropertyNode);
556 configNode->setStringValue("name", "navtest");
557 configNode->setIntValue("number", 2);
558 std::unique_ptr<FGNavRadio> r(new FGNavRadio(configNode));
559 r->bind();
560 r->init();
561 SGPropertyNode_ptr node = globals->get_props()->getNode("instrumentation/navtest[2]");
562 node->setBoolValue("serviceable", true);
563 // needed for the radio to power up
564 globals->get_props()->setDoubleValue("systems/electrical/outputs/nav", 6.0);
565 //
566 // GS beam depth +-0.7deg; needle deflection -+3.5; gs-direct: Rxvr elevation from GS Txmitter level
567 //
568 const double halfBeam = 0.700;
569 const double deflFact = 3.500;
570 //
571 int tale = sizeof(GSTestRoll) / sizeof(GSTestRoll[0]);
572 for (int i = 0; (i < tale); i++) {
573 // prep error message
574 const std::string itemDesc = "newnavRadioGS Item " + GSTestRoll[i].tDesc + " @ ";
575 // Txmitting navaid
576 node->setDoubleValue("frequencies/selected-mhz", GSTestRoll[i].nvFreq);
577 node->setDoubleValue("radials/selected-deg", GSTestRoll[i].rTruDeg);
578 FGPositioned::TypeFilter f{{FGPositioned::VOR, FGPositioned::GS, FGPositioned::LOC}};
579 FGNavRecordRef nav = fgpositioned_cast<FGNavRecord>(FGPositioned::findClosestWithIdent(GSTestRoll[i].nvIden,
580 SGGeod::fromDeg(GSTestRoll[i].nvLon, GSTestRoll[i].nvLat), &f));
581
582 // Check for proper nav type befor doing GS things
583 std::string tMesg = itemDesc + "GS Type ?";
584 CPPUNIT_ASSERT_MESSAGE(tMesg, nav->type() == FGPositioned::GS);
585 /////////////
586 // derive the GS geometry in cartesian vectors, to match what navradio.cxx does
587 SGGeod aboveGS = nav->geod();
588 aboveGS.setElevationM(nav->geod().getElevationM() + 100);
589 SGVec3d gsVerticalAxis = SGVec3d::fromGeod(aboveGS) - nav->cart();
590 // intentionally different approach to what navradio uses
591 gsVerticalAxis *= 0.01; // make it per meter, since we used 100m above
592 // derive the baseline
593 SGQuatd baseLineRot = SGQuatd::fromLonLat(nav->geod()) * SGQuatd::fromHeadAttBankDeg(GSTestRoll[i].atHdg, 0, 0);
594 SGVec3d gsAltAxis = baseLineRot.backTransform(SGVec3d(1.0, 0.0, 0.0));
595 const SGVec3d gsCart = nav->cart();
596 //////////////////
597 // expected deflection is calculated here if atAltFt is non-zero
598 double xpecAzim, xpecDefl, xpecDefn;
599 double bngToNavaid, az2, s;
600 if (GSTestRoll[i].atAltFt == 0) {
601 // Line item atAlt is zero so use degrees off GlideSlope for Rx position
602 double gsAngleRad = (nav->glideSlopeAngleDeg() + GSTestRoll[i].plusDeg) * SG_DEGREES_TO_RADIANS;
603 SGVec3d radioPos = gsCart;
604 radioPos += (gsVerticalAxis * tan(gsAngleRad) * GSTestRoll[i].atDstNM * SG_NM_TO_METER);
605 radioPos += (gsAltAxis * GSTestRoll[i].atDstNM * SG_NM_TO_METER);
606 setPositionAndStabilise(r.get(), SGGeod::fromCart(radioPos));
607 xpecAzim = (GSTestRoll[i].nvAzim + GSTestRoll[i].plusDeg);
608 } else {
609 // Line item atAlt is non zero so use altitude for Rx position
610 SGGeod p = SGGeodesy::direct(nav->geod(), GSTestRoll[i].atAltFt, GSTestRoll[i].atDstNM * SG_NM_TO_METER);
611 p.setElevationFt(GSTestRoll[i].atAltFt);
612 setPositionAndStabilise(r.get(), p);
613 //tbd calc Rx Azim from Tx for altitude case
614 SGGeodesy::inverse(p, nav->geod(), bngToNavaid, az2, s);
615 xpecAzim = SG_RADIANS_TO_DEGREES * (atan((GSTestRoll[i].atAltFt * SG_FEET_TO_METER) / s));
616 }
617 //
618 if (GSTestRoll[i].vFalse) {
619 // rxFlse indicates false signal, use deflections manually entered in Item
620 xpecDefl = GSTestRoll[i].vGSDefl;
621 xpecDefn = GSTestRoll[i].vGSDefn;
622 } else {
623 if (GSTestRoll[i].atAltFt == 0) {
624 // not rxFlse and atAltFt is zero : calculate needle deflections from Rx posn degrees wrt beam
625 xpecDefn = 0 - GSTestRoll[i].plusDeg / halfBeam; // Plane high: needle below
626 } else {
627 // not rxFlse and atAltFt non zero : calculate needle deflections from Rx posn azimuth wrt beam
628 xpecDefn = (GSTestRoll[i].nvAzim - az2) / halfBeam; // Plane high: needle below;
629 }
630 xpecDefn = (xpecDefn > 1) ? 1 : xpecDefn;
631 xpecDefn = (xpecDefn < -1) ? -1 : xpecDefn;
632 xpecDefl = xpecDefn * deflFact;
633 }
634 //
635 // Verify expected:
636 tMesg = itemDesc + "Operable";
637 CPPUNIT_ASSERT_EQUAL_MESSAGE(tMesg, GSTestRoll[i].vInRnge, node->getBoolValue("operable"));
638 tMesg = itemDesc + "nav-id";
639 auto dddbug = node->getStringValue("nav-id");
640 CPPUNIT_ASSERT_MESSAGE(tMesg, node->getStringValue("nav-id") == GSTestRoll[i].nvIden);
641 tMesg = itemDesc + "Sig Norm";
642 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, GSTestRoll[i].vSigNorm, node->getDoubleValue("signal-quality-norm"), GSTestRoll[i].vSigTolr);
643 tMesg = itemDesc + "gs-direct";
644 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, xpecAzim, node->getDoubleValue("gs-direct-deg"), 1);
645 tMesg = itemDesc + "needle defl";
646 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, xpecDefl, node->getDoubleValue("gs-needle-deflection"), GSTestRoll[i].vDeflTolr);
647 tMesg = itemDesc + "defl norm";
648 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(tMesg, xpecDefn, node->getDoubleValue("gs-needle-deflection-norm"), GSTestRoll[i].vDefnTolr);
649 //
650 }
651 }
652
653 void NavRadioTests::testGS()
654 {
655 // radio setup
656 SGPropertyNode_ptr configNode(new SGPropertyNode);
657 configNode->setStringValue("name", "navtest");
658 configNode->setIntValue("number", 2);
659 std::unique_ptr<FGNavRadio> r(new FGNavRadio(configNode));
660 r->bind();
661 r->init();
662
663 SGPropertyNode_ptr node = globals->get_props()->getNode("instrumentation/navtest[2]");
664 node->setBoolValue("serviceable", true);
665 globals->get_props()->setDoubleValue("systems/electrical/outputs/nav", 6.0);
666
667 // EDDT 28R
668 FGPositioned::TypeFilter f{FGPositioned::GS};
669 FGNavRecordRef gs = fgpositioned_cast<FGNavRecord>(
670 FGPositioned::findClosestWithIdent("ITLW", SGGeod::fromDeg(13, 52), &f));
671 CPPUNIT_ASSERT(gs->type() == FGPositioned::GS);
672 node->setDoubleValue("frequencies/selected-mhz", 110.10);
673 CPPUNIT_ASSERT(node->getStringValue("frequencies/selected-mhz-fmt") == "110.10");
674
675 CPPUNIT_ASSERT_DOUBLES_EQUAL(gs->glideSlopeAngleDeg(), 3.0, 0.001);
676 double gsAngleRad = gs->glideSlopeAngleDeg() * SG_DEGREES_TO_RADIANS;
677
678 /////////////
679 // derive the GS geometry in cartesian vectors, to match what
680 // navradio.cxx does
681 SGGeod aboveGS = gs->geod();
682 aboveGS.setElevationM(gs->geod().getElevationM() + 100.0);
683 SGVec3d gsVerticalAxis = SGVec3d::fromGeod(aboveGS) - gs->cart();
684 // intentionally different approach to what navradio uses
685
686 gsVerticalAxis *= 0.01; // make it per meter, since we used 100m above
687
688 // dervice the baseline
689 SGQuatd baseLineRot = SGQuatd::fromLonLat(gs->geod()) * SGQuatd::fromHeadAttBankDeg(80.828, 0, 0);
690 SGVec3d gsAltAxis = baseLineRot.backTransform(SGVec3d(1.0, 0.0, 0.0));
691
692 const SGVec3d gsCart = gs->cart();
693
694 //////////////////
695
696 SGVec3d radioPos = gsCart;
697 radioPos += (gsVerticalAxis * tan(gsAngleRad) * 8 * SG_NM_TO_METER);
698 radioPos += (gsAltAxis * 8 * SG_NM_TO_METER);
699
700 setPositionAndStabilise(r.get(), SGGeod::fromCart(radioPos));
701
702 CPPUNIT_ASSERT(node->getStringValue("nav-id") == "ITLW");
703 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, node->getDoubleValue("signal-quality-norm"), 0.01);
704 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, node->getDoubleValue("gs-direct-deg"), 0.1);
705 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, node->getDoubleValue("gs-needle-deflection"), 0.1);
706 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, node->getDoubleValue("gs-needle-deflection-norm"), 0.01);
707 CPPUNIT_ASSERT(node->getBoolValue("gs-in-range"));
708
709 // 0.5 degree offset above
710 gsAngleRad = (gs->glideSlopeAngleDeg() + 0.5) * SG_DEGREES_TO_RADIANS;
711 radioPos = gsCart;
712 radioPos += (gsVerticalAxis * tan(gsAngleRad) * 4 * SG_NM_TO_METER);
713 radioPos += (gsAltAxis * 4 * SG_NM_TO_METER);
714
715 setPositionAndStabilise(r.get(), SGGeod::fromCart(radioPos));
716
717 CPPUNIT_ASSERT(node->getStringValue("nav-id") == "ITLW");
718 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, node->getDoubleValue("signal-quality-norm"), 0.01);
719 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.5, node->getDoubleValue("gs-direct-deg"), 0.1);
720 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.5, node->getDoubleValue("gs-needle-deflection"), 0.1);
721 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.714, node->getDoubleValue("gs-needle-deflection-norm"), 0.01);
722 CPPUNIT_ASSERT(node->getBoolValue("gs-in-range"));
723
724 // 1 degree below (danger!)
725 gsAngleRad = (gs->glideSlopeAngleDeg() - 1.0) * SG_DEGREES_TO_RADIANS;
726 radioPos = gsCart;
727 radioPos += (gsVerticalAxis * tan(gsAngleRad) * 2 * SG_NM_TO_METER);
728 radioPos += (gsAltAxis * 2 * SG_NM_TO_METER);
729
730 setPositionAndStabilise(r.get(), SGGeod::fromCart(radioPos));
731
732 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, node->getDoubleValue("signal-quality-norm"), 0.01);
733 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, node->getDoubleValue("gs-direct-deg"), 0.1);
734 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.5, node->getDoubleValue("gs-needle-deflection"), 0.1);
735 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, node->getDoubleValue("gs-needle-deflection-norm"), 0.01);
736 CPPUNIT_ASSERT(node->getBoolValue("gs-in-range"));
737
738 // false course above, reversed
739 gsAngleRad = (gs->glideSlopeAngleDeg() + 3.0) * SG_DEGREES_TO_RADIANS;
740 radioPos = gsCart;
741 radioPos += (gsVerticalAxis * tan(gsAngleRad) * 5 * SG_NM_TO_METER);
742 radioPos += (gsAltAxis * 5 * SG_NM_TO_METER);
743
744 setPositionAndStabilise(r.get(), SGGeod::fromCart(radioPos));
745
746 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, node->getDoubleValue("signal-quality-norm"), 0.01);
747 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.0, node->getDoubleValue("gs-direct-deg"), 0.1);
748 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, node->getDoubleValue("gs-needle-deflection"), 0.1);
749 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, node->getDoubleValue("gs-needle-deflection-norm"), 0.01);
750 CPPUNIT_ASSERT(node->getBoolValue("gs-in-range"));
751
752 // false course above, reversed, 0.35 offset below
753 gsAngleRad = (gs->glideSlopeAngleDeg() + 2.65) * SG_DEGREES_TO_RADIANS;
754 radioPos = gsCart;
755 radioPos += (gsVerticalAxis * tan(gsAngleRad) * 3 * SG_NM_TO_METER);
756 radioPos += (gsAltAxis * 3 * SG_NM_TO_METER);
757
758 setPositionAndStabilise(r.get(), SGGeod::fromCart(radioPos));
759
760 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, node->getDoubleValue("signal-quality-norm"), 0.01);
761 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.65, node->getDoubleValue("gs-direct-deg"), 0.1);
762 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.75, node->getDoubleValue("gs-needle-deflection"), 0.1);
763 CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.5, node->getDoubleValue("gs-needle-deflection-norm"), 0.01);
764 CPPUNIT_ASSERT(node->getBoolValue("gs-in-range"));
765 }
766
767 void NavRadioTests::testILSFalseCourse()
768 {
769
770 // also GS false lobes
771 }
772
773 void NavRadioTests::testILSPaired()
774 {
775 // EGPH and countless more
776 }
777
778 void NavRadioTests::testILSAdjacentPaired()
779 {
780 // eg KJFK
781 }
782
783 void NavRadioTests::testGlideslopeLongDistance()
784 {
785 // radio setup
786 SGPropertyNode_ptr configNode(new SGPropertyNode);
787 configNode->setStringValue("name", "navtest");
788 configNode->setIntValue("number", 2);
789 std::unique_ptr<FGNavRadio> r(new FGNavRadio(configNode));
790 r->bind();
791 r->init();
792
793 SGPropertyNode_ptr node = globals->get_props()->getNode("instrumentation/navtest[2]");
794 node->setBoolValue("serviceable", true);
795 globals->get_props()->setDoubleValue("systems/electrical/outputs/nav", 6.0);
796
797 // EGLL 27L
798 FGPositioned::TypeFilter f{FGPositioned::GS};
799 FGNavRecordRef gs = fgpositioned_cast<FGNavRecord>(
800 FGPositioned::findClosestWithIdent("ILL", SGGeod::fromDeg(0, 51), &f));
801 CPPUNIT_ASSERT(gs->type() == FGPositioned::GS);
802 node->setDoubleValue("frequencies/selected-mhz", 109.50);
803 CPPUNIT_ASSERT(node->getStringValue("frequencies/selected-mhz-fmt") == "109.50");
804
805 CPPUNIT_ASSERT_DOUBLES_EQUAL(gs->glideSlopeAngleDeg(), 3.0, 0.001);
806
807 // standard approach (per charts)
808 SGGeod p = SGGeodesy::direct(gs->geod(), 90, 7.5 * SG_NM_TO_METER);
809 p.setElevationFt(2500);
810 setPositionAndStabilise(r.get(), p);
811 CPPUNIT_ASSERT_EQUAL(true, node->getBoolValue("gs-in-range"));
812
813 // normal approach
814 p = SGGeodesy::direct(gs->geod(), 90, 9 * SG_NM_TO_METER);
815 p.setElevationFt(3000);
816 setPositionAndStabilise(r.get(), p);
817 CPPUNIT_ASSERT_EQUAL(true, node->getBoolValue("gs-in-range"));
818
819 // in our current nav data, the GS range is defined as 10nm, so the gs-in-range
820 // is false for these
821
822 // 4000 feet intercept
823 p = SGGeodesy::direct(gs->geod(), 90, 12 * SG_NM_TO_METER);
824 p.setElevationFt(4000);
825 setPositionAndStabilise(r.get(), p);
826 CPPUNIT_ASSERT_EQUAL(false, node->getBoolValue("gs-in-range"));
827 CPPUNIT_ASSERT_EQUAL(true, node->getBoolValue("in-range"));
828
829 // further back
830 p = SGGeodesy::direct(gs->geod(), 90, 17.5 * SG_NM_TO_METER);
831 p.setElevationFt(4000);
832 setPositionAndStabilise(r.get(), p);
833 CPPUNIT_ASSERT_EQUAL(false, node->getBoolValue("gs-in-range"));
834 CPPUNIT_ASSERT_EQUAL(true, node->getBoolValue("in-range"));
835
836 // really pushing it
837 p = SGGeodesy::direct(gs->geod(), 90, 25 * SG_NM_TO_METER);
838 p.setElevationFt(4000);
839 setPositionAndStabilise(r.get(), p);
840 CPPUNIT_ASSERT_EQUAL(false, node->getBoolValue("gs-in-range"));
841 CPPUNIT_ASSERT_EQUAL(true, node->getBoolValue("in-range"));
842 }
843
844 void NavRadioTests::testVORSignalQuality()
845 {
846 std::unique_ptr<FGNavRadio> r = testVORSignalQuality_setup("navtest", 2);
847 SGPropertyNode* node = fgGetNode("/instrumentation/navtest[2]");
848
849 SGGeod pos = SGGeod::fromDegFt(-3.35277800, 55.499167, 20000);
850 setPositionAndStabilise(r.get(), pos);
851 // The signal quality should be good here
852 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0,
853 node->getDoubleValue("signal-quality-norm"),
854 0.01);
855
856 // 2786 feet is the navaid altitude above sea level, according to nav.dat.
857 // I believe 150000 is high enough, however I'm not knowledgeable in this
858 // field.
859 pos = SGGeod::fromDegFt(-3.35277800, 55.499167, 2786 + 150000);
860 setPositionAndStabilise(r.get(), pos);
861 // Too high for a good signal here
862 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0,
863 node->getDoubleValue("signal-quality-norm"),
864 0.01);
865 r.reset();
866
867 // Test that changing the standby frequency doesn't affect the rate of
868 // change of signal quality (it has no reason to disable the low-pass
869 // filter).
870 double rate1 = testVORSignalQuality_maxRateOfChange(false);
871 double rate2 = testVORSignalQuality_maxRateOfChange(true);
872 // At the time of this writing, rate1 == rate2, however randomness, signal
873 // quality affected by weather... might be added in the future.
874 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, rate2 / rate1, 0.01);
875 }
876
877 std::unique_ptr<FGNavRadio>
878 NavRadioTests::testVORSignalQuality_setup(const std::string& name, int index)
879 {
880 SGPropertyNode_ptr configNode(new SGPropertyNode);
881 configNode->setStringValue("name", name);
882 configNode->setIntValue("number", index);
883 auto r = std::make_unique<FGNavRadio>(configNode);
884 r->bind();
885 r->init();
886
887 SGPropertyNode* node = fgGetNode("/instrumentation/" + name, index);
888 node->setBoolValue("serviceable", true);
889 // Needed for the radio to power up
890 fgSetDouble("/systems/electrical/outputs/nav", 6.0);
891 node->setDoubleValue("frequencies/selected-mhz", 113.8);
892 node->setDoubleValue("frequencies/standby-mhz", 112.4); // whatever
893
894 return r;
895 }
896
897 // Rise above the selected VOR station and measure how quickly the signal
898 // quality diminishes. Return the largest variation seen between two
899 // consecutive positions.
900 //
901 // When the low-pass filter is disabled, the return value is larger (by a
902 // factor of approximately four with the FG code from November 2022).
903 double
904 NavRadioTests::testVORSignalQuality_maxRateOfChange(bool changeStandbyFreq)
905 {
906 std::unique_ptr<FGNavRadio> r = testVORSignalQuality_setup("navtest", 2);
907 SGPropertyNode* node = fgGetNode("/instrumentation/navtest[2]");
908
909 double currAlt = 2786 + 65000; // in feet, above MSL
910 double maxChange = 0.0;
911 double signalQuality, lastSignalQuality = 1.0;
912
913 for (int i = 0; i < 1000; i++) {
914 currAlt += 20;
915 SGGeod pos = SGGeod::fromDegFt(-3.35277800, 55.499167, currAlt);
916 FGTestApi::setPosition(pos);
917
918 if (changeStandbyFreq) {
919 node->setDoubleValue("frequencies/standby-mhz",
920 (i % 2) ? 112.2 : 112.5);
921 }
922 r->update(0.01);
923
924 signalQuality = node->getDoubleValue("signal-quality-norm");
925 maxChange = std::max(maxChange,
926 std::abs(signalQuality - lastSignalQuality));
927 lastSignalQuality = signalQuality;
928 }
929
930 return maxChange;
931 }