# include <config.h>
#endif
-#include "AIFlightPlan.hxx"
#include <simgear/math/sg_geodesy.hxx>
+
+#include <Airports/simple.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.
+bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
+ bool firstFlight, FGAirport *dep,
double latitude,
double longitude,
double radius,
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) {
" of flight type " << fltType <<
" of airline " << airline <<
" at airport " << dep->getId());
+ return false;
char buffer[10];
snprintf (buffer, 10, "%d", gateId);
//FGTaxiNode *tn = dep->getDynamics()->getGroundNetwork()->findNode(node);
// 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;
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;
+ return true;
}
//cerr << "getting parking " << gateId;
// 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;
}
// 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 {
+ /*
+ 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, 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 );
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;
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;
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;
wpt->on_ground = true;
wpt->routeIndex = (*ts)->getIndex();
waypoints.push_back(wpt);
-
-
}
}
+ return true;
}
/*******************************************************************
* createPushBackFallBack
* 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,
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);
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;
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;
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;