]> git.mxchange.org Git - flightgear.git/commitdiff
Make AIplanes respond to TCAS RAs.
authorThorstenB <brehmt@gmail.com>
Mon, 17 Jan 2011 22:33:54 +0000 (23:33 +0100)
committerThorstenB <brehmt@gmail.com>
Fri, 25 Feb 2011 20:12:35 +0000 (21:12 +0100)
src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx

index 8d7df9225d226ff4ea0b9035f6c2528fec413671..d0e3197052a77fe3e332f6be6fa0cc6042e27157 100644 (file)
@@ -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
+}
index 1d81037261786083a450dcd3501a16971cda5d60..ea99462d8b5ff1b7984338f0501366e7f352acd4 100644 (file)
@@ -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);