1 // FGGround - a class to provide ground control at larger airports.
3 // Written by David Luff, started March 2002.
5 // Copyright (C) 2002 David C. Luff - david.luff@nottingham.ac.uk
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef _FG_GROUND_HXX
22 #define _FG_GROUND_HXX
33 #include <simgear/math/point3d.hxx>
34 #include <simgear/misc/sgstream.hxx>
35 #include <simgear/math/sg_geodesy.hxx>
38 //#include "ATCmgr.hxx"
39 #include "ATCProjection.hxx"
40 #include "AIEntity.hxx"
41 //#include "AILocalTraffic.hxx" // RunwayDetails - this is a temporary hack
47 //////////////////////////////////////////////////////
48 // Types for the logical network data structure
64 TRANSPORT_PASSENGER_NARROWBODY,
65 TRANSPORT_PASSENGER_WIDEBODY,
73 OTHER // ie. anything goes!!
76 enum network_element_type {
81 struct ground_network_element {
82 network_element_type struct_type;
85 struct arc : public ground_network_element {
89 bool directed; //false if 2-way, true if 1-way.
90 //This is a can of worms since arcs might be one way in different directions under different circumstances
91 unsigned int n1; // The nodeID of the first node
92 unsigned int n2; // The nodeID of the second node
93 // If the arc is directed then flow is normally from n1 to n2. See the above can of worms comment though.
96 typedef vector <arc*> arc_array_type; // This was and may become again a list instead of vector
97 typedef arc_array_type::iterator arc_array_iterator;
98 typedef arc_array_type::const_iterator arc_array_const_iterator;
100 struct node : public ground_network_element {
104 unsigned int nodeID; //each node in an airport needs a unique ID number - this is ZERO-BASED to match array position
110 double max_turn_radius;
113 typedef vector <node*> node_array_type;
114 typedef node_array_type::iterator node_array_iterator;
115 typedef node_array_type::const_iterator node_array_const_iterator;
117 struct Gate : public node {
119 int max_weight; //units??
120 //airline_code airline; //For the future - we don't have any airline codes ATM
121 int id; // The gate number in the logical scheme of things
122 string name; // The real-world gate letter/number
125 double heading; // The direction the parked-up plane should point in degrees
128 typedef vector < Gate* > gate_vec_type;
129 typedef gate_vec_type::iterator gate_vec_iterator;
130 typedef gate_vec_type::const_iterator gate_vec_const_iterator;
132 // A map of gate vs. the logical (internal FGFS) gate ID
133 typedef map < int, Gate* > gate_map_type;
134 typedef gate_map_type::iterator gate_map_iterator;
135 typedef gate_map_type::const_iterator gate_map_const_iterator;
137 // Runways - all the runway stuff is likely to change in the future
139 int id; //note this is a very simplified scheme for now - R & L are not differentiated
140 //It should work for simple one rwy airports
141 node_array_type exits; //Array of available exits from runway
142 // should probably add an FGRunway structure here as well eventually
143 // Eventually we will also want some encoding of real-life preferred runways
144 // This will get us up and running for single runway airports though.
147 typedef vector < Rwy > runway_array_type;
148 typedef runway_array_type::iterator runway_array_iterator;
149 typedef runway_array_type::const_iterator runway_array_const_iterator;
151 // end logical network types
152 ///////////////////////////////////////////////////////
154 ///////////////////////////////////////////////////////
155 // Structures to use the network
157 // A path through the network
158 typedef vector < ground_network_element* > ground_network_path_type;
159 typedef ground_network_path_type::iterator ground_network_path_iterator;
160 typedef ground_network_path_type::const_iterator ground_network_path_const_iterator;
162 //////////////////////////////////////////////////////////////////////////////////////////
164 ////////////////////////////////////////////////
166 // Stuff for the shortest-path algorithms
170 ground_network_path_type path;
174 // Paths mapped by nodeID reached so-far
175 typedef map < unsigned int, a_path* > shortest_path_map_type;
176 typedef shortest_path_map_type::iterator shortest_path_map_iterator;
178 // Nodes mapped by their ID
179 //typedef map < unsigned int, node* > node_map_type;
180 //typedef node_map_type::iterator node_map_iterator;
181 ////////////////////////////////////////////////
183 // Planes active within the ground network.
185 // A more specialist plane rec to include ground information
187 FGAIEntity* planePtr; // This might move to the planeRec eventually
192 node* last_clearance;
193 bool taxiRequestOutstanding; // Plane has requested taxi and we haven't responded yet
194 double clearanceCounter; // Hack for communication timing - counter since clearance requested in seconds
196 bool cleared; // set true when the plane has been cleared to somewhere
197 bool incoming; //true for arrivals, false for departures
199 // Almost certainly need to add more here
202 typedef list < GroundRec* > ground_rec_list;
203 typedef ground_rec_list::iterator ground_rec_list_itr;
204 typedef ground_rec_list::const_iterator ground_rec_list_const_itr;
206 //////////////////////////////////////////////////////////////////////////////////////////
209 // perhaps we could use an FGRunway instead of this
210 struct GRunwayDetails {
211 Point3D threshold_pos;
212 Point3D end1ortho; // ortho projection end1 (the threshold ATM)
213 Point3D end2ortho; // ortho projection end2 (the take off end in the current hardwired scheme)
214 double hdg; // true runway heading
215 double length; // In *METERS*
219 ///////////////////////////////////////////////////////////////////////////////
223 ///////////////////////////////////////////////////////////////////////////////
224 class FGGround : public FGATC {
228 FGGround(const string& id);
232 void Update(double dt);
234 inline const string& get_trans_ident() { return trans_ident; }
236 // Contact ground control on arrival, assumed to request any gate
237 //void NewArrival(plane_rec plane);
239 // Contact ground control on departure, assumed to request currently active runway.
240 void RequestDeparture(const PlaneRec& plane, FGAIEntity* requestee);
242 // Contact ground control when the calling routine doesn't know if arrival
243 // or departure is appropriate.
244 //void NewContact(plane_rec plane);
246 // Make a request of ground control.
247 //void Request(ground_request request);
249 // Randomly fill some of the available gates and GA parking spots with planes
250 void PopulateGates();
252 // Return a suitable gate (maybe this should be a list of suitable gates so the plane or controller can choose the closest one)
253 void ReturnGate(Gate &gate, GateType type);
255 // Return a pointer to an unused gate
258 // Return a pointer to a hold short node
259 node* GetHoldShortNode(const string& rwyID);
261 // Runway stuff - this might change in the future.
262 // Get a list of exits from a given runway
263 // It is up to the calling function to check for non-zero size of returned array before use
264 node_array_type GetExits(const string& rwyID);
266 // Get a path from one node to another
267 ground_network_path_type GetPath(node* A, node* B);
269 // Get a path from a node to a runway threshold
270 ground_network_path_type GetPath(node* A, const string& rwyID);
272 // Get a path from a node to a runway hold short point
273 // Bit of a hack this at the moment!
274 ground_network_path_type GetPathToHoldShort(node* A, const string& rwyID);
278 // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
280 // Need a data structure to hold details of the various active planes
281 // Need a data structure to hold details of the logical network
282 // including which gates are filled - or possibly another data structure
283 // with the positions of the inactive planes.
284 // Need a data structure to hold outstanding communications from aircraft.
285 // Possibly need a data structure to hold outstanding communications to aircraft.
287 // The logical network
288 // NODES WILL BE STORED IN THE NETWORK IN ORDER OF nodeID NUMBER
289 // ie. NODE 5 WILL BE AT network[5]
290 node_array_type network;
292 // A map of all the gates indexed against internal (FGFS) ID
294 gate_map_iterator gatesItr;
296 FGATCAlignedProjection ortho;
298 // Planes currently active
299 //ground_rec_list ground_traffic;
301 // Find the shortest route through the logical network between two points.
302 //FindShortestRoute(point a, point b);
304 // Assign a gate or parking location to a new arrival
305 //AssignGate(ground_rec &g);
307 // Generate the next clearance for an airplane
308 //NextClearance(ground_rec &g);
310 // environment - need to make sure we're getting the surface winds and not winds aloft.
311 SGPropertyNode* wind_from_hdg; //degrees
312 SGPropertyNode* wind_speed_knots; //knots
314 // for failure modeling
315 string trans_ident; // transmitted ident
316 bool ground_failed; // ground failed?
317 bool networkLoadOK; // Indicates whether LoadNetwork returned true or false at last attempt
320 bool untowered; // True if this is an untowered airport (we still need the ground class for shortest path implementation etc
321 //FGATC* tower; // Pointer to the tower control
323 // Logical runway details - this might change in the future.
324 //runway_array_type runways; // STL way
325 Rwy runways[37]; // quick hack!
327 // Physical runway details
328 double aptElev; // Airport elevation
329 string activeRwy; // Active runway number - For now we'll disregard multiple / alternate runway operation.
330 RunwayDetails rwy; // Assumed to be the active one for now.// Figure out which runways are active.
332 // For now we'll just be simple and do one active runway - eventually this will get much more complex
333 // Copied from FGTower - TODO - it would be better to implement this just once, and have ground call tower
334 // for runway operation details, but at the moment we can't guarantee that tower control at a given airport
335 // will be initialised before ground so we can't do that.
338 // Load the logical ground network for this airport from file.
339 // Return true if successfull.
342 // Parse a runway exit string and push the supplied node pointer onto the runway exit list
343 void ParseRwyExits(node* np, char* es);
345 // Return a random gate ID of an unused gate.
346 // Two error values may be returned and must be checked for by the calling function:
347 // -2 signifies that no gates exist at this airport.
348 // -1 signifies that all gates are currently full.
349 // TODO - modify to return a suitable gate based on aircraft size/weight.
350 int GetRandomGateID();
352 // Return a pointer to the node at a runway threshold
353 // Returns NULL if unsuccessful.
354 node* GetThresholdNode(const string& rwyID);
356 // A shortest path algorithm from memory (I can't find the bl&*dy book again!)
357 ground_network_path_type GetShortestPath(node* A, node* B);
360 ground_rec_list ground_traffic;
361 ground_rec_list_itr ground_traffic_itr;
364 #endif // _FG_GROUND_HXX