]> git.mxchange.org Git - flightgear.git/blob - src/ATCDCL/ground.hxx
CMake update for new KLN89 file.
[flightgear.git] / src / ATCDCL / ground.hxx
1 // FGGround - a class to provide ground control at larger airports.
2 //
3 // Written by David Luff, started March 2002.
4 //
5 // Copyright (C) 2002  David C. Luff - david.luff@nottingham.ac.uk
6 //
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.
11 //
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.
16 //
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.
20
21 #ifndef _FG_GROUND_HXX
22 #define _FG_GROUND_HXX
23
24 #include <map>
25 #include <vector>
26 #include <list>
27
28 #include <simgear/math/SGMath.hxx>
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/props/props.hxx>
31
32 #include "ATC.hxx"
33 #include "ATCProjection.hxx"
34
35 #include <string>
36
37 class FGATCMgr;
38
39 //////////////////////////////////////////////////////
40 // Types for the logical network data structure
41 enum arc_type {
42         RUNWAY,
43         TAXIWAY
44 };
45
46 enum node_type {
47         GATE,
48         APRON,
49         HOLD,
50         JUNCTION,
51         TJUNCTION
52 };
53
54 enum GateType {
55         TRANSPORT_PASSENGER,
56         TRANSPORT_PASSENGER_NARROWBODY,
57         TRANSPORT_PASSENGER_WIDEBODY,
58         TRANSPORT_CARGO,
59         GA_LOCAL,
60         GA_LOCAL_SINGLE,
61         GA_LOCAL_TWIN,
62         GA_TRANSIENT,
63         GA_TRANSIENT_SINGLE,
64         GA_TRANSIENT_TWIN,
65         OTHER   // ie. anything goes!!
66 };
67
68 enum network_element_type {
69         NODE,
70         ARC
71 };
72
73 struct ground_network_element {
74         network_element_type struct_type;
75 };
76
77 struct arc : public ground_network_element {
78         int distance;
79         std::string name;
80         arc_type type;
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.
86 };
87
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; 
91
92 struct node : public ground_network_element {
93         node();
94         ~node();
95         
96         unsigned int nodeID;    //each node in an airport needs a unique ID number - this is ZERO-BASED to match array position
97         SGGeod pos;
98         SGVec3d orthoPos;
99         std::string name;
100         node_type type;
101         arc_array_type arcs;
102         double max_turn_radius;
103 };
104
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;
108
109 struct Gate : public node {
110         GateType gateType;
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
115         //node* pNode;
116         bool used;
117         double heading; // The direction the parked-up plane should point in degrees
118 };
119
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;
123
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;
128
129 // Runways - all the runway stuff is likely to change in the future
130 struct Rwy {
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.
137 };
138
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;
142
143 // end logical network types
144 ///////////////////////////////////////////////////////
145
146 ///////////////////////////////////////////////////////
147 // Structures to use the network
148
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;
153
154 //////////////////////////////////////////////////////////////////////////////////////////
155
156 ////////////////////////////////////////////////
157 //
158 // Stuff for the shortest-path algorithms
159 struct a_path {
160         a_path();
161         
162         ground_network_path_type path;
163         int cost;
164 };
165
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;
169
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 ////////////////////////////////////////////////
174
175 // Planes active within the ground network.
176
177 // A more specialist plane rec to include ground information
178 struct GroundRec {      
179     PlaneRec plane;
180     node* destination;
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 
184         
185     bool cleared;  // set true when the plane has been cleared to somewhere
186     bool incoming; //true for arrivals, false for departures
187     // status?
188     // Almost certainly need to add more here
189 };
190
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;
194
195 ///////////////////////////////////////////////////////////////////////////////
196 //
197 // FGGround
198 //
199 ///////////////////////////////////////////////////////////////////////////////
200 class FGGround : public FGATC {
201
202 public:
203         FGGround();
204         FGGround(const std::string& id);
205         ~FGGround();
206     void Init();
207
208     void Update(double dt);
209         
210         inline const std::string& get_trans_ident() { return trans_ident; }
211         
212         // Randomly fill some of the available gates and GA parking spots with planes
213         void PopulateGates();
214         
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);
217         
218         // Return a pointer to an unused gate
219         Gate* GetGateNode();
220         
221         // Return a pointer to a hold short node
222         node* GetHoldShortNode(const std::string& rwyID);
223         
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);
228         
229         // Get a path from one node to another
230         ground_network_path_type GetPath(node* A, node* B);
231         
232         // Get a path from a node to a runway threshold
233         ground_network_path_type GetPath(node* A, const std::string& rwyID);
234         
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);
238
239 private:
240         FGATCMgr* ATCmgr;       
241         // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
242         
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.
249
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;
254         
255         // A map of all the gates indexed against internal (FGFS) ID
256         gate_map_type gates;
257         gate_map_iterator gatesItr;
258
259         FGATCAlignedProjection ortho;
260         
261         // Planes currently active
262     //ground_rec_list ground_traffic;
263
264     // Find the shortest route through the logical network between two points.
265     //FindShortestRoute(point a, point b);
266
267     // Assign a gate or parking location to a new arrival
268     //AssignGate(ground_rec &g);
269
270     // Generate the next clearance for an airplane
271     //NextClearance(ground_rec &g);
272         
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
276         
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
281         
282         // Tower control
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
285
286         // Logical runway details - this might change in the future.
287         //runway_array_type runways;    // STL way
288         Rwy runways[37];        // quick hack!
289         
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.
294         
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.
299         void DoRwyDetails();    
300         
301         // Load the logical ground network for this airport from file.
302         // Return true if successfull.
303         bool LoadNetwork();
304         
305         // Parse a runway exit string and push the supplied node pointer onto the runway exit list
306         void ParseRwyExits(node* np, char* es);
307         
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();
314         
315         // Return a pointer to the node at a runway threshold
316         // Returns NULL if unsuccessful.
317         node* GetThresholdNode(const std::string& rwyID);
318         
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); 
321         
322         // Planes
323         ground_rec_list ground_traffic;
324         ground_rec_list_itr ground_traffic_itr;
325 };
326
327 #endif  // _FG_GROUND_HXX
328