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"
41 //////////////////////////////////////////////////////
42 // Types for the logical network data structure
58 TRANSPORT_PASSENGER_NARROWBODY,
59 TRANSPORT_PASSENGER_WIDEBODY,
67 OTHER // ie. anything goes!!
70 enum network_element_type {
75 struct ground_network_element {
76 network_element_type struct_type;
79 struct arc : public ground_network_element {
83 bool directed; //false if 2-way, true if 1-way.
84 //This is a can of worms since arcs might be one way in different directions under different circumstances
85 unsigned int n1; // The nodeID of the first node
86 unsigned int n2; // The nodeID of the second node
87 // If the arc is directed then flow is normally from n1 to n2. See the above can of worms comment though.
90 typedef std::vector <arc*> arc_array_type; // This was and may become again a list instead of vector
91 typedef arc_array_type::iterator arc_array_iterator;
92 typedef arc_array_type::const_iterator arc_array_const_iterator;
94 struct node : public ground_network_element {
98 unsigned int nodeID; //each node in an airport needs a unique ID number - this is ZERO-BASED to match array position
104 double max_turn_radius;
107 typedef std::vector <node*> node_array_type;
108 typedef node_array_type::iterator node_array_iterator;
109 typedef node_array_type::const_iterator node_array_const_iterator;
111 struct Gate : public node {
113 int max_weight; //units??
114 //airline_code airline; //For the future - we don't have any airline codes ATM
115 int id; // The gate number in the logical scheme of things
116 std::string name; // The real-world gate letter/number
119 double heading; // The direction the parked-up plane should point in degrees
122 typedef std::vector < Gate* > gate_vec_type;
123 typedef gate_vec_type::iterator gate_vec_iterator;
124 typedef gate_vec_type::const_iterator gate_vec_const_iterator;
126 // A map of gate vs. the logical (internal FGFS) gate ID
127 typedef std::map < int, Gate* > gate_map_type;
128 typedef gate_map_type::iterator gate_map_iterator;
129 typedef gate_map_type::const_iterator gate_map_const_iterator;
131 // Runways - all the runway stuff is likely to change in the future
133 int id; //note this is a very simplified scheme for now - R & L are not differentiated
134 //It should work for simple one rwy airports
135 node_array_type exits; //Array of available exits from runway
136 // should probably add an FGRunway structure here as well eventually
137 // Eventually we will also want some encoding of real-life preferred runways
138 // This will get us up and running for single runway airports though.
141 typedef std::vector < Rwy > runway_array_type;
142 typedef runway_array_type::iterator runway_array_iterator;
143 typedef runway_array_type::const_iterator runway_array_const_iterator;
145 // end logical network types
146 ///////////////////////////////////////////////////////
148 ///////////////////////////////////////////////////////
149 // Structures to use the network
151 // A path through the network
152 typedef std::vector < ground_network_element* > ground_network_path_type;
153 typedef ground_network_path_type::iterator ground_network_path_iterator;
154 typedef ground_network_path_type::const_iterator ground_network_path_const_iterator;
156 //////////////////////////////////////////////////////////////////////////////////////////
158 ////////////////////////////////////////////////
160 // Stuff for the shortest-path algorithms
164 ground_network_path_type path;
168 // Paths mapped by nodeID reached so-far
169 typedef std::map < unsigned int, a_path* > shortest_path_map_type;
170 typedef shortest_path_map_type::iterator shortest_path_map_iterator;
172 // Nodes mapped by their ID
173 //typedef map < unsigned int, node* > node_map_type;
174 //typedef node_map_type::iterator node_map_iterator;
175 ////////////////////////////////////////////////
177 // Planes active within the ground network.
179 // A more specialist plane rec to include ground information
181 FGAIEntity* planePtr; // This might move to the planeRec eventually
186 node* last_clearance;
187 bool taxiRequestOutstanding; // Plane has requested taxi and we haven't responded yet
188 double clearanceCounter; // Hack for communication timing - counter since clearance requested in seconds
190 bool cleared; // set true when the plane has been cleared to somewhere
191 bool incoming; //true for arrivals, false for departures
193 // Almost certainly need to add more here
196 typedef std::list < GroundRec* > ground_rec_list;
197 typedef ground_rec_list::iterator ground_rec_list_itr;
198 typedef ground_rec_list::const_iterator ground_rec_list_const_itr;
200 //////////////////////////////////////////////////////////////////////////////////////////
203 // perhaps we could use an FGRunway instead of this
204 struct GRunwayDetails {
205 Point3D threshold_pos;
206 Point3D end1ortho; // ortho projection end1 (the threshold ATM)
207 Point3D end2ortho; // ortho projection end2 (the take off end in the current hardwired scheme)
208 double hdg; // true runway heading
209 double length; // In *METERS*
213 ///////////////////////////////////////////////////////////////////////////////
217 ///////////////////////////////////////////////////////////////////////////////
218 class FGGround : public FGATC {
222 FGGround(const std::string& id);
226 void Update(double dt);
228 inline const std::string& get_trans_ident() { return trans_ident; }
230 // Contact ground control on arrival, assumed to request any gate
231 //void NewArrival(plane_rec plane);
233 // Contact ground control on departure, assumed to request currently active runway.
234 void RequestDeparture(const PlaneRec& plane, FGAIEntity* requestee);
236 // Contact ground control when the calling routine doesn't know if arrival
237 // or departure is appropriate.
238 //void NewContact(plane_rec plane);
240 // Make a request of ground control.
241 //void Request(ground_request request);
243 // Randomly fill some of the available gates and GA parking spots with planes
244 void PopulateGates();
246 // Return a suitable gate (maybe this should be a list of suitable gates so the plane or controller can choose the closest one)
247 void ReturnGate(Gate &gate, GateType type);
249 // Return a pointer to an unused gate
252 // Return a pointer to a hold short node
253 node* GetHoldShortNode(const std::string& rwyID);
255 // Runway stuff - this might change in the future.
256 // Get a list of exits from a given runway
257 // It is up to the calling function to check for non-zero size of returned array before use
258 node_array_type GetExits(const std::string& rwyID);
260 // Get a path from one node to another
261 ground_network_path_type GetPath(node* A, node* B);
263 // Get a path from a node to a runway threshold
264 ground_network_path_type GetPath(node* A, const std::string& rwyID);
266 // Get a path from a node to a runway hold short point
267 // Bit of a hack this at the moment!
268 ground_network_path_type GetPathToHoldShort(node* A, const std::string& rwyID);
272 // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
274 // Need a data structure to hold details of the various active planes
275 // Need a data structure to hold details of the logical network
276 // including which gates are filled - or possibly another data structure
277 // with the positions of the inactive planes.
278 // Need a data structure to hold outstanding communications from aircraft.
279 // Possibly need a data structure to hold outstanding communications to aircraft.
281 // The logical network
282 // NODES WILL BE STORED IN THE NETWORK IN ORDER OF nodeID NUMBER
283 // ie. NODE 5 WILL BE AT network[5]
284 node_array_type network;
286 // A map of all the gates indexed against internal (FGFS) ID
288 gate_map_iterator gatesItr;
290 FGATCAlignedProjection ortho;
292 // Planes currently active
293 //ground_rec_list ground_traffic;
295 // Find the shortest route through the logical network between two points.
296 //FindShortestRoute(point a, point b);
298 // Assign a gate or parking location to a new arrival
299 //AssignGate(ground_rec &g);
301 // Generate the next clearance for an airplane
302 //NextClearance(ground_rec &g);
304 // environment - need to make sure we're getting the surface winds and not winds aloft.
305 SGPropertyNode_ptr wind_from_hdg; //degrees
306 SGPropertyNode_ptr wind_speed_knots; //knots
308 // for failure modeling
309 std::string trans_ident; // transmitted ident
310 bool ground_failed; // ground failed?
311 bool networkLoadOK; // Indicates whether LoadNetwork returned true or false at last attempt
314 bool untowered; // True if this is an untowered airport (we still need the ground class for shortest path implementation etc
315 //FGATC* tower; // Pointer to the tower control
317 // Logical runway details - this might change in the future.
318 //runway_array_type runways; // STL way
319 Rwy runways[37]; // quick hack!
321 // Physical runway details
322 double aptElev; // Airport elevation
323 std::string activeRwy; // Active runway number - For now we'll disregard multiple / alternate runway operation.
324 RunwayDetails rwy; // Assumed to be the active one for now.// Figure out which runways are active.
326 // For now we'll just be simple and do one active runway - eventually this will get much more complex
327 // Copied from FGTower - TODO - it would be better to implement this just once, and have ground call tower
328 // for runway operation details, but at the moment we can't guarantee that tower control at a given airport
329 // will be initialised before ground so we can't do that.
332 // Load the logical ground network for this airport from file.
333 // Return true if successfull.
336 // Parse a runway exit string and push the supplied node pointer onto the runway exit list
337 void ParseRwyExits(node* np, char* es);
339 // Return a random gate ID of an unused gate.
340 // Two error values may be returned and must be checked for by the calling function:
341 // -2 signifies that no gates exist at this airport.
342 // -1 signifies that all gates are currently full.
343 // TODO - modify to return a suitable gate based on aircraft size/weight.
344 int GetRandomGateID();
346 // Return a pointer to the node at a runway threshold
347 // Returns NULL if unsuccessful.
348 node* GetThresholdNode(const std::string& rwyID);
350 // A shortest path algorithm from memory (I can't find the bl&*dy book again!)
351 ground_network_path_type GetShortestPath(node* A, node* B);
354 ground_rec_list ground_traffic;
355 ground_rec_list_itr ground_traffic_itr;
358 #endif // _FG_GROUND_HXX