From: ThorstenB Date: Mon, 17 Jan 2011 22:33:54 +0000 (+0100) Subject: Make AIplanes respond to TCAS RAs. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f6b9c5b90804b4cba64737c86c7665aac1a33e02;p=flightgear.git Make AIplanes respond to TCAS RAs. --- diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index 8d7df9225..d0e319705 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -332,6 +332,7 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) { use_perf_vs = false; tgt_vs = (curr->crossat - altitude_ft) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr) / 6076.0 / speed*60.0); + checkTcas(); tgt_altitude_ft = curr->crossat; } else { use_perf_vs = true; @@ -343,6 +344,32 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) { } } +void FGAIAircraft::checkTcas(void) +{ + if (props->getIntValue("tcas/threat-level",0)==3) + { + int RASense = props->getIntValue("tcas/ra-sense",0); + if ((RASense>0)&&(tgt_vs<4000)) + // upward RA: climb! + tgt_vs = 4000; + else + if (RASense<0) + { + // downward RA: descend! + if (altitude_ft < 1000) + { + // too low: level off + if (tgt_vs>0) + tgt_vs = 0; + } + else + { + if (tgt_vs >- 4000) + tgt_vs = -4000; + } + } + } +} void FGAIAircraft::initializeFlightPlan() { } @@ -603,6 +630,7 @@ void FGAIAircraft::handleFirstWaypoint() { tgt_vs = (curr->crossat - prev->altitude) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr) / 6076.0 / prev->speed*60.0); + checkTcas(); tgt_altitude_ft = curr->crossat; } else { use_perf_vs = true; @@ -1025,6 +1053,7 @@ void FGAIAircraft::updateVerticalSpeedTarget() { } } //else // tgt_vs = 0.0; + checkTcas(); } void FGAIAircraft::updatePitchAngleTarget() { @@ -1183,4 +1212,4 @@ time_t FGAIAircraft::checkForArrivalTime(string wptName) { cerr << "Checking arrival time: ete " << ete << ". Time to go : " << secondsToGo << ". Track length = " << tracklength << endl; } return (ete - secondsToGo); // Positive when we're too slow... -} \ No newline at end of file +} diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index 1d8103726..ea99462d8 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -94,6 +94,7 @@ public: inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");}; std::string atGate(); + void checkTcas(); protected: void Run(double dt);