2002-04-03 23:54:44 +00:00
|
|
|
// FGTower - a class to provide tower control at towered airports.
|
|
|
|
//
|
|
|
|
// Written by David Luff, started March 2002.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2002 David C. Luff - david.luff@nottingham.ac.uk
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
#ifndef _FG_TOWER_HXX
|
|
|
|
#define _FG_TOWER_HXX
|
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
|
|
|
#include <simgear/math/point3d.hxx>
|
|
|
|
#include <simgear/misc/sgstream.hxx>
|
2003-03-27 15:41:09 +00:00
|
|
|
//#include <simgear/math/sg_geodesy.hxx>
|
2002-04-03 23:54:44 +00:00
|
|
|
#include <plib/sg.h>
|
2003-03-27 15:41:09 +00:00
|
|
|
//#include <Airports/runways.hxx>
|
2002-04-03 23:54:44 +00:00
|
|
|
|
2002-04-04 20:47:23 +00:00
|
|
|
#include STL_IOSTREAM
|
|
|
|
#include STL_STRING
|
2002-04-03 23:54:44 +00:00
|
|
|
|
|
|
|
SG_USING_STD(string);
|
2002-04-04 01:32:00 +00:00
|
|
|
SG_USING_STD(ios);
|
2002-04-03 23:54:44 +00:00
|
|
|
|
|
|
|
#include "ATC.hxx"
|
2002-12-04 20:06:20 +00:00
|
|
|
//#include "ATCmgr.hxx"
|
|
|
|
#include "ground.hxx"
|
2003-03-27 15:41:09 +00:00
|
|
|
#include "ATCProjection.hxx"
|
2003-04-15 22:55:22 +00:00
|
|
|
#include "AIPlane.hxx"
|
2002-04-03 23:54:44 +00:00
|
|
|
|
|
|
|
//DCL - a complete guess for now.
|
|
|
|
#define FG_TOWER_DEFAULT_RANGE 30
|
|
|
|
|
2003-03-10 13:41:37 +00:00
|
|
|
enum tower_traffic_type {
|
|
|
|
CIRCUIT,
|
2003-09-22 23:57:57 +00:00
|
|
|
INBOUND, // CIRCUIT traffic gets changed to INBOUND when on final of the full-stop circuit.
|
2003-03-10 13:41:37 +00:00
|
|
|
OUTBOUND,
|
2003-04-15 22:55:22 +00:00
|
|
|
TTT_UNKNOWN, // departure, but we don't know if for circuits or leaving properly
|
2003-03-10 13:41:37 +00:00
|
|
|
STRAIGHT_IN
|
2003-09-22 23:57:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ostream& operator << (ostream& os, tower_traffic_type ttt);
|
|
|
|
|
|
|
|
// TODO - need some differentiation of IFR and VFR traffic in order to give the former priority.
|
2003-03-10 13:41:37 +00:00
|
|
|
|
2002-12-04 20:06:20 +00:00
|
|
|
// Structure for holding details of a plane under tower control.
|
|
|
|
// Not fixed yet - may include more stuff later.
|
|
|
|
class TowerPlaneRec {
|
|
|
|
|
2003-03-27 15:41:09 +00:00
|
|
|
public:
|
2002-12-04 20:06:20 +00:00
|
|
|
|
|
|
|
TowerPlaneRec();
|
2003-03-27 15:41:09 +00:00
|
|
|
TowerPlaneRec(PlaneRec p);
|
2002-12-04 20:06:20 +00:00
|
|
|
TowerPlaneRec(Point3D pt);
|
2003-03-27 15:41:09 +00:00
|
|
|
TowerPlaneRec(PlaneRec p, Point3D pt);
|
|
|
|
|
2003-04-15 22:55:22 +00:00
|
|
|
FGAIPlane* planePtr; // This might move to the planeRec eventually
|
2003-03-27 15:41:09 +00:00
|
|
|
PlaneRec plane;
|
2002-12-04 20:06:20 +00:00
|
|
|
|
|
|
|
Point3D pos;
|
2003-03-27 15:41:09 +00:00
|
|
|
double eta; // seconds
|
|
|
|
double dist_out; // meters from theshold
|
2002-12-04 20:06:20 +00:00
|
|
|
bool clearedToLand;
|
2003-03-27 15:41:09 +00:00
|
|
|
bool clearedToLineUp;
|
|
|
|
bool clearedToTakeOff;
|
2002-12-04 20:06:20 +00:00
|
|
|
// ought to add time cleared to depart so we can nag if necessary
|
2003-03-27 15:41:09 +00:00
|
|
|
bool holdShortReported;
|
2003-10-15 14:10:30 +00:00
|
|
|
bool downwindReported;
|
2002-12-04 20:06:20 +00:00
|
|
|
bool longFinalReported;
|
|
|
|
bool longFinalAcknowledged;
|
|
|
|
bool finalReported;
|
|
|
|
bool finalAcknowledged;
|
2003-03-27 15:41:09 +00:00
|
|
|
bool onRwy; // is physically on the runway
|
|
|
|
bool nextOnRwy; // currently projected by tower to be the next on the runway
|
|
|
|
|
2003-03-10 13:41:37 +00:00
|
|
|
// Type of operation the plane is doing
|
|
|
|
tower_traffic_type opType;
|
2003-03-27 15:41:09 +00:00
|
|
|
|
|
|
|
// Whereabouts in circuit if doing circuits
|
2003-04-15 22:55:22 +00:00
|
|
|
PatternLeg leg;
|
2003-03-27 15:41:09 +00:00
|
|
|
|
2003-09-22 23:57:57 +00:00
|
|
|
LandingType landingType;
|
|
|
|
|
2003-03-27 15:41:09 +00:00
|
|
|
bool isUser; // true if this plane is the user
|
2002-12-04 20:06:20 +00:00
|
|
|
};
|
2002-04-03 23:54:44 +00:00
|
|
|
|
2003-03-10 13:41:37 +00:00
|
|
|
|
2002-12-04 20:06:20 +00:00
|
|
|
typedef list < TowerPlaneRec* > tower_plane_rec_list_type;
|
2003-01-17 16:45:26 +00:00
|
|
|
typedef tower_plane_rec_list_type::iterator tower_plane_rec_list_iterator;
|
|
|
|
typedef tower_plane_rec_list_type::const_iterator tower_plane_rec_list_const_iterator;
|
2002-04-03 23:54:44 +00:00
|
|
|
|
|
|
|
|
2002-12-04 20:06:20 +00:00
|
|
|
class FGTower : public FGATC {
|
2002-04-03 23:54:44 +00:00
|
|
|
|
2003-03-10 13:41:37 +00:00
|
|
|
public:
|
2002-12-04 20:06:20 +00:00
|
|
|
|
|
|
|
FGTower();
|
|
|
|
~FGTower();
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
|
2003-03-27 15:41:09 +00:00
|
|
|
void Update(double dt);
|
2002-12-17 11:36:14 +00:00
|
|
|
|
|
|
|
void RequestLandingClearance(string ID);
|
|
|
|
void RequestDepartureClearance(string ID);
|
2002-12-04 20:06:20 +00:00
|
|
|
void ReportFinal(string ID);
|
|
|
|
void ReportLongFinal(string ID);
|
|
|
|
void ReportOuterMarker(string ID);
|
|
|
|
void ReportMiddleMarker(string ID);
|
|
|
|
void ReportInnerMarker(string ID);
|
|
|
|
void ReportGoingAround(string ID);
|
|
|
|
void ReportRunwayVacated(string ID);
|
2003-03-27 15:41:09 +00:00
|
|
|
void ReportReadyForDeparture(string ID);
|
2003-10-06 15:20:47 +00:00
|
|
|
void ReportDownwind(string ID);
|
2003-03-27 15:41:09 +00:00
|
|
|
|
2003-04-15 22:55:22 +00:00
|
|
|
// Contact tower when at a hold short for departure - for now we'll assume plane - maybe vehicles might want to cross runway eventually?
|
|
|
|
void ContactAtHoldShort(PlaneRec plane, FGAIPlane* requestee, tower_traffic_type operation);
|
2002-12-04 20:06:20 +00:00
|
|
|
|
2003-03-27 15:41:09 +00:00
|
|
|
// Public interface to the active runway - this will get more complex
|
|
|
|
// in the future and consider multi-runway use, airplane weight etc.
|
|
|
|
inline string GetActiveRunway() { return activeRwy; }
|
2003-03-28 15:24:02 +00:00
|
|
|
inline RunwayDetails GetActiveRunwayDetails() { return rwy; }
|
2003-03-27 15:41:09 +00:00
|
|
|
|
|
|
|
inline void SetDisplay() { display = true; }
|
|
|
|
inline void SetNoDisplay() { display = false; }
|
2002-12-04 20:06:20 +00:00
|
|
|
|
|
|
|
inline string get_trans_ident() { return trans_ident; }
|
|
|
|
inline atc_type GetType() { return TOWER; }
|
|
|
|
|
2003-03-27 15:41:09 +00:00
|
|
|
inline FGGround* GetGroundPtr() { return ground; }
|
2003-06-11 21:49:46 +00:00
|
|
|
|
|
|
|
// Returns true if positions of crosswind/downwind/base leg turns should be constrained by previous traffic
|
|
|
|
// plus the constraint position as a rwy orientated orthopos (meters)
|
|
|
|
bool GetCrosswindConstraint(double& cpos);
|
|
|
|
bool GetDownwindConstraint(double& dpos);
|
|
|
|
bool GetBaseConstraint(double& bpos);
|
2003-03-10 13:41:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
FGATCMgr* ATCmgr;
|
|
|
|
// This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
|
2003-10-14 11:10:17 +00:00
|
|
|
|
2003-10-15 14:10:30 +00:00
|
|
|
// Respond to a transmission
|
|
|
|
void Respond();
|
|
|
|
|
2003-10-14 11:10:17 +00:00
|
|
|
void CheckHoldList(double dt);
|
|
|
|
|
|
|
|
void CheckCircuitList(double dt);
|
|
|
|
|
|
|
|
void CheckRunwayList(double dt);
|
|
|
|
|
|
|
|
void CheckApproachList(double dt);
|
2003-10-15 14:10:30 +00:00
|
|
|
|
2003-10-15 21:50:05 +00:00
|
|
|
// Currently this assumes we *are* next on the runway and doesn't check for planes about to land -
|
|
|
|
// this should be done prior to calling this function.
|
|
|
|
void ClearHoldingPlane(TowerPlaneRec* t);
|
|
|
|
|
2003-10-15 14:10:30 +00:00
|
|
|
// Find a pointer to plane of callsign ID within the internal data structures
|
|
|
|
TowerPlaneRec* FindPlane(string ID);
|
|
|
|
|
2003-03-27 15:41:09 +00:00
|
|
|
// Figure out if a given position lies on the active runway
|
|
|
|
// Might have to change when we consider more than one active rwy.
|
|
|
|
bool OnActiveRunway(Point3D pt);
|
|
|
|
|
|
|
|
// Figure out if a given position lies on a runway or not
|
|
|
|
bool OnAnyRunway(Point3D pt);
|
2003-03-10 13:41:37 +00:00
|
|
|
|
2003-09-19 16:51:27 +00:00
|
|
|
// Calculate the eta of a plane to the threshold.
|
2003-03-10 13:41:37 +00:00
|
|
|
// For ground traffic this is the fastest they can get there.
|
|
|
|
// For air traffic this is the middle approximation.
|
2003-09-22 23:57:57 +00:00
|
|
|
void CalcETA(TowerPlaneRec* tpr, bool printout = false);
|
2003-09-19 16:51:27 +00:00
|
|
|
|
|
|
|
// Iterate through all the lists and call CalcETA for all the planes.
|
2003-03-10 13:41:37 +00:00
|
|
|
void doThresholdETACalc();
|
|
|
|
|
|
|
|
// Order the list of traffic as per expected threshold use and flag any conflicts
|
|
|
|
bool doThresholdUseOrder();
|
2002-12-04 20:06:20 +00:00
|
|
|
|
2003-09-19 16:51:27 +00:00
|
|
|
// Calculate the crow-flys distance of a plane to the threshold in meters
|
|
|
|
double CalcDistOutM(TowerPlaneRec* tpr);
|
|
|
|
|
|
|
|
// Calculate the crow-flys distance of a plane to the threshold in miles
|
|
|
|
double CalcDistOutMiles(TowerPlaneRec* tpr);
|
|
|
|
|
2003-09-22 23:57:57 +00:00
|
|
|
/*
|
2003-03-10 13:41:37 +00:00
|
|
|
void doCommunication();
|
2003-09-22 23:57:57 +00:00
|
|
|
*/
|
2002-12-04 20:06:20 +00:00
|
|
|
|
|
|
|
void IssueLandingClearance(TowerPlaneRec* tpr);
|
|
|
|
void IssueGoAround(TowerPlaneRec* tpr);
|
|
|
|
void IssueDepartureClearance(TowerPlaneRec* tpr);
|
|
|
|
|
2003-09-22 23:57:57 +00:00
|
|
|
unsigned int update_count; // Convienince counter for speading computational load over several updates
|
|
|
|
unsigned int update_count_max; // ditto.
|
|
|
|
|
2002-12-04 20:06:20 +00:00
|
|
|
bool display; // Flag to indicate whether we should be outputting to the ATC display.
|
|
|
|
bool displaying; // Flag to indicate whether we are outputting to the ATC display.
|
|
|
|
|
2003-09-22 23:57:57 +00:00
|
|
|
double timeSinceLastDeparture; // Time in seconds since last departure from active rwy.
|
|
|
|
bool departed; // set true when the above needs incrementing with time, false when it doesn't.
|
|
|
|
|
2003-03-27 15:41:09 +00:00
|
|
|
// environment - need to make sure we're getting the surface winds and not winds aloft.
|
|
|
|
SGPropertyNode* wind_from_hdg; //degrees
|
|
|
|
SGPropertyNode* wind_speed_knots; //knots
|
|
|
|
|
|
|
|
double aptElev; // Airport elevation
|
|
|
|
string activeRwy; // Active runway number - For now we'll disregard multiple / alternate runway operation.
|
|
|
|
RunwayDetails rwy; // Assumed to be the active one for now.
|
|
|
|
bool rwyOccupied; // Active runway occupied flag. For now we'll disregard land-and-hold-short operations.
|
|
|
|
FGATCAlignedProjection ortho; // Orthogonal mapping of the local area with the active runway threshold at the origin
|
|
|
|
|
|
|
|
// Figure out which runways are active.
|
|
|
|
// For now we'll just be simple and do one active runway - eventually this will get much more complex
|
|
|
|
// This is a private function - public interface to the results of this is through GetActiveRunway
|
|
|
|
void DoRwyDetails();
|
2003-03-10 13:41:37 +00:00
|
|
|
|
2002-12-04 20:06:20 +00:00
|
|
|
// Need a data structure to hold details of the various active planes
|
|
|
|
// or possibly another data structure with the positions of the inactive planes.
|
|
|
|
// Need a data structure to hold outstanding communications from aircraft.
|
2003-03-27 15:41:09 +00:00
|
|
|
|
2003-09-19 16:51:27 +00:00
|
|
|
// Linked-list of planes on approach to active rwy ordered with nearest first (timewise).
|
2002-12-04 20:06:20 +00:00
|
|
|
// Includes planes that have landed but not yet vacated runway.
|
|
|
|
// Somewhat analagous to the paper strips used (used to be used?) in real life.
|
2003-03-27 15:41:09 +00:00
|
|
|
// Doesn't include planes in circuit until they turn onto base/final?
|
2003-09-19 16:51:27 +00:00
|
|
|
// TODO - may need to alter this for operation to more than one active rwy.
|
2002-12-04 20:06:20 +00:00
|
|
|
tower_plane_rec_list_type appList;
|
2003-03-27 15:41:09 +00:00
|
|
|
tower_plane_rec_list_iterator appListItr;
|
2003-09-19 16:51:27 +00:00
|
|
|
|
|
|
|
// What should we do with planes approaching the airport to join the circuit somewhere
|
|
|
|
// but not on straight-in though? - put them in here for now.
|
|
|
|
tower_plane_rec_list_type circuitAppList;
|
|
|
|
tower_plane_rec_list_iterator circuitAppListItr;
|
2002-12-04 20:06:20 +00:00
|
|
|
|
2003-03-27 15:41:09 +00:00
|
|
|
// List of departed planes (planes doing circuits go into circuitList not depList after departure)
|
2002-12-04 20:06:20 +00:00
|
|
|
tower_plane_rec_list_type depList;
|
2003-03-27 15:41:09 +00:00
|
|
|
tower_plane_rec_list_iterator depListItr;
|
|
|
|
|
|
|
|
// List of planes in the circuit (ordered by nearest to landing first)
|
|
|
|
tower_plane_rec_list_type circuitList;
|
|
|
|
tower_plane_rec_list_iterator circuitListItr;
|
2002-12-04 20:06:20 +00:00
|
|
|
|
|
|
|
// List of planes waiting to depart
|
|
|
|
tower_plane_rec_list_type holdList;
|
2003-03-27 15:41:09 +00:00
|
|
|
tower_plane_rec_list_iterator holdListItr;
|
|
|
|
|
2002-12-04 20:06:20 +00:00
|
|
|
// List of planes on rwy
|
|
|
|
tower_plane_rec_list_type rwyList;
|
2003-03-27 15:41:09 +00:00
|
|
|
tower_plane_rec_list_iterator rwyListItr;
|
2003-03-10 13:41:37 +00:00
|
|
|
|
2003-03-27 15:41:09 +00:00
|
|
|
// List of all planes due to use a given rwy arranged in projected order of rwy use
|
2003-03-10 13:41:37 +00:00
|
|
|
tower_plane_rec_list_type trafficList; // TODO - needs to be expandable to more than one rwy
|
2003-03-27 15:41:09 +00:00
|
|
|
tower_plane_rec_list_iterator trafficListItr;
|
2003-09-19 16:51:27 +00:00
|
|
|
|
|
|
|
// Returns true if successful
|
|
|
|
bool RemoveFromTrafficList(string id);
|
|
|
|
|
|
|
|
// Return the ETA of plane no. list_pos (1-based) in the traffic list.
|
|
|
|
// i.e. list_pos = 1 implies next to use runway.
|
2003-09-22 23:57:57 +00:00
|
|
|
double GetTrafficETA(unsigned int list_pos, bool printout = false);
|
2003-09-19 16:51:27 +00:00
|
|
|
|
|
|
|
// Add a tower plane rec with ETA to the traffic list in the correct position ETA-wise.
|
|
|
|
// Returns true if this could cause a threshold ETA conflict with other traffic, false otherwise.
|
|
|
|
bool AddToTrafficList(TowerPlaneRec* t, bool holding = false);
|
2002-12-04 20:06:20 +00:00
|
|
|
|
|
|
|
// Ground can be separate or handled by tower in real life.
|
|
|
|
// In the program we will always use a separate FGGround class, but we need to know
|
|
|
|
// whether it is supposed to be separate or not to give the correct instructions.
|
|
|
|
bool separateGround; // true if ground control is separate
|
2003-03-10 13:41:37 +00:00
|
|
|
FGGround* ground; // The ground control associated with this airport.
|
2002-12-04 20:06:20 +00:00
|
|
|
|
|
|
|
// for failure modeling
|
|
|
|
string trans_ident; // transmitted ident
|
|
|
|
bool tower_failed; // tower failed?
|
|
|
|
|
2003-09-05 10:21:29 +00:00
|
|
|
// Pointers to current users position and orientation
|
|
|
|
SGPropertyNode* user_lon_node;
|
|
|
|
SGPropertyNode* user_lat_node;
|
|
|
|
SGPropertyNode* user_elev_node;
|
|
|
|
SGPropertyNode* user_hdg_node;
|
2003-04-15 22:55:22 +00:00
|
|
|
|
|
|
|
// Details of the general traffic flow etc in the circuit
|
|
|
|
double crosswind_leg_pos; // Distance from threshold crosswind leg is being turned to in meters (actual operation - *not* ideal circuit)
|
|
|
|
double downwind_leg_pos; // Actual offset distance in meters from the runway that planes are flying the downwind leg
|
|
|
|
// Currently not sure whether the above should be always +ve or just take the natural orthopos sign (+ve for RH circuit, -ve for LH).
|
|
|
|
double base_leg_pos; // Actual offset distance from the threshold (-ve) that planes are turning to base leg.
|
2003-03-27 15:41:09 +00:00
|
|
|
|
2002-12-04 20:06:20 +00:00
|
|
|
friend istream& operator>> ( istream&, FGTower& );
|
2002-04-03 23:54:44 +00:00
|
|
|
};
|
|
|
|
|
2002-04-04 01:32:00 +00:00
|
|
|
#endif //_FG_TOWER_HXX
|