| 1 |
/* |
| 2 |
* Copyright (C) 2019 James Turner |
| 3 |
* |
| 4 |
* This file is part of the program FlightGear. |
| 5 |
* |
| 6 |
* This program is free software: you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation, either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "test_gps.hxx" |
| 21 |
|
| 22 |
#include <memory> |
| 23 |
#include <cstring> |
| 24 |
|
| 25 |
#include "test_suite/FGTestApi/testGlobals.hxx" |
| 26 |
#include "test_suite/FGTestApi/NavDataCache.hxx" |
| 27 |
#include "test_suite/FGTestApi/TestPilot.hxx" |
| 28 |
#include "test_suite/FGTestApi/TestDataLogger.hxx" |
| 29 |
|
| 30 |
#include <Navaids/FlightPlan.hxx> |
| 31 |
#include <Navaids/NavDataCache.hxx> |
| 32 |
#include <Navaids/fixlist.hxx> |
| 33 |
#include <Navaids/navlist.hxx> |
| 34 |
#include <Navaids/navrecord.hxx> |
| 35 |
|
| 36 |
#include <Instrumentation/gps.hxx> |
| 37 |
#include <Instrumentation/navradio.hxx> |
| 38 |
|
| 39 |
#include <Autopilot/route_mgr.hxx> |
| 40 |
|
| 41 |
using namespace flightgear; |
| 42 |
using namespace std::string_literals; |
| 43 |
|
| 44 |
///////////////////////////////////////////////////////////////////////////// |
| 45 |
|
| 46 |
class TestFPDelegate : public FlightPlan::Delegate |
| 47 |
{ |
| 48 |
public: |
| 49 |
FlightPlanRef thePlan; |
| 50 |
int sequenceCount = 0; |
| 51 |
|
| 52 |
void sequence() override |
| 53 |
{ |
| 54 |
|
| 55 |
++sequenceCount; |
| 56 |
int newIndex = thePlan->currentIndex() + 1; |
| 57 |
if (newIndex >= thePlan->numLegs()) { |
| 58 |
thePlan->finish(); |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
thePlan->setCurrentIndex(newIndex); |
| 63 |
} |
| 64 |
|
| 65 |
void currentWaypointChanged() override |
| 66 |
{ |
| 67 |
} |
| 68 |
|
| 69 |
}; |
| 70 |
|
| 71 |
///////////////////////////////////////////////////////////////////////////// |
| 72 |
|
| 73 |
// Set up function for each test. |
| 74 |
void GPSTests::setUp() |
| 75 |
{ |
| 76 |
FGTestApi::setUp::initTestGlobals("gps"); |
| 77 |
FGTestApi::setUp::initNavDataCache(); |
| 78 |
|
| 79 |
globals->get_subsystem_mgr()->bind(); |
| 80 |
globals->get_subsystem_mgr()->init(); |
| 81 |
|
| 82 |
setupRouteManager(); |
| 83 |
} |
| 84 |
|
| 85 |
// Clean up after each test. |
| 86 |
void GPSTests::tearDown() |
| 87 |
{ |
| 88 |
FGTestApi::tearDown::shutdownTestGlobals(); |
| 89 |
} |
| 90 |
|
| 91 |
GPS* GPSTests::setupStandardGPS(SGPropertyNode_ptr config, |
| 92 |
const std::string name, const int index) |
| 93 |
{ |
| 94 |
SGPropertyNode_ptr configNode(config.valid() ? config |
| 95 |
: SGPropertyNode_ptr{new SGPropertyNode}); |
| 96 |
configNode->setStringValue("name", name); |
| 97 |
configNode->setIntValue("number", index); |
| 98 |
|
| 99 |
GPS* gps(new GPS(configNode)); |
| 100 |
|
| 101 |
SGPropertyNode_ptr node = globals->get_props()->getNode("instrumentation", true)->getChild(name, index, true); |
| 102 |
node->setBoolValue("serviceable", true); |
| 103 |
globals->get_props()->setDoubleValue("systems/electrical/outputs/gps", 6.0); |
| 104 |
|
| 105 |
gps->bind(); |
| 106 |
gps->init(); |
| 107 |
|
| 108 |
globals->get_subsystem_mgr()->add("gps", gps); |
| 109 |
return gps; |
| 110 |
} |
| 111 |
|
| 112 |
void GPSTests::setupRouteManager() |
| 113 |
{ |
| 114 |
auto rm = globals->get_subsystem_mgr()->add<FGRouteMgr>(); |
| 115 |
rm->bind(); |
| 116 |
rm->init(); |
| 117 |
rm->postinit(); |
| 118 |
} |
| 119 |
|
| 120 |
///////////////////////////////////////////////////////////////////////////// |
| 121 |
|
| 122 |
void GPSTests::testBasic() |
| 123 |
{ |
| 124 |
setupStandardGPS(); |
| 125 |
|
| 126 |
FGPositioned::TypeFilter f{FGPositioned::VOR}; |
| 127 |
auto bodrumVOR = fgpositioned_cast<FGNavRecord>(FGPositioned::findClosestWithIdent("BDR", SGGeod::fromDeg(27.6, 37), &f)); |
| 128 |
SGGeod p1 = SGGeodesy::direct(bodrumVOR->geod(), 45.0, 5.0 * SG_NM_TO_METER); |
| 129 |
|
| 130 |
FGTestApi::setPositionAndStabilise(p1); |
| 131 |
|
| 132 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 133 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(p1.getLongitudeDeg(), gpsNode->getDoubleValue("indicated-longitude-deg"), 0.01); |
| 134 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(p1.getLatitudeDeg(), gpsNode->getDoubleValue("indicated-latitude-deg"), 0.01); |
| 135 |
|
| 136 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 137 |
pilot->setSpeedKts(120); |
| 138 |
pilot->setCourseTrue(225.0); |
| 139 |
|
| 140 |
FGTestApi::runForTime(30.0); |
| 141 |
|
| 142 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(225, gpsNode->getDoubleValue("indicated-track-true-deg"), 0.5); |
| 143 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(120, gpsNode->getDoubleValue("indicated-ground-speed-kt"), 1); |
| 144 |
|
| 145 |
// 120kts = |
| 146 |
double speedMSec = 120 * SG_KT_TO_MPS; |
| 147 |
double components = speedMSec * (1.0 / sqrt(2.0)); |
| 148 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-components, gpsNode->getDoubleValue("ew-velocity-msec"), 0.1); |
| 149 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-components, gpsNode->getDoubleValue("ns-velocity-msec"), 0.1); |
| 150 |
|
| 151 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(120 * (30.0 / 3600), gpsNode->getDoubleValue("odometer"), 0.1); |
| 152 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(120 * (30.0 / 3600), gpsNode->getDoubleValue("trip-odometer"), 0.1); |
| 153 |
} |
| 154 |
|
| 155 |
void GPSTests::testOBSMode() |
| 156 |
{ |
| 157 |
setupStandardGPS(); |
| 158 |
|
| 159 |
FGPositioned::TypeFilter f{FGPositioned::VOR}; |
| 160 |
auto bodrumVOR = fgpositioned_cast<FGNavRecord>(FGPositioned::findClosestWithIdent("BDR", SGGeod::fromDeg(27.6, 37), &f)); |
| 161 |
SGGeod p1 = SGGeodesy::direct(bodrumVOR->geod(), 45.0, 5.0 * SG_NM_TO_METER); |
| 162 |
|
| 163 |
FGTestApi::setPositionAndStabilise(p1); |
| 164 |
|
| 165 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 166 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(p1.getLongitudeDeg(), gpsNode->getDoubleValue("indicated-longitude-deg"), 0.01); |
| 167 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(p1.getLatitudeDeg(), gpsNode->getDoubleValue("indicated-latitude-deg"), 0.01); |
| 168 |
|
| 169 |
gpsNode->setDoubleValue("selected-course-deg", 225); |
| 170 |
|
| 171 |
// query BDR from the GPS database |
| 172 |
gpsNode->setStringValue("scratch/query", "BDR"); |
| 173 |
gpsNode->setStringValue("scratch/type", "vor"); |
| 174 |
gpsNode->setStringValue("command", "search"); |
| 175 |
|
| 176 |
CPPUNIT_ASSERT_EQUAL(true, gpsNode->getBoolValue("scratch/valid")); |
| 177 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(225.0, gpsNode->getDoubleValue("scratch/true-bearing-deg"), 0.5); |
| 178 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, gpsNode->getDoubleValue("scratch/distance-nm"), 0.1); |
| 179 |
|
| 180 |
// select OBS mode one it |
| 181 |
gpsNode->setStringValue("command", "obs"); |
| 182 |
|
| 183 |
FGTestApi::setPositionAndStabilise(p1); |
| 184 |
|
| 185 |
CPPUNIT_ASSERT_EQUAL(std::string{"obs"}, std::string{gpsNode->getStringValue("mode")}); |
| 186 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, gpsNode->getDoubleValue("wp/wp[1]/distance-nm"), 0.01); |
| 187 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(225.0, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 188 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(bodrumVOR->get_lon(), gpsNode->getDoubleValue("wp/wp[1]/longitude-deg"), 0.01); |
| 189 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(bodrumVOR->get_lat(), gpsNode->getDoubleValue("wp/wp[1]/latitude-deg"), 0.01); |
| 190 |
|
| 191 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(225.0, gpsNode->getDoubleValue("desired-course-deg"), 0.01); |
| 192 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.1); |
| 193 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 194 |
|
| 195 |
// off axis, angular |
| 196 |
SGGeod p2 = SGGeodesy::direct(bodrumVOR->geod(), 40.0, 4.0 * SG_NM_TO_METER); |
| 197 |
FGTestApi::setPositionAndStabilise(p2); |
| 198 |
|
| 199 |
CPPUNIT_ASSERT_EQUAL(std::string{"obs"}, std::string{gpsNode->getStringValue("mode")}); |
| 200 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0, gpsNode->getDoubleValue("wp/wp[1]/distance-nm"), 0.01); |
| 201 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(220.0, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 202 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(225.0, gpsNode->getDoubleValue("desired-course-deg"), 0.01); |
| 203 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-5.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.1); |
| 204 |
|
| 205 |
// off axis, perpendicular |
| 206 |
SGGeod p3 = SGGeodesy::direct(p1, 135, 0.5 * SG_NM_TO_METER); |
| 207 |
FGTestApi::setPositionAndStabilise(p3); |
| 208 |
|
| 209 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(225.0, gpsNode->getDoubleValue("desired-course-deg"), 0.01); |
| 210 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.5, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 211 |
} |
| 212 |
|
| 213 |
void GPSTests::testDirectTo() |
| 214 |
{ |
| 215 |
setupStandardGPS(); |
| 216 |
|
| 217 |
FGPositioned::TypeFilter f{FGPositioned::VOR}; |
| 218 |
auto bodrumVOR = fgpositioned_cast<FGNavRecord>(FGPositioned::findClosestWithIdent("BDR", SGGeod::fromDeg(27.6, 37), &f)); |
| 219 |
SGGeod p1 = SGGeodesy::direct(bodrumVOR->geod(), 30.0, 16.0 * SG_NM_TO_METER); |
| 220 |
|
| 221 |
FGTestApi::setPositionAndStabilise(p1); |
| 222 |
|
| 223 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 224 |
|
| 225 |
// load into the scratch |
| 226 |
gpsNode->setStringValue("scratch/query", "BDR"); |
| 227 |
gpsNode->setStringValue("scratch/type", "vor"); |
| 228 |
gpsNode->setStringValue("command", "search"); |
| 229 |
|
| 230 |
CPPUNIT_ASSERT_EQUAL(true, gpsNode->getBoolValue("scratch/valid")); |
| 231 |
|
| 232 |
gpsNode->setStringValue("command", "direct"); |
| 233 |
|
| 234 |
CPPUNIT_ASSERT_EQUAL(std::string{"dto"}, std::string{gpsNode->getStringValue("mode")}); |
| 235 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(p1.getLongitudeDeg(), gpsNode->getDoubleValue("wp/wp[0]/longitude-deg"), 0.01); |
| 236 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(p1.getLatitudeDeg(), gpsNode->getDoubleValue("wp/wp[0]/latitude-deg"), 0.01); |
| 237 |
|
| 238 |
CPPUNIT_ASSERT_EQUAL(std::string{"BDR"}, std::string{gpsNode->getStringValue("wp/wp[1]/ID")}); |
| 239 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(16.0, gpsNode->getDoubleValue("wp/wp[1]/distance-nm"), 0.01); |
| 240 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(210, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 241 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(bodrumVOR->get_lon(), gpsNode->getDoubleValue("wp/wp[1]/longitude-deg"), 0.01); |
| 242 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(bodrumVOR->get_lat(), gpsNode->getDoubleValue("wp/wp[1]/latitude-deg"), 0.01); |
| 243 |
|
| 244 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.1); |
| 245 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 246 |
|
| 247 |
// move off the direct-to line, check everything works |
| 248 |
|
| 249 |
SGGeod p2 = SGGeodesy::direct(bodrumVOR->geod(), 35.0, 12.0 * SG_NM_TO_METER); |
| 250 |
FGTestApi::setPositionAndStabilise(p2); |
| 251 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(5, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.1); |
| 252 |
|
| 253 |
SGGeod p3 = SGGeodesy::direct(p1, 210, 6.0 * SG_NM_TO_METER); |
| 254 |
SGGeod xtk = SGGeodesy::direct(p3, 120, 0.8 * SG_NM_TO_METER); |
| 255 |
FGTestApi::setPositionAndStabilise(xtk); |
| 256 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 257 |
|
| 258 |
SGGeod xtk2 = SGGeodesy::direct(p3, 120, -1.8 * SG_NM_TO_METER); |
| 259 |
FGTestApi::setPositionAndStabilise(xtk2); |
| 260 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.8, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 261 |
} |
| 262 |
|
| 263 |
void GPSTests::testNavRadioSlave() |
| 264 |
{ |
| 265 |
SGPropertyNode_ptr radioConfigNode(new SGPropertyNode); |
| 266 |
radioConfigNode->setStringValue("name", "navtest"); |
| 267 |
radioConfigNode->setIntValue("number", 2); |
| 268 |
std::unique_ptr<FGNavRadio> r(new FGNavRadio(radioConfigNode)); |
| 269 |
} |
| 270 |
|
| 271 |
void GPSTests::testLegMode() |
| 272 |
{ |
| 273 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 274 |
|
| 275 |
auto fp = FlightPlan::create(); |
| 276 |
rm->setFlightPlan(fp); |
| 277 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "EBBR", "07L", "EGGD", "27", |
| 278 |
"NIK COA DVR TAWNY WOD"); |
| 279 |
|
| 280 |
// takes the place of the Nasal delegates |
| 281 |
auto testDelegate = new TestFPDelegate; |
| 282 |
testDelegate->thePlan = fp; |
| 283 |
|
| 284 |
CPPUNIT_ASSERT(rm->activate()); |
| 285 |
|
| 286 |
fp->addDelegate(testDelegate); |
| 287 |
setupStandardGPS(); |
| 288 |
|
| 289 |
FGTestApi::setPositionAndStabilise(fp->departureRunway()->pointOnCenterline(0.0)); |
| 290 |
|
| 291 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 292 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 293 |
gpsNode->setStringValue("command", "leg"); |
| 294 |
|
| 295 |
CPPUNIT_ASSERT_EQUAL(std::string{"leg"}, std::string{gpsNode->getStringValue("mode")}); |
| 296 |
CPPUNIT_ASSERT_EQUAL(std::string{"EBBR-07L"}, std::string{gpsNode->getStringValue("wp/wp[1]/ID")}); |
| 297 |
|
| 298 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(65.0, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 299 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(65.0, gpsNode->getDoubleValue("desired-course-deg"), 0.5); |
| 300 |
|
| 301 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 302 |
pilot->setSpeedKts(200); |
| 303 |
pilot->setCourseTrue(65.0); |
| 304 |
pilot->setTargetAltitudeFtMSL(6000); |
| 305 |
FGTestApi::runForTime(60.0); |
| 306 |
|
| 307 |
// check we sequenced to NIK |
| 308 |
CPPUNIT_ASSERT_EQUAL(1, testDelegate->sequenceCount); |
| 309 |
CPPUNIT_ASSERT_EQUAL(1, fp->currentIndex()); |
| 310 |
|
| 311 |
CPPUNIT_ASSERT_EQUAL(std::string{"EBBR-07L"}, std::string{gpsNode->getStringValue("wp/wp[0]/ID")}); |
| 312 |
CPPUNIT_ASSERT_EQUAL(std::string{"NIK"}, std::string{gpsNode->getStringValue("wp/wp[1]/ID")}); |
| 313 |
|
| 314 |
// reposition along the leg, closer to NIK |
| 315 |
// and fly to COA |
| 316 |
|
| 317 |
SGGeod nikPos = fp->currentLeg()->waypoint()->position(); |
| 318 |
SGGeod p2 = SGGeodesy::direct(nikPos, 90, 5 * SG_NM_TO_METER); // due east of NIK |
| 319 |
FGTestApi::setPositionAndStabilise(p2); |
| 320 |
|
| 321 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(270, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 322 |
|
| 323 |
auto depRwy = fp->departureRunway(); |
| 324 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(SGGeodesy::distanceNm(nikPos, depRwy->end()), gpsNode->getDoubleValue("wp/leg-distance-nm"), 0.1); |
| 325 |
const double legCourse = SGGeodesy::courseDeg(depRwy->end(), nikPos); |
| 326 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(legCourse, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 327 |
|
| 328 |
const double crsToNIK = SGGeodesy::courseDeg(p2, nikPos); |
| 329 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToNIK - legCourse, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 330 |
|
| 331 |
pilot->setSpeedKts(200); |
| 332 |
pilot->setCourseTrue(270); |
| 333 |
FGTestApi::runForTime(120.0); |
| 334 |
|
| 335 |
CPPUNIT_ASSERT_EQUAL(2, testDelegate->sequenceCount); |
| 336 |
CPPUNIT_ASSERT_EQUAL(2, fp->currentIndex()); |
| 337 |
CPPUNIT_ASSERT_EQUAL(std::string{"NIK"}, std::string{gpsNode->getStringValue("wp/wp[0]/ID")}); |
| 338 |
CPPUNIT_ASSERT_EQUAL(std::string{"COA"}, std::string{gpsNode->getStringValue("wp/wp[1]/ID")}); |
| 339 |
|
| 340 |
SGGeod coaPos = fp->currentLeg()->waypoint()->position(); |
| 341 |
|
| 342 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(SGGeodesy::distanceNm(nikPos, coaPos), gpsNode->getDoubleValue("wp/leg-distance-nm"), 0.1); |
| 343 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(SGGeodesy::courseDeg(nikPos, coaPos), gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 344 |
|
| 345 |
// check manual sequencing |
| 346 |
fp->setCurrentIndex(3); |
| 347 |
CPPUNIT_ASSERT_EQUAL(std::string{"COA"}, std::string{gpsNode->getStringValue("wp/wp[0]/ID")}); |
| 348 |
CPPUNIT_ASSERT_EQUAL(std::string{"DVR"}, std::string{gpsNode->getStringValue("wp/wp[1]/ID")}); |
| 349 |
|
| 350 |
// check course deviation / cross-track error |
| 351 |
SGGeod doverPos = fp->currentLeg()->waypoint()->position(); |
| 352 |
double course = SGGeodesy::courseDeg(coaPos, doverPos); |
| 353 |
double revCourse = SGGeodesy::courseDeg(doverPos, coaPos); |
| 354 |
|
| 355 |
FGTestApi::setPositionAndStabilise(coaPos); |
| 356 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(course, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 357 |
|
| 358 |
SGGeod off1 = SGGeodesy::direct(doverPos, revCourse - 5.0, 16 * SG_NM_TO_METER); |
| 359 |
FGTestApi::setPositionAndStabilise(off1); |
| 360 |
|
| 361 |
double courseToDover = SGGeodesy::courseDeg(off1, doverPos); |
| 362 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseToDover, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 363 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-5.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 364 |
|
| 365 |
CPPUNIT_ASSERT_EQUAL(true, gpsNode->getBoolValue("wp/wp[1]/to-flag")); |
| 366 |
CPPUNIT_ASSERT_EQUAL(false, gpsNode->getBoolValue("wp/wp[1]/from-flag")); |
| 367 |
|
| 368 |
SGGeod off2 = SGGeodesy::direct(doverPos, revCourse + 8.0, 40 * SG_NM_TO_METER); |
| 369 |
FGTestApi::setPositionAndStabilise(off2); |
| 370 |
|
| 371 |
courseToDover = SGGeodesy::courseDeg(off2, doverPos); |
| 372 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseToDover, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 373 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(8.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 374 |
CPPUNIT_ASSERT_EQUAL(true, gpsNode->getBoolValue("wp/wp[1]/to-flag")); |
| 375 |
CPPUNIT_ASSERT_EQUAL(false, gpsNode->getBoolValue("wp/wp[1]/from-flag")); |
| 376 |
|
| 377 |
// check cross-track error calculation |
| 378 |
SGGeod alongTrack = SGGeodesy::direct(coaPos, course, 20 * SG_NM_TO_METER); |
| 379 |
SGGeod offTrack = SGGeodesy::direct(alongTrack, course + 90, SG_NM_TO_METER * 0.7); |
| 380 |
|
| 381 |
FGTestApi::setPositionAndStabilise(offTrack); |
| 382 |
courseToDover = SGGeodesy::courseDeg(offTrack, doverPos); |
| 383 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseToDover, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 384 |
|
| 385 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.7, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 386 |
|
| 387 |
SGGeod offTrack2 = SGGeodesy::direct(alongTrack, courseToDover - 90, SG_NM_TO_METER * 3.4); |
| 388 |
FGTestApi::setPositionAndStabilise(offTrack2); |
| 389 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(3.4, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 390 |
|
| 391 |
// check cross track very close to COA |
| 392 |
SGGeod alongTrack11 = SGGeodesy::direct(coaPos, course, 0.3); |
| 393 |
SGGeod offTrack25 = SGGeodesy::direct(alongTrack11, course + 90, SG_NM_TO_METER * -3.2); |
| 394 |
FGTestApi::setPositionAndStabilise(offTrack25); |
| 395 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(3.2, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 396 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(course, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.1); |
| 397 |
|
| 398 |
// check cross track very close to DVR |
| 399 |
double distanceCOA_DVR = SGGeodesy::distanceM(coaPos, doverPos); |
| 400 |
SGGeod alongTrack2 = SGGeodesy::direct(coaPos, course, distanceCOA_DVR - 0.3); |
| 401 |
SGGeod offTrack3 = SGGeodesy::direct(alongTrack2, course + 90, SG_NM_TO_METER * 1.6); |
| 402 |
FGTestApi::setPositionAndStabilise(offTrack3); |
| 403 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.6, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 404 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(revCourse + 180.0, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.1); |
| 405 |
|
| 406 |
// check cross track in the middle |
| 407 |
SGGeod alongTrack3 = SGGeodesy::direct(coaPos, course, distanceCOA_DVR * 0.52); |
| 408 |
SGGeod offTrack4 = SGGeodesy::direct(alongTrack3, course + 90, SG_NM_TO_METER * 15.6); |
| 409 |
FGTestApi::setPositionAndStabilise(offTrack4); |
| 410 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-15.6, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 411 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(261.55, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.1); |
| 412 |
} |
| 413 |
|
| 414 |
void GPSTests::testBuiltinRevertToOBSAtEnd() |
| 415 |
{ |
| 416 |
//FGTestApi::setUp::logPositionToKML("gps_route_end_revert_to_obs"); |
| 417 |
|
| 418 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 419 |
|
| 420 |
auto fp = FlightPlan::create(); |
| 421 |
rm->setFlightPlan(fp); |
| 422 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "EBBR", "07L", "EGGD", "27", |
| 423 |
"NIK COA DVR TAWNY BDN"); |
| 424 |
|
| 425 |
// FGTestApi::writeFlightPlanToKML(fp); |
| 426 |
|
| 427 |
// takes the place of the Nasal delegates |
| 428 |
auto testDelegate = new TestFPDelegate; |
| 429 |
testDelegate->thePlan = fp; |
| 430 |
|
| 431 |
CPPUNIT_ASSERT(rm->activate()); |
| 432 |
|
| 433 |
fp->addDelegate(testDelegate); |
| 434 |
auto gps = setupStandardGPS(); |
| 435 |
|
| 436 |
FGTestApi::setPositionAndStabilise(fp->departureRunway()->pointOnCenterline(0.0)); |
| 437 |
|
| 438 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 439 |
gpsNode->setStringValue("command", "leg"); |
| 440 |
|
| 441 |
// move to point 18.0 nm after BDN |
| 442 |
auto posNearApproach = fp->pointAlongRoute(5, 18.0); |
| 443 |
FGTestApi::setPositionAndStabilise(posNearApproach); |
| 444 |
fp->setCurrentIndex(6); |
| 445 |
|
| 446 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 447 |
pilot->resetAtPosition(posNearApproach); |
| 448 |
pilot->setSpeedKts(250); |
| 449 |
pilot->flyGPSCourse(gps); |
| 450 |
|
| 451 |
bool ok = FGTestApi::runForTimeWithCheck(600.0, [gpsNode] () { |
| 452 |
const std::string mode = gpsNode->getStringValue("mode"); |
| 453 |
if (mode == "obs") { |
| 454 |
return true; |
| 455 |
} |
| 456 |
return false; |
| 457 |
}); |
| 458 |
|
| 459 |
CPPUNIT_ASSERT(ok); |
| 460 |
CPPUNIT_ASSERT_EQUAL(std::string{"obs"}, std::string{gpsNode->getStringValue("mode")}); |
| 461 |
// should have deactivated |
| 462 |
CPPUNIT_ASSERT_EQUAL(false, fp->isActive()); |
| 463 |
} |
| 464 |
|
| 465 |
void GPSTests::testDirectToLegOnFlightplan() |
| 466 |
{ |
| 467 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 468 |
|
| 469 |
auto fp = FlightPlan::create(); |
| 470 |
rm->setFlightPlan(fp); |
| 471 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "EBBR", "07L", "EGGD", "27", |
| 472 |
"NIK COA DVR TAWNY WOD"); |
| 473 |
|
| 474 |
// takes the place of the Nasal delegates |
| 475 |
auto testDelegate = new TestFPDelegate; |
| 476 |
testDelegate->thePlan = fp; |
| 477 |
|
| 478 |
CPPUNIT_ASSERT(rm->activate()); |
| 479 |
|
| 480 |
fp->addDelegate(testDelegate); |
| 481 |
setupStandardGPS(); |
| 482 |
|
| 483 |
FGTestApi::setPositionAndStabilise(fp->departureRunway()->pointOnCenterline(0.0)); |
| 484 |
|
| 485 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 486 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 487 |
gpsNode->setStringValue("command", "leg"); |
| 488 |
|
| 489 |
CPPUNIT_ASSERT_EQUAL(std::string{"leg"}, std::string{gpsNode->getStringValue("mode")}); |
| 490 |
CPPUNIT_ASSERT_EQUAL(std::string{"EBBR-07L"}, std::string{gpsNode->getStringValue("wp/wp[1]/ID")}); |
| 491 |
|
| 492 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(65.0, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 493 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(65.0, gpsNode->getDoubleValue("desired-course-deg"), 0.5); |
| 494 |
|
| 495 |
// initiate a direct to |
| 496 |
SGGeod p2 = fp->departureRunway()->pointOnCenterline(5.0* SG_NM_TO_METER); |
| 497 |
FGTestApi::setPositionAndStabilise(p2); |
| 498 |
|
| 499 |
auto doverVOR = fp->legAtIndex(3)->waypoint()->source(); |
| 500 |
|
| 501 |
double distanceToDover = SGGeodesy::distanceNm(p2, doverVOR->geod()); |
| 502 |
double bearingToDover = SGGeodesy::courseDeg(p2, doverVOR->geod()); |
| 503 |
|
| 504 |
CPPUNIT_ASSERT_EQUAL(std::string{"DVR"}, doverVOR->ident()); |
| 505 |
gpsNode->setStringValue("scratch/ident", "DVR"); |
| 506 |
gpsNode->setDoubleValue("scratch/longitude-deg", doverVOR->geod().getLongitudeDeg()); |
| 507 |
gpsNode->setDoubleValue("scratch/latitude-deg", doverVOR->geod().getLatitudeDeg()); |
| 508 |
|
| 509 |
gpsNode->setStringValue("command", "direct"); |
| 510 |
|
| 511 |
CPPUNIT_ASSERT_EQUAL(std::string{"dto"}, std::string{gpsNode->getStringValue("mode")}); |
| 512 |
|
| 513 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(p2.getLongitudeDeg(), gpsNode->getDoubleValue("wp/wp[0]/longitude-deg"), 0.01); |
| 514 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(p2.getLatitudeDeg(), gpsNode->getDoubleValue("wp/wp[0]/latitude-deg"), 0.01); |
| 515 |
|
| 516 |
CPPUNIT_ASSERT_EQUAL(std::string{"DVR"}, std::string{gpsNode->getStringValue("wp/wp[1]/ID")}); |
| 517 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(distanceToDover, gpsNode->getDoubleValue("wp/wp[1]/distance-nm"), 0.01); |
| 518 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(bearingToDover, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 519 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(doverVOR->geod().getLongitudeDeg(), gpsNode->getDoubleValue("wp/wp[1]/longitude-deg"), 0.01); |
| 520 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(doverVOR->geod().getLatitudeDeg(), gpsNode->getDoubleValue("wp/wp[1]/latitude-deg"), 0.01); |
| 521 |
|
| 522 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.1); |
| 523 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 524 |
} |
| 525 |
|
| 526 |
void GPSTests::testDirectToLegOnFlightplanAndResumeBuiltin() |
| 527 |
{ |
| 528 |
// this tests uses the legacy built-in sequencing behaviour of the GPS |
| 529 |
// which is now handled by the Nasal delegate in some cases. |
| 530 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 531 |
// FGTestApi::setUp::logPositionToKML("gps_dto_resume_leg"); |
| 532 |
|
| 533 |
auto fp = FlightPlan::create(); |
| 534 |
rm->setFlightPlan(fp); |
| 535 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "EBBR", "07L", "EGGD", "27", |
| 536 |
"NIK COA DVR TAWNY WOD"); |
| 537 |
|
| 538 |
//FGTestApi::writeFlightPlanToKML(fp); |
| 539 |
|
| 540 |
CPPUNIT_ASSERT(rm->activate()); |
| 541 |
auto gps = setupStandardGPS(); |
| 542 |
|
| 543 |
FGTestApi::setPositionAndStabilise(fp->departureRunway()->pointOnCenterline(0.0)); |
| 544 |
|
| 545 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 546 |
gpsNode->setStringValue("command", "leg"); |
| 547 |
|
| 548 |
CPPUNIT_ASSERT_EQUAL(std::string{"leg"}, std::string{gpsNode->getStringValue("mode")}); |
| 549 |
CPPUNIT_ASSERT_EQUAL(std::string{"EBBR-07L"}, std::string{gpsNode->getStringValue("wp/wp[1]/ID")}); |
| 550 |
|
| 551 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(65.0, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 552 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(65.0, gpsNode->getDoubleValue("desired-course-deg"), 0.5); |
| 553 |
|
| 554 |
// initiate a direct to |
| 555 |
SGGeod p2 = fp->departureRunway()->pointOnCenterline(5.0* SG_NM_TO_METER); |
| 556 |
FGTestApi::setPositionAndStabilise(p2); |
| 557 |
|
| 558 |
auto doverVOR = fp->legAtIndex(3)->waypoint()->source(); |
| 559 |
|
| 560 |
double distanceToDover = SGGeodesy::distanceNm(p2, doverVOR->geod()); |
| 561 |
double bearingToDover = SGGeodesy::courseDeg(p2, doverVOR->geod()); |
| 562 |
|
| 563 |
CPPUNIT_ASSERT_EQUAL(std::string{"DVR"}, doverVOR->ident()); |
| 564 |
gpsNode->setStringValue("scratch/ident", "DVR"); |
| 565 |
gpsNode->setDoubleValue("scratch/longitude-deg", doverVOR->geod().getLongitudeDeg()); |
| 566 |
gpsNode->setDoubleValue("scratch/latitude-deg", doverVOR->geod().getLatitudeDeg()); |
| 567 |
gpsNode->setStringValue("command", "direct"); |
| 568 |
CPPUNIT_ASSERT_EQUAL(std::string{"dto"}, std::string{gpsNode->getStringValue("mode")}); |
| 569 |
|
| 570 |
// check that upon reaching DOVER, we sequence to TAWNY and resume leg mode |
| 571 |
// note this behaviour is from the old C++ sequencing |
| 572 |
|
| 573 |
SGGeod posNearDover = SGGeodesy::direct(p2, bearingToDover, (distanceToDover - 8.0) * SG_NM_TO_METER); |
| 574 |
FGTestApi::setPositionAndStabilise(posNearDover); |
| 575 |
|
| 576 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 577 |
pilot->resetAtPosition(posNearDover); |
| 578 |
pilot->setSpeedKts(250); |
| 579 |
pilot->flyGPSCourse(gps); |
| 580 |
|
| 581 |
bool ok = FGTestApi::runForTimeWithCheck(180.0, [fp] () { |
| 582 |
if (fp->currentIndex() == 4) { |
| 583 |
return true; |
| 584 |
} |
| 585 |
return false; |
| 586 |
}); |
| 587 |
|
| 588 |
CPPUNIT_ASSERT(ok); |
| 589 |
CPPUNIT_ASSERT_EQUAL(std::string{"leg"}, std::string{gpsNode->getStringValue("mode")}); |
| 590 |
} |
| 591 |
|
| 592 |
void GPSTests::testLongLeg() |
| 593 |
{ |
| 594 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 595 |
auto fp = FlightPlan::create(); |
| 596 |
rm->setFlightPlan(fp); |
| 597 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "KLAX", "25R", "KJFK", "22R","VNY TEB"); |
| 598 |
|
| 599 |
// takes the place of the Nasal delegates |
| 600 |
auto testDelegate = new TestFPDelegate; |
| 601 |
testDelegate->thePlan = fp; |
| 602 |
|
| 603 |
CPPUNIT_ASSERT(rm->activate()); |
| 604 |
|
| 605 |
fp->addDelegate(testDelegate); |
| 606 |
setupStandardGPS(); |
| 607 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 608 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 609 |
gpsNode->setStringValue("command", "leg"); |
| 610 |
|
| 611 |
// custom CDI deflection output |
| 612 |
gpsNode->setDoubleValue("config/cdi-max-deflection-nm", 20.0); |
| 613 |
|
| 614 |
auto vanNuysVOR = fp->legAtIndex(1)->waypoint()->source(); |
| 615 |
CPPUNIT_ASSERT_EQUAL(std::string{"VAN NUYS VOR-DME"}, vanNuysVOR->name()); |
| 616 |
|
| 617 |
auto teterboroVOR = fp->legAtIndex(2)->waypoint()->source(); |
| 618 |
CPPUNIT_ASSERT_EQUAL(std::string{"TETERBORO VOR-DME"}, teterboroVOR->name()); |
| 619 |
|
| 620 |
|
| 621 |
fp->setCurrentIndex(2); |
| 622 |
// initial course at VNY |
| 623 |
FGTestApi::setPositionAndStabilise(vanNuysVOR->geod()); |
| 624 |
|
| 625 |
const double initialCourse = SGGeodesy::courseDeg(vanNuysVOR->geod(), teterboroVOR->geod()); |
| 626 |
const double distanceM = SGGeodesy::distanceM(vanNuysVOR->geod(), teterboroVOR->geod()); |
| 627 |
|
| 628 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(initialCourse, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 629 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(initialCourse, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 630 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 631 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 632 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(distanceM * SG_METER_TO_NM, gpsNode->getDoubleValue("wp/wp[1]/distance-nm"), 0.01); |
| 633 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(distanceM * SG_METER_TO_NM, gpsNode->getDoubleValue("wp/leg-distance-nm"), 0.01); |
| 634 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("cdi-deflection"), 0.01); |
| 635 |
|
| 636 |
// part of the way, check enroute leg course |
| 637 |
const SGGeod onTheWay = SGGeodesy::direct(vanNuysVOR->geod(), initialCourse, distanceM * 0.7); |
| 638 |
FGTestApi::setPositionAndStabilise(onTheWay); |
| 639 |
|
| 640 |
const double courseNow = SGGeodesy::courseDeg(onTheWay, teterboroVOR->geod()); |
| 641 |
const double distNow = SGGeodesy::distanceM(onTheWay, teterboroVOR->geod()); |
| 642 |
|
| 643 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseNow, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 644 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseNow, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 645 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 646 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 647 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(distNow * SG_METER_TO_NM, gpsNode->getDoubleValue("wp/wp[1]/distance-nm"), 0.01); |
| 648 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(distanceM * SG_METER_TO_NM, gpsNode->getDoubleValue("wp/leg-distance-nm"), 0.01); |
| 649 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("cdi-deflection"), 0.01); |
| 650 |
|
| 651 |
// check a seriously abeam point, we got far of course |
| 652 |
// to the right of the course, i.e desired track is to our left, so -ve |
| 653 |
const SGGeod offTheWay = SGGeodesy::direct(onTheWay, courseNow + 90, SG_NM_TO_METER * 13.5); |
| 654 |
FGTestApi::setPositionAndStabilise(offTheWay); |
| 655 |
const double courseFromOff1 = SGGeodesy::courseDeg(offTheWay, teterboroVOR->geod()); |
| 656 |
const double dist2 = SGGeodesy::distanceM(offTheWay, teterboroVOR->geod()); |
| 657 |
|
| 658 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseFromOff1, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 659 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseNow, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 660 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-13.5, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 661 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseFromOff1 - courseNow, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 662 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(dist2 * SG_METER_TO_NM, gpsNode->getDoubleValue("wp/wp[1]/distance-nm"), 0.01); |
| 663 |
|
| 664 |
const double expectedDefl1 = -13.5 / 20.0; |
| 665 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedDefl1 * 10.0, gpsNode->getDoubleValue("cdi-deflection"), 0.01); |
| 666 |
|
| 667 |
// check off the other side, close to the destination |
| 668 |
const SGGeod onTheWay2 = SGGeodesy::direct(vanNuysVOR->geod(), initialCourse, distanceM * 0.92); |
| 669 |
const double courseOn2 = SGGeodesy::courseDeg(onTheWay2, teterboroVOR->geod()); |
| 670 |
const SGGeod off2 = SGGeodesy::direct(onTheWay2, courseOn2 - 90, SG_NM_TO_METER * 31.2); |
| 671 |
FGTestApi::setPositionAndStabilise(off2); |
| 672 |
const double courseFromOff2 = SGGeodesy::courseDeg(off2, teterboroVOR->geod()); |
| 673 |
const double dist3 = SGGeodesy::distanceM(off2, teterboroVOR->geod()); |
| 674 |
|
| 675 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseFromOff2, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 676 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseOn2, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 677 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(31.2, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 678 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseFromOff2 - courseOn2, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 679 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(dist3 * SG_METER_TO_NM, gpsNode->getDoubleValue("wp/wp[1]/distance-nm"), 0.01); |
| 680 |
|
| 681 |
// should peg the CDI, +ve |
| 682 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, gpsNode->getDoubleValue("cdi-deflection"), 0.01); |
| 683 |
} |
| 684 |
|
| 685 |
void GPSTests::testLongLegWestbound() |
| 686 |
{ |
| 687 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 688 |
auto fp = FlightPlan::create(); |
| 689 |
rm->setFlightPlan(fp); |
| 690 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "ENBR", "35", "BIKF", "29","VOO GAKTU"); |
| 691 |
|
| 692 |
// takes the place of the Nasal delegates |
| 693 |
auto testDelegate = new TestFPDelegate; |
| 694 |
testDelegate->thePlan = fp; |
| 695 |
|
| 696 |
CPPUNIT_ASSERT(rm->activate()); |
| 697 |
|
| 698 |
fp->addDelegate(testDelegate); |
| 699 |
setupStandardGPS(); |
| 700 |
|
| 701 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 702 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 703 |
gpsNode->setStringValue("command", "leg"); |
| 704 |
// custom CDI deflection output |
| 705 |
gpsNode->setDoubleValue("config/cdi-max-deflection-nm", 25.0); |
| 706 |
|
| 707 |
auto volloVOR = fp->legAtIndex(1)->waypoint()->source(); |
| 708 |
CPPUNIT_ASSERT_EQUAL(std::string{"VOLLO VOR-DME"}, volloVOR->name()); |
| 709 |
|
| 710 |
auto gaktu = fp->legAtIndex(2)->waypoint()->source(); |
| 711 |
CPPUNIT_ASSERT_EQUAL(std::string{"GAKTU"}, gaktu->name()); |
| 712 |
|
| 713 |
fp->setCurrentIndex(2); |
| 714 |
// initial course at VNY |
| 715 |
FGTestApi::setPositionAndStabilise(volloVOR->geod()); |
| 716 |
|
| 717 |
const double initialCourse = SGGeodesy::courseDeg(volloVOR->geod(), gaktu->geod()); |
| 718 |
const double distanceM = SGGeodesy::distanceM(volloVOR->geod(), gaktu->geod()); |
| 719 |
|
| 720 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(initialCourse, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 721 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(initialCourse, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 722 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 723 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 724 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(distanceM * SG_METER_TO_NM, gpsNode->getDoubleValue("wp/wp[1]/distance-nm"), 0.01); |
| 725 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(distanceM * SG_METER_TO_NM, gpsNode->getDoubleValue("wp/leg-distance-nm"), 0.01); |
| 726 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("cdi-deflection"), 0.01); |
| 727 |
|
| 728 |
// part of the way, check enroute leg course |
| 729 |
const SGGeod onTheWay = SGGeodesy::direct(volloVOR->geod(), initialCourse, distanceM * 0.4); |
| 730 |
FGTestApi::setPositionAndStabilise(onTheWay); |
| 731 |
|
| 732 |
const double courseNow = SGGeodesy::courseDeg(onTheWay, gaktu->geod()); |
| 733 |
const double distNow = SGGeodesy::distanceM(onTheWay, gaktu->geod()); |
| 734 |
|
| 735 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseNow, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 736 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseNow, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 737 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 738 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 739 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(distNow * SG_METER_TO_NM, gpsNode->getDoubleValue("wp/wp[1]/distance-nm"), 0.01); |
| 740 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(distanceM * SG_METER_TO_NM, gpsNode->getDoubleValue("wp/leg-distance-nm"), 0.01); |
| 741 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("cdi-deflection"), 0.01); |
| 742 |
|
| 743 |
// check a seriously abeam point, we got far of course |
| 744 |
// to the right of the course, i.e desired track is to our left, so -ve |
| 745 |
const SGGeod offTheWay = SGGeodesy::direct(onTheWay, courseNow + 90, SG_NM_TO_METER * 18.6); |
| 746 |
FGTestApi::setPositionAndStabilise(offTheWay); |
| 747 |
const double courseFromOff1 = SGGeodesy::courseDeg(offTheWay, gaktu->geod()); |
| 748 |
const double dist2 = SGGeodesy::distanceM(offTheWay, gaktu->geod()); |
| 749 |
|
| 750 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseFromOff1, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 751 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseNow, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 752 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(-18.6, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 753 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseFromOff1 - courseNow, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 754 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(dist2 * SG_METER_TO_NM, gpsNode->getDoubleValue("wp/wp[1]/distance-nm"), 0.01); |
| 755 |
|
| 756 |
const double expectedDefl1 = -18.6 / 25.0; |
| 757 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedDefl1 * 10.0, gpsNode->getDoubleValue("cdi-deflection"), 0.01); |
| 758 |
} |
| 759 |
|
| 760 |
void GPSTests::testOverflightSequencing() |
| 761 |
{ |
| 762 |
// check that we sequence as we pass over the top |
| 763 |
|
| 764 |
// FGTestApi::setUp::logPositionToKML("gps_sequence"); |
| 765 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 766 |
auto fp = FlightPlan::create(); |
| 767 |
rm->setFlightPlan(fp); |
| 768 |
|
| 769 |
// let's use New Zealand for some southern hemisphere confusion :) |
| 770 |
|
| 771 |
// this route has some deliberately sharp turns to work the turn code |
| 772 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "NZCH", "02", "NZAA", "05L", |
| 773 |
"ALADA NS WB WN MAMOD KAPTI OH"); |
| 774 |
|
| 775 |
// FGTestApi::writeFlightPlanToKML(fp); |
| 776 |
|
| 777 |
// takes the place of the Nasal delegates |
| 778 |
auto testDelegate = new TestFPDelegate; |
| 779 |
testDelegate->thePlan = fp; |
| 780 |
CPPUNIT_ASSERT(rm->activate()); |
| 781 |
fp->addDelegate(testDelegate); |
| 782 |
auto gps = setupStandardGPS(); |
| 783 |
|
| 784 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 785 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 786 |
gpsNode->setStringValue("command", "leg"); |
| 787 |
|
| 788 |
// very tight tolerance on the overflight. We need a little bit or the |
| 789 |
// test-piot gets confused right on top |
| 790 |
gpsNode->setDoubleValue("config/over-flight-distance-nm", 0.01); |
| 791 |
|
| 792 |
// enroute to NELSON VOR |
| 793 |
fp->setCurrentIndex(2); |
| 794 |
SGGeod pos = fp->pointAlongRoute(2, -5.0); |
| 795 |
FGTestApi::setPositionAndStabilise(pos); |
| 796 |
|
| 797 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 798 |
pilot->resetAtPosition(pos); |
| 799 |
pilot->setSpeedKts(300); // decent speed to make things tougher |
| 800 |
pilot->flyGPSCourse(gps); |
| 801 |
|
| 802 |
bool ok = FGTestApi::runForTimeWithCheck(180.0, [fp] () { |
| 803 |
if (fp->currentIndex() == 3) { |
| 804 |
return true; |
| 805 |
} |
| 806 |
return false; |
| 807 |
}); |
| 808 |
CPPUNIT_ASSERT(ok); |
| 809 |
|
| 810 |
// check we're on top of NELSON |
| 811 |
auto nelsonVOR = fp->legAtIndex(2)->waypoint()->source(); |
| 812 |
CPPUNIT_ASSERT_EQUAL(std::string{"NELSON VOR-DME"}, nelsonVOR->name()); |
| 813 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, SGGeodesy::distanceNm(globals->get_aircraft_position(), nelsonVOR->geod()), 0.1); |
| 814 |
|
| 815 |
FGTestApi::runForTime(120.0); |
| 816 |
// check we're on course to Woodburne |
| 817 |
|
| 818 |
auto woodbourneVOR = fp->legAtIndex(3)->waypoint()->source(); |
| 819 |
const double crsToWB = SGGeodesy::courseDeg(globals->get_aircraft_position(), woodbourneVOR->geod()); |
| 820 |
const double crsNSWB = SGGeodesy::courseDeg(nelsonVOR->geod(), woodbourneVOR->geod()); |
| 821 |
|
| 822 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToWB, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 823 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsNSWB, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 824 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 825 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 826 |
|
| 827 |
// point a bit before MAMOD |
| 828 |
SGGeod pos2 = fp->pointAlongRoute(5, -5.0); |
| 829 |
FGTestApi::setPositionAndStabilise(pos2); |
| 830 |
fp->setCurrentIndex(5); |
| 831 |
auto mamod = fp->legAtIndex(5)->waypoint()->source(); |
| 832 |
|
| 833 |
ok = FGTestApi::runForTimeWithCheck(180.0, [fp] () { |
| 834 |
if (fp->currentIndex() == 6) { |
| 835 |
return true; |
| 836 |
} |
| 837 |
return false; |
| 838 |
}); |
| 839 |
CPPUNIT_ASSERT(ok); |
| 840 |
|
| 841 |
// check we're on top of MAMOD |
| 842 |
CPPUNIT_ASSERT_EQUAL(std::string{"MAMOD"}, mamod->name()); |
| 843 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, SGGeodesy::distanceNm(globals->get_aircraft_position(), mamod->geod()), 0.1); |
| 844 |
|
| 845 |
FGTestApi::runForTime(180.0); |
| 846 |
// check we're on course to KAPTI |
| 847 |
|
| 848 |
auto kapti = fp->legAtIndex(6)->waypoint()->source(); |
| 849 |
const double crsKapti = SGGeodesy::courseDeg(globals->get_aircraft_position(), kapti->geod()); |
| 850 |
const double crsMamodKapti = SGGeodesy::courseDeg(mamod->geod(), kapti->geod()); |
| 851 |
|
| 852 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsKapti, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 853 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsMamodKapti, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 854 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 855 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 856 |
} |
| 857 |
|
| 858 |
void GPSTests::testOffcourseSequencing() |
| 859 |
{ |
| 860 |
// ensure that if we pass through the overflight arm cone, but not |
| 861 |
// over the waypoint direclty, we still sequence at the mid-point |
| 862 |
|
| 863 |
// FGTestApi::setUp::logPositionToKML("gps_sequence_off"); |
| 864 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 865 |
auto fp = FlightPlan::create(); |
| 866 |
rm->setFlightPlan(fp); |
| 867 |
|
| 868 |
|
| 869 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "NZCH", "02", "NZAA", "05L", |
| 870 |
"ALADA NS WB WN MAMOD KAPTI OH"); |
| 871 |
|
| 872 |
// FGTestApi::writeFlightPlanToKML(fp); |
| 873 |
|
| 874 |
// takes the place of the Nasal delegates |
| 875 |
auto testDelegate = new TestFPDelegate; |
| 876 |
testDelegate->thePlan = fp; |
| 877 |
CPPUNIT_ASSERT(rm->activate()); |
| 878 |
fp->addDelegate(testDelegate); |
| 879 |
auto gps = setupStandardGPS(); |
| 880 |
|
| 881 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 882 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 883 |
gpsNode->setStringValue("command", "leg"); |
| 884 |
gpsNode->setDoubleValue("config/over-flight-distance-nm", 0.01); |
| 885 |
|
| 886 |
// enroute to NELSON VOR |
| 887 |
fp->setCurrentIndex(2); |
| 888 |
SGGeod pos = fp->pointAlongRoute(2, -5.0); |
| 889 |
|
| 890 |
pos = SGGeodesy::direct(pos, 180, 1.5 * SG_NM_TO_METER); |
| 891 |
FGTestApi::setPositionAndStabilise(pos); |
| 892 |
|
| 893 |
|
| 894 |
auto nelsonVOR = fp->legAtIndex(2)->waypoint()->source(); |
| 895 |
CPPUNIT_ASSERT_EQUAL(std::string{"NELSON VOR-DME"}, nelsonVOR->name()); |
| 896 |
|
| 897 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 898 |
pilot->resetAtPosition(pos); |
| 899 |
pilot->setSpeedKts(300); // decent speed to make things tougher |
| 900 |
|
| 901 |
// since we're south of the route, but will fly parallel to it, we won't |
| 902 |
// pass over NELSON directly. |
| 903 |
|
| 904 |
const double legCourse = gpsNode->getDoubleValue("wp/leg-true-course-deg"); |
| 905 |
pilot->turnToCourse(legCourse); |
| 906 |
|
| 907 |
bool ok = FGTestApi::runForTimeWithCheck(180.0, [fp] () { |
| 908 |
if (fp->currentIndex() == 3) { |
| 909 |
return true; |
| 910 |
} |
| 911 |
return false; |
| 912 |
}); |
| 913 |
CPPUNIT_ASSERT(ok); |
| 914 |
|
| 915 |
// check we're close NELSON |
| 916 |
const double distToNELSON = SGGeodesy::distanceNm(globals->get_aircraft_position(), nelsonVOR->geod()); |
| 917 |
CPPUNIT_ASSERT(distToNELSON < 1.0); |
| 918 |
|
| 919 |
const double bearingToNELSON = SGGeodesy::courseDeg(globals->get_aircraft_position(), nelsonVOR->geod()); |
| 920 |
// find the inbound course from ALADA at NELSON |
| 921 |
double finalLegTrack = SGGeodesy::courseDeg(nelsonVOR->geod(), fp->legAtIndex(1)->waypoint()->position()) + 180.0; |
| 922 |
SG_NORMALIZE_RANGE(finalLegTrack, 0.0, 360.0); |
| 923 |
|
| 924 |
double dev = bearingToNELSON - finalLegTrack; |
| 925 |
SG_NORMALIZE_RANGE(dev, -180.0, 180.0); |
| 926 |
double absDeviation = fabs(dev); |
| 927 |
|
| 928 |
// 90 is the overflight arm angle, i.e we sequence as soon as the waypoint is abeam us |
| 929 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(90.0, absDeviation, 1.0); |
| 930 |
|
| 931 |
pilot->flyGPSCourse(gps); |
| 932 |
FGTestApi::runForTime(120.0); |
| 933 |
// check we're on course to Woodburne |
| 934 |
|
| 935 |
auto woodbourneVOR = fp->legAtIndex(3)->waypoint()->source(); |
| 936 |
const double crsToWB = SGGeodesy::courseDeg(globals->get_aircraft_position(), woodbourneVOR->geod()); |
| 937 |
const double crsNSWB = SGGeodesy::courseDeg(nelsonVOR->geod(), woodbourneVOR->geod()); |
| 938 |
|
| 939 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToWB, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 940 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsNSWB, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 941 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 942 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 943 |
|
| 944 |
|
| 945 |
// let's go wide at MAMOD |
| 946 |
SGGeod pos2 = fp->pointAlongRoute(5, -5.0); |
| 947 |
pos2 = SGGeodesy::direct(pos2, 180, 0.8 * SG_NM_TO_METER); |
| 948 |
|
| 949 |
fp->setCurrentIndex(5); |
| 950 |
FGTestApi::setPositionAndStabilise(pos2); |
| 951 |
// start facing the right way |
| 952 |
pilot->setCourseTrue(gpsNode->getDoubleValue("wp/leg-true-course-deg")); |
| 953 |
pilot->flyHeading(gpsNode->getDoubleValue("wp/leg-true-course-deg")); |
| 954 |
auto mamod = fp->legAtIndex(5)->waypoint()->source(); |
| 955 |
|
| 956 |
ok = FGTestApi::runForTimeWithCheck(180.0, [fp] () { |
| 957 |
if (fp->currentIndex() == 6) { |
| 958 |
return true; |
| 959 |
} |
| 960 |
return false; |
| 961 |
}); |
| 962 |
CPPUNIT_ASSERT(ok); |
| 963 |
|
| 964 |
// check we're on top of MAMOD |
| 965 |
CPPUNIT_ASSERT_EQUAL(std::string{"MAMOD"}, mamod->name()); |
| 966 |
const double distToMAMOD = SGGeodesy::distanceNm(globals->get_aircraft_position(), mamod->geod()); |
| 967 |
CPPUNIT_ASSERT(distToMAMOD < 1.0); |
| 968 |
|
| 969 |
// check the angle we sequenced at |
| 970 |
const double bearingToMAMOD = SGGeodesy::courseDeg(globals->get_aircraft_position(), mamod->geod()); |
| 971 |
// find the inbound course from WELLINGTON at MAMOD |
| 972 |
finalLegTrack = SGGeodesy::courseDeg(mamod->geod(), fp->legAtIndex(4)->waypoint()->position()) + 180.0; |
| 973 |
|
| 974 |
SG_NORMALIZE_RANGE(finalLegTrack, 0.0, 360.0); |
| 975 |
dev = bearingToMAMOD - finalLegTrack; |
| 976 |
SG_NORMALIZE_RANGE(dev, -180.0, 180.0); |
| 977 |
absDeviation = fabs(dev); |
| 978 |
|
| 979 |
// 90 is the overflight arm angle, i.e we sequence as soon as the waypoint is abeam us |
| 980 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(90.0, absDeviation, 1.0); |
| 981 |
|
| 982 |
|
| 983 |
// check we don't sequence, if we're too far off course |
| 984 |
|
| 985 |
SGGeod pos3 = fp->pointAlongRoute(6, -5.0); |
| 986 |
pos3 = SGGeodesy::direct(pos3, 90, 1.8 * SG_NM_TO_METER); |
| 987 |
|
| 988 |
fp->setCurrentIndex(6); |
| 989 |
FGTestApi::setPositionAndStabilise(pos3); |
| 990 |
// start facing the right way |
| 991 |
pilot->setCourseTrue(gpsNode->getDoubleValue("wp/leg-true-course-deg")); |
| 992 |
pilot->flyHeading(gpsNode->getDoubleValue("wp/leg-true-course-deg")); |
| 993 |
|
| 994 |
ok = FGTestApi::runForTimeWithCheck(180.0, [fp] () { |
| 995 |
if (fp->currentIndex() != 6) { |
| 996 |
CPPUNIT_ASSERT(false); |
| 997 |
return true; |
| 998 |
} |
| 999 |
return false; |
| 1000 |
}); |
| 1001 |
|
| 1002 |
|
| 1003 |
} |
| 1004 |
|
| 1005 |
void GPSTests::testOffsetFlight() |
| 1006 |
{ |
| 1007 |
// verify the XTK value during waypoint transitions, especially that we |
| 1008 |
// don't get any weird discontinuities |
| 1009 |
|
| 1010 |
// FGTestApi::setUp::logPositionToKML("gps_offset_flight"); |
| 1011 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 1012 |
auto fp = FlightPlan::create(); |
| 1013 |
rm->setFlightPlan(fp); |
| 1014 |
|
| 1015 |
|
| 1016 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "UHMA", "01", "PAMR", "25", |
| 1017 |
"SOMEG BE KIVAK BET"); |
| 1018 |
|
| 1019 |
// FGTestApi::writeFlightPlanToKML(fp); |
| 1020 |
|
| 1021 |
// takes the place of the Nasal delegates |
| 1022 |
auto testDelegate = new TestFPDelegate; |
| 1023 |
testDelegate->thePlan = fp; |
| 1024 |
CPPUNIT_ASSERT(rm->activate()); |
| 1025 |
fp->addDelegate(testDelegate); |
| 1026 |
auto gps = setupStandardGPS(); |
| 1027 |
|
| 1028 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 1029 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 1030 |
gpsNode->setStringValue("command", "leg"); |
| 1031 |
gpsNode->setDoubleValue("config/over-flight-distance-nm", 0.01); |
| 1032 |
|
| 1033 |
// enroute to BERINGOVSKY NDB |
| 1034 |
fp->setCurrentIndex(2); |
| 1035 |
|
| 1036 |
SGGeod pos = fp->pointAlongRoute(2, -10.0); |
| 1037 |
pos = SGGeodesy::direct(pos, 180, 2.0 * SG_NM_TO_METER); |
| 1038 |
FGTestApi::setPositionAndStabilise(pos); |
| 1039 |
|
| 1040 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 1041 |
pilot->resetAtPosition(pos); |
| 1042 |
pilot->setSpeedKts(300); // decent speed to make things tougher |
| 1043 |
|
| 1044 |
// start facing the right way |
| 1045 |
pilot->setCourseTrue(gpsNode->getDoubleValue("wp/leg-true-course-deg")); |
| 1046 |
pilot->flyGPSCourseOffset(gps, 0.8); |
| 1047 |
|
| 1048 |
FGTestApi::runForTime(90.0); |
| 1049 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 1050 |
|
| 1051 |
bool ok = FGTestApi::runForTimeWithCheck(180.0, [fp] () { |
| 1052 |
if (fp->currentIndex() == 3) { |
| 1053 |
return true; |
| 1054 |
} |
| 1055 |
return false; |
| 1056 |
}); |
| 1057 |
CPPUNIT_ASSERT(ok); |
| 1058 |
|
| 1059 |
FGTestApi::runForTime(120.0); |
| 1060 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 1061 |
|
| 1062 |
// fly until we cross the awkward line :) |
| 1063 |
ok = FGTestApi::runForTimeWithCheck(6000.0, [] () { |
| 1064 |
const double lon = globals->get_aircraft_position().getLongitudeDeg(); |
| 1065 |
if ((lon > -178.0) && (lon < -170.0)) { |
| 1066 |
return true; |
| 1067 |
} |
| 1068 |
return false; |
| 1069 |
}); |
| 1070 |
CPPUNIT_ASSERT(ok); |
| 1071 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 1072 |
|
| 1073 |
// and try an inside corrner |
| 1074 |
fp->setCurrentIndex(3); |
| 1075 |
pos = fp->pointAlongRoute(3, -18.0); |
| 1076 |
pos = SGGeodesy::direct(pos, 180, 2.0 * SG_NM_TO_METER); |
| 1077 |
FGTestApi::setPositionAndStabilise(pos); |
| 1078 |
pilot->resetAtPosition(pos); |
| 1079 |
// start facing the right way |
| 1080 |
pilot->setCourseTrue(gpsNode->getDoubleValue("wp/leg-true-course-deg")); |
| 1081 |
|
| 1082 |
FGTestApi::runForTime(120.0); |
| 1083 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 1084 |
|
| 1085 |
ok = FGTestApi::runForTimeWithCheck(180.0, [fp] () { |
| 1086 |
if (fp->currentIndex() == 4) { |
| 1087 |
return true; |
| 1088 |
} |
| 1089 |
return false; |
| 1090 |
}); |
| 1091 |
CPPUNIT_ASSERT(ok); |
| 1092 |
|
| 1093 |
FGTestApi::runForTime(120.0); |
| 1094 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.8, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 1095 |
|
| 1096 |
} |
| 1097 |
|
| 1098 |
void GPSTests::testLegIntercept() |
| 1099 |
{ |
| 1100 |
// FGTestApi::setUp::logPositionToKML("gps_intercept"); |
| 1101 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 1102 |
auto fp = FlightPlan::create(); |
| 1103 |
rm->setFlightPlan(fp); |
| 1104 |
|
| 1105 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "NZCH", "02", "NZAA", "05L", |
| 1106 |
"ALADA NS WB WN MAMOD KAPTI OH"); |
| 1107 |
|
| 1108 |
// auto dl = FGTestApi::DataLogger::instance(); |
| 1109 |
// dl->initTest("gps_leg_intercept"); |
| 1110 |
// dl->recordProperty("gps-error-nm", globals->get_props()->getNode("instrumentation/gps/wp/wp[1]/course-error-nm", true)); |
| 1111 |
// dl->recordProperty("gps-dev-deg", globals->get_props()->getNode("instrumentation/gps/wp/wp[1]/course-deviation-deg", true)); |
| 1112 |
// dl->recordProperty("hdg", globals->get_props()-> getNode("orientation/heading-deg", true)); |
| 1113 |
// dl->recordProperty("leg-track", globals->get_props()->getNode("instrumentation/gps/wp/leg-true-course-deg", true)); |
| 1114 |
|
| 1115 |
FGTestApi::writeFlightPlanToKML(fp); |
| 1116 |
|
| 1117 |
// takes the place of the Nasal delegates |
| 1118 |
auto testDelegate = new TestFPDelegate; |
| 1119 |
testDelegate->thePlan = fp; |
| 1120 |
CPPUNIT_ASSERT(rm->activate()); |
| 1121 |
fp->addDelegate(testDelegate); |
| 1122 |
auto gps = setupStandardGPS(); |
| 1123 |
|
| 1124 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 1125 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 1126 |
gpsNode->setBoolValue("config/enable-fly-by", true); |
| 1127 |
gpsNode->setStringValue("command", "leg"); |
| 1128 |
|
| 1129 |
|
| 1130 |
// enroute to NELSON VOR |
| 1131 |
fp->setCurrentIndex(2); |
| 1132 |
|
| 1133 |
|
| 1134 |
// point that should intercept |
| 1135 |
SGGeod pos = fp->pointAlongRoute(1, 5.0); |
| 1136 |
pos = SGGeodesy::direct(pos, 0, 12.0 * SG_NM_TO_METER); |
| 1137 |
|
| 1138 |
FGTestApi::setPositionAndStabilise(pos); |
| 1139 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 1140 |
pilot->resetAtPosition(pos); |
| 1141 |
pilot->setCourseTrue(180.0); // start facing an annoying direction |
| 1142 |
pilot->setSpeedKts(300); // decent speed to make things tougher |
| 1143 |
pilot->flyGPSCourse(gps); |
| 1144 |
|
| 1145 |
auto courseErrorNode = gpsNode->getNode("wp/wp[1]/course-error-nm"); |
| 1146 |
bool ok = FGTestApi::runForTimeWithCheck(600.0, [courseErrorNode]() { |
| 1147 |
return fabs(courseErrorNode->getDoubleValue()) < 0.1; |
| 1148 |
}); |
| 1149 |
CPPUNIT_ASSERT(ok); |
| 1150 |
CPPUNIT_ASSERT_EQUAL(2, fp->currentIndex()); // shouldn;t have sequenced |
| 1151 |
|
| 1152 |
// repeat this test from right of the leg, and much further out |
| 1153 |
pos = fp->pointAlongRoute(1, -5.0); |
| 1154 |
pos = SGGeodesy::direct(pos, 240, 10.0 * SG_NM_TO_METER); |
| 1155 |
|
| 1156 |
// cycle the GPS mode to re-do the intercept logic |
| 1157 |
FGTestApi::setPositionAndStabilise(pos); |
| 1158 |
gpsNode->setStringValue("command", "obs"); |
| 1159 |
gpsNode->setStringValue("command", "leg"); |
| 1160 |
|
| 1161 |
pilot->resetAtPosition(pos); |
| 1162 |
pilot->setCourseTrue(360.0); |
| 1163 |
pilot->setSpeedKts(300); |
| 1164 |
pilot->flyGPSCourse(gps); |
| 1165 |
|
| 1166 |
ok = FGTestApi::runForTimeWithCheck(600.0, [courseErrorNode]() { |
| 1167 |
return fabs(courseErrorNode->getDoubleValue()) < 0.1; |
| 1168 |
}); |
| 1169 |
CPPUNIT_ASSERT(ok); |
| 1170 |
|
| 1171 |
// repeat much closer to NELSON |
| 1172 |
pos = fp->pointAlongRoute(2, -10.0); |
| 1173 |
pos = SGGeodesy::direct(pos, 180, 5.0 * SG_NM_TO_METER); |
| 1174 |
|
| 1175 |
// cycle the GPS mode to re-do the intercept logic |
| 1176 |
FGTestApi::setPositionAndStabilise(pos); |
| 1177 |
gpsNode->setStringValue("command", "obs"); |
| 1178 |
gpsNode->setStringValue("command", "leg"); |
| 1179 |
|
| 1180 |
pilot->resetAtPosition(pos); |
| 1181 |
pilot->setCourseTrue(300.0); // awkward course |
| 1182 |
pilot->setSpeedKts(300); |
| 1183 |
pilot->flyGPSCourse(gps); |
| 1184 |
|
| 1185 |
ok = FGTestApi::runForTimeWithCheck(600.0, [courseErrorNode]() { |
| 1186 |
return fabs(courseErrorNode->getDoubleValue()) < 0.1; |
| 1187 |
}); |
| 1188 |
CPPUNIT_ASSERT(ok); |
| 1189 |
|
| 1190 |
// now try a start location well outside the 45-degree envelope |
| 1191 |
pos = fp->pointAlongRoute(2, -5.0); |
| 1192 |
pos = SGGeodesy::direct(pos, 160, 18.0 * SG_NM_TO_METER); |
| 1193 |
|
| 1194 |
// cycle the GPS mode to re-do the intercept logic |
| 1195 |
FGTestApi::setPositionAndStabilise(pos); |
| 1196 |
gpsNode->setStringValue("command", "obs"); |
| 1197 |
gpsNode->setStringValue("command", "leg"); |
| 1198 |
|
| 1199 |
pilot->resetAtPosition(pos); |
| 1200 |
pilot->setCourseTrue(45.0); // awkward course |
| 1201 |
pilot->setSpeedKts(300); |
| 1202 |
pilot->flyGPSCourse(gps); |
| 1203 |
|
| 1204 |
auto nelsonVORPos = fp->legAtIndex(2)->waypoint()->position(); |
| 1205 |
const double crsToNS = SGGeodesy::courseDeg(globals->get_aircraft_position(), nelsonVORPos); |
| 1206 |
const double crsFromStart = SGGeodesy::courseDeg(pos, nelsonVORPos); |
| 1207 |
|
| 1208 |
// we should be established on a direct to, from our start pos, let's check |
| 1209 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToNS, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 1210 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsFromStart, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 1211 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 1212 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 1213 |
|
| 1214 |
// run until we sequence, which should happen as normal |
| 1215 |
ok = FGTestApi::runForTimeWithCheck(6000.0, [fp] () { |
| 1216 |
if (fp->currentIndex() == 3) { |
| 1217 |
return true; |
| 1218 |
} |
| 1219 |
return false; |
| 1220 |
}); |
| 1221 |
CPPUNIT_ASSERT(ok); |
| 1222 |
|
| 1223 |
// check we manage the punishing turn back onto track |
| 1224 |
FGTestApi::runForTime(180.0); |
| 1225 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 1226 |
|
| 1227 |
// similar, but onthe other side, so closer aligned to the exit course at nelson. |
| 1228 |
// this should do a fly-by |
| 1229 |
|
| 1230 |
|
| 1231 |
pos = fp->pointAlongRoute(2, -4.0); |
| 1232 |
pos = SGGeodesy::direct(pos, 1, 10.0 * SG_NM_TO_METER); |
| 1233 |
fp->setCurrentIndex(2); |
| 1234 |
|
| 1235 |
// cycle the GPS mode to re-do the intercept logic |
| 1236 |
FGTestApi::setPositionAndStabilise(pos); |
| 1237 |
gpsNode->setStringValue("command", "obs"); |
| 1238 |
gpsNode->setStringValue("command", "leg"); |
| 1239 |
|
| 1240 |
pilot->resetAtPosition(pos); |
| 1241 |
pilot->setCourseTrue(320.0); // awkward course |
| 1242 |
pilot->setSpeedKts(300); |
| 1243 |
pilot->flyGPSCourse(gps); |
| 1244 |
|
| 1245 |
const double crsToNS2 = SGGeodesy::courseDeg(globals->get_aircraft_position(), nelsonVORPos); |
| 1246 |
const double crsFromStart2 = SGGeodesy::courseDeg(pos, nelsonVORPos); |
| 1247 |
|
| 1248 |
// we should be established on a direct to, from our start pos, let's check |
| 1249 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToNS2, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 1250 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsFromStart2, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 1251 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 1252 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 1253 |
|
| 1254 |
// run until we sequence, which should happen as normal |
| 1255 |
ok = FGTestApi::runForTimeWithCheck(6000.0, [fp] () { |
| 1256 |
if (fp->currentIndex() == 3) { |
| 1257 |
return true; |
| 1258 |
} |
| 1259 |
return false; |
| 1260 |
}); |
| 1261 |
CPPUNIT_ASSERT(ok); |
| 1262 |
|
| 1263 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 1264 |
// check we are on course the whole way through |
| 1265 |
FGTestApi::runForTime(10); |
| 1266 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.1); |
| 1267 |
} |
| 1268 |
|
| 1269 |
void GPSTests::testTurnAnticipation() |
| 1270 |
{ |
| 1271 |
//FGTestApi::setUp::logPositionToKML("gps_flyby_sequence"); |
| 1272 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 1273 |
auto fp = FlightPlan::create(); |
| 1274 |
rm->setFlightPlan(fp); |
| 1275 |
|
| 1276 |
// this route has some deliberately sharp turns to work the turn code |
| 1277 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "LEMG", "30", "EIDW", "28", |
| 1278 |
"BLN VTB TLD DELOG IDRIK ARE KOFAL STU VATRY"); |
| 1279 |
|
| 1280 |
// auto dl = FGTestApi::DataLogger::instance(); |
| 1281 |
// dl->initTest("gps_flyby_sequence"); |
| 1282 |
// dl->recordProperty("gps-error-nm", globals->get_props()->getNode("instrumentation/gps/wp/wp[1]/course-error-nm", true)); |
| 1283 |
// dl->recordProperty("gps-dev-deg", globals->get_props()->getNode("instrumentation/gps/wp/wp[1]/course-deviation-deg", true)); |
| 1284 |
// dl->recordProperty("hdg", globals->get_props()-> getNode("orientation/heading-deg", true)); |
| 1285 |
// dl->recordProperty("leg-track", globals->get_props()->getNode("instrumentation/gps/wp/leg-true-course-deg", true)); |
| 1286 |
|
| 1287 |
|
| 1288 |
FGTestApi::writeFlightPlanToKML(fp); |
| 1289 |
|
| 1290 |
// takes the place of the Nasal delegates |
| 1291 |
auto testDelegate = new TestFPDelegate; |
| 1292 |
testDelegate->thePlan = fp; |
| 1293 |
CPPUNIT_ASSERT(rm->activate()); |
| 1294 |
fp->addDelegate(testDelegate); |
| 1295 |
auto gps = setupStandardGPS(); |
| 1296 |
|
| 1297 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 1298 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 1299 |
gpsNode->setBoolValue("config/enable-fly-by", true); |
| 1300 |
gpsNode->setStringValue("command", "leg"); |
| 1301 |
|
| 1302 |
|
| 1303 |
// enroute to VILLATOBAS VOR |
| 1304 |
fp->setCurrentIndex(2); |
| 1305 |
SGGeod pos = fp->pointAlongRoute(2, -5.0); |
| 1306 |
FGTestApi::setPositionAndStabilise(pos); |
| 1307 |
|
| 1308 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 1309 |
pilot->resetAtPosition(pos); |
| 1310 |
pilot->setSpeedKts(300); // decent speed to make things tougher |
| 1311 |
pilot->flyGPSCourse(gps); |
| 1312 |
|
| 1313 |
bool ok = FGTestApi::runForTimeWithCheck(180.0, [fp] () { |
| 1314 |
if (fp->currentIndex() == 3) { |
| 1315 |
return true; |
| 1316 |
} |
| 1317 |
return false; |
| 1318 |
}); |
| 1319 |
CPPUNIT_ASSERT(ok); |
| 1320 |
|
| 1321 |
// check we sequenced at the half way point |
| 1322 |
auto vtbVOR = fp->legAtIndex(2)->waypoint()->source(); |
| 1323 |
CPPUNIT_ASSERT_EQUAL(std::string{"VILLATOBAS VOR-DME"}, vtbVOR->name()); |
| 1324 |
|
| 1325 |
const double courseToVTB = SGGeodesy::courseDeg(globals->get_aircraft_position(), vtbVOR->geod()); |
| 1326 |
// course should be half-way between the inbound and outbound leg courses, and then offset |
| 1327 |
// let's see |
| 1328 |
double ht = (fp->legAtIndex(3)->courseDeg() - fp->legAtIndex(2)->courseDeg()); |
| 1329 |
SG_NORMALIZE_RANGE(ht, -180.0, 180.0); |
| 1330 |
ht *= 0.5; |
| 1331 |
ht += fp->legAtIndex(2)->courseDeg(); |
| 1332 |
ht += 90; |
| 1333 |
SG_NORMALIZE_RANGE(ht, 0.0, 360.0); |
| 1334 |
|
| 1335 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(ht, courseToVTB, 5.0); |
| 1336 |
|
| 1337 |
FGTestApi::runForTime(30.0); |
| 1338 |
// check we're on course to TOLEDO |
| 1339 |
|
| 1340 |
auto toledoVOR = fp->legAtIndex(3)->waypoint()->source(); |
| 1341 |
// const double crsToWB = SGGeodesy::courseDeg(globals->get_aircraft_position(), woodbourneVOR->geod()); |
| 1342 |
// const double crsNSWB = SGGeodesy::courseDeg(nelsonVOR->geod(), woodbourneVOR->geod()); |
| 1343 |
|
| 1344 |
// CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToWB, gpsNode->getDoubleValue("wp/wp[1]/bearing-true-deg"), 0.5); |
| 1345 |
// CPPUNIT_ASSERT_DOUBLES_EQUAL(crsNSWB, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 0.5); |
| 1346 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 1347 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 1348 |
|
| 1349 |
// check a right-hand turn |
| 1350 |
pos = fp->pointAlongRoute(3, -5.0); |
| 1351 |
FGTestApi::setPositionAndStabilise(pos); |
| 1352 |
pilot->resetAtPosition(pos); |
| 1353 |
|
| 1354 |
ok = FGTestApi::runForTimeWithCheck(180.0, [fp] () { |
| 1355 |
if (fp->currentIndex() == 4) { |
| 1356 |
return true; |
| 1357 |
} |
| 1358 |
return false; |
| 1359 |
}); |
| 1360 |
CPPUNIT_ASSERT(ok); |
| 1361 |
|
| 1362 |
|
| 1363 |
const double courseToTLD = SGGeodesy::courseDeg(globals->get_aircraft_position(), toledoVOR->geod()); |
| 1364 |
// course should be half-way between the inbound and outbound leg courses, and then offset |
| 1365 |
// let's see |
| 1366 |
ht = (fp->legAtIndex(4)->courseDeg() - fp->legAtIndex(3)->courseDeg()); |
| 1367 |
SG_NORMALIZE_RANGE(ht, -180.0, 180.0); |
| 1368 |
ht *= 0.5; |
| 1369 |
ht += fp->legAtIndex(3)->courseDeg(); |
| 1370 |
ht -= 90; // right hand turn |
| 1371 |
SG_NORMALIZE_RANGE(ht, 0.0, 360.0); |
| 1372 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(courseToTLD, ht, 5.0); |
| 1373 |
|
| 1374 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 1375 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 1376 |
|
| 1377 |
FGTestApi::runForTime(30.0); |
| 1378 |
|
| 1379 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-error-nm"), 0.05); |
| 1380 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gpsNode->getDoubleValue("wp/wp[1]/course-deviation-deg"), 0.5); |
| 1381 |
|
| 1382 |
} |
| 1383 |
|
| 1384 |
void GPSTests::testExceedFlyByMaxAngleTurn() |
| 1385 |
{ |
| 1386 |
// FGTestApi::setUp::logPositionToKML("gps_fly_by_exceed_max_angle"); |
| 1387 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 1388 |
auto fp = FlightPlan::create(); |
| 1389 |
rm->setFlightPlan(fp); |
| 1390 |
|
| 1391 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "LFBD", "23", "EHAM", "18L", "SOMOS ROYAN TIRAV BOBRI ADABI"); |
| 1392 |
FGTestApi::writeFlightPlanToKML(fp); |
| 1393 |
|
| 1394 |
// takes the place of the Nasal delegates |
| 1395 |
auto testDelegate = new TestFPDelegate; |
| 1396 |
testDelegate->thePlan = fp; |
| 1397 |
CPPUNIT_ASSERT(rm->activate()); |
| 1398 |
fp->addDelegate(testDelegate); |
| 1399 |
auto gps = setupStandardGPS(); |
| 1400 |
|
| 1401 |
fp->setCurrentIndex(4); // BOBRI |
| 1402 |
|
| 1403 |
// somehwat before BOBRI |
| 1404 |
SGGeod initPos = fp->pointAlongRouteNorm(4, -0.1); |
| 1405 |
FGTestApi::setPositionAndStabilise(initPos); |
| 1406 |
FGTestApi::writePointToKML("init point", initPos); |
| 1407 |
|
| 1408 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 1409 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 1410 |
gpsNode->setDoubleValue("config/max-fly-by-turn-angle-deg", 75.0); |
| 1411 |
gpsNode->setStringValue("command", "leg"); |
| 1412 |
|
| 1413 |
FGPositioned::TypeFilter fixFilter(FGPositioned::FIX); |
| 1414 |
auto tiravFix = FGPositioned::findFirstWithIdent("TIRAV", &fixFilter); |
| 1415 |
auto bobriFix = FGPositioned::findFirstWithIdent("BOBRI", &fixFilter); |
| 1416 |
auto adabiFix = FGPositioned::findFirstWithIdent("ADABI", &fixFilter); |
| 1417 |
|
| 1418 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 1419 |
pilot->resetAtPosition(initPos); |
| 1420 |
pilot->setCourseTrue(fp->legAtIndex(4)->courseDeg()); |
| 1421 |
pilot->setSpeedKts(280); |
| 1422 |
pilot->flyGPSCourse(gps); |
| 1423 |
|
| 1424 |
bool ok = FGTestApi::runForTimeWithCheck(1200.0, [&fp]() { |
| 1425 |
return fp->currentIndex() == 5; |
| 1426 |
}); |
| 1427 |
CPPUNIT_ASSERT(ok); |
| 1428 |
// ensure we did a fly-over |
| 1429 |
CPPUNIT_ASSERT(!gps->previousLegData().value().didFlyBy); |
| 1430 |
FGTestApi::writePointToKML("seq point", globals->get_aircraft_position()); |
| 1431 |
|
| 1432 |
// ensure leg course is the one we want |
| 1433 |
const auto crs = SGGeodesy::courseDeg(bobriFix->geod(), adabiFix->geod()); |
| 1434 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crs, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 1.0); |
| 1435 |
|
| 1436 |
// ensure we fly the comepnsation turns, so that end up back on the next leg's course |
| 1437 |
// exactly |
| 1438 |
FGTestApi::runForTime(60.0); |
| 1439 |
|
| 1440 |
|
| 1441 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crs, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 1.0); |
| 1442 |
} |
| 1443 |
|
| 1444 |
void GPSTests::testRadialIntercept() |
| 1445 |
{ |
| 1446 |
// FGTestApi::setUp::logPositionToKML("gps_radial_intercept"); |
| 1447 |
|
| 1448 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 1449 |
auto fp = FlightPlan::create(); |
| 1450 |
rm->setFlightPlan(fp); |
| 1451 |
|
| 1452 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "LFKC", "36", "LIRF", "25", "BUNAX BEBEV AJO"); |
| 1453 |
|
| 1454 |
// set BUNAX as overflight |
| 1455 |
fp->legAtIndex(1)->waypoint()->setFlag(WPT_OVERFLIGHT); |
| 1456 |
|
| 1457 |
// insert KC502 manually |
| 1458 |
fp->insertWayptAtIndex(new BasicWaypt(SGGeod::fromDeg(8.78333, 42.566), "KC502", fp), 1); |
| 1459 |
|
| 1460 |
|
| 1461 |
SGGeod pos = SGGeod::fromDeg(8.445556,42.216944); |
| 1462 |
auto intc = new RadialIntercept(fp, "INTC", pos, 230, 5); |
| 1463 |
fp->insertWayptAtIndex(intc, 3); |
| 1464 |
|
| 1465 |
FGTestApi::writeFlightPlanToKML(fp); |
| 1466 |
|
| 1467 |
// position slightly before BUNAX |
| 1468 |
SGGeod initPos = fp->pointAlongRoute(2, -3.0); |
| 1469 |
|
| 1470 |
// takes the place of the Nasal delegates |
| 1471 |
auto testDelegate = new TestFPDelegate; |
| 1472 |
testDelegate->thePlan = fp; |
| 1473 |
CPPUNIT_ASSERT(rm->activate()); |
| 1474 |
fp->addDelegate(testDelegate); |
| 1475 |
auto gps = setupStandardGPS(); |
| 1476 |
|
| 1477 |
FGTestApi::setPositionAndStabilise(initPos); |
| 1478 |
|
| 1479 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 1480 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 1481 |
gpsNode->setBoolValue("config/enable-fly-by", false); |
| 1482 |
gpsNode->setStringValue("command", "leg"); |
| 1483 |
|
| 1484 |
fp->setCurrentIndex(2); |
| 1485 |
|
| 1486 |
CPPUNIT_ASSERT_EQUAL("BUNAX"s, gpsNode->getStringValue("wp/wp[1]/ID")); |
| 1487 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(312, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 1.0); |
| 1488 |
|
| 1489 |
|
| 1490 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 1491 |
pilot->resetAtPosition(initPos); |
| 1492 |
pilot->setCourseTrue(fp->legAtIndex(2)->courseDeg()); |
| 1493 |
pilot->setSpeedKts(300); // decent speed to make things tougher |
| 1494 |
pilot->flyGPSCourse(gps); |
| 1495 |
|
| 1496 |
bool ok = FGTestApi::runForTimeWithCheck(600.0, [fp]() { |
| 1497 |
return fp->currentIndex() == 4; |
| 1498 |
}); |
| 1499 |
CPPUNIT_ASSERT(ok); |
| 1500 |
|
| 1501 |
// flying to BEBEV now |
| 1502 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(185, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 1.0); |
| 1503 |
FGTestApi::runForTime(30.0); |
| 1504 |
|
| 1505 |
// repeat but with fly-by enabled |
| 1506 |
gpsNode->setBoolValue("config/enable-fly-by", true); |
| 1507 |
gpsNode->setStringValue("command", "obs"); |
| 1508 |
|
| 1509 |
FGTestApi::setPositionAndStabilise(initPos); |
| 1510 |
pilot->resetAtPosition(initPos); |
| 1511 |
fp->setCurrentIndex(2); |
| 1512 |
gpsNode->setStringValue("command", "leg"); |
| 1513 |
|
| 1514 |
CPPUNIT_ASSERT_EQUAL("BUNAX"s, gpsNode->getStringValue("wp/wp[1]/ID")); |
| 1515 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(312, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 1.0); |
| 1516 |
|
| 1517 |
|
| 1518 |
pilot->setCourseTrue(fp->legAtIndex(2)->courseDeg()); |
| 1519 |
pilot->flyGPSCourse(gps); |
| 1520 |
|
| 1521 |
ok = FGTestApi::runForTimeWithCheck(600.0, [fp]() { |
| 1522 |
return fp->currentIndex() == 4; |
| 1523 |
}); |
| 1524 |
CPPUNIT_ASSERT(ok); |
| 1525 |
|
| 1526 |
// flying to BEBEV now |
| 1527 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(185, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 1.0); |
| 1528 |
FGTestApi::runForTime(30.0); |
| 1529 |
} |
| 1530 |
|
| 1531 |
void GPSTests::testSWIFT8() |
| 1532 |
{ |
| 1533 |
FGTestApi::setUp::logPositionToKML("gps_swift8"); |
| 1534 |
|
| 1535 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 1536 |
auto fp = FlightPlan::create(); |
| 1537 |
rm->setFlightPlan(fp); |
| 1538 |
|
| 1539 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "YBCS", "15", "YBTL", "25", "SWIFT"); |
| 1540 |
|
| 1541 |
auto hdgToAlt_400 = new HeadingToAltitude(fp, "(400)", 150); |
| 1542 |
hdgToAlt_400->setAltitude(400, RESTRICT_AT); |
| 1543 |
fp->insertWayptAtIndex(hdgToAlt_400, 1); |
| 1544 |
|
| 1545 |
SGGeod pos = SGGeod::fromDeg(145.743889,-16.850028); |
| 1546 |
auto intc = new RadialIntercept(fp, "(INTC)", pos, 30, 80); |
| 1547 |
fp->insertWayptAtIndex(intc, 2); |
| 1548 |
|
| 1549 |
auto hdgToAlt_4000 = new HeadingToAltitude(fp, "(4000)", 80); |
| 1550 |
hdgToAlt_4000->setAltitude(4000, RESTRICT_AT); |
| 1551 |
fp->insertWayptAtIndex(hdgToAlt_4000, 3); |
| 1552 |
|
| 1553 |
FGTestApi::writeFlightPlanToKML(fp); |
| 1554 |
|
| 1555 |
// position slightly before INTC |
| 1556 |
SGGeod initPos = fp->pointAlongRoute(1, -1); |
| 1557 |
|
| 1558 |
// takes the place of the Nasal delegates |
| 1559 |
auto testDelegate = new TestFPDelegate; |
| 1560 |
testDelegate->thePlan = fp; |
| 1561 |
CPPUNIT_ASSERT(rm->activate()); |
| 1562 |
fp->addDelegate(testDelegate); |
| 1563 |
auto gps = setupStandardGPS(); |
| 1564 |
|
| 1565 |
FGTestApi::setPositionAndStabilise(initPos); |
| 1566 |
|
| 1567 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 1568 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 1569 |
gpsNode->setBoolValue("config/enable-fly-by", false); |
| 1570 |
gpsNode->setStringValue("command", "leg"); |
| 1571 |
|
| 1572 |
fp->setCurrentIndex(1); |
| 1573 |
|
| 1574 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 1575 |
pilot->resetAtPosition(initPos); |
| 1576 |
pilot->setCourseTrue(fp->legAtIndex(1)->courseDeg()); |
| 1577 |
pilot->setSpeedKts(200); |
| 1578 |
pilot->setTargetAltitudeFtMSL(6000); |
| 1579 |
pilot->flyGPSCourse(gps); |
| 1580 |
|
| 1581 |
bool ok = FGTestApi::runForTimeWithCheck(600.0, [fp]() { |
| 1582 |
return fp->currentIndex() == 4; |
| 1583 |
}); |
| 1584 |
CPPUNIT_ASSERT(ok); |
| 1585 |
|
| 1586 |
FGTestApi::runForTime(600.0); |
| 1587 |
|
| 1588 |
// Flying to SWIFT |
| 1589 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(149, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 1.0); |
| 1590 |
FGTestApi::runForTime(30.0); |
| 1591 |
} |
| 1592 |
|
| 1593 |
void GPSTests::testDMEIntercept() |
| 1594 |
{ |
| 1595 |
// FGTestApi::setUp::logPositionToKML("gps_dme_intercept"); |
| 1596 |
|
| 1597 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 1598 |
auto fp = FlightPlan::create(); |
| 1599 |
rm->setFlightPlan(fp); |
| 1600 |
|
| 1601 |
// manually consturct something close to the publichsed approach transition for EGPH ILS 06 |
| 1602 |
|
| 1603 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "EGLL", "27R", "EGPH", "06", "SHAPP TLA"); |
| 1604 |
|
| 1605 |
// DMEIntercept(RouteBase* aOwner, const std::string& aIdent, const SGGeod& aPos, |
| 1606 |
// double aCourseDeg, double aDistanceNm); |
| 1607 |
auto dmeArc = new DMEIntercept(fp, "TLA-11", SGGeod::fromDeg(-3.352833, 55.499145), 323.0, 11.0); |
| 1608 |
fp->insertWayptAtIndex(dmeArc, 3); |
| 1609 |
|
| 1610 |
// now a normal WP |
| 1611 |
fp->insertWayptAtIndex(new BasicWaypt(SGGeod::fromDeg(-3.636708, 55.689981), "D3230", fp), 4); |
| 1612 |
|
| 1613 |
auto dmeArc2 = new DMEIntercept(fp, "TLA-20", SGGeod::fromDeg(-3.352833, 55.499145), 323.0, 20.0); |
| 1614 |
fp->insertWayptAtIndex(dmeArc2, 5); |
| 1615 |
|
| 1616 |
// and another normal WP |
| 1617 |
fp->insertWayptAtIndex(new BasicWaypt(SGGeod::fromDeg(-3.751056, 55.766122), "D323U", fp), 6); |
| 1618 |
|
| 1619 |
// and another one |
| 1620 |
fp->insertWayptAtIndex(new BasicWaypt(SGGeod::fromDeg(-3.690845, 55.841378), "CI06", fp), 7); |
| 1621 |
|
| 1622 |
FGTestApi::writeFlightPlanToKML(fp); |
| 1623 |
|
| 1624 |
// position slightly before TLA |
| 1625 |
SGGeod initPos = fp->pointAlongRoute(2, -2.0); |
| 1626 |
|
| 1627 |
// takes the place of the Nasal delegates |
| 1628 |
auto testDelegate = new TestFPDelegate; |
| 1629 |
testDelegate->thePlan = fp; |
| 1630 |
CPPUNIT_ASSERT(rm->activate()); |
| 1631 |
fp->addDelegate(testDelegate); |
| 1632 |
auto gps = setupStandardGPS(); |
| 1633 |
|
| 1634 |
FGTestApi::setPositionAndStabilise(initPos); |
| 1635 |
|
| 1636 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 1637 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 1638 |
gpsNode->setBoolValue("config/enable-fly-by", true); |
| 1639 |
gpsNode->setStringValue("command", "leg"); |
| 1640 |
|
| 1641 |
fp->setCurrentIndex(2); |
| 1642 |
|
| 1643 |
CPPUNIT_ASSERT_EQUAL("TLA"s, gpsNode->getStringValue("wp/wp[1]/ID")); |
| 1644 |
// CPPUNIT_ASSERT_DOUBLES_EQUAL(312, gpsNode->getDoubleValue("wp/leg-true-course-deg"), 1.0); |
| 1645 |
|
| 1646 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 1647 |
pilot->resetAtPosition(initPos); |
| 1648 |
pilot->setCourseTrue(fp->legAtIndex(2)->courseDeg()); |
| 1649 |
pilot->setSpeedKts(220); |
| 1650 |
pilot->flyGPSCourse(gps); |
| 1651 |
|
| 1652 |
bool ok = FGTestApi::runForTimeWithCheck(1200.0, [fp]() { |
| 1653 |
return fp->currentIndex() == 8; |
| 1654 |
}); |
| 1655 |
CPPUNIT_ASSERT(ok); |
| 1656 |
|
| 1657 |
} |
| 1658 |
|
| 1659 |
void GPSTests::testFinalLegCourse() |
| 1660 |
{ |
| 1661 |
// FGTestApi::setUp::logPositionToKML("gps_final_course"); |
| 1662 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 1663 |
auto fp = FlightPlan::create(); |
| 1664 |
rm->setFlightPlan(fp); |
| 1665 |
|
| 1666 |
// we can't use the standard function as it puts a waypoint on |
| 1667 |
// the extended centerline |
| 1668 |
FGAirportRef depApt = FGAirport::getByIdent("EGAA"); |
| 1669 |
fp->setDeparture(depApt->getRunwayByIdent("07")); |
| 1670 |
|
| 1671 |
|
| 1672 |
FGAirportRef destApt = FGAirport::getByIdent("EGPF"); |
| 1673 |
fp->setDestination(destApt->getRunwayByIdent("23")); |
| 1674 |
|
| 1675 |
// since we don't have the Nasal route-manager delegate, insert the |
| 1676 |
// runway waypoints manually |
| 1677 |
auto depRwy = new RunwayWaypt(fp->departureRunway(), fp); |
| 1678 |
depRwy->setFlag(WPT_DEPARTURE); |
| 1679 |
fp->insertWayptAtIndex(depRwy, -1); |
| 1680 |
|
| 1681 |
fp->insertWayptAtIndex(fp->waypointFromString("LISBO"), -1); |
| 1682 |
|
| 1683 |
auto destRwy = fp->destinationRunway(); |
| 1684 |
fp->insertWayptAtIndex(new RunwayWaypt(destRwy, fp), -1); |
| 1685 |
|
| 1686 |
// takes the place of the Nasal delegates |
| 1687 |
auto testDelegate = new TestFPDelegate; |
| 1688 |
testDelegate->thePlan = fp; |
| 1689 |
CPPUNIT_ASSERT(rm->activate()); |
| 1690 |
fp->addDelegate(testDelegate); |
| 1691 |
setupStandardGPS(); |
| 1692 |
|
| 1693 |
fp->setCurrentIndex(2); |
| 1694 |
|
| 1695 |
// position halfway between EGAA and EGPF |
| 1696 |
SGGeod initPos = fp->pointAlongRoute(1, -30.5); |
| 1697 |
FGTestApi::setPositionAndStabilise(initPos); |
| 1698 |
|
| 1699 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 1700 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 1701 |
gpsNode->setStringValue("command", "leg"); |
| 1702 |
|
| 1703 |
|
| 1704 |
// FGTestApi::writeFlightPlanToKML(fp); |
| 1705 |
// check that the final leg course doesn't fall back to 233 deg |
| 1706 |
|
| 1707 |
// EXPECTED FAIL: at the moment, we don't do the right thing for this, yet |
| 1708 |
// CPPUNIT_ASSERT_DOUBLES_EQUAL(37, gpsNode->getDoubleValue("desired-course-deg"), 2.0); |
| 1709 |
} |
| 1710 |
|
| 1711 |
// Test to check the situation where you have two legs forming a straight line |
| 1712 |
// with the current waypoint being the third waypoint |
| 1713 |
void GPSTests::testCourseLegIntermediateWaypoint() |
| 1714 |
{ |
| 1715 |
// FGTestApi::setUp::logPositionToKML("gps_leg_course_intermediate"); |
| 1716 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 1717 |
auto fp = FlightPlan::create(); |
| 1718 |
rm->setFlightPlan(fp); |
| 1719 |
|
| 1720 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "EGAA", "25", "EGPH", "06", "LISBO BLACA"); |
| 1721 |
|
| 1722 |
// takes the place of the Nasal delegates |
| 1723 |
auto testDelegate = new TestFPDelegate; |
| 1724 |
testDelegate->thePlan = fp; |
| 1725 |
CPPUNIT_ASSERT(rm->activate()); |
| 1726 |
fp->addDelegate(testDelegate); |
| 1727 |
auto gps = setupStandardGPS(); |
| 1728 |
|
| 1729 |
SGGeod decelPos = fp->pointAlongRoute(2, -15.0); |
| 1730 |
fp->insertWayptAtIndex(new BasicWaypt(decelPos, "DECEL", fp), 2); |
| 1731 |
fp->setCurrentIndex(2); // DECEL |
| 1732 |
|
| 1733 |
SGGeod initPos = fp->pointAlongRouteNorm(1, 0.1); |
| 1734 |
FGTestApi::setPositionAndStabilise(initPos); |
| 1735 |
|
| 1736 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 1737 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 1738 |
gpsNode->setStringValue("command", "leg"); |
| 1739 |
|
| 1740 |
|
| 1741 |
// FGTestApi::writeFlightPlanToKML(fp); |
| 1742 |
// check that the leg course is correct |
| 1743 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(56.5, gpsNode->getDoubleValue("desired-course-deg"), 2.0); |
| 1744 |
|
| 1745 |
auto legToDecel = fp->legAtIndex(2); |
| 1746 |
auto legToBlaca = fp->legAtIndex(3); |
| 1747 |
|
| 1748 |
auto wpNode = gpsNode->getChild("wp", 0, true); |
| 1749 |
|
| 1750 |
FGPositioned::TypeFilter fixFilter(FGPositioned::FIX); |
| 1751 |
auto lisbo = FGPositioned::findClosestWithIdent("LISBO", fp->departureAirport()->geod(), &fixFilter); |
| 1752 |
auto blaca = FGPositioned::findClosestWithIdent("BLACA", fp->departureAirport()->geod(), &fixFilter); |
| 1753 |
|
| 1754 |
const double crsToDecel = SGGeodesy::courseDeg(lisbo->geod(), decelPos); |
| 1755 |
const double crsToBlaca = SGGeodesy::courseDeg(decelPos, blaca->geod()); |
| 1756 |
|
| 1757 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToDecel, legToDecel->courseDeg(), 1.0); |
| 1758 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToBlaca, legToBlaca->courseDeg(), 1.0); |
| 1759 |
|
| 1760 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToDecel, gpsNode->getDoubleValue("desired-course-deg"), 2.0); |
| 1761 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToDecel, wpNode->getDoubleValue("leg-true-course-deg"), 0.5); |
| 1762 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToDecel, wpNode->getDoubleValue("leg-mag-course-deg"), 0.5); |
| 1763 |
|
| 1764 |
fp->setCurrentIndex(3); // BLACA |
| 1765 |
|
| 1766 |
FGTestApi::runForTime(0.1); |
| 1767 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToBlaca, gpsNode->getDoubleValue("desired-course-deg"), 2.0); |
| 1768 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToBlaca, wpNode->getDoubleValue("leg-true-course-deg"), 0.5); |
| 1769 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(crsToBlaca, wpNode->getDoubleValue("leg-mag-course-deg"), 0.5); |
| 1770 |
|
| 1771 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 1772 |
pilot->resetAtPosition(initPos); |
| 1773 |
pilot->setCourseTrue(fp->legAtIndex(2)->courseDeg()); |
| 1774 |
pilot->setSpeedKts(280); |
| 1775 |
pilot->flyGPSCourse(gps); |
| 1776 |
|
| 1777 |
bool ok = FGTestApi::runForTimeWithCheck(1200.0, [&fp]() { |
| 1778 |
return fp->currentIndex() == 4; |
| 1779 |
}); |
| 1780 |
CPPUNIT_ASSERT(ok); |
| 1781 |
} |
| 1782 |
|
| 1783 |
// Test to check the situation where you have two legs forming a straight line |
| 1784 |
// with the current waypoint being the third waypoint |
| 1785 |
void GPSTests::testFlyOverMaxInterceptAngle() |
| 1786 |
{ |
| 1787 |
//FGTestApi::setUp::logPositionToKML("gps_fly_over_max_intercept_angle"); |
| 1788 |
auto rm = globals->get_subsystem<FGRouteMgr>(); |
| 1789 |
auto fp = FlightPlan::create(); |
| 1790 |
rm->setFlightPlan(fp); |
| 1791 |
|
| 1792 |
FGTestApi::setUp::populateFPWithoutNasal(fp, "EGAA", "25", "EGPH", "06", "LISBO BLACA"); |
| 1793 |
|
| 1794 |
// takes the place of the Nasal delegates |
| 1795 |
auto testDelegate = new TestFPDelegate; |
| 1796 |
testDelegate->thePlan = fp; |
| 1797 |
CPPUNIT_ASSERT(rm->activate()); |
| 1798 |
fp->addDelegate(testDelegate); |
| 1799 |
|
| 1800 |
FGTestApi::writeFlightPlanToKML(fp); |
| 1801 |
|
| 1802 |
SGGeod initPos = fp->pointAlongRouteNorm(1, -0.15); |
| 1803 |
FGTestApi::writePointToKML("Start pos", initPos); |
| 1804 |
|
| 1805 |
auto gps = setupStandardGPS(); |
| 1806 |
FGTestApi::setPositionAndStabilise(initPos); |
| 1807 |
|
| 1808 |
auto gpsNode = globals->get_props()->getNode("instrumentation/gps"); |
| 1809 |
gpsNode->setBoolValue("config/delegate-sequencing", true); |
| 1810 |
gpsNode->setStringValue("command", "leg"); |
| 1811 |
|
| 1812 |
auto gpsErrorNmNode = gpsNode->getNode("wp/wp[1]/course-error-nm"); |
| 1813 |
|
| 1814 |
fp->setCurrentIndex(1); // BLACA |
| 1815 |
|
| 1816 |
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot); |
| 1817 |
pilot->resetAtPosition(initPos); |
| 1818 |
pilot->setCourseTrue(fp->legAtIndex(1)->courseDeg()); |
| 1819 |
pilot->setSpeedKts(280); |
| 1820 |
pilot->flyGPSCourse(gps); |
| 1821 |
|
| 1822 |
bool ok = FGTestApi::runForTimeWithCheck(1200.0, [&fp]() { |
| 1823 |
return fp->currentIndex() == 2; |
| 1824 |
}); |
| 1825 |
CPPUNIT_ASSERT(ok); |
| 1826 |
|
| 1827 |
FGPositioned::TypeFilter fixFilter(FGPositioned::FIX); |
| 1828 |
auto lisbo = FGPositioned::findClosestWithIdent("LISBO", fp->departureAirport()->geod(), &fixFilter); |
| 1829 |
auto blaca = FGPositioned::findClosestWithIdent("BLACA", fp->departureAirport()->geod(), &fixFilter); |
| 1830 |
|
| 1831 |
const double crsToBlaca = SGGeodesy::courseDeg(lisbo->geod(), blaca->geod()); |
| 1832 |
|
| 1833 |
ok = FGTestApi::runForTimeWithCheck(1200.0, [pilot, crsToBlaca, gpsErrorNmNode]() |
| 1834 |
{ |
| 1835 |
const double heading = pilot->trueCourseDeg(); |
| 1836 |
if (heading < (crsToBlaca - 45.0)) { |
| 1837 |
CPPUNIT_FAIL("Turned too far on intercept"); |
| 1838 |
} |
| 1839 |
|
| 1840 |
// check if we're near the leg |
| 1841 |
if (fabs(gpsErrorNmNode->getDoubleValue()) > 0.05) { |
| 1842 |
return false; |
| 1843 |
} |
| 1844 |
|
| 1845 |
return pilot->isOnHeading(crsToBlaca); |
| 1846 |
}); |
| 1847 |
CPPUNIT_ASSERT(ok); |
| 1848 |
} |