1
0
Fork 0

* A new algorithm for determining hold position instructions. This version still needs some finetuning, but already appears to be more solid than the old version.

* Some tweaks to the traffic scheduling algorithm.
* Misc cleanup.
This commit is contained in:
Durk Talsma 2011-10-03 20:54:58 +02:00
parent ab84ff5904
commit 4640f5bb02
9 changed files with 1301 additions and 878 deletions

View file

@ -773,10 +773,10 @@ bool FGAIAircraft::leadPointReached(FGAIWaypoint* curr) {
} }
if (trafficRef) { if (trafficRef) {
//cerr << "Tracking callsign : \"" << fgGetString("/ai/track-callsign") << "\"" << endl; //cerr << "Tracking callsign : \"" << fgGetString("/ai/track-callsign") << "\"" << endl;
/* if (trafficRef->getCallSign() == fgGetString("/ai/track-callsign")) { if (trafficRef->getCallSign() == fgGetString("/ai/track-callsign")) {
cerr << trafficRef->getCallSign() << " " << tgt_altitude_ft << " " << _getSpeed() << " " cerr << trafficRef->getCallSign() << " " << tgt_altitude_ft << " " << _getSpeed() << " "
<< _getAltitude() << " "<< _getLatitude() << " " << _getLongitude() << " " << dist_to_go << " " << lead_dist << " " << curr->name << " " << vs << " " << tgt_vs << " " << bearing << " " << minBearing << " " << speedFraction << endl; << _getAltitude() << " "<< _getLatitude() << " " << _getLongitude() << " " << dist_to_go << " " << lead_dist << " " << curr->getName() << " " << vs << " " << tgt_vs << " " << bearing << " " << minBearing << " " << speedFraction << " " << invisible << endl;
}*/ }
} }
if ((dist_to_go < lead_dist) || (bearing > (minBearing * 1.1))) { if ((dist_to_go < lead_dist) || (bearing > (minBearing * 1.1))) {
minBearing = 360; minBearing = 360;
@ -1223,20 +1223,20 @@ bool FGAIAircraft::reachedEndOfCruise(double &distance) {
double distanceCovered = descentSpeed * descentTimeNeeded; double distanceCovered = descentSpeed * descentTimeNeeded;
//cerr << "Tracking : " << fgGetString("/ai/track-callsign"); //cerr << "Tracking : " << fgGetString("/ai/track-callsign");
if (trafficRef->getCallSign() == fgGetString("/ai/track-callsign")) { // if (trafficRef->getCallSign() == fgGetString("/ai/track-callsign")) {
cerr << "Checking for end of cruise stage for :" << trafficRef->getCallSign() << endl; // cerr << "Checking for end of cruise stage for :" << trafficRef->getCallSign() << endl;
cerr << "Descent rate : " << descentRate << endl; // cerr << "Descent rate : " << descentRate << endl;
cerr << "Descent speed : " << descentSpeed << endl; // cerr << "Descent speed : " << descentSpeed << endl;
cerr << "VerticalDistance : " << verticalDistance << ". Altitude : " << altitude_ft << ". Elevation " << trafficRef->getArrivalAirport()->getElevation() << endl; // cerr << "VerticalDistance : " << verticalDistance << ". Altitude : " << altitude_ft << ". Elevation " << trafficRef->getArrivalAirport()->getElevation() << endl;
cerr << "DecentTimeNeeded : " << descentTimeNeeded << endl; // cerr << "DecentTimeNeeded : " << descentTimeNeeded << endl;
cerr << "DistanceCovered : " << distanceCovered << endl; // cerr << "DistanceCovered : " << distanceCovered << endl;
} // }
//cerr << "Distance = " << distance << endl; //cerr << "Distance = " << distance << endl;
distance = distanceCovered; distance = distanceCovered;
if (dist < distanceCovered) { if (dist < distanceCovered) {
if (trafficRef->getCallSign() == fgGetString("/ai/track-callsign")) { // if (trafficRef->getCallSign() == fgGetString("/ai/track-callsign")) {
//exit(1); // //exit(1);
} // }
return true; return true;
} else { } else {
return false; return false;
@ -1290,8 +1290,8 @@ time_t FGAIAircraft::checkForArrivalTime(string wptName) {
time_t ete = tracklength / ((speed * SG_NM_TO_METER) / 3600.0); time_t ete = tracklength / ((speed * SG_NM_TO_METER) / 3600.0);
time_t secondsToGo = arrivalTime - now; time_t secondsToGo = arrivalTime - now;
if (trafficRef->getCallSign() == fgGetString("/ai/track-callsign")) { // if (trafficRef->getCallSign() == fgGetString("/ai/track-callsign")) {
cerr << "Checking arrival time: ete " << ete << ". Time to go : " << secondsToGo << ". Track length = " << tracklength << endl; // cerr << "Checking arrival time: ete " << ete << ". Time to go : " << secondsToGo << ". Track length = " << tracklength << endl;
} // }
return (ete - secondsToGo); // Positive when we're too slow... return (ete - secondsToGo); // Positive when we're too slow...
} }

View file

@ -62,6 +62,11 @@ bool FGAIFlightPlan::create(FGAIAircraft * ac, FGAirport * dep,
case 1: case 1:
retVal = createPushBack(ac, firstFlight, dep, latitude, longitude, retVal = createPushBack(ac, firstFlight, dep, latitude, longitude,
radius, fltType, aircraftType, airline); radius, fltType, aircraftType, airline);
// Pregenerate the
if (retVal) {
waypoints.back()->setName( waypoints.back()->getName() + string("legend"));
retVal = createTakeoffTaxi(ac, false, dep, radius, fltType, aircraftType, airline);
}
break; break;
case 2: case 2:
retVal = createTakeoffTaxi(ac, firstFlight, dep, radius, fltType, retVal = createTakeoffTaxi(ac, firstFlight, dep, radius, fltType,

View file

@ -247,5 +247,7 @@ void FGATCManager::update ( double time ) {
//cerr << "Adding groundnetWork to the scenegraph::update" << endl; //cerr << "Adding groundnetWork to the scenegraph::update" << endl;
prevController = controller; prevController = controller;
} }
//globals->get_scenery()->get_scene_graph()->addChild(node); for (AtcVecIterator atc = activeStations.begin(); atc != activeStations.end(); atc++) {
(*atc)->update(time);
}
} }

View file

@ -65,7 +65,7 @@ time_t ActiveRunway::requestTimeSlot(time_t eta)
TimeVectorIterator i = estimatedArrivalTimes.begin(); TimeVectorIterator i = estimatedArrivalTimes.begin();
//cerr << "Checking eta slots " << eta << ": " << endl; //cerr << "Checking eta slots " << eta << ": " << endl;
for (i = estimatedArrivalTimes.begin(); for (i = estimatedArrivalTimes.begin();
i != estimatedArrivalTimes.end(); i++) { i != estimatedArrivalTimes.end(); i++) {
//cerr << "Stored time : " << (*i) << endl; //cerr << "Stored time : " << (*i) << endl;
} }
i = estimatedArrivalTimes.begin(); i = estimatedArrivalTimes.begin();
@ -144,18 +144,20 @@ time_t ActiveRunway::requestTimeSlot(time_t eta)
* FGTrafficRecord * FGTrafficRecord
**************************************************************************/ **************************************************************************/
FGTrafficRecord::FGTrafficRecord(): FGTrafficRecord::FGTrafficRecord():
id(0), waitsForId(0), id(0), waitsForId(0),
currentPos(0), currentPos(0),
leg(0), leg(0),
frequencyId(0), frequencyId(0),
state(0), state(0),
allowTransmission(true), allowTransmission(true),
latitude(0), longitude(0), heading(0), speed(0), altitude(0), radius(0) allowPushback(true),
priority(0),
latitude(0), longitude(0), heading(0), speed(0), altitude(0), radius(0)
{ {
} }
void FGTrafficRecord::setPositionAndIntentions(int pos, void FGTrafficRecord::setPositionAndIntentions(int pos,
FGAIFlightPlan * route) FGAIFlightPlan * route)
{ {
currentPos = pos; currentPos = pos;
@ -166,7 +168,7 @@ void FGTrafficRecord::setPositionAndIntentions(int pos,
"Error in FGTrafficRecord::setPositionAndIntentions"); "Error in FGTrafficRecord::setPositionAndIntentions");
//cerr << "Pos : " << pos << " Curr " << *(intentions.begin()) << endl; //cerr << "Pos : " << pos << " Curr " << *(intentions.begin()) << endl;
for (intVecIterator i = intentions.begin(); for (intVecIterator i = intentions.begin();
i != intentions.end(); i++) { i != intentions.end(); i++) {
//cerr << (*i) << " "; //cerr << (*i) << " ";
} }
//cerr << endl; //cerr << endl;
@ -194,7 +196,7 @@ void FGTrafficRecord::setPositionAndIntentions(int pos,
//exit(1); //exit(1);
} }
/** /**
* Check if another aircraft is ahead of the current one, and on the same * Check if another aircraft is ahead of the current one, and on the same
* return true / false is the is/isn't the case. * return true / false is the is/isn't the case.
* *
****************************************************************************/ ****************************************************************************/
@ -207,10 +209,10 @@ bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord & other)
//cerr << callsign << ": Check Position and intentions: we are on the same taxiway" << other.callsign << "Index = " << currentPos << endl; //cerr << callsign << ": Check Position and intentions: we are on the same taxiway" << other.callsign << "Index = " << currentPos << endl;
result = true; result = true;
} }
// else if (other.intentions.size()) // else if (other.intentions.size())
// { // {
// cerr << "Start check 2" << endl; // cerr << "Start check 2" << endl;
// intVecIterator i = other.intentions.begin(); // intVecIterator i = other.intentions.begin();
// while (!((i == other.intentions.end()) || ((*i) == currentPos))) // while (!((i == other.intentions.end()) || ((*i) == currentPos)))
// i++; // i++;
// if (i != other.intentions.end()) { // if (i != other.intentions.end()) {
@ -237,8 +239,8 @@ bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord & other)
} }
void FGTrafficRecord::setPositionAndHeading(double lat, double lon, void FGTrafficRecord::setPositionAndHeading(double lat, double lon,
double hdg, double spd, double hdg, double spd,
double alt) double alt)
{ {
latitude = lat; latitude = lat;
longitude = lon; longitude = lon;
@ -251,12 +253,12 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net,
FGTrafficRecord & other) FGTrafficRecord & other)
{ {
if (checkPositionAndIntentions(other) if (checkPositionAndIntentions(other)
|| (other.checkPositionAndIntentions(*this))) || (other.checkPositionAndIntentions(*this)))
return -1; return -1;
intVecIterator i, j; intVecIterator i, j;
int currentTargetNode = 0, otherTargetNode = 0; int currentTargetNode = 0, otherTargetNode = 0;
if (currentPos > 0) if (currentPos > 0)
currentTargetNode = net->findSegment(currentPos)->getEnd()->getIndex(); // OKAY,... currentTargetNode = net->findSegment(currentPos)->getEnd()->getIndex(); // OKAY,...
if (other.currentPos > 0) if (other.currentPos > 0)
otherTargetNode = net->findSegment(other.currentPos)->getEnd()->getIndex(); // OKAY,... otherTargetNode = net->findSegment(other.currentPos)->getEnd()->getIndex(); // OKAY,...
if ((currentTargetNode == otherTargetNode) && currentTargetNode > 0) if ((currentTargetNode == otherTargetNode) && currentTargetNode > 0)
@ -265,7 +267,7 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net,
for (i = intentions.begin(); i != intentions.end(); i++) { for (i = intentions.begin(); i != intentions.end(); i++) {
if ((*i) > 0) { if ((*i) > 0) {
if ((currentTargetNode == if ((currentTargetNode ==
net->findSegment(*i)->getEnd()->getIndex())) { net->findSegment(*i)->getEnd()->getIndex())) {
//cerr << "Current crosses at " << currentTargetNode <<endl; //cerr << "Current crosses at " << currentTargetNode <<endl;
return currentTargetNode; return currentTargetNode;
} }
@ -274,10 +276,10 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net,
} }
if (other.intentions.size()) { if (other.intentions.size()) {
for (i = other.intentions.begin(); i != other.intentions.end(); for (i = other.intentions.begin(); i != other.intentions.end();
i++) { i++) {
if ((*i) > 0) { if ((*i) > 0) {
if (otherTargetNode == if (otherTargetNode ==
net->findSegment(*i)->getEnd()->getIndex()) { net->findSegment(*i)->getEnd()->getIndex()) {
//cerr << "Other crosses at " << currentTargetNode <<endl; //cerr << "Other crosses at " << currentTargetNode <<endl;
return otherTargetNode; return otherTargetNode;
} }
@ -287,7 +289,7 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net,
if (intentions.size() && other.intentions.size()) { if (intentions.size() && other.intentions.size()) {
for (i = intentions.begin(); i != intentions.end(); i++) { for (i = intentions.begin(); i != intentions.end(); i++) {
for (j = other.intentions.begin(); j != other.intentions.end(); for (j = other.intentions.begin(); j != other.intentions.end();
j++) { j++) {
//cerr << "finding segment " << *i << " and " << *j << endl; //cerr << "finding segment " << *i << " and " << *j << endl;
if (((*i) > 0) && ((*j) > 0)) { if (((*i) > 0) && ((*j) > 0)) {
currentTargetNode = currentTargetNode =
@ -318,7 +320,7 @@ bool FGTrafficRecord::onRoute(FGGroundNetwork * net,
return true; return true;
if (other.intentions.size()) { if (other.intentions.size()) {
for (intVecIterator i = other.intentions.begin(); for (intVecIterator i = other.intentions.begin();
i != other.intentions.end(); i++) { i != other.intentions.end(); i++) {
if (*i > 0) { if (*i > 0) {
othernode = net->findSegment(*i)->getEnd()->getIndex(); othernode = net->findSegment(*i)->getEnd()->getIndex();
if ((node == othernode) && (node > -1)) if ((node == othernode) && (node > -1))
@ -332,7 +334,7 @@ bool FGTrafficRecord::onRoute(FGGroundNetwork * net,
// { // {
// for (intVecIterator i = intentions.begin(); i != intentions.end(); i++) // for (intVecIterator i = intentions.begin(); i != intentions.end(); i++)
// { // {
// if (*i > 0) // if (*i > 0)
// { // {
// node = net->findSegment(*i)->getEnd()->getIndex(); // node = net->findSegment(*i)->getEnd()->getIndex();
// if ((node == othernode) && (node > -1)) // if ((node == othernode) && (node > -1))
@ -358,13 +360,13 @@ bool FGTrafficRecord::isOpposing(FGGroundNetwork * net,
} }
for (intVecIterator i = intentions.begin(); i != intentions.end(); for (intVecIterator i = intentions.begin(); i != intentions.end();
i++) { i++) {
if ((opp = net->findSegment(other.currentPos)->opposite())) { if ((opp = net->findSegment(other.currentPos)->opposite())) {
if ((*i) > 0) if ((*i) > 0)
if (opp->getIndex() == if (opp->getIndex() ==
net->findSegment(*i)->getIndex()) { net->findSegment(*i)->getIndex()) {
if (net->findSegment(*i)->getStart()->getIndex() == if (net->findSegment(*i)->getStart()->getIndex() ==
node) { node) {
{ {
//cerr << "Found the node " << node << endl; //cerr << "Found the node " << node << endl;
return true; return true;
@ -374,17 +376,17 @@ bool FGTrafficRecord::isOpposing(FGGroundNetwork * net,
} }
if (other.intentions.size()) { if (other.intentions.size()) {
for (intVecIterator j = other.intentions.begin(); for (intVecIterator j = other.intentions.begin();
j != other.intentions.end(); j++) { j != other.intentions.end(); j++) {
// cerr << "Current segment 1 " << (*i) << endl; // cerr << "Current segment 1 " << (*i) << endl;
if ((*i) > 0) { if ((*i) > 0) {
if ((opp = net->findSegment(*i)->opposite())) { if ((opp = net->findSegment(*i)->opposite())) {
if (opp->getIndex() == if (opp->getIndex() ==
net->findSegment(*j)->getIndex()) { net->findSegment(*j)->getIndex()) {
//cerr << "Nodes " << net->findSegment(*i)->getIndex() //cerr << "Nodes " << net->findSegment(*i)->getIndex()
// << " and " << net->findSegment(*j)->getIndex() // << " and " << net->findSegment(*j)->getIndex()
// << " are opposites " << endl; // << " are opposites " << endl;
if (net->findSegment(*i)->getStart()-> if (net->findSegment(*i)->getStart()->
getIndex() == node) { getIndex() == node) {
{ {
//cerr << "Found the node " << node << endl; //cerr << "Found the node " << node << endl;
return true; return true;
@ -400,6 +402,14 @@ bool FGTrafficRecord::isOpposing(FGGroundNetwork * net,
return false; return false;
} }
bool FGTrafficRecord::isActive(int margin)
{
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
time_t deptime = aircraft->getTrafficRef()->getDepartureTime();
return ((now + margin) > deptime);
}
void FGTrafficRecord::setSpeedAdjustment(double spd) void FGTrafficRecord::setSpeedAdjustment(double spd)
{ {
instruction.setChangeSpeed(true); instruction.setChangeSpeed(true);
@ -414,31 +424,12 @@ void FGTrafficRecord::setHeadingAdjustment(double heading)
bool FGTrafficRecord::pushBackAllowed() bool FGTrafficRecord::pushBackAllowed()
{ {
// With the user ATC / AI integration, checking whether the user's aircraft is near no longer works, because return allowPushback;
// this will effectively block the user's aircraft itself from receiving pushback clearance.
// So, what can we do?
/*
double course, az2, dist;
SGGeod curr(SGGeod::fromDegM(getLongitude(),
getLatitude(), getAltitude()));
double userLatitude = fgGetDouble("/position/latitude-deg");
double userLongitude = fgGetDouble("/position/longitude-deg");
SGGeod user(SGGeod::fromDeg(userLongitude, userLatitude));
SGGeodesy::inverse(curr, user, course, az2, dist);
//cerr << "Distance to user : " << dist << endl;
return (dist > 250);
*/
// In essence, we should check whether the pusbback route itself, as well as the associcated
// taxiways near the pushback point are free of traffic.
// To do so, we need to
return true;
} }
/*************************************************************************** /***************************************************************************
* FGATCInstruction * FGATCInstruction
* *
@ -483,7 +474,7 @@ FGATCController::FGATCController()
FGATCController::~FGATCController() FGATCController::~FGATCController()
{ {
//cerr << "running FGATController destructor" << endl; //cerr << "running FGATController destructor" << endl;
} }
string FGATCController::getGateName(FGAIAircraft * ref) string FGATCController::getGateName(FGAIAircraft * ref)
@ -491,9 +482,9 @@ string FGATCController::getGateName(FGAIAircraft * ref)
return ref->atGate(); return ref->atGate();
} }
bool FGATCController::isUserAircraft(FGAIAircraft* ac) bool FGATCController::isUserAircraft(FGAIAircraft* ac)
{ {
return (ac->getCallSign() == fgGetString("/sim/multiplay/callsign")) ? true : false; return (ac->getCallSign() == fgGetString("/sim/multiplay/callsign")) ? true : false;
}; };
void FGATCController::transmit(FGTrafficRecord * rec, AtcMsgId msgId, void FGATCController::transmit(FGTrafficRecord * rec, AtcMsgId msgId,
@ -536,7 +527,7 @@ void FGATCController::transmit(FGTrafficRecord * rec, AtcMsgId msgId,
taxiFreq = taxiFreq =
rec->getAircraft()->getTrafficRef()->getDepartureAirport()-> rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
getDynamics()->getGroundFrequency(2); getDynamics()->getGroundFrequency(2);
towerFreq = towerFreq =
rec->getAircraft()->getTrafficRef()->getDepartureAirport()-> rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
getDynamics()->getTowerFrequency(2); getDynamics()->getTowerFrequency(2);
receiver = receiver =
@ -585,11 +576,11 @@ void FGATCController::transmit(FGTrafficRecord * rec, AtcMsgId msgId,
getRunwayClassFromTrafficType(fltType); getRunwayClassFromTrafficType(fltType);
rec->getAircraft()->getTrafficRef()->getDepartureAirport()-> rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
getDynamics()->getActiveRunway(rwyClass, 1, activeRunway, getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
heading); heading);
rec->getAircraft()->GetFlightPlan()->setRunway(activeRunway); rec->getAircraft()->GetFlightPlan()->setRunway(activeRunway);
fp = rec->getAircraft()->getTrafficRef()->getDepartureAirport()-> fp = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
getDynamics()->getSID(activeRunway, heading); getDynamics()->getSID(activeRunway, heading);
rec->getAircraft()->GetFlightPlan()->setSID(fp); rec->getAircraft()->GetFlightPlan()->setSID(fp);
if (fp) { if (fp) {
SID = fp->getName() + " departure"; SID = fp->getName() + " departure";
@ -681,17 +672,17 @@ void FGATCController::transmit(FGTrafficRecord * rec, AtcMsgId msgId,
case MSG_REPORT_RUNWAY_HOLD_SHORT: case MSG_REPORT_RUNWAY_HOLD_SHORT:
activeRunway = rec->getAircraft()->GetFlightPlan()->getRunway(); activeRunway = rec->getAircraft()->GetFlightPlan()->getRunway();
//activeRunway = "test"; //activeRunway = "test";
text = receiver + ". Holding short runway " text = receiver + ". Holding short runway "
+ activeRunway + activeRunway
+ ". " + sender; + ". " + sender;
//text = "test1"; //text = "test1";
//cerr << "1 Currently at leg " << rec->getLeg() << endl; //cerr << "1 Currently at leg " << rec->getLeg() << endl;
break; break;
case MSG_ACKNOWLEDGE_REPORT_RUNWAY_HOLD_SHORT: case MSG_ACKNOWLEDGE_REPORT_RUNWAY_HOLD_SHORT:
activeRunway = rec->getAircraft()->GetFlightPlan()->getRunway(); activeRunway = rec->getAircraft()->GetFlightPlan()->getRunway();
text = receiver + "Roger. Holding short runway " text = receiver + "Roger. Holding short runway "
// + activeRunway // + activeRunway
+ ". " + sender; + ". " + sender;
//text = "test2"; //text = "test2";
//cerr << "2 Currently at leg " << rec->getLeg() << endl; //cerr << "2 Currently at leg " << rec->getLeg() << endl;
break; break;
@ -725,7 +716,7 @@ void FGATCController::transmit(FGTrafficRecord * rec, AtcMsgId msgId,
// the relevant frequency. // the relevant frequency.
// Note that distance attenuation is currently not yet implemented // Note that distance attenuation is currently not yet implemented
if ((onBoardRadioFreqI0 == stationFreq) if ((onBoardRadioFreqI0 == stationFreq)
|| (onBoardRadioFreqI1 == stationFreq)) { || (onBoardRadioFreqI1 == stationFreq)) {
if (rec->allowTransmissions()) { if (rec->allowTransmissions()) {
fgSetString("/sim/messages/atc", text.c_str()); fgSetString("/sim/messages/atc", text.c_str());
} }
@ -743,7 +734,7 @@ string FGATCController::formatATCFrequency3_2(int freq)
} }
// TODO: Set transponder codes according to real-world routes. // TODO: Set transponder codes according to real-world routes.
// The current version just returns a random string of four octal numbers. // The current version just returns a random string of four octal numbers.
string FGATCController::genTransponderCode(string fltRules) string FGATCController::genTransponderCode(string fltRules)
{ {
if (fltRules == "VFR") { if (fltRules == "VFR") {
@ -756,12 +747,12 @@ string FGATCController::genTransponderCode(string fltRules)
} }
} }
void FGATCController::init() void FGATCController::init()
{ {
if (!initialized) { if (!initialized) {
FGATCManager *mgr = (FGATCManager*) globals->get_subsystem("ATC"); FGATCManager *mgr = (FGATCManager*) globals->get_subsystem("ATC");
mgr->addController(this); mgr->addController(this);
initialized = true; initialized = true;
} }
} }
@ -770,19 +761,19 @@ void FGATCController::init()
* *
**************************************************************************/ **************************************************************************/
FGTowerController::FGTowerController(FGAirportDynamics *par) : FGTowerController::FGTowerController(FGAirportDynamics *par) :
FGATCController() FGATCController()
{ {
parent = par; parent = par;
} }
// //
void FGTowerController::announcePosition(int id, void FGTowerController::announcePosition(int id,
FGAIFlightPlan * intendedRoute, FGAIFlightPlan * intendedRoute,
int currentPosition, double lat, int currentPosition, double lat,
double lon, double heading, double lon, double heading,
double speed, double alt, double speed, double alt,
double radius, int leg, double radius, int leg,
FGAIAircraft * ref) FGAIAircraft * ref)
{ {
init(); init();
TrafficVectorIterator i = activeTraffic.begin(); TrafficVectorIterator i = activeTraffic.begin();
@ -809,7 +800,7 @@ void FGTowerController::announcePosition(int id,
rec.setRadius(radius); rec.setRadius(radius);
rec.setAircraft(ref); rec.setAircraft(ref);
activeTraffic.push_back(rec); activeTraffic.push_back(rec);
// Don't just schedule the aircraft for the tower controller, also assign if to the correct active runway. // Don't just schedule the aircraft for the tower controller, also assign if to the correct active runway.
ActiveRunwayVecIterator rwy = activeRunways.begin(); ActiveRunwayVecIterator rwy = activeRunways.begin();
if (activeRunways.size()) { if (activeRunways.size()) {
while (rwy != activeRunways.end()) { while (rwy != activeRunways.end()) {
@ -835,8 +826,8 @@ void FGTowerController::announcePosition(int id,
} }
void FGTowerController::updateAircraftInformation(int id, double lat, double lon, void FGTowerController::updateAircraftInformation(int id, double lat, double lon,
double heading, double speed, double alt, double heading, double speed, double alt,
double dt) double dt)
{ {
TrafficVectorIterator i = activeTraffic.begin(); TrafficVectorIterator i = activeTraffic.begin();
// Search whether the current id has an entry // Search whether the current id has an entry
@ -863,7 +854,7 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon
// see if we already have a clearance record for the currently active runway // see if we already have a clearance record for the currently active runway
// NOTE: dd. 2011-08-07: Because the active runway has been constructed in the announcePosition function, we may safely assume that is // NOTE: dd. 2011-08-07: Because the active runway has been constructed in the announcePosition function, we may safely assume that is
// already exists here. So, we can simplify the current code. // already exists here. So, we can simplify the current code.
ActiveRunwayVecIterator rwy = activeRunways.begin(); ActiveRunwayVecIterator rwy = activeRunways.begin();
while (rwy != activeRunways.end()) { while (rwy != activeRunways.end()) {
if (rwy->getRunwayName() == current->getRunway()) { if (rwy->getRunwayName() == current->getRunway()) {
@ -899,6 +890,8 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon
rwy->setCleared(id); rwy->setCleared(id);
} }
} }
} else {
} }
} }
@ -947,7 +940,7 @@ void FGTowerController::signOff(int id)
// NOTE: // NOTE:
// IF WE MAKE TRAFFICRECORD A MEMBER OF THE BASE CLASS // IF WE MAKE TRAFFICRECORD A MEMBER OF THE BASE CLASS
// THE FOLLOWING THREE FUNCTIONS: SIGNOFF, HAS INSTRUCTION AND GETINSTRUCTION CAN // THE FOLLOWING THREE FUNCTIONS: SIGNOFF, HAS INSTRUCTION AND GETINSTRUCTION CAN
// BECOME DEVIRTUALIZED AND BE A MEMBER OF THE BASE ATCCONTROLLER CLASS // BECOME DEVIRTUALIZED AND BE A MEMBER OF THE BASE ATCCONTROLLER CLASS
// WHICH WOULD SIMPLIFY CODE MAINTENANCE. // WHICH WOULD SIMPLIFY CODE MAINTENANCE.
// Note that this function is probably obsolete // Note that this function is probably obsolete
@ -1006,6 +999,11 @@ string FGTowerController::getName() {
return string(parent->getId() + "-tower"); return string(parent->getId() + "-tower");
} }
void FGTowerController::update(double dt)
{
}
/*************************************************************************** /***************************************************************************
@ -1013,18 +1011,18 @@ string FGTowerController::getName() {
* *
**************************************************************************/ **************************************************************************/
FGStartupController::FGStartupController(FGAirportDynamics *par): FGStartupController::FGStartupController(FGAirportDynamics *par):
FGATCController() FGATCController()
{ {
parent = par; parent = par;
} }
void FGStartupController::announcePosition(int id, void FGStartupController::announcePosition(int id,
FGAIFlightPlan * intendedRoute, FGAIFlightPlan * intendedRoute,
int currentPosition, double lat, int currentPosition, double lat,
double lon, double heading, double lon, double heading,
double speed, double alt, double speed, double alt,
double radius, int leg, double radius, int leg,
FGAIAircraft * ref) FGAIAircraft * ref)
{ {
init(); init();
TrafficVectorIterator i = activeTraffic.begin(); TrafficVectorIterator i = activeTraffic.begin();
@ -1061,7 +1059,7 @@ void FGStartupController::announcePosition(int id,
// NOTE: // NOTE:
// IF WE MAKE TRAFFICRECORD A MEMBER OF THE BASE CLASS // IF WE MAKE TRAFFICRECORD A MEMBER OF THE BASE CLASS
// THE FOLLOWING THREE FUNCTIONS: SIGNOFF, HAS INSTRUCTION AND GETINSTRUCTION CAN // THE FOLLOWING THREE FUNCTIONS: SIGNOFF, HAS INSTRUCTION AND GETINSTRUCTION CAN
// BECOME DEVIRTUALIZED AND BE A MEMBER OF THE BASE ATCCONTROLLER CLASS // BECOME DEVIRTUALIZED AND BE A MEMBER OF THE BASE ATCCONTROLLER CLASS
// WHICH WOULD SIMPLIFY CODE MAINTENANCE. // WHICH WOULD SIMPLIFY CODE MAINTENANCE.
// Note that this function is probably obsolete // Note that this function is probably obsolete
@ -1136,20 +1134,20 @@ void FGStartupController::signOff(int id)
} }
bool FGStartupController::checkTransmissionState(int st, time_t now, time_t startTime, TrafficVectorIterator i, AtcMsgId msgId, bool FGStartupController::checkTransmissionState(int st, time_t now, time_t startTime, TrafficVectorIterator i, AtcMsgId msgId,
AtcMsgDir msgDir) AtcMsgDir msgDir)
{ {
int state = i->getState(); int state = i->getState();
if ((state == st) && available) { if ((state == st) && available) {
if ((msgDir == ATC_AIR_TO_GROUND) && isUserAircraft(i->getAircraft())) { if ((msgDir == ATC_AIR_TO_GROUND) && isUserAircraft(i->getAircraft())) {
//cerr << "Checking state " << st << " for " << i->getAircraft()->getCallSign() << endl; //cerr << "Checking state " << st << " for " << i->getAircraft()->getCallSign() << endl;
static SGPropertyNode_ptr trans_num = globals->get_props()->getNode("/sim/atc/transmission-num", true); static SGPropertyNode_ptr trans_num = globals->get_props()->getNode("/sim/atc/transmission-num", true);
int n = trans_num->getIntValue(); int n = trans_num->getIntValue();
if (n == 0) { if (n == 0) {
trans_num->setIntValue(-1); trans_num->setIntValue(-1);
// PopupCallback(n); // PopupCallback(n);
//cerr << "Selected transmission message " << n << endl; //cerr << "Selected transmission message " << n << endl;
FGATCDialogNew::instance()->removeEntry(1); FGATCDialogNew::instance()->removeEntry(1);
} else { } else {
//cerr << "creading message for " << i->getAircraft()->getCallSign() << endl; //cerr << "creading message for " << i->getAircraft()->getCallSign() << endl;
transmit(&(*i), msgId, msgDir, false); transmit(&(*i), msgId, msgDir, false);
@ -1169,8 +1167,8 @@ bool FGStartupController::checkTransmissionState(int st, time_t now, time_t star
} }
void FGStartupController::updateAircraftInformation(int id, double lat, double lon, void FGStartupController::updateAircraftInformation(int id, double lat, double lon,
double heading, double speed, double alt, double heading, double speed, double alt,
double dt) double dt)
{ {
TrafficVectorIterator i = activeTraffic.begin(); TrafficVectorIterator i = activeTraffic.begin();
// Search search if the current id has an entry // Search search if the current id has an entry
@ -1198,11 +1196,11 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l
int state = i->getState(); int state = i->getState();
// The user controlled aircraft should have crased here, because it doesn't have a traffic reference. // The user controlled aircraft should have crased here, because it doesn't have a traffic reference.
// NOTE: if we create a traffic schedule for the user aircraft, we can use this to plan a flight. // NOTE: if we create a traffic schedule for the user aircraft, we can use this to plan a flight.
time_t startTime = i->getAircraft()->getTrafficRef()->getDepartureTime(); time_t startTime = i->getAircraft()->getTrafficRef()->getDepartureTime();
time_t now = time(NULL) + fgGetLong("/sim/time/warp"); time_t now = time(NULL) + fgGetLong("/sim/time/warp");
//cerr << i->getAircraft()->getTrafficRef()->getCallSign() //cerr << i->getAircraft()->getTrafficRef()->getCallSign()
// << " is scheduled to depart in " << startTime-now << " seconds. Available = " << available // << " is scheduled to depart in " << startTime-now << " seconds. Available = " << available
// << " at parking " << getGateName(i->getAircraft()) << endl; // << " at parking " << getGateName(i->getAircraft()) << endl;
@ -1222,7 +1220,7 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l
checkTransmissionState(7, now, (startTime + 180), i, MSG_REQUEST_PUSHBACK_CLEARANCE, ATC_AIR_TO_GROUND); checkTransmissionState(7, now, (startTime + 180), i, MSG_REQUEST_PUSHBACK_CLEARANCE, ATC_AIR_TO_GROUND);
if ((state == 8) && available) { if ((state == 8) && available) {
if (now > startTime + 200) { if (now > startTime + 200) {
if (i->pushBackAllowed()) { if (i->pushBackAllowed()) {
@ -1269,10 +1267,10 @@ void FGStartupController::render(bool visible)
//while (group->getNumChildren()) { //while (group->getNumChildren()) {
// cerr << "Number of children: " << group->getNumChildren() << endl; // cerr << "Number of children: " << group->getNumChildren() << endl;
//simgear::EffectGeode* geode = (simgear::EffectGeode*) group->getChild(0); //simgear::EffectGeode* geode = (simgear::EffectGeode*) group->getChild(0);
//osg::MatrixTransform *obj_trans = (osg::MatrixTransform*) group->getChild(0); //osg::MatrixTransform *obj_trans = (osg::MatrixTransform*) group->getChild(0);
//geode->releaseGLObjects(); //geode->releaseGLObjects();
//group->removeChild(geode); //group->removeChild(geode);
//delete geode; //delete geode;
group = 0; group = 0;
} }
if (visible) { if (visible) {
@ -1285,135 +1283,64 @@ void FGStartupController::render(bool visible)
//for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) { //for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) {
double dx = 0; double dx = 0;
for (TrafficVectorIterator i = activeTraffic.begin(); i != activeTraffic.end(); i++) { for (TrafficVectorIterator i = activeTraffic.begin(); i != activeTraffic.end(); i++) {
// Handle start point if (i->isActive(300)) {
int pos = i->getCurrentPosition(); // Handle start point
//cerr << "rendering for " << i->getAircraft()->getCallSign() << "pos = " << pos << endl; int pos = i->getCurrentPosition();
if (pos > 0) { //cerr << "rendering for " << i->getAircraft()->getCallSign() << "pos = " << pos << endl;
FGTaxiSegment *segment = parent->getGroundNetwork()->findSegment(pos); if (pos > 0) {
SGGeod start(SGGeod::fromDeg((i->getLongitude()), (i->getLatitude()))); FGTaxiSegment *segment = parent->getGroundNetwork()->findSegment(pos);
SGGeod end (SGGeod::fromDeg(segment->getEnd()->getLongitude(), segment->getEnd()->getLatitude())); SGGeod start(SGGeod::fromDeg((i->getLongitude()), (i->getLatitude())));
SGGeod end (SGGeod::fromDeg(segment->getEnd()->getLongitude(), segment->getEnd()->getLatitude()));
double length = SGGeodesy::distanceM(start, end); double length = SGGeodesy::distanceM(start, end);
//heading = SGGeodesy::headingDeg(start->getGeod(), end->getGeod()); //heading = SGGeodesy::headingDeg(start->getGeod(), end->getGeod());
double az2, heading; //, distanceM; double az2, heading; //, distanceM;
SGGeodesy::inverse(start, end, heading, az2, length); SGGeodesy::inverse(start, end, heading, az2, length);
double coveredDistance = length * 0.5; double coveredDistance = length * 0.5;
SGGeod center; SGGeod center;
SGGeodesy::direct(start, heading, coveredDistance, center, az2); SGGeodesy::direct(start, heading, coveredDistance, center, az2);
//cerr << "Active Aircraft : Centerpoint = (" << center.getLatitudeDeg() << ", " << center.getLongitudeDeg() << "). Heading = " << heading << endl; //cerr << "Active Aircraft : Centerpoint = (" << center.getLatitudeDeg() << ", " << center.getLongitudeDeg() << "). Heading = " << heading << endl;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Make a helper function out of this // Make a helper function out of this
osg::Matrix obj_pos; osg::Matrix obj_pos;
osg::MatrixTransform *obj_trans = new osg::MatrixTransform;
obj_trans->setDataVariance(osg::Object::STATIC);
// Experimental: Calculate slope here, based on length, and the individual elevations
double elevationStart;
if (isUserAircraft((i)->getAircraft())) {
elevationStart = fgGetDouble("/position/ground-elev-m");
} else {
elevationStart = ((i)->getAircraft()->_getAltitude());
}
double elevationEnd = segment->getEnd()->getElevation();
if ((elevationEnd == 0) || (elevationEnd == parent->getElevation())) {
SGGeod center2 = end;
center2.setElevationM(SG_MAX_ELEVATION_M);
if (local_scenery->get_elevation_m( center2, elevationEnd, NULL )) {
elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5;
//elevation_meters += 0.5;
}
else {
elevationEnd = parent->getElevation();
}
segment->getEnd()->setElevation(elevationEnd);
}
double elevationMean = (elevationStart + elevationEnd) / 2.0;
double elevDiff = elevationEnd - elevationStart;
double slope = atan2(elevDiff, length) * SGD_RADIANS_TO_DEGREES;
//cerr << "1. Using mean elevation : " << elevationMean << " and " << slope << endl;
WorldCoordinate( obj_pos, center.getLatitudeDeg(), center.getLongitudeDeg(), elevationMean + 0.5, -(heading), slope );
;
obj_trans->setMatrix( obj_pos );
//osg::Vec3 center(0, 0, 0)
float width = length /2.0;
osg::Vec3 corner(-width, 0, 0.25f);
osg::Vec3 widthVec(2*width + 1, 0, 0);
osg::Vec3 heightVec(0, 1, 0);
osg::Geometry* geometry;
geometry = osg::createTexturedQuadGeometry(corner, widthVec, heightVec);
simgear::EffectGeode* geode = new simgear::EffectGeode;
geode->setName("test");
geode->addDrawable(geometry);
//osg::Node *custom_obj;
SGMaterial *mat = matlib->find("UnidirectionalTaper");
if (mat)
geode->setEffect(mat->get_effect());
obj_trans->addChild(geode);
// wire as much of the scene graph together as we can
//->addChild( obj_trans );
group->addChild( obj_trans );
/////////////////////////////////////////////////////////////////////
} else {
//cerr << "BIG FAT WARNING: current position is here : " << pos << endl;
}
for(intVecIterator j = (i)->getIntentions().begin(); j != (i)->getIntentions().end(); j++) {
osg::Matrix obj_pos;
int k = (*j);
if (k > 0) {
//cerr << "rendering for " << i->getAircraft()->getCallSign() << "intention = " << k << endl;
osg::MatrixTransform *obj_trans = new osg::MatrixTransform; osg::MatrixTransform *obj_trans = new osg::MatrixTransform;
obj_trans->setDataVariance(osg::Object::STATIC); obj_trans->setDataVariance(osg::Object::STATIC);
FGTaxiSegment *segment = parent->getGroundNetwork()->findSegment(k); // Experimental: Calculate slope here, based on length, and the individual elevations
double elevationStart;
double elevationStart = segment->getStart()->getElevation(); if (isUserAircraft((i)->getAircraft())) {
double elevationEnd = segment->getEnd ()->getElevation(); elevationStart = fgGetDouble("/position/ground-elev-m");
if ((elevationStart == 0) || (elevationStart == parent->getElevation())) { } else {
SGGeod center2 = segment->getStart()->getGeod(); elevationStart = ((i)->getAircraft()->_getAltitude() * SG_FEET_TO_METER);
center2.setElevationM(SG_MAX_ELEVATION_M);
if (local_scenery->get_elevation_m( center2, elevationStart, NULL )) {
elevation_feet = elevationStart * SG_METER_TO_FEET + 0.5;
//elevation_meters += 0.5;
}
else {
elevationStart = parent->getElevation();
}
segment->getStart()->setElevation(elevationStart);
} }
double elevationEnd = segment->getEnd()->getElevation();
if ((elevationEnd == 0) || (elevationEnd == parent->getElevation())) { if ((elevationEnd == 0) || (elevationEnd == parent->getElevation())) {
SGGeod center2 = segment->getEnd()->getGeod(); SGGeod center2 = end;
center2.setElevationM(SG_MAX_ELEVATION_M); center2.setElevationM(SG_MAX_ELEVATION_M);
if (local_scenery->get_elevation_m( center2, elevationEnd, NULL )) { if (local_scenery->get_elevation_m( center2, elevationEnd, NULL )) {
elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5; elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5;
//elevation_meters += 0.5; //elevation_meters += 0.5;
} }
else { else {
elevationEnd = parent->getElevation(); elevationEnd = parent->getElevation();
} }
segment->getEnd()->setElevation(elevationEnd); segment->getEnd()->setElevation(elevationEnd);
} }
double elevationMean = (elevationStart + elevationEnd) / 2.0; double elevationMean = (elevationStart + elevationEnd) / 2.0;
double elevDiff = elevationEnd - elevationStart; double elevDiff = elevationEnd - elevationStart;
double length = segment->getLength();
double slope = atan2(elevDiff, length) * SGD_RADIANS_TO_DEGREES; double slope = atan2(elevDiff, length) * SGD_RADIANS_TO_DEGREES;
//cerr << "2. Using mean elevation : " << elevationMean << " and " << slope << endl;
//cerr << "1. Using mean elevation : " << elevationMean << " and " << slope << endl;
WorldCoordinate( obj_pos, segment->getLatitude(), segment->getLongitude(), elevationMean + 0.5, -(segment->getHeading()), slope ); WorldCoordinate( obj_pos, center.getLatitudeDeg(), center.getLongitudeDeg(), elevationMean + 0.5 + dx, -(heading), slope );
;
//WorldCoordinate( obj_pos, segment->getLatitude(), segment->getLongitude(), parent->getElevation()+8+dx, -(segment->getHeading()) );
obj_trans->setMatrix( obj_pos ); obj_trans->setMatrix( obj_pos );
//osg::Vec3 center(0, 0, 0) //osg::Vec3 center(0, 0, 0)
float width = segment->getLength() /2.0; float width = length /2.0;
osg::Vec3 corner(-width, 0, 0.25f); osg::Vec3 corner(-width, 0, 0.25f);
osg::Vec3 widthVec(2*width + 1, 0, 0); osg::Vec3 widthVec(2*width + 1, 0, 0);
osg::Vec3 heightVec(0, 1, 0); osg::Vec3 heightVec(0, 1, 0);
@ -1423,18 +1350,101 @@ void FGStartupController::render(bool visible)
geode->setName("test"); geode->setName("test");
geode->addDrawable(geometry); geode->addDrawable(geometry);
//osg::Node *custom_obj; //osg::Node *custom_obj;
SGMaterial *mat = matlib->find("UnidirectionalTaper"); SGMaterial *mat;
if (segment->hasBlock()) {
mat = matlib->find("UnidirectionalTaperRed");
} else {
mat = matlib->find("UnidirectionalTaperGreen");
}
if (mat) if (mat)
geode->setEffect(mat->get_effect()); geode->setEffect(mat->get_effect());
obj_trans->addChild(geode); obj_trans->addChild(geode);
// wire as much of the scene graph together as we can // wire as much of the scene graph together as we can
//->addChild( obj_trans ); //->addChild( obj_trans );
group->addChild( obj_trans ); group->addChild( obj_trans );
/////////////////////////////////////////////////////////////////////
} else { } else {
//cerr << "BIG FAT WARNING: k is here : " << pos << endl; //cerr << "BIG FAT WARNING: current position is here : " << pos << endl;
} }
for (intVecIterator j = (i)->getIntentions().begin(); j != (i)->getIntentions().end(); j++) {
osg::Matrix obj_pos;
int k = (*j);
if (k > 0) {
//cerr << "rendering for " << i->getAircraft()->getCallSign() << "intention = " << k << endl;
osg::MatrixTransform *obj_trans = new osg::MatrixTransform;
obj_trans->setDataVariance(osg::Object::STATIC);
FGTaxiSegment *segment = parent->getGroundNetwork()->findSegment(k);
double elevationStart = segment->getStart()->getElevation();
double elevationEnd = segment->getEnd ()->getElevation();
if ((elevationStart == 0) || (elevationStart == parent->getElevation())) {
SGGeod center2 = segment->getStart()->getGeod();
center2.setElevationM(SG_MAX_ELEVATION_M);
if (local_scenery->get_elevation_m( center2, elevationStart, NULL )) {
elevation_feet = elevationStart * SG_METER_TO_FEET + 0.5;
//elevation_meters += 0.5;
}
else {
elevationStart = parent->getElevation();
}
segment->getStart()->setElevation(elevationStart);
}
if ((elevationEnd == 0) || (elevationEnd == parent->getElevation())) {
SGGeod center2 = segment->getEnd()->getGeod();
center2.setElevationM(SG_MAX_ELEVATION_M);
if (local_scenery->get_elevation_m( center2, elevationEnd, NULL )) {
elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5;
//elevation_meters += 0.5;
}
else {
elevationEnd = parent->getElevation();
}
segment->getEnd()->setElevation(elevationEnd);
}
double elevationMean = (elevationStart + elevationEnd) / 2.0;
double elevDiff = elevationEnd - elevationStart;
double length = segment->getLength();
double slope = atan2(elevDiff, length) * SGD_RADIANS_TO_DEGREES;
//cerr << "2. Using mean elevation : " << elevationMean << " and " << slope << endl;
WorldCoordinate( obj_pos, segment->getLatitude(), segment->getLongitude(), elevationMean + 0.5 + dx, -(segment->getHeading()), slope );
//WorldCoordinate( obj_pos, segment->getLatitude(), segment->getLongitude(), parent->getElevation()+8+dx, -(segment->getHeading()) );
obj_trans->setMatrix( obj_pos );
//osg::Vec3 center(0, 0, 0)
float width = segment->getLength() /2.0;
osg::Vec3 corner(-width, 0, 0.25f);
osg::Vec3 widthVec(2*width + 1, 0, 0);
osg::Vec3 heightVec(0, 1, 0);
osg::Geometry* geometry;
geometry = osg::createTexturedQuadGeometry(corner, widthVec, heightVec);
simgear::EffectGeode* geode = new simgear::EffectGeode;
geode->setName("test");
geode->addDrawable(geometry);
//osg::Node *custom_obj;
SGMaterial *mat;
if (segment->hasBlock()) {
mat = matlib->find("UnidirectionalTaperRed");
} else {
mat = matlib->find("UnidirectionalTaperGreen");
}
if (mat)
geode->setEffect(mat->get_effect());
obj_trans->addChild(geode);
// wire as much of the scene graph together as we can
//->addChild( obj_trans );
group->addChild( obj_trans );
} else {
//cerr << "BIG FAT WARNING: k is here : " << pos << endl;
}
}
dx += 0.2;
} }
//dx += 0.1;
} }
globals->get_scenery()->get_scene_graph()->addChild(group); globals->get_scenery()->get_scene_graph()->addChild(group);
} }
@ -1444,25 +1454,31 @@ string FGStartupController::getName() {
return string(parent->getId() + "-startup"); return string(parent->getId() + "-startup");
} }
void FGStartupController::update(double dt)
{
}
/*************************************************************************** /***************************************************************************
* class FGApproachController * class FGApproachController
* *
**************************************************************************/ **************************************************************************/
FGApproachController::FGApproachController(FGAirportDynamics *par): FGApproachController::FGApproachController(FGAirportDynamics *par):
FGATCController() FGATCController()
{ {
parent = par; parent = par;
} }
// //
void FGApproachController::announcePosition(int id, void FGApproachController::announcePosition(int id,
FGAIFlightPlan * intendedRoute, FGAIFlightPlan * intendedRoute,
int currentPosition, int currentPosition,
double lat, double lon, double lat, double lon,
double heading, double speed, double heading, double speed,
double alt, double radius, double alt, double radius,
int leg, FGAIAircraft * ref) int leg, FGAIAircraft * ref)
{ {
init(); init();
TrafficVectorIterator i = activeTraffic.begin(); TrafficVectorIterator i = activeTraffic.begin();
@ -1494,8 +1510,8 @@ void FGApproachController::announcePosition(int id,
} }
void FGApproachController::updateAircraftInformation(int id, double lat, double lon, void FGApproachController::updateAircraftInformation(int id, double lat, double lon,
double heading, double speed, double alt, double heading, double speed, double alt,
double dt) double dt)
{ {
TrafficVectorIterator i = activeTraffic.begin(); TrafficVectorIterator i = activeTraffic.begin();
// Search search if the current id has an entry // Search search if the current id has an entry
@ -1567,6 +1583,10 @@ void FGApproachController::signOff(int id)
} }
} }
void FGApproachController::update(double dt)
{
}

View file

@ -38,11 +38,14 @@
#include <simgear/structure/SGReferenced.hxx> #include <simgear/structure/SGReferenced.hxx>
#include <simgear/structure/SGSharedPtr.hxx> #include <simgear/structure/SGSharedPtr.hxx>
#include <string> #include <string>
#include <vector> #include <vector>
#include <list>
using std::string; using std::string;
using std::vector; using std::vector;
using std::list;
typedef vector<int> intVec; typedef vector<int> intVec;
@ -62,43 +65,79 @@ class FGAirportDynamics;
class FGATCInstruction class FGATCInstruction
{ {
private: private:
bool holdPattern; bool holdPattern;
bool holdPosition; bool holdPosition;
bool changeSpeed; bool changeSpeed;
bool changeHeading; bool changeHeading;
bool changeAltitude; bool changeAltitude;
bool resolveCircularWait; bool resolveCircularWait;
double speed; double speed;
double heading; double heading;
double alt; double alt;
public: public:
FGATCInstruction(); FGATCInstruction();
bool hasInstruction (); bool hasInstruction ();
bool getHoldPattern () { return holdPattern; }; bool getHoldPattern () {
bool getHoldPosition () { return holdPosition; }; return holdPattern;
bool getChangeSpeed () { return changeSpeed; }; };
bool getChangeHeading () { return changeHeading; }; bool getHoldPosition () {
bool getChangeAltitude() { return changeAltitude; }; return holdPosition;
};
bool getChangeSpeed () {
return changeSpeed;
};
bool getChangeHeading () {
return changeHeading;
};
bool getChangeAltitude() {
return changeAltitude;
};
double getSpeed () { return speed; }; double getSpeed () {
double getHeading () { return heading; }; return speed;
double getAlt () { return alt; }; };
double getHeading () {
return heading;
};
double getAlt () {
return alt;
};
bool getCheckForCircularWait() { return resolveCircularWait; }; bool getCheckForCircularWait() {
return resolveCircularWait;
};
void setHoldPattern (bool val) { holdPattern = val; }; void setHoldPattern (bool val) {
void setHoldPosition (bool val) { holdPosition = val; }; holdPattern = val;
void setChangeSpeed (bool val) { changeSpeed = val; }; };
void setChangeHeading (bool val) { changeHeading = val; }; void setHoldPosition (bool val) {
void setChangeAltitude(bool val) { changeAltitude = val; }; holdPosition = val;
};
void setChangeSpeed (bool val) {
changeSpeed = val;
};
void setChangeHeading (bool val) {
changeHeading = val;
};
void setChangeAltitude(bool val) {
changeAltitude = val;
};
void setResolveCircularWait (bool val) { resolveCircularWait = val; }; void setResolveCircularWait (bool val) {
resolveCircularWait = val;
};
void setSpeed (double val) { speed = val; }; void setSpeed (double val) {
void setHeading (double val) { heading = val; }; speed = val;
void setAlt (double val) { alt = val; }; };
void setHeading (double val) {
heading = val;
};
void setAlt (double val) {
alt = val;
};
}; };
@ -111,88 +150,175 @@ public:
class FGTrafficRecord class FGTrafficRecord
{ {
private: private:
int id, waitsForId; int id, waitsForId;
int currentPos; int currentPos;
int leg; int leg;
int frequencyId; int frequencyId;
int state; int state;
bool allowTransmission; bool allowTransmission;
time_t timer; bool allowPushback;
intVec intentions; int priority;
FGATCInstruction instruction; time_t timer;
double latitude, longitude, heading, speed, altitude, radius; intVec intentions;
string runway; FGATCInstruction instruction;
//FGAISchedule *trafficRef; double latitude, longitude, heading, speed, altitude, radius;
FGAIAircraft *aircraft; string runway;
//FGAISchedule *trafficRef;
FGAIAircraft *aircraft;
public: public:
FGTrafficRecord(); FGTrafficRecord();
void setId(int val) { id = val; };
void setRadius(double rad) { radius = rad;};
void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
void setRunway(string rwy) { runway = rwy;};
void setLeg(int lg) { leg = lg;};
int getId() { return id;};
int getState() { return state;};
void setState(int s) { state = s;}
FGATCInstruction getInstruction() { return instruction;};
bool hasInstruction() { return instruction.hasInstruction(); };
void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
bool checkPositionAndIntentions(FGTrafficRecord &other);
int crosses (FGGroundNetwork *, FGTrafficRecord &other);
bool isOpposing (FGGroundNetwork *, FGTrafficRecord &other, int node);
bool onRoute(FGGroundNetwork *, FGTrafficRecord &other); void setId(int val) {
id = val;
};
void setRadius(double rad) {
radius = rad;
};
void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
void setRunway(string rwy) {
runway = rwy;
};
void setLeg(int lg) {
leg = lg;
};
int getId() {
return id;
};
int getState() {
return state;
};
void setState(int s) {
state = s;
}
FGATCInstruction getInstruction() {
return instruction;
};
bool hasInstruction() {
return instruction.hasInstruction();
};
void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
bool checkPositionAndIntentions(FGTrafficRecord &other);
int crosses (FGGroundNetwork *, FGTrafficRecord &other);
bool isOpposing (FGGroundNetwork *, FGTrafficRecord &other, int node);
bool isActive(int margin);
bool getSpeedAdjustment() { return instruction.getChangeSpeed(); }; bool onRoute(FGGroundNetwork *, FGTrafficRecord &other);
double getLatitude () { return latitude ; };
double getLongitude() { return longitude; };
double getHeading () { return heading ; };
double getSpeed () { return speed ; };
double getAltitude () { return altitude ; };
double getRadius () { return radius ; };
int getWaitsForId () { return waitsForId; }; bool getSpeedAdjustment() {
return instruction.getChangeSpeed();
};
void setSpeedAdjustment(double spd); double getLatitude () {
void setHeadingAdjustment(double heading); return latitude ;
void clearSpeedAdjustment () { instruction.setChangeSpeed (false); }; };
void clearHeadingAdjustment() { instruction.setChangeHeading(false); }; double getLongitude() {
return longitude;
};
double getHeading () {
return heading ;
};
double getSpeed () {
return speed ;
};
double getAltitude () {
return altitude ;
};
double getRadius () {
return radius ;
};
bool hasHeadingAdjustment() { return instruction.getChangeHeading(); }; int getWaitsForId () {
bool hasHoldPosition() { return instruction.getHoldPosition(); }; return waitsForId;
void setHoldPosition (bool inst) { instruction.setHoldPosition(inst); }; };
void setWaitsForId(int id) { waitsForId = id; }; void setSpeedAdjustment(double spd);
void setHeadingAdjustment(double heading);
void clearSpeedAdjustment () {
instruction.setChangeSpeed (false);
};
void clearHeadingAdjustment() {
instruction.setChangeHeading(false);
};
void setResolveCircularWait() { instruction.setResolveCircularWait(true); }; bool hasHeadingAdjustment() {
void clearResolveCircularWait() { instruction.setResolveCircularWait(false); }; return instruction.getChangeHeading();
};
bool hasHoldPosition() {
return instruction.getHoldPosition();
};
void setHoldPosition (bool inst) {
instruction.setHoldPosition(inst);
};
string getRunway() { return runway; }; void setWaitsForId(int id) {
//void setCallSign(string clsgn) { callsign = clsgn; }; waitsForId = id;
void setAircraft(FGAIAircraft *ref) { aircraft = ref;}; };
void updateState() { state++; allowTransmission=true; };
//string getCallSign() { return callsign; };
FGAIAircraft *getAircraft() { return aircraft;};
int getTime() { return timer; };
int getLeg() { return leg; };
void setTime(time_t time) { timer = time; };
bool pushBackAllowed(); void setResolveCircularWait() {
bool allowTransmissions() { return allowTransmission; }; instruction.setResolveCircularWait(true);
void suppressRepeatedTransmissions () { allowTransmission=false; }; };
void allowRepeatedTransmissions () { allowTransmission=true; }; void clearResolveCircularWait() {
void nextFrequency() { frequencyId++; }; instruction.setResolveCircularWait(false);
int getNextFrequency() { return frequencyId; }; };
intVec& getIntentions() { return intentions; };
int getCurrentPosition() { return currentPos; }; string getRunway() {
return runway;
};
//void setCallSign(string clsgn) { callsign = clsgn; };
void setAircraft(FGAIAircraft *ref) {
aircraft = ref;
};
void updateState() {
state++;
allowTransmission=true;
};
//string getCallSign() { return callsign; };
FGAIAircraft *getAircraft() {
return aircraft;
};
int getTime() {
return timer;
};
int getLeg() {
return leg;
};
void setTime(time_t time) {
timer = time;
};
bool pushBackAllowed();
bool allowTransmissions() {
return allowTransmission;
};
void allowPushBack() { allowPushback =true;};
void denyPushBack () { allowPushback = false;};
void suppressRepeatedTransmissions () {
allowTransmission=false;
};
void allowRepeatedTransmissions () {
allowTransmission=true;
};
void nextFrequency() {
frequencyId++;
};
int getNextFrequency() {
return frequencyId;
};
intVec& getIntentions() {
return intentions;
};
int getCurrentPosition() {
return currentPos;
};
void setPriority(int p) { priority = p; };
int getPriority() { return priority; };
}; };
typedef vector<FGTrafficRecord> TrafficVector; typedef list<FGTrafficRecord> TrafficVector;
typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator; typedef list<FGTrafficRecord>::iterator TrafficVectorIterator;
typedef vector<time_t> TimeVector; typedef vector<time_t> TimeVector;
typedef vector<time_t>::iterator TimeVectorIterator; typedef vector<time_t>::iterator TimeVectorIterator;
@ -207,28 +333,48 @@ typedef vector<FGAIAircraft*>::iterator AircraftVecIterator;
class ActiveRunway class ActiveRunway
{ {
private: private:
string rwy; string rwy;
int currentlyCleared; int currentlyCleared;
double distanceToFinal; double distanceToFinal;
TimeVector estimatedArrivalTimes; TimeVector estimatedArrivalTimes;
AircraftVec departureCue; AircraftVec departureCue;
public: public:
ActiveRunway(string r, int cc) { rwy = r; currentlyCleared = cc; distanceToFinal = 6.0 * SG_NM_TO_METER; }; ActiveRunway(string r, int cc) {
rwy = r;
string getRunwayName() { return rwy; }; currentlyCleared = cc;
int getCleared () { return currentlyCleared; }; distanceToFinal = 6.0 * SG_NM_TO_METER;
double getApproachDistance() { return distanceToFinal; }; };
//time_t getEstApproachTime() { return estimatedArrival; };
//void setEstApproachTime(time_t time) { estimatedArrival = time; }; string getRunwayName() {
void addToDepartureCue(FGAIAircraft *ac) { departureCue.push_back(ac); }; return rwy;
void setCleared(int number) { currentlyCleared = number; }; };
time_t requestTimeSlot(time_t eta); int getCleared () {
return currentlyCleared;
};
double getApproachDistance() {
return distanceToFinal;
};
//time_t getEstApproachTime() { return estimatedArrival; };
int getDepartureCueSize() { return departureCue.size(); }; //void setEstApproachTime(time_t time) { estimatedArrival = time; };
FGAIAircraft* getFirstAircraftInDepartureCue() { return departureCue.size() ? *(departureCue.begin()) : NULL; }; void addToDepartureCue(FGAIAircraft *ac) {
void updateDepartureCue() { departureCue.erase(departureCue.begin()); } departureCue.push_back(ac);
};
void setCleared(int number) {
currentlyCleared = number;
};
time_t requestTimeSlot(time_t eta);
int getDepartureCueSize() {
return departureCue.size();
};
FGAIAircraft* getFirstAircraftInDepartureCue() {
return departureCue.size() ? *(departureCue.begin()) : NULL;
};
void updateDepartureCue() {
departureCue.erase(departureCue.begin());
}
}; };
typedef vector<ActiveRunway> ActiveRunwayVec; typedef vector<ActiveRunway> ActiveRunwayVec;
@ -236,79 +382,86 @@ typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
/** /**
* class FGATCController * class FGATCController
* NOTE: this class serves as an abstraction layer for all sorts of ATC controllers. * NOTE: this class serves as an abstraction layer for all sorts of ATC controllers.
*************************************************************************************/ *************************************************************************************/
class FGATCController class FGATCController
{ {
private: private:
protected: protected:
bool initialized; bool initialized;
bool available; bool available;
time_t lastTransmission; time_t lastTransmission;
double dt_count; double dt_count;
osg::Group* group; osg::Group* group;
string formatATCFrequency3_2(int ); string formatATCFrequency3_2(int );
string genTransponderCode(string fltRules); string genTransponderCode(string fltRules);
bool isUserAircraft(FGAIAircraft*); bool isUserAircraft(FGAIAircraft*);
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, MSG_ACKNOWLEDGE_SWITCH_GROUND_FREQUENCY,
MSG_INITIATE_CONTACT, MSG_INITIATE_CONTACT,
MSG_ACKNOWLEDGE_INITIATE_CONTACT, MSG_ACKNOWLEDGE_INITIATE_CONTACT,
MSG_REQUEST_TAXI_CLEARANCE, MSG_REQUEST_TAXI_CLEARANCE,
MSG_ISSUE_TAXI_CLEARANCE, MSG_ISSUE_TAXI_CLEARANCE,
MSG_ACKNOWLEDGE_TAXI_CLEARANCE, MSG_ACKNOWLEDGE_TAXI_CLEARANCE,
MSG_HOLD_POSITION, MSG_HOLD_POSITION,
MSG_ACKNOWLEDGE_HOLD_POSITION, MSG_ACKNOWLEDGE_HOLD_POSITION,
MSG_RESUME_TAXI, MSG_RESUME_TAXI,
MSG_ACKNOWLEDGE_RESUME_TAXI, MSG_ACKNOWLEDGE_RESUME_TAXI,
MSG_REPORT_RUNWAY_HOLD_SHORT, MSG_REPORT_RUNWAY_HOLD_SHORT,
MSG_ACKNOWLEDGE_REPORT_RUNWAY_HOLD_SHORT, MSG_ACKNOWLEDGE_REPORT_RUNWAY_HOLD_SHORT,
MSG_SWITCH_TOWER_FREQUENCY, MSG_SWITCH_TOWER_FREQUENCY,
MSG_ACKNOWLEDGE_SWITCH_TOWER_FREQUENCY MSG_ACKNOWLEDGE_SWITCH_TOWER_FREQUENCY
} AtcMsgId; } AtcMsgId;
typedef enum { typedef enum {
ATC_AIR_TO_GROUND, ATC_AIR_TO_GROUND,
ATC_GROUND_TO_AIR } AtcMsgDir; ATC_GROUND_TO_AIR
FGATCController(); } AtcMsgDir;
virtual ~FGATCController(); FGATCController();
void init(); virtual ~FGATCController();
void init();
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,
double hdg, double spd, double alt, double radius, int leg, double hdg, double spd, double alt, double radius, int leg,
FGAIAircraft *aircraft) = 0; FGAIAircraft *aircraft) = 0;
virtual void signOff(int id) = 0; virtual void signOff(int id) = 0;
virtual void updateAircraftInformation(int id, double lat, double lon, virtual void updateAircraftInformation(int id, double lat, double lon,
double heading, double speed, double alt, double dt) = 0; double heading, double speed, double alt, double dt) = 0;
virtual bool hasInstruction(int id) = 0; virtual bool hasInstruction(int id) = 0;
virtual FGATCInstruction getInstruction(int id) = 0; virtual FGATCInstruction getInstruction(int id) = 0;
double getDt() { return dt_count; }; double getDt() {
void setDt(double dt) { dt_count = dt;}; return dt_count;
void transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir msgDir, bool audible); };
string getGateName(FGAIAircraft *aircraft); void setDt(double dt) {
virtual void render(bool) = 0; dt_count = dt;
virtual string getName() = 0; };
void transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir msgDir, bool audible);
string getGateName(FGAIAircraft *aircraft);
virtual void render(bool) = 0;
virtual string getName() = 0;
virtual void update(double) = 0;
private: private:
AtcMsgDir lastTransmissionDirection; AtcMsgDir lastTransmissionDirection;
}; };
/****************************************************************************** /******************************************************************************
@ -317,65 +470,75 @@ private:
class FGTowerController : public FGATCController class FGTowerController : public FGATCController
{ {
private: private:
TrafficVector activeTraffic; TrafficVector activeTraffic;
ActiveRunwayVec activeRunways; ActiveRunwayVec activeRunways;
FGAirportDynamics *parent; FGAirportDynamics *parent;
public:
FGTowerController(FGAirportDynamics *parent);
virtual ~FGTowerController() {};
virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
double lat, double lon,
double hdg, double spd, double alt, double radius, int leg,
FGAIAircraft *aircraft);
virtual void signOff(int id);
virtual void updateAircraftInformation(int id, double lat, double lon,
double heading, double speed, double alt, double dt);
virtual bool hasInstruction(int id);
virtual FGATCInstruction getInstruction(int id);
virtual void render(bool); public:
virtual string getName(); FGTowerController(FGAirportDynamics *parent);
bool hasActiveTraffic() { return activeTraffic.size() != 0; }; virtual ~FGTowerController() {};
TrafficVector &getActiveTraffic() { return activeTraffic; }; virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
double lat, double lon,
double hdg, double spd, double alt, double radius, int leg,
FGAIAircraft *aircraft);
virtual void signOff(int id);
virtual void updateAircraftInformation(int id, double lat, double lon,
double heading, double speed, double alt, double dt);
virtual bool hasInstruction(int id);
virtual FGATCInstruction getInstruction(int id);
virtual void render(bool);
virtual string getName();
virtual void update(double dt);
bool hasActiveTraffic() {
return activeTraffic.size() != 0;
};
TrafficVector &getActiveTraffic() {
return activeTraffic;
};
}; };
/****************************************************************************** /******************************************************************************
* class FGStartupController * class FGStartupController
* handle * handle
*****************************************************************************/ *****************************************************************************/
class FGStartupController : public FGATCController class FGStartupController : public FGATCController
{ {
private: private:
TrafficVector activeTraffic; TrafficVector activeTraffic;
//ActiveRunwayVec activeRunways; //ActiveRunwayVec activeRunways;
FGAirportDynamics *parent; FGAirportDynamics *parent;
public: public:
FGStartupController(FGAirportDynamics *parent); FGStartupController(FGAirportDynamics *parent);
virtual ~FGStartupController() {}; virtual ~FGStartupController() {};
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,
double hdg, double spd, double alt, double radius, int leg, double hdg, double spd, double alt, double radius, int leg,
FGAIAircraft *aircraft); FGAIAircraft *aircraft);
virtual void signOff(int id); virtual void signOff(int id);
virtual void updateAircraftInformation(int id, double lat, double lon, virtual void updateAircraftInformation(int id, double lat, double lon,
double heading, double speed, double alt, double dt); double heading, double speed, double alt, double dt);
virtual bool hasInstruction(int id); virtual bool hasInstruction(int id);
virtual FGATCInstruction getInstruction(int id); virtual FGATCInstruction getInstruction(int id);
virtual void render(bool); virtual void render(bool);
virtual string getName(); virtual string getName();
virtual void update(double dt);
bool hasActiveTraffic() { return activeTraffic.size() != 0; }; bool hasActiveTraffic() {
TrafficVector &getActiveTraffic() { return activeTraffic; }; return activeTraffic.size() != 0;
};
TrafficVector &getActiveTraffic() {
return activeTraffic;
};
// Hpoefully, we can move this function to the base class, but I need to verify what is needed for the other controllers before doing so. // Hpoefully, we can move this function to the base class, but I need to verify what is needed for the other controllers before doing so.
bool checkTransmissionState(int st, time_t now, time_t startTime, TrafficVectorIterator i, AtcMsgId msgId, bool checkTransmissionState(int st, time_t now, time_t startTime, TrafficVectorIterator i, AtcMsgId msgId,
AtcMsgDir msgDir); AtcMsgDir msgDir);
}; };
/****************************************************************************** /******************************************************************************
* class FGTowerControl * class FGTowerControl
@ -383,30 +546,35 @@ public:
class FGApproachController : public FGATCController class FGApproachController : public FGATCController
{ {
private: private:
TrafficVector activeTraffic; TrafficVector activeTraffic;
ActiveRunwayVec activeRunways; ActiveRunwayVec activeRunways;
FGAirportDynamics *parent; FGAirportDynamics *parent;
public: public:
FGApproachController(FGAirportDynamics * parent); FGApproachController(FGAirportDynamics * parent);
virtual ~FGApproachController() { }; virtual ~FGApproachController() { };
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,
double hdg, double spd, double alt, double radius, int leg, double hdg, double spd, double alt, double radius, int leg,
FGAIAircraft *aircraft); FGAIAircraft *aircraft);
virtual void signOff(int id); virtual void signOff(int id);
virtual void updateAircraftInformation(int id, double lat, double lon, virtual void updateAircraftInformation(int id, double lat, double lon,
double heading, double speed, double alt, double dt); double heading, double speed, double alt, double dt);
virtual bool hasInstruction(int id); virtual bool hasInstruction(int id);
virtual FGATCInstruction getInstruction(int id); virtual FGATCInstruction getInstruction(int id);
virtual void render(bool); virtual void render(bool);
virtual string getName(); virtual string getName();
virtual void update(double dt);
ActiveRunway* getRunway(string name); ActiveRunway* getRunway(string name);
bool hasActiveTraffic() { return activeTraffic.size() != 0; }; bool hasActiveTraffic() {
TrafficVector &getActiveTraffic() { return activeTraffic; }; return activeTraffic.size() != 0;
};
TrafficVector &getActiveTraffic() {
return activeTraffic;
};
}; };

View file

@ -35,93 +35,117 @@ class FGEnvironment;
class FGAirportDynamics { class FGAirportDynamics {
private: private:
FGAirport* _ap; FGAirport* _ap;
FGParkingVec parkings; FGParkingVec parkings;
FGRunwayPreference rwyPrefs; FGRunwayPreference rwyPrefs;
FGSidStar SIDs; FGSidStar SIDs;
FGStartupController startupController; FGStartupController startupController;
FGGroundNetwork groundNetwork; FGGroundNetwork groundNetwork;
FGTowerController towerController; FGTowerController towerController;
FGApproachController approachController; FGApproachController approachController;
time_t lastUpdate; time_t lastUpdate;
std::string prevTrafficType; std::string prevTrafficType;
stringVec landing; stringVec landing;
stringVec takeoff; stringVec takeoff;
stringVec milActive, comActive, genActive, ulActive; stringVec milActive, comActive, genActive, ulActive;
stringVec *currentlyActive; stringVec *currentlyActive;
intVec freqAwos; // </AWOS> intVec freqAwos; // </AWOS>
intVec freqUnicom; // </UNICOM> intVec freqUnicom; // </UNICOM>
intVec freqClearance;// </CLEARANCE> intVec freqClearance;// </CLEARANCE>
intVec freqGround; // </GROUND> intVec freqGround; // </GROUND>
intVec freqTower; // </TOWER> intVec freqTower; // </TOWER>
intVec freqApproach; // </APPROACH> intVec freqApproach; // </APPROACH>
int atisSequenceIndex; int atisSequenceIndex;
double atisSequenceTimeStamp; double atisSequenceTimeStamp;
std::string chooseRunwayFallback();
bool innerGetActiveRunway(const std::string &trafficType, int action, std::string &runway, double heading);
std::string chooseRwyByHeading(stringVec rwys, double heading);
double elevation; std::string chooseRunwayFallback();
bool innerGetActiveRunway(const std::string &trafficType, int action, std::string &runway, double heading);
std::string chooseRwyByHeading(stringVec rwys, double heading);
double elevation;
public: public:
FGAirportDynamics(FGAirport* ap); FGAirportDynamics(FGAirport* ap);
~FGAirportDynamics(); ~FGAirportDynamics();
void addAwosFreq (int val) { freqAwos.push_back(val); }; void addAwosFreq (int val) {
void addUnicomFreq (int val) { freqUnicom.push_back(val); }; freqAwos.push_back(val);
void addClearanceFreq(int val) { freqClearance.push_back(val); }; };
void addGroundFreq (int val) { freqGround.push_back(val); }; void addUnicomFreq (int val) {
void addTowerFreq (int val) { freqTower.push_back(val); }; freqUnicom.push_back(val);
void addApproachFreq (int val) { freqApproach.push_back(val); }; };
void addClearanceFreq(int val) {
freqClearance.push_back(val);
};
void addGroundFreq (int val) {
freqGround.push_back(val);
};
void addTowerFreq (int val) {
freqTower.push_back(val);
};
void addApproachFreq (int val) {
freqApproach.push_back(val);
};
void init(); void init();
double getLongitude() const; double getLongitude() const;
// Returns degrees // Returns degrees
double getLatitude() const; double getLatitude() const;
// Returns ft // Returns ft
double getElevation() const; double getElevation() const;
const string& getId() const; const string& getId() const;
void getActiveRunway(const string& trafficType, int action, string& runway, double heading);
void addParking(FGParking& park); void getActiveRunway(const string& trafficType, int action, string& runway, double heading);
bool getAvailableParking(double *lat, double *lon,
double *heading, int *gate, double rad, const string& fltype,
const string& acType, const string& airline);
void getParking (int id, double *lat, double* lon, double *heading);
FGParking *getParking(int i);
void releaseParking(int id);
string getParkingName(int i);
int getNrOfParkings() { return parkings.size(); };
//FGAirport *getAddress() { return this; };
//const string &getName() const { return _name;};
// Returns degrees
// Departure / Arrival procedures void addParking(FGParking& park);
FGSidStar * getSIDs() { return &SIDs; }; bool getAvailableParking(double *lat, double *lon,
FGAIFlightPlan * getSID(string activeRunway, double heading); double *heading, int *gate, double rad, const string& fltype,
const string& acType, const string& airline);
void getParking (int id, double *lat, double* lon, double *heading);
FGParking *getParking(int i);
void releaseParking(int id);
string getParkingName(int i);
int getNrOfParkings() {
return parkings.size();
};
//FGAirport *getAddress() { return this; };
//const string &getName() const { return _name;};
// Returns degrees
// Departure / Arrival procedures
FGSidStar * getSIDs() {
return &SIDs;
};
FGAIFlightPlan * getSID(string activeRunway, double heading);
// ATC related functions. // ATC related functions.
FGStartupController *getStartupController() { return &startupController; }; FGStartupController *getStartupController() {
FGGroundNetwork *getGroundNetwork() { return &groundNetwork; }; return &startupController;
FGTowerController *getTowerController() { return &towerController; }; };
FGApproachController *getApproachController() { return &approachController; }; FGGroundNetwork *getGroundNetwork() {
return &groundNetwork;
};
FGTowerController *getTowerController() {
return &towerController;
};
FGApproachController *getApproachController() {
return &approachController;
};
int getGroundFrequency(unsigned leg); int getGroundFrequency(unsigned leg);
int getTowerFrequency (unsigned nr); int getTowerFrequency (unsigned nr);
/// get current ATIS sequence letter
const std::string getAtisSequence();
/// get the current ATIS sequence number, updating it if necessary /// get current ATIS sequence letter
int updateAtisSequence(int interval, bool forceUpdate); const std::string getAtisSequence();
void setRwyUse(const FGRunwayPreference& ref); /// get the current ATIS sequence number, updating it if necessary
int updateAtisSequence(int interval, bool forceUpdate);
void setRwyUse(const FGRunwayPreference& ref);
}; };

View file

@ -88,7 +88,7 @@ void FGTaxiSegment::setEnd(FGTaxiNodeVector * nodes)
// There is probably a computationally cheaper way of // There is probably a computationally cheaper way of
// doing this. // doing this.
void FGTaxiSegment::setDimensions(double elevation) void FGTaxiSegment::setDimensions(double elevation)
{ {
@ -164,9 +164,9 @@ bool FGTaxiRoute::next(int *nde, int *rte)
} else { } else {
// If currNode points to the first node, this means the aircraft is not on the taxi node // If currNode points to the first node, this means the aircraft is not on the taxi node
// yet. Make sure to return a unique identifyer in this situation though, because otherwise // yet. Make sure to return a unique identifyer in this situation though, because otherwise
// the speed adjust AI code may be unable to resolve whether two aircraft are on the same // the speed adjust AI code may be unable to resolve whether two aircraft are on the same
// taxi route or not. the negative of the preceding route seems a logical choice, as it is // taxi route or not. the negative of the preceding route seems a logical choice, as it is
// unique for any starting location. // unique for any starting location.
// Note that this is probably just a temporary fix until I get Parking / tower control working. // Note that this is probably just a temporary fix until I get Parking / tower control working.
*rte = -1 * *(currRoute); *rte = -1 * *(currRoute);
} }
@ -205,6 +205,11 @@ bool compare_segments(FGTaxiSegment * a, FGTaxiSegment * b)
return (*a) < (*b); return (*a) < (*b);
} }
bool compare_trafficrecords(FGTrafficRecord a, FGTrafficRecord b)
{
return (a.getIntentions().size() < b.getIntentions().size());
}
FGGroundNetwork::FGGroundNetwork() FGGroundNetwork::FGGroundNetwork()
{ {
hasNetwork = false; hasNetwork = false;
@ -244,18 +249,18 @@ FGGroundNetwork::~FGGroundNetwork()
} }
cachefile << "[GroundNetcachedata:ref:2011:09:04]" << endl; cachefile << "[GroundNetcachedata:ref:2011:09:04]" << endl;
for (FGTaxiNodeVectorIterator node = nodes.begin(); for (FGTaxiNodeVectorIterator node = nodes.begin();
node != nodes.end(); node++) { node != nodes.end(); node++) {
if (saveData) { if (saveData) {
cachefile << (*node)->getIndex () << " " cachefile << (*node)->getIndex () << " "
<< (*node)->getElevation () << " " << (*node)->getElevation () << " "
<< endl; << endl;
} }
delete(*node); delete(*node);
} }
nodes.clear(); nodes.clear();
pushBackNodes.clear(); pushBackNodes.clear();
for (FGTaxiSegmentVectorIterator seg = segments.begin(); for (FGTaxiSegmentVectorIterator seg = segments.begin();
seg != segments.end(); seg++) { seg != segments.end(); seg++) {
delete(*seg); delete(*seg);
} }
segments.clear(); segments.clear();
@ -288,12 +293,12 @@ void FGGroundNetwork::saveElevationCache() {
} }
cachefile << "[GroundNetcachedata:ref:2011:09:04]" << endl; cachefile << "[GroundNetcachedata:ref:2011:09:04]" << endl;
for (FGTaxiNodeVectorIterator node = nodes.begin(); for (FGTaxiNodeVectorIterator node = nodes.begin();
node != nodes.end(); node++) { node != nodes.end(); node++) {
if (saveData) { if (saveData) {
cachefile << (*node)->getIndex () << " " cachefile << (*node)->getIndex () << " "
<< (*node)->getElevation () << " " << (*node)->getElevation () << " "
<< endl; << endl;
} }
} }
if (saveData) { if (saveData) {
cachefile.close(); cachefile.close();
@ -405,12 +410,12 @@ void FGGroundNetwork::init()
string revisionStr; string revisionStr;
data >> revisionStr; data >> revisionStr;
if (revisionStr != "[GroundNetcachedata:ref:2011:09:04]") { if (revisionStr != "[GroundNetcachedata:ref:2011:09:04]") {
SG_LOG(SG_GENERAL, SG_ALERT,"GroundNetwork Warning: discarding outdated cachefile " << SG_LOG(SG_GENERAL, SG_ALERT,"GroundNetwork Warning: discarding outdated cachefile " <<
cacheData.c_str() << " for Airport " << airport); cacheData.c_str() << " for Airport " << airport);
} else { } else {
for (FGTaxiNodeVectorIterator i = nodes.begin(); for (FGTaxiNodeVectorIterator i = nodes.begin();
i != nodes.end(); i != nodes.end();
i++) { i++) {
(*i)->setElevation(parent->getElevation() * SG_FEET_TO_METER); (*i)->setElevation(parent->getElevation() * SG_FEET_TO_METER);
data >> index >> elev; data >> index >> elev;
if (data.eof()) if (data.eof())
@ -435,7 +440,7 @@ int FGGroundNetwork::findNearestNode(const SGGeod & aGeod)
int index = -1; int index = -1;
for (FGTaxiNodeVectorIterator itr = nodes.begin(); itr != nodes.end(); for (FGTaxiNodeVectorIterator itr = nodes.begin(); itr != nodes.end();
itr++) { itr++) {
double d = SGGeodesy::distanceM(aGeod, (*itr)->getGeod()); double d = SGGeodesy::distanceM(aGeod, (*itr)->getGeod());
if (d < minDist) { if (d < minDist) {
minDist = d; minDist = d;
@ -454,7 +459,7 @@ int FGGroundNetwork::findNearestNode(double lat, double lon)
FGTaxiNode *FGGroundNetwork::findNode(unsigned idx) FGTaxiNode *FGGroundNetwork::findNode(unsigned idx)
{ /* { /*
for (FGTaxiNodeVectorIterator for (FGTaxiNodeVectorIterator
itr = nodes.begin(); itr = nodes.begin();
itr != nodes.end(); itr++) itr != nodes.end(); itr++)
{ {
@ -470,13 +475,13 @@ FGTaxiNode *FGGroundNetwork::findNode(unsigned idx)
FGTaxiSegment *FGGroundNetwork::findSegment(unsigned idx) FGTaxiSegment *FGGroundNetwork::findSegment(unsigned idx)
{ /* { /*
for (FGTaxiSegmentVectorIterator for (FGTaxiSegmentVectorIterator
itr = segments.begin(); itr = segments.begin();
itr != segments.end(); itr++) itr != segments.end(); itr++)
{ {
if (itr->getIndex() == idx) if (itr->getIndex() == idx)
return itr->getAddress(); return itr->getAddress();
} }
*/ */
if ((idx > 0) && (idx <= segments.size())) if ((idx > 0) && (idx <= segments.size()))
return segments[idx - 1]->getAddress(); return segments[idx - 1]->getAddress();
@ -488,7 +493,7 @@ FGTaxiSegment *FGGroundNetwork::findSegment(unsigned idx)
FGTaxiRoute FGGroundNetwork::findShortestRoute(int start, int end, FGTaxiRoute FGGroundNetwork::findShortestRoute(int start, int end,
bool fullSearch) bool fullSearch)
{ {
//implements Dijkstra's algorithm to find shortest distance route from start to end //implements Dijkstra's algorithm to find shortest distance route from start to end
//taken from http://en.wikipedia.org/wiki/Dijkstra's_algorithm //taken from http://en.wikipedia.org/wiki/Dijkstra's_algorithm
@ -504,7 +509,7 @@ FGTaxiRoute FGGroundNetwork::findShortestRoute(int start, int end,
} }
for (FGTaxiNodeVectorIterator for (FGTaxiNodeVectorIterator
itr = currNodesSet->begin(); itr != currNodesSet->end(); itr++) { itr = currNodesSet->begin(); itr != currNodesSet->end(); itr++) {
(*itr)->setPathScore(HUGE_VAL); //infinity by all practical means (*itr)->setPathScore(HUGE_VAL); //infinity by all practical means
(*itr)->setPreviousNode(0); // (*itr)->setPreviousNode(0); //
(*itr)->setPreviousSeg(0); // (*itr)->setPreviousSeg(0); //
@ -520,7 +525,7 @@ FGTaxiRoute FGGroundNetwork::findShortestRoute(int start, int end,
while (!unvisited.empty()) { while (!unvisited.empty()) {
FGTaxiNode *best = *(unvisited.begin()); FGTaxiNode *best = *(unvisited.begin());
for (FGTaxiNodeVectorIterator for (FGTaxiNodeVectorIterator
itr = unvisited.begin(); itr != unvisited.end(); itr++) { itr = unvisited.begin(); itr != unvisited.end(); itr++) {
if ((*itr)->getPathScore() < best->getPathScore()) if ((*itr)->getPathScore() < best->getPathScore())
best = (*itr); best = (*itr);
} }
@ -533,8 +538,8 @@ FGTaxiRoute FGGroundNetwork::findShortestRoute(int start, int end,
break; break;
} else { } else {
for (FGTaxiSegmentVectorIterator for (FGTaxiSegmentVectorIterator
seg = best->getBeginRoute(); seg = best->getBeginRoute();
seg != best->getEndRoute(); seg++) { seg != best->getEndRoute(); seg++) {
if (fullSearch || (*seg)->isPushBack()) { if (fullSearch || (*seg)->isPushBack()) {
FGTaxiNode *tgt = (*seg)->getEnd(); FGTaxiNode *tgt = (*seg)->getEnd();
double alt = double alt =
@ -623,7 +628,8 @@ void FGGroundNetwork::announcePosition(int id,
rec.setPositionAndHeading(lat, lon, heading, speed, alt); rec.setPositionAndHeading(lat, lon, heading, speed, alt);
rec.setRadius(radius); // only need to do this when creating the record. rec.setRadius(radius); // only need to do this when creating the record.
rec.setAircraft(aircraft); rec.setAircraft(aircraft);
activeTraffic.push_back(rec); activeTraffic.push_front(rec);
} else { } else {
i->setPositionAndIntentions(currentPosition, intendedRoute); i->setPositionAndIntentions(currentPosition, intendedRoute);
i->setPositionAndHeading(lat, lon, heading, speed, alt); i->setPositionAndHeading(lat, lon, heading, speed, alt);
@ -666,7 +672,7 @@ void FGGroundNetwork::signOff(int id)
* 9 = Acknowledge switch tower frequency * 9 = Acknowledge switch tower frequency
*************************************************************************************************************************/ *************************************************************************************************************************/
bool FGGroundNetwork::checkTransmissionState(int minState, int maxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId, bool FGGroundNetwork::checkTransmissionState(int minState, int maxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
AtcMsgDir msgDir) AtcMsgDir msgDir)
{ {
int state = i->getState(); int state = i->getState();
if ((state >= minState) && (state <= maxState) && available) { if ((state >= minState) && (state <= maxState) && available) {
@ -676,10 +682,10 @@ bool FGGroundNetwork::checkTransmissionState(int minState, int maxState, Traffic
int n = trans_num->getIntValue(); int n = trans_num->getIntValue();
if (n == 0) { if (n == 0) {
trans_num->setIntValue(-1); trans_num->setIntValue(-1);
// PopupCallback(n); // PopupCallback(n);
//cerr << "Selected transmission message " << n << endl; //cerr << "Selected transmission message " << n << endl;
FGATCManager *atc = (FGATCManager*) globals->get_subsystem("atc"); FGATCManager *atc = (FGATCManager*) globals->get_subsystem("atc");
FGATCDialogNew::instance()->removeEntry(1); FGATCDialogNew::instance()->removeEntry(1);
} else { } else {
//cerr << "creating message for " << i->getAircraft()->getCallSign() << endl; //cerr << "creating message for " << i->getAircraft()->getCallSign() << endl;
transmit(&(*i), msgId, msgDir, false); transmit(&(*i), msgId, msgDir, false);
@ -696,18 +702,18 @@ bool FGGroundNetwork::checkTransmissionState(int minState, int maxState, Traffic
} }
void FGGroundNetwork::updateAircraftInformation(int id, double lat, double lon, void FGGroundNetwork::updateAircraftInformation(int id, double lat, double lon,
double heading, double speed, double alt, double heading, double speed, double alt,
double dt) double dt)
{ {
time_t currentTime = time(NULL); time_t currentTime = time(NULL);
if (nextSave < currentTime) { if (nextSave < currentTime) {
saveElevationCache(); saveElevationCache();
nextSave = currentTime + 100 + rand() % 200; nextSave = currentTime + 100 + rand() % 200;
} }
// Check whether aircraft are on hold due to a preceding pushback. If so, make sure to // Check whether aircraft are on hold due to a preceding pushback. If so, make sure to
// Transmit air-to-ground "Ready to taxi request: // Transmit air-to-ground "Ready to taxi request:
// Transmit ground to air approval / hold // Transmit ground to air approval / hold
// Transmit confirmation ... // Transmit confirmation ...
// Probably use a status mechanism similar to the Engine start procedure in the startup controller. // Probably use a status mechanism similar to the Engine start procedure in the startup controller.
@ -747,9 +753,9 @@ void FGGroundNetwork::updateAircraftInformation(int id, double lat, double lon,
bool needsTaxiClearance = current->getAircraft()->getTaxiClearanceRequest(); bool needsTaxiClearance = current->getAircraft()->getTaxiClearanceRequest();
if (!needsTaxiClearance) { if (!needsTaxiClearance) {
checkHoldPosition(id, lat, lon, heading, speed, alt); checkHoldPosition(id, lat, lon, heading, speed, alt);
if (checkForCircularWaits(id)) { //if (checkForCircularWaits(id)) {
i->setResolveCircularWait(); // i->setResolveCircularWait();
} //}
} else { } else {
current->setHoldPosition(true); current->setHoldPosition(true);
int state = current->getState(); int state = current->getState();
@ -783,7 +789,7 @@ void FGGroundNetwork::updateAircraftInformation(int id, double lat, double lon,
aircraft. For traffic that is on other routes we need to issue a "HOLD Position" aircraft. For traffic that is on other routes we need to issue a "HOLD Position"
instruction. See below for the hold position instruction. instruction. See below for the hold position instruction.
Note that there currently still is one flaw in the logic that needs to be addressed. Note that there currently still is one flaw in the logic that needs to be addressed.
There can be situations where one aircraft is in front of the current aircraft, on a separate There can be situations where one aircraft is in front of the current aircraft, on a separate
route, but really close after an intersection coming off the current route. This route, but really close after an intersection coming off the current route. This
aircraft is still close enough to block the current aircraft. This situation is currently aircraft is still close enough to block the current aircraft. This situation is currently
@ -791,11 +797,11 @@ void FGGroundNetwork::updateAircraftInformation(int id, double lat, double lon,
*/ */
void FGGroundNetwork::checkSpeedAdjustment(int id, double lat, void FGGroundNetwork::checkSpeedAdjustment(int id, double lat,
double lon, double heading, double lon, double heading,
double speed, double alt) double speed, double alt)
{ {
TrafficVectorIterator current, closest; TrafficVectorIterator current, closest, closestOnNetwork;
TrafficVectorIterator i = activeTraffic.begin(); TrafficVectorIterator i = activeTraffic.begin();
bool otherReasonToSlowDown = false; bool otherReasonToSlowDown = false;
bool previousInstruction; bool previousInstruction;
@ -825,7 +831,7 @@ void FGGroundNetwork::checkSpeedAdjustment(int id, double lat,
//TrafficVector iterator closest; //TrafficVector iterator closest;
closest = current; closest = current;
for (TrafficVectorIterator i = activeTraffic.begin(); for (TrafficVectorIterator i = activeTraffic.begin();
i != activeTraffic.end(); i++) { i != activeTraffic.end(); i++) {
if (i == current) { if (i == current) {
continue; continue;
} }
@ -840,14 +846,16 @@ void FGGroundNetwork::checkSpeedAdjustment(int id, double lat,
if ((dist < mindist) && (bearing < 60.0)) { if ((dist < mindist) && (bearing < 60.0)) {
mindist = dist; mindist = dist;
closest = i; closest = i;
closestOnNetwork = i;
minbearing = bearing; minbearing = bearing;
} }
} }
//Check traffic at the tower controller //Check traffic at the tower controller
if (towerController->hasActiveTraffic()) { if (towerController->hasActiveTraffic()) {
for (TrafficVectorIterator i = for (TrafficVectorIterator i =
towerController->getActiveTraffic().begin(); towerController->getActiveTraffic().begin();
i != towerController->getActiveTraffic().end(); i++) { i != towerController->getActiveTraffic().end(); i++) {
//cerr << "Comparing " << current->getId() << " and " << i->getId() << endl; //cerr << "Comparing " << current->getId() << " and " << i->getId() << endl;
SGGeod other(SGGeod::fromDegM(i->getLongitude(), SGGeod other(SGGeod::fromDegM(i->getLongitude(),
i->getLatitude(), i->getLatitude(),
@ -858,8 +866,8 @@ void FGGroundNetwork::checkSpeedAdjustment(int id, double lat,
bearing = 360 - bearing; bearing = 360 - bearing;
if ((dist < mindist) && (bearing < 60.0)) { if ((dist < mindist) && (bearing < 60.0)) {
//cerr << "Current aircraft " << current->getAircraft()->getTrafficRef()->getCallSign() //cerr << "Current aircraft " << current->getAircraft()->getTrafficRef()->getCallSign()
// << " is closest to " << i->getAircraft()->getTrafficRef()->getCallSign() // << " is closest to " << i->getAircraft()->getTrafficRef()->getCallSign()
// << ", which has status " << i->getAircraft()->isScheduledForTakeoff() // << ", which has status " << i->getAircraft()->isScheduledForTakeoff()
// << endl; // << endl;
mindist = dist; mindist = dist;
closest = i; closest = i;
@ -887,9 +895,9 @@ void FGGroundNetwork::checkSpeedAdjustment(int id, double lat,
} }
*/ */
current->clearSpeedAdjustment(); current->clearSpeedAdjustment();
bool needBraking = false;
if (current->checkPositionAndIntentions(*closest) if (current->checkPositionAndIntentions(*closest)
|| otherReasonToSlowDown) { || otherReasonToSlowDown) {
double maxAllowableDistance = double maxAllowableDistance =
(1.1 * current->getRadius()) + (1.1 * current->getRadius()) +
(1.1 * closest->getRadius()); (1.1 * closest->getRadius());
@ -901,12 +909,13 @@ void FGGroundNetwork::checkSpeedAdjustment(int id, double lat,
if (closest->getId() != current->getId()) { if (closest->getId() != current->getId()) {
current->setSpeedAdjustment(closest->getSpeed() * current->setSpeedAdjustment(closest->getSpeed() *
(mindist / 100)); (mindist / 100));
if ( needBraking = true;
closest->getAircraft()->getTakeOffStatus() && if (
closest->getAircraft()->getTakeOffStatus() &&
(current->getAircraft()->getTrafficRef()->getDepartureAirport() == closest->getAircraft()->getTrafficRef()->getDepartureAirport()) && (current->getAircraft()->getTrafficRef()->getDepartureAirport() == closest->getAircraft()->getTrafficRef()->getDepartureAirport()) &&
(current->getAircraft()->GetFlightPlan()->getRunway() == closest->getAircraft()->GetFlightPlan()->getRunway()) (current->getAircraft()->GetFlightPlan()->getRunway() == closest->getAircraft()->GetFlightPlan()->getRunway())
) )
current->getAircraft()->scheduleForATCTowerDepartureControl(1); current->getAircraft()->scheduleForATCTowerDepartureControl(1);
} else { } else {
current->setSpeedAdjustment(0); // This can only happen when the user aircraft is the one closest current->setSpeedAdjustment(0); // This can only happen when the user aircraft is the one closest
} }
@ -920,6 +929,9 @@ void FGGroundNetwork::checkSpeedAdjustment(int id, double lat,
} }
} }
} }
if ((closest == closestOnNetwork) && (current->getPriority() < closest->getPriority()) && needBraking) {
swap(current, closest);
}
} }
} }
@ -938,7 +950,7 @@ void FGGroundNetwork::checkHoldPosition(int id, double lat,
TrafficVectorIterator current; TrafficVectorIterator current;
TrafficVectorIterator i = activeTraffic.begin(); TrafficVectorIterator i = activeTraffic.begin();
if (activeTraffic.size()) { if (activeTraffic.size()) {
//while ((i->getId() != id) && i != activeTraffic.end()) //while ((i->getId() != id) && i != activeTraffic.end())
while (i != activeTraffic.end()) { while (i != activeTraffic.end()) {
if (i->getId() == id) { if (i->getId() == id) {
break; break;
@ -956,80 +968,100 @@ void FGGroundNetwork::checkHoldPosition(int id, double lat,
bool origStatus = current->hasHoldPosition(); bool origStatus = current->hasHoldPosition();
current->setHoldPosition(false); current->setHoldPosition(false);
SGGeod curr(SGGeod::fromDegM(lon, lat, alt)); SGGeod curr(SGGeod::fromDegM(lon, lat, alt));
int currentRoute = i->getCurrentPosition();
int nextRoute;
if (i->getIntentions().size()) {
nextRoute = (*(i->getIntentions().begin()));
} else {
nextRoute = 0;
}
if (currentRoute > 0) {
FGTaxiSegment *tx = findSegment(currentRoute);
FGTaxiSegment *nx;
if (nextRoute) {
nx = findSegment(nextRoute);
} else {
nx = tx;
}
if (tx->hasBlock() || nx->hasBlock() ) {
current->setHoldPosition(true);
}
}
for (i = activeTraffic.begin(); i != activeTraffic.end(); i++) {
if (i->getId() != current->getId()) {
int node = current->crosses(this, *i);
if (node != -1) {
FGTaxiNode *taxiNode = findNode(node);
// Determine whether it's save to continue or not. /* for (i = activeTraffic.begin(); i != activeTraffic.end(); i++) {
// If we have a crossing route, there are two possibilities: if (i->getId() != current->getId()) {
// 1) This is an interestion int node = current->crosses(this, *i);
// 2) This is oncoming two-way traffic, using the same taxiway. if (node != -1) {
//cerr << "Hold check 1 : " << id << " has common node " << node << endl; FGTaxiNode *taxiNode = findNode(node);
SGGeod other(SGGeod:: // Determine whether it's save to continue or not.
fromDegM(i->getLongitude(), i->getLatitude(), // If we have a crossing route, there are two possibilities:
i->getAltitude())); // 1) This is an interestion
bool needsToWait; // 2) This is oncoming two-way traffic, using the same taxiway.
bool opposing; //cerr << "Hold check 1 : " << id << " has common node " << node << endl;
if (current->isOpposing(this, *i, node)) {
needsToWait = true; SGGeod other(SGGeod::
opposing = true; fromDegM(i->getLongitude(), i->getLatitude(),
//cerr << "Hold check 2 : " << node << " has opposing segment " << endl; i->getAltitude()));
// issue a "Hold Position" as soon as we're close to the offending node bool needsToWait;
// For now, I'm doing this as long as the other aircraft doesn't bool opposing;
// have a hold instruction as soon as we're within a reasonable if (current->isOpposing(this, *i, node)) {
// distance from the offending node.
// This may be a bit of a conservative estimate though, as it may
// be well possible that both aircraft can both continue to taxi
// without crashing into each other.
} else {
opposing = false;
if (SGGeodesy::distanceM(other, taxiNode->getGeod()) > 200) // 2.0*i->getRadius())
{
needsToWait = false;
//cerr << "Hold check 3 : " << id <<" Other aircraft approaching node is still far away. (" << dist << " nm). Can safely continue "
// << endl;
} else {
needsToWait = true; needsToWait = true;
//cerr << "Hold check 4: " << id << " Would need to wait for other aircraft : distance = " << dist << " meters" << endl; opposing = true;
} //cerr << "Hold check 2 : " << node << " has opposing segment " << endl;
} // issue a "Hold Position" as soon as we're close to the offending node
// For now, I'm doing this as long as the other aircraft doesn't
double dist = // have a hold instruction as soon as we're within a reasonable
SGGeodesy::distanceM(curr, taxiNode->getGeod()); // distance from the offending node.
if (!(i->hasHoldPosition())) { // This may be a bit of a conservative estimate though, as it may
// be well possible that both aircraft can both continue to taxi
if ((dist < 200) && //2.5*current->getRadius()) && // without crashing into each other.
(needsToWait) && (i->onRoute(this, *current)) &&
//((i->onRoute(this, *current)) || ((!(i->getSpeedAdjustment())))) &&
(!(current->getId() == i->getWaitsForId())))
//(!(i->getSpeedAdjustment()))) // &&
//(!(current->getSpeedAdjustment())))
{
if (!(isUserAircraft(i->getAircraft()))) { // test code. Don't wait for the user, let the user wait for you.
current->setHoldPosition(true);
current->setWaitsForId(i->getId());
}
//cerr << "Hold check 5: " << current->getCallSign() <<" Setting Hold Position: distance to node (" << node << ") "
// << dist << " meters. Waiting for " << i->getCallSign();
//if (opposing)
//cerr <<" [opposing] " << endl;
//else
// cerr << "[non-opposing] " << endl;
//if (i->hasSpeefAdjustment())
// {
// cerr << " (which in turn waits for ) " << i->
} else { } else {
//cerr << "Hold check 6: " << id << " No need to hold yet: Distance to node : " << dist << " nm"<< endl; opposing = false;
if (SGGeodesy::distanceM(other, taxiNode->getGeod()) > 200) // 2.0*i->getRadius())
{
needsToWait = false;
//cerr << "Hold check 3 : " << id <<" Other aircraft approaching node is still far away. (" << dist << " nm). Can safely continue "
// << endl;
} else {
needsToWait = true;
//cerr << "Hold check 4: " << id << " Would need to wait for other aircraft : distance = " << dist << " meters" << endl;
}
}
double dist =
SGGeodesy::distanceM(curr, taxiNode->getGeod());
if (!(i->hasHoldPosition())) {
if ((dist < 200) && //2.5*current->getRadius()) &&
(needsToWait) && (i->onRoute(this, *current)) &&
//((i->onRoute(this, *current)) || ((!(i->getSpeedAdjustment())))) &&
(!(current->getId() == i->getWaitsForId())))
//(!(i->getSpeedAdjustment()))) // &&
//(!(current->getSpeedAdjustment())))
{
if (!(isUserAircraft(i->getAircraft()))) { // test code. Don't wait for the user, let the user wait for you.
current->setHoldPosition(true);
current->setWaitsForId(i->getId());
}
//cerr << "Hold check 5: " << current->getCallSign() <<" Setting Hold Position: distance to node (" << node << ") "
// << dist << " meters. Waiting for " << i->getCallSign();
//if (opposing)
//cerr <<" [opposing] " << endl;
//else
// cerr << "[non-opposing] " << endl;
//if (i->hasSpeefAdjustment())
// {
// cerr << " (which in turn waits for ) " << i->
} else {
//cerr << "Hold check 6: " << id << " No need to hold yet: Distance to node : " << dist << " nm"<< endl;
}
} }
} }
} }
} } */
}
bool currStatus = current->hasHoldPosition(); bool currStatus = current->hasHoldPosition();
current->setHoldPosition(origStatus); current->setHoldPosition(origStatus);
// Either a Hold Position or a resume taxi transmission has been issued // Either a Hold Position or a resume taxi transmission has been issued
@ -1064,17 +1096,17 @@ void FGGroundNetwork::checkHoldPosition(int id, double lat,
//int state = current->getState(); //int state = current->getState();
if (checkTransmissionState(1,1, current, now, MSG_ACKNOWLEDGE_HOLD_POSITION, ATC_AIR_TO_GROUND)) { if (checkTransmissionState(1,1, current, now, MSG_ACKNOWLEDGE_HOLD_POSITION, ATC_AIR_TO_GROUND)) {
current->setState(0); current->setState(0);
current->setHoldPosition(true); current->setHoldPosition(true);
} }
if (checkTransmissionState(2,2, current, now, MSG_ACKNOWLEDGE_RESUME_TAXI, ATC_AIR_TO_GROUND)) { if (checkTransmissionState(2,2, current, now, MSG_ACKNOWLEDGE_RESUME_TAXI, ATC_AIR_TO_GROUND)) {
current->setState(0); current->setState(0);
current->setHoldPosition(false); current->setHoldPosition(false);
} }
if (current->getAircraft()->getTakeOffStatus() && (current->getState() == 0)) { if (current->getAircraft()->getTakeOffStatus() && (current->getState() == 0)) {
//cerr << "Scheduling " << current->getAircraft()->getCallSign() << " for hold short" << endl; //cerr << "Scheduling " << current->getAircraft()->getCallSign() << " for hold short" << endl;
current->setState(6); current->setState(6);
} }
if (checkTransmissionState(6,6, current, now, MSG_REPORT_RUNWAY_HOLD_SHORT, ATC_AIR_TO_GROUND)) { if (checkTransmissionState(6,6, current, now, MSG_REPORT_RUNWAY_HOLD_SHORT, ATC_AIR_TO_GROUND)) {
} }
if (checkTransmissionState(7,7, current, now, MSG_ACKNOWLEDGE_REPORT_RUNWAY_HOLD_SHORT, ATC_GROUND_TO_AIR)) { if (checkTransmissionState(7,7, current, now, MSG_ACKNOWLEDGE_REPORT_RUNWAY_HOLD_SHORT, ATC_GROUND_TO_AIR)) {
@ -1086,15 +1118,15 @@ void FGGroundNetwork::checkHoldPosition(int id, double lat,
//current->setState(0); //current->setState(0);
} }
/** /**
* Check whether situations occur where the current aircraft is waiting for itself * Check whether situations occur where the current aircraft is waiting for itself
* due to higher order interactions. * due to higher order interactions.
* A 'circular' wait is a situation where a waits for b, b waits for c, and c waits * A 'circular' wait is a situation where a waits for b, b waits for c, and c waits
* for a. Ideally each aircraft only waits for one other aircraft, so by tracing * for a. Ideally each aircraft only waits for one other aircraft, so by tracing
* through this list of waiting aircraft, we can check if we'd eventually end back * through this list of waiting aircraft, we can check if we'd eventually end back
* at the current aircraft. * at the current aircraft.
* *
* Note that we should consider the situation where we are actually checking aircraft * Note that we should consider the situation where we are actually checking aircraft
@ -1140,7 +1172,7 @@ bool FGGroundNetwork::checkForCircularWaits(int id)
//printed = true; //printed = true;
TrafficVectorIterator i = activeTraffic.begin(); TrafficVectorIterator i = activeTraffic.begin();
if (trafficSize) { if (trafficSize) {
//while ((i->getId() != id) && i != activeTraffic.end()) //while ((i->getId() != id) && i != activeTraffic.end())
while (i != activeTraffic.end()) { while (i != activeTraffic.end()) {
if (i->getId() == target) { if (i->getId() == target) {
break; break;
@ -1161,7 +1193,7 @@ bool FGGroundNetwork::checkForCircularWaits(int id)
// actually this trap isn't as impossible as it first seemed: // actually this trap isn't as impossible as it first seemed:
// the setWaitsForID(id) is set to current when the aircraft // the setWaitsForID(id) is set to current when the aircraft
// is waiting for the user controlled aircraft. // is waiting for the user controlled aircraft.
//if (current->getId() == other->getId()) { //if (current->getId() == other->getId()) {
// cerr << "Caught the impossible trap" << endl; // cerr << "Caught the impossible trap" << endl;
// cerr << "Current = " << current->getId() << endl; // cerr << "Current = " << current->getId() << endl;
@ -1175,7 +1207,7 @@ bool FGGroundNetwork::checkForCircularWaits(int id)
if (current->getId() == other->getId()) if (current->getId() == other->getId())
return false; return false;
//} //}
//cerr << current->getCallSign() << " (" << current->getId() << ") " << " -> " << other->getCallSign() //cerr << current->getCallSign() << " (" << current->getId() << ") " << " -> " << other->getCallSign()
// << " (" << other->getId() << "); " << endl;; // << " (" << other->getId() << "); " << endl;;
//current = other; //current = other;
} }
@ -1271,10 +1303,10 @@ void FGGroundNetwork::render(bool visible)
//while (group->getNumChildren()) { //while (group->getNumChildren()) {
// cerr << "Number of children: " << group->getNumChildren() << endl; // cerr << "Number of children: " << group->getNumChildren() << endl;
//simgear::EffectGeode* geode = (simgear::EffectGeode*) group->getChild(0); //simgear::EffectGeode* geode = (simgear::EffectGeode*) group->getChild(0);
//osg::MatrixTransform *obj_trans = (osg::MatrixTransform*) group->getChild(0); //osg::MatrixTransform *obj_trans = (osg::MatrixTransform*) group->getChild(0);
//geode->releaseGLObjects(); //geode->releaseGLObjects();
//group->removeChild(geode); //group->removeChild(geode);
//delete geode; //delete geode;
group = 0; group = 0;
} }
if (visible) { if (visible) {
@ -1288,7 +1320,7 @@ void FGGroundNetwork::render(bool visible)
// Handle start point // Handle start point
int pos = i->getCurrentPosition() - 1; int pos = i->getCurrentPosition() - 1;
if (pos >= 0) { if (pos >= 0) {
SGGeod start(SGGeod::fromDeg((i->getLongitude()), (i->getLatitude()))); SGGeod start(SGGeod::fromDeg((i->getLongitude()), (i->getLatitude())));
SGGeod end (SGGeod::fromDeg(segments[pos]->getEnd()->getLongitude(), segments[pos]->getEnd()->getLatitude())); SGGeod end (SGGeod::fromDeg(segments[pos]->getEnd()->getLongitude(), segments[pos]->getEnd()->getLatitude()));
@ -1301,7 +1333,7 @@ void FGGroundNetwork::render(bool visible)
SGGeod center; SGGeod center;
SGGeodesy::direct(start, heading, coveredDistance, center, az2); SGGeodesy::direct(start, heading, coveredDistance, center, az2);
//cerr << "Active Aircraft : Centerpoint = (" << center.getLatitudeDeg() << ", " << center.getLongitudeDeg() << "). Heading = " << heading << endl; //cerr << "Active Aircraft : Centerpoint = (" << center.getLatitudeDeg() << ", " << center.getLongitudeDeg() << "). Heading = " << heading << endl;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Make a helper function out of this // Make a helper function out of this
osg::Matrix obj_pos; osg::Matrix obj_pos;
osg::MatrixTransform *obj_trans = new osg::MatrixTransform; osg::MatrixTransform *obj_trans = new osg::MatrixTransform;
@ -1311,7 +1343,7 @@ void FGGroundNetwork::render(bool visible)
if (isUserAircraft((i)->getAircraft())) { if (isUserAircraft((i)->getAircraft())) {
elevationStart = fgGetDouble("/position/ground-elev-m"); elevationStart = fgGetDouble("/position/ground-elev-m");
} else { } else {
elevationStart = ((i)->getAircraft()->_getAltitude()); elevationStart = ((i)->getAircraft()->_getAltitude());
} }
double elevationEnd = segments[pos]->getEnd()->getElevation(); double elevationEnd = segments[pos]->getEnd()->getElevation();
//cerr << "Using elevation " << elevationEnd << endl; //cerr << "Using elevation " << elevationEnd << endl;
@ -1321,19 +1353,19 @@ void FGGroundNetwork::render(bool visible)
center2.setElevationM(SG_MAX_ELEVATION_M); center2.setElevationM(SG_MAX_ELEVATION_M);
if (local_scenery->get_elevation_m( center2, elevationEnd, NULL )) { if (local_scenery->get_elevation_m( center2, elevationEnd, NULL )) {
elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5; elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5;
//elevation_meters += 0.5; //elevation_meters += 0.5;
} }
else { else {
elevationEnd = parent->getElevation(); elevationEnd = parent->getElevation();
} }
segments[pos]->getEnd()->setElevation(elevationEnd); segments[pos]->getEnd()->setElevation(elevationEnd);
} }
double elevationMean = (elevationStart + elevationEnd) / 2.0; double elevationMean = (elevationStart + elevationEnd) / 2.0;
double elevDiff = elevationEnd - elevationStart; double elevDiff = elevationEnd - elevationStart;
double slope = atan2(elevDiff, length) * SGD_RADIANS_TO_DEGREES; double slope = atan2(elevDiff, length) * SGD_RADIANS_TO_DEGREES;
//cerr << "1. Using mean elevation : " << elevationMean << " and " << slope << endl; //cerr << "1. Using mean elevation : " << elevationMean << " and " << slope << endl;
WorldCoordinate( obj_pos, center.getLatitudeDeg(), center.getLongitudeDeg(), elevationMean+ 0.5, -(heading), slope ); WorldCoordinate( obj_pos, center.getLatitudeDeg(), center.getLongitudeDeg(), elevationMean+ 0.5, -(heading), slope );
@ -1350,18 +1382,23 @@ void FGGroundNetwork::render(bool visible)
geode->setName("test"); geode->setName("test");
geode->addDrawable(geometry); geode->addDrawable(geometry);
//osg::Node *custom_obj; //osg::Node *custom_obj;
SGMaterial *mat = matlib->find("UnidirectionalTaper"); SGMaterial *mat;
if (segments[pos]->hasBlock()) {
mat = matlib->find("UnidirectionalTaperRed");
} else {
mat = matlib->find("UnidirectionalTaperGreen");
}
if (mat) if (mat)
geode->setEffect(mat->get_effect()); geode->setEffect(mat->get_effect());
obj_trans->addChild(geode); obj_trans->addChild(geode);
// wire as much of the scene graph together as we can // wire as much of the scene graph together as we can
//->addChild( obj_trans ); //->addChild( obj_trans );
group->addChild( obj_trans ); group->addChild( obj_trans );
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
} else { } else {
//cerr << "BIG FAT WARNING: current position is here : " << pos << endl; //cerr << "BIG FAT WARNING: current position is here : " << pos << endl;
} }
for(intVecIterator j = (i)->getIntentions().begin(); j != (i)->getIntentions().end(); j++) { for (intVecIterator j = (i)->getIntentions().begin(); j != (i)->getIntentions().end(); j++) {
osg::Matrix obj_pos; osg::Matrix obj_pos;
int k = (*j)-1; int k = (*j)-1;
if (k >= 0) { if (k >= 0) {
@ -1378,7 +1415,7 @@ void FGGroundNetwork::render(bool visible)
elevation_feet = elevationStart * SG_METER_TO_FEET + 0.5; elevation_feet = elevationStart * SG_METER_TO_FEET + 0.5;
//elevation_meters += 0.5; //elevation_meters += 0.5;
} }
else { else {
elevationStart = parent->getElevation(); elevationStart = parent->getElevation();
} }
segments[k]->getStart()->setElevation(elevationStart); segments[k]->getStart()->setElevation(elevationStart);
@ -1390,7 +1427,7 @@ void FGGroundNetwork::render(bool visible)
elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5; elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5;
//elevation_meters += 0.5; //elevation_meters += 0.5;
} }
else { else {
elevationEnd = parent->getElevation(); elevationEnd = parent->getElevation();
} }
segments[k]->getEnd()->setElevation(elevationEnd); segments[k]->getEnd()->setElevation(elevationEnd);
@ -1400,8 +1437,8 @@ void FGGroundNetwork::render(bool visible)
double elevDiff = elevationEnd - elevationStart; double elevDiff = elevationEnd - elevationStart;
double length = segments[k]->getLength(); double length = segments[k]->getLength();
double slope = atan2(elevDiff, length) * SGD_RADIANS_TO_DEGREES; double slope = atan2(elevDiff, length) * SGD_RADIANS_TO_DEGREES;
// cerr << "2. Using mean elevation : " << elevationMean << " and " << slope << endl; // cerr << "2. Using mean elevation : " << elevationMean << " and " << slope << endl;
WorldCoordinate( obj_pos, segments[k]->getLatitude(), segments[k]->getLongitude(), elevationMean+ 0.5, -(segments[k]->getHeading()), slope ); WorldCoordinate( obj_pos, segments[k]->getLatitude(), segments[k]->getLongitude(), elevationMean+ 0.5, -(segments[k]->getHeading()), slope );
@ -1419,7 +1456,12 @@ void FGGroundNetwork::render(bool visible)
geode->setName("test"); geode->setName("test");
geode->addDrawable(geometry); geode->addDrawable(geometry);
//osg::Node *custom_obj; //osg::Node *custom_obj;
SGMaterial *mat = matlib->find("UnidirectionalTaper"); SGMaterial *mat;
if (segments[k]->hasBlock()) {
mat = matlib->find("UnidirectionalTaperRed");
} else {
mat = matlib->find("UnidirectionalTaperGreen");
}
if (mat) if (mat)
geode->setEffect(mat->get_effect()); geode->setEffect(mat->get_effect());
obj_trans->addChild(geode); obj_trans->addChild(geode);
@ -1437,3 +1479,96 @@ void FGGroundNetwork::render(bool visible)
string FGGroundNetwork::getName() { string FGGroundNetwork::getName() {
return string(parent->getId() + "-ground"); return string(parent->getId() + "-ground");
} }
void FGGroundNetwork::update(double dt)
{
for (FGTaxiSegmentVectorIterator tsi = segments.begin(); tsi != segments.end(); tsi++) {
(*tsi)->unblock();
}
int priority = 1;
//sort(activeTraffic.begin(), activeTraffic.end(), compare_trafficrecords);
// Handle traffic that is under ground control first; this way we'll prevent clutter at the gate areas.
// Don't allow an aircraft to pushback when a taxiing aircraft is currently using part of the intended route.
for (TrafficVectorIterator i = parent->getDynamics()->getStartupController()->getActiveTraffic().begin();
i != parent->getDynamics()->getStartupController()->getActiveTraffic().end(); i++) {
i->allowPushBack();
i->setPriority(priority++);
if (i->isActive(60)) {
// Check for all active aircraft whether it's current pos segment is
// an opposite of one of the departing aircraft's intentions
for (TrafficVectorIterator j = activeTraffic.begin(); j != activeTraffic.end(); j++) {
int pos = j->getCurrentPosition();
if (pos > 0) {
FGTaxiSegment *seg = segments[pos-1]->opposite();
if (seg) {
int posReverse = seg->getIndex();
for (intVecIterator k = i->getIntentions().begin(); k != i->getIntentions().end(); k++) {
if ((*k) == posReverse) {
i->denyPushBack();
segments[posReverse-1]->block();
}
}
}
}
}
// if the current aircraft is still allowed to pushback, we can start reserving a route for if by blocking all the entry taxiways.
if (i->pushBackAllowed()) {
int pos = i->getCurrentPosition();
if (pos > 0) {
FGTaxiSegment *seg = segments[pos-1];
FGTaxiNode *node = seg->getEnd();
for (FGTaxiSegmentVectorIterator tsi = segments.begin(); tsi != segments.end(); tsi++) {
if (((*tsi)->getEnd() == node) && ((*tsi) != seg)) {
(*tsi)->block();
}
}
}
for (intVecIterator j = i->getIntentions().begin(); j != i->getIntentions().end(); j++) {
int pos = (*j);
if (pos > 0) {
FGTaxiSegment *seg = segments[pos-1];
FGTaxiNode *node = seg->getEnd();
for (FGTaxiSegmentVectorIterator tsi = segments.begin(); tsi != segments.end(); tsi++) {
if (((*tsi)->getEnd() == node) && ((*tsi) != seg)) {
(*tsi)->block();
}
}
}
}
}
}
}
for (TrafficVectorIterator i = activeTraffic.begin(); i != activeTraffic.end(); i++) {
i->setPriority(priority++);
int pos = i->getCurrentPosition();
if (pos > 0) {
if (segments[pos-1]->hasBlock()) {
SG_LOG(SG_GENERAL, SG_ALERT, "Taxiway incursion for AI aircraft" << i->getAircraft()->getCallSign());
}
}
intVecIterator ivi;
for (ivi = i->getIntentions().begin(); ivi != i->getIntentions().end(); ivi++) {
int segIndex = (*ivi);
if (segIndex > 0) {
if (segments[segIndex-1]->hasBlock())
break;
}
}
//after this, ivi points just behind the last valid unblocked taxi segment.
for (intVecIterator j = i->getIntentions().begin(); j != ivi; j++) {
int pos = (*j);
if (pos > 0) {
FGTaxiSegment *seg = segments[pos-1];
FGTaxiNode *node = seg->getEnd();
for (FGTaxiSegmentVectorIterator tsi = segments.begin(); tsi != segments.end(); tsi++) {
if (((*tsi)->getEnd() == node) && ((*tsi) != seg)) {
(*tsi)->block();
}
}
}
}
}
}

View file

@ -60,98 +60,143 @@ typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
class FGTaxiSegment class FGTaxiSegment
{ {
private: private:
int startNode; int startNode;
int endNode; int endNode;
double length; double length;
double heading; double heading;
SGGeod center; SGGeod center;
bool isActive; bool isActive;
bool isPushBackRoute; bool isPushBackRoute;
FGTaxiNode *start; bool isBlocked;
FGTaxiNode *end; FGTaxiNode *start;
int index; FGTaxiNode *end;
FGTaxiSegment *oppositeDirection; int index;
FGTaxiSegment *oppositeDirection;
public: public:
FGTaxiSegment() : FGTaxiSegment() :
startNode(0), startNode(0),
endNode(0), endNode(0),
length(0), length(0),
heading(0), heading(0),
isActive(0), isActive(0),
isPushBackRoute(0), isPushBackRoute(0),
start(0), isBlocked(0),
end(0), start(0),
index(0), end(0),
oppositeDirection(0) index(0),
{ oppositeDirection(0)
}; {
};
FGTaxiSegment (const FGTaxiSegment &other) : FGTaxiSegment (const FGTaxiSegment &other) :
startNode (other.startNode), startNode (other.startNode),
endNode (other.endNode), endNode (other.endNode),
length (other.length), length (other.length),
heading (other.heading), heading (other.heading),
center (other.center), center (other.center),
isActive (other.isActive), isActive (other.isActive),
isPushBackRoute (other.isPushBackRoute), isPushBackRoute (other.isPushBackRoute),
start (other.start), isBlocked (other.isBlocked),
end (other.end), start (other.start),
index (other.index), end (other.end),
oppositeDirection (other.oppositeDirection) index (other.index),
{ oppositeDirection (other.oppositeDirection)
}; {
};
FGTaxiSegment& operator=(const FGTaxiSegment &other) FGTaxiSegment& operator=(const FGTaxiSegment &other)
{ {
startNode = other.startNode; startNode = other.startNode;
endNode = other.endNode; endNode = other.endNode;
length = other.length; length = other.length;
heading = other.heading; heading = other.heading;
center = other.center; center = other.center;
isActive = other.isActive; isActive = other.isActive;
isPushBackRoute = other.isPushBackRoute; isPushBackRoute = other.isPushBackRoute;
start = other.start; isBlocked = other.isBlocked;
end = other.end; start = other.start;
index = other.index; end = other.end;
oppositeDirection = other.oppositeDirection; index = other.index;
return *this; oppositeDirection = other.oppositeDirection;
}; return *this;
};
void setIndex (int val) { index = val; }; void setIndex (int val) {
void setStartNodeRef (int val) { startNode = val; }; index = val;
void setEndNodeRef (int val) { endNode = val; }; };
void setStartNodeRef (int val) {
startNode = val;
};
void setEndNodeRef (int val) {
endNode = val;
};
void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; }; void setOpposite(FGTaxiSegment *opp) {
oppositeDirection = opp;
};
void setStart(FGTaxiNodeVector *nodes); void setStart(FGTaxiNodeVector *nodes);
void setEnd (FGTaxiNodeVector *nodes); void setEnd (FGTaxiNodeVector *nodes);
void setPushBackType(bool val) { isPushBackRoute = val; }; void setPushBackType(bool val) {
void setDimensions(double elevation); isPushBackRoute = val;
};
void setDimensions(double elevation);
void block() {
isBlocked = true;
}
void unblock() {
isBlocked = false;
};
bool hasBlock() {
return isBlocked;
};
FGTaxiNode * getEnd() { return end;}; FGTaxiNode * getEnd() {
FGTaxiNode * getStart() { return start; }; return end;
double getLength() { return length; }; };
int getIndex() { return index; }; FGTaxiNode * getStart() {
double getLatitude() { return center.getLatitudeDeg(); }; return start;
double getLongitude() { return center.getLongitudeDeg(); }; };
double getHeading() { return heading; }; double getLength() {
bool isPushBack() { return isPushBackRoute; }; return length;
};
int getIndex() {
return index;
};
double getLatitude() {
return center.getLatitudeDeg();
};
double getLongitude() {
return center.getLongitudeDeg();
};
double getHeading() {
return heading;
};
bool isPushBack() {
return isPushBackRoute;
};
int getPenalty(int nGates); int getPenalty(int nGates);
FGTaxiSegment *getAddress() { return this;}; FGTaxiSegment *getAddress() {
return this;
};
bool operator<(const FGTaxiSegment &other) const {
return index < other.index;
};
//bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
FGTaxiSegment *opposite() {
return oppositeDirection;
};
void setCourseDiff(double crse);
bool operator<(const FGTaxiSegment &other) const { return index < other.index; };
//bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
FGTaxiSegment *opposite() { return oppositeDirection; };
void setCourseDiff(double crse);
}; };
@ -168,52 +213,67 @@ typedef vector<int>::iterator intVecIterator;
class FGTaxiRoute class FGTaxiRoute
{ {
private: private:
intVec nodes; intVec nodes;
intVec routes; intVec routes;
double distance; double distance;
// int depth; // int depth;
intVecIterator currNode; intVecIterator currNode;
intVecIterator currRoute; intVecIterator currRoute;
public: public:
FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();}; FGTaxiRoute() {
FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) { distance = 0;
nodes = nds; currNode = nodes.begin();
routes = rts; currRoute = routes.begin();
distance = dist; };
currNode = nodes.begin(); FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
currRoute = routes.begin(); nodes = nds;
routes = rts;
distance = dist;
currNode = nodes.begin();
currRoute = routes.begin();
// depth = dpth; // depth = dpth;
}; };
FGTaxiRoute& operator= (const FGTaxiRoute &other) { FGTaxiRoute& operator= (const FGTaxiRoute &other) {
nodes = other.nodes; nodes = other.nodes;
routes = other.routes; routes = other.routes;
distance = other.distance; distance = other.distance;
// depth = other.depth; // depth = other.depth;
currNode = nodes.begin(); currNode = nodes.begin();
currRoute = routes.begin(); currRoute = routes.begin();
return *this; return *this;
}; };
FGTaxiRoute(const FGTaxiRoute& copy) : FGTaxiRoute(const FGTaxiRoute& copy) :
nodes(copy.nodes), nodes(copy.nodes),
routes(copy.routes), routes(copy.routes),
distance(copy.distance), distance(copy.distance),
// depth(copy.depth), // depth(copy.depth),
currNode(nodes.begin()), currNode(nodes.begin()),
currRoute(routes.begin()) currRoute(routes.begin())
{}; {};
bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; }; bool operator< (const FGTaxiRoute &other) const {
bool empty () { return nodes.begin() == nodes.end(); }; return distance < other.distance;
bool next(int *nde); };
bool next(int *nde, int *rte); bool empty () {
void rewind(int legNr); return nodes.begin() == nodes.end();
};
void first() { currNode = nodes.begin(); currRoute = routes.begin(); }; bool next(int *nde);
int size() { return nodes.size(); }; bool next(int *nde, int *rte);
int nodesLeft() { return nodes.end() - currNode; }; void rewind(int legNr);
void first() {
currNode = nodes.begin();
currRoute = routes.begin();
};
int size() {
return nodes.size();
};
int nodesLeft() {
return nodes.end() - currNode;
};
// int getDepth() { return depth; }; // int getDepth() { return depth; };
}; };
@ -227,75 +287,84 @@ typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
class FGGroundNetwork : public FGATCController class FGGroundNetwork : public FGATCController
{ {
private: private:
bool hasNetwork; bool hasNetwork;
bool networkInitialized; bool networkInitialized;
time_t nextSave; time_t nextSave;
//int maxDepth; //int maxDepth;
int count; int count;
FGTaxiNodeVector nodes; FGTaxiNodeVector nodes;
FGTaxiNodeVector pushBackNodes; FGTaxiNodeVector pushBackNodes;
FGTaxiSegmentVector segments; FGTaxiSegmentVector segments;
//intVec route; //intVec route;
//intVec nodesStack; //intVec nodesStack;
//intVec routesStack; //intVec routesStack;
TaxiRouteVector routes; TaxiRouteVector routes;
TrafficVector activeTraffic; TrafficVector activeTraffic;
TrafficVectorIterator currTraffic; TrafficVectorIterator currTraffic;
bool foundRoute; bool foundRoute;
double totalDistance, maxDistance; double totalDistance, maxDistance;
FGTowerController *towerController; FGTowerController *towerController;
FGAirport *parent; FGAirport *parent;
//void printRoutingError(string); //void printRoutingError(string);
void checkSpeedAdjustment(int id, double lat, double lon, void checkSpeedAdjustment(int id, double lat, double lon,
double heading, double speed, double alt); double heading, double speed, double alt);
void checkHoldPosition(int id, double lat, double lon, void checkHoldPosition(int id, double lat, double lon,
double heading, double speed, double alt); double heading, double speed, double alt);
public: public:
FGGroundNetwork(); FGGroundNetwork();
~FGGroundNetwork(); ~FGGroundNetwork();
void addNode (const FGTaxiNode& node); void addNode (const FGTaxiNode& node);
void addNodes (FGParkingVec *parkings); void addNodes (FGParkingVec *parkings);
void addSegment(const FGTaxiSegment& seg); void addSegment(const FGTaxiSegment& seg);
void init(); void init();
bool exists() { return hasNetwork; }; bool exists() {
void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; }; return hasNetwork;
};
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);
//void trace(FGTaxiNode *, int, int, double dist); //void trace(FGTaxiNode *, int, int, double dist);
int getNrOfNodes() { return nodes.size(); }; int getNrOfNodes() {
return nodes.size();
};
void setParent(FGAirport *par) { parent = par; }; void setParent(FGAirport *par) {
parent = par;
};
virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
double lat, double lon, double hdg, double spd, double alt, double lat, double lon, double hdg, double spd, double alt,
double radius, int leg, FGAIAircraft *aircraft); double radius, int leg, FGAIAircraft *aircraft);
virtual void signOff(int id); virtual void signOff(int id);
virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt); virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
virtual bool hasInstruction(int id); virtual bool hasInstruction(int id);
virtual FGATCInstruction getInstruction(int id); virtual FGATCInstruction getInstruction(int id);
bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId, bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
AtcMsgDir msgDir); AtcMsgDir msgDir);
bool checkForCircularWaits(int id); bool checkForCircularWaits(int id);
virtual void render(bool); virtual void render(bool);
virtual string getName(); virtual string getName();
virtual void update(double dt);
void saveElevationCache(); void saveElevationCache();
}; };

View file

@ -380,7 +380,7 @@ void FGAISchedule::scheduleFlights(time_t now)
FGScheduledFlight *flight = NULL; FGScheduledFlight *flight = NULL;
do { do {
if (currentDestination.empty()) { if (currentDestination.empty()) {
flight = findAvailableFlight(userPort, flightIdentifier, now, (now+6400)); //flight = findAvailableFlight(userPort, flightIdentifier, now, (now+1800));
if (!flight) if (!flight)
flight = findAvailableFlight(currentDestination, flightIdentifier); flight = findAvailableFlight(currentDestination, flightIdentifier);
} else { } else {
@ -423,7 +423,7 @@ void FGAISchedule::scheduleFlights(time_t now)
<< " " << arrT << ":"); << " " << arrT << ":");
flights.push_back(flight); flights.push_back(flight);
} while (currentDestination != startingPort); } while (1); //(currentDestination != startingPort);
SG_LOG(SG_GENERAL, SG_BULK, " Done "); SG_LOG(SG_GENERAL, SG_BULK, " Done ");
} }