From 45ac50d2b783ee44c91e3817fae4ca97d7ee981f Mon Sep 17 00:00:00 2001 From: portree_kid Date: Mon, 24 May 2021 16:50:37 +0200 Subject: [PATCH] Time moving --- src/AIModel/AIAircraft.cxx | 26 +- src/AIModel/AIFlightPlan.cxx | 3 +- src/ATC/atc_mgr.cxx | 2 +- src/Traffic/Schedule.cxx | 4 +- test_suite/test_data/AI/Traffic/H/HBR.xml | 435 ---------------------- test_suite/test_data/AI/Traffic/H/TST.xml | 272 +------------- test_suite/unit_tests/AI/test_traffic.cxx | 129 ++++--- 7 files changed, 116 insertions(+), 755 deletions(-) diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index e2e68782e..1f974c9fc 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -224,8 +224,9 @@ void FGAIAircraft::setPerformance(const std::string& acType, const std::string& void FGAIAircraft::AccelTo(double speed) { tgt_speed = speed; - if (!isStationary()) + if (!isStationary()) { _needsGroundElevation = true; + } } @@ -853,6 +854,7 @@ bool FGAIAircraft::leadPointReached(FGAIWaypoint* curr, FGAIWaypoint* next, int } if (fp->getPreviousWaypoint()->getSpeed() < tgt_speed) { + SG_LOG(SG_AI, SG_BULK, "Set speed of WP from " << fp->getPreviousWaypoint()->getSpeed() << " to " << tgt_speed); fp->getPreviousWaypoint()->setSpeed(tgt_speed); } } @@ -1236,6 +1238,14 @@ const string& FGAIAircraft::atGate() void FGAIAircraft::handleATCRequests(double dt) { + time_t startTime = this->getTrafficRef()->getDepartureTime(); + time_t now = globals->get_time_params()->get_cur_time(); + + if ((startTime-now)>0) { + SG_LOG(SG_AI, SG_BULK, this->getCallSign() + << " is scheduled to depart in " << startTime-now << " seconds."); + } + //TODO implement NullController for having no ATC to save the conditionals if (controller) { controller->updateAircraftInformation(getID(), @@ -1462,6 +1472,7 @@ void FGAIAircraft::dumpCSVHeader(std::ofstream& o) { o << "Index\t"; o << "Lat\t"; o << "Lon\t"; + o << "Callsign\t"; o << "heading change rate\t"; o << "headingErr\t"; o << "hdg\t"; @@ -1477,13 +1488,16 @@ void FGAIAircraft::dumpCSVHeader(std::ofstream& o) { o << "Bearing\t"; o << "headingChangeRate\t"; o << "headingError\t"; + o << "Name\t"; o << "WP Lat\t"; o << "WP Lon\t"; o << "Dist\t"; + o << "Departuretime\t"; o << "Time\t"; o << "Leg\t"; o << "Num WP\t"; + o << "Leaddistance\t"; o << endl; } @@ -1491,6 +1505,7 @@ void FGAIAircraft::dumpCSV(std::ofstream& o, int lineIndex) { o << lineIndex << "\t"; o << this->getGeodPos().getLatitudeDeg() << "\t"; o << this->getGeodPos().getLongitudeDeg() << "\t"; + o << this->getCallSign() << "\t"; o << headingChangeRate << "\t"; o << headingError << "\t"; o << hdg << "\t"; @@ -1504,23 +1519,26 @@ void FGAIAircraft::dumpCSV(std::ofstream& o, int lineIndex) { o << groundTargetSpeed << "\t"; o << round(this->getVerticalSpeedFPM()) << "\t"; o << this->getTrueHeadingDeg() << "\t"; - o << this->GetFlightPlan()->getBearing(this->getGeodPos(), this->GetFlightPlan()->getCurrentWaypoint()) << "\t"; + FGAIFlightPlan* fp = this->GetFlightPlan(); o << headingChangeRate << "\t"; o << headingError << "\t"; FGAIWaypoint* currentWP = this->GetFlightPlan()->getCurrentWaypoint(); if (currentWP) { + o << this->GetFlightPlan()->getBearing(this->getGeodPos(), this->GetFlightPlan()->getCurrentWaypoint()) << "\t"; o << currentWP->getName() << "\t"; o << this->GetFlightPlan()->getCurrentWaypoint()->getPos().getLatitudeDeg() << "\t"; o << this->GetFlightPlan()->getCurrentWaypoint()->getPos().getLongitudeDeg() << "\t"; o << SGGeodesy::distanceM(this->getGeodPos(), currentWP->getPos()) << "\t"; o << this->GetFlightPlan()->getStartTime() << "\t"; + o << globals->get_time_params()->get_cur_time() << "\t"; + o << this->GetFlightPlan()->getStartTime() - globals->get_time_params()->get_cur_time() << "\t"; } else { - o << "\t\t\t\t"; + o << "\t\t\t\t\t\t\t"; } - FGAIFlightPlan* fp = this->GetFlightPlan(); if (fp->isValidPlan()) { o << fp->getLeg() << "\t"; o << fp->getNrOfWayPoints() << "\t"; + o << fp->getLeadDistance() << "\t"; } else { o << "NotValid\t\t"; } diff --git a/src/AIModel/AIFlightPlan.cxx b/src/AIModel/AIFlightPlan.cxx index 726e5b9d5..625b818c8 100644 --- a/src/AIModel/AIFlightPlan.cxx +++ b/src/AIModel/AIFlightPlan.cxx @@ -435,6 +435,7 @@ void FGAIFlightPlan::setLeadDistance(double speed, double bearing, // At a turn rate of 30 degrees per second, it takes 12 seconds to do a full 360 degree turn // So, to get an estimate of the turn radius, calculate the cicumference of the circle // we travel on. Get the turn radius by dividing by PI (*2). + // FIXME Why when going backwards? No fabs if (speed < 0.5) { lead_distance = 0.5; return; @@ -535,7 +536,7 @@ void FGAIFlightPlan::pushBackWaypoint(FGAIWaypoint *wpt) size_t pos = wpt_iterator - waypoints.begin(); waypoints.push_back(wpt); wpt_iterator = waypoints.begin() + pos; - SG_LOG(SG_AI, SG_BULK, "Added WP : \t" << wpt->getName() << "\t" << wpt->getPos()); + SG_LOG(SG_AI, SG_BULK, "Added WP : \t" << wpt->getName() << "\t" << wpt->getPos() << "\t" << wpt->getSpeed()); } // Start flightplan over from the beginning diff --git a/src/ATC/atc_mgr.cxx b/src/ATC/atc_mgr.cxx index 9262073f5..9fded2024 100644 --- a/src/ATC/atc_mgr.cxx +++ b/src/ATC/atc_mgr.cxx @@ -300,7 +300,7 @@ update its state. update. On first update, delta time will be 0. */ void FGATCManager::update ( double time ) { - SG_LOG(SG_ATC, SG_BULK, "ATC update code is running at time: " << time); + // SG_LOG(SG_ATC, SG_BULK, "ATC update code is running at time: " << time); // Test code: let my virtual co-pilot handle ATC FGAIManager* aiManager = globals->get_subsystem(); diff --git a/src/Traffic/Schedule.cxx b/src/Traffic/Schedule.cxx index 846c8e0da..e12371c52 100644 --- a/src/Traffic/Schedule.cxx +++ b/src/Traffic/Schedule.cxx @@ -579,7 +579,7 @@ FGScheduledFlight* FGAISchedule::findAvailableFlight (const string ¤tDesti fltEnd = tmgr->getLastFlight(req); - SG_LOG (SG_AI, SG_BULK, "Finding available flight for " << req); + SG_LOG (SG_AI, SG_BULK, "Finding available flight for " << req << " at " << now); // For Now: // Traverse every registered flight if (fltBegin == fltEnd) { @@ -622,7 +622,7 @@ FGScheduledFlight* FGAISchedule::findAvailableFlight (const string ¤tDesti time_t departure = (*i)->getDepartureTime(); int groundTime = groundTimeFromRadius(); if (departure < (arrival+(groundTime))) { - SG_LOG (SG_AI, SG_BULK, "Not flight candidate : " << (*i)->getCallSign() << " Arrival : " << arrival << " Planned Departure " << departure << " < " << (arrival+groundTime) << " Diff : " << (arrival+groundTime-departure)); + SG_LOG (SG_AI, SG_BULK, "Not flight candidate : " << (*i)->getCallSign() << " Flight Arrival : " << arrival << " Planned Departure : " << departure << " < " << (arrival+groundTime) << " Diff between arrival + groundtime and departure : " << (arrival+groundTime-departure) << " Groundtime : " << groundTime); continue; } else { SG_LOG (SG_AI, SG_BULK, "Next flight candidate : " << (*i)->getCallSign() ); diff --git a/test_suite/test_data/AI/Traffic/H/HBR.xml b/test_suite/test_data/AI/Traffic/H/HBR.xml index e7da02521..59fd0bce0 100644 --- a/test_suite/test_data/AI/Traffic/H/HBR.xml +++ b/test_suite/test_data/AI/Traffic/H/HBR.xml @@ -59,439 +59,4 @@ WEEK - - Hebridean_1002 - HBR_BN_2 - VFR - - EGEO - - - 50 - - EGEY - - - WEEK - - - Hebridean_1003 - HBR_BN_2 - VFR - - EGEO - - - 50 - - EGEY - - - WEEK - - - Hebridean_1004 - HBR_BN_2 - VFR - - EGEO - - - 50 - - EGEY - - - WEEK - - - Hebridean_1005 - HBR_BN_2 - VFR - - EGEO - - - 50 - - EGEY - - - WEEK - - - Hebridean_1006 - HBR_BN_2 - VFR - - EGEO - - - 50 - - EGPI - - - WEEK - - - Hebridean_1007 - HBR_BN_2 - VFR - - EGEO - - - 50 - - EGPI - - - WEEK - - - Hebridean_1008 - HBR_BN_2 - VFR - - EGEO - - - 50 - - EGPI - - - WEEK - - - Hebridean_1009 - HBR_BN_2 - VFR - - EGEO - - - 50 - - EGPI - - - WEEK - - - Hebridean_1017 - HBR_BN_2 - VFR - - EGEO - - - 50 - - EGPU - - - WEEK - - - Hebridean_1018 - HBR_BN_2 - VFR - - EGEO - - - 50 - - EGPU - - - WEEK - - - Hebridean_1019 - HBR_BN_2 - VFR - - EGEO - - - 50 - - EGPU - - - WEEK - - - Hebridean_1020 - HBR_BN_2 - VFR - - EGEY - - - 50 - - EGPI - - - WEEK - - - Hebridean_1021 - HBR_BN_2 - VFR - - EGEY - - - 50 - - EGPI - - - WEEK - - - Hebridean_1022 - HBR_BN_2 - VFR - - EGEY - - - 50 - - EGEO - - - WEEK - - - Hebridean_1023 - HBR_BN_2 - VFR - - EGEY - - - 50 - - EGEO - - - WEEK - - - Hebridean_1024 - HBR_BN_2 - VFR - - EGEY - - - 50 - - EGEO - - - WEEK - - - Hebridean_1025 - HBR_BN_2 - VFR - - EGEY - - - 50 - - EGEO - - - WEEK - - - Hebridean_1026 - HBR_BN_2 - VFR - - EGEY - - - 50 - - EGEO - - - WEEK - - - Hebridean_1027 - HBR_BN_2 - VFR - - EGEY - - - 50 - - EGEO - - - WEEK - - - Hebridean_1036 - HBR_BN_2 - VFR - - EGPI - - - 50 - - EGEY - - - WEEK - - - Hebridean_1037 - HBR_BN_2 - VFR - - EGPI - - - 50 - - EGEY - - - WEEK - - - Hebridean_1038 - HBR_BN_2 - VFR - - EGPI - - - 50 - - EGEO - - - WEEK - - - Hebridean_1039 - HBR_BN_2 - VFR - - EGPI - - - 50 - - EGEO - - - WEEK - - - Hebridean_1040 - HBR_BN_2 - VFR - - EGPI - - - 50 - - EGEO - - - WEEK - - - Hebridean_1041 - HBR_BN_2 - VFR - - EGPI - - - 50 - - EGEO - - - WEEK - - - Hebridean_1044 - HBR_BN_2 - VFR - - EGPU - - - 50 - - EGEO - - - WEEK - - - Hebridean_1045 - HBR_BN_2 - VFR - - EGPU - - - 50 - - EGEO - - - WEEK - - - Hebridean_1046 - HBR_BN_2 - VFR - - EGPU - - - 50 - - EGEO - - - WEEK - - - Hebridean_1047 - HBR_BN_2 - VFR - - EGPU - - - 50 - - EGEO - - - WEEK - \ No newline at end of file diff --git a/test_suite/test_data/AI/Traffic/H/TST.xml b/test_suite/test_data/AI/Traffic/H/TST.xml index 6cb31c719..308da9b04 100644 --- a/test_suite/test_data/AI/Traffic/H/TST.xml +++ b/test_suite/test_data/AI/Traffic/H/TST.xml @@ -6,11 +6,10 @@ TST TST YSSY - TST_BN_2 + TST_BN_1 BN2 0 8 - ga turboprop_transport G-HEBO false @@ -24,294 +23,53 @@ BN2 0 8 - ga turboprop_transport - G-HEBS + G-HEBY false - Test_0001 - TST_BN_2 + Test_YBBN_0001 + TST_BN_1 VFR YBBN - - - 50 - - YSSY - - - 02Hr - - - Test_1001 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1001 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1002 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1002 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1003 - TST_BN_2 - VFR - - YSSY 50 - YBBN - + YSSY + - 02Hr + 01Hr - Test_1003 - TST_BN_2 + Test_YSSY_1001 + TST_BN_1 VFR YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1004 - TST_BN_2 - VFR - - YSSY - + 50 YBBN - 02Hr + 01Hr - Test_1004 + Test_YSSY_1002 TST_BN_2 VFR YSSY - + 50 YBBN - + - 02Hr - - - Test_1005 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1005 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1006 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1006 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1007 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1008 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1009 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1010 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1011 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr - - - Test_1012 - TST_BN_2 - VFR - - YSSY - - - 50 - - YBBN - - - 02Hr + 03Hr diff --git a/test_suite/unit_tests/AI/test_traffic.cxx b/test_suite/unit_tests/AI/test_traffic.cxx index 52e20e0c7..fe4a5a033 100644 --- a/test_suite/unit_tests/AI/test_traffic.cxx +++ b/test_suite/unit_tests/AI/test_traffic.cxx @@ -41,7 +41,9 @@ #include #include