]> git.mxchange.org Git - flightgear.git/commitdiff
- Make two variable name modification to clarify units: altitude -> altitude_ft
authorcurt <curt>
Sat, 24 Jun 2006 00:00:27 +0000 (00:00 +0000)
committercurt <curt>
Sat, 24 Jun 2006 00:00:27 +0000 (00:00 +0000)
  and tgt_altitude -> tgt_altitude_ft.  Also fix a comment in AIBase.hxx
  indicating that the altitude is in meters, even though the usage throughout the
  code was most definitely feet.

- In AIMultiplayer.cxx, update the altitude_ft variable so that the altitude
  is reported correctly in the entity's property subtree.

- In AIMultiplayer.cxx, compute a velocity value in kts to fill in the speed
  entry in the entity's property subtree.  Note, this is not an earth centered
  reference speed, not an indicated speed and not a speed relative to the local
  airmass (that would be much harder to do.)

src/AIModel/AIAircraft.cxx
src/AIModel/AIBallistic.cxx
src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx
src/AIModel/AIMultiplayer.cxx
src/AIModel/AIStorm.cxx

index 0f1295276452c0e932abedb66b2934d9fd3e8482..b6605278555257cad86f0821cfebd8c2314d2b3d 100644 (file)
@@ -180,7 +180,7 @@ void FGAIAircraft::Run(double dt) {
                 doGroundAltitude();
                 //cerr << " Actual altitude " << altitude << endl;
                 // Transform();
-                pos.setElevationFt(altitude);
+                pos.setElevationFt(altitude_ft);
             }
             return;
         }
@@ -389,9 +389,8 @@ void FGAIAircraft::Run(double dt) {
     }
 
     // adjust altitude (meters) based on current vertical speed (fpm)
-    altitude += vs / 60.0 * dt;
-    pos.setElevationFt(altitude);  
-    double altitude_ft = altitude;
+    altitude_ft += vs / 60.0 * dt;
+    pos.setElevationFt(altitude_ft);  
 
     // adjust target Altitude, based on ground elevation when on ground
     if (no_roll) {
@@ -400,23 +399,23 @@ void FGAIAircraft::Run(double dt) {
     } else {
         // find target vertical speed if altitude lock engaged
         if (alt_lock && use_perf_vs) {
-            if (altitude_ft < tgt_altitude) {
-                tgt_vs = tgt_altitude - altitude_ft;
+            if (altitude_ft < tgt_altitude_ft) {
+                tgt_vs = tgt_altitude_ft - altitude_ft;
                 if (tgt_vs > performance->climb_rate)
                     tgt_vs = performance->climb_rate;
             } else {
-                tgt_vs = tgt_altitude - altitude_ft;
+                tgt_vs = tgt_altitude_ft - altitude_ft;
                 if (tgt_vs  < (-performance->descent_rate))
                     tgt_vs = -performance->descent_rate;
             }
         }
 
         if (alt_lock && !use_perf_vs) {
-            double max_vs = 4*(tgt_altitude - altitude);
+            double max_vs = 4*(tgt_altitude_ft - altitude_ft);
             double min_vs = 100;
-            if (tgt_altitude < altitude)
+            if (tgt_altitude_ft < altitude_ft)
                 min_vs = -100.0;
-            if ((fabs(tgt_altitude - altitude) < 1500.0)
+            if ((fabs(tgt_altitude_ft - altitude_ft) < 1500.0)
                     && (fabs(max_vs) < fabs(tgt_vs)))
                 tgt_vs = max_vs;
 
@@ -493,8 +492,8 @@ void FGAIAircraft::YawTo(double angle) {
 }
 
 
-void FGAIAircraft::ClimbTo(double altitude) {
-    tgt_altitude = altitude;
+void FGAIAircraft::ClimbTo(double alt_ft ) {
+    tgt_altitude_ft = alt_ft;
     alt_lock = true;
 }
 
@@ -595,10 +594,10 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
             tgt_vs = (curr->crossat - prev->altitude)
                     / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
                     / 6076.0 / prev->speed*60.0);
-            tgt_altitude = curr->crossat;
+            tgt_altitude_ft = curr->crossat;
         } else {
             use_perf_vs = true;
-            tgt_altitude = prev->altitude;
+            tgt_altitude_ft = prev->altitude;
         }
         alt_lock = hdg_lock = true;
         no_roll = prev->on_ground;
@@ -761,19 +760,19 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
 
         //cerr << "5.1" << endl;
         if (!(prev->on_ground)) { // only update the tgt altitude from flightplan if not on the ground
-            tgt_altitude = prev->altitude;
+            tgt_altitude_ft = prev->altitude;
             if (curr->crossat > -1000.0) {
                 //cerr << "5.1a" << endl;
                 use_perf_vs = false;
-                tgt_vs = (curr->crossat - altitude) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
+                tgt_vs = (curr->crossat - altitude_ft) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
                         / 6076.0 / speed*60.0);
                 //cerr << "5.1b" << endl;
-                tgt_altitude = curr->crossat;
+                tgt_altitude_ft = curr->crossat;
             } else {
                 //cerr << "5.1c" << endl;
                 use_perf_vs = true;
                 //cerr << "5.1d" << endl;
-                //cerr << "Setting target altitude : " <<tgt_altitude << endl;
+                //cerr << "Setting target altitude : " <<tgt_altitude_ft << endl;
             }
         }
         //cerr << "6" << endl;
@@ -782,7 +781,7 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
         no_roll = prev->on_ground;
         //cout << "Crossing waypoint: " << prev->name << endl;
         //cout << "  Target speed:    " << tgt_speed << endl;
-        //cout << "  Target altitude: " << tgt_altitude << endl;
+        //cout << "  Target altitude: " << tgt_altitude_ft << endl;
         //cout << "  Target heading:  " << tgt_heading << endl << endl;
 
     } else {
@@ -892,16 +891,16 @@ void FGAIAircraft::loadNextLeg() {
         //        //cerr << "25.1a" << endl;
         //        use_perf_vs = false;
         //
-        //        tgt_vs = (curr->crossat - altitude)/
+        //        tgt_vs = (curr->crossat - altitude_ft)/
         //          (fp->getDistanceToGo(pos.lat(), pos.lon(), curr)/6076.0/speed*60.0);
         //        //cerr << "25.1b" << endl;
-        //        tgt_altitude = curr->crossat;
+        //        tgt_altitude_ft = curr->crossat;
         //} else {
         //        //cerr << "25.1c" << endl;
         //        use_perf_vs = true;
         //        //cerr << "25.1d" << endl;
-        //        tgt_altitude = prev->altitude;
-        //        //cerr << "Setting target altitude : " <<tgt_altitude << endl;
+        //        tgt_altitude_ft = prev->altitude;
+        //        //cerr << "Setting target altitude : " <<tgt_altitude_ft << endl;
         // }
         //cerr << "26" << endl;
         //tgt_speed = prev->speed;
@@ -963,13 +962,13 @@ void FGAIAircraft::getGroundElev(double dt) {
         // FIXME: make sure the pos.lat/pos.lon values are in degrees ...
         double alt;
         if (globals->get_scenery()->get_elevation_m(pos.getLatitudeDeg(), pos.getLongitudeDeg(), 20000.0, alt, 0))
-            tgt_altitude = alt * SG_METER_TO_FEET;
+            tgt_altitude_ft = alt * SG_METER_TO_FEET;
 
-        //cerr << "Target altitude : " << tgt_altitude << endl;
+        //cerr << "Target altitude : " << tgt_altitude_ft << endl;
         // if (globals->get_scenery()->get_elevation_m(pos.lat(), pos.lon(),
         //                                            20000.0, alt))
-        //    tgt_altitude = alt * SG_METER_TO_FEET;
-        //cerr << "Target altitude : " << tgt_altitude << endl;
+        //    tgt_altitude_ft = alt * SG_METER_TO_FEET;
+        //cerr << "Target altitude : " << tgt_altitude_ft << endl;
     }
 }
 
@@ -985,9 +984,9 @@ void FGAIAircraft::setTACANChannelID(const string& id) {
 
 
 void FGAIAircraft::doGroundAltitude() {
-   if (fabs(altitude - (tgt_altitude+groundOffset)) > 1000.0)
-       altitude = (tgt_altitude + groundOffset);
+   if (fabs(altitude_ft - (tgt_altitude_ft+groundOffset)) > 1000.0)
+       altitude_ft = (tgt_altitude_ft + groundOffset);
    else
-      altitude += 0.1 * ((tgt_altitude+groundOffset) - altitude);
+      altitude_ft += 0.1 * ((tgt_altitude_ft+groundOffset) - altitude_ft);
 }
 
index a91e440fed092e77edb9a0880f977e983d3555fa..c7a5ab72c2c78f94318df4e1fe7ba902e9d40c88 100644 (file)
@@ -193,8 +193,8 @@ void FGAIBallistic::Run(double dt) {
    vs -= (gravity - buoyancy) * dt;
    
    // adjust altitude (feet)
-   altitude += vs * dt;
-   pos.setElevationFt(altitude); 
+   altitude_ft += vs * dt;
+   pos.setElevationFt(altitude_ft); 
 
    // recalculate pitch (velocity vector) if aerostabilized
    //   cout << "aero_stabilised " << aero_stabilised  << endl ;
@@ -204,7 +204,7 @@ void FGAIBallistic::Run(double dt) {
    speed = sqrt( vs * vs + hs * hs);
 
    // set destruction flag if altitude less than sea level -1000
-   if (altitude < -1000.0) setDie(true);
+   if (altitude_ft < -1000.0) setDie(true);
 
 }  // end Run
 
index 43a001cb94266ca3b24d470cd827e9df29045eb8..0a1401e50e89b1daadc725a06a69de6517ae15c8 100644 (file)
@@ -56,7 +56,7 @@ FGAIBase::FGAIBase(object_type ot)
     _refID( _newAIModelID() ),
     _otype(ot)
 {
-    tgt_heading = hdg = tgt_altitude = tgt_speed = 0.0;
+    tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0;
     tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0;
     bearing = elevation = range = rdot = 0.0;
     x_shift = y_shift = rotation = 0.0;
@@ -229,7 +229,7 @@ void FGAIBase::bind() {
    props->setDoubleValue("controls/flight/target-roll", roll);
 
    props->setStringValue("controls/flight/longitude-mode", "alt");
-   props->setDoubleValue("controls/flight/target-alt", altitude);
+   props->setDoubleValue("controls/flight/target-alt", altitude_ft);
    props->setDoubleValue("controls/flight/target-pitch", pitch);
 
    props->setDoubleValue("controls/flight/target-spd", speed);
@@ -318,7 +318,7 @@ double FGAIBase::UpdateRadar(FGAIManager* manager)
      if (horiz_offset < -180.0) horiz_offset += 360.0;
 
      // calculate elevation to target
-     elevation = atan2( altitude - user_altitude, range_ft ) * SG_RADIANS_TO_DEGREES;
+     elevation = atan2( altitude_ft - user_altitude, range_ft ) * SG_RADIANS_TO_DEGREES;
 
      // calculate look up/down to target
      vert_offset = elevation - user_pitch;
@@ -342,7 +342,7 @@ double FGAIBase::UpdateRadar(FGAIManager* manager)
      x_shift = range * sin( horiz_offset * SG_DEGREES_TO_RADIANS);
      rotation = hdg - user_heading;
      if (rotation < 0.0) rotation += 360.0;
-     ht_diff = altitude - user_altitude;
+     ht_diff = altitude_ft - user_altitude;
 
    }
 
@@ -396,7 +396,7 @@ void FGAIBase::_setVS_fps( double _vs ) {
 }
 
 double FGAIBase::_getAltitude() const {
-    return altitude;
+    return altitude_ft;
 }
 void FGAIBase::_setAltitude( double _alt ) {
     setAltitude( _alt );
@@ -414,6 +414,8 @@ void FGAIBase::CalculateMach() {
     // Calculate rho at altitude, using standard atmosphere
     // For the temperature T and the pressure p,
 
+    double altitude = altitude_ft;
+
     if (altitude < 36152) {            // curve fits for the troposphere
       T = 59 - 0.00356 * altitude;
       p = 2116 * pow( ((T + 459.7) / 518.6) , 5.256);
index d214144861c4608dc5f55142800dbb601272db81..5fd191c8713d2dd885f782c3298f872ce421e738 100644 (file)
@@ -88,7 +88,7 @@ protected:
     double roll;       // degrees, left is negative
     double pitch;      // degrees, nose-down is negative
     double speed;       // knots true airspeed
-    double altitude;    // meters above sea level
+    double altitude_ft; // feet above sea level
     double vs;          // vertical speed, feet per minute
     double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
 
@@ -96,9 +96,9 @@ protected:
     double ft_per_deg_lat;
 
     // these describe the model's desired state
-    double tgt_heading;  // target heading, degrees true
-    double tgt_altitude; // target altitude, *feet* above sea level
-    double tgt_speed;    // target speed, KTAS
+    double tgt_heading;     // target heading, degrees true
+    double tgt_altitude_ft; // target altitude, *feet* above sea level
+    double tgt_speed;       // target speed, KTAS
     double tgt_roll;
     double tgt_pitch;
     double tgt_yaw;
@@ -202,9 +202,9 @@ inline void FGAIBase::setHeading( double heading ) {
     hdg = tgt_heading = heading;
 }
 
-inline void FGAIBase::setAltitude( double altitude_ft ) {
-    altitude = tgt_altitude = altitude_ft;
-    pos.setElevationFt(altitude);
+inline void FGAIBase::setAltitude( double alt_ft ) {
+    altitude_ft = tgt_altitude_ft = alt_ft;
+    pos.setElevationFt(altitude_ft);
 }
 
 inline void FGAIBase::setBank( double bank ) {
index e4bb79176aeaf42feb6ce87727a2cde379d1ba1f..000386b88408952dc310063d5b31f6b839b03af8 100755 (executable)
@@ -172,6 +172,8 @@ void FGAIMultiplayer::update(double dt)
 
   SGVec3d ecPos;
   SGQuatf ecOrient;
+  SGVec3f myVel;
+
   if (tInterp <= curentPkgTime) {
     // Ok, we need a time prevous to the last available packet,
     // that is good ...
@@ -184,6 +186,7 @@ void FGAIMultiplayer::update(double dt)
       MotionInfo::iterator firstIt = mMotionInfo.begin();
       ecPos = firstIt->second.position;
       ecOrient = firstIt->second.orientation;
+      myVel = firstIt->second.linearVel;
 
       std::vector<FGFloatPropertyData>::const_iterator firstPropIt;
       std::vector<FGFloatPropertyData>::const_iterator firstPropItEnd;
@@ -217,6 +220,7 @@ void FGAIMultiplayer::update(double dt)
       ecPos = ((1-tau)*prevIt->second.position + tau*nextIt->second.position);
       ecOrient = interpolate((float)tau, prevIt->second.orientation,
                              nextIt->second.orientation);
+      myVel = ((1-tau)*prevIt->second.linearVel + tau*nextIt->second.linearVel);
 
       if (prevIt->second.properties.size()
           == nextIt->second.properties.size()) {
@@ -262,6 +266,7 @@ void FGAIMultiplayer::update(double dt)
     ecOrient = motionInfo.orientation;
     SGVec3f linearVel = motionInfo.linearVel;
     SGVec3f angularVel = motionInfo.angularVel;
+    myVel = linearVel;
     while (0 < t) {
       double h = 1e-1;
       if (t < h)
@@ -272,6 +277,7 @@ void FGAIMultiplayer::update(double dt)
       ecOrient += h*ecOrient.derivative(angularVel);
 
       linearVel += h*(cross(linearVel, angularVel) + motionInfo.linearAccel);
+      myVel = linearVel;
       angularVel += h*motionInfo.angularAccel;
       
       t -= h;
@@ -292,7 +298,15 @@ void FGAIMultiplayer::update(double dt)
   
   // extract the position
   pos = SGGeod::fromCart(ecPos);
-  
+  altitude_ft = pos.getElevationFt();
+
+  // estimate speed (we care only about magnitude not direction/frame
+  // of reference here)
+  double vel_ms = sqrt( myVel[0]*myVel[0] + myVel[1]*myVel[1]
+                        + myVel[2]*myVel[2] );
+  double vel_kts = vel_ms * SG_METER_TO_NM * 3600.0;
+  speed = vel_kts;
+
   // The quaternion rotating from the earth centered frame to the
   // horizontal local frame
   SGQuatf qEc2Hl = SGQuatf::fromLonLatRad((float)pos.getLongitudeRad(),
index 0fafd7055168f1f043d3cd1e87cc85b26f0a6d8b..51e79e31cc4b5795ac3f6a6d018b1bb4834ec1c9 100644 (file)
@@ -165,7 +165,7 @@ void FGAIStorm::Run(double dt) {
    range = range_ft / 6076.11549;
 
    if (range < (diameter * 0.5) &&
-       user_altitude > (altitude - 1000.0) &&
+       user_altitude > (altitude_ft - 1000.0) &&
        user_altitude < height) {
               turb_mag_node->setDoubleValue(strength_norm);
               turb_rate_node->setDoubleValue(0.5);