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/SGMath.hxx>
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/props/props.hxx>
33 #include "ATCProjection.hxx"
40 //////////////////////////////////////////////////////
41 // Types for the logical network data structure
57 TRANSPORT_PASSENGER_NARROWBODY,
58 TRANSPORT_PASSENGER_WIDEBODY,
66 OTHER // ie. anything goes!!
69 enum network_element_type {
74 struct ground_network_element {
75 network_element_type struct_type;
78 struct arc : public ground_network_element {
82 bool directed; //false if 2-way, true if 1-way.
83 //This is a can of worms since arcs might be one way in different directions under different circumstances
84 unsigned int n1; // The nodeID of the first node
85 unsigned int n2; // The nodeID of the second node
86 // If the arc is directed then flow is normally from n1 to n2. See the above can of worms comment though.
89 typedef std::vector <arc*> arc_array_type; // This was and may become again a list instead of vector
90 typedef arc_array_type::iterator arc_array_iterator;
91 typedef arc_array_type::const_iterator arc_array_const_iterator;
93 struct node : public ground_network_element {
97 unsigned int nodeID; //each node in an airport needs a unique ID number - this is ZERO-BASED to match array position
103 double max_turn_radius;
106 typedef std::vector <node*> node_array_type;
107 typedef node_array_type::iterator node_array_iterator;
108 typedef node_array_type::const_iterator node_array_const_iterator;
110 struct Gate : public node {
112 int max_weight; //units??
113 //airline_code airline; //For the future - we don't have any airline codes ATM
114 int id; // The gate number in the logical scheme of things
115 std::string name; // The real-world gate letter/number
118 double heading; // The direction the parked-up plane should point in degrees
121 typedef std::vector < Gate* > gate_vec_type;
122 typedef gate_vec_type::iterator gate_vec_iterator;
123 typedef gate_vec_type::const_iterator gate_vec_const_iterator;
125 // A map of gate vs. the logical (internal FGFS) gate ID
126 typedef std::map < int, Gate* > gate_map_type;
127 typedef gate_map_type::iterator gate_map_iterator;
128 typedef gate_map_type::const_iterator gate_map_const_iterator;
130 // Runways - all the runway stuff is likely to change in the future
132 int id; //note this is a very simplified scheme for now - R & L are not differentiated
133 //It should work for simple one rwy airports
134 node_array_type exits; //Array of available exits from runway
135 // should probably add an FGRunway structure here as well eventually
136 // Eventually we will also want some encoding of real-life preferred runways
137 // This will get us up and running for single runway airports though.
140 typedef std::vector < Rwy > runway_array_type;
141 typedef runway_array_type::iterator runway_array_iterator;
142 typedef runway_array_type::const_iterator runway_array_const_iterator;
144 // end logical network types
145 ///////////////////////////////////////////////////////
147 ///////////////////////////////////////////////////////
148 // Structures to use the network
150 // A path through the network
151 typedef std::vector < ground_network_element* > ground_network_path_type;
152 typedef ground_network_path_type::iterator ground_network_path_iterator;
153 typedef ground_network_path_type::const_iterator ground_network_path_const_iterator;
155 //////////////////////////////////////////////////////////////////////////////////////////
157 ////////////////////////////////////////////////
159 // Stuff for the shortest-path algorithms
163 ground_network_path_type path;
167 // Paths mapped by nodeID reached so-far
168 typedef std::map < unsigned int, a_path* > shortest_path_map_type;
169 typedef shortest_path_map_type::iterator shortest_path_map_iterator;
171 // Nodes mapped by their ID
172 //typedef map < unsigned int, node* > node_map_type;
173 //typedef node_map_type::iterator node_map_iterator;
174 ////////////////////////////////////////////////
176 // Planes active within the ground network.
178 // A more specialist plane rec to include ground information
180 FGAIEntity* planePtr; // This might move to the planeRec eventually
184 node* last_clearance;
185 bool taxiRequestOutstanding; // Plane has requested taxi and we haven't responded yet
186 double clearanceCounter; // Hack for communication timing - counter since clearance requested in seconds
188 bool cleared; // set true when the plane has been cleared to somewhere
189 bool incoming; //true for arrivals, false for departures
191 // Almost certainly need to add more here
194 typedef std::list < GroundRec* > ground_rec_list;
195 typedef ground_rec_list::iterator ground_rec_list_itr;
196 typedef ground_rec_list::const_iterator ground_rec_list_const_itr;
198 ///////////////////////////////////////////////////////////////////////////////
202 ///////////////////////////////////////////////////////////////////////////////
203 class FGGround : public FGATC {
207 FGGround(const std::string& id);
211 void Update(double dt);
213 inline const std::string& get_trans_ident() { return trans_ident; }
215 // Contact ground control on arrival, assumed to request any gate
216 //void NewArrival(plane_rec plane);
218 // Contact ground control on departure, assumed to request currently active runway.
219 void RequestDeparture(const PlaneRec& plane, FGAIEntity* requestee);
221 // Contact ground control when the calling routine doesn't know if arrival
222 // or departure is appropriate.
223 //void NewContact(plane_rec plane);
225 // Make a request of ground control.
226 //void Request(ground_request request);
228 // Randomly fill some of the available gates and GA parking spots with planes
229 void PopulateGates();
231 // Return a suitable gate (maybe this should be a list of suitable gates so the plane or controller can choose the closest one)
232 void ReturnGate(Gate &gate, GateType type);
234 // Return a pointer to an unused gate
237 // Return a pointer to a hold short node
238 node* GetHoldShortNode(const std::string& rwyID);
240 // Runway stuff - this might change in the future.
241 // Get a list of exits from a given runway
242 // It is up to the calling function to check for non-zero size of returned array before use
243 node_array_type GetExits(const std::string& rwyID);
245 // Get a path from one node to another
246 ground_network_path_type GetPath(node* A, node* B);
248 // Get a path from a node to a runway threshold
249 ground_network_path_type GetPath(node* A, const std::string& rwyID);
251 // Get a path from a node to a runway hold short point
252 // Bit of a hack this at the moment!
253 ground_network_path_type GetPathToHoldShort(node* A, const std::string& rwyID);
257 // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
259 // Need a data structure to hold details of the various active planes
260 // Need a data structure to hold details of the logical network
261 // including which gates are filled - or possibly another data structure
262 // with the positions of the inactive planes.
263 // Need a data structure to hold outstanding communications from aircraft.
264 // Possibly need a data structure to hold outstanding communications to aircraft.
266 // The logical network
267 // NODES WILL BE STORED IN THE NETWORK IN ORDER OF nodeID NUMBER
268 // ie. NODE 5 WILL BE AT network[5]
269 node_array_type network;
271 // A map of all the gates indexed against internal (FGFS) ID
273 gate_map_iterator gatesItr;
275 FGATCAlignedProjection ortho;
277 // Planes currently active
278 //ground_rec_list ground_traffic;
280 // Find the shortest route through the logical network between two points.
281 //FindShortestRoute(point a, point b);
283 // Assign a gate or parking location to a new arrival
284 //AssignGate(ground_rec &g);
286 // Generate the next clearance for an airplane
287 //NextClearance(ground_rec &g);
289 // environment - need to make sure we're getting the surface winds and not winds aloft.
290 SGPropertyNode_ptr wind_from_hdg; //degrees
291 SGPropertyNode_ptr wind_speed_knots; //knots
293 // for failure modeling
294 std::string trans_ident; // transmitted ident
295 bool ground_failed; // ground failed?
296 bool networkLoadOK; // Indicates whether LoadNetwork returned true or false at last attempt
299 bool untowered; // True if this is an untowered airport (we still need the ground class for shortest path implementation etc
300 //FGATC* tower; // Pointer to the tower control
302 // Logical runway details - this might change in the future.
303 //runway_array_type runways; // STL way
304 Rwy runways[37]; // quick hack!
306 // Physical runway details
307 double aptElev; // Airport elevation
308 std::string activeRwy; // Active runway number - For now we'll disregard multiple / alternate runway operation.
309 RunwayDetails rwy; // Assumed to be the active one for now.// Figure out which runways are active.
311 // For now we'll just be simple and do one active runway - eventually this will get much more complex
312 // Copied from FGTower - TODO - it would be better to implement this just once, and have ground call tower
313 // for runway operation details, but at the moment we can't guarantee that tower control at a given airport
314 // will be initialised before ground so we can't do that.
317 // Load the logical ground network for this airport from file.
318 // Return true if successfull.
321 // Parse a runway exit string and push the supplied node pointer onto the runway exit list
322 void ParseRwyExits(node* np, char* es);
324 // Return a random gate ID of an unused gate.
325 // Two error values may be returned and must be checked for by the calling function:
326 // -2 signifies that no gates exist at this airport.
327 // -1 signifies that all gates are currently full.
328 // TODO - modify to return a suitable gate based on aircraft size/weight.
329 int GetRandomGateID();
331 // Return a pointer to the node at a runway threshold
332 // Returns NULL if unsuccessful.
333 node* GetThresholdNode(const std::string& rwyID);
335 // A shortest path algorithm from memory (I can't find the bl&*dy book again!)
336 ground_network_path_type GetShortestPath(node* A, node* B);
339 ground_rec_list ground_traffic;
340 ground_rec_list_itr ground_traffic_itr;
343 #endif // _FG_GROUND_HXX