From 657dfefec0ed52bce5f132d3e783d475433cfab5 Mon Sep 17 00:00:00 2001 From: daveluff Date: Fri, 28 Mar 2003 15:25:48 +0000 Subject: [PATCH] Calculate active runway in FGGround. It would be better to get the active runway from FGTower instead of duplicating the code to calculate it, but at the moment I can't guarantee that tower control at a given airport will be initialised before ground control, so this will have to do for now... --- src/ATC/ground.cxx | 89 ++++++++++++++++++++++++++++++++++++++++------ src/ATC/ground.hxx | 36 +++++++++++++------ 2 files changed, 105 insertions(+), 20 deletions(-) diff --git a/src/ATC/ground.cxx b/src/ATC/ground.cxx index 66daabc7e..526aec07e 100644 --- a/src/ATC/ground.cxx +++ b/src/ATC/ground.cxx @@ -52,18 +52,28 @@ a_path::a_path() { } FGGround::FGGround() { + ATCmgr = globals->get_ATC_mgr(); display = false; networkLoadOK = false; ground_traffic.erase(ground_traffic.begin(), ground_traffic.end()); ground_traffic_itr = ground_traffic.begin(); + + // Init the property nodes - TODO - need to make sure we're getting surface winds. + wind_from_hdg = fgGetNode("/environment/wind-from-heading-deg", true); + wind_speed_knots = fgGetNode("/environment/wind-speed-kts", true); } FGGround::FGGround(string id) { + ATCmgr = globals->get_ATC_mgr(); display = false; networkLoadOK = false; ground_traffic.erase(ground_traffic.begin(), ground_traffic.end()); ground_traffic_itr = ground_traffic.begin(); ident = id; + + // Init the property nodes - TODO - need to make sure we're getting surface winds. + wind_from_hdg = fgGetNode("/environment/wind-from-heading-deg", true); + wind_speed_knots = fgGetNode("/environment/wind-speed-kts", true); } FGGround::~FGGround() { @@ -258,16 +268,15 @@ bool FGGround::LoadNetwork() { void FGGround::Init() { display = false; + untowered = false; - //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - // For now we'll hardwire the threshold end FIXME FIXME FIXME - use actual active rwy - Point3D P010(-118.037483, 34.081358, 296 * SG_FEET_TO_METER); - double hdg = 25.32; - ortho.Init(P010, hdg); - // FIXME TODO FIXME TODO - // TODO FIXME TODO FIXME - //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - + // Figure out which is the active runway - TODO - it would be better to have ground call tower + // for runway operation details, but at the moment we can't guarantee that tower control at a given airport + // will be initialised before ground so we can't do that. + DoRwyDetails(); + //cout << "In FGGround::Init, active rwy is " << activeRwy << '\n'; + ortho.Init(rwy.threshold_pos, rwy.hdg); + networkLoadOK = LoadNetwork(); } @@ -301,7 +310,7 @@ void FGGround::Update(double dt) { trns += g->plane.callsign; trns += " taxi holding point runway "; // TODO - add the holding point name // eg " taxi holding point G2 runway " - //trns += " + trns += ConvertRwyNumToSpokenString(activeRwy); if(display) { globals->get_ATC_display()->RegisterSingleMessage(trns, 0); } @@ -332,6 +341,66 @@ void FGGround::Update(double dt) { } } +// Figure out which runways are active. +// For now we'll just be simple and do one active runway - eventually this will get much more complex +// Copied from FGTower - TODO - it would be better to implement this just once, and have ground call tower +// for runway operation details, but at the moment we can't guarantee that tower control at a given airport +// will be initialised before ground so we can't do that. +void FGGround::DoRwyDetails() { + //cout << "GetRwyDetails called" << endl; + + // Based on the airport-id and wind get the active runway + SGPath path( globals->get_fg_root() ); + path.append( "Airports" ); + path.append( "runways.mk4" ); + FGRunways r_ways( path.c_str() ); + + //wind + double hdg = wind_from_hdg->getDoubleValue(); + double speed = wind_speed_knots->getDoubleValue(); + hdg = (speed == 0.0 ? 270.0 : hdg); + //cout << "Heading = " << hdg << '\n'; + + FGRunway runway; + bool rwyGood = r_ways.search(ident, int(hdg), &runway); + if(rwyGood) { + activeRwy = runway.rwy_no; + rwy.rwyID = runway.rwy_no; + SG_LOG(SG_ATC, SG_INFO, "In FGGround, active runway for airport " << ident << " is " << activeRwy); + + // Get the threshold position + double other_way = runway.heading - 180.0; + while(other_way <= 0.0) { + other_way += 360.0; + } + // move to the +l end/center of the runway + //cout << "Runway center is at " << runway.lon << ", " << runway.lat << '\n'; + Point3D origin = Point3D(runway.lon, runway.lat, aptElev); + Point3D ref = origin; + double tshlon, tshlat, tshr; + double tolon, tolat, tor; + rwy.length = runway.length * SG_FEET_TO_METER; + geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), other_way, + rwy.length / 2.0 - 25.0, &tshlat, &tshlon, &tshr ); + geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), runway.heading, + rwy.length / 2.0 - 25.0, &tolat, &tolon, &tor ); + // Note - 25 meters in from the runway end is a bit of a hack to put the plane ahead of the user. + // now copy what we need out of runway into rwy + rwy.threshold_pos = Point3D(tshlon, tshlat, aptElev); + Point3D takeoff_end = Point3D(tolon, tolat, aptElev); + //cout << "Threshold position = " << tshlon << ", " << tshlat << ", " << aptElev << '\n'; + //cout << "Takeoff position = " << tolon << ", " << tolat << ", " << aptElev << '\n'; + rwy.hdg = runway.heading; + // Set the projection for the local area based on this active runway + ortho.Init(rwy.threshold_pos, rwy.hdg); + rwy.end1ortho = ortho.ConvertToLocal(rwy.threshold_pos); // should come out as zero + rwy.end2ortho = ortho.ConvertToLocal(takeoff_end); + } else { + SG_LOG(SG_ATC, SG_ALERT, "Help - can't get good runway in FGTower!!"); + activeRwy = "NN"; + } +} + // Return a random gate ID of an unused gate. // Two error values may be returned and must be checked for by the calling function: // -2 signifies that no gates exist at this airport. diff --git a/src/ATC/ground.hxx b/src/ATC/ground.hxx index 4ec09fca8..797c95e6f 100644 --- a/src/ATC/ground.hxx +++ b/src/ATC/ground.hxx @@ -211,13 +211,9 @@ struct GRunwayDetails { Point3D threshold_pos; Point3D end1ortho; // ortho projection end1 (the threshold ATM) Point3D end2ortho; // ortho projection end2 (the take off end in the current hardwired scheme) - double mag_hdg; - double mag_var; double hdg; // true runway heading double length; // In *METERS* - int ID; // 1 -> 36 string rwyID; - // Do we really need *both* the last two?? }; /////////////////////////////////////////////////////////////////////////////// @@ -278,8 +274,9 @@ public: ground_network_path_type GetPathToHoldShort(node* A, string rwyID); private: - // Tower stuff - + FGATCMgr* ATCmgr; + // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code! + // Need a data structure to hold details of the various active planes // Need a data structure to hold details of the logical network // including which gates are filled - or possibly another data structure @@ -295,10 +292,6 @@ private: // A map of all the gates indexed against internal (FGFS) ID gate_map_type gates; gate_map_iterator gatesItr; - - // Runway stuff - this might change in the future. - //runway_array_type runways; // STL way - Rwy runways[36]; // quick hack! FGATCAlignedProjection ortho; @@ -314,6 +307,10 @@ private: // Generate the next clearance for an airplane //NextClearance(ground_rec &g); + // environment - need to make sure we're getting the surface winds and not winds aloft. + SGPropertyNode* wind_from_hdg; //degrees + SGPropertyNode* wind_speed_knots; //knots + bool display; // Flag to indicate whether we should be outputting to the ATC display. bool displaying; // Flag to indicate whether we are outputting to the ATC display. // for failure modeling @@ -321,6 +318,25 @@ private: bool ground_failed; // ground failed? bool networkLoadOK; // Indicates whether LoadNetwork returned true or false at last attempt + // Tower control + bool untowered; // True if this is an untowered airport (we still need the ground class for shortest path implementation etc + //FGATC* tower; // Pointer to the tower control + + // Logical runway details - this might change in the future. + //runway_array_type runways; // STL way + Rwy runways[36]; // quick hack! + + // Physical runway details + double aptElev; // Airport elevation + string activeRwy; // Active runway number - For now we'll disregard multiple / alternate runway operation. + RunwayDetails rwy; // Assumed to be the active one for now.// Figure out which runways are active. + + // For now we'll just be simple and do one active runway - eventually this will get much more complex + // Copied from FGTower - TODO - it would be better to implement this just once, and have ground call tower + // for runway operation details, but at the moment we can't guarantee that tower control at a given airport + // will be initialised before ground so we can't do that. + void DoRwyDetails(); + // Load the logical ground network for this airport from file. // Return true if successfull. bool LoadNetwork(); -- 2.39.5