]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIFlightPlanCreatePushBack.cxx
Merge branch 'jmt/gps'
[flightgear.git] / src / AIModel / AIFlightPlanCreatePushBack.cxx
index e83e0dcbd85aa3dd2ebc12e7cb4cac5701d8e9b1..d97e30da22eea2b37eef3bc372cc1a72a0386c46 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
  **************************************************************************/
-#include "AIFlightPlan.hxx"
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <simgear/math/sg_geodesy.hxx>
 #include <Airports/runways.hxx>
+#include <Airports/dynamics.hxx>
 
 #include <Environment/environment_mgr.hxx>
 #include <Environment/environment.hxx>
 
+#include "AIFlightPlan.hxx"
+#include "AIAircraft.hxx"
+#include "performancedata.hxx"
+
 
-void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep, 
+// TODO: Use James Turner's createOnGround functions.
+void FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
+                                    bool firstFlight, FGAirport *dep, 
                                    double latitude,
                                    double longitude,
                                    double radius,
@@ -34,13 +45,21 @@ void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep,
                                    const string& airline)
 {
     double lat, lon, heading;
+    double vTaxi = ac->getPerformance()->vTaxi();
+    double vTaxiBackward = vTaxi * (-2.0/3.0);
+    double vTaxiReduced  = vTaxi * (2.0/3.0);
     FGTaxiRoute *pushBackRoute;
+    // Active runway can be conditionally set by ATC, so at the start of a new flight, this
+    // must be reset.
+    activeRunway.clear();
+
     if (!(dep->getDynamics()->getGroundNetwork()->exists())) {
        //cerr << "Push Back fallback" << endl;
-        createPushBackFallBack(firstFlight, dep, latitude, longitude,
+        createPushBackFallBack(ac, firstFlight, dep, latitude, longitude,
                                radius, fltType, aircraftType, airline);
     } else {
         if (firstFlight) {
+             
              if (!(dep->getDynamics()->getAvailableParking(&lat, &lon, 
                                                            &heading, &gateId, 
                                                            radius, fltType, 
@@ -61,7 +80,7 @@ void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep,
                     // Elevation is currently disregarded when on_ground is true
                     // because the AIModel obtains a periodic ground elevation estimate.
                    wpt->altitude  = dep->getElevation();
-                   wpt->speed = -10;
+                   wpt->speed = vTaxiBackward;
                    wpt->crossat   = -10000;
                    wpt->gear_down = true;
                    wpt->flaps_down= true;
@@ -70,12 +89,18 @@ void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep,
                    wpt->routeIndex = -1;
                    waypoints.push_back(wpt);
             }
+           //cerr << "Success : GateId = " << gateId << endl;
+           SG_LOG(SG_INPUT, SG_WARN, "Warning: Succesfully found a parking for a " << 
+                                              aircraftType <<
+                                              " of flight type " << fltType << 
+                                              " of airline     " << airline <<
+                                              " at airport     " << dep->getId());
         } else {
            //cerr << "Push Back follow-up Flight" << endl;
             dep->getDynamics()->getParking(gateId, &lat, &lon, &heading);
         }
         if (gateId < 0) {
-             createPushBackFallBack(firstFlight, dep, latitude, longitude,
+             createPushBackFallBack(ac, firstFlight, dep, latitude, longitude,
                                     radius, fltType, aircraftType, airline);
              return;
 
@@ -89,61 +114,21 @@ void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep,
        FGParking *parking = dep->getDynamics()->getParking(gateId);
         int pushBackNode = parking->getPushBackPoint();
 
-       // initialize the pushback route. Note that parts
-       // of this procedure should probably be done inside
-        // taxidraw. This code is likely to change once this
-        // this is fully implemented in taxidraw. Until that time,
-        // however, the full initialization procedure looks like this:
-        // 1) Build a list of all the nodes that are classified as 
-        //    pushBack hold points
-        // 2) For each hold point, use the dykstra algorithm to find a route
-        //    between the gate and the pushBack hold nodes, however use only
-        //    segments that are classified as "pushback" routes.
-        // 3) return the TaxiRoute class that is non empty. 
-        // 4) store refer this route in the parking object, for future use
-
-       if (pushBackNode < 0) {
-            //cerr << "Initializing PushBackRoute " << endl;
-            intVec pushBackNodes;
-           int nAINodes = dep->getDynamics()->getGroundNetwork()->getNrOfNodes();
-            int hits = 0;
-           parking->setPushBackPoint(0); // default in case no network was found.
 
-            // Collect all the nodes that are classified as having pushBack hold status
-            for (int i = 0; i < nAINodes; i++) {
-                if (dep->getDynamics()->getGroundNetwork()->findNode(i)->getHoldPointType() == 3) {
-                    pushBackNodes.push_back(i);
-                }
-           }
-
-            // For each node found in step 1, check if it can be reached
-            FGTaxiRoute route;
-            for (intVecIterator nodes = pushBackNodes.begin();
-                                 nodes != pushBackNodes.end();
-                                 nodes++) {
-               route = dep->getDynamics()->getGroundNetwork()->findShortestRoute(gateId, *nodes, false);
-                if (!(route.empty())) {
-                   //cerr << "Found Pushback route of size " << route.size() << endl;
-                    hits++;
-                    parking->setPushBackRoute(new FGTaxiRoute(route));
-                    parking->setPushBackPoint(*nodes);
-                   pushBackNode = *nodes;
-                }
-             }
-             if (hits == 0) {
-                 SG_LOG(SG_GENERAL, SG_INFO, "No pushback route found for gate " << gateId << " at " << dep->getId());
-             }
-             if (hits > 1) {
-                 SG_LOG(SG_GENERAL, SG_WARN, hits << " pushback routes found for gate " << gateId << " at " << dep->getId());
-             }
-        }
-        if (pushBackNode > 0) {
+        pushBackRoute = parking->getPushBackRoute();
+        if ((pushBackNode > 0) && (pushBackRoute == 0)) {
             int node, rte;
-            //cerr << "Found valid pusback node " << pushBackNode << "for gate " << gateId << endl;
+            FGTaxiRoute route;
+            //cerr << "Creating push-back for " << gateId << " (" << parking->getName() << ") using push-back point " << pushBackNode << endl;
+            route = dep->getDynamics()->getGroundNetwork()->findShortestRoute(gateId, pushBackNode, false);
+            parking->setPushBackRoute(new FGTaxiRoute(route));
+            
+
             pushBackRoute = parking->getPushBackRoute();
             int size = pushBackRoute->size();
             if (size < 2) {
                SG_LOG(SG_GENERAL, SG_WARN, "Push back route from gate " << gateId << " has only " << size << " nodes.");
+                SG_LOG(SG_GENERAL, SG_WARN, "Using  " << pushBackNode);
             }
             pushBackRoute->first();
             waypoint *wpt;
@@ -161,7 +146,7 @@ void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep,
                // Elevation is currently disregarded when on_ground is true
                // because the AIModel obtains a periodic ground elevation estimate.
                wpt->altitude  = dep->getElevation();
-               wpt->speed = -10;
+               wpt->speed = vTaxiBackward;
                wpt->crossat   = -10000;
                wpt->gear_down = true;
                wpt->flaps_down= true;
@@ -172,10 +157,13 @@ void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep,
              }
               // some special considerations for the last point:
               wpt->name = string("PushBackPoint");
-              wpt->speed = 15;
+              wpt->speed = vTaxi;
+              //for (wpt_vector_iterator i = waypoints.begin(); i != waypoints.end(); i++) {
+              //    cerr << "Waypoint Name: " << (*i)->name << endl;
+              //}
         } else {
            //cerr << "Creating direct forward departure route fragment" << endl;
-           double lat2, lon2, az2;
+           double lat2 = 0.0, lon2 = 0.0, az2 = 0.0;
            waypoint *wpt;
            geo_direct_wgs_84 ( 0, lat, lon, heading, 
                                2, &lat2, &lon2, &az2 );
@@ -184,7 +172,7 @@ void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep,
            wpt->latitude  = lat2;
            wpt->longitude = lon2;
            wpt->altitude  = dep->getElevation();
-           wpt->speed     = 10
+           wpt->speed     = vTaxiReduced
            wpt->crossat   = -10000;
            wpt->gear_down = true;
            wpt->flaps_down= true;
@@ -200,7 +188,7 @@ void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep,
            wpt->latitude  = lat2;
            wpt->longitude = lon2;
            wpt->altitude  = dep->getElevation();
-           wpt->speed     = 10
+           wpt->speed     = vTaxiReduced
            wpt->crossat   = -10000;
            wpt->gear_down = true;
            wpt->flaps_down= true;
@@ -228,7 +216,7 @@ void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep,
            wpt->latitude  = tn->getLatitude();
            wpt->longitude = tn->getLongitude();
            wpt->altitude  = dep->getElevation();
-           wpt->speed     = 10
+           wpt->speed     = vTaxiReduced
            wpt->crossat   = -10000;
            wpt->gear_down = true;
            wpt->flaps_down= true;
@@ -247,7 +235,7 @@ void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep,
  * This is the backup function for airports that don't have a 
  * network yet. 
  ******************************************************************/
-void FGAIFlightPlan::createPushBackFallBack(bool firstFlight, FGAirport *dep, 
+void FGAIFlightPlan::createPushBackFallBack(FGAIAircraft *ac, bool firstFlight, FGAirport *dep, 
                                    double latitude,
                                    double longitude,
                                    double radius,
@@ -258,9 +246,13 @@ void FGAIFlightPlan::createPushBackFallBack(bool firstFlight, FGAirport *dep,
   double heading;
   double lat;
   double lon;
-  double lat2;
-  double lon2;
-  double az2;
+  double lat2 = 0.0;
+  double lon2 = 0.0;
+  double az2 = 0.0;
+
+  double vTaxi = ac->getPerformance()->vTaxi();
+  double vTaxiBackward = vTaxi * (-2.0/3.0);
+  double vTaxiReduced  = vTaxi * (2.0/3.0);
 
 
 
@@ -274,7 +266,7 @@ void FGAIFlightPlan::createPushBackFallBack(bool firstFlight, FGAirport *dep,
   wpt->latitude  = lat;
   wpt->longitude = lon;
   wpt->altitude  = dep->getElevation();
-  wpt->speed     = -10
+  wpt->speed     = vTaxiBackward
   wpt->crossat   = -10000;
   wpt->gear_down = true;
   wpt->flaps_down= true;
@@ -291,7 +283,7 @@ void FGAIFlightPlan::createPushBackFallBack(bool firstFlight, FGAirport *dep,
   wpt->latitude  = lat2;
   wpt->longitude = lon2;
   wpt->altitude  = dep->getElevation();
-  wpt->speed     = -10
+  wpt->speed     = vTaxiBackward
   wpt->crossat   = -10000;
   wpt->gear_down = true;
   wpt->flaps_down= true;
@@ -307,7 +299,7 @@ void FGAIFlightPlan::createPushBackFallBack(bool firstFlight, FGAirport *dep,
   wpt->latitude  = lat2;
   wpt->longitude = lon2;
   wpt->altitude  = dep->getElevation();
-  wpt->speed     = 10
+  wpt->speed     = vTaxiReduced
   wpt->crossat   = -10000;
   wpt->gear_down = true;
   wpt->flaps_down= true;