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"
39 //////////////////////////////////////////////////////
40 // Types for the logical network data structure
56 TRANSPORT_PASSENGER_NARROWBODY,
57 TRANSPORT_PASSENGER_WIDEBODY,
65 OTHER // ie. anything goes!!
68 enum network_element_type {
73 struct ground_network_element {
74 network_element_type struct_type;
77 struct arc : public ground_network_element {
81 bool directed; //false if 2-way, true if 1-way.
82 //This is a can of worms since arcs might be one way in different directions under different circumstances
83 unsigned int n1; // The nodeID of the first node
84 unsigned int n2; // The nodeID of the second node
85 // If the arc is directed then flow is normally from n1 to n2. See the above can of worms comment though.
88 typedef std::vector <arc*> arc_array_type; // This was and may become again a list instead of vector
89 typedef arc_array_type::iterator arc_array_iterator;
90 typedef arc_array_type::const_iterator arc_array_const_iterator;
92 struct node : public ground_network_element {
96 unsigned int nodeID; //each node in an airport needs a unique ID number - this is ZERO-BASED to match array position
102 double max_turn_radius;
105 typedef std::vector <node*> node_array_type;
106 typedef node_array_type::iterator node_array_iterator;
107 typedef node_array_type::const_iterator node_array_const_iterator;
109 struct Gate : public node {
111 int max_weight; //units??
112 //airline_code airline; //For the future - we don't have any airline codes ATM
113 int id; // The gate number in the logical scheme of things
114 std::string name; // The real-world gate letter/number
117 double heading; // The direction the parked-up plane should point in degrees
120 typedef std::vector < Gate* > gate_vec_type;
121 typedef gate_vec_type::iterator gate_vec_iterator;
122 typedef gate_vec_type::const_iterator gate_vec_const_iterator;
124 // A map of gate vs. the logical (internal FGFS) gate ID
125 typedef std::map < int, Gate* > gate_map_type;
126 typedef gate_map_type::iterator gate_map_iterator;
127 typedef gate_map_type::const_iterator gate_map_const_iterator;
129 // Runways - all the runway stuff is likely to change in the future
131 int id; //note this is a very simplified scheme for now - R & L are not differentiated
132 //It should work for simple one rwy airports
133 node_array_type exits; //Array of available exits from runway
134 // should probably add an FGRunway structure here as well eventually
135 // Eventually we will also want some encoding of real-life preferred runways
136 // This will get us up and running for single runway airports though.
139 typedef std::vector < Rwy > runway_array_type;
140 typedef runway_array_type::iterator runway_array_iterator;
141 typedef runway_array_type::const_iterator runway_array_const_iterator;
143 // end logical network types
144 ///////////////////////////////////////////////////////
146 ///////////////////////////////////////////////////////
147 // Structures to use the network
149 // A path through the network
150 typedef std::vector < ground_network_element* > ground_network_path_type;
151 typedef ground_network_path_type::iterator ground_network_path_iterator;
152 typedef ground_network_path_type::const_iterator ground_network_path_const_iterator;
154 //////////////////////////////////////////////////////////////////////////////////////////
156 ////////////////////////////////////////////////
158 // Stuff for the shortest-path algorithms
162 ground_network_path_type path;
166 // Paths mapped by nodeID reached so-far
167 typedef std::map < unsigned int, a_path* > shortest_path_map_type;
168 typedef shortest_path_map_type::iterator shortest_path_map_iterator;
170 // Nodes mapped by their ID
171 //typedef map < unsigned int, node* > node_map_type;
172 //typedef node_map_type::iterator node_map_iterator;
173 ////////////////////////////////////////////////
175 // Planes active within the ground network.
177 // A more specialist plane rec to include ground information
181 node* last_clearance;
182 bool taxiRequestOutstanding; // Plane has requested taxi and we haven't responded yet
183 double clearanceCounter; // Hack for communication timing - counter since clearance requested in seconds
185 bool cleared; // set true when the plane has been cleared to somewhere
186 bool incoming; //true for arrivals, false for departures
188 // Almost certainly need to add more here
191 typedef std::list < GroundRec* > ground_rec_list;
192 typedef ground_rec_list::iterator ground_rec_list_itr;
193 typedef ground_rec_list::const_iterator ground_rec_list_const_itr;
195 ///////////////////////////////////////////////////////////////////////////////
199 ///////////////////////////////////////////////////////////////////////////////
200 class FGGround : public FGATC {
204 FGGround(const std::string& id);
208 void Update(double dt);
210 inline const std::string& get_trans_ident() { return trans_ident; }
212 // Randomly fill some of the available gates and GA parking spots with planes
213 void PopulateGates();
215 // Return a suitable gate (maybe this should be a list of suitable gates so the plane or controller can choose the closest one)
216 void ReturnGate(Gate &gate, GateType type);
218 // Return a pointer to an unused gate
221 // Return a pointer to a hold short node
222 node* GetHoldShortNode(const std::string& rwyID);
224 // Runway stuff - this might change in the future.
225 // Get a list of exits from a given runway
226 // It is up to the calling function to check for non-zero size of returned array before use
227 node_array_type GetExits(const std::string& rwyID);
229 // Get a path from one node to another
230 ground_network_path_type GetPath(node* A, node* B);
232 // Get a path from a node to a runway threshold
233 ground_network_path_type GetPath(node* A, const std::string& rwyID);
235 // Get a path from a node to a runway hold short point
236 // Bit of a hack this at the moment!
237 ground_network_path_type GetPathToHoldShort(node* A, const std::string& rwyID);
241 // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
243 // Need a data structure to hold details of the various active planes
244 // Need a data structure to hold details of the logical network
245 // including which gates are filled - or possibly another data structure
246 // with the positions of the inactive planes.
247 // Need a data structure to hold outstanding communications from aircraft.
248 // Possibly need a data structure to hold outstanding communications to aircraft.
250 // The logical network
251 // NODES WILL BE STORED IN THE NETWORK IN ORDER OF nodeID NUMBER
252 // ie. NODE 5 WILL BE AT network[5]
253 node_array_type network;
255 // A map of all the gates indexed against internal (FGFS) ID
257 gate_map_iterator gatesItr;
259 FGATCAlignedProjection ortho;
261 // Planes currently active
262 //ground_rec_list ground_traffic;
264 // Find the shortest route through the logical network between two points.
265 //FindShortestRoute(point a, point b);
267 // Assign a gate or parking location to a new arrival
268 //AssignGate(ground_rec &g);
270 // Generate the next clearance for an airplane
271 //NextClearance(ground_rec &g);
273 // environment - need to make sure we're getting the surface winds and not winds aloft.
274 SGPropertyNode_ptr wind_from_hdg; //degrees
275 SGPropertyNode_ptr wind_speed_knots; //knots
277 // for failure modeling
278 std::string trans_ident; // transmitted ident
279 bool ground_failed; // ground failed?
280 bool networkLoadOK; // Indicates whether LoadNetwork returned true or false at last attempt
283 bool untowered; // True if this is an untowered airport (we still need the ground class for shortest path implementation etc
284 //FGATC* tower; // Pointer to the tower control
286 // Logical runway details - this might change in the future.
287 //runway_array_type runways; // STL way
288 Rwy runways[37]; // quick hack!
290 // Physical runway details
291 double aptElev; // Airport elevation
292 std::string activeRwy; // Active runway number - For now we'll disregard multiple / alternate runway operation.
293 RunwayDetails rwy; // Assumed to be the active one for now.// Figure out which runways are active.
295 // For now we'll just be simple and do one active runway - eventually this will get much more complex
296 // Copied from FGTower - TODO - it would be better to implement this just once, and have ground call tower
297 // for runway operation details, but at the moment we can't guarantee that tower control at a given airport
298 // will be initialised before ground so we can't do that.
301 // Load the logical ground network for this airport from file.
302 // Return true if successfull.
305 // Parse a runway exit string and push the supplied node pointer onto the runway exit list
306 void ParseRwyExits(node* np, char* es);
308 // Return a random gate ID of an unused gate.
309 // Two error values may be returned and must be checked for by the calling function:
310 // -2 signifies that no gates exist at this airport.
311 // -1 signifies that all gates are currently full.
312 // TODO - modify to return a suitable gate based on aircraft size/weight.
313 int GetRandomGateID();
315 // Return a pointer to the node at a runway threshold
316 // Returns NULL if unsuccessful.
317 node* GetThresholdNode(const std::string& rwyID);
319 // A shortest path algorithm from memory (I can't find the bl&*dy book again!)
320 ground_network_path_type GetShortestPath(node* A, node* B);
323 ground_rec_list ground_traffic;
324 ground_rec_list_itr ground_traffic_itr;
327 #endif // _FG_GROUND_HXX