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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef _FG_GROUND_HXX
22 #define _FG_GROUND_HXX
28 #include <simgear/math/point3d.hxx>
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/math/sg_geodesy.hxx>
31 #include <simgear/props/props.hxx>
34 #include "ATCProjection.hxx"
49 //////////////////////////////////////////////////////
50 // Types for the logical network data structure
66 TRANSPORT_PASSENGER_NARROWBODY,
67 TRANSPORT_PASSENGER_WIDEBODY,
75 OTHER // ie. anything goes!!
78 enum network_element_type {
83 struct ground_network_element {
84 network_element_type struct_type;
87 struct arc : public ground_network_element {
91 bool directed; //false if 2-way, true if 1-way.
92 //This is a can of worms since arcs might be one way in different directions under different circumstances
93 unsigned int n1; // The nodeID of the first node
94 unsigned int n2; // The nodeID of the second node
95 // If the arc is directed then flow is normally from n1 to n2. See the above can of worms comment though.
98 typedef vector <arc*> arc_array_type; // This was and may become again a list instead of vector
99 typedef arc_array_type::iterator arc_array_iterator;
100 typedef arc_array_type::const_iterator arc_array_const_iterator;
102 struct node : public ground_network_element {
106 unsigned int nodeID; //each node in an airport needs a unique ID number - this is ZERO-BASED to match array position
112 double max_turn_radius;
115 typedef vector <node*> node_array_type;
116 typedef node_array_type::iterator node_array_iterator;
117 typedef node_array_type::const_iterator node_array_const_iterator;
119 struct Gate : public node {
121 int max_weight; //units??
122 //airline_code airline; //For the future - we don't have any airline codes ATM
123 int id; // The gate number in the logical scheme of things
124 string name; // The real-world gate letter/number
127 double heading; // The direction the parked-up plane should point in degrees
130 typedef vector < Gate* > gate_vec_type;
131 typedef gate_vec_type::iterator gate_vec_iterator;
132 typedef gate_vec_type::const_iterator gate_vec_const_iterator;
134 // A map of gate vs. the logical (internal FGFS) gate ID
135 typedef map < int, Gate* > gate_map_type;
136 typedef gate_map_type::iterator gate_map_iterator;
137 typedef gate_map_type::const_iterator gate_map_const_iterator;
139 // Runways - all the runway stuff is likely to change in the future
141 int id; //note this is a very simplified scheme for now - R & L are not differentiated
142 //It should work for simple one rwy airports
143 node_array_type exits; //Array of available exits from runway
144 // should probably add an FGRunway structure here as well eventually
145 // Eventually we will also want some encoding of real-life preferred runways
146 // This will get us up and running for single runway airports though.
149 typedef vector < Rwy > runway_array_type;
150 typedef runway_array_type::iterator runway_array_iterator;
151 typedef runway_array_type::const_iterator runway_array_const_iterator;
153 // end logical network types
154 ///////////////////////////////////////////////////////
156 ///////////////////////////////////////////////////////
157 // Structures to use the network
159 // A path through the network
160 typedef vector < ground_network_element* > ground_network_path_type;
161 typedef ground_network_path_type::iterator ground_network_path_iterator;
162 typedef ground_network_path_type::const_iterator ground_network_path_const_iterator;
164 //////////////////////////////////////////////////////////////////////////////////////////
166 ////////////////////////////////////////////////
168 // Stuff for the shortest-path algorithms
172 ground_network_path_type path;
176 // Paths mapped by nodeID reached so-far
177 typedef map < unsigned int, a_path* > shortest_path_map_type;
178 typedef shortest_path_map_type::iterator shortest_path_map_iterator;
180 // Nodes mapped by their ID
181 //typedef map < unsigned int, node* > node_map_type;
182 //typedef node_map_type::iterator node_map_iterator;
183 ////////////////////////////////////////////////
185 // Planes active within the ground network.
187 // A more specialist plane rec to include ground information
189 FGAIEntity* planePtr; // This might move to the planeRec eventually
194 node* last_clearance;
195 bool taxiRequestOutstanding; // Plane has requested taxi and we haven't responded yet
196 double clearanceCounter; // Hack for communication timing - counter since clearance requested in seconds
198 bool cleared; // set true when the plane has been cleared to somewhere
199 bool incoming; //true for arrivals, false for departures
201 // Almost certainly need to add more here
204 typedef list < GroundRec* > ground_rec_list;
205 typedef ground_rec_list::iterator ground_rec_list_itr;
206 typedef ground_rec_list::const_iterator ground_rec_list_const_itr;
208 //////////////////////////////////////////////////////////////////////////////////////////
211 // perhaps we could use an FGRunway instead of this
212 struct GRunwayDetails {
213 Point3D threshold_pos;
214 Point3D end1ortho; // ortho projection end1 (the threshold ATM)
215 Point3D end2ortho; // ortho projection end2 (the take off end in the current hardwired scheme)
216 double hdg; // true runway heading
217 double length; // In *METERS*
221 ///////////////////////////////////////////////////////////////////////////////
225 ///////////////////////////////////////////////////////////////////////////////
226 class FGGround : public FGATC {
230 FGGround(const string& id);
234 void Update(double dt);
236 inline const string& get_trans_ident() { return trans_ident; }
238 // Contact ground control on arrival, assumed to request any gate
239 //void NewArrival(plane_rec plane);
241 // Contact ground control on departure, assumed to request currently active runway.
242 void RequestDeparture(const PlaneRec& plane, FGAIEntity* requestee);
244 // Contact ground control when the calling routine doesn't know if arrival
245 // or departure is appropriate.
246 //void NewContact(plane_rec plane);
248 // Make a request of ground control.
249 //void Request(ground_request request);
251 // Randomly fill some of the available gates and GA parking spots with planes
252 void PopulateGates();
254 // Return a suitable gate (maybe this should be a list of suitable gates so the plane or controller can choose the closest one)
255 void ReturnGate(Gate &gate, GateType type);
257 // Return a pointer to an unused gate
260 // Return a pointer to a hold short node
261 node* GetHoldShortNode(const string& rwyID);
263 // Runway stuff - this might change in the future.
264 // Get a list of exits from a given runway
265 // It is up to the calling function to check for non-zero size of returned array before use
266 node_array_type GetExits(const string& rwyID);
268 // Get a path from one node to another
269 ground_network_path_type GetPath(node* A, node* B);
271 // Get a path from a node to a runway threshold
272 ground_network_path_type GetPath(node* A, const string& rwyID);
274 // Get a path from a node to a runway hold short point
275 // Bit of a hack this at the moment!
276 ground_network_path_type GetPathToHoldShort(node* A, const string& rwyID);
280 // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
282 // Need a data structure to hold details of the various active planes
283 // Need a data structure to hold details of the logical network
284 // including which gates are filled - or possibly another data structure
285 // with the positions of the inactive planes.
286 // Need a data structure to hold outstanding communications from aircraft.
287 // Possibly need a data structure to hold outstanding communications to aircraft.
289 // The logical network
290 // NODES WILL BE STORED IN THE NETWORK IN ORDER OF nodeID NUMBER
291 // ie. NODE 5 WILL BE AT network[5]
292 node_array_type network;
294 // A map of all the gates indexed against internal (FGFS) ID
296 gate_map_iterator gatesItr;
298 FGATCAlignedProjection ortho;
300 // Planes currently active
301 //ground_rec_list ground_traffic;
303 // Find the shortest route through the logical network between two points.
304 //FindShortestRoute(point a, point b);
306 // Assign a gate or parking location to a new arrival
307 //AssignGate(ground_rec &g);
309 // Generate the next clearance for an airplane
310 //NextClearance(ground_rec &g);
312 // environment - need to make sure we're getting the surface winds and not winds aloft.
313 SGPropertyNode_ptr wind_from_hdg; //degrees
314 SGPropertyNode_ptr wind_speed_knots; //knots
316 // for failure modeling
317 string trans_ident; // transmitted ident
318 bool ground_failed; // ground failed?
319 bool networkLoadOK; // Indicates whether LoadNetwork returned true or false at last attempt
322 bool untowered; // True if this is an untowered airport (we still need the ground class for shortest path implementation etc
323 //FGATC* tower; // Pointer to the tower control
325 // Logical runway details - this might change in the future.
326 //runway_array_type runways; // STL way
327 Rwy runways[37]; // quick hack!
329 // Physical runway details
330 double aptElev; // Airport elevation
331 string activeRwy; // Active runway number - For now we'll disregard multiple / alternate runway operation.
332 RunwayDetails rwy; // Assumed to be the active one for now.// Figure out which runways are active.
334 // For now we'll just be simple and do one active runway - eventually this will get much more complex
335 // Copied from FGTower - TODO - it would be better to implement this just once, and have ground call tower
336 // for runway operation details, but at the moment we can't guarantee that tower control at a given airport
337 // will be initialised before ground so we can't do that.
340 // Load the logical ground network for this airport from file.
341 // Return true if successfull.
344 // Parse a runway exit string and push the supplied node pointer onto the runway exit list
345 void ParseRwyExits(node* np, char* es);
347 // Return a random gate ID of an unused gate.
348 // Two error values may be returned and must be checked for by the calling function:
349 // -2 signifies that no gates exist at this airport.
350 // -1 signifies that all gates are currently full.
351 // TODO - modify to return a suitable gate based on aircraft size/weight.
352 int GetRandomGateID();
354 // Return a pointer to the node at a runway threshold
355 // Returns NULL if unsuccessful.
356 node* GetThresholdNode(const string& rwyID);
358 // A shortest path algorithm from memory (I can't find the bl&*dy book again!)
359 ground_network_path_type GetShortestPath(node* A, node* B);
362 ground_rec_list ground_traffic;
363 ground_rec_list_itr ground_traffic_itr;
366 #endif // _FG_GROUND_HXX