From 6ee1d7411be71815ce22c49a0951322f2c81c099 Mon Sep 17 00:00:00 2001 From: Durk Talsma Date: Sat, 7 May 2011 10:03:27 +0200 Subject: [PATCH] Simple FlightPlan generation and execution for the user aircraft: This will allow ATC guided taxiing to the runway. --- src/AIModel/AIAircraft.cxx | 4 +- src/AIModel/AIAircraft.hxx | 3 +- src/AIModel/AIFlightPlanCreatePushBack.cxx | 61 +++++++++++++++++++++- src/ATC/atc_mgr.cxx | 47 ++++++++++++----- src/ATC/trafficcontrol.cxx | 5 +- src/Airports/groundnetwork.cxx | 2 +- src/Airports/groundnetwork.hxx | 1 + 7 files changed, 104 insertions(+), 19 deletions(-) diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index 811dbfe9a..7396074a1 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -997,8 +997,8 @@ void FGAIAircraft::updateHeading() { } } if (trafficRef) - cerr << trafficRef->getCallSign() << " Heading " - << hdg << ". Target " << tgt_heading << ". Diff " << fabs(sum - tgt_heading) << ". Speed " << speed << "Heading change rate : " << headingChangeRate << " bacnk sence " << bank_sense << endl; + //cerr << trafficRef->getCallSign() << " Heading " + // << hdg << ". Target " << tgt_heading << ". Diff " << fabs(sum - tgt_heading) << ". Speed " << speed << "Heading change rate : " << headingChangeRate << " bacnk sence " << bank_sense << endl; hdg += headingChangeRate * dt * sqrt(fabs(speed) / 15); headingError = headingDiff; } else { diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index e064acfc9..c1bbaa9f9 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -1,4 +1,3 @@ - // FGAIAircraft - AIBase derived class creates an AI aircraft // // Written by David Culp, started October 2003. @@ -97,6 +96,8 @@ public: std::string atGate(); void checkTcas(); + + FGATCController * getATCController() { return controller; }; protected: void Run(double dt); diff --git a/src/AIModel/AIFlightPlanCreatePushBack.cxx b/src/AIModel/AIFlightPlanCreatePushBack.cxx index 191423ff9..de2d83eeb 100644 --- a/src/AIModel/AIFlightPlanCreatePushBack.cxx +++ b/src/AIModel/AIFlightPlanCreatePushBack.cxx @@ -165,7 +165,66 @@ bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac, // cerr << "Waypoint Name: " << (*i)->name << endl; //} } else { + /* + string rwyClass = getRunwayClassFromTrafficType(fltType); + + // Only set this if it hasn't been set by ATC already. + if (activeRunway.empty()) { + //cerr << "Getting runway for " << ac->getTrafficRef()->getCallSign() << " at " << apt->getId() << endl; + double depHeading = ac->getTrafficRef()->getCourse(); + dep->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway, + depHeading); + } + rwy = dep->getRunwayByIdent(activeRunway); + SGGeod runwayTakeoff = rwy->pointOnCenterline(5.0); + + FGGroundNetwork *gn = dep->getDynamics()->getGroundNetwork(); + if (!gn->exists()) { + createDefaultTakeoffTaxi(ac, dep, rwy); + return true; + } + int runwayId = gn->findNearestNode(runwayTakeoff); + int node = 0; + // Find out which node to start from + FGParking *park = dep->getDynamics()->getParking(gateId); + if (park) { + node = park->getPushBackPoint(); + } + + if (node == -1) { + node = gateId; + } + // HAndle case where parking doens't have a node + if ((node == 0) && park) { + if (firstFlight) { + node = gateId; + } else { + node = gateId; + } + } + //delete taxiRoute; + //taxiRoute = new FGTaxiRoute; + FGTaxiRoute tr = gn->findShortestRoute(node, runwayId); + int route; + FGTaxiNode *tn; + waypoint *wpt; + int nr = 0; + cerr << "Creating taxiroute from gate: " << gateId << " at " << dep->getId() << endl; + while (tr.next(&node, &route) && (nr++ < 3)) { + char buffer[10]; + snprintf(buffer, 10, "%d", node); + tn = dep->getDynamics()->getGroundNetwork()->findNode(node); + wpt = createOnGround(ac, buffer, tn->getGeod(), dep->getElevation(), + vTaxiReduced); + wpt->routeIndex = route; + waypoints.push_back(wpt); + } + wpt->name = "PushBackPoint"; + lastNodeVisited = tn->getIndex(); + //FGTaxiNode *firstNode = findNode(gateId); + //FGTaxiNode *lastNode = findNode(runwayId); //cerr << "Creating direct forward departure route fragment" << endl; + */ double lat2 = 0.0, lon2 = 0.0, az2 = 0.0; waypoint *wpt; geo_direct_wgs_84 ( 0, lat, lon, heading, @@ -227,8 +286,6 @@ bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac, wpt->on_ground = true; wpt->routeIndex = (*ts)->getIndex(); waypoints.push_back(wpt); - - } } diff --git a/src/ATC/atc_mgr.cxx b/src/ATC/atc_mgr.cxx index 917d25cbb..0bdc5e5cd 100644 --- a/src/ATC/atc_mgr.cxx +++ b/src/ATC/atc_mgr.cxx @@ -170,13 +170,40 @@ void FGATCManager::addController(FGATCController *controller) { void FGATCManager::update ( double time ) { //cerr << "ATC update code is running at time: " << time << endl; + // Test code: let my virtual co-pilot handle ATC: + + + + FGAIFlightPlan *fp = ai_ac.GetFlightPlan(); + + /* test code : find out how the routing develops */ + int size = fp->getNrOfWayPoints(); + //cerr << "Setting pos" << pos << " "; + cerr << "setting intentions " ; + for (int i = 0; i < size; i++) { + int val = fp->getRouteIndex(i); + cerr << val << " "; + //if ((val) && (val != pos)) { + //intentions.push_back(val); + //cerr << "[done ] " << endl; + //} + } + cerr << "[done ] " << endl; + double longitude = fgGetDouble("/position/longitude-deg"); + double latitude = fgGetDouble("/position/latitude-deg"); + double heading = fgGetDouble("/orientation/heading-deg"); + double speed = fgGetDouble("/velocities/groundspeed-kt"); + double altitude = fgGetDouble("/position/altitude-ft"); + ai_ac.setLatitude(latitude); + ai_ac.setLongitude(longitude); + ai_ac.setAltitude(altitude); + ai_ac.setHeading(heading); + ai_ac.setSpeed(speed); + ai_ac.update(time); + controller = ai_ac.getATCController(); currentATCDialog->update(time); if (controller) { - double longitude = fgGetDouble("/position/longitude-deg"); - double latitude = fgGetDouble("/position/latitude-deg"); - double heading = fgGetDouble("/orientation/heading-deg"); - double speed = fgGetDouble("/velocities/groundspeed-kt"); - double altitude = fgGetDouble("/position/altitude-ft"); + //cerr << "Running FGATCManager::update()" << endl; controller->updateAircraftInformation(ai_ac.getID(), @@ -188,13 +215,9 @@ void FGATCManager::update ( double time ) { //string airport = fgGetString("/sim/presets/airport-id"); //FGAirport *apt = FGAirport::findByIdent(airport); // AT this stage we should update the flightplan, so that waypoint incrementing is conducted as well as leg loading. - ai_ac.setLatitude(latitude); - ai_ac.setLongitude(longitude); - ai_ac.setAltitude(altitude); - ai_ac.setHeading(heading); - ai_ac.setSpeed(speed); - ai_ac.update(time); - controller->render(); + + controller->render(); + //cerr << "Adding groundnetWork to the scenegraph::update" << endl; } //globals->get_scenery()->get_scene_graph()->addChild(node); diff --git a/src/ATC/trafficcontrol.cxx b/src/ATC/trafficcontrol.cxx index 43859b188..e15f9d3c9 100644 --- a/src/ATC/trafficcontrol.cxx +++ b/src/ATC/trafficcontrol.cxx @@ -1033,6 +1033,7 @@ void FGStartupController::signOff(int id) SG_LOG(SG_GENERAL, SG_ALERT, "AI error: Aircraft without traffic record is signing off from tower"); } else { + cerr << i->getAircraft()->getCallSign() << " signing off from startupcontroller" << endl; i = activeTraffic.erase(i); } } @@ -1182,6 +1183,7 @@ void FGStartupController::render() for (TrafficVectorIterator i = activeTraffic.begin(); i != activeTraffic.end(); i++) { // Handle start point int pos = i->getCurrentPosition(); + //cerr << "rendering for " << i->getAircraft()->getCallSign() << "pos = " << pos << endl; if (pos > 0) { FGTaxiSegment *segment = parent->getGroundNetwork()->findSegment(pos); SGGeod start(SGGeod::fromDeg((i->getLongitude()), (i->getLatitude()))); @@ -1232,6 +1234,7 @@ void FGStartupController::render() osg::Matrix obj_pos; int k = (*j); if (k > 0) { + //cerr << "rendering for " << i->getAircraft()->getCallSign() << "intention = " << k << endl; osg::MatrixTransform *obj_trans = new osg::MatrixTransform; obj_trans->setDataVariance(osg::Object::STATIC); FGTaxiSegment *segment = parent->getGroundNetwork()->findSegment(k); @@ -1261,7 +1264,7 @@ void FGStartupController::render() cerr << "BIG FAT WARNING: k is here : " << pos << endl; } } - dx += 0.1; + //dx += 0.1; } globals->get_scenery()->get_scene_graph()->addChild(group); } diff --git a/src/Airports/groundnetwork.cxx b/src/Airports/groundnetwork.cxx index 8554dcbaa..c6a07982f 100644 --- a/src/Airports/groundnetwork.cxx +++ b/src/Airports/groundnetwork.cxx @@ -1202,7 +1202,7 @@ void FGGroundNetwork::render() group->addChild( obj_trans ); } } - dx += 0.1; + //dx += 0.1; } globals->get_scenery()->get_scene_graph()->addChild(group); } \ No newline at end of file diff --git a/src/Airports/groundnetwork.hxx b/src/Airports/groundnetwork.hxx index 857fb0314..bc51fd857 100644 --- a/src/Airports/groundnetwork.hxx +++ b/src/Airports/groundnetwork.hxx @@ -181,6 +181,7 @@ public: routes = rts; distance = dist; currNode = nodes.begin(); + currRoute = routes.begin(); // depth = dpth; }; -- 2.39.5