*
*
**************************************************************************/
-#include <AIFlightPlan.hxx>
+#include "AIFlightPlan.hxx"
#include <simgear/math/sg_geodesy.hxx>
#include <Airports/runways.hxx>
// Check lat/lon values during initialization;
void FGAIFlightPlan::create(FGAirport *dep, FGAirport *arr, int legNr, double alt, double speed,
double latitude, double longitude, bool firstFlight,
- double radius, string fltType, string aircraftType, string airline)
+ double radius, const string& fltType, const string& aircraftType, const string& airline)
{
int currWpt = wpt_iterator - waypoints.begin();
switch(legNr)
break;
case 2:
//cerr << "Creating Taxi" << endl;
- createTaxi(firstFlight, 1, dep, radius, fltType, aircraftType, airline);
+ createTaxi(firstFlight, 1, dep, latitude, longitude, radius, fltType, aircraftType, airline);
break;
case 3:
//cerr << "Creating TAkeoff" << endl;
break;
case 8:
//cerr << "Creating Taxi 2" << endl;
- createTaxi(false, 2, arr, radius, fltType, aircraftType, airline);
+ createTaxi(false, 2, arr, latitude, longitude, radius, fltType, aircraftType, airline);
break;
case 9:
//cerr << "Creating Parking" << endl;
double latitude,
double longitude,
double radius,
- string fltType,
- string aircraftType,
- string airline)
+ const string& fltType,
+ const string& aircraftType,
+ const string& airline)
{
double heading;
double lat;
wpt->on_ground = true;
waypoints.push_back(wpt);
geo_direct_wgs_84 ( 0, lat, lon, heading,
- 100,
+ radius, // push back one entire aircraft radius
&lat2, &lon2, &az2 );
wpt = new waypoint;
wpt->name = "taxiStart";
wpt->on_ground = true;
waypoints.push_back(wpt);
- //wpt = new waypoint;
- //wpt->name = "END";
- //wpt->finished = false;
- //waypoints.push_back(wpt); // add one more to prevent a segfault.
- //waypoints.push_back(wpt); // add one more to prevent a segfault.
- //wpt_iterator = waypoints.begin();
- //if (!firstFlight)
- // wpt_iterator++;
- //wpt_iterator = waypoints.begin()+currWpt;
+
}
/*******************************************************************
* createCreate Taxi.
* initialize the Aircraft at the parking location
******************************************************************/
-void FGAIFlightPlan::createTaxi(bool firstFlight, int direction, FGAirport *apt, double radius, string fltType, string acType, string airline)
+void FGAIFlightPlan::createTaxi(bool firstFlight, int direction, FGAirport *apt, double latitude, double longitude, double radius, const string& fltType, const string& acType, const string& airline)
{
double wind_speed;
double wind_heading;
//int currWpt = wpt_iterator - waypoints.begin();
if (direction == 1)
{
-
-
-
-
- // Get the current active runway, based on code from David Luff
- // This should actually be unified and extended to include
- // Preferential runway use schema's
- //FGEnvironment
- //stationweather = ((FGEnvironmentMgr *) globals->get_subsystem("environment"))
- //->getEnvironment(apt->getLatitude(), apt->getLongitude(), apt->getElevation());
-
- //wind_speed = stationweather.get_wind_speed_kt();
- //wind_heading = stationweather.get_wind_from_heading_deg();
- //if (wind_speed == 0) {
- //wind_heading = 270; // This forces West-facing rwys to be used in no-wind situations
- // which is consistent with Flightgear's initial setup.
- //}
-
- //string rwy_no = globals->get_runways()->search(apt->getId(), int(wind_heading));
- string name;
- apt->getActiveRunway("com", 1, &name);
+ //string name;
+ // "NOTE: this is currently fixed to "com" for commercial traffic
+ // Should be changed to be used dynamically to allow "gen" and "mil"
+ // as well
+ apt->getActiveRunway("com", 1, activeRunway);
if (!(globals->get_runways()->search(apt->getId(),
- name,
+ activeRunway,
&rwy)))
{
cout << "Failed to find runway for " << apt->getId() << endl;
exit(1);
}
//string test;
- //apt->getActiveRunway(string("com"), 1, &test);
+ //apt->getActiveRunway(string("com"), 1, test);
//exit(1);
heading = rwy._heading;
geo_direct_wgs_84 ( 0, rwy._lat, rwy._lon, azimuth,
rwy._length * SG_FEET_TO_METER * 0.5 - 5.0,
&lat2, &lon2, &az2 );
-
- //Add the runway startpoint;
- wpt = new waypoint;
- wpt->name = "Airport Center";
- wpt->latitude = apt->getLatitude();
- wpt->longitude = apt->getLongitude();
- wpt->altitude = apt->getElevation();
- wpt->speed = 15;
- wpt->crossat = -10000;
- wpt->gear_down = true;
- wpt->flaps_down= true;
- wpt->finished = false;
- wpt->on_ground = true;
- waypoints.push_back(wpt);
-
- //Add the runway startpoint;
- wpt = new waypoint;
- wpt->name = "Runway Takeoff";
- wpt->latitude = lat2;
- wpt->longitude = lon2;
- wpt->altitude = apt->getElevation();
- wpt->speed = 15;
- wpt->crossat = -10000;
- wpt->gear_down = true;
- wpt->flaps_down= true;
- wpt->finished = false;
- wpt->on_ground = true;
- waypoints.push_back(wpt);
- //wpt = new waypoint;
- //wpt->finished = false;
- //waypoints.push_back(wpt); // add one more to prevent a segfault.
+ if (apt->getGroundNetwork()->exists())
+ {
+ intVec ids;
+ int runwayId = apt->getGroundNetwork()->findNearestNode(lat2, lon2);
+ //int currId = apt->getGroundNetwork()->findNearestNode(latitude,longitude);
+ //exit(1);
+
+ // A negative gateId indicates an overflow parking, use a
+ // fallback mechanism for this.
+ // Starting from gate 0 is a bit of a hack...
+ FGTaxiRoute route;
+ if (gateId >= 0)
+ route = apt->getGroundNetwork()->findShortestRoute(gateId, runwayId);
+ else
+ route = apt->getGroundNetwork()->findShortestRoute(0, runwayId);
+ intVecIterator i;
+ //cerr << "creating route : ";
+ // No route found: go from gate directly to runway
+ if (route.empty()) {
+ //Add the runway startpoint;
+ wpt = new waypoint;
+ wpt->name = "Airport Center";
+ wpt->latitude = latitude;
+ wpt->longitude = longitude;
+ wpt->altitude = apt->getElevation();
+ wpt->speed = 15;
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ waypoints.push_back(wpt);
+
+ //Add the runway startpoint;
+ wpt = new waypoint;
+ wpt->name = "Runway Takeoff";
+ wpt->latitude = lat2;
+ wpt->longitude = lon2;
+ wpt->altitude = apt->getElevation();
+ wpt->speed = 15;
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ waypoints.push_back(wpt);
+ } else {
+ int node;
+ route.first();
+ while(route.next(&node))
+ {
+ //i = ids.end()-1;
+ //cerr << "Creating Node: " << node << endl;
+ FGTaxiNode *tn = apt->getGroundNetwork()->findNode(node);
+ //ids.pop_back();
+ wpt = new waypoint;
+ wpt->name = "taxiway"; // fixme: should be the name of the taxiway
+ wpt->latitude = tn->getLatitude();
+ wpt->longitude = tn->getLongitude();
+ wpt->altitude = apt->getElevation(); // should maybe be tn->elev too
+ wpt->speed = 15;
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ waypoints.push_back(wpt);
+ }
+ cerr << endl;
+ }
+ //exit(1);
+ }
+ else
+ {
+ //Add the runway startpoint;
+ wpt = new waypoint;
+ wpt->name = "Airport Center";
+ wpt->latitude = apt->getLatitude();
+ wpt->longitude = apt->getLongitude();
+ wpt->altitude = apt->getElevation();
+ wpt->speed = 15;
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ waypoints.push_back(wpt);
+
+ //Add the runway startpoint;
+ wpt = new waypoint;
+ wpt->name = "Runway Takeoff";
+ wpt->latitude = lat2;
+ wpt->longitude = lon2;
+ wpt->altitude = apt->getElevation();
+ wpt->speed = 15;
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ waypoints.push_back(wpt);
+ //wpt = new waypoint;
+ //wpt->finished = false;
+ //waypoints.push_back(wpt); // add one more to prevent a segfault.
+ }
}
- else
+ else // Landing taxi
{
- //direction = (rand() % 360);
- //geo_direct_wgs_84 ( 0, arr->getLatitude(), arr->getLongitude(), direction,
- //100,
- //&lat2, &lon2, &az2 );
+ //string name;
+ // "NOTE: this is currently fixed to "com" for commercial traffic
+ // Should be changed to be used dynamically to allow "gen" and "mil"
+ // as well
+ //apt->getActiveRunway("com", 1, name);
+ //if (!(globals->get_runways()->search(apt->getId(),
+ // name,
+ // &rwy)))
+ //{//
+ //cout << "Failed to find runway for " << apt->getId() << endl;
+ // Hmm, how do we handle a potential error like this?
+ // exit(1);
+ // }
+ //string test;
+ //apt->getActiveRunway(string("com"), 1, test);
+ //exit(1);
- // This next statement really requires the flight plan to be
- // split up into smaller sections, because
- // gate assignments will typically not be known until minutes before
- // landing, and certainly not at the start of a 10 hour flight.
+ //heading = rwy._heading;
+ //double azimuth = heading + 180.0;
+ //while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
+ //geo_direct_wgs_84 ( 0, rwy._lat, rwy._lon, azimuth,
+ // rwy._length * SG_FEET_TO_METER * 0.5 - 5.0,
+ // &lat2, &lon2, &az2 );
apt->getAvailableParking(&lat, &lon, &heading, &gateId, radius, fltType, acType, airline);
heading += 180.0;
if (heading > 360)
geo_direct_wgs_84 ( 0, lat, lon, heading,
100,
&lat2, &lon2, &az2 );
- //Add the runway center
- wpt = new waypoint;
- wpt->name = "Airport Center";
- wpt->latitude = apt->getLatitude();
- wpt->longitude = apt->getLongitude();
- wpt->altitude = apt->getElevation();
- wpt->speed = 15;
- wpt->crossat = -10000;
- wpt->gear_down = true;
- wpt->flaps_down= true;
- wpt->finished = false;
- wpt->on_ground = true;
- waypoints.push_back(wpt);
+ double lat3 = (*(waypoints.end()-1))->latitude;
+ double lon3 = (*(waypoints.end()-1))->longitude;
+ cerr << (*(waypoints.end()-1))->name << endl;
+ if (apt->getGroundNetwork()->exists())
+ {
+ intVec ids;
+ int runwayId = apt->getGroundNetwork()->findNearestNode(lat3, lon3);
+ //int currId = apt->getGroundNetwork()->findNearestNode(latitude,longitude);
+ //exit(1);
+
+ // A negative gateId indicates an overflow parking, use a
+ // fallback mechanism for this.
+ // Starting from gate 0 is a bit of a hack...
+ FGTaxiRoute route;
+ if (gateId >= 0)
+ route = apt->getGroundNetwork()->findShortestRoute(runwayId, gateId);
+ else
+ route = apt->getGroundNetwork()->findShortestRoute(runwayId, 0);
+ intVecIterator i;
+ //cerr << "creating route : ";
+ // No route found: go from gate directly to runway
+ if (route.empty()) {
+ //Add the runway startpoint;
+ wpt = new waypoint;
+ wpt->name = "Airport Center";
+ wpt->latitude = latitude;
+ wpt->longitude = longitude;
+ wpt->altitude = apt->getElevation();
+ wpt->speed = 15;
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ waypoints.push_back(wpt);
+
+ //Add the runway startpoint;
+ wpt = new waypoint;
+ wpt->name = "Runway Takeoff";
+ wpt->latitude = lat2;
+ wpt->longitude = lon2;
+ wpt->altitude = apt->getElevation();
+ wpt->speed = 15;
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ waypoints.push_back(wpt);
+ } else {
+ int node;
+ route.first();
+ while(route.next(&node))
+ {
+ //i = ids.end()-1;
+ //cerr << "Creating Node: " << node << endl;
+ FGTaxiNode *tn = apt->getGroundNetwork()->findNode(node);
+ //ids.pop_back();
+ wpt = new waypoint;
+ wpt->name = "taxiway"; // fixme: should be the name of the taxiway
+ wpt->latitude = tn->getLatitude();
+ wpt->longitude = tn->getLongitude();
+ wpt->altitude = apt->getElevation(); // should maybe be tn->elev too
+ wpt->speed = 15;
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ waypoints.push_back(wpt);
+ }
+ cerr << endl;
+ }
+ //exit(1);
+ }
+ else
+ {
+ //Add the runway startpoint;
+ wpt = new waypoint;
+ wpt->name = "Airport Center";
+ wpt->latitude = apt->getLatitude();
+ wpt->longitude = apt->getLongitude();
+ wpt->altitude = apt->getElevation();
+ wpt->speed = 15;
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ waypoints.push_back(wpt);
+
+ }
+
+
+
// Add the final destination waypoint
wpt = new waypoint;
- wpt->name = "Begin Parkingg"; //apt->getId(); //wpt_node->getStringValue("name", "END");
+ wpt->name = "Begin Parking"; //apt->getId(); //wpt_node->getStringValue("name", "END");
wpt->latitude = lat2;
wpt->longitude = lon2;
wpt->altitude = apt->getElevation();
// Preferential runway use schema's
if (firstFlight)
{
- string name;
- apt->getActiveRunway("com", 1, &name);
+ //string name;
+ // "NOTE: this is currently fixed to "com" for commercial traffic
+ // Should be changed to be used dynamically to allow "gen" and "mil"
+ // as well
+ apt->getActiveRunway("com", 1, activeRunway);
if (!(globals->get_runways()->search(apt->getId(),
- name,
+ activeRunway,
&rwy)))
{
cout << "Failed to find runway for " << apt->getId() << endl;
exit(1);
}
//string test;
- //apt->getActiveRunway(string("com"), 1, &test);
+ //apt->getActiveRunway(string("com"), 1, test);
//exit(1);
}
// Preferential runway use schema's
if (firstFlight)
{
- string name;
- apt->getActiveRunway("com", 1, &name);
+ //string name;
+ // "NOTE: this is currently fixed to "com" for commercial traffic
+ // Should be changed to be used dynamically to allow "gen" and "mil"
+ // as well
+ apt->getActiveRunway("com", 1, activeRunway);
if (!(globals->get_runways()->search(apt->getId(),
- name,
+ activeRunway,
&rwy)))
{
cout << "Failed to find runway for " << apt->getId() << endl;
exit(1);
}
//string test;
- //apt->getActiveRunway(string("com"), 1, &test);
+ //apt->getActiveRunway(string("com"), 1, test);
//exit(1);
}
waypoints.push_back(wpt);
//Beginning of Decent
- string name;
- arr->getActiveRunway("com", 2, &name);
+ //string name;
+ // should be changed dynamically to allow "gen" and "mil"
+ arr->getActiveRunway("com", 2, activeRunway);
if (!(globals->get_runways()->search(arr->getId(),
- name,
+ activeRunway,
&rwy)))
{
cout << "Failed to find runway for " << arr->getId() << endl;
exit(1);
}
//string test;
- //arr->getActiveRunway(string("com"), 1, &test);
+ //arr->getActiveRunway(string("com"), 1, test);
//exit(1);
//cerr << "Altitude = " << alt << endl;
//resetWaypoints();
//Beginning of Decent
- string name;
- apt->getActiveRunway("com", 2, &name);
+ //string name;
+ // allow "mil" and "gen" as well
+ apt->getActiveRunway("com", 2, activeRunway);
if (!(globals->get_runways()->search(apt->getId(),
- name,
+ activeRunway,
&rwy)))
{
cout << "Failed to find runway for " << apt->getId() << endl;
exit(1);
}
//string test;
- //apt->getActiveRunway(string("com"), 1, &test);
+ //apt->getActiveRunway(string("com"), 1, test);
//exit(1);
//cerr << "Done" << endl;