]> git.mxchange.org Git - flightgear.git/commitdiff
Expose vertical speed for MP planes
authorThorstenB <brehmt@gmail.com>
Wed, 29 Dec 2010 21:13:04 +0000 (22:13 +0100)
committerThorstenB <brehmt@gmail.com>
Fri, 25 Feb 2011 20:12:35 +0000 (21:12 +0100)
vertical speed of MP planes was always 0,
calculate their (average) vertical speed since
it's required for TCAS and TCAS display

src/AIModel/AIMultiplayer.cxx
src/AIModel/AIMultiplayer.hxx

index 0652dfef73751daf52f67997d72028ef2e6ad916..a9635c5f7b5541902035b8ee508cd6fbda54f294 100644 (file)
@@ -39,11 +39,11 @@ FGAIMultiplayer::FGAIMultiplayer() : FGAIBase(otMultiplayer) {
    mTimeOffsetSet = false;
    mAllowExtrapolation = true;
    mLagAdjustSystemSpeed = 10;
-
+   mLastTimestamp = 0;
    aip.getSceneGraph()->setNodeMask(~SG_NODEMASK_TERRAIN_BIT);
+   lastUpdateTime = 0;
 
-}
-
+} 
 
 FGAIMultiplayer::~FGAIMultiplayer() {
 }
@@ -417,8 +417,21 @@ void FGAIMultiplayer::update(double dt)
   
   // extract the position
   pos = SGGeod::fromCart(ecPos);
+  double recent_alt_ft = altitude_ft;
   altitude_ft = pos.getElevationFt();
 
+  // expose a valid vertical speed
+  if (lastUpdateTime != 0)
+  {
+      double dT = curtime - lastUpdateTime;
+      double Weighting=1;
+      if (dt < 1.0)
+          Weighting = dt;
+      // simple smoothing over 1 second
+      vs = (1.0-Weighting)*vs +  Weighting * (altitude_ft - recent_alt_ft) / dT * 60;
+  }
+  lastUpdateTime = curtime;
+
   // The quaternion rotating from the earth centered frame to the
   // horizontal local frame
   SGQuatf qEc2Hl = SGQuatf::fromLonLatRad((float)pos.getLongitudeRad(),
index d79f0c20614cef4f7b9d6f74a20de1953ff8981f..4c8d50a001d086f237fc4d2ac8ed8f58076ac48b 100644 (file)
@@ -78,6 +78,8 @@ private:
   double mTimeOffset;
   bool mTimeOffsetSet;
 
+  double lastUpdateTime;
+
   /// Properties which are for now exposed for testing
   bool mAllowExtrapolation;
   double mLagAdjustSystemSpeed;