]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGTrimLong.cpp
Fixes to jsbsim.
[flightgear.git] / src / FDM / JSBSim / FGTrimLong.cpp
index 9ab7dea505e75557c2213eeac93045a1bcca3c8b..7bc91686ae0de5affb5b59420e25f8833f4a6385 100644 (file)
@@ -1,40 +1,40 @@
 /*******************************************************************************
+
  Header:       FGTrimLong.cpp
  Author:       Tony Peden
  Date started: 9/8/99
- ------------- Copyright (C) 1999  Anthony K. Peden (apeden@earthlink.net) -------------
+
+ --------- Copyright (C) 1999  Anthony K. Peden (apeden@earthlink.net) ---------
+
  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free Software
  Foundation; either version 2 of the License, or (at your option) any later
  version.
+
  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  details.
+
  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  Place - Suite 330, Boston, MA  02111-1307, USA.
+
  Further information about the GNU General Public License can also be found on
  the world wide web at http://www.gnu.org.
+
+
  HISTORY
 --------------------------------------------------------------------------------
 9/8/99   TP   Created
+
+
 FUNCTIONAL DESCRIPTION
 --------------------------------------------------------------------------------
+
 This class takes the given set of IC's and finds the angle of attack, elevator,
 and throttle setting required to fly steady level. This is currently for in-air
-conditions only.  It is implemented using an iterative, one-axis-at-a-time 
+conditions only.  It is implemented using an iterative, one-axis-at-a-time
 scheme. */
 
 //  !!!!!!! BEWARE ALL YE WHO ENTER HERE !!!!!!!
@@ -54,10 +54,6 @@ INCLUDES
 CLASS DECLARATION
 *******************************************************************************/
 
-
-
-
-
 FGTrimLong::FGTrimLong(FGFDMExec *FDMExec,FGInitialCondition *FGIC ) {
 
   Ncycles=40;
@@ -82,14 +78,13 @@ FGTrimLong::FGTrimLong(FGFDMExec *FDMExec,FGInitialCondition *FGIC ) {
   trimudot=true;
   axis_count=0;
 
-
 }
 
-FGTrimLong::~FGTrimLong(void) {}
-
-
+/******************************************************************************/
 
+FGTrimLong::~FGTrimLong(void) {}
 
+/******************************************************************************/
 
 void FGTrimLong::TrimStats() {
   cout << endl << "  Trim Statistics: " << endl;
@@ -102,6 +97,8 @@ void FGTrimLong::TrimStats() {
   }
 }
 
+/******************************************************************************/
+
 void FGTrimLong::Report(void) {
   cout << endl << "  Trim Results" << endl;
   cout << "  Alpha: " << fdmex->GetTranslation()->Getalpha()*RADTODEG
@@ -117,6 +114,8 @@ void FGTrimLong::Report(void) {
   << " Tolerance " << A_Tolerance << endl;
 }
 
+/******************************************************************************/
+
 void FGTrimLong::ReportState(void) {
   cout << endl << "  JSBSim Trim Report" << endl;
   cout << "    Weight: " << fdmex->GetAircraft()->GetWeight()
@@ -175,6 +174,8 @@ void FGTrimLong::ReportState(void) {
   cout << "    Throttle: " << fdmex->GetFCS()->GetThrottlePos(0)/100 << endl;
 }
 
+/******************************************************************************/
+
 void FGTrimLong::setThrottlesPct(float tt) {
 
   float tMin,tMax;
@@ -187,6 +188,7 @@ void FGTrimLong::setThrottlesPct(float tt) {
   }
 }
 
+/******************************************************************************/
 
 int FGTrimLong::checkLimits(trimfp fp, float current, float min, float max) {
   float lo,hi;
@@ -209,12 +211,15 @@ int FGTrimLong::checkLimits(trimfp fp, float current, float min, float max) {
   return result;
 }
 
-bool FGTrimLong::solve(trimfp fp,float guess,float desired, float *result, float eps, float min, float max, int max_iterations, int *actual_its) {
+/******************************************************************************/
+
+bool FGTrimLong::solve(trimfp fp,float guess,float desired, float *result,
+         float eps, float min, float max, int max_iterations, int *actual_its) {
 
   float x1,x2,x3,f1,f2,f3,d,d0;
   float const relax =0.9;
-  x1=x3=0;
   int i;
+  x1 = x3 = x2 = 0;
   d=1;
   bool success=false;
   //initializations
@@ -233,8 +238,8 @@ bool FGTrimLong::solve(trimfp fp,float guess,float desired, float *result, float
     i=0;
     while ((fabs(d) > eps) && (i < max_iterations)) {
       if(Debug > 1)
-        cout << "FGTrimLong::solve i,x1,x2,x3: " << i << ", " << x1 << ", " << x2 << ", " << x3 << endl;
-
+        cout << "FGTrimLong::solve i,x1,x2,x3: " << i << ", " << x1
+                                            << ", " << x2 << ", " << x3 << endl;
       d=(x3-x1)/d0;
       x2=x1-d*d0*f1/(f3-f1);
       // if(x2 < min)
@@ -265,8 +270,10 @@ bool FGTrimLong::solve(trimfp fp,float guess,float desired, float *result, float
   return success;
 }
 
-bool FGTrimLong::findInterval(trimfp fp, float *lo, float *hi,float guess,float desired,int max_iterations) {
+/******************************************************************************/
 
+bool FGTrimLong::findInterval(trimfp fp, float *lo, float *hi,float guess,
+                                             float desired,int max_iterations) {
   int i=0;
   bool found=false;
   float flo,fhi,fguess;
@@ -292,37 +299,52 @@ bool FGTrimLong::findInterval(trimfp fp, float *lo, float *hi,float guess,float
       }
     }
     if(Debug > 1)
-      cout << "FGTrimLong::findInterval: i=" << i << " Lo= " << xlo << " Hi= " << xhi << " flo*fhi: " << flo*fhi << endl;
+      cout << "FGTrimLong::findInterval: i=" << i << " Lo= " << xlo
+                           << " Hi= " << xhi << " flo*fhi: " << flo*fhi << endl;
   } while((found == 0) && (i <= max_iterations));
   *lo=xlo;
   *hi=xhi;
   return found;
 }
 
+/******************************************************************************/
+
 float FGTrimLong::udot_func(float x) {
   setThrottlesPct(x);
   fdmex->RunIC(fgic);
   return fdmex->GetTranslation()->GetUVWdot()(1);
 }
 
+/******************************************************************************/
+
 float FGTrimLong::wdot_func(float x) {
   fgic->SetAlphaDegIC(x);
   fdmex->RunIC(fgic);
   return fdmex->GetTranslation()->GetUVWdot()(3);
 }
 
+/******************************************************************************/
+
 float FGTrimLong::qdot_func(float x) {
   fdmex->GetFCS()->SetPitchTrimCmd(x);
   fdmex->RunIC(fgic);
   return fdmex->GetRotation()->GetPQRdot()(2);
 }
 
+/******************************************************************************/
+
 bool FGTrimLong::DoTrim(void) {
-  int k=0,j=0,sum=0,trim_failed=0,jmax=Naxis;
+  int k=0;
   int its;
-  float step,temp,min,max;
+  
+
+  if(fgic->GetVtrueKtsIC() < 1) {
+    cout << "Trim failed, on-ground trimming not yet implemented." << endl;
+    cout << "Or did you *really* mean to start in-air"
+         << " with less than 1 knot airspeed?" << endl;
+    return false;
+  }
 
-  trimfp fp;
 
   fgic -> SetAlphaDegIC((alphaMin+alphaMax)/2);
   fdmex -> GetFCS() -> SetDeCmd(0);
@@ -379,22 +401,18 @@ bool FGTrimLong::DoTrim(void) {
           total_its=k;
           k=Ncycles; //force the trim to fail
         }
-
-
-
-      }
+     }
       if( udot > Tolerance ) {
         if(checkLimits(udotf,dth,0,1) == false) {
           cout << "    Sorry, udot doesn't appear to be trimmable" << endl;
           cout << "    Resetting throttles to zero" << endl;
+          setThrottlesPct(0);
           fdmex->GetFCS()->SetThrottleCmd(-1,0);
+          fdmex->RunIC(fgic);
           total_its=k;
           k=Ncycles; //force the trim to fail
         }
-
-
-
-      }
+     }
       if(qdot > A_Tolerance) {
 
         if(checkLimits(qdotf,fdmex->GetFCS()->GetPitchTrimCmd(),-1,1) == false) {
@@ -402,9 +420,6 @@ bool FGTrimLong::DoTrim(void) {
           total_its=k;
           k=Ncycles; //force the trim to fail
         }
-
-
-
       }
     }
     k++;
@@ -421,5 +436,5 @@ bool FGTrimLong::DoTrim(void) {
 
 }
 
-
 //YOU WERE WARNED, BUT YOU DID IT ANYWAY.
+