/*******************************************************************************
-
+
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 !!!!!!!
CLASS DECLARATION
*******************************************************************************/
-
-
-
-
FGTrimLong::FGTrimLong(FGFDMExec *FDMExec,FGInitialCondition *FGIC ) {
Ncycles=40;
trimudot=true;
axis_count=0;
-
}
-FGTrimLong::~FGTrimLong(void) {}
-
-
+/******************************************************************************/
+FGTrimLong::~FGTrimLong(void) {}
+/******************************************************************************/
void FGTrimLong::TrimStats() {
cout << endl << " Trim Statistics: " << endl;
}
}
+/******************************************************************************/
+
void FGTrimLong::Report(void) {
cout << endl << " Trim Results" << endl;
cout << " Alpha: " << fdmex->GetTranslation()->Getalpha()*RADTODEG
<< " Tolerance " << A_Tolerance << endl;
}
+/******************************************************************************/
+
void FGTrimLong::ReportState(void) {
cout << endl << " JSBSim Trim Report" << endl;
cout << " Weight: " << fdmex->GetAircraft()->GetWeight()
cout << " Throttle: " << fdmex->GetFCS()->GetThrottlePos(0)/100 << endl;
}
+/******************************************************************************/
+
void FGTrimLong::setThrottlesPct(float tt) {
float tMin,tMax;
}
}
+/******************************************************************************/
int FGTrimLong::checkLimits(trimfp fp, float current, float min, float max) {
float lo,hi;
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
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)
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;
}
}
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);
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) {
total_its=k;
k=Ncycles; //force the trim to fail
}
-
-
-
}
}
k++;
}
-
//YOU WERE WARNED, BUT YOU DID IT ANYWAY.
+