}
} else {
if ((((*j) - (*i)) > (separation * 2))) { // found a potential slot
- // now check whether this slow is usable:
+ // now check whether this slot is usable:
// 1) eta should fall between the two points
// i.e. eta > i AND eta < j
//
}
//exit(1);
}
+/**
+ * Check if another aircraft is ahead of the current one, and on the same
+ * return true / false is the is/isn't the case.
+ *
+ ****************************************************************************/
bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord & other)
{
string sender, receiver;
int stationFreq = 0;
int taxiFreq = 0;
+ int towerFreq = 0;
int freqId = 0;
string atisInformation;
string text;
string taxiFreqStr;
+ string towerFreqStr;
double heading = 0;
string activeRunway;
string fltType;
string transponderCode;
FGAIFlightPlan *fp;
string fltRules;
+ string instructionText;
//double commFreqD;
sender = rec->getAircraft()->getTrafficRef()->getCallSign();
+ if (rec->getAircraft()->getTaxiClearanceRequest()) {
+ instructionText = "push-back and taxi";
+ } else {
+ instructionText = "taxi";
+ }
//cerr << "transmitting for: " << sender << "Leg = " << rec->getLeg() << endl;
switch (rec->getLeg()) {
+ case 1:
case 2:
- case 3:
freqId = rec->getNextFrequency();
stationFreq =
rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
getDynamics()->getGroundFrequency(rec->getLeg() + freqId);
taxiFreq =
rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
- getDynamics()->getGroundFrequency(3);
+ getDynamics()->getGroundFrequency(2);
+ towerFreq =
+ rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
+ getDynamics()->getTowerFrequency(2);
receiver =
rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
getName() + "-Ground";
rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
getDynamics()->getAtisSequence();
break;
- case 4:
+ case 3:
receiver =
rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
getName() + "-Tower";
receiver + ". Start-up approved. " + atisInformation +
" correct, runway " + activeRunway + ", " + SID + ", squawk " +
transponderCode + ". " +
- "For push-back and taxi clearance call " + taxiFreqStr + ". " +
+ "For "+ instructionText + " clearance call " + taxiFreqStr + ". " +
sender + " control.";
break;
case MSG_DENY_ENGINE_START:
taxiFreqStr = formatATCFrequency3_2(taxiFreq);
activeRunway = rec->getAircraft()->GetFlightPlan()->getRunway();
transponderCode = rec->getAircraft()->GetTransponderCode();
+
text =
receiver + ". Start-up approved. " + atisInformation +
" correct, runway " + activeRunway + ", " + SID + ", squawk " +
transponderCode + ". " +
- "For push-back and taxi clearance call " + taxiFreqStr + ". " +
+ "For " + instructionText + " clearance call " + taxiFreqStr + ". " +
sender;
break;
case MSG_ACKNOWLEDGE_SWITCH_GROUND_FREQUENCY:
text = receiver + ". Roger. " + sender;
break;
case MSG_REQUEST_PUSHBACK_CLEARANCE:
- text = receiver + ". Request push-back. " + sender;
+ if (rec->getAircraft()->getTaxiClearanceRequest()) {
+ text = receiver + ". Request push-back. " + sender;
+ } else {
+ text = receiver + ". Request Taxi clearance. " + sender;
+ }
break;
case MSG_PERMIT_PUSHBACK_CLEARANCE:
- text = receiver + ". Push-back approved. " + sender;
+ if (rec->getAircraft()->getTaxiClearanceRequest()) {
+ text = receiver + ". Push-back approved. " + sender;
+ } else {
+ text = receiver + ". Cleared to Taxi." + sender;
+ }
break;
case MSG_HOLD_PUSHBACK_CLEARANCE:
text = receiver + ". Standby. " + sender;
case MSG_ACKNOWLEDGE_RESUME_TAXI:
text = receiver + ". Continuing Taxi. " + sender;
break;
+ case MSG_REPORT_RUNWAY_HOLD_SHORT:
+ activeRunway = rec->getAircraft()->GetFlightPlan()->getRunway();
+ //activeRunway = "test";
+ text = receiver + ". Holding short runway "
+ + activeRunway
+ + ". " + sender;
+ //text = "test1";
+ //cerr << "1 Currently at leg " << rec->getLeg() << endl;
+ break;
+ case MSG_ACKNOWLEDGE_REPORT_RUNWAY_HOLD_SHORT:
+ activeRunway = rec->getAircraft()->GetFlightPlan()->getRunway();
+ text = receiver + "Roger. Holding short runway "
+ // + activeRunway
+ + ". " + sender;
+ //text = "test2";
+ //cerr << "2 Currently at leg " << rec->getLeg() << endl;
+ break;
+ case MSG_SWITCH_TOWER_FREQUENCY:
+ towerFreqStr = formatATCFrequency3_2(towerFreq);
+ text = receiver + "Contact Tower at " + towerFreqStr + ". " + sender;
+ //text = "test3";
+ //cerr << "3 Currently at leg " << rec->getLeg() << endl;
+ break;
+ case MSG_ACKNOWLEDGE_SWITCH_TOWER_FREQUENCY:
+ towerFreqStr = formatATCFrequency3_2(towerFreq);
+ text = receiver + "Roger, switching to tower at " + towerFreqStr + ". " + sender;
+ //text = "test4";
+ //cerr << "4 Currently at leg " << rec->getLeg() << endl;
+ break;
default:
+ //text = "test3";
text = text + sender + ". Transmitting unknown Message";
break;
}
* class FGTowerController
*
**************************************************************************/
-FGTowerController::FGTowerController():
+FGTowerController::FGTowerController(FGAirportDynamics *par) :
FGATCController()
{
+ parent = par;
}
//
rec.setRunway(intendedRoute->getRunway());
rec.setLeg(leg);
//rec.setCallSign(callsign);
+ rec.setRadius(radius);
rec.setAircraft(ref);
activeTraffic.push_back(rec);
+ // Don't just schedule the aircraft for the tower controller, also assign if to the correct active runway.
+ ActiveRunwayVecIterator rwy = activeRunways.begin();
+ if (activeRunways.size()) {
+ while (rwy != activeRunways.end()) {
+ if (rwy->getRunwayName() == intendedRoute->getRunway()) {
+ break;
+ }
+ rwy++;
+ }
+ }
+ if (rwy == activeRunways.end()) {
+ ActiveRunway aRwy(intendedRoute->getRunway(), id);
+ aRwy.addToDepartureCue(ref);
+ activeRunways.push_back(aRwy);
+ rwy = (activeRunways.end()-1);
+ } else {
+ rwy->addToDepartureCue(ref);
+ }
+
+ //cerr << ref->getTrafficRef()->getCallSign() << " You are number " << rwy->getDepartureCueSize() << " for takeoff " << endl;
} else {
i->setPositionAndHeading(lat, lon, heading, speed, alt);
}
}
setDt(getDt() + dt);
-// // 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
+ // already exists here. So, we can simplify the current code.
ActiveRunwayVecIterator rwy = activeRunways.begin();
- // again, a map might be more efficient here
- if (activeRunways.size()) {
- //while ((rwy->getRunwayName() != current->getRunway()) && (rwy != activeRunways.end())) {
- while (rwy != activeRunways.end()) {
- if (rwy->getRunwayName() == current->getRunway()) {
- break;
- }
- rwy++;
+ while (rwy != activeRunways.end()) {
+ if (rwy->getRunwayName() == current->getRunway()) {
+ break;
}
+ rwy++;
}
- if (rwy == activeRunways.end()) {
- ActiveRunway aRwy(current->getRunway(), id);
- activeRunways.push_back(aRwy); // Since there are no clearance records for this runway yet
- current->setHoldPosition(false); // Clear the current aircraft to continue
- } else {
- // Okay, we have a clearance record for this runway, so check
- // whether the clearence ID matches that of the current aircraft
- if (id == rwy->getCleared()) {
- current->setHoldPosition(false);
+
+ // only bother running the following code if the current aircraft is the
+ // first in line for depature
+ /* if (current->getAircraft() == rwy->getFirstAircraftInDepartureCue()) {
+ if (rwy->getCleared()) {
+ if (id == rwy->getCleared()) {
+ current->setHoldPosition(false);
+ } else {
+ current->setHoldPosition(true);
+ }
} else {
- current->setHoldPosition(true);
+ // For now. At later stages, this will probably be the place to check for inbound traffc.
+ rwy->setCleared(id);
+ }
+ } */
+ // only bother with aircraft that have a takeoff status of 2, since those are essentially under tower control
+ if (current->getAircraft()->getTakeOffStatus() == 2) {
+ current->setHoldPosition(true);
+ int clearanceId = rwy->getCleared();
+ if (clearanceId) {
+ if (id == clearanceId) {
+ current->setHoldPosition(false);
+ }
+ } else {
+ if (current->getAircraft() == rwy->getFirstAircraftInDepartureCue()) {
+ rwy->setCleared(id);
+ }
}
}
}
rwy++;
}
if (rwy != activeRunways.end()) {
- rwy = activeRunways.erase(rwy);
+ rwy->setCleared(0);
+ rwy->updateDepartureCue();
} else {
SG_LOG(SG_GENERAL, SG_ALERT,
"AI error: Attempting to erase non-existing runway clearance record in FGTowerController::signoff");
SG_LOG(SG_GENERAL, SG_ALERT,
"AI error: Aircraft without traffic record is signing off from tower");
} else {
+ i->getAircraft()->resetTakeOffStatus();
i = activeTraffic.erase(i);
//cerr << "Signing off from tower controller" << endl;
}
//cerr << "FGTowerController::render function not yet implemented" << endl;
}
+string FGTowerController::getName() {
+ return string(parent->getId() + "-tower");
+}
+
+
/***************************************************************************
* class FGStartupController
// Note that this function is copied from simgear. for maintanance purposes, it's probabtl better to make a general function out of that.
static void WorldCoordinate(osg::Matrix& obj_pos, double lat,
- double lon, double elev, double hdg)
+ double lon, double elev, double hdg, double slope)
{
SGGeod geod = SGGeod::fromDegM(lon, lat, elev);
obj_pos = geod.makeZUpFrame();
// around the Z axis
obj_pos.preMult(osg::Matrix::rotate(hdg * SGD_DEGREES_TO_RADIANS,
0.0, 0.0, 1.0));
+ obj_pos.preMult(osg::Matrix::rotate(slope * SGD_DEGREES_TO_RADIANS,
+ 0.0, 1.0, 0.0));
}
globals->get_scenery()->get_scene_graph()->removeChild(group);
//while (group->getNumChildren()) {
// 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);
//geode->releaseGLObjects();
//group->removeChild(geode);
}
if (visible) {
group = new osg::Group;
+ FGScenery * local_scenery = globals->get_scenery();
+ double elevation_meters = 0.0;
+ double elevation_feet = 0.0;
+
//for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) {
double dx = 0;
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(), parent->getElevation()+8+dx, -(heading) );
+ WorldCoordinate( obj_pos, center.getLatitudeDeg(), center.getLongitudeDeg(), elevationMean + 0.5, -(heading), slope );
+;
obj_trans->setMatrix( obj_pos );
//osg::Vec3 center(0, 0, 0)
osg::MatrixTransform *obj_trans = new osg::MatrixTransform;
obj_trans->setDataVariance(osg::Object::STATIC);
FGTaxiSegment *segment = parent->getGroundNetwork()->findSegment(k);
- WorldCoordinate( obj_pos, segment->getLatitude(), segment->getLongitude(), parent->getElevation()+8+dx, -(segment->getHeading()) );
+
+ 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, -(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)
}
}
+string FGStartupController::getName() {
+ return string(parent->getId() + "-startup");
+}
+
+
/***************************************************************************
* class FGApproachController
*
**************************************************************************/
-FGApproachController::FGApproachController():
+FGApproachController::FGApproachController(FGAirportDynamics *par):
FGATCController()
{
+ parent = par;
}
//
void FGApproachController::render(bool visible) {
//cerr << "FGApproachController::render function not yet implemented" << endl;
}
+
+
+
+string FGApproachController::getName() {
+ return string(parent->getId() + "-approach");
+}