1
0
Fork 0

Another small, incremental step towards interactive tower control.

This commit is contained in:
daveluff 2003-09-22 23:57:57 +00:00
parent 0d9ea4d27c
commit 9bba532487
2 changed files with 439 additions and 220 deletions

View file

@ -47,6 +47,7 @@ onRwy(false),
nextOnRwy(false), nextOnRwy(false),
opType(TTT_UNKNOWN), opType(TTT_UNKNOWN),
leg(LEG_UNKNOWN), leg(LEG_UNKNOWN),
landingType(AIP_LT_UNKNOWN),
isUser(false) isUser(false)
{ {
plane.callsign = "UNKNOWN"; plane.callsign = "UNKNOWN";
@ -65,6 +66,7 @@ onRwy(false),
nextOnRwy(false), nextOnRwy(false),
opType(TTT_UNKNOWN), opType(TTT_UNKNOWN),
leg(LEG_UNKNOWN), leg(LEG_UNKNOWN),
landingType(AIP_LT_UNKNOWN),
isUser(false) isUser(false)
{ {
plane = p; plane = p;
@ -83,6 +85,7 @@ onRwy(false),
nextOnRwy(false), nextOnRwy(false),
opType(TTT_UNKNOWN), opType(TTT_UNKNOWN),
leg(LEG_UNKNOWN), leg(LEG_UNKNOWN),
landingType(AIP_LT_UNKNOWN),
isUser(false) isUser(false)
{ {
plane.callsign = "UNKNOWN"; plane.callsign = "UNKNOWN";
@ -102,6 +105,7 @@ onRwy(false),
nextOnRwy(false), nextOnRwy(false),
opType(TTT_UNKNOWN), opType(TTT_UNKNOWN),
leg(LEG_UNKNOWN), leg(LEG_UNKNOWN),
landingType(AIP_LT_UNKNOWN),
isUser(false) isUser(false)
{ {
plane = p; plane = p;
@ -118,6 +122,9 @@ FGTower::FGTower() {
wind_from_hdg = fgGetNode("/environment/wind-from-heading-deg", true); wind_from_hdg = fgGetNode("/environment/wind-from-heading-deg", true);
wind_speed_knots = fgGetNode("/environment/wind-speed-kt", true); wind_speed_knots = fgGetNode("/environment/wind-speed-kt", true);
update_count = 0;
update_count_max = 15;
holdListItr = holdList.begin(); holdListItr = holdList.begin();
appListItr = appList.begin(); appListItr = appList.begin();
depListItr = depList.begin(); depListItr = depList.begin();
@ -126,6 +133,9 @@ FGTower::FGTower() {
trafficListItr = trafficList.begin(); trafficListItr = trafficList.begin();
freqClear = true; freqClear = true;
timeSinceLastDeparture = 9999;
departed = false;
} }
FGTower::~FGTower() { FGTower::~FGTower() {
@ -204,17 +214,17 @@ void FGTower::Init() {
t->plane.callsign = "Charlie Foxtrot Sierra"; // C-FGFS !!! - fixme - this is a bit hardwired t->plane.callsign = "Charlie Foxtrot Sierra"; // C-FGFS !!! - fixme - this is a bit hardwired
t->plane.type = GA_SINGLE; t->plane.type = GA_SINGLE;
t->opType = TTT_UNKNOWN; // We don't know if the user wants to do circuits or a departure... t->opType = TTT_UNKNOWN; // We don't know if the user wants to do circuits or a departure...
t->landingType = AIP_LT_UNKNOWN;
t->leg = TAKEOFF_ROLL; t->leg = TAKEOFF_ROLL;
t->isUser = true; t->isUser = true;
t->planePtr = NULL; t->planePtr = NULL;
t->clearedToTakeOff = true; t->clearedToTakeOff = true;
rwyList.push_back(t); rwyList.push_back(t);
departed = false;
} }
} }
void FGTower::Update(double dt) { void FGTower::Update(double dt) {
static int ii = 0; // Counter for spreading the load
int ii_max = 15;
//cout << "T" << flush; //cout << "T" << flush;
// Each time step, what do we need to do? // Each time step, what do we need to do?
// We need to go through the list of outstanding requests and acknowedgements // We need to go through the list of outstanding requests and acknowedgements
@ -228,22 +238,36 @@ void FGTower::Update(double dt) {
// Sort the arriving planes // Sort the arriving planes
/*
if(ident == "KEMT") {
cout << update_count << "\ttL: " << trafficList.size() << " cL: " << circuitList.size() << " hL: " << holdList.size() << " aL: " << appList.size() << '\n';
}
*/
if(departed != false) {
timeSinceLastDeparture += dt;
//if(ident == "KEMT")
// cout << " dt = " << dt << " timeSinceLastDeparture = " << timeSinceLastDeparture << '\n';
}
// Calculate the eta of each plane to the threshold. // Calculate the eta of each plane to the threshold.
// For ground traffic this is the fastest they can get there. // For ground traffic this is the fastest they can get there.
// For air traffic this is the middle approximation. // For air traffic this is the middle approximation.
if(ii == 1) { if(update_count == 1) {
doThresholdETACalc(); doThresholdETACalc();
} }
// Order the list of traffic as per expected threshold use and flag any conflicts // Order the list of traffic as per expected threshold use and flag any conflicts
if(ii == 2) { if(update_count == 2) {
bool conflicts = doThresholdUseOrder(); //bool conflicts = doThresholdUseOrder();
doThresholdUseOrder();
} }
// sortConficts() !!! // sortConficts() !!!
// Do one plane from the hold list // Do one plane from the hold list
if(ii == 4) { if(update_count == 4) {
//cout << "ug\n";
if(holdList.size()) { if(holdList.size()) {
//cout << "*holdListItr = " << *holdListItr << endl; //cout << "*holdListItr = " << *holdListItr << endl;
if(holdListItr == holdList.end()) { if(holdListItr == holdList.end()) {
@ -254,113 +278,118 @@ void FGTower::Update(double dt) {
TowerPlaneRec* t = *holdListItr; TowerPlaneRec* t = *holdListItr;
//cout << "t = " << t << endl; //cout << "t = " << t << endl;
if(t->holdShortReported) { if(t->holdShortReported) {
//cout << "ding\n";
double responseTime = 10.0; // seconds - this should get more sophisticated at some point double responseTime = 10.0; // seconds - this should get more sophisticated at some point
if(t->clearanceCounter > responseTime) { if(t->clearanceCounter > responseTime) {
if(t->nextOnRwy) { if(t->nextOnRwy) {
if(rwyOccupied) { if(rwyOccupied) { // TODO - ought to add a sanity check that it isn't this plane only on the runway (even though it shouldn't be!!)
// Do nothing for now - consider acknowloging hold short eventually // Do nothing for now - consider acknowloging hold short eventually
} else { } else {
// Lets Roll !!!! // Lets Roll !!!!
string trns = t->plane.callsign; string trns = t->plane.callsign;
//if(departed plane < some threshold in time away) { //if(departed plane < some threshold in time away) {
if(0) { // FIXME if(0) { // FIXME
trns += " line up"; trns += " line up";
t->clearedToLineUp = true; t->clearedToLineUp = true;
t->planePtr->RegisterTransmission(3); // cleared to line-up t->planePtr->RegisterTransmission(3); // cleared to line-up
t->leg = TAKEOFF_ROLL; t->leg = TAKEOFF_ROLL;
//} else if(arriving plane < some threshold away) { //} else if(arriving plane < some threshold away) {
} else if(GetTrafficETA(2) < 150.0) { } else if(GetTrafficETA(2) < 150.0) {
trns += " cleared immediate take-off"; trns += " cleared immediate take-off";
if(trafficList.size()) { if(trafficList.size()) {
tower_plane_rec_list_iterator trfcItr = trafficList.begin(); tower_plane_rec_list_iterator trfcItr = trafficList.begin();
trfcItr++; // At the moment the holding plane should be first in trafficList. trfcItr++; // At the moment the holding plane should be first in trafficList.
// Note though that this will break if holding planes aren't put in trafficList in the future. // Note though that this will break if holding planes aren't put in trafficList in the future.
TowerPlaneRec* trfc = *trfcItr; TowerPlaneRec* trfc = *trfcItr;
trns += "... traffic is"; trns += "... traffic is";
switch(trfc->plane.type) { switch(trfc->plane.type) {
case UNKNOWN: case UNKNOWN:
break; break;
case GA_SINGLE: case GA_SINGLE:
trns += " a Cessna"; // TODO - add ability to specify actual plane type somewhere trns += " a Cessna"; // TODO - add ability to specify actual plane type somewhere
break; break;
case GA_HP_SINGLE: case GA_HP_SINGLE:
trns += " a Piper"; trns += " a Piper";
break; break;
case GA_TWIN: case GA_TWIN:
trns += " a King-air"; trns += " a King-air";
break; break;
case GA_JET: case GA_JET:
trns += " a Learjet"; trns += " a Learjet";
break; break;
case MEDIUM: case MEDIUM:
trns += " a Regional"; trns += " a Regional";
break; break;
case HEAVY: case HEAVY:
trns += " a Heavy"; trns += " a Heavy";
break; break;
case MIL_JET: case MIL_JET:
trns += " Military"; trns += " Military";
break; break;
} }
if(trfc->opType == STRAIGHT_IN || trfc->opType == TTT_UNKNOWN) { if(trfc->opType == STRAIGHT_IN || trfc->opType == TTT_UNKNOWN) {
double miles_out = CalcDistOutMiles(trfc); double miles_out = CalcDistOutMiles(trfc);
if(miles_out < 2) { if(miles_out < 2) {
trns += " on final"; trns += " on final";
} else { } else {
trns += " on "; trns += " on ";
trns += ConvertNumToSpokenDigits((int)miles_out); trns += ConvertNumToSpokenDigits((int)miles_out);
trns += " mile final"; trns += " mile final";
} }
} else if(trfc->opType == CIRCUIT) { } else if(trfc->opType == CIRCUIT) {
switch(trfc->leg) { switch(trfc->leg) {
case FINAL: case FINAL:
trns += " on final"; trns += " on final";
break; break;
case TURN4: case TURN4:
trns += " turning final"; trns += " turning final";
break; break;
case BASE: case BASE:
trns += " on base"; trns += " on base";
break; break;
case TURN3: case TURN3:
trns += " turning base"; trns += " turning base";
break; break;
case DOWNWIND: case DOWNWIND:
trns += " in circuit"; trns += " in circuit";
break; break;
// And to eliminate compiler warnings... // And to eliminate compiler warnings...
case TAKEOFF_ROLL: break; case TAKEOFF_ROLL: break;
case CLIMBOUT: break; case CLIMBOUT: break;
case TURN1: break; case TURN1: break;
case CROSSWIND: break; case CROSSWIND: break;
case TURN2: break; case TURN2: break;
case LANDING_ROLL: break; case LANDING_ROLL: break;
case LEG_UNKNOWN: break; case LEG_UNKNOWN: break;
} }
}
} else {
// By definition there should be some arriving traffic if we're cleared for immediate takeoff
SG_LOG(SG_ATC, SG_WARN, "Warning: Departing traffic cleared for *immediate* take-off despite no arriving traffic in FGTower");
} }
t->clearedToTakeOff = true;
t->planePtr->RegisterTransmission(4); // cleared to take-off - TODO differentiate between immediate and normal take-off
t->leg = TAKEOFF_ROLL;
} else { } else {
trns += " cleared for take-off"; // By definition there should be some arriving traffic if we're cleared for immediate takeoff
// TODO - add traffic is... ? SG_LOG(SG_ATC, SG_WARN, "Warning: Departing traffic cleared for *immediate* take-off despite no arriving traffic in FGTower");
t->clearedToTakeOff = true;
t->planePtr->RegisterTransmission(4); // cleared to take-off
t->leg = TAKEOFF_ROLL;
} }
if(display) { t->clearedToTakeOff = true;
globals->get_ATC_display()->RegisterSingleMessage(trns, 0); t->planePtr->RegisterTransmission(4); // cleared to take-off - TODO differentiate between immediate and normal take-off
} t->leg = TAKEOFF_ROLL;
t->holdShortReported = false; departed = false;
t->clearanceCounter = 0; timeSinceLastDeparture = 0.0;
rwyList.push_back(t); } else {
rwyOccupied = true; trns += " cleared for take-off";
holdList.erase(holdListItr); // TODO - add traffic is... ?
holdListItr = holdList.begin(); t->clearedToTakeOff = true;
t->planePtr->RegisterTransmission(4); // cleared to take-off
t->leg = TAKEOFF_ROLL;
departed = false;
timeSinceLastDeparture = 0.0;
}
if(display) {
globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
}
t->holdShortReported = false;
t->clearanceCounter = 0;
rwyList.push_back(t);
rwyOccupied = true;
holdList.erase(holdListItr);
holdListItr = holdList.begin();
} }
} else { } else {
// Tell him to hold and what position he is. // Tell him to hold and what position he is.
@ -375,34 +404,51 @@ void FGTower::Update(double dt) {
// TODO - add some idea of what traffic is blocking him. // TODO - add some idea of what traffic is blocking him.
} }
} else { } else {
t->clearanceCounter += (dt * holdList.size() * ii_max); t->clearanceCounter += (dt * holdList.size() * update_count_max);
} }
} else { // not responding to report, but still need to clear if clear } else { // not responding to report, but still need to clear if clear
//cout << "dong\n";
if(t->nextOnRwy) { if(t->nextOnRwy) {
//cout << "departed = " << departed << '\n';
//cout << "timeSinceLastDeparture = " << timeSinceLastDeparture << '\n';
if(rwyOccupied) { if(rwyOccupied) {
// Do nothing for now - consider acknowloging hold short eventually // Do nothing for now - consider acknowloging hold short eventually
} else if(timeSinceLastDeparture <= 60.0 && departed == true) {
// Do nothing - this is a bit of a hack - should maybe do line up be ready here
} else { } else {
// Lets Roll !!!! // Lets Roll !!!!
string trns = t->plane.callsign; string trns = t->plane.callsign;
//cout << "******************* squaggle\n";
//cout << "departed = " << departed << '\n';
//cout << "timeSinceLastDeparture = " << timeSinceLastDeparture << '\n';
//if(departed plane < some threshold in time away) { //if(departed plane < some threshold in time away) {
if(0) { // FIXME if(0) { // FIXME
//cout << "A\n";
trns += " line up"; trns += " line up";
t->clearedToLineUp = true; t->clearedToLineUp = true;
t->planePtr->RegisterTransmission(3); // cleared to line-up t->planePtr->RegisterTransmission(3); // cleared to line-up
t->leg = TAKEOFF_ROLL; t->leg = TAKEOFF_ROLL;
//} else if(arriving plane < some threshold away) { //} else if(arriving plane < some threshold away) {
} else if(GetTrafficETA(2) < 150.0) { } else if(GetTrafficETA(2) < 150.0 && (timeSinceLastDeparture > 60.0 || departed == false)) { // Hack - hardwired time
//cout << "B\n";
trns += " cleared immediate take-off"; trns += " cleared immediate take-off";
// TODO - add traffic is... ? // TODO - add traffic is... ?
t->clearedToTakeOff = true; t->clearedToTakeOff = true;
t->planePtr->RegisterTransmission(4); // cleared to take-off - TODO differentiate between immediate and normal take-off t->planePtr->RegisterTransmission(4); // cleared to take-off - TODO differentiate between immediate and normal take-off
t->leg = TAKEOFF_ROLL; t->leg = TAKEOFF_ROLL;
} else { departed = false;
timeSinceLastDeparture = 0.0;
} else if(timeSinceLastDeparture > 60.0 || departed == false) { // Hack - test for timeSinceLastDeparture should be in lineup block eventually
//cout << "C\n";
trns += " cleared for take-off"; trns += " cleared for take-off";
// TODO - add traffic is... ? // TODO - add traffic is... ?
t->clearedToTakeOff = true; t->clearedToTakeOff = true;
t->planePtr->RegisterTransmission(4); // cleared to take-off t->planePtr->RegisterTransmission(4); // cleared to take-off
t->leg = TAKEOFF_ROLL; t->leg = TAKEOFF_ROLL;
departed = false;
timeSinceLastDeparture = 0.0;
} else {
//cout << "D\n";
} }
if(display) { if(display) {
globals->get_ATC_display()->RegisterSingleMessage(trns, 0); globals->get_ATC_display()->RegisterSingleMessage(trns, 0);
@ -413,15 +459,24 @@ void FGTower::Update(double dt) {
holdListItr = holdList.begin(); holdListItr = holdList.begin();
} }
} }
// TODO - remove the considerable code duplication above! // TODO - rationalise the considerable code duplication above!
} }
++holdListItr; ++holdListItr;
} }
} }
// Uggh - HACK - why have we got rwyOccupied - wouldn't simply testing rwyList.size() do?
if(rwyList.size()) {
rwyOccupied = true;
} else {
rwyOccupied = false;
}
// Do the runway list - we'll do the whole runway list since it's important and there'll never be many planes on the rwy at once!! // Do the runway list - we'll do the whole runway list since it's important and there'll never be many planes on the rwy at once!!
// FIXME - at the moment it looks like we're only doing the first plane from the rwy list. // FIXME - at the moment it looks like we're only doing the first plane from the rwy list.
if(ii == 5) { // (However, at the moment there should only be one airplane on the rwy at once, until we
// start allowing planes to line up whilst previous arrival clears the rwy.)
if(update_count == 5) {
if(rwyOccupied) { if(rwyOccupied) {
if(!rwyList.size()) { if(!rwyList.size()) {
rwyOccupied = false; rwyOccupied = false;
@ -429,51 +484,64 @@ void FGTower::Update(double dt) {
rwyListItr = rwyList.begin(); rwyListItr = rwyList.begin();
TowerPlaneRec* t = *rwyListItr; TowerPlaneRec* t = *rwyListItr;
if(t->isUser) { if(t->isUser) {
bool on_rwy = OnActiveRunway(Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0)); t->pos.setlon(user_lon_node->getDoubleValue());
// TODO - how do we find the position when it's not the user? t->pos.setlat(user_lat_node->getDoubleValue());
if(!on_rwy) { t->pos.setelev(user_elev_node->getDoubleValue());
if((t->opType == INBOUND) || (t->opType == STRAIGHT_IN)) { } else {
rwyList.pop_front(); t->pos = t->planePtr->GetPos(); // We should probably only set the pos's on one walk through the traffic list in the update function, to save a few CPU should we end up duplicating this.
delete t; }
// TODO - tell it to taxi / contact ground / don't delete it etc! bool on_rwy = OnActiveRunway(t->pos);
} else if(t->opType == OUTBOUND) { if(!on_rwy) {
depList.push_back(t); if((t->opType == INBOUND) || (t->opType == STRAIGHT_IN)) {
rwyList.pop_front(); rwyList.pop_front();
} else if(t->opType == CIRCUIT) { delete t;
circuitList.push_back(t); // TODO - tell it to taxi / contact ground / don't delete it etc!
//cout << "Oggy oggy oggy\n"; } else if(t->opType == OUTBOUND) {
AddToTrafficList(t); depList.push_back(t);
rwyList.pop_front(); rwyList.pop_front();
} else if(t->opType == TTT_UNKNOWN) { departed = true;
depList.push_back(t); timeSinceLastDeparture = 0.0;
circuitList.push_back(t); } else if(t->opType == CIRCUIT) {
//cout << "Aggy aggy aggy\n"; circuitList.push_back(t);
AddToTrafficList(t); AddToTrafficList(t);
rwyList.pop_front(); rwyList.pop_front();
} else { departed = true;
// HELP - we shouldn't ever get here!!! timeSinceLastDeparture = 0.0;
} } else if(t->opType == TTT_UNKNOWN) {
depList.push_back(t);
circuitList.push_back(t);
AddToTrafficList(t);
rwyList.pop_front();
departed = true;
timeSinceLastDeparture = 0.0; // TODO - we need to take into account that the user might taxi-in when flagged opType UNKNOWN - check speed/altitude etc to make decision as to what user is up to.
} else {
// HELP - we shouldn't ever get here!!!
} }
} // else TODO figure out what to do when it's not the user }
} }
} }
} }
// do the ciruit list // do the ciruit list
if(ii == 6) { if(update_count == 6) {
// Clear the constraints - we recalculate here. // Clear the constraints - we recalculate here.
base_leg_pos = 0.0; base_leg_pos = 0.0;
downwind_leg_pos = 0.0; downwind_leg_pos = 0.0;
crosswind_leg_pos = 0.0; crosswind_leg_pos = 0.0;
if(circuitList.size()) {
circuitListItr = circuitList.begin(); // TODO - at the moment we're constraining plane 2 based on plane 1 - this won't work for 3 planes in the circuit!! if(circuitList.size()) { // Do one plane from the circuit
if(circuitListItr == circuitList.end()) {
circuitListItr = circuitList.begin();
}
TowerPlaneRec* t = *circuitListItr; TowerPlaneRec* t = *circuitListItr;
if(t->isUser) { if(t->isUser) {
t->pos.setlon(user_lon_node->getDoubleValue()); t->pos.setlon(user_lon_node->getDoubleValue());
t->pos.setlat(user_lat_node->getDoubleValue()); t->pos.setlat(user_lat_node->getDoubleValue());
t->pos.setelev(user_elev_node->getDoubleValue()); t->pos.setelev(user_elev_node->getDoubleValue());
} else { } else {
// TODO - set/update the position if it's an AI plane t->pos = t->planePtr->GetPos(); // We should probably only set the pos's on one walk through the traffic list in the update function, to save a few CPU should we end up duplicating this.
t->landingType = t->planePtr->GetLandingOption();
//cout << "AI plane landing option is " << t->landingType << '\n';
} }
Point3D tortho = ortho.ConvertToLocal(t->pos); Point3D tortho = ortho.ConvertToLocal(t->pos);
if(t->isUser) { if(t->isUser) {
@ -550,57 +618,82 @@ void FGTower::Update(double dt) {
t->leg = DOWNWIND; t->leg = DOWNWIND;
//cout << "Downwind\n"; //cout << "Downwind\n";
} }
if(t->leg == FINAL) {
if(OnActiveRunway(t->pos)) {
t->leg = LANDING_ROLL;
}
}
} else { } else {
t->leg = t->planePtr->GetLeg(); t->leg = t->planePtr->GetLeg();
} }
switch(t->leg) {
case FINAL: // Set the constraints IF this is the first plane in the circuit
// Base leg must be at least as far out as the plane is - actually possibly not necessary for separation, but we'll use that for now. // TODO - at the moment we're constraining plane 2 based on plane 1 - this won't (or might not) work for 3 planes in the circuit!!
base_leg_pos = tortho.y(); if(circuitListItr == circuitList.begin()) {
//cout << "base_leg_pos = " << base_leg_pos << '\n'; switch(t->leg) {
break; case FINAL:
case TURN4: // Base leg must be at least as far out as the plane is - actually possibly not necessary for separation, but we'll use that for now.
// Fall through to base base_leg_pos = tortho.y();
case BASE: //cout << "base_leg_pos = " << base_leg_pos << '\n';
base_leg_pos = tortho.y(); break;
//cout << "base_leg_pos = " << base_leg_pos << '\n'; case TURN4:
break; // Fall through to base
case TURN3: case BASE:
// Fall through to downwind base_leg_pos = tortho.y();
case DOWNWIND: //cout << "base_leg_pos = " << base_leg_pos << '\n';
// Only have the downwind leg pos as turn-to-base constraint if more negative than we already have. break;
base_leg_pos = (tortho.y() < base_leg_pos ? tortho.y() : base_leg_pos); case TURN3:
//cout << "base_leg_pos = " << base_leg_pos; // Fall through to downwind
downwind_leg_pos = tortho.x(); // Assume that a following plane can simply be constrained by the immediately in front downwind plane case DOWNWIND:
//cout << " downwind_leg_pos = " << downwind_leg_pos << '\n'; // Only have the downwind leg pos as turn-to-base constraint if more negative than we already have.
break; base_leg_pos = (tortho.y() < base_leg_pos ? tortho.y() : base_leg_pos);
case TURN2: //cout << "base_leg_pos = " << base_leg_pos;
// Fall through to crosswind downwind_leg_pos = tortho.x(); // Assume that a following plane can simply be constrained by the immediately in front downwind plane
case CROSSWIND: //cout << " downwind_leg_pos = " << downwind_leg_pos << '\n';
crosswind_leg_pos = tortho.y(); break;
//cout << "crosswind_leg_pos = " << crosswind_leg_pos << '\n'; case TURN2:
break; // Fall through to crosswind
case TURN1: case CROSSWIND:
// Fall through to climbout crosswind_leg_pos = tortho.y();
case CLIMBOUT: //cout << "crosswind_leg_pos = " << crosswind_leg_pos << '\n';
// Only use current by constraint as largest break;
crosswind_leg_pos = (tortho.y() > crosswind_leg_pos ? tortho.y() : crosswind_leg_pos); case TURN1:
//cout << "crosswind_leg_pos = " << crosswind_leg_pos << '\n'; // Fall through to climbout
break; case CLIMBOUT:
case TAKEOFF_ROLL: // Only use current by constraint as largest
break; crosswind_leg_pos = (tortho.y() > crosswind_leg_pos ? tortho.y() : crosswind_leg_pos);
case LEG_UNKNOWN: //cout << "crosswind_leg_pos = " << crosswind_leg_pos << '\n';
break; break;
case LANDING_ROLL: case TAKEOFF_ROLL:
break; break;
default: case LEG_UNKNOWN:
break; break;
case LANDING_ROLL:
break;
default:
break;
}
} }
if(t->leg == FINAL) {
if(t->landingType == FULL_STOP) t->opType = INBOUND;
} else if(t->leg == LANDING_ROLL) {
rwyList.push_front(t);
RemoveFromTrafficList(t->plane.callsign);
if(t->isUser) {
t->opType = TTT_UNKNOWN;
} // TODO - allow the user to specify opType via ATC menu
circuitListItr = circuitList.erase(circuitListItr);
if(circuitListItr == circuitList.end() ) {
circuitListItr = circuitList.begin();
}
}
++circuitListItr;
} }
} }
// Do one plane from the approach list // Do one plane from the approach list
if(ii == 7) { if(update_count == 7) {
if(appList.size()) { if(appList.size()) {
if(appListItr == appList.end()) { if(appListItr == appList.end()) {
appListItr = appList.begin(); appListItr = appList.begin();
@ -622,7 +715,9 @@ void FGTower::Update(double dt) {
} }
} }
doCommunication(); // TODO - do one plane from the departure list and set departed = false when out of consideration
//doCommunication();
if(!separateGround) { if(!separateGround) {
// The display stuff might have to get more clever than this when not separate // The display stuff might have to get more clever than this when not separate
@ -636,10 +731,10 @@ void FGTower::Update(double dt) {
ground->Update(dt); ground->Update(dt);
} }
++ii; ++update_count;
// How big should ii get - ie how long should the update cycle interval stretch? // How big should ii get - ie how long should the update cycle interval stretch?
if(ii >= ii_max) { if(update_count >= update_count_max) {
ii = 0; update_count = 0;
} }
if(ident == "KEMT") { if(ident == "KEMT") {
@ -811,41 +906,65 @@ bool FGTower::RemoveFromTrafficList(string id) {
// Returns true if this could cause a threshold ETA conflict with other traffic, false otherwise. // Returns true if this could cause a threshold ETA conflict with other traffic, false otherwise.
// For planes holding they are put in the first position with time to go, and the return value is // For planes holding they are put in the first position with time to go, and the return value is
// true if in the first position (nextOnRwy) and false otherwise. // true if in the first position (nextOnRwy) and false otherwise.
// See the comments in FGTower::doThresholdUseOrder for notes on the ordering
bool FGTower::AddToTrafficList(TowerPlaneRec* t, bool holding) { bool FGTower::AddToTrafficList(TowerPlaneRec* t, bool holding) {
//cout << "ADD: " << trafficList.size();
//cout << "AddToTrafficList called, currently size = " << trafficList.size() << ", holding = " << holding << '\n'; //cout << "AddToTrafficList called, currently size = " << trafficList.size() << ", holding = " << holding << '\n';
double separation_time = 90.0; // seconds - this is currently a guess for light plane separation, and includes a few seconds for a holding plane to taxi onto the rwy. double separation_time = 90.0; // seconds - this is currently a guess for light plane separation, and includes a few seconds for a holding plane to taxi onto the rwy.
double departure_sep_time = 60.0; // Separation time behind departing airplanes. Comments above also apply.
bool conflict = false; bool conflict = false;
double lastETA = 0.0; double lastETA = 0.0;
bool firstTime = true; bool firstTime = true;
// FIXME - make this more robust for different plane types eg. light following heavy. // FIXME - make this more robust for different plane types eg. light following heavy.
tower_plane_rec_list_iterator twrItr; tower_plane_rec_list_iterator twrItr;
//twrItr = trafficList.begin();
//while(1) {
for(twrItr = trafficList.begin(); twrItr != trafficList.end(); twrItr++) { for(twrItr = trafficList.begin(); twrItr != trafficList.end(); twrItr++) {
TowerPlaneRec* tpr = *twrItr; //if(twrItr == trafficList.end()) {
if(holding) { // cout << " END ";
//cout << (tpr->isUser ? "USER!\n" : "NOT user\n"); // trafficList.push_back(t);
//cout << "tpr->eta - lastETA = " << tpr->eta - lastETA << '\n'; // return(holding ? firstTime : conflict);
if(tpr->eta - lastETA > separation_time) { //} else {
t->nextOnRwy = firstTime; TowerPlaneRec* tpr = *twrItr;
trafficList.insert(twrItr, t); if(holding) {
return(firstTime); //cout << (tpr->isUser ? "USER!\n" : "NOT user\n");
} //cout << "tpr->eta - lastETA = " << tpr->eta - lastETA << '\n';
firstTime = false; double dep_allowance = (timeSinceLastDeparture < departure_sep_time ? departure_sep_time - timeSinceLastDeparture : 0.0);
} else { double slot_time = (firstTime ? separation_time + dep_allowance : separation_time + departure_sep_time);
if(t->eta < tpr->eta) { // separation_time + departure_sep_time in the above accounts for the fact that the arrival could be touch and go,
// Ugg - this one's tricky. // and if not needs time to clear the rwy anyway.
// It depends on what the two planes are doing and whether there's a conflict what we do. if(tpr->eta - lastETA > slot_time) {
if(tpr->eta - t->eta > separation_time) { // No probs, plane 2 can squeeze in before plane 1 with no apparent conflict t->nextOnRwy = firstTime;
if(tpr->nextOnRwy) {
tpr->nextOnRwy = false;
t->nextOnRwy = true;
}
trafficList.insert(twrItr, t); trafficList.insert(twrItr, t);
} else { // Ooops - this ones tricky - we have a potential conflict! //cout << "\tH\t" << trafficList.size() << '\n';
conflict = true; return(firstTime);
}
firstTime = false;
} else {
if(t->eta < tpr->eta) {
// Ugg - this one's tricky.
// It depends on what the two planes are doing and whether there's a conflict what we do.
if(tpr->eta - t->eta > separation_time) { // No probs, plane 2 can squeeze in before plane 1 with no apparent conflict
if(tpr->nextOnRwy) {
tpr->nextOnRwy = false;
t->nextOnRwy = true;
}
trafficList.insert(twrItr, t);
} else { // Ooops - this ones tricky - we have a potential conflict!
conflict = true;
// HACK - just add anyway for now and flag conflict - TODO - FIX THIS using CIRCUIT/STRAIGHT_IN and VFR/IFR precedence rules.
if(tpr->nextOnRwy) {
tpr->nextOnRwy = false;
t->nextOnRwy = true;
}
trafficList.insert(twrItr, t);
}
//cout << "\tC\t" << trafficList.size() << '\n';
return(conflict);
} }
return(conflict);
} }
} //}
//++twrItr;
} }
// If we get here we must be at the end of the list, or maybe the list is empty. // If we get here we must be at the end of the list, or maybe the list is empty.
if(!trafficList.size()) { if(!trafficList.size()) {
@ -853,6 +972,7 @@ bool FGTower::AddToTrafficList(TowerPlaneRec* t, bool holding) {
// conflict and firstTime should be false and true respectively in this case anyway. // conflict and firstTime should be false and true respectively in this case anyway.
} }
trafficList.push_back(t); trafficList.push_back(t);
//cout << "\tE\t" << trafficList.size() << '\n';
return(holding ? firstTime : conflict); return(holding ? firstTime : conflict);
} }
@ -860,17 +980,26 @@ bool FGTower::AddToTrafficList(TowerPlaneRec* t, bool holding) {
// Calculate the eta of a plane to the threshold. // Calculate the eta of a plane to the threshold.
// For ground traffic this is the fastest they can get there. // For ground traffic this is the fastest they can get there.
// For air traffic this is the middle approximation. // For air traffic this is the middle approximation.
void FGTower::CalcETA(TowerPlaneRec* tpr) { void FGTower::CalcETA(TowerPlaneRec* tpr, bool printout) {
// For now we'll be very crude and hardwire expected speeds to C172-like values // For now we'll be very crude and hardwire expected speeds to C172-like values
// The speeds below are specified in knots IAS and then converted to m/s // The speeds below are specified in knots IAS and then converted to m/s
double app_ias = 100.0 * 0.514444; // Speed during straight-in approach double app_ias = 100.0 * 0.514444; // Speed during straight-in approach
double circuit_ias = 80.0 * 0.514444; // Speed around circuit double circuit_ias = 80.0 * 0.514444; // Speed around circuit
double final_ias = 70.0 * 0.514444; // Speed during final approach double final_ias = 70.0 * 0.514444; // Speed during final approach
//if(printout) {
// cout << "In CalcETA, airplane ident = " << tpr->plane.callsign << '\n';
// cout << (tpr->isUser ? "USER\n" : "AI\n");
//}
// Sign convention - dist_out is -ve for approaching planes and +ve for departing planes // Sign convention - dist_out is -ve for approaching planes and +ve for departing planes
// dist_across is +ve in the pattern direction - ie a plane correctly on downwind will have a +ve dist_across // dist_across is +ve in the pattern direction - ie a plane correctly on downwind will have a +ve dist_across
Point3D op = ortho.ConvertToLocal(tpr->pos); Point3D op = ortho.ConvertToLocal(tpr->pos);
//if(printout) {
// cout << "Orthopos is " << op.x() << ", " << op.y() << '\n';
// cout << "opType is " << tpr->opType << '\n';
//}
double dist_out_m = op.y(); double dist_out_m = op.y();
double dist_across_m = fabs(op.x()); // FIXME = the fabs is a hack to cope with the fact that we don't know the circuit direction yet double dist_across_m = fabs(op.x()); // FIXME = the fabs is a hack to cope with the fact that we don't know the circuit direction yet
//cout << "Doing ETA calc for " << tpr->plane.callsign << '\n'; //cout << "Doing ETA calc for " << tpr->plane.callsign << '\n';
@ -884,6 +1013,9 @@ void FGTower::CalcETA(TowerPlaneRec* tpr) {
} }
} else if(tpr->opType == CIRCUIT || tpr->opType == TTT_UNKNOWN) { // Hack alert - UNKNOWN has sort of been added here as a temporary hack. } else if(tpr->opType == CIRCUIT || tpr->opType == TTT_UNKNOWN) { // Hack alert - UNKNOWN has sort of been added here as a temporary hack.
// It's complicated - depends on if base leg is delayed or not // It's complicated - depends on if base leg is delayed or not
//if(printout) {
// cout << "Leg = " << tpr->leg << '\n';
//}
if(tpr->leg == LANDING_ROLL) { if(tpr->leg == LANDING_ROLL) {
tpr->eta = 0; tpr->eta = 0;
} else if((tpr->leg == FINAL) || (tpr->leg == TURN4)) { } else if((tpr->leg == FINAL) || (tpr->leg == TURN4)) {
@ -904,20 +1036,42 @@ void FGTower::CalcETA(TowerPlaneRec* tpr) {
if(!GetDownwindConstraint(current_dist_across_m)) { if(!GetDownwindConstraint(current_dist_across_m)) {
current_dist_across_m = nominal_dist_across_m; current_dist_across_m = nominal_dist_across_m;
} }
double nominal_cross_dist_out_m = 1000; // Bit of a guess - AI plane turns to crosswind at 600ft agl. double nominal_cross_dist_out_m = 2000; // Bit of a guess - AI plane turns to crosswind at 600ft agl.
tpr->eta = fabs(current_base_dist_out_m) / final_ias; // final tpr->eta = fabs(current_base_dist_out_m) / final_ias; // final
//if(printout) cout << "a = " << tpr->eta << '\n';
if((tpr->leg == DOWNWIND) || (tpr->leg == TURN2)) { if((tpr->leg == DOWNWIND) || (tpr->leg == TURN2)) {
tpr->eta += dist_across_m / circuit_ias; tpr->eta += dist_across_m / circuit_ias;
//if(printout) cout << "b = " << tpr->eta << '\n';
tpr->eta += fabs(current_base_dist_out_m - dist_out_m) / circuit_ias; tpr->eta += fabs(current_base_dist_out_m - dist_out_m) / circuit_ias;
//if(printout) cout << "c = " << tpr->eta << '\n';
} else if((tpr->leg == CROSSWIND) || (tpr->leg == TURN1)) { } else if((tpr->leg == CROSSWIND) || (tpr->leg == TURN1)) {
tpr->eta += nominal_dist_across_m / circuit_ias; // should we use the dist across of the previous plane if there is previous still on downwind? if(dist_across_m > nominal_dist_across_m) {
tpr->eta += fabs(current_base_dist_out_m - nominal_cross_dist_out_m) / circuit_ias; tpr->eta += dist_across_m / circuit_ias;
tpr->eta += (nominal_dist_across_m - dist_across_m) / circuit_ias; } else {
tpr->eta += nominal_dist_across_m / circuit_ias;
}
// should we use the dist across of the previous plane if there is previous still on downwind?
//if(printout) cout << "bb = " << tpr->eta << '\n';
if(dist_out_m > nominal_cross_dist_out_m) {
tpr->eta += fabs(current_base_dist_out_m - dist_out_m) / circuit_ias;
} else {
tpr->eta += fabs(current_base_dist_out_m - nominal_cross_dist_out_m) / circuit_ias;
}
//if(printout) cout << "cc = " << tpr->eta << '\n';
if(nominal_dist_across_m > dist_across_m) {
tpr->eta += (nominal_dist_across_m - dist_across_m) / circuit_ias;
} else {
// Nothing to add
}
//if(printout) cout << "dd = " << tpr->eta << '\n';
} else { } else {
// We've only just started - why not use a generic estimate? // We've only just started - why not use a generic estimate?
tpr->eta = 240.0;
} }
} }
//cout << "ETA = " << tpr->eta << '\n'; //if(printout) {
// cout << "ETA = " << tpr->eta << '\n';
//}
} else { } else {
tpr->eta = 99999; tpr->eta = 99999;
} }
@ -960,17 +1114,55 @@ void FGTower::doThresholdETACalc() {
bool FGTower::doThresholdUseOrder() { bool FGTower::doThresholdUseOrder() {
bool conflict = false; bool conflict = false;
// TODO - write some code here! // Wipe out traffic list, go through circuit, app and hold list, and reorder them in traffic list.
// Here's the rather simplistic assumptions we're using:
// Currently all planes are assumed to be GA light singles with corresponding speeds and separation times.
// In order of priority for runway use:
// STRAIGHT_IN > CIRCUIT > HOLDING_FOR_DEPARTURE
// No modification of planes speeds occurs - conflicts are resolved by delaying turn for base,
// and holding planes until a space.
// When calculating if a holding plane can use the runway, time clearance from last departure
// as well as time clearance to next arrival must be considered.
trafficList.clear();
tower_plane_rec_list_iterator twrItr;
// Do the approach list first
for(twrItr = appList.begin(); twrItr != appList.end(); twrItr++) {
TowerPlaneRec* tpr = *twrItr;
conflict = AddToTrafficList(tpr);
}
// Then the circuit list
for(twrItr = circuitList.begin(); twrItr != circuitList.end(); twrItr++) {
TowerPlaneRec* tpr = *twrItr;
conflict = AddToTrafficList(tpr);
}
// And finally the hold list
for(twrItr = holdList.begin(); twrItr != holdList.end(); twrItr++) {
TowerPlaneRec* tpr = *twrItr;
AddToTrafficList(tpr, true);
}
if(0) {
//if(ident == "KEMT") {
for(twrItr = trafficList.begin(); twrItr != trafficList.end(); twrItr++) {
TowerPlaneRec* tpr = *twrItr;
cout << tpr->plane.callsign << '\t' << tpr->eta << '\t';
}
cout << '\n';
}
return(conflict); return(conflict);
} }
/*
void FGTower::doCommunication() { void FGTower::doCommunication() {
} }
*/
// Return the ETA of plane no. list_pos (1-based) in the traffic list. // Return the ETA of plane no. list_pos (1-based) in the traffic list.
// i.e. list_pos = 1 implies next to use runway. // i.e. list_pos = 1 implies next to use runway.
double FGTower::GetTrafficETA(unsigned int list_pos) { double FGTower::GetTrafficETA(unsigned int list_pos, bool printout) {
if(trafficList.size() < list_pos) { if(trafficList.size() < list_pos) {
return(99999); return(99999);
} }
@ -978,8 +1170,10 @@ double FGTower::GetTrafficETA(unsigned int list_pos) {
tower_plane_rec_list_iterator twrItr; tower_plane_rec_list_iterator twrItr;
twrItr = trafficList.begin(); twrItr = trafficList.begin();
for(unsigned int i = 1; i < list_pos; i++, twrItr++); for(unsigned int i = 1; i < list_pos; i++, twrItr++);
//cout << "ETA returned = " << (*twrItr)->eta << '\n'; TowerPlaneRec* tpr = *twrItr;
return((*twrItr)->eta); CalcETA(tpr, printout);
//cout << "ETA returned = " << tpr->eta << '\n';
return(tpr->eta);
} }
@ -1053,3 +1247,15 @@ void FGTower::RequestDepartureClearance(string ID) {
void FGTower::ReportRunwayVacated(string ID) { void FGTower::ReportRunwayVacated(string ID) {
//cout << "Report Runway Vacated Called...\n"; //cout << "Report Runway Vacated Called...\n";
} }
ostream& operator << (ostream& os, tower_traffic_type ttt) {
switch(ttt) {
case(CIRCUIT): return(os << "CIRCUIT");
case(INBOUND): return(os << "INBOUND");
case(OUTBOUND): return(os << "OUTBOUND");
case(TTT_UNKNOWN): return(os << "UNKNOWN");
case(STRAIGHT_IN): return(os << "STRAIGHT_IN");
}
return(os << "ERROR - Unknown switch in tower_traffic_type operator << ");
}

View file

@ -45,12 +45,15 @@ SG_USING_STD(ios);
enum tower_traffic_type { enum tower_traffic_type {
CIRCUIT, CIRCUIT,
INBOUND, INBOUND, // CIRCUIT traffic gets changed to INBOUND when on final of the full-stop circuit.
OUTBOUND, OUTBOUND,
TTT_UNKNOWN, // departure, but we don't know if for circuits or leaving properly TTT_UNKNOWN, // departure, but we don't know if for circuits or leaving properly
STRAIGHT_IN STRAIGHT_IN
// Umm - what's the difference between INBOUND and STRAIGHT_IN ? };
}; // TODO - need some differentiation of IFR and VFR traffic in order to give the former priority.
ostream& operator << (ostream& os, tower_traffic_type ttt);
// TODO - need some differentiation of IFR and VFR traffic in order to give the former priority.
// Structure for holding details of a plane under tower control. // Structure for holding details of a plane under tower control.
// Not fixed yet - may include more stuff later. // Not fixed yet - may include more stuff later.
@ -89,6 +92,8 @@ public:
// Whereabouts in circuit if doing circuits // Whereabouts in circuit if doing circuits
PatternLeg leg; PatternLeg leg;
LandingType landingType;
bool isUser; // true if this plane is the user bool isUser; // true if this plane is the user
}; };
@ -165,7 +170,7 @@ private:
// Calculate the eta of a plane to the threshold. // Calculate the eta of a plane to the threshold.
// For ground traffic this is the fastest they can get there. // For ground traffic this is the fastest they can get there.
// For air traffic this is the middle approximation. // For air traffic this is the middle approximation.
void CalcETA(TowerPlaneRec* tpr); void CalcETA(TowerPlaneRec* tpr, bool printout = false);
// Iterate through all the lists and call CalcETA for all the planes. // Iterate through all the lists and call CalcETA for all the planes.
void doThresholdETACalc(); void doThresholdETACalc();
@ -179,17 +184,25 @@ private:
// Calculate the crow-flys distance of a plane to the threshold in miles // Calculate the crow-flys distance of a plane to the threshold in miles
double CalcDistOutMiles(TowerPlaneRec* tpr); double CalcDistOutMiles(TowerPlaneRec* tpr);
/*
void doCommunication(); void doCommunication();
*/
void IssueLandingClearance(TowerPlaneRec* tpr); void IssueLandingClearance(TowerPlaneRec* tpr);
void IssueGoAround(TowerPlaneRec* tpr); void IssueGoAround(TowerPlaneRec* tpr);
void IssueDepartureClearance(TowerPlaneRec* tpr); void IssueDepartureClearance(TowerPlaneRec* tpr);
unsigned int update_count; // Convienince counter for speading computational load over several updates
unsigned int update_count_max; // ditto.
bool display; // Flag to indicate whether we should be outputting to the ATC display. 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. bool displaying; // Flag to indicate whether we are outputting to the ATC display.
bool freqClear; // Flag to indicate if the frequency is clear of ongoing dialog bool freqClear; // Flag to indicate if the frequency is clear of ongoing dialog
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.
// environment - need to make sure we're getting the surface winds and not winds aloft. // environment - need to make sure we're getting the surface winds and not winds aloft.
SGPropertyNode* wind_from_hdg; //degrees SGPropertyNode* wind_from_hdg; //degrees
SGPropertyNode* wind_speed_knots; //knots SGPropertyNode* wind_speed_knots; //knots
@ -247,7 +260,7 @@ private:
// Return the ETA of plane no. list_pos (1-based) in the traffic list. // Return the ETA of plane no. list_pos (1-based) in the traffic list.
// i.e. list_pos = 1 implies next to use runway. // i.e. list_pos = 1 implies next to use runway.
double GetTrafficETA(unsigned int list_pos); double GetTrafficETA(unsigned int list_pos, bool printout = false);
// Add a tower plane rec with ETA to the traffic list in the correct position ETA-wise. // 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. // Returns true if this could cause a threshold ETA conflict with other traffic, false otherwise.