1
0
Fork 0

Merge branch 'durk/ai-atc'

This commit is contained in:
Tim Moore 2010-05-06 11:05:59 +02:00
commit 2a9bf393c3
9 changed files with 1237 additions and 1143 deletions

View file

@ -80,6 +80,7 @@ FGAIAircraft::FGAIAircraft(FGAISchedule *ref) : FGAIBase(otAircraft) {
headingError = 0; headingError = 0;
holdPos = false; holdPos = false;
needsTaxiClearance = false;
_performance = 0; //TODO initialize to JET_TRANSPORT from PerformanceDB _performance = 0; //TODO initialize to JET_TRANSPORT from PerformanceDB
dt = 0; dt = 0;
@ -663,9 +664,8 @@ bool FGAIAircraft::handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t
//cerr << trafficRef->getCallSign() << " has passed waypoint " << prev->name << " at speed " << speed << endl; //cerr << trafficRef->getCallSign() << " has passed waypoint " << prev->name << " at speed " << speed << endl;
if (prev->name == "PushBackPoint") { if (prev->name == "PushBackPoint") {
dep->getDynamics()->releaseParking(fp->getGate()); dep->getDynamics()->releaseParking(fp->getGate());
time_t holdUntil = now + 120; AccelTo(0.0);
fp->setTime(holdUntil); setTaxiClearanceRequest(true);
//cerr << _getCallsign() << "Holding at pushback point" << endl;
} }
// This is the last taxi waypoint, and marks the the end of the flight plan // This is the last taxi waypoint, and marks the the end of the flight plan

View file

@ -70,6 +70,8 @@ public:
void announcePositionToController(); //TODO have to be public? void announcePositionToController(); //TODO have to be public?
void processATC(FGATCInstruction instruction); void processATC(FGATCInstruction instruction);
void setTaxiClearanceRequest(bool arg) { needsTaxiClearance = arg; };
bool getTaxiClearanceRequest() { return needsTaxiClearance; };
FGAISchedule * getTrafficRef() { return trafficRef; }; FGAISchedule * getTrafficRef() { return trafficRef; };
virtual const char* getTypeString(void) const { return "aircraft"; } virtual const char* getTypeString(void) const { return "aircraft"; }
@ -150,6 +152,7 @@ private:
const char * _getTransponderCode() const; const char * _getTransponderCode() const;
bool reachedWaypoint; bool reachedWaypoint;
bool needsTaxiClearance;
time_t timeElapsed; time_t timeElapsed;
PerformanceData* _performance; // the performance data for this aircraft PerformanceData* _performance; // the performance data for this aircraft

View file

@ -340,11 +340,27 @@ FGATCInstruction::FGATCInstruction()
alt = 0; alt = 0;
} }
bool FGATCInstruction::hasInstruction() bool FGATCInstruction::hasInstruction()
{ {
return (holdPattern || holdPosition || changeSpeed || changeHeading || changeAltitude || resolveCircularWait); return (holdPattern || holdPosition || changeSpeed || changeHeading || changeAltitude || resolveCircularWait);
} }
/***************************************************************************
* FGATCController
*
**************************************************************************/
FGATCController::FGATCController()
{
dt_count = 0;
available = true;
lastTransmission = 0;
}
string FGATCController::getGateName(FGAIAircraft *ref) string FGATCController::getGateName(FGAIAircraft *ref)
{ {
return ref->atGate(); return ref->atGate();
@ -370,6 +386,7 @@ void FGATCController::transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir m
//double commFreqD; //double commFreqD;
sender = rec->getAircraft()->getTrafficRef()->getCallSign(); sender = rec->getAircraft()->getTrafficRef()->getCallSign();
//cerr << "transmitting for: " << sender << "Leg = " << rec->getLeg() << endl;
switch (rec->getLeg()) { switch (rec->getLeg()) {
case 2: case 2:
case 3: case 3:
@ -449,6 +466,12 @@ void FGATCController::transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir m
taxiFreqStr = formatATCFrequency3_2(taxiFreq); taxiFreqStr = formatATCFrequency3_2(taxiFreq);
text = receiver + ". Switching to " + taxiFreqStr + ". " + sender; text = receiver + ". Switching to " + taxiFreqStr + ". " + sender;
break; break;
case MSG_INITIATE_CONTACT:
text = receiver + ". With you. " + sender;
break;
case MSG_ACKNOWLEDGE_INITIATE_CONTACT:
text = receiver + ". Roger. " + sender;
break;
case MSG_REQUEST_PUSHBACK_CLEARANCE: case MSG_REQUEST_PUSHBACK_CLEARANCE:
text = receiver + ". Request push-back. " + sender; text = receiver + ". Request push-back. " + sender;
break; break;
@ -457,9 +480,30 @@ void FGATCController::transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir m
break; break;
case MSG_HOLD_PUSHBACK_CLEARANCE: case MSG_HOLD_PUSHBACK_CLEARANCE:
text = receiver + ". Standby. " + sender; text = receiver + ". Standby. " + sender;
break; break;
default: case MSG_REQUEST_TAXI_CLEARANCE:
text = sender + ". Transmitting unknown Message"; text = receiver + ". Ready to Taxi. " + sender;
break;
case MSG_ISSUE_TAXI_CLEARANCE:
text = receiver + ". Cleared to taxi. " + sender;
break;
case MSG_ACKNOWLEDGE_TAXI_CLEARANCE:
text = receiver + ". Cleared to taxi. " + sender;
break;
case MSG_HOLD_POSITION:
text = receiver + ". Hold Position. " + sender;
break;
case MSG_ACKNOWLEDGE_HOLD_POSITION:
text = receiver + ". Holding Position. " + sender;
break;
case MSG_RESUME_TAXI:
text = receiver + ". Resume Taxiing. " + sender;
break;
case MSG_ACKNOWLEDGE_RESUME_TAXI:
text = receiver + ". Continuing Taxi. " + sender;
break;
default:
text = text + sender + ". Transmitting unknown Message";
break; break;
} }
double onBoardRadioFreq0 = fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz"); double onBoardRadioFreq0 = fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz");
@ -691,8 +735,6 @@ FGATCInstruction FGTowerController::getInstruction(int id)
FGStartupController::FGStartupController() : FGStartupController::FGStartupController() :
FGATCController() FGATCController()
{ {
available = false;
lastTransmission = 0;
} }
void FGStartupController::announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentPosition, void FGStartupController::announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentPosition,
@ -874,7 +916,7 @@ void FGStartupController::update(int id, double lat, double lon, double heading,
available = false; available = false;
} }
} }
// Note: The next two stages are only necessesary when Startup control is // Note: The next four stages are only necessesary when Startup control is
// on a different frequency, compared to ground control // on a different frequency, compared to ground control
if ((state == 4) && available){ if ((state == 4) && available){
if (now > startTime+130) { if (now > startTime+130) {
@ -885,20 +927,36 @@ void FGStartupController::update(int id, double lat, double lon, double heading,
available = false; available = false;
} }
} }
// TODO: Switch to APRON control and request pushback Clearance.
// Get Push back clearance
if ((state == 5) && available){ if ((state == 5) && available){
if (now > startTime+160) { if (now > startTime+140) {
transmit(&(*i), MSG_REQUEST_PUSHBACK_CLEARANCE, ATC_AIR_TO_GROUND); transmit(&(*i), MSG_INITIATE_CONTACT, ATC_AIR_TO_GROUND);
i->updateState(); i->updateState();
lastTransmission = now; lastTransmission = now;
available = false; available = false;
} }
} }
if ((state == 6) && available){ if ((state == 6) && available){
if (now > startTime+150) {
transmit(&(*i), MSG_ACKNOWLEDGE_INITIATE_CONTACT, ATC_GROUND_TO_AIR);
i->updateState();
lastTransmission = now;
available = false;
}
}
// TODO: Switch to APRON control and request pushback Clearance.
// Get Push back clearance
if ((state == 7) && available){
if (now > startTime+180) { if (now > startTime+180) {
transmit(&(*i), MSG_REQUEST_PUSHBACK_CLEARANCE, ATC_AIR_TO_GROUND);
i->updateState();
lastTransmission = now;
available = false;
}
}
if ((state == 8) && available){
if (now > startTime+200) {
if (i->pushBackAllowed()) { if (i->pushBackAllowed()) {
i->allowRepeatedTransmissions(); i->allowRepeatedTransmissions();
transmit(&(*i), MSG_PERMIT_PUSHBACK_CLEARANCE, ATC_GROUND_TO_AIR); transmit(&(*i), MSG_PERMIT_PUSHBACK_CLEARANCE, ATC_GROUND_TO_AIR);
@ -911,7 +969,7 @@ void FGStartupController::update(int id, double lat, double lon, double heading,
available = false; available = false;
} }
} }
if ((state == 6) && available){ if ((state == 9) && available){
i->setHoldPosition(false); i->setHoldPosition(false);
} }
} }

View file

@ -129,6 +129,7 @@ public:
void setLeg(int lg) { leg = lg;}; void setLeg(int lg) { leg = lg;};
int getId() { return id;}; int getId() { return id;};
int getState() { return state;}; int getState() { return state;};
void setState(int s) { state = s;}
FGATCInstruction getInstruction() { return instruction;}; FGATCInstruction getInstruction() { return instruction;};
bool hasInstruction() { return instruction.hasInstruction(); }; bool hasInstruction() { return instruction.hasInstruction(); };
void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt); void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
@ -210,7 +211,10 @@ typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
*************************************************************************************/ *************************************************************************************/
class FGATCController class FGATCController
{ {
private: protected:
bool available;
time_t lastTransmission;
double dt_count; double dt_count;
@ -220,18 +224,27 @@ private:
public: public:
typedef enum { typedef enum {
MSG_ANNOUNCE_ENGINE_START, MSG_ANNOUNCE_ENGINE_START,
MSG_REQUEST_ENGINE_START, MSG_REQUEST_ENGINE_START,
MSG_PERMIT_ENGINE_START, MSG_PERMIT_ENGINE_START,
MSG_DENY_ENGINE_START, MSG_DENY_ENGINE_START,
MSG_ACKNOWLEDGE_ENGINE_START, MSG_ACKNOWLEDGE_ENGINE_START,
MSG_REQUEST_PUSHBACK_CLEARANCE, MSG_REQUEST_PUSHBACK_CLEARANCE,
MSG_PERMIT_PUSHBACK_CLEARANCE, MSG_PERMIT_PUSHBACK_CLEARANCE,
MSG_HOLD_PUSHBACK_CLEARANCE, MSG_HOLD_PUSHBACK_CLEARANCE,
MSG_ACKNOWLEDGE_SWITCH_GROUND_FREQUENCY } AtcMsgId; MSG_ACKNOWLEDGE_SWITCH_GROUND_FREQUENCY,
MSG_INITIATE_CONTACT,
MSG_ACKNOWLEDGE_INITIATE_CONTACT,
MSG_REQUEST_TAXI_CLEARANCE,
MSG_ISSUE_TAXI_CLEARANCE,
MSG_ACKNOWLEDGE_TAXI_CLEARANCE,
MSG_HOLD_POSITION,
MSG_ACKNOWLEDGE_HOLD_POSITION,
MSG_RESUME_TAXI,
MSG_ACKNOWLEDGE_RESUME_TAXI } AtcMsgId;
typedef enum { typedef enum {
ATC_AIR_TO_GROUND, ATC_AIR_TO_GROUND,
ATC_GROUND_TO_AIR } AtcMsgDir; ATC_GROUND_TO_AIR } AtcMsgDir;
FGATCController() { dt_count = 0;}; FGATCController();
virtual ~FGATCController() {}; virtual ~FGATCController() {};
virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
double lat, double lon, double lat, double lon,
@ -284,8 +297,6 @@ class FGStartupController : public FGATCController
{ {
private: private:
TrafficVector activeTraffic; TrafficVector activeTraffic;
bool available;
time_t lastTransmission;
//ActiveRunwayVec activeRunways; //ActiveRunwayVec activeRunways;
public: public:

View file

@ -237,7 +237,6 @@ private:
SGGeod pos(SGGeod::fromDegFt(lon, lat, last_apt_elev)); SGGeod pos(SGGeod::fromDegFt(lon, lat, last_apt_elev));
FGAirport* apt = new FGAirport(last_apt_id, pos, tower, last_apt_name, false, FGAirport* apt = new FGAirport(last_apt_id, pos, tower, last_apt_name, false,
fptypeFromRobinType(atoi(last_apt_type.c_str()))); fptypeFromRobinType(atoi(last_apt_type.c_str())));
apt->setRunwaysAndTaxiways(runways, taxiways, pavements); apt->setRunwaysAndTaxiways(runways, taxiways, pavements);
} }

View file

@ -50,31 +50,34 @@ using std::random_shuffle;
#include "simple.hxx" #include "simple.hxx"
#include "dynamics.hxx" #include "dynamics.hxx"
FGAirportDynamics::FGAirportDynamics(FGAirport* ap) : FGAirportDynamics::FGAirportDynamics(FGAirport * ap):
_ap(ap), rwyPrefs(ap), SIDs(ap) { _ap(ap), rwyPrefs(ap), SIDs(ap)
lastUpdate = 0; {
lastUpdate = 0;
// For testing only. This needs to be refined when we move ATIS functionality over. // For testing only. This needs to be refined when we move ATIS functionality over.
atisInformation = "Sierra"; atisInformation = "Sierra";
} }
// Note that the ground network should also be copied // Note that the ground network should also be copied
FGAirportDynamics::FGAirportDynamics(const FGAirportDynamics& other) : FGAirportDynamics::
rwyPrefs(other.rwyPrefs), FGAirportDynamics(const FGAirportDynamics & other):rwyPrefs(other.
SIDs(other.SIDs) rwyPrefs),
SIDs(other.SIDs)
{ {
for (FGParkingVecConstIterator ip= other.parkings.begin(); ip != other.parkings.end(); ip++) for (FGParkingVecConstIterator ip = other.parkings.begin();
parkings.push_back(*(ip)); ip != other.parkings.end(); ip++)
// rwyPrefs = other.rwyPrefs; parkings.push_back(*(ip));
lastUpdate = other.lastUpdate; // rwyPrefs = other.rwyPrefs;
lastUpdate = other.lastUpdate;
stringVecConstIterator il;
for (il = other.landing.begin(); il != other.landing.end(); il++) stringVecConstIterator il;
landing.push_back(*il); for (il = other.landing.begin(); il != other.landing.end(); il++)
for (il = other.takeoff.begin(); il != other.takeoff.end(); il++) landing.push_back(*il);
takeoff.push_back(*il); for (il = other.takeoff.begin(); il != other.takeoff.end(); il++)
lastUpdate = other.lastUpdate; takeoff.push_back(*il);
atisInformation = other.atisInformation; lastUpdate = other.lastUpdate;
atisInformation = other.atisInformation;
} }
// Destructor // Destructor
@ -84,449 +87,404 @@ FGAirportDynamics::~FGAirportDynamics()
// Initialization required after XMLRead // Initialization required after XMLRead
void FGAirportDynamics::init() void FGAirportDynamics::init()
{ {
// This may seem a bit weird to first randomly shuffle the parkings // This may seem a bit weird to first randomly shuffle the parkings
// and then sort them again. However, parkings are sorted here by ascending // and then sort them again. However, parkings are sorted here by ascending
// radius. Since many parkings have similar radii, with each radius class they will // radius. Since many parkings have similar radii, with each radius class they will
// still be allocated relatively systematically. Randomizing prior to sorting will // still be allocated relatively systematically. Randomizing prior to sorting will
// prevent any initial orderings to be destroyed, leading (hopefully) to a more // prevent any initial orderings to be destroyed, leading (hopefully) to a more
// naturalistic gate assignment. // naturalistic gate assignment.
random_shuffle(parkings.begin(), parkings.end()); random_shuffle(parkings.begin(), parkings.end());
sort(parkings.begin(), parkings.end()); sort(parkings.begin(), parkings.end());
// add the gate positions to the ground network. // add the gate positions to the ground network.
groundNetwork.addNodes(&parkings); groundNetwork.addNodes(&parkings);
groundNetwork.init(); groundNetwork.init();
groundNetwork.setTowerController(&towerController); groundNetwork.setTowerController(&towerController);
groundNetwork.setParent(_ap); groundNetwork.setParent(_ap);
} }
bool FGAirportDynamics::getAvailableParking(double *lat, double *lon, double *heading, int *gateId, double rad, const string &flType, const string &acType, const string &airline) bool FGAirportDynamics::getAvailableParking(double *lat, double *lon,
double *heading, int *gateId,
double rad,
const string & flType,
const string & acType,
const string & airline)
{ {
bool found = false; bool found = false;
bool available = false; bool available = false;
//string gateType;
FGParkingVecIterator i;
// if (flType == "cargo")
// {
// gateType = "RAMP_CARGO";
// }
// else if (flType == "ga")
// {
// gateType = "RAMP_GA";
// }
// else gateType = "GATE";
if (parkings.begin() == parkings.end())
{
//cerr << "Could not find parking spot at " << _ap->getId() << endl;
*lat = _ap->getLatitude();
*lon = _ap->getLongitude();
*heading = 0;
found = true;
}
else
{
// First try finding a parking with a designated airline code
for (i = parkings.begin(); !(i == parkings.end() || found); i++)
{
//cerr << "Gate Id: " << i->getIndex()
// << " Type : " << i->getType()
// << " Codes : " << i->getCodes()
// << " Radius: " << i->getRadius()
// << " Name : " << i->getName()
// << " Available: " << i->isAvailable() << endl;
available = true;
// Taken by another aircraft
if (!(i->isAvailable()))
{
available = false;
continue;
}
// No airline codes, so skip
if (i->getCodes().empty())
{
available = false;
continue;
}
else // Airline code doesn't match
{
//cerr << "Code = " << airline << ": Codes " << i->getCodes();
if (i->getCodes().find(airline, 0) == string::npos)
{
available = false;
//cerr << "Unavailable" << endl;
continue;
}
else
{
//cerr << "Available" << endl;
}
}
// Type doesn't match
if (i->getType() != flType)
{
available = false;
continue;
}
// too small
if (i->getRadius() < rad)
{
available = false;
continue;
}
if (available)
{
*lat = i->getLatitude ();
*lon = i->getLongitude();
*heading = i->getHeading ();
*gateId = i->getIndex ();
i->setAvailable(false);
found = true;
}
}
// then try again for those without codes.
for (i = parkings.begin(); !(i == parkings.end() || found); i++)
{
available = true;
if (!(i->isAvailable()))
{
available = false;
continue;
}
if (!(i->getCodes().empty()))
{
if ((i->getCodes().find(airline,0) == string::npos))
{
available = false;
continue;
}
}
if (i->getType() != flType)
{
available = false;
continue;
}
if (i->getRadius() < rad)
{
available = false;
continue;
}
if (available)
{
*lat = i->getLatitude ();
*lon = i->getLongitude();
*heading = i->getHeading ();
*gateId = i->getIndex ();
i->setAvailable(false);
found = true;
}
}
// And finally once more if that didn't work. Now ignore the airline codes, as a last resort
for (i = parkings.begin(); !(i == parkings.end() || found); i++)
{
available = true;
if (!(i->isAvailable()))
{
available = false;
continue;
}
if (i->getType() != flType)
{
available = false;
continue;
}
if (i->getRadius() < rad)
{
available = false;
continue;
}
if (available)
{
*lat = i->getLatitude ();
*lon = i->getLongitude();
*heading = i->getHeading ();
*gateId = i->getIndex ();
i->setAvailable(false);
found = true;
}
}
}
if (!found)
{
//cerr << "Traffic overflow at" << _ap->getId()
// << ". flType = " << flType
// << ". airline = " << airline
// << " Radius = " <<rad
// << endl;
*lat = _ap->getLatitude();
*lon = _ap->getLongitude();
*heading = 0;
*gateId = -1;
//exit(1);
}
return found;
}
void FGAirportDynamics::getParking (int id, double *lat, double* lon, double *heading) FGParkingVecIterator i;
{ if (parkings.begin() == parkings.end()) {
if (id < 0) //cerr << "Could not find parking spot at " << _ap->getId() << endl;
{ *lat = _ap->getLatitude();
*lat = _ap->getLatitude(); *lon = _ap->getLongitude();
*lon = _ap->getLongitude(); *heading = 0;
*heading = 0; found = true;
} } else {
else // First try finding a parking with a designated airline code
{ for (i = parkings.begin(); !(i == parkings.end() || found); i++) {
FGParkingVecIterator i = parkings.begin(); available = true;
for (i = parkings.begin(); i != parkings.end(); i++) // Taken by another aircraft
{ if (!(i->isAvailable())) {
if (id == i->getIndex()) available = false;
{ continue;
*lat = i->getLatitude(); }
*lon = i->getLongitude(); // No airline codes, so skip
*heading = i->getHeading(); if (i->getCodes().empty()) {
} available = false;
} continue;
} } else { // Airline code doesn't match
} //cerr << "Code = " << airline << ": Codes " << i->getCodes();
if (i->getCodes().find(airline, 0) == string::npos) {
available = false;
//cerr << "Unavailable" << endl;
continue;
} else {
//cerr << "Available" << endl;
}
}
// Type doesn't match
if (i->getType() != flType) {
available = false;
continue;
}
// too small
if (i->getRadius() < rad) {
available = false;
continue;
}
FGParking *FGAirportDynamics::getParking(int id) if (available) {
{ *lat = i->getLatitude();
FGParkingVecIterator i = parkings.begin(); *lon = i->getLongitude();
for (i = parkings.begin(); i != parkings.end(); i++) *heading = i->getHeading();
{ *gateId = i->getIndex();
if (id == i->getIndex()) { i->setAvailable(false);
return &(*i); found = true;
} }
} }
// then try again for those without codes.
for (i = parkings.begin(); !(i == parkings.end() || found); i++) {
available = true;
if (!(i->isAvailable())) {
available = false;
continue;
}
if (!(i->getCodes().empty())) {
if ((i->getCodes().find(airline, 0) == string::npos)) {
available = false;
continue;
}
}
if (i->getType() != flType) {
available = false;
continue;
}
if (i->getRadius() < rad) {
available = false;
continue;
}
if (available) {
*lat = i->getLatitude();
*lon = i->getLongitude();
*heading = i->getHeading();
*gateId = i->getIndex();
i->setAvailable(false);
found = true;
}
}
// And finally once more if that didn't work. Now ignore the airline codes, as a last resort
for (i = parkings.begin(); !(i == parkings.end() || found); i++) {
available = true;
if (!(i->isAvailable())) {
available = false;
continue;
}
if (i->getType() != flType) {
available = false;
continue;
}
if (i->getRadius() < rad) {
available = false;
continue;
}
if (available) {
*lat = i->getLatitude();
*lon = i->getLongitude();
*heading = i->getHeading();
*gateId = i->getIndex();
i->setAvailable(false);
found = true;
}
}
}
if (!found) {
//cerr << "Traffic overflow at" << _ap->getId()
// << ". flType = " << flType
// << ". airline = " << airline
// << " Radius = " <<rad
// << endl;
*lat = _ap->getLatitude();
*lon = _ap->getLongitude();
*heading = 0;
*gateId = -1;
//exit(1);
}
return found;
}
void FGAirportDynamics::getParking(int id, double *lat, double *lon,
double *heading)
{
if (id < 0) {
*lat = _ap->getLatitude();
*lon = _ap->getLongitude();
*heading = 0;
} else {
FGParkingVecIterator i = parkings.begin();
for (i = parkings.begin(); i != parkings.end(); i++) {
if (id == i->getIndex()) {
*lat = i->getLatitude();
*lon = i->getLongitude();
*heading = i->getHeading();
}
}
}
}
FGParking *FGAirportDynamics::getParking(int id)
{
FGParkingVecIterator i = parkings.begin();
for (i = parkings.begin(); i != parkings.end(); i++) {
if (id == i->getIndex()) {
return &(*i);
}
}
return 0; return 0;
} }
string FGAirportDynamics::getParkingName(int id)
{ string FGAirportDynamics::getParkingName(int id)
{
FGParkingVecIterator i = parkings.begin(); FGParkingVecIterator i = parkings.begin();
for (i = parkings.begin(); i != parkings.end(); i++) for (i = parkings.begin(); i != parkings.end(); i++) {
{ if (id == i->getIndex()) {
if (id == i->getIndex()) { return i->getName();
return i->getName();
}
} }
}
return string("overflow"); return string("overflow");
} }
void FGAirportDynamics::releaseParking(int id) void FGAirportDynamics::releaseParking(int id)
{ {
if (id >= 0) if (id >= 0) {
{
FGParkingVecIterator i = parkings.begin();
FGParkingVecIterator i = parkings.begin(); for (i = parkings.begin(); i != parkings.end(); i++) {
for (i = parkings.begin(); i != parkings.end(); i++) if (id == i->getIndex()) {
{ i->setAvailable(true);
if (id == i->getIndex()) }
{ }
i -> setAvailable(true);
}
}
} }
} }
void FGAirportDynamics::setRwyUse(const FGRunwayPreference& ref) void FGAirportDynamics::setRwyUse(const FGRunwayPreference & ref)
{ {
rwyPrefs = ref; rwyPrefs = ref;
//cerr << "Exiting due to not implemented yet" << endl; //cerr << "Exiting due to not implemented yet" << endl;
//exit(1); //exit(1);
} }
bool FGAirportDynamics::innerGetActiveRunway(const string &trafficType, int action, string &runway, double heading) bool FGAirportDynamics::innerGetActiveRunway(const string & trafficType,
int action, string & runway,
double heading)
{ {
double windSpeed; double windSpeed;
double windHeading; double windHeading;
double maxTail; double maxTail;
double maxCross; double maxCross;
string name; string name;
string type; string type;
if (!rwyPrefs.available()) { if (!rwyPrefs.available()) {
return false; return false;
} }
RunwayGroup *currRunwayGroup = 0;
int nrActiveRunways = 0;
time_t dayStart = fgGetLong("/sim/time/utc/day-seconds");
if ((abs((long)(dayStart - lastUpdate)) > 600) || trafficType != prevTrafficType)
{
landing.clear();
takeoff.clear();
lastUpdate = dayStart;
prevTrafficType = trafficType;
FGEnvironment RunwayGroup *currRunwayGroup = 0;
stationweather = ((FGEnvironmentMgr *) globals->get_subsystem("environment")) int nrActiveRunways = 0;
->getEnvironment(getLatitude(), time_t dayStart = fgGetLong("/sim/time/utc/day-seconds");
getLongitude(), if ((abs((long) (dayStart - lastUpdate)) > 600)
getElevation()); || trafficType != prevTrafficType) {
landing.clear();
windSpeed = stationweather.get_wind_speed_kt(); takeoff.clear();
windHeading = stationweather.get_wind_from_heading_deg(); lastUpdate = dayStart;
string scheduleName; prevTrafficType = trafficType;
//cerr << "finding active Runway for" << _ap->getId() << endl;
//cerr << "Nr of seconds since day start << " << dayStart << endl;
ScheduleTime *currSched; FGEnvironment
//cerr << "A"<< endl; stationweather =
currSched = rwyPrefs.getSchedule(trafficType.c_str()); ((FGEnvironmentMgr *) globals->get_subsystem("environment"))
if (!(currSched)) ->getEnvironment(getLatitude(), getLongitude(),
return false; getElevation());
//cerr << "B"<< endl;
scheduleName = currSched->getName(dayStart); windSpeed = stationweather.get_wind_speed_kt();
maxTail = currSched->getTailWind (); windHeading = stationweather.get_wind_from_heading_deg();
maxCross = currSched->getCrossWind (); string scheduleName;
//cerr << "SChedule anme = " << scheduleName << endl; //cerr << "finding active Runway for" << _ap->getId() << endl;
if (scheduleName.empty()) //cerr << "Nr of seconds since day start << " << dayStart << endl;
return false;
//cerr << "C"<< endl; ScheduleTime *currSched;
currRunwayGroup = rwyPrefs.getGroup(scheduleName); //cerr << "A"<< endl;
//cerr << "D"<< endl; currSched = rwyPrefs.getSchedule(trafficType.c_str());
if (!(currRunwayGroup)) if (!(currSched))
return false; return false;
nrActiveRunways = currRunwayGroup->getNrActiveRunways(); //cerr << "B"<< endl;
scheduleName = currSched->getName(dayStart);
maxTail = currSched->getTailWind();
maxCross = currSched->getCrossWind();
//cerr << "SChedule anme = " << scheduleName << endl;
if (scheduleName.empty())
return false;
//cerr << "C"<< endl;
currRunwayGroup = rwyPrefs.getGroup(scheduleName);
//cerr << "D"<< endl;
if (!(currRunwayGroup))
return false;
nrActiveRunways = currRunwayGroup->getNrActiveRunways();
// Keep a history of the currently active runways, to ensure // Keep a history of the currently active runways, to ensure
// that an already established selection of runways will not // that an already established selection of runways will not
// be overridden once a more preferred selection becomes // be overridden once a more preferred selection becomes
// available as that can lead to random runway swapping. // available as that can lead to random runway swapping.
if (trafficType == "com") { if (trafficType == "com") {
currentlyActive = &comActive; currentlyActive = &comActive;
} else if (trafficType == "gen") { } else if (trafficType == "gen") {
currentlyActive = &genActive; currentlyActive = &genActive;
} else if (trafficType == "mil") { } else if (trafficType == "mil") {
currentlyActive = &milActive; currentlyActive = &milActive;
} else if (trafficType == "ul") { } else if (trafficType == "ul") {
currentlyActive = &ulActive; currentlyActive = &ulActive;
} }
//
currRunwayGroup->setActive(_ap,
windSpeed,
windHeading,
maxTail,
maxCross,
currentlyActive);
// Note that I SHOULD keep multiple lists in memory, one for currRunwayGroup->setActive(_ap,
// general aviation, one for commercial and one for military windSpeed,
// traffic. windHeading,
currentlyActive->clear(); maxTail, maxCross, currentlyActive);
nrActiveRunways = currRunwayGroup->getNrActiveRunways();
//cerr << "Choosing runway for " << trafficType << endl;
for (int i = 0; i < nrActiveRunways; i++)
{
type = "unknown"; // initialize to something other than landing or takeoff
currRunwayGroup->getActive(i, name, type);
if (type == "landing")
{
landing.push_back(name);
currentlyActive->push_back(name);
//cerr << "Landing " << name << endl;
}
if (type == "takeoff")
{
takeoff.push_back(name);
currentlyActive->push_back(name);
//cerr << "takeoff " << name << endl;
}
}
//cerr << endl;
}
if (action == 1) // takeoff
{
int nr = takeoff.size();
if (nr)
{
// Note that the randomization below, is just a placeholder to choose between
// multiple active runways for this action. This should be
// under ATC control.
runway = chooseRwyByHeading (takeoff, heading);
}
else
{ // Fallback
runway = chooseRunwayFallback();
}
}
if (action == 2) // landing
{
int nr = landing.size();
if (nr)
{
runway = chooseRwyByHeading (landing, heading);
}
else
{ //fallback
runway = chooseRunwayFallback();
}
}
return true; // Note that I SHOULD keep multiple lists in memory, one for
// general aviation, one for commercial and one for military
// traffic.
currentlyActive->clear();
nrActiveRunways = currRunwayGroup->getNrActiveRunways();
//cerr << "Choosing runway for " << trafficType << endl;
for (int i = 0; i < nrActiveRunways; i++) {
type = "unknown"; // initialize to something other than landing or takeoff
currRunwayGroup->getActive(i, name, type);
if (type == "landing") {
landing.push_back(name);
currentlyActive->push_back(name);
//cerr << "Landing " << name << endl;
}
if (type == "takeoff") {
takeoff.push_back(name);
currentlyActive->push_back(name);
//cerr << "takeoff " << name << endl;
}
}
//cerr << endl;
}
if (action == 1) // takeoff
{
int nr = takeoff.size();
if (nr) {
// Note that the randomization below, is just a placeholder to choose between
// multiple active runways for this action. This should be
// under ATC control.
runway = chooseRwyByHeading(takeoff, heading);
} else { // Fallback
runway = chooseRunwayFallback();
}
}
if (action == 2) // landing
{
int nr = landing.size();
if (nr) {
runway = chooseRwyByHeading(landing, heading);
} else { //fallback
runway = chooseRunwayFallback();
}
}
return true;
} }
string FGAirportDynamics::chooseRwyByHeading(stringVec rwys, double heading) { string FGAirportDynamics::chooseRwyByHeading(stringVec rwys,
double bestError = 360.0; double heading)
double rwyHeading, headingError; {
string runway; double bestError = 360.0;
for (stringVecIterator i = rwys.begin(); i != rwys.end(); i++) { double rwyHeading, headingError;
FGRunway *rwy = _ap->getRunwayByIdent((*i)); string runway;
rwyHeading = rwy->headingDeg(); for (stringVecIterator i = rwys.begin(); i != rwys.end(); i++) {
headingError = fabs(heading - rwyHeading); FGRunway *rwy = _ap->getRunwayByIdent((*i));
rwyHeading = rwy->headingDeg();
headingError = fabs(heading - rwyHeading);
if (headingError > 180) if (headingError > 180)
headingError = fabs(headingError - 360); headingError = fabs(headingError - 360);
if (headingError < bestError) { if (headingError < bestError) {
runway = (*i); runway = (*i);
bestError = headingError; bestError = headingError;
} }
} }
//cerr << "Using active runway " << runway << " for heading " << heading << endl; //cerr << "Using active runway " << runway << " for heading " << heading << endl;
return runway; return runway;
} }
void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, string &runway, double heading) void FGAirportDynamics::getActiveRunway(const string & trafficType,
int action, string & runway,
double heading)
{ {
bool ok = innerGetActiveRunway(trafficType, action, runway, heading); bool ok = innerGetActiveRunway(trafficType, action, runway, heading);
if (!ok) { if (!ok) {
runway = chooseRunwayFallback(); runway = chooseRunwayFallback();
} }
} }
string FGAirportDynamics::chooseRunwayFallback() string FGAirportDynamics::chooseRunwayFallback()
{ {
FGRunway* rwy = _ap->getActiveRunwayForUsage(); FGRunway *rwy = _ap->getActiveRunwayForUsage();
return rwy->ident(); return rwy->ident();
} }
void FGAirportDynamics::addParking(FGParking& park) { void FGAirportDynamics::addParking(FGParking & park)
parkings.push_back(park); {
parkings.push_back(park);
} }
double FGAirportDynamics::getLatitude() const { double FGAirportDynamics::getLatitude() const
return _ap->getLatitude(); {
return _ap->getLatitude();
} }
double FGAirportDynamics::getLongitude() const { double FGAirportDynamics::getLongitude() const
return _ap->getLongitude(); {
return _ap->getLongitude();
} }
double FGAirportDynamics::getElevation() const { double FGAirportDynamics::getElevation() const
return _ap->getElevation(); {
return _ap->getElevation();
} }
const string& FGAirportDynamics::getId() const { const string & FGAirportDynamics::getId() const
return _ap->getId(); {
return _ap->getId();
} }
// Experimental: Return a different ground frequency depending on the leg of the // Experimental: Return a different ground frequency depending on the leg of the
@ -536,28 +494,34 @@ const string& FGAirportDynamics::getId() const {
// so that at least I can start working on assigning different frequencies to different // so that at least I can start working on assigning different frequencies to different
// operations. // operations.
int FGAirportDynamics::getGroundFrequency(unsigned leg) { int FGAirportDynamics::getGroundFrequency(unsigned leg)
//return freqGround.size() ? freqGround[0] : 0; }; {
int groundFreq = 0; //return freqGround.size() ? freqGround[0] : 0; };
if (leg < 2) { int groundFreq = 0;
SG_LOG(SG_ATC, SG_ALERT, "Leg value is smaller than two at " << SG_ORIGIN); if (leg < 2) {
} SG_LOG(SG_ATC, SG_ALERT,
if (freqGround.size() == 0) { "Leg value is smaller than two at " << SG_ORIGIN);
return 0; }
} if (freqGround.size() == 0) {
if ((freqGround.size() > leg-1) && (leg > 1)) { return 0;
groundFreq = freqGround[leg-1]; }
} if ((freqGround.size() > leg - 1) && (leg > 1)) {
if ((freqGround.size() < leg-1) && (leg > 1)) { groundFreq = freqGround[leg - 1];
groundFreq = (freqGround.size() < (leg-1)) ? freqGround[freqGround.size()-1] : freqGround[leg-2]; }
} if ((freqGround.size() < leg - 1) && (leg > 1)) {
if ((freqGround.size() >= leg-1) && (leg > 1)) { groundFreq =
groundFreq = freqGround[leg-2]; (freqGround.size() <
} (leg - 1)) ? freqGround[freqGround.size() -
1] : freqGround[leg - 2];
}
if ((freqGround.size() >= leg - 1) && (leg > 1)) {
groundFreq = freqGround[leg - 2];
}
return groundFreq; return groundFreq;
} }
FGAIFlightPlan *FGAirportDynamics::getSID(string activeRunway, double heading) FGAIFlightPlan *FGAirportDynamics::getSID(string activeRunway,
double heading)
{ {
return SIDs.getBest(activeRunway, heading); return SIDs.getBest(activeRunway, heading);
} }

File diff suppressed because it is too large Load diff

View file

@ -252,10 +252,10 @@ public:
void init(); void init();
bool exists() { return hasNetwork; }; bool exists() { return hasNetwork; };
void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; }; void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; };
int findNearestNode(double lat, double lon); int findNearestNode(double lat, double lon);
int findNearestNode(const SGGeod& aGeod); int findNearestNode(const SGGeod& aGeod);
FGTaxiNode *findNode(unsigned idx); FGTaxiNode *findNode(unsigned idx);
FGTaxiSegment *findSegment(unsigned idx); FGTaxiSegment *findSegment(unsigned idx);
FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true); FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);

View file

@ -201,15 +201,17 @@ bool FGAISchedule::update(time_t now, const SGVec3d& userCart)
if (firstRun) { if (firstRun) {
if (fgGetBool("/sim/traffic-manager/instantaneous-action") == true) { if (fgGetBool("/sim/traffic-manager/instantaneous-action") == true) {
deptime = now + rand() % 300; // Wait up to 5 minutes until traffic starts moving to prevent too many aircraft deptime = now; // + rand() % 300; // Wait up to 5 minutes until traffic starts moving to prevent too many aircraft
// from cluttering the gate areas. // from cluttering the gate areas.
} }
firstRun = false; firstRun = false;
} }
FGScheduledFlight* flight = flights.front(); FGScheduledFlight* flight = flights.front();
if (!deptime) if (!deptime) {
deptime = flight->getDepartureTime(); deptime = flight->getDepartureTime();
//cerr << "Settiing departure time " << deptime << endl;
}
if (AIManagerRef) { if (AIManagerRef) {
// Check if this aircraft has been released. // Check if this aircraft has been released.