From: durk Date: Sat, 30 Jan 2010 15:40:33 +0000 (+0000) Subject: A couple of last-minute patched / bugfixes to mitigate the probability of collisions... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e54798a8e2392b9eefa689fb9a003a0d6b98981f;p=flightgear.git A couple of last-minute patched / bugfixes to mitigate the probability of collisions between user controlled aircraft and AI traffic. * AI aircraft distance to user proximity detection works again (lat/lon were inverted). * The parking uses by the user aircraft is marked as such to prevent it being reused by an AI aicraft * AI aircraft won't receive permission for pushback until the user aircraft is at a fair distance. --- diff --git a/src/ATC/trafficcontrol.cxx b/src/ATC/trafficcontrol.cxx index 57f718812..af0f729e7 100644 --- a/src/ATC/trafficcontrol.cxx +++ b/src/ATC/trafficcontrol.cxx @@ -44,7 +44,8 @@ FGTrafficRecord::FGTrafficRecord() : heading(0), speed(0), altitude(0), - radius(0) { + radius(0), + allowTransmission(true) { } void FGTrafficRecord::setPositionAndIntentions(int pos, FGAIFlightPlan *route) @@ -303,6 +304,21 @@ void FGTrafficRecord::setHeadingAdjustment(double heading) instruction.setHeading(heading); } +bool FGTrafficRecord::pushBackAllowed() { + 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); + +} + /*************************************************************************** @@ -441,8 +457,18 @@ void FGATCController::transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir m activeRunway + ", " + SID + ", squawk " + transponderCode + ". " + "For push-back and taxi clearance call " + taxiFreqStr + ". " + sender; break; - default: + case MSG_REQUEST_PUSHBACK_CLEARANCE: + text = receiver + ". Request push-back. " + sender; break; + case MSG_PERMIT_PUSHBACK_CLEARANCE: + text = receiver + ". Push-back approved. " + sender; + break; + case MSG_HOLD_PUSHBACK_CLEARANCE: + text = receiver + ". Standby. " + sender; + break; + default: + text = sender + ". Transmitting unknown Message"; + break; } double onBoardRadioFreq0 = fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz"); double onBoardRadioFreq1 = fgGetDouble("/instrumentation/comm[1]/frequencies/selected-mhz"); @@ -455,8 +481,9 @@ void FGATCController::transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir m // Note that distance attenuation is currently not yet implemented //cerr << "Transmitting " << text << " at " << stationFreq; if ((onBoardRadioFreqI0 == stationFreq) || (onBoardRadioFreqI1 == stationFreq)) { - fgSetString("/sim/messages/atc", text.c_str()); - //cerr << "Printing Message: " << endl; + if (rec->allowTransmissions()) { + fgSetString("/sim/messages/atc", text.c_str()); + } } } @@ -857,6 +884,28 @@ void FGStartupController::update(int id, double lat, double lon, double heading, // TODO: Switch to APRON control and request pushback Clearance. // Get Push back clearance if ((state == 4) && available){ + if (now > startTime+130) { + transmit(&(*i), MSG_REQUEST_PUSHBACK_CLEARANCE, ATC_AIR_TO_GROUND); + i->updateState(); + lastTransmission = now; + available = false; + } + } + if ((state == 5) && available){ + if (now > startTime+130) { + if (i->pushBackAllowed()) { + i->allowRepeatedTransmissions(); + transmit(&(*i), MSG_PERMIT_PUSHBACK_CLEARANCE, ATC_GROUND_TO_AIR); + i->updateState(); + } else { + transmit(&(*i), MSG_HOLD_PUSHBACK_CLEARANCE, ATC_GROUND_TO_AIR); + i->suppressRepeatedTransmissions(); + } + lastTransmission = now; + available = false; + } + } + if ((state == 6) && available){ i->setHoldPosition(false); } } diff --git a/src/ATC/trafficcontrol.hxx b/src/ATC/trafficcontrol.hxx index 7ca8e88bf..93217cc12 100644 --- a/src/ATC/trafficcontrol.hxx +++ b/src/ATC/trafficcontrol.hxx @@ -109,6 +109,7 @@ private: int currentPos; int leg; int state; + bool allowTransmission; time_t timer; intVec intentions; FGATCInstruction instruction; @@ -165,12 +166,17 @@ public: string getRunway() { return runway; }; //void setCallSign(string clsgn) { callsign = clsgn; }; void setAircraft(FGAIAircraft *ref) { aircraft = ref;}; - void updateState() { state++;}; + 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 suppressRepeatedTransmissions () { allowTransmission=false; }; + void allowRepeatedTransmissions () { allowTransmission=true; }; }; typedef vector TrafficVector; @@ -215,7 +221,10 @@ public: MSG_REQUEST_ENGINE_START, MSG_PERMIT_ENGINE_START, MSG_DENY_ENGINE_START, - MSG_ACKNOWLEDGE_ENGINE_START } AtcMsgId; + MSG_ACKNOWLEDGE_ENGINE_START, + MSG_REQUEST_PUSHBACK_CLEARANCE, + MSG_PERMIT_PUSHBACK_CLEARANCE, + MSG_HOLD_PUSHBACK_CLEARANCE } AtcMsgId; typedef enum { ATC_AIR_TO_GROUND, ATC_GROUND_TO_AIR } AtcMsgDir; diff --git a/src/Airports/groundnetwork.cxx b/src/Airports/groundnetwork.cxx index 8bdd947fc..054741ac4 100644 --- a/src/Airports/groundnetwork.cxx +++ b/src/Airports/groundnetwork.cxx @@ -554,7 +554,7 @@ void FGGroundNetwork::update(int id, double lat, double lon, double heading, dou instruction. See below for the hold position instruction. Note that there currently still is one flaw in the logic that needs to be addressed. - 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 aircraft is still close enough to block the current aircraft. This situation is currently not addressed yet, but should be. @@ -625,7 +625,8 @@ void FGGroundNetwork::checkSpeedAdjustment(int id, double lat, { //cerr << "Comparing " << current->getId() << " and " << i->getId() << endl; SGGeod other(SGGeod::fromDegM(i->getLongitude(), - i->getLatitude(), i->getAltitude())); + i->getLatitude(), + i->getAltitude())); SGGeodesy::inverse(curr, other, course, az2, dist); bearing = fabs(heading-course); if (bearing > 180) @@ -642,12 +643,12 @@ void FGGroundNetwork::checkSpeedAdjustment(int id, double lat, // Finally, check UserPosition double userLatitude = fgGetDouble("/position/latitude-deg"); double userLongitude = fgGetDouble("/position/longitude-deg"); - SGGeod user(SGGeod::fromDeg(userLatitude,userLongitude)); - SGGeodesy::inverse(user, curr, course, az2, dist); - + SGGeod user(SGGeod::fromDeg(userLongitude,userLatitude)); + SGGeodesy::inverse(curr, user, course, az2, dist); + bearing = fabs(heading-course); if (bearing > 180) - bearing = 360-bearing; + bearing = 360-bearing; if ((dist < mindist) && (bearing < 60.0)) { mindist = dist; @@ -655,13 +656,7 @@ void FGGroundNetwork::checkSpeedAdjustment(int id, double lat, minbearing = bearing; otherReasonToSlowDown = true; } - - // if (closest == current) { - // //SG_LOG(SG_GENERAL, SG_ALERT, "AI error: closest and current match"); - // //return; - // } - //cerr << "Distance : " << dist << " bearing : " << bearing << " heading : " << heading - // << " course : " << course << endl; + current->clearSpeedAdjustment(); if (current->checkPositionAndIntentions(*closest) || otherReasonToSlowDown) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 99a2ea6a6..27a0311c3 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -802,6 +802,7 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par return false; } FGParking* parking = dcs->getParking(park_index); + parking->setAvailable(false); fgApplyStartOffset( SGGeod::fromDeg(parking->getLongitude(), parking->getLatitude()), parking->getHeading());