2000-11-03 23:02:47 +00:00
|
|
|
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2004-06-14 11:40:45 +00:00
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
Header: FGTrimAxis.cpp
|
|
|
|
Author: Tony Peden
|
|
|
|
Date started: 7/3/00
|
2004-06-14 11:40:45 +00:00
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
--------- Copyright (C) 1999 Anthony K. Peden (apeden@earthlink.net) ---------
|
2004-06-14 11:40:45 +00:00
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
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.
|
2004-06-14 11:40:45 +00:00
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
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.
|
2004-06-14 11:40:45 +00:00
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
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.
|
2004-06-14 11:40:45 +00:00
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
Further information about the GNU General Public License can also be found on
|
|
|
|
the world wide web at http://www.gnu.org.
|
2004-06-14 11:40:45 +00:00
|
|
|
|
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
HISTORY
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
7/3/00 TP Created
|
2004-06-14 11:40:45 +00:00
|
|
|
|
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
|
|
|
|
2002-04-30 13:42:26 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning (disable : 4786)
|
|
|
|
#endif
|
|
|
|
|
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"
|
2002-09-22 15:31:09 +00:00
|
|
|
#include "FGAerodynamics.h"
|
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
|
2003-01-24 12:55:28 +00:00
|
|
|
namespace JSBSim {
|
|
|
|
|
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;
|
|
|
|
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;
|
2001-11-30 17:49:37 +00:00
|
|
|
state_target=0;
|
|
|
|
switch(state) {
|
2001-11-12 16:06:29 +00:00
|
|
|
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;
|
2001-11-30 17:49:37 +00:00
|
|
|
case tNlf: state_target=1.0; tolerance = 1E-5; break;
|
2001-12-24 13:54:55 +00:00
|
|
|
case tAll: break;
|
2004-06-14 11:40:45 +00:00
|
|
|
}
|
|
|
|
|
2001-11-12 16:06:29 +00:00
|
|
|
solver_eps=tolerance;
|
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:
|
2001-11-12 16:06:29 +00:00
|
|
|
control_min=-30*degtorad;
|
|
|
|
control_max=30*degtorad;
|
|
|
|
control_convert=radtodeg;
|
2000-10-02 23:07:30 +00:00
|
|
|
break;
|
|
|
|
case tAlpha:
|
2002-06-08 03:14:03 +00:00
|
|
|
control_min=fdmex->GetAerodynamics()->GetAlphaCLMin();
|
|
|
|
control_max=fdmex->GetAerodynamics()->GetAlphaCLMax();
|
2000-10-02 23:07:30 +00:00
|
|
|
if(control_max <= control_min) {
|
2001-11-12 16:06:29 +00:00
|
|
|
control_max=20*degtorad;
|
|
|
|
control_min=-5*degtorad;
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
|
|
|
control_value= (control_min+control_max)/2;
|
2001-11-12 16:06:29 +00:00
|
|
|
control_convert=radtodeg;
|
2000-10-02 23:07:30 +00:00
|
|
|
solver_eps=tolerance/100;
|
|
|
|
break;
|
|
|
|
case tPitchTrim:
|
|
|
|
case tElevator:
|
|
|
|
case tRollTrim:
|
|
|
|
case tAileron:
|
|
|
|
case tYawTrim:
|
|
|
|
case tRudder:
|
|
|
|
control_min=-1;
|
|
|
|
control_max=1;
|
2001-11-12 16:06:29 +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;
|
2004-06-14 11:40:45 +00:00
|
|
|
control_value=fdmex->GetPropagate()->GetDistanceAGL();
|
2000-10-02 23:07:30 +00:00
|
|
|
solver_eps=tolerance/100;
|
|
|
|
break;
|
|
|
|
case tTheta:
|
2004-09-11 12:41:05 +00:00
|
|
|
control_min=fdmex->GetPropagate()->GetEuler(eTht) - 5*degtorad;
|
|
|
|
control_max=fdmex->GetPropagate()->GetEuler(eTht) + 5*degtorad;
|
2001-11-12 16:06:29 +00:00
|
|
|
state_convert=radtodeg;
|
2000-10-02 23:07:30 +00:00
|
|
|
break;
|
|
|
|
case tPhi:
|
2004-09-11 12:41:05 +00:00
|
|
|
control_min=fdmex->GetPropagate()->GetEuler(ePhi) - 30*degtorad;
|
|
|
|
control_max=fdmex->GetPropagate()->GetEuler(ePhi) + 30*degtorad;
|
2001-11-12 16:06:29 +00:00
|
|
|
state_convert=radtodeg;
|
|
|
|
control_convert=radtodeg;
|
2000-10-02 23:07:30 +00:00
|
|
|
break;
|
|
|
|
case tGamma:
|
|
|
|
solver_eps=tolerance/100;
|
2001-11-12 16:06:29 +00:00
|
|
|
control_min=-80*degtorad;
|
|
|
|
control_max=80*degtorad;
|
|
|
|
control_convert=radtodeg;
|
2000-10-02 23:07:30 +00:00
|
|
|
break;
|
2001-03-30 01:04:50 +00:00
|
|
|
case tHeading:
|
2004-09-11 12:41:05 +00:00
|
|
|
control_min=fdmex->GetPropagate()->GetEuler(ePsi) - 30*degtorad;
|
|
|
|
control_max=fdmex->GetPropagate()->GetEuler(ePsi) + 30*degtorad;
|
2001-11-12 16:06:29 +00:00
|
|
|
state_convert=radtodeg;
|
2001-03-30 01:04:50 +00:00
|
|
|
break;
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
2004-06-14 11:40:45 +00:00
|
|
|
|
|
|
|
|
2001-12-13 04:48:34 +00:00
|
|
|
Debug(0);
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2001-12-13 04:48:34 +00:00
|
|
|
FGTrimAxis::~FGTrimAxis(void)
|
2001-03-30 01:04:50 +00:00
|
|
|
{
|
2001-12-13 04:48:34 +00:00
|
|
|
Debug(1);
|
2001-03-30 01:04:50 +00:00
|
|
|
}
|
2000-10-02 23:07:30 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2001-03-30 01:04:50 +00:00
|
|
|
void FGTrimAxis::getState(void) {
|
|
|
|
switch(state) {
|
2004-06-14 11:40:45 +00:00
|
|
|
case tUdot: state_value=fdmex->GetPropagate()->GetUVWdot(1)-state_target; break;
|
|
|
|
case tVdot: state_value=fdmex->GetPropagate()->GetUVWdot(2)-state_target; break;
|
|
|
|
case tWdot: state_value=fdmex->GetPropagate()->GetUVWdot(3)-state_target; break;
|
|
|
|
case tQdot: state_value=fdmex->GetPropagate()->GetPQRdot(2)-state_target;break;
|
|
|
|
case tPdot: state_value=fdmex->GetPropagate()->GetPQRdot(1)-state_target; break;
|
|
|
|
case tRdot: state_value=fdmex->GetPropagate()->GetPQRdot(3)-state_target; break;
|
2001-11-30 17:49:37 +00:00
|
|
|
case tHmgt: state_value=computeHmgt()-state_target; break;
|
|
|
|
case tNlf: state_value=fdmex->GetAircraft()->GetNlf()-state_target; break;
|
2001-12-24 13:54:55 +00:00
|
|
|
case tAll: 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;
|
2004-06-14 11:40:45 +00:00
|
|
|
case tBeta: control_value=fdmex->GetAuxiliary()->Getalpha(); break;
|
|
|
|
case tAlpha: control_value=fdmex->GetAuxiliary()->Getbeta(); break;
|
2000-10-02 23:07:30 +00:00
|
|
|
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;
|
2004-06-14 11:40:45 +00:00
|
|
|
case tAltAGL: control_value=fdmex->GetPropagate()->GetDistanceAGL();break;
|
2004-09-11 12:41:05 +00:00
|
|
|
case tTheta: control_value=fdmex->GetPropagate()->GetEuler(eTht); break;
|
|
|
|
case tPhi: control_value=fdmex->GetPropagate()->GetEuler(ePhi); break;
|
2004-06-14 11:40:45 +00:00
|
|
|
case tGamma: control_value=fdmex->GetAuxiliary()->GetGamma();break;
|
2004-09-11 12:41:05 +00:00
|
|
|
case tHeading: control_value=fdmex->GetPropagate()->GetEuler(ePsi); break;
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2001-11-20 22:34:24 +00:00
|
|
|
double FGTrimAxis::computeHmgt(void) {
|
|
|
|
double diff;
|
2004-06-14 11:40:45 +00:00
|
|
|
|
2004-09-11 12:41:05 +00:00
|
|
|
diff = fdmex->GetPropagate()->GetEuler(ePsi) -
|
2004-06-14 11:40:45 +00:00
|
|
|
fdmex->GetAuxiliary()->GetGroundTrack();
|
|
|
|
|
2001-03-30 01:04:50 +00:00
|
|
|
if( diff < -M_PI ) {
|
|
|
|
return (diff + 2*M_PI);
|
|
|
|
} else if( diff > M_PI ) {
|
|
|
|
return (diff - 2*M_PI);
|
|
|
|
} else {
|
|
|
|
return diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2004-06-14 11:40:45 +00:00
|
|
|
|
2001-03-30 01:04:50 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
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
|
|
|
|
2004-06-14 11:40:45 +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
|
2004-06-14 11:40:45 +00:00
|
|
|
// contact the ground so the altitude needs to be changed when pitch
|
|
|
|
// and roll angle are adjusted. Instead of attempting to calculate the
|
2000-10-02 23:07:30 +00:00
|
|
|
// 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 =
|
2004-06-14 11:40:45 +00:00
|
|
|
// earth z component of that vector (which is in body axes )
|
2001-11-20 22:34:24 +00:00
|
|
|
void FGTrimAxis::SetThetaOnGround(double ff) {
|
2000-10-02 23:07:30 +00:00
|
|
|
int center,i,ref;
|
|
|
|
|
|
|
|
// favor an off-center unit so that the same one can be used for both
|
2004-06-14 11:40:45 +00:00
|
|
|
// pitch and roll. An on-center unit is used (for pitch)if that's all
|
2000-10-02 23:07:30 +00:00
|
|
|
// that's in contact with the ground.
|
|
|
|
i=0; ref=-1; center=-1;
|
2001-10-29 19:00:24 +00:00
|
|
|
while( (ref < 0) && (i < fdmex->GetGroundReactions()->GetNumGearUnits()) ) {
|
|
|
|
if(fdmex->GetGroundReactions()->GetGearUnit(i)->GetWOW()) {
|
|
|
|
if(fabs(fdmex->GetGroundReactions()->GetGearUnit(i)->GetBodyLocation(2)) > 0.01)
|
2000-10-02 23:07:30 +00:00
|
|
|
ref=i;
|
|
|
|
else
|
|
|
|
center=i;
|
2004-06-14 11:40:45 +00:00
|
|
|
}
|
|
|
|
i++;
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
|
|
|
if((ref < 0) && (center >= 0)) {
|
|
|
|
ref=center;
|
|
|
|
}
|
|
|
|
cout << "SetThetaOnGround ref gear: " << ref << endl;
|
|
|
|
if(ref >= 0) {
|
2004-09-11 12:41:05 +00:00
|
|
|
double sp = fdmex->GetPropagate()->GetSinEuler(ePhi);
|
|
|
|
double cp = fdmex->GetPropagate()->GetCosEuler(ePhi);
|
2004-06-14 11:40:45 +00:00
|
|
|
double lx = fdmex->GetGroundReactions()->GetGearUnit(ref)->GetBodyLocation(1);
|
|
|
|
double ly = fdmex->GetGroundReactions()->GetGearUnit(ref)->GetBodyLocation(2);
|
|
|
|
double lz = fdmex->GetGroundReactions()->GetGearUnit(ref)->GetBodyLocation(3);
|
2001-11-20 22:34:24 +00:00
|
|
|
double hagl = -1*lx*sin(ff) +
|
2000-10-02 23:07:30 +00:00
|
|
|
ly*sp*cos(ff) +
|
|
|
|
lz*cp*cos(ff);
|
2004-06-14 11:40:45 +00:00
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
fgic->SetAltitudeAGLFtIC(hagl);
|
|
|
|
cout << "SetThetaOnGround new alt: " << hagl << endl;
|
2004-06-14 11:40:45 +00:00
|
|
|
}
|
|
|
|
fgic->SetPitchAngleRadIC(ff);
|
|
|
|
cout << "SetThetaOnGround new theta: " << ff << endl;
|
|
|
|
}
|
2000-10-02 23:07:30 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2000-11-03 23:02:47 +00:00
|
|
|
bool FGTrimAxis::initTheta(void) {
|
2004-06-14 11:40:45 +00:00
|
|
|
int i,N;
|
|
|
|
int iForward = 0;
|
|
|
|
int iAft = 1;
|
|
|
|
double zAft,zForward,zDiff,theta;
|
2004-06-03 17:59:14 +00:00
|
|
|
double xAft,xForward,xDiff;
|
2004-06-14 11:40:45 +00:00
|
|
|
bool level;
|
2001-11-20 22:34:24 +00:00
|
|
|
double saveAlt;
|
2004-06-14 11:40:45 +00:00
|
|
|
|
2000-11-03 23:02:47 +00:00
|
|
|
saveAlt=fgic->GetAltitudeAGLFtIC();
|
|
|
|
fgic->SetAltitudeAGLFtIC(100);
|
2004-06-14 11:40:45 +00:00
|
|
|
|
|
|
|
|
2001-10-29 19:00:24 +00:00
|
|
|
N=fdmex->GetGroundReactions()->GetNumGearUnits();
|
2004-06-14 11:40:45 +00:00
|
|
|
|
2000-11-03 23:02:47 +00:00
|
|
|
//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-10-29 19:00:24 +00:00
|
|
|
if(fdmex->GetGroundReactions()->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-10-29 19:00:24 +00:00
|
|
|
if(fdmex->GetGroundReactions()->GetGearUnit(i)->GetBodyLocation(1) < 0 ) {
|
2000-11-03 23:02:47 +00:00
|
|
|
iAft=i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-06-03 17:59:14 +00:00
|
|
|
|
2004-06-14 11:40:45 +00:00
|
|
|
// now adjust theta till the wheels are the same distance from the ground
|
|
|
|
xAft=fdmex->GetGroundReactions()->GetGearUnit(iAft)->GetBodyLocation(1);
|
|
|
|
xForward=fdmex->GetGroundReactions()->GetGearUnit(iForward)->GetBodyLocation(1);
|
|
|
|
xDiff = xForward - xAft;
|
|
|
|
zAft=fdmex->GetGroundReactions()->GetGearUnit(iAft)->GetLocalGear(3);
|
|
|
|
zForward=fdmex->GetGroundReactions()->GetGearUnit(iForward)->GetLocalGear(3);
|
|
|
|
zDiff = zForward - zAft;
|
|
|
|
level=false;
|
|
|
|
theta=fgic->GetPitchAngleDegIC();
|
|
|
|
while(!level && (i < 100)) {
|
|
|
|
theta+=radtodeg*atan(zDiff/xDiff);
|
|
|
|
fgic->SetPitchAngleDegIC(theta);
|
|
|
|
fdmex->RunIC();
|
|
|
|
zAft=fdmex->GetGroundReactions()->GetGearUnit(iAft)->GetLocalGear(3);
|
|
|
|
zForward=fdmex->GetGroundReactions()->GetGearUnit(iForward)->GetLocalGear(3);
|
2003-07-17 02:32:39 +00:00
|
|
|
zDiff = zForward - zAft;
|
2004-06-14 11:40:45 +00:00
|
|
|
//cout << endl << theta << " " << zDiff << endl;
|
|
|
|
//cout << "0: " << fdmex->GetGroundReactions()->GetGearUnit(0)->GetLocalGear() << endl;
|
|
|
|
//cout << "1: " << fdmex->GetGroundReactions()->GetGearUnit(1)->GetLocalGear() << endl;
|
|
|
|
if(fabs(zDiff ) < 0.1)
|
|
|
|
level=true;
|
|
|
|
i++;
|
|
|
|
}
|
2000-11-03 23:02:47 +00:00
|
|
|
//cout << i << endl;
|
2003-11-24 17:59:41 +00:00
|
|
|
if (debug_lvl > 0) {
|
2004-09-11 12:41:05 +00:00
|
|
|
cout << " Initial Theta: " << fdmex->GetPropagate()->GetEuler(eTht)*radtodeg << endl;
|
2003-11-24 17:59:41 +00:00
|
|
|
cout << " Used gear unit " << iAft << " as aft and " << iForward << " as forward" << endl;
|
|
|
|
}
|
2001-11-12 16:06:29 +00:00
|
|
|
control_min=(theta+5)*degtorad;
|
|
|
|
control_max=(theta-5)*degtorad;
|
2000-11-03 23:02:47 +00:00
|
|
|
fgic->SetAltitudeAGLFtIC(saveAlt);
|
2004-06-14 11:40:45 +00:00
|
|
|
if(i < 100)
|
2000-11-03 23:02:47 +00:00
|
|
|
return true;
|
|
|
|
else
|
2004-06-14 11:40:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2000-11-03 23:02:47 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2001-11-20 22:34:24 +00:00
|
|
|
void FGTrimAxis::SetPhiOnGround(double ff) {
|
2000-10-02 23:07:30 +00:00
|
|
|
int i,ref;
|
|
|
|
|
|
|
|
i=0; ref=-1;
|
2004-06-14 11:40:45 +00:00
|
|
|
//must have an off-center unit here
|
|
|
|
while ( (ref < 0) && (i < fdmex->GetGroundReactions()->GetNumGearUnits()) ) {
|
|
|
|
if ( (fdmex->GetGroundReactions()->GetGearUnit(i)->GetWOW()) &&
|
2001-10-29 19:00:24 +00:00
|
|
|
(fabs(fdmex->GetGroundReactions()->GetGearUnit(i)->GetBodyLocation(2)) > 0.01))
|
2000-10-02 23:07:30 +00:00
|
|
|
ref=i;
|
2004-06-14 11:40:45 +00:00
|
|
|
i++;
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
2004-06-14 11:40:45 +00:00
|
|
|
if (ref >= 0) {
|
2004-09-11 12:41:05 +00:00
|
|
|
double st = fdmex->GetPropagate()->GetSinEuler(eTht);
|
|
|
|
double ct = fdmex->GetPropagate()->GetCosEuler(eTht);
|
2004-06-14 11:40:45 +00:00
|
|
|
double lx = fdmex->GetGroundReactions()->GetGearUnit(ref)->GetBodyLocation(1);
|
|
|
|
double ly = fdmex->GetGroundReactions()->GetGearUnit(ref)->GetBodyLocation(2);
|
|
|
|
double lz = fdmex->GetGroundReactions()->GetGearUnit(ref)->GetBodyLocation(3);
|
2001-11-20 22:34:24 +00:00
|
|
|
double hagl = -1*lx*st +
|
2000-10-02 23:07:30 +00:00
|
|
|
ly*sin(ff)*ct +
|
|
|
|
lz*cos(ff)*ct;
|
2004-06-14 11:40:45 +00:00
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
fgic->SetAltitudeAGLFtIC(hagl);
|
2004-06-14 11:40:45 +00:00
|
|
|
}
|
2000-10-02 23:07:30 +00:00
|
|
|
fgic->SetRollAngleRadIC(ff);
|
2002-06-08 03:14:03 +00:00
|
|
|
|
2004-06-14 11:40:45 +00:00
|
|
|
}
|
2000-10-02 23:07:30 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
void FGTrimAxis::Run(void) {
|
|
|
|
|
2001-11-20 22:34:24 +00:00
|
|
|
double 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;
|
2002-09-22 15:31:09 +00:00
|
|
|
fdmex->RunIC();
|
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) {
|
2001-11-20 22:34:24 +00:00
|
|
|
double 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;
|
2001-11-06 22:33:05 +00:00
|
|
|
fdmex->GetFCS()->SetThrottleCmd(i,tMin+control_value*(tMax-tMin));
|
|
|
|
//cout << "setThrottlespct: " << fdmex->GetFCS()->GetThrottleCmd(i) << endl;
|
2002-09-22 15:31:09 +00:00
|
|
|
fdmex->RunIC(); //apply throttle change
|
2001-11-06 22:33:05 +00:00
|
|
|
fdmex->GetPropulsion()->GetSteadyState();
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
void FGTrimAxis::AxisReport(void) {
|
2004-06-14 11:40:45 +00:00
|
|
|
|
2000-10-02 23:07:30 +00:00
|
|
|
char out[80];
|
2004-09-11 12:41:05 +00:00
|
|
|
|
|
|
|
sprintf(out," %20s: %6.2f %5s: %9.2e Tolerance: %3.0e",
|
2000-10-02 23:07:30 +00:00
|
|
|
GetControlName().c_str(), GetControl()*control_convert,
|
2004-06-14 11:40:45 +00:00
|
|
|
GetStateName().c_str(), GetState()+state_target, GetTolerance());
|
2000-10-02 23:07:30 +00:00
|
|
|
cout << out;
|
|
|
|
|
2004-09-15 12:19:46 +00:00
|
|
|
if( fabs(GetState()+state_target) < fabs(GetTolerance()) )
|
2004-09-11 12:41:05 +00:00
|
|
|
cout << " Passed" << endl;
|
|
|
|
else
|
|
|
|
cout << " Failed" << endl;
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2001-11-20 22:34:24 +00:00
|
|
|
double FGTrimAxis::GetAvgStability( void ) {
|
2000-10-02 23:07:30 +00:00
|
|
|
if(total_iterations > 0) {
|
2001-11-20 22:34:24 +00:00
|
|
|
return double(total_stability_iterations)/double(total_iterations);
|
2000-10-02 23:07:30 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-03-30 01:04:50 +00:00
|
|
|
/*****************************************************************************/
|
2001-12-13 04:48:34 +00:00
|
|
|
// The bitmasked value choices are as follows:
|
|
|
|
// unset: In this case (the default) JSBSim would only print
|
|
|
|
// out the normally expected messages, essentially echoing
|
|
|
|
// the config files as they are read. If the environment
|
|
|
|
// variable is not set, debug_lvl is set to 1 internally
|
|
|
|
// 0: This requests JSBSim not to output any messages
|
|
|
|
// whatsoever.
|
|
|
|
// 1: This value explicity requests the normal JSBSim
|
|
|
|
// startup messages
|
|
|
|
// 2: This value asks for a message to be printed out when
|
|
|
|
// a class is instantiated
|
|
|
|
// 4: When this value is set, a message is displayed when a
|
|
|
|
// FGModel object executes its Run() method
|
|
|
|
// 8: When this value is set, various runtime state variables
|
|
|
|
// are printed out periodically
|
|
|
|
// 16: When set various parameters are sanity checked and
|
|
|
|
// a message is printed out when they go out of bounds
|
|
|
|
|
|
|
|
void FGTrimAxis::Debug(int from)
|
2001-03-30 01:04:50 +00:00
|
|
|
{
|
2001-12-13 04:48:34 +00:00
|
|
|
|
2001-12-24 13:54:55 +00:00
|
|
|
if (debug_lvl <= 0) return;
|
|
|
|
if (debug_lvl & 1 ) { // Standard console startup message output
|
2001-12-13 04:48:34 +00:00
|
|
|
if (from == 0) { // Constructor
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (debug_lvl & 2 ) { // Instantiation/Destruction notification
|
|
|
|
if (from == 0) cout << "Instantiated: FGTrimAxis" << endl;
|
|
|
|
if (from == 1) cout << "Destroyed: FGTrimAxis" << endl;
|
|
|
|
}
|
|
|
|
if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
|
|
|
|
}
|
|
|
|
if (debug_lvl & 8 ) { // Runtime state variables
|
|
|
|
}
|
|
|
|
if (debug_lvl & 16) { // Sanity checking
|
|
|
|
}
|
2001-12-24 13:54:55 +00:00
|
|
|
if (debug_lvl & 64) {
|
|
|
|
if (from == 0) { // Constructor
|
|
|
|
cout << IdSrc << endl;
|
|
|
|
cout << IdHdr << endl;
|
|
|
|
}
|
|
|
|
}
|
2001-03-30 01:04:50 +00:00
|
|
|
}
|
2003-01-24 12:55:28 +00:00
|
|
|
}
|