Debian Codegraph @

src/ATC/trafficcontrol.hxx

raw symbols SCIP
1 // trafficcontrol.hxx - classes to manage AIModels based air traffic control
2 // Written by Durk Talsma, started September 2006.
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License as
6 // published by the Free Software Foundation; either version 2 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 //
18 // $Id$
19
20
21 #ifndef _TRAFFIC_CONTROL_HXX_
22 #define _TRAFFIC_CONTROL_HXX_
23
24 #include <Airports/airports_fwd.hxx>
25
26 #include <osg/Geode>
27 #include <osg/Geometry>
28 #include <osg/MatrixTransform>
29 #include <osg/Shape>
30
31 #include <simgear/compiler.h>
32 // There is probably a better include than sg_geodesy to get the SG_NM_TO_METER...
33 #include <simgear/math/sg_geodesy.hxx>
34 #include <simgear/debug/logstream.hxx>
35 #include <simgear/structure/SGReferenced.hxx>
36 #include <simgear/structure/SGSharedPtr.hxx>
37
38 class FGAIAircraft;
39 typedef std::vector<FGAIAircraft*> AircraftVec;
40 typedef std::vector<FGAIAircraft*>::iterator AircraftVecIterator;
41
42 class FGAIFlightPlan;
43 typedef std::vector<FGAIFlightPlan*> FlightPlanVec;
44 typedef std::vector<FGAIFlightPlan*>::iterator FlightPlanVecIterator;
45 typedef std::map<std::string, FlightPlanVec> FlightPlanVecMap;
46
47 class FGTrafficRecord;
48 typedef std::list<FGTrafficRecord> TrafficVector;
49 typedef std::list<FGTrafficRecord>::iterator TrafficVectorIterator;
50
51 class ActiveRunway;
52 typedef std::vector<ActiveRunway> ActiveRunwayVec;
53 typedef std::vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
54
55 typedef std::vector<int> intVec;
56 typedef std::vector<int>::iterator intVecIterator;
57
58 /**************************************************************************************
59 * class FGATCInstruction
60 * like class FGATC Controller, this class definition should go into its own file
61 * and or directory... For now, just testing this stuff out though...
62 *************************************************************************************/
63 class FGATCInstruction
64 {
65 private:
66 bool holdPattern;
67 int requestedArrivalTime{0};
68 bool holdPosition;
69 bool changeSpeed;
70 bool changeHeading;
71 bool changeAltitude;
72 bool resolveCircularWait;
73
74 double speed;
75 double heading;
76 double alt;
77 public:
78 FGATCInstruction();
79
80 bool hasInstruction () const;
81 bool getHoldPattern () const {
82 return holdPattern;
83 };
84 void setRunwaySlot (int val) {
85 requestedArrivalTime = val;
86 };
87 int getRunwaySlot () const {
88 return requestedArrivalTime;
89 };
90 bool getHoldPosition () const {
91 return holdPosition;
92 };
93 bool getChangeSpeed () const {
94 return changeSpeed;
95 };
96 bool getChangeHeading () const {
97 return changeHeading;
98 };
99 bool getChangeAltitude() const {
100 return changeAltitude;
101 };
102 bool getCheckForCircularWait() const {
103 return resolveCircularWait;
104 };
105
106 double getSpeed () const {
107 return speed;
108 };
109 double getHeading () const {
110 return heading;
111 };
112 double getAlt () const {
113 return alt;
114 };
115
116 void setHoldPattern (bool val) {
117 holdPattern = val;
118 };
119 void setHoldPosition (bool val) {
120 holdPosition = val;
121 };
122 void setChangeSpeed (bool val) {
123 changeSpeed = val;
124 };
125 void setChangeHeading (bool val) {
126 changeHeading = val;
127 };
128 void setChangeAltitude(bool val) {
129 changeAltitude = val;
130 };
131 void setResolveCircularWait (bool val) {
132 resolveCircularWait = val;
133 };
134
135 void setSpeed (double val) {
136 speed = val;
137 };
138 void setHeading (double val) {
139 heading = val;
140 };
141 void setAlt (double val) {
142 alt = val;
143 };
144 };
145
146
147 /**************************************************************************************
148 * class FGTrafficRecord
149 * Represents the interaction of an AI Aircraft and ATC
150 *************************************************************************************/
151 class FGTrafficRecord
152 {
153 private:
154 int id;
155 int waitsForId;
156 int currentPos;
157 int leg;
158 int frequencyId;
159 int state;
160 bool allowTransmission;
161 bool allowPushback;
162 int priority;
163 int plannedArrivalTime{0};
164 time_t timer;
165 intVec intentions;
166 FGATCInstruction instruction;
167 SGGeod pos;
168 double heading, speed, altitude, radius;
169 std::string callsign;
170 std::string runway;
171 SGSharedPtr<FGAIAircraft> aircraft;
172
173
174 public:
175 FGTrafficRecord();
176 virtual ~FGTrafficRecord();
177
178 void setId(int val) {
179 id = val;
180 };
181 void setRadius(double rad) {
182 radius = rad;
183 };
184 void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
185 void setRunway(const std::string& rwy) {
186 runway = rwy;
187 };
188 void setLeg(int lg) {
189 leg = lg;
190 };
191 int getId() const {
192 return id;
193 };
194 /**
195 * Return the current ATC State of type @see ATCMessageState
196 */
197 int getState() const {
198 return state;
199 };
200 /**
201 * Set the current ATC State of type @see ATCMessageState
202 */
203 void setState(int s) {
204 state = s;
205 }
206 FGATCInstruction getInstruction() const {
207 return instruction;
208 };
209 bool hasInstruction() const {
210 return instruction.hasInstruction();
211 };
212 void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
213 bool checkPositionAndIntentions(FGTrafficRecord &other);
214 int crosses (FGGroundNetwork *, FGTrafficRecord &other);
215 bool isOpposing (FGGroundNetwork *, FGTrafficRecord &other, int node);
216
217 bool isActive(int margin) const;
218 bool isDead() const;
219 void clearATCController() const;
220
221 bool onRoute(FGGroundNetwork *, FGTrafficRecord &other);
222
223 bool getSpeedAdjustment() const {
224 return instruction.getChangeSpeed();
225 };
226 void setPlannedArrivalTime (int val) {
227 plannedArrivalTime = val;
228 };
229 /**Arrival time planned by aircraft.*/
230 int getPlannedArrivalTime () const {
231 return plannedArrivalTime;
232 };
233 void setRunwaySlot( int val ) {
234 if (plannedArrivalTime) {
235 SG_LOG(SG_ATC, SG_BULK, callsign << "| Runwayslot " << (val-plannedArrivalTime));
236 }
237 instruction.setRunwaySlot(val);
238 };
239 /**Arrival time requested by ATC.*/
240 int getRunwaySlot() {
241 return instruction.getRunwaySlot();
242 };
243 SGGeod getPos() {
244 return pos;
245 }
246 double getHeading () const {
247 return heading ;
248 };
249 double getSpeed () const {
250 return speed ;
251 };
252 double getFAltitude () const {
253 return altitude ;
254 };
255 double getRadius () const {
256 return radius ;
257 };
258
259 int getWaitsForId () const {
260 return waitsForId;
261 };
262
263 void setSpeedAdjustment(double spd);
264 void setHeadingAdjustment(double heading);
265 void clearSpeedAdjustment () {
266 instruction.setChangeSpeed (false);
267 };
268 void clearHeadingAdjustment() {
269 instruction.setChangeHeading(false);
270 };
271
272 bool hasHeadingAdjustment() const {
273 return instruction.getChangeHeading();
274 };
275 bool hasHoldPosition() const {
276 return instruction.getHoldPosition();
277 };
278 void setHoldPosition (bool inst) {
279 instruction.setHoldPosition(inst);
280 };
281 void setWaitsForId(int id) {
282 waitsForId = id;
283 };
284
285 void setResolveCircularWait() {
286 instruction.setResolveCircularWait(true);
287 };
288 void clearResolveCircularWait() {
289 instruction.setResolveCircularWait(false);
290 };
291
292 void setCallsign(const std::string& clsgn) { callsign = clsgn; };
293 const std::string& getCallsign() const {
294 return callsign;
295 };
296
297 const std::string& getRunway() const {
298 return runway;
299 };
300
301 void setAircraft(FGAIAircraft *ref);
302
303 void updateState() {
304 state++;
305 allowTransmission=true;
306 };
307
308 FGAIAircraft *getAircraft() const;
309
310 int getTime() const {
311 return timer;
312 };
313 int getLeg() const {
314 return leg;
315 };
316 void setTime(time_t time) {
317 timer = time;
318 };
319
320 bool pushBackAllowed() const;
321 bool allowTransmissions() const {
322 return allowTransmission;
323 };
324 void allowPushBack() { allowPushback =true;};
325 void denyPushBack () { allowPushback = false;};
326 void suppressRepeatedTransmissions () {
327 allowTransmission=false;
328 };
329 void allowRepeatedTransmissions () {
330 allowTransmission=true;
331 };
332 void nextFrequency() {
333 frequencyId++;
334 };
335 int getNextFrequency() const {
336 return frequencyId;
337 };
338 intVec& getIntentions() {
339 return intentions;
340 };
341 int getCurrentPosition() const {
342 return currentPos;
343 };
344 void setPriority(int p) { priority = p; };
345 int getPriority() const { return priority; };
346 };
347
348 /***********************************************************************
349 * Active runway, a utility class to keep track of which aircraft has
350 * clearance for a given runway.
351 **********************************************************************/
352 class ActiveRunway
353 {
354 private:
355 const std::string rwy;
356 int currentlyCleared;
357 double distanceToFinal;
358 TimeVector estimatedArrivalTimes;
359
360 using AircraftRefVec = std::vector<SGSharedPtr<FGAIAircraft>>;
361 AircraftRefVec departureQueue;
362
363 public:
364 ActiveRunway(const std::string& r, int cc);
365
366 const std::string& getRunwayName() const
367 {
368 return rwy;
369 };
370 int getCleared() const
371 {
372 return currentlyCleared;
373 };
374 double getApproachDistance() const
375 {
376 return distanceToFinal;
377 };
378 //time_t getEstApproachTime() { return estimatedArrival; };
379
380 //void setEstApproachTime(time_t time) { estimatedArrival = time; };
381 void addToDepartureQueue(FGAIAircraft *ac);
382
383 void setCleared(int number) {
384 currentlyCleared = number;
385 };
386 time_t requestTimeSlot(time_t eta);
387 //time_t requestTimeSlot(time_t eta, std::string wakeCategory);
388 void slotHousekeeping(time_t newEta);
389 int getdepartureQueueSize() {
390 return departureQueue.size();
391 };
392
393 SGSharedPtr<FGAIAircraft> getFirstAircraftInDepartureQueue() const;
394
395 SGSharedPtr<FGAIAircraft> getFirstOfStatus(int stat) const;
396
397 void removeFromDepartureQueue(int id);
398
399 void updateDepartureQueue();
400
401 void printDepartureQueue();
402 };
403
404
405 #endif // _TRAFFIC_CONTROL_HXX