2000-11-03 23:02:47 +00:00
|
|
|
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2000-10-02 23:07:30 +00:00
|
|
|
|
|
|
|
Header: FGTrimAxis.cpp
|
|
|
|
Author: Tony Peden
|
|
|
|
Date started: 7/3/00
|
|
|
|
|
|
|
|
--------- 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
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
7/3/00 TP Created
|
|
|
|
|
2000-11-03 23:02:47 +00:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2000-10-02 23:07:30 +00:00
|
|
|
INCLUDES
|
2000-11-03 23:02:47 +00:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
2000-10-02 23:07:30 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "FGFDMExec.h"
|
|
|
|
#include "FGAtmosphere.h"
|
|
|
|
#include "FGInitialCondition.h"
|
|
|
|
#include "FGTrimAxis.h"
|
|
|
|
#include "FGAircraft.h"
|
2001-03-30 01:04:50 +00:00
|
|
|
#include "FGPropulsion.h"
|
2000-10-02 23:07:30 +00:00
|
|
|
|
2001-03-30 01:04:50 +00:00
|
|
|
static const char *IdSrc = "$Id$";
|
2000-10-14 02:10:10 +00:00
|
|
|
static const char *IdHdr = ID_TRIMAXIS;
|
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
2001-03-30 01:04:50 +00:00
|
|
|
FGTrimAxis::FGTrimAxis(FGFDMExec* fdex, FGInitialCondition* ic, State st,
|
|
|
|
Control ctrl) {
|
2000-10-02 23:07:30 +00:00
|
|
|
|
|
|
|
fdmex=fdex;
|
|
|
|
fgic=ic;
|
2001-03-30 01:04:50 +00:00
|
|
|
state=st;
|
2000-10-02 23:07:30 +00:00
|
|
|
control=ctrl;
|
|
|
|
solver_eps=tolerance;
|
|
|
|
max_iterations=10;
|
|
|
|
control_value=0;
|
|
|
|
its_to_stable_value=0;
|
|
|
|
total_iterations=0;
|
|
|
|
total_stability_iterations=0;
|
2001-03-30 01:04:50 +00:00
|
|
|
state_convert=1.0;
|
2000-10-02 23:07:30 +00:00
|
|
|
control_convert=1.0;
|
2001-03-30 01:04:50 +00:00
|
|
|
state_value=0;
|
2000-10-02 23:07:30 +00:00
|
|
|
switch(control) {
|
|
|
|
case tThrottle:
|
|
|
|
control_min=0;
|
|
|
|
control_max=1;
|
|
|
|
control_value=0.5;
|
|
|
|
break;
|
|
|
|
case tBeta:
|
|
|
|
control_min=-30*DEGTORAD;
|
|
|
|
control_max=30*DEGTORAD;
|
|
|
|
control_convert=RADTODEG;
|
|
|
|
break;
|
|
|
|
case tAlpha:
|
|
|
|
control_min=fdmex->GetAircraft()->GetAlphaCLMin();
|
|
|
|
control_max=fdmex->GetAircraft()->GetAlphaCLMax();
|
|
|
|
if(control_max <= control_min) {
|
|
|
|
control_max=20*DEGTORAD;
|
|
|
|
control_min=-5*DEGTORAD;
|
|
|
|
}
|
|
|
|
control_value= (control_min+control_max)/2;
|
|
|
|
control_convert=RADTODEG;
|
|
|
|
solver_eps=tolerance/100;
|
|
|
|
break;
|
|
|
|
case tPitchTrim:
|
|
|
|
case tElevator:
|
|
|
|
case tRollTrim:
|
|
|
|
case tAileron:
|
|
|
|
case tYawTrim:
|
|
|
|
case tRudder:
|
|
|
|
control_min=-1;
|
|
|
|
control_max=1;
|
2001-03-30 01:04:50 +00:00
|
|
|
state_convert=RADTODEG;
|
2000-10-02 23:07:30 +00:00
|
|
|
solver_eps=tolerance/100;
|
|
|
|
break;
|
|
|
|
case tAltAGL:
|
|
|
|
control_min=0;
|
|
|
|
control_max=30;
|
|
|
|
control_value=fdmex->GetPosition()->GetDistanceAGL();
|
|
|
|
solver_eps=tolerance/100;
|
|
|
|
break;
|
|
|
|
case tTheta:
|
2000-11-03 23:02:47 +00:00
|
|
|
control_min=fdmex->GetRotation()->Gettht() - 5*DEGTORAD;
|
|
|
|
control_max=fdmex->GetRotation()->Gettht() + 5*DEGTORAD;
|
2001-03-30 01:04:50 +00:00
|
|
|
state_convert=RADTODEG;
|
2000-10-02 23:07:30 +00:00
|
|
|
break;
|
|
|
|
case tPhi:
|
2001-03-30 01:04:50 +00:00
|
|
|
control_min=fdmex->GetRotation()->Getphi() - 30*DEGTORAD;
|
|
|
|
control_max=fdmex->GetRotation()->Getphi() + 30*DEGTORAD;
|
|
|
|
state_convert=RADTODEG;
|
|
|
|
control_convert=RADTODEG;
|
2000-10-02 23:07:30 +00:00
|
|
|
break;
|
|
|
|
case tGamma:
|
|
|
|
solver_eps=tolerance/100;
|
|
|
|
control_min=-80*DEGTORAD;
|
|
|
|
control_max=80*DEGTORAD;
|
|
|
|
control_convert=RADTODEG;
|
|
|
|
break;
|
2001-03-30 01:04:50 +00:00
|
|
|
case tHeading:
|
|
|
|
control_min=fdmex->GetRotation()->Getpsi() - 30*DEGTORAD;
|
|
|
|
control_max=fdmex->GetRotation()->Getpsi() + 30*DEGTORAD;
|
|
|
|
state_convert=RADTODEG;
|
|
|
|
break;
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
|
|
|
|
2001-03-30 01:04:50 +00:00
|
|
|
switch(state) {
|
|
|
|
case tUdot: tolerance = DEFAULT_TOLERANCE; break;
|
|
|
|
case tVdot: tolerance = DEFAULT_TOLERANCE; break;
|
|
|
|
case tWdot: tolerance = DEFAULT_TOLERANCE; break;
|
|
|
|
case tQdot: tolerance = DEFAULT_TOLERANCE / 10; break;
|
|
|
|
case tPdot: tolerance = DEFAULT_TOLERANCE / 10; break;
|
|
|
|
case tRdot: tolerance = DEFAULT_TOLERANCE / 10; break;
|
|
|
|
case tHmgt: tolerance = 0.01; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug_lvl & 2) cout << "Instantiated: FGTrimAxis" << endl;
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2001-03-30 01:04:50 +00:00
|
|
|
FGTrimAxis::~FGTrimAxis()
|
|
|
|
{
|
|
|
|
if (debug_lvl & 2) cout << "Destroyed: FGTrimAxis" << endl;
|
|
|
|
}
|
2000-10-02 23:07:30 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2001-03-30 01:04:50 +00:00
|
|
|
void FGTrimAxis::getState(void) {
|
|
|
|
switch(state) {
|
2001-04-17 21:19:54 +00:00
|
|
|
case tUdot: state_value=fdmex->GetTranslation()->GetUVWdot(1); break;
|
|
|
|
case tVdot: state_value=fdmex->GetTranslation()->GetUVWdot(2); break;
|
|
|
|
case tWdot: state_value=fdmex->GetTranslation()->GetUVWdot(3); break;
|
|
|
|
case tQdot: state_value=fdmex->GetRotation()->GetPQRdot(2);break;
|
|
|
|
case tPdot: state_value=fdmex->GetRotation()->GetPQRdot(1); break;
|
|
|
|
case tRdot: state_value=fdmex->GetRotation()->GetPQRdot(3); break;
|
2001-03-30 01:04:50 +00:00
|
|
|
case tHmgt: state_value=computeHmgt(); break;
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2001-03-30 01:04:50 +00:00
|
|
|
//States are not settable
|
2000-10-02 23:07:30 +00:00
|
|
|
|
|
|
|
void FGTrimAxis::getControl(void) {
|
|
|
|
switch(control) {
|
|
|
|
case tThrottle: control_value=fdmex->GetFCS()->GetThrottleCmd(0); break;
|
|
|
|
case tBeta: control_value=fdmex->GetTranslation()->Getalpha(); break;
|
|
|
|
case tAlpha: control_value=fdmex->GetTranslation()->Getbeta(); break;
|
|
|
|
case tPitchTrim: control_value=fdmex->GetFCS() -> GetPitchTrimCmd(); break;
|
|
|
|
case tElevator: control_value=fdmex->GetFCS() -> GetDeCmd(); break;
|
|
|
|
case tRollTrim:
|
|
|
|
case tAileron: control_value=fdmex->GetFCS() -> GetDaCmd(); break;
|
|
|
|
case tYawTrim:
|
|
|
|
case tRudder: control_value=fdmex->GetFCS() -> GetDrCmd(); break;
|
|
|
|
case tAltAGL: control_value=fdmex->GetPosition()->GetDistanceAGL();break;
|
|
|
|
case tTheta: control_value=fdmex->GetRotation()->Gettht(); break;
|
|
|
|
case tPhi: control_value=fdmex->GetRotation()->Getphi(); break;
|
|
|
|
case tGamma: control_value=fdmex->GetPosition()->GetGamma();break;
|
2001-03-30 01:04:50 +00:00
|
|
|
case tHeading: control_value=fdmex->GetRotation()->Getpsi(); break;
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2001-03-30 01:04:50 +00:00
|
|
|
float FGTrimAxis::computeHmgt(void) {
|
|
|
|
float diff;
|
|
|
|
|
|
|
|
diff = fdmex->GetRotation()->Getpsi() -
|
|
|
|
fdmex->GetPosition()->GetGroundTrack();
|
|
|
|
|
|
|
|
if( diff < -M_PI ) {
|
|
|
|
return (diff + 2*M_PI);
|
|
|
|
} else if( diff > M_PI ) {
|
|
|
|
return (diff - 2*M_PI);
|
|
|
|
} else {
|
|
|
|
return diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
|
|
|
|
void FGTrimAxis::setControl(void) {
|
|
|
|
switch(control) {
|
|
|
|
case tThrottle: setThrottlesPct(); break;
|
|
|
|
case tBeta: fgic->SetBetaRadIC(control_value); break;
|
|
|
|
case tAlpha: fgic->SetAlphaRadIC(control_value); break;
|
2001-03-30 01:04:50 +00:00
|
|
|
case tPitchTrim: fdmex->GetFCS()->SetPitchTrimCmd(control_value); break;
|
|
|
|
case tElevator: fdmex->GetFCS()->SetDeCmd(control_value); break;
|
2000-10-02 23:07:30 +00:00
|
|
|
case tRollTrim:
|
2001-03-30 01:04:50 +00:00
|
|
|
case tAileron: fdmex->GetFCS()->SetDaCmd(control_value); break;
|
2000-10-02 23:07:30 +00:00
|
|
|
case tYawTrim:
|
2001-03-30 01:04:50 +00:00
|
|
|
case tRudder: fdmex->GetFCS()->SetDrCmd(control_value); break;
|
2000-10-02 23:07:30 +00:00
|
|
|
case tAltAGL: fgic->SetAltitudeAGLFtIC(control_value); break;
|
|
|
|
case tTheta: fgic->SetPitchAngleRadIC(control_value); break;
|
|
|
|
case tPhi: fgic->SetRollAngleRadIC(control_value); break;
|
|
|
|
case tGamma: fgic->SetFlightPathAngleRadIC(control_value); break;
|
2001-03-30 01:04:50 +00:00
|
|
|
case tHeading: fgic->SetTrueHeadingRadIC(control_value); break;
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-03 23:02:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
// the aircraft center of rotation is no longer the cg once the gear
|
|
|
|
// contact the ground so the altitude needs to be changed when pitch
|
|
|
|
// and roll angle are adjusted. Instead of attempting to calculate the
|
|
|
|
// new center of rotation, pick a gear unit as a reference and use its
|
|
|
|
// location vector to calculate the new height change. i.e. new altitude =
|
|
|
|
// earth z component of that vector (which is in body axes )
|
|
|
|
void FGTrimAxis::SetThetaOnGround(float ff) {
|
|
|
|
int center,i,ref;
|
|
|
|
|
|
|
|
// favor an off-center unit so that the same one can be used for both
|
|
|
|
// pitch and roll. An on-center unit is used (for pitch)if that's all
|
|
|
|
// that's in contact with the ground.
|
|
|
|
i=0; ref=-1; center=-1;
|
|
|
|
while( (ref < 0) && (i < fdmex->GetAircraft()->GetNumGearUnits()) ) {
|
|
|
|
if(fdmex->GetAircraft()->GetGearUnit(i)->GetWOW()) {
|
2001-04-17 21:19:54 +00:00
|
|
|
if(fabs(fdmex->GetAircraft()->GetGearUnit(i)->GetBodyLocation(2)) > 0.01)
|
2000-10-02 23:07:30 +00:00
|
|
|
ref=i;
|
|
|
|
else
|
|
|
|
center=i;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if((ref < 0) && (center >= 0)) {
|
|
|
|
ref=center;
|
|
|
|
}
|
|
|
|
cout << "SetThetaOnGround ref gear: " << ref << endl;
|
|
|
|
if(ref >= 0) {
|
|
|
|
float sp=fdmex->GetRotation()->GetSinphi();
|
|
|
|
float cp=fdmex->GetRotation()->GetCosphi();
|
2001-04-17 21:19:54 +00:00
|
|
|
float lx=fdmex->GetAircraft()->GetGearUnit(ref)->GetBodyLocation(1);
|
|
|
|
float ly=fdmex->GetAircraft()->GetGearUnit(ref)->GetBodyLocation(2);
|
|
|
|
float lz=fdmex->GetAircraft()->GetGearUnit(ref)->GetBodyLocation(3);
|
2000-10-02 23:07:30 +00:00
|
|
|
float hagl = -1*lx*sin(ff) +
|
|
|
|
ly*sp*cos(ff) +
|
|
|
|
lz*cp*cos(ff);
|
|
|
|
|
|
|
|
fgic->SetAltitudeAGLFtIC(hagl);
|
|
|
|
cout << "SetThetaOnGround new alt: " << hagl << endl;
|
|
|
|
}
|
|
|
|
fgic->SetPitchAngleRadIC(ff);
|
|
|
|
cout << "SetThetaOnGround new theta: " << ff << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2000-11-03 23:02:47 +00:00
|
|
|
bool FGTrimAxis::initTheta(void) {
|
|
|
|
int i,N,iAft, iForward;
|
|
|
|
float zAft,zForward,zDiff,theta;
|
|
|
|
bool level;
|
|
|
|
float saveAlt;
|
|
|
|
|
|
|
|
saveAlt=fgic->GetAltitudeAGLFtIC();
|
|
|
|
fgic->SetAltitudeAGLFtIC(100);
|
|
|
|
|
|
|
|
|
|
|
|
N=fdmex->GetAircraft()->GetNumGearUnits();
|
|
|
|
|
|
|
|
//find the first wheel unit forward of the cg
|
|
|
|
//the list is short so a simple linear search is fine
|
|
|
|
for( i=0; i<N; i++ ) {
|
2001-04-17 21:19:54 +00:00
|
|
|
if(fdmex->GetAircraft()->GetGearUnit(i)->GetBodyLocation(1) > 0 ) {
|
2000-11-03 23:02:47 +00:00
|
|
|
iForward=i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//now find the first wheel unit aft of the cg
|
|
|
|
for( i=0; i<N; i++ ) {
|
2001-04-17 21:19:54 +00:00
|
|
|
if(fdmex->GetAircraft()->GetGearUnit(i)->GetBodyLocation(1) < 0 ) {
|
2000-11-03 23:02:47 +00:00
|
|
|
iAft=i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now adjust theta till the wheels are the same distance from the ground
|
2001-04-17 21:19:54 +00:00
|
|
|
zAft=fdmex->GetAircraft()->GetGearUnit(1)->GetLocalGear(3);
|
|
|
|
zForward=fdmex->GetAircraft()->GetGearUnit(0)->GetLocalGear(3);
|
2000-11-03 23:02:47 +00:00
|
|
|
zDiff = zForward - zAft;
|
|
|
|
level=false;
|
|
|
|
theta=fgic->GetPitchAngleDegIC();
|
|
|
|
while(!level && (i < 100)) {
|
|
|
|
theta+=2.0*zDiff;
|
|
|
|
fgic->SetPitchAngleDegIC(theta);
|
|
|
|
fdmex->RunIC(fgic);
|
2001-04-17 21:19:54 +00:00
|
|
|
zAft=fdmex->GetAircraft()->GetGearUnit(1)->GetLocalGear(3);
|
|
|
|
zForward=fdmex->GetAircraft()->GetGearUnit(0)->GetLocalGear(3);
|
2000-11-03 23:02:47 +00:00
|
|
|
zDiff = zForward - zAft;
|
|
|
|
//cout << endl << theta << " " << zDiff << endl;
|
|
|
|
//cout << "0: " << fdmex->GetAircraft()->GetGearUnit(0)->GetLocalGear() << endl;
|
|
|
|
//cout << "1: " << fdmex->GetAircraft()->GetGearUnit(1)->GetLocalGear() << endl;
|
|
|
|
|
|
|
|
if(fabs(zDiff ) < 0.1)
|
|
|
|
level=true;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
//cout << i << endl;
|
|
|
|
cout << " Initial Theta: " << fdmex->GetRotation()->Gettht()*RADTODEG << endl;
|
|
|
|
control_min=(theta+5)*DEGTORAD;
|
|
|
|
control_max=(theta-5)*DEGTORAD;
|
|
|
|
fgic->SetAltitudeAGLFtIC(saveAlt);
|
|
|
|
if(i < 100)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
void FGTrimAxis::SetPhiOnGround(float ff) {
|
|
|
|
int i,ref;
|
|
|
|
|
|
|
|
i=0; ref=-1;
|
|
|
|
//must have an off-center unit here
|
|
|
|
while( (ref < 0) && (i < fdmex->GetAircraft()->GetNumGearUnits()) ) {
|
|
|
|
if( (fdmex->GetAircraft()->GetGearUnit(i)->GetWOW()) &&
|
2001-04-17 21:19:54 +00:00
|
|
|
(fabs(fdmex->GetAircraft()->GetGearUnit(i)->GetBodyLocation(2)) > 0.01))
|
2000-10-02 23:07:30 +00:00
|
|
|
ref=i;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if(ref >= 0) {
|
|
|
|
float st=fdmex->GetRotation()->GetSintht();
|
|
|
|
float ct=fdmex->GetRotation()->GetCostht();
|
2001-04-17 21:19:54 +00:00
|
|
|
float lx=fdmex->GetAircraft()->GetGearUnit(ref)->GetBodyLocation(1);
|
|
|
|
float ly=fdmex->GetAircraft()->GetGearUnit(ref)->GetBodyLocation(2);
|
|
|
|
float lz=fdmex->GetAircraft()->GetGearUnit(ref)->GetBodyLocation(3);
|
2000-10-02 23:07:30 +00:00
|
|
|
float hagl = -1*lx*st +
|
|
|
|
ly*sin(ff)*ct +
|
|
|
|
lz*cos(ff)*ct;
|
|
|
|
|
|
|
|
fgic->SetAltitudeAGLFtIC(hagl);
|
|
|
|
}
|
|
|
|
fgic->SetRollAngleRadIC(ff);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
void FGTrimAxis::Run(void) {
|
|
|
|
|
2001-03-30 01:04:50 +00:00
|
|
|
float last_state_value;
|
2000-10-02 23:07:30 +00:00
|
|
|
int i;
|
|
|
|
setControl();
|
|
|
|
//cout << "FGTrimAxis::Run: " << control_value << endl;
|
|
|
|
i=0;
|
|
|
|
bool stable=false;
|
|
|
|
while(!stable) {
|
|
|
|
i++;
|
2001-03-30 01:04:50 +00:00
|
|
|
last_state_value=state_value;
|
2000-10-02 23:07:30 +00:00
|
|
|
fdmex->RunIC(fgic);
|
2001-03-30 01:04:50 +00:00
|
|
|
getState();
|
2000-10-02 23:07:30 +00:00
|
|
|
if(i > 1) {
|
2001-03-30 01:04:50 +00:00
|
|
|
if((fabs(last_state_value - state_value) < tolerance) || (i >= 100) )
|
2000-10-02 23:07:30 +00:00
|
|
|
stable=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
its_to_stable_value=i;
|
|
|
|
total_stability_iterations+=its_to_stable_value;
|
|
|
|
total_iterations++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
void FGTrimAxis::setThrottlesPct(void) {
|
|
|
|
float tMin,tMax;
|
2001-03-30 01:04:50 +00:00
|
|
|
for(unsigned i=0;i<fdmex->GetPropulsion()->GetNumEngines();i++) {
|
|
|
|
tMin=fdmex->GetPropulsion()->GetEngine(i)->GetThrottleMin();
|
|
|
|
tMax=fdmex->GetPropulsion()->GetEngine(i)->GetThrottleMax();
|
2000-10-02 23:07:30 +00:00
|
|
|
//cout << "setThrottlespct: " << i << ", " << control_min << ", " << control_max << ", " << control_value;
|
|
|
|
fdmex -> GetFCS() -> SetThrottleCmd(i,tMin+control_value*(tMax-tMin));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
void FGTrimAxis::AxisReport(void) {
|
|
|
|
|
|
|
|
char out[80];
|
|
|
|
sprintf(out," %20s: %6.2f %5s: %9.2e Tolerance: %3.0e\n",
|
|
|
|
GetControlName().c_str(), GetControl()*control_convert,
|
2001-03-30 01:04:50 +00:00
|
|
|
GetStateName().c_str(), GetState(), GetTolerance());
|
2000-10-02 23:07:30 +00:00
|
|
|
cout << out;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
float FGTrimAxis::GetAvgStability( void ) {
|
|
|
|
if(total_iterations > 0) {
|
|
|
|
return float(total_stability_iterations)/float(total_iterations);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-03-30 01:04:50 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
void FGTrimAxis::Debug(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|