]> git.mxchange.org Git - flightgear.git/commitdiff
Simple FlightPlan generation and execution for the user aircraft: This will allow...
authorDurk Talsma <durk@localhost.(none)>
Sat, 7 May 2011 08:03:27 +0000 (10:03 +0200)
committerDurk Talsma <durk@localhost.(none)>
Sat, 7 May 2011 08:03:27 +0000 (10:03 +0200)
src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx
src/AIModel/AIFlightPlanCreatePushBack.cxx
src/ATC/atc_mgr.cxx
src/ATC/trafficcontrol.cxx
src/Airports/groundnetwork.cxx
src/Airports/groundnetwork.hxx

index 811dbfe9a9ae30a6ce67f897b20d3235301443c5..7396074a173debb7af134c603a25587d46e498fb 100644 (file)
@@ -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 {
index e064acfc965bb61b1762e5ecf5cd765cae5f1ceb..c1bbaa9f9b1b3b4229d801e90a4f9217b1eb87b0 100644 (file)
@@ -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);
index 191423ff901b925d200323d11bf8c4f4b9e9f4ed..de2d83eeb3ce56a2e2260452c24af061c76b7e9a 100644 (file)
@@ -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);
-
-
         }
 
     }
index 917d25cbb4178632e0081ba3b0b2d3ab80c17cec..0bdc5e5cd5a65ac31a3ba14dfb2dcf321a4c55f0 100644 (file)
@@ -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);
index 43859b1883d8e7cbca7ef9b6a50c8cdd82dd44e1..e15f9d3c9e53e692f7919978e6824991da3dc0f7 100644 (file)
@@ -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);
 }
index 8554dcbaa7f1c7be0ecef508fdf3108666742410..c6a07982f4f9b26c2b1558c2fa29ab009e9d2252 100644 (file)
@@ -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
index 857fb0314cc8721122ed5b44111fe2ee758d7930..bc51fd85731560f71ca49eca76514b86889ce8e8 100644 (file)
@@ -181,6 +181,7 @@ public:
     routes = rts;
     distance = dist; 
     currNode = nodes.begin();
+    currRoute = routes.begin();
 //    depth = dpth;
   };