1 // trafficcontrol.hxx - classes to manage AIModels based air traffic control
2 // Written by Durk Talsma, started September 2006.
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.
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.
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.
21 #ifndef _TRAFFIC_CONTROL_HXX_
22 #define _TRAFFIC_CONTROL_HXX_
26 # error This library requires C++
30 #include <osg/Geometry>
31 #include <osg/MatrixTransform>
34 #include <simgear/compiler.h>
35 // There is probably a better include than sg_geodesy to get the SG_NM_TO_METER...
36 #include <simgear/math/sg_geodesy.hxx>
37 #include <simgear/debug/logstream.hxx>
38 #include <simgear/structure/SGReferenced.hxx>
39 #include <simgear/structure/SGSharedPtr.hxx>
51 typedef vector<int> intVec;
52 typedef vector<int>::iterator intVecIterator;
55 class FGAIFlightPlan; // forward reference
56 class FGGroundNetwork; // forward reference
57 class FGAIAircraft; // forward reference
58 class FGAirportDynamics;
60 /**************************************************************************************
61 * class FGATCInstruction
62 * like class FGATC Controller, this class definition should go into its own file
63 * and or directory... For now, just testing this stuff out though...
64 *************************************************************************************/
65 class FGATCInstruction
73 bool resolveCircularWait;
81 bool hasInstruction ();
82 bool getHoldPattern () {
85 bool getHoldPosition () {
88 bool getChangeSpeed () {
91 bool getChangeHeading () {
94 bool getChangeAltitude() {
95 return changeAltitude;
101 double getHeading () {
108 bool getCheckForCircularWait() {
109 return resolveCircularWait;
112 void setHoldPattern (bool val) {
115 void setHoldPosition (bool val) {
118 void setChangeSpeed (bool val) {
121 void setChangeHeading (bool val) {
124 void setChangeAltitude(bool val) {
125 changeAltitude = val;
128 void setResolveCircularWait (bool val) {
129 resolveCircularWait = val;
132 void setSpeed (double val) {
135 void setHeading (double val) {
138 void setAlt (double val) {
147 /**************************************************************************************
148 * class FGTrafficRecord
149 *************************************************************************************/
150 class FGTrafficRecord
158 bool allowTransmission;
163 FGATCInstruction instruction;
164 double latitude, longitude, heading, speed, altitude, radius;
166 //FGAISchedule *trafficRef;
167 FGAIAircraft *aircraft;
173 void setId(int val) {
176 void setRadius(double rad) {
179 void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
180 void setRunway(string rwy) {
183 void setLeg(int lg) {
192 void setState(int s) {
195 FGATCInstruction getInstruction() {
198 bool hasInstruction() {
199 return instruction.hasInstruction();
201 void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
202 bool checkPositionAndIntentions(FGTrafficRecord &other);
203 int crosses (FGGroundNetwork *, FGTrafficRecord &other);
204 bool isOpposing (FGGroundNetwork *, FGTrafficRecord &other, int node);
206 bool isActive(int margin);
208 bool onRoute(FGGroundNetwork *, FGTrafficRecord &other);
210 bool getSpeedAdjustment() {
211 return instruction.getChangeSpeed();
214 double getLatitude () {
217 double getLongitude() {
220 double getHeading () {
226 double getAltitude () {
229 double getRadius () {
233 int getWaitsForId () {
237 void setSpeedAdjustment(double spd);
238 void setHeadingAdjustment(double heading);
239 void clearSpeedAdjustment () {
240 instruction.setChangeSpeed (false);
242 void clearHeadingAdjustment() {
243 instruction.setChangeHeading(false);
246 bool hasHeadingAdjustment() {
247 return instruction.getChangeHeading();
249 bool hasHoldPosition() {
250 return instruction.getHoldPosition();
252 void setHoldPosition (bool inst) {
253 instruction.setHoldPosition(inst);
256 void setWaitsForId(int id) {
260 void setResolveCircularWait() {
261 instruction.setResolveCircularWait(true);
263 void clearResolveCircularWait() {
264 instruction.setResolveCircularWait(false);
270 //void setCallSign(string clsgn) { callsign = clsgn; };
271 void setAircraft(FGAIAircraft *ref) {
276 allowTransmission=true;
278 //string getCallSign() { return callsign; };
279 FGAIAircraft *getAircraft() {
288 void setTime(time_t time) {
292 bool pushBackAllowed();
293 bool allowTransmissions() {
294 return allowTransmission;
296 void allowPushBack() { allowPushback =true;};
297 void denyPushBack () { allowPushback = false;};
298 void suppressRepeatedTransmissions () {
299 allowTransmission=false;
301 void allowRepeatedTransmissions () {
302 allowTransmission=true;
304 void nextFrequency() {
307 int getNextFrequency() {
310 intVec& getIntentions() {
313 int getCurrentPosition() {
316 void setPriority(int p) { priority = p; };
317 int getPriority() { return priority; };
320 typedef list<FGTrafficRecord> TrafficVector;
321 typedef list<FGTrafficRecord>::iterator TrafficVectorIterator;
323 typedef vector<time_t> TimeVector;
324 typedef vector<time_t>::iterator TimeVectorIterator;
326 typedef vector<FGAIAircraft*> AircraftVec;
327 typedef vector<FGAIAircraft*>::iterator AircraftVecIterator;
329 /***********************************************************************
330 * Active runway, a utility class to keep track of which aircraft has
331 * clearance for a given runway.
332 **********************************************************************/
337 int currentlyCleared;
338 double distanceToFinal;
339 TimeVector estimatedArrivalTimes;
340 AircraftVec departureCue;
343 ActiveRunway(string r, int cc) {
345 currentlyCleared = cc;
346 distanceToFinal = 6.0 * SG_NM_TO_METER;
349 string getRunwayName() {
353 return currentlyCleared;
355 double getApproachDistance() {
356 return distanceToFinal;
358 //time_t getEstApproachTime() { return estimatedArrival; };
360 //void setEstApproachTime(time_t time) { estimatedArrival = time; };
361 void addToDepartureCue(FGAIAircraft *ac) {
362 departureCue.push_back(ac);
364 void setCleared(int number) {
365 currentlyCleared = number;
367 time_t requestTimeSlot(time_t eta);
369 int getDepartureCueSize() {
370 return departureCue.size();
372 FGAIAircraft* getFirstAircraftInDepartureCue() {
373 return departureCue.size() ? *(departureCue.begin()) : NULL;
375 void updateDepartureCue() {
376 departureCue.erase(departureCue.begin());
380 typedef vector<ActiveRunway> ActiveRunwayVec;
381 typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
384 * class FGATCController
385 * NOTE: this class serves as an abstraction layer for all sorts of ATC controllers.
386 *************************************************************************************/
387 class FGATCController
395 time_t lastTransmission;
400 string formatATCFrequency3_2(int );
401 string genTransponderCode(string fltRules);
402 bool isUserAircraft(FGAIAircraft*);
406 MSG_ANNOUNCE_ENGINE_START,
407 MSG_REQUEST_ENGINE_START,
408 MSG_PERMIT_ENGINE_START,
409 MSG_DENY_ENGINE_START,
410 MSG_ACKNOWLEDGE_ENGINE_START,
411 MSG_REQUEST_PUSHBACK_CLEARANCE,
412 MSG_PERMIT_PUSHBACK_CLEARANCE,
413 MSG_HOLD_PUSHBACK_CLEARANCE,
414 MSG_ACKNOWLEDGE_SWITCH_GROUND_FREQUENCY,
415 MSG_INITIATE_CONTACT,
416 MSG_ACKNOWLEDGE_INITIATE_CONTACT,
417 MSG_REQUEST_TAXI_CLEARANCE,
418 MSG_ISSUE_TAXI_CLEARANCE,
419 MSG_ACKNOWLEDGE_TAXI_CLEARANCE,
421 MSG_ACKNOWLEDGE_HOLD_POSITION,
423 MSG_ACKNOWLEDGE_RESUME_TAXI,
424 MSG_REPORT_RUNWAY_HOLD_SHORT,
425 MSG_ACKNOWLEDGE_REPORT_RUNWAY_HOLD_SHORT,
426 MSG_SWITCH_TOWER_FREQUENCY,
427 MSG_ACKNOWLEDGE_SWITCH_TOWER_FREQUENCY
435 virtual ~FGATCController();
438 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
439 double lat, double lon,
440 double hdg, double spd, double alt, double radius, int leg,
441 FGAIAircraft *aircraft) = 0;
442 virtual void signOff(int id) = 0;
443 virtual void updateAircraftInformation(int id, double lat, double lon,
444 double heading, double speed, double alt, double dt) = 0;
445 virtual bool hasInstruction(int id) = 0;
446 virtual FGATCInstruction getInstruction(int id) = 0;
451 void setDt(double dt) {
454 void transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir msgDir, bool audible);
455 string getGateName(FGAIAircraft *aircraft);
456 virtual void render(bool) = 0;
457 virtual string getName() = 0;
459 virtual void update(double) = 0;
464 AtcMsgDir lastTransmissionDirection;
467 /******************************************************************************
468 * class FGTowerControl
469 *****************************************************************************/
470 class FGTowerController : public FGATCController
473 TrafficVector activeTraffic;
474 ActiveRunwayVec activeRunways;
475 FGAirportDynamics *parent;
478 FGTowerController(FGAirportDynamics *parent);
479 virtual ~FGTowerController() {};
480 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
481 double lat, double lon,
482 double hdg, double spd, double alt, double radius, int leg,
483 FGAIAircraft *aircraft);
484 virtual void signOff(int id);
485 virtual void updateAircraftInformation(int id, double lat, double lon,
486 double heading, double speed, double alt, double dt);
487 virtual bool hasInstruction(int id);
488 virtual FGATCInstruction getInstruction(int id);
490 virtual void render(bool);
491 virtual string getName();
492 virtual void update(double dt);
493 bool hasActiveTraffic() {
494 return activeTraffic.size() != 0;
496 TrafficVector &getActiveTraffic() {
497 return activeTraffic;
501 /******************************************************************************
502 * class FGStartupController
504 *****************************************************************************/
506 class FGStartupController : public FGATCController
509 TrafficVector activeTraffic;
510 //ActiveRunwayVec activeRunways;
511 FGAirportDynamics *parent;
514 FGStartupController(FGAirportDynamics *parent);
515 virtual ~FGStartupController() {};
516 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
517 double lat, double lon,
518 double hdg, double spd, double alt, double radius, int leg,
519 FGAIAircraft *aircraft);
520 virtual void signOff(int id);
521 virtual void updateAircraftInformation(int id, double lat, double lon,
522 double heading, double speed, double alt, double dt);
523 virtual bool hasInstruction(int id);
524 virtual FGATCInstruction getInstruction(int id);
526 virtual void render(bool);
527 virtual string getName();
528 virtual void update(double dt);
530 bool hasActiveTraffic() {
531 return activeTraffic.size() != 0;
533 TrafficVector &getActiveTraffic() {
534 return activeTraffic;
537 // Hpoefully, we can move this function to the base class, but I need to verify what is needed for the other controllers before doing so.
538 bool checkTransmissionState(int st, time_t now, time_t startTime, TrafficVectorIterator i, AtcMsgId msgId,
543 /******************************************************************************
544 * class FGTowerControl
545 *****************************************************************************/
546 class FGApproachController : public FGATCController
549 TrafficVector activeTraffic;
550 ActiveRunwayVec activeRunways;
551 FGAirportDynamics *parent;
554 FGApproachController(FGAirportDynamics * parent);
555 virtual ~FGApproachController() { };
556 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
557 double lat, double lon,
558 double hdg, double spd, double alt, double radius, int leg,
559 FGAIAircraft *aircraft);
560 virtual void signOff(int id);
561 virtual void updateAircraftInformation(int id, double lat, double lon,
562 double heading, double speed, double alt, double dt);
563 virtual bool hasInstruction(int id);
564 virtual FGATCInstruction getInstruction(int id);
566 virtual void render(bool);
567 virtual string getName();
568 virtual void update(double dt);
570 ActiveRunway* getRunway(string name);
572 bool hasActiveTraffic() {
573 return activeTraffic.size() != 0;
575 TrafficVector &getActiveTraffic() {
576 return activeTraffic;
581 #endif // _TRAFFIC_CONTROL_HXX