JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGTrimAnalysis Class Reference
+ Inheritance diagram for FGTrimAnalysis:
+ Collaboration diagram for FGTrimAnalysis:

Public Member Functions

 FGTrimAnalysis (FGFDMExec *FDMExec, TrimAnalysisMode tam=taFull)
 Initializes the trimming class. More...
 
 ~FGTrimAnalysis (void)
 Destructor.
 
bool AddControl (TaControl control)
 Add a control to the current configuration. More...
 
void CalculatePhiWFromTargetNlfTurn (double nlf)
 Calculate the wind axis bank angle from a given Nlf (sets also the target Nlf) More...
 
void ClearControls (void)
 Clear all controls from the current configuration. More...
 
void ClearDebug (void)
 
bool DoTrim (void)
 Execute the trim.
 
bool EditState (TaControl new_control, double new_initvalue, double new_step, double new_min, double new_max)
 Change the control settings previously configured. More...
 
vector< FGTrimAnalysisControl * > * GetControls ()
 
double GetCostFunctionValue () const
 
double GetGamma ()
 Return the current flight path angle in TrimAnalysis object. More...
 
bool GetGammaFallback (void)
 query the fallback state More...
 
double GetGammaRad ()
 Gets flight path angle. More...
 
TrimAnalysisMode GetMode () const
 
double GetPhiRad ()
 Gets Euler angle phi. More...
 
double GetPhiWRad ()
 Gets Euler angle phiW (wind axes) More...
 
double GetPsiRad ()
 Gets Euler angle psi. More...
 
ofstream * GetResultsFile () const
 Get the pointer to the file where trim analysis results are written,. More...
 
double GetTargetNlf (void)
 Gets target normal load factor in steady turn. More...
 
double GetThetaRad ()
 Gets Euler angle theta. More...
 
double GetTolerance (void)
 Get the tolerance for declaring a state trimmed. More...
 
bool GetTrimFailed (void)
 Gets trim result status. More...
 
double GetVtFps ()
 Gets true speed [fps] from IC. More...
 
bool Load (string fname, bool useStoredPath=true)
 Loads the trim configuration from file. More...
 
bool RemoveControl (TaControl control)
 Remove a specific control from the current configuration. More...
 
void Report (void)
 Print the results of the trim. More...
 
void SetCostFunctionValue (double value)
 Set the value of the cost function. More...
 
void SetDebug (int level)
 Debug level 1 shows results of each top-level iteration Debug level 2 shows level 1 & results of each per-axis iteration.
 
void SetDottedValues (double udot, double vdot, double wdot, double pdot, double qdot, double rdot)
 Sets Dotted values. More...
 
void SetEulerAngles (double phi0, double theta0, double psi0)
 Sets Euler angles. More...
 
void SetGammaFallback (bool bb)
 automatically switch to trimming longitudinal acceleration with flight path angle (gamma) once it becomes apparent that there is not enough/too much thrust. More...
 
void SetMaxCycles (int ii)
 Set the iteration limit. More...
 
void SetMode (TrimAnalysisMode tam)
 Clear all controls and set a predefined trim mode (Note: controls are intended here as those variables to be adjusted for attaining convergence of the trimming algorithm) More...
 
bool SetResultsFile (string name)
 Set the file where trim analysis results are written, open and get ready. More...
 
void SetState (double u0, double v0, double w0, double p0, double q0, double r0, double alpha0, double beta0, double phi0, double theta0, double psi0, double gamma0)
 Sets state variables. More...
 
void SetTargetNlf (double nlf)
 Sets target normal load factor in steady turn. More...
 
void SetTolerance (double tt)
 Set the tolerance for declaring a state trimmed. More...
 
void SetTrimFailed (bool tf)
 Sets trim result status. More...
 
void SetTrimSuccessfull ()
 
void TrimStats ()
 Iteration statistics.
 
FGColumnVector3 UpdateRatesPullup (void)
 Updates angular rates for pull-up trim. More...
 
FGColumnVector3 UpdateRatesTurn (double psi, double theta, double phi, double phiW)
 Updates angular rates for turn trim according to turning trim constraints. More...
 
- Public Member Functions inherited from FGJSBBase
 FGJSBBase ()
 Constructor for FGJSBBase.
 
virtual ~FGJSBBase ()
 Destructor for FGJSBBase.
 
void disableHighLighting (void)
 Disables highlighting in the console output.
 
std::string GetVersion (void)
 Returns the version number of JSBSim. More...
 
void PutMessage (const Message &msg)
 Places a Message structure on the Message queue. More...
 
void PutMessage (const std::string &text)
 Creates a message with the given text and places it on the queue. More...
 
void PutMessage (const std::string &text, bool bVal)
 Creates a message with the given text and boolean value and places it on the queue. More...
 
void PutMessage (const std::string &text, int iVal)
 Creates a message with the given text and integer value and places it on the queue. More...
 
void PutMessage (const std::string &text, double dVal)
 Creates a message with the given text and double value and places it on the queue. More...
 
int SomeMessages (void)
 Reads the message on the queue (but does not delete it). More...
 
void ProcessMessage (void)
 Reads the message on the queue and removes it from the queue. More...
 
MessageProcessNextMessage (void)
 Reads the next message on the queue and removes it from the queue. More...
 
- Public Member Functions inherited from FGXMLFileRead
ElementLoadXMLDocument (const SGPath &XML_filename, bool verbose=true)
 
ElementLoadXMLDocument (const SGPath &XML_filename, FGXMLParse &fparse, bool verbose=true)
 
void ResetParser (void)
 

Friends

class Objective
 

Additional Inherited Members

- Public Types inherited from FGJSBBase
enum  { eL = 1, eM, eN }
 Moments L, M, N.
 
enum  { eP = 1, eQ, eR }
 Rates P, Q, R.
 
enum  { eU = 1, eV, eW }
 Velocities U, V, W.
 
enum  { eX = 1, eY, eZ }
 Positions X, Y, Z.
 
enum  { ePhi = 1, eTht, ePsi }
 Euler angles Phi, Theta, Psi.
 
enum  { eDrag = 1, eSide, eLift }
 Stability axis forces, Drag, Side force, Lift.
 
enum  { eRoll = 1, ePitch, eYaw }
 Local frame orientation Roll, Pitch, Yaw.
 
enum  { eNorth = 1, eEast, eDown }
 Local frame position North, East, Down.
 
enum  { eLat = 1, eLong, eRad }
 Locations Radius, Latitude, Longitude.
 
enum  {
  inNone = 0, inDegrees, inRadians, inMeters,
  inFeet
}
 Conversion specifiers.
 
- Static Public Member Functions inherited from FGJSBBase
static double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit. More...
 
static double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin. More...
 
static double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine. More...
 
static double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
static bool EqualToRoundoff (double a, double b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (float a, float b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (float a, double b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (double a, float b)
 Finite precision comparison. More...
 
static double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius. More...
 
static double FeetToMeters (double measure)
 Converts from feet to meters. More...
 
static double GaussianRandomNumber (void)
 
static double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius. More...
 
static double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit. More...
 
static double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine. More...
 
static double MachFromVcalibrated (double vcas, double p, double psl, double rhosl)
 Calculate the Mach number from the calibrated airspeed. More...
 
static double PitotTotalPressure (double mach, double p)
 Compute the total pressure in front of the Pitot tube. More...
 
static double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius. More...
 
static double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin. More...
 
static double sign (double num)
 
static double VcalibratedFromMach (double mach, double p, double psl, double rhosl)
 Calculate the calibrated airspeed from the Mach number. More...
 
- Static Public Attributes inherited from FGJSBBase
static short debug_lvl = 1
 
static char highint [5] = {27, '[', '1', 'm', '\0' }
 highlights text
 
static char halfint [5] = {27, '[', '2', 'm', '\0' }
 low intensity text
 
static char normint [6] = {27, '[', '2', '2', 'm', '\0' }
 normal intensity text
 
static char reset [5] = {27, '[', '0', 'm', '\0' }
 resets text properties
 
static char underon [5] = {27, '[', '4', 'm', '\0' }
 underlines text
 
static char underoff [6] = {27, '[', '2', '4', 'm', '\0' }
 underline off
 
static char fgblue [6] = {27, '[', '3', '4', 'm', '\0' }
 blue text
 
static char fgcyan [6] = {27, '[', '3', '6', 'm', '\0' }
 cyan text
 
static char fgred [6] = {27, '[', '3', '1', 'm', '\0' }
 red text
 
static char fggreen [6] = {27, '[', '3', '2', 'm', '\0' }
 green text
 
static char fgdef [6] = {27, '[', '3', '9', 'm', '\0' }
 default text
 
- Protected Member Functions inherited from FGJSBBase
void Debug (int)
 
- Static Protected Member Functions inherited from FGJSBBase
static std::string CreateIndexedPropertyName (const std::string &Property, int index)
 
- Static Protected Attributes inherited from FGJSBBase
static const double degtorad = 0.017453292519943295769236907684886
 
static const double fpstokts = 1.0/ktstofps
 
static const double fttom = 0.3048
 
static int gaussian_random_number_phase = 0
 
static const double hptoftlbssec = 550.0
 
static const double in3tom3 = 1.638706E-5
 
static const double inchtoft = 0.08333333
 
static const double inhgtopa = 3386.38
 
static const std::string JSBSim_version = "1.0 " __DATE__ " " __TIME__
 
static const double kgtolb = 2.20462
 
static const double kgtoslug = 0.06852168
 
static const double ktstofps = 1.68781
 
static const double lbtoslug = 1.0/slugtolb
 
static Message localMsg
 
static const double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static double Mair = 28.9645
 
static unsigned int messageId = 0
 
static std::queue< MessageMessages
 
static const std::string needed_cfg_version = "2.0"
 
static const double psftoinhg = 0.014138
 
static const double psftopa = 47.88
 
static const double radtodeg = 57.295779513082320876798154814105
 
static double Reng = 1716.56
 
static double Rstar = 1545.348
 
static const double SHRatio = 1.40
 
static const double slugtolb = 32.174049
 

Detailed Description

Definition at line 330 of file FGTrimAnalysis.h.

Constructor & Destructor Documentation

◆ FGTrimAnalysis()

FGTrimAnalysis ( FGFDMExec FDMExec,
TrimAnalysisMode  tam = taFull 
)

Initializes the trimming class.

Parameters
FDMExecpointer to a JSBSim executive object.
tamtrim mode

Definition at line 320 of file FGTrimAnalysis.cpp.

321 {
322  SetDebug(2);
323 
324  N=0;
325 
326  trim_failed = true;
327 
328  max_iterations=2500;
329  stop_criterion="Stop-On-Delta";
330 
331  Debug=0;DebugLevel=0;
332 
333  fdmex=FDMExec;
334 
335  fgic=fdmex->GetIC();
336  total_its=0;
337  trimudot=true;
338  gamma_fallback=true;
339  ctrl_count=0;
340  mode=tt;
341  _targetNlf=1.0;
342  _targetNlf=fgic->GetTargetNlfIC();
343 
344  _vtIC = fgic->GetVtrueFpsIC();
345  _hIC = fgic->GetAltitudeFtIC();
346  _gamma = fgic->GetFlightPathAngleRadIC();
347  _rocIC = _vtIC*cos(_gamma);
348  _vdownIC = _rocIC;
349 
350  // state variables
351  _u = fgic->GetUBodyFpsIC();
352  _v = fgic->GetVBodyFpsIC();
353  _w = fgic->GetWBodyFpsIC();
354  _p = fgic->GetPRadpsIC();
355  _q = fgic->GetQRadpsIC();
356  _r = fgic->GetRRadpsIC();
357  _alpha = fgic->GetAlphaRadIC();
358  _beta = fgic->GetBetaRadIC();
359  _theta = fgic->GetThetaRadIC();
360  _phi = fgic->GetPhiRadIC();
361  _psiIC = fgic->GetPsiRadIC();
362  _psi = _psiIC;
363  _psigtIC = _psi;
364 
365  _phiW = _psiW = 0.0;
366 
367  _vgIC = _vtIC*cos(_gamma);
368  _vnorthIC = _vgIC * cos(_psigtIC);
369  _veastIC = _vgIC * sin(_psigtIC);
370  wnorthIC = _weastIC = _wdownIC = 0.;
371 
372  _udot=_vdot=_wdot=_pdot=_qdot=_rdot=0.;
373  _psidot=_thetadot=0.;
374  _psiWdot = _phiWdot = _gammadot = 0.;
375 
376  C1 = C2 = C3 = 1.0;
377  _cbeta = cos(_beta);
378  _sbeta = sin(_beta);
379  _sphi = sin(_phi);
380 
381  SetMode(tt); // creates vTrimAnalysisControls
382  fdmex->SetTrimMode( (int)tt );
383 
384  trim_id = "default-trim";
385 
386  // direct search stuff
387  search_type = "Nelder-Mead";
388  sigma_nm = 0.5; alpha_nm = 1.0; beta_nm = 0.5; gamma_nm = 2.0;
389  initial_step = 0.01;
390  tolerance = 1.0E-10; // 0.0000000001
391  cost_function_value = 9999.0;
392 
393  rf_name = "";
394  if (rf.is_open()) rf.close();
395 
396  Auxiliary = fdmex->GetAuxiliary();
397  Aerodynamics = fdmex->GetAerodynamics();
398  Propulsion = fdmex->GetPropulsion();
399  FCS = fdmex->GetFCS();
400 }
FGInitialCondition * GetIC(void)
Returns a pointer to the FGInitialCondition object.
Definition: FGFDMExec.h:385
double GetBetaRadIC(void) const
Gets the initial angle of sideslip.
double GetVtrueFpsIC(void) const
Gets the initial true velocity.
double GetFlightPathAngleRadIC(void) const
Gets the initial flight path angle.
void SetDebug(int level)
Debug level 1 shows results of each top-level iteration Debug level 2 shows level 1 & results of each...
void SetMode(TrimAnalysisMode tam)
Clear all controls and set a predefined trim mode (Note: controls are intended here as those variable...
double GetRRadpsIC() const
Gets the initial body axis yaw rate.
double GetPhiRadIC(void) const
Gets the initial roll angle.
double GetUBodyFpsIC(void) const
Gets the initial body axis X velocity.
FGAuxiliary * GetAuxiliary(void)
Returns the FGAuxiliary pointer.
Definition: FGFDMExec.h:371
double GetQRadpsIC() const
Gets the initial body axis pitch rate.
double GetVBodyFpsIC(void) const
Gets the initial body axis Y velocity.
double GetPRadpsIC() const
Gets the initial body axis roll rate.
double GetTargetNlfIC(void) const
Gets the target normal load factor set from IC.
double GetPsiRadIC(void) const
Gets the initial heading angle.
FGFCS * GetFCS(void)
Returns the FGFCS pointer.
Definition: FGFDMExec.h:351
double GetAlphaRadIC(void) const
Gets the initial angle of attack.
FGAerodynamics * GetAerodynamics(void)
Returns the FGAerodynamics pointer.
Definition: FGFDMExec.h:357
FGPropulsion * GetPropulsion(void)
Returns the FGPropulsion pointer.
Definition: FGFDMExec.h:353
double GetThetaRadIC(void) const
Gets the initial pitch angle.
double GetWBodyFpsIC(void) const
Gets the initial body axis Z velocity.
+ Here is the call graph for this function:

Member Function Documentation

◆ AddControl()

bool AddControl ( TaControl  control)

Add a control to the current configuration.

See the enums TaControl in FGTrimAnalysisControl.h for the available options. (Note: controls are intended here as those variables to be adjusted for attaining convergence of the trimming algorithm) Will fail if the given state is already configured.

Parameters
controlthe control to be adjusted in the trimming algorithm
Returns
true if add is successful

Definition at line 673 of file FGTrimAnalysis.cpp.

673  {
674 
675  FGTrimAnalysisControl* tac;
676  bool result=true;
677 
678  mode = taCustom;
679  vector <FGTrimAnalysisControl*>::iterator iControls = vTrimAnalysisControls.begin();
680  while (iControls != vTrimAnalysisControls.end()) {
681  tac=*iControls;
682  if( tac->GetControlType() == control )
683  result=false;
684  iControls++;
685  }
686  if(result) {
687  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,control));
688  }
689  return result;
690 }
+ Here is the call graph for this function:

◆ CalculatePhiWFromTargetNlfTurn()

void CalculatePhiWFromTargetNlfTurn ( double  nlf)

Calculate the wind axis bank angle from a given Nlf (sets also the target Nlf)

Parameters
nlf

Definition at line 752 of file FGTrimAnalysis.cpp.

752  {
753  if ( ( mode == taTurn ) || ( mode == taTurnFull ) ) {
754  // target Nlf is given
755  // set _phiW according to given Nlf
756  _targetNlf = nlf;
757  _phiW = atan2( sqrt(_targetNlf*_targetNlf-cos(_gamma)*cos(_gamma)), cos(_gamma) );
758  }
759 }

◆ ClearControls()

void ClearControls ( void  )

Clear all controls from the current configuration.

The trimming routine must have at least one control configured to be useful (Note: controls are intended here as those variables to be adjusted for attaining convergence of the trimming algorithm)

Definition at line 653 of file FGTrimAnalysis.cpp.

653  {
654 
655  FGTrimAnalysisControl* tac;
656 
657  mode=taCustom;
658  vector<FGTrimAnalysisControl*>::iterator iControls;
659  iControls = vTrimAnalysisControls.begin();
660  while (iControls != vTrimAnalysisControls.end()) {
661  tac=*iControls;
662  delete tac;
663 
664  iControls++;
665  }
666 
667  vTrimAnalysisControls.clear();
668 
669 }

◆ EditState()

bool EditState ( TaControl  new_control,
double  new_initvalue,
double  new_step,
double  new_min,
double  new_max 
)

Change the control settings previously configured.

Parameters
new_controlthe control used to zero the state
new_initvaluea new initial value
new_stepa new adjusting step
new_min,new_maxa new range
Returns
true if editing is successful

Definition at line 717 of file FGTrimAnalysis.cpp.

717  {
718  FGTrimAnalysisControl* tac;
719  bool result=false;
720 
721  mode = taCustom;
722  vector <FGTrimAnalysisControl*>::iterator iControls = vTrimAnalysisControls.begin();
723  while (iControls != vTrimAnalysisControls.end()) {
724  tac=*iControls;
725  if( tac->GetControlType() == new_control ) {
726  vTrimAnalysisControls.insert(iControls,1,new FGTrimAnalysisControl(fdmex,fgic,new_control));
727  delete tac;
728  vTrimAnalysisControls.erase(iControls+1);
729  result=true;
730  break;
731  }
732  iControls++;
733  }
734  return result;
735 }
+ Here is the call graph for this function:

◆ GetCostFunctionValue()

double GetCostFunctionValue ( ) const
inline
Returns
The current cost function value

Definition at line 482 of file FGTrimAnalysis.h.

482 { return cost_function_value;}

◆ GetGamma()

double GetGamma ( void  )
inline

Return the current flight path angle in TrimAnalysis object.

Returns
value of gamma

Definition at line 536 of file FGTrimAnalysis.h.

536 { return _gamma; }
+ Here is the caller graph for this function:

◆ GetGammaFallback()

bool GetGammaFallback ( void  )
inline

query the fallback state

Returns
true if fallback is enabled.

Definition at line 548 of file FGTrimAnalysis.h.

548 { return gamma_fallback; }

◆ GetGammaRad()

double GetGammaRad ( )
inline

Gets flight path angle.

Returns
gamma [rad]

Definition at line 623 of file FGTrimAnalysis.h.

623 { return _gamma;}
+ Here is the caller graph for this function:

◆ GetMode()

TrimAnalysisMode GetMode ( ) const
inline
Returns
The Trim Analysis mode taLongitudinal, taFull, taGround, taCustom, or taNone

Definition at line 495 of file FGTrimAnalysis.h.

495 { return mode;};
+ Here is the caller graph for this function:

◆ GetPhiRad()

double GetPhiRad ( )
inline

Gets Euler angle phi.

Returns
phi [rad]

Definition at line 606 of file FGTrimAnalysis.h.

606 { return _phi;}
+ Here is the caller graph for this function:

◆ GetPhiWRad()

double GetPhiWRad ( )
inline

Gets Euler angle phiW (wind axes)

Returns
phiW [rad]

Definition at line 619 of file FGTrimAnalysis.h.

619 { return _phiW;}
+ Here is the caller graph for this function:

◆ GetPsiRad()

double GetPsiRad ( )
inline

Gets Euler angle psi.

Returns
phi [rad]

Definition at line 614 of file FGTrimAnalysis.h.

614 { return _psi;}

◆ GetResultsFile()

ofstream* GetResultsFile ( ) const
inline

Get the pointer to the file where trim analysis results are written,.

Returns
non null pointer if file is open

Definition at line 473 of file FGTrimAnalysis.h.

473 { if (rf.is_open()) return &rf; else return 0; } // const_cast<ofstream*>(&rf) (if rf is not mutable)
+ Here is the caller graph for this function:

◆ GetTargetNlf()

double GetTargetNlf ( void  )
inline

Gets target normal load factor in steady turn.

Returns
_targetNlf

Definition at line 663 of file FGTrimAnalysis.h.

663 { return _targetNlf; }
+ Here is the caller graph for this function:

◆ GetThetaRad()

double GetThetaRad ( )
inline

Gets Euler angle theta.

Returns
phi [rad]

Definition at line 610 of file FGTrimAnalysis.h.

610 { return _theta;}

◆ GetTolerance()

double GetTolerance ( void  )
inline

Get the tolerance for declaring a state trimmed.

Returns
tolerance.

Definition at line 569 of file FGTrimAnalysis.h.

569 {return tolerance; }

◆ GetTrimFailed()

bool GetTrimFailed ( void  )
inline

Gets trim result status.

Returns
trim_failed (boolean)

Definition at line 578 of file FGTrimAnalysis.h.

578 { return trim_failed; }

◆ GetVtFps()

double GetVtFps ( )
inline

Gets true speed [fps] from IC.

Returns
Vt [fps]

Definition at line 627 of file FGTrimAnalysis.h.

627 { return _vtIC;}
+ Here is the caller graph for this function:

◆ Load()

bool Load ( string  fname,
bool  useStoredPath = true 
)

Loads the trim configuration from file.

Parameters
fnameThe name of a trim configuration file
useStoredPathtrue if the stored path to the trim config file should be used
Returns
true if successful

Definition at line 450 of file FGTrimAnalysis.cpp.

451 {
452  string name="", type="";
453  string trimDef;
454  Element *element=0, *trimCfg=0, *search_element=0, *output_element=0;
455 
456  string sep = "/";
457 # ifdef macintosh
458  sep = ";";
459 # endif
460 
461  if( useStoredPath ) {
462  trimDef = fdmex->GetFullAircraftPath() + sep + fname + ".xml";
463  } else {
464  trimDef = fname;
465  }
466 
467  document = this->LoadXMLDocument(trimDef);
468 
469  trimCfg = document->FindElement("trim_config");
470  if (!trimCfg) {
471  cerr << "File: " << trimDef << " does not contain a trim configuration tag" << endl;
472  return false;
473  }
474 
475  name = trimCfg->GetAttributeValue("name");
476  trim_id = name;
477 
478  // First, find "search" element that specifies the type of cost function minimum search
479 
480  search_element = trimCfg->FindElement("search");
481  if (!search_element) {
482  cerr << "Using the Nelder-Mead search algorithm (default)." << endl;
483  } else {
484  type = search_element->GetAttributeValue("type");
485  if (type.size() > 0) search_type = type; // if search type is not set, default is already Nelder-Mead
486  if (search_type == "Nelder-Mead") {
487  // Read settings from search
488  // Note: all of these have defaults set above
489  if ( search_element->FindElement("sigma_nm") )
490  sigma_nm = search_element->FindElementValueAsNumber("sigma_nm");
491  if ( search_element->FindElement("alpha_nm") )
492  alpha_nm = search_element->FindElementValueAsNumber("alpha_nm");
493  if ( search_element->FindElement("beta_nm") )
494  beta_nm = search_element->FindElementValueAsNumber("beta_nm");
495  if ( search_element->FindElement("gamma_nm") )
496  gamma_nm = search_element->FindElementValueAsNumber("gamma_nm");
497  }
498  // ToDo: manage all the other possible choices here
499  // if (search_type == "Sequential-Multiple-Nelder-Mead") { }
500  // if (search_type == "Multicompass") { }
501  // etc ...
502  if ( search_element->FindElement("tolerance") ) {
503  tolerance = search_element->FindElement("tolerance")->GetAttributeValueAsNumber("value");
504  }
505  if ( search_element->FindElement("max_iterations") ) {
506  max_iterations = (unsigned int)search_element->FindElement("max_iterations")->GetAttributeValueAsNumber("value");
507  }
508  if ( search_element->FindElement("stop_criterion") ) {
509  stop_criterion = search_element->FindElement("stop_criterion")->GetAttributeValue("type");
510  }
511  }
512 
513  // Initialize trim controls based on what is in the trim config file. This
514  // includes initial trim values (or defaults from the IC file) and step
515  // size values.
516 
517  element = trimCfg->FindElement("phi");
518  InitializeTrimControl(fgic->GetPhiRadIC(), element, "RAD", JSBSim::taPhi);
519  if ( ( fabs(_phi) < 89.5*(FGJSBBase::degtorad ) ) && ( mode == taTurn ))
520  _targetNlf = 1./cos(_phi);
521 
522  element = trimCfg->FindElement("theta");
523  InitializeTrimControl(fgic->GetThetaRadIC(), element, "RAD", JSBSim::taTheta);
524 
525  element = trimCfg->FindElement("psi");
526  InitializeTrimControl(fgic->GetPsiRadIC(), element, "RAD", JSBSim::taHeading);
527 
528  element = trimCfg->FindElement("gamma");
529  _gamma = fgic->GetFlightPathAngleRadIC();
530  if (element)
531  if (element->GetNumDataLines() > 0) _gamma = element->GetDataAsNumber();
532 
533  element = trimCfg->FindElement("nlf");
534  if (element) {
535  if (element->GetNumDataLines() > 0) _targetNlf = element->GetDataAsNumber();
536  CalculatePhiWFromTargetNlfTurn(_targetNlf);
537  }
538 
539  element = trimCfg->FindElement("throttle_cmd");
540  if (element) InitializeTrimControl(0, element, "", JSBSim::taThrottle);
541 
542  element = trimCfg->FindElement("elevator_cmd");
543  if (element) InitializeTrimControl(0, element, "", JSBSim::taElevator);
544 
545  element = trimCfg->FindElement("rudder_cmd");
546  if (element) InitializeTrimControl(0, element, "", JSBSim::taRudder);
547 
548  element = trimCfg->FindElement("aileron_cmd");
549  if (element) InitializeTrimControl(0, element, "", JSBSim::taAileron);
550 
551  output_element = trimCfg->FindElement("output_file");
552  if (output_element) {
553  rf_name = output_element->GetAttributeValue("name");
554  if (rf_name.empty()) {
555  cerr << "name must be specified in output_file \"name\" attribute."<< endl;
556  } else {
557  if ( !SetResultsFile(rf_name) )
558  cerr << "Unable to use output file "<< rf_name << endl;
559  }
560  }
561  return true;
562 }
double GetFlightPathAngleRadIC(void) const
Gets the initial flight path angle.
bool SetResultsFile(string name)
Set the file where trim analysis results are written, open and get ready.
double GetPhiRadIC(void) const
Gets the initial roll angle.
const SGPath & GetFullAircraftPath(void)
Retrieves the full aircraft path name.
Definition: FGFDMExec.h:397
double GetPsiRadIC(void) const
Gets the initial heading angle.
double GetThetaRadIC(void) const
Gets the initial pitch angle.
void CalculatePhiWFromTargetNlfTurn(double nlf)
Calculate the wind axis bank angle from a given Nlf (sets also the target Nlf)
+ Here is the call graph for this function:

◆ RemoveControl()

bool RemoveControl ( TaControl  control)

Remove a specific control from the current configuration.

Parameters
controlthe state to remove
Returns
true if removal is successful

Definition at line 694 of file FGTrimAnalysis.cpp.

694  {
695 
696  FGTrimAnalysisControl* tac;
697  bool result=false;
698 
699  mode = taCustom;
700  vector <FGTrimAnalysisControl*>::iterator iControls = vTrimAnalysisControls.begin();
701  while (iControls != vTrimAnalysisControls.end()) {
702  tac=*iControls;
703  if( tac->GetControlType() == control ) {
704  delete tac;
705  vTrimAnalysisControls.erase(iControls);
706  result=true;
707  continue;
708  }
709  iControls++;
710  }
711 
712  return result;
713 }
+ Here is the call graph for this function:

◆ Report()

void Report ( void  )

Print the results of the trim.

For each axis trimmed, this includes the final state value, control value, and tolerance used.

Returns
true if trim succeeds

Definition at line 610 of file FGTrimAnalysis.cpp.

610  {
611 
612  cout << "---------------------------------------------------------------------\n";
613 
614  cout << "Trim report: " << endl;
615  cout << "\tTrim algorithm terminated with the following values:" << endl;
616  cout << "\tu, v, w (ft/s): " << _u <<", "<< _v <<", "<< _w << endl
617  << "\tp, q, r (rad/s): " << _p <<", "<< _q <<", "<< _r << endl
618  << "\talpha, beta (deg): " << _alpha*57.3 <<", "<< _beta*57.3 << endl
619  << "\tphi, theta, psi (deg): " << _phi*57.3 <<", "<< _theta*57.3 << ", " << _psi*57.3 << endl
620  << "\tCost function value : " << cost_function_value << endl
621  << "\tCycles executed : " << total_its << endl << endl;
622 
623  cout << "\tTrim variables adjusted:" << endl;
624  for (unsigned int i=0; i<vTrimAnalysisControls.size();i++){
625  cout << "\t\t" << vTrimAnalysisControls[i]->GetControlName() <<": ";
626  cout << vTrimAnalysisControls[i]->GetControl() << endl;
627  }
628  //...
629 
630  cout << endl;
631 
632  cout << "\t** Initial -> Final Conditions **" << endl;
633  cout << "\tAlpha IC: " << fgic->GetAlphaDegIC() << " Degrees" << endl;
634  cout << "\t Final: " << Auxiliary->Getalpha()*57.3 << " Degrees" << endl;
635  cout << "\tBeta IC: " << fgic->GetBetaDegIC() << " Degrees" << endl;
636  cout << "\t Final: " << Auxiliary->Getbeta()*57.3 << " Degrees" << endl;
637  cout << "\tGamma IC: " << fgic->GetFlightPathAngleDegIC() << " Degrees" << endl;
638  cout << "\t Final: " << Auxiliary->GetGamma()*57.3 << " Degrees" << endl;
639  cout << "\tPhi IC : " << fgic->GetPhiDegIC() << " Degrees" << endl;
640  cout << "\t Final: " << fdmex->GetPropagate()->GetEuler(1)*57.3 << " Degrees" << endl;
641  cout << "\tTheta IC: " << fgic->GetThetaDegIC() << " Degrees" << endl;
642  cout << "\t Final: " << fdmex->GetPropagate()->GetEuler(2)*57.3 << " Degrees" << endl;
643  cout << "\tPsi IC : " << fgic->GetPsiDegIC() << " Degrees" << endl;
644  cout << "\t Final: " << fdmex->GetPropagate()->GetEuler(3)*57.3 << " Degrees" << endl;
645  cout << endl;
646  cout << "--------------------------------------------------------------------- \n\n";
647 
648  fdmex->EnableOutput();
649 }
double GetAlphaDegIC(void) const
Gets the initial angle of attack.
double GetThetaDegIC(void) const
Gets the initial pitch angle.
double GetBetaDegIC(void) const
Gets the initial sideslip angle.
void EnableOutput(void)
Enables data logging to all outputs.
Definition: FGFDMExec.h:476
double GetFlightPathAngleDegIC(void) const
Gets the initial flight path angle.
double GetPsiDegIC(void) const
Gets the initial heading angle.
double GetPhiDegIC(void) const
Gets the initial roll angle.
const FGColumnVector3 & GetEuler(void) const
Retrieves the Euler angles that define the vehicle orientation.
Definition: FGPropagate.h:260
FGPropagate * GetPropagate(void)
Returns the FGPropagate pointer.
Definition: FGFDMExec.h:369

◆ SetCostFunctionValue()

void SetCostFunctionValue ( double  value)
inline

Set the value of the cost function.

Parameters
valuethe cost function value

Definition at line 478 of file FGTrimAnalysis.h.

478 {cost_function_value = value;}
+ Here is the caller graph for this function:

◆ SetDottedValues()

void SetDottedValues ( double  udot,
double  vdot,
double  wdot,
double  pdot,
double  qdot,
double  rdot 
)

Sets Dotted values.

Parameters
udot,vdot,wdot,pdot,qdot,rdot

Definition at line 443 of file FGTrimAnalysis.cpp.

444 {
445  _udot=udot; _vdot=vdot; _wdot=wdot; _pdot=pdot; _qdot=qdot; _rdot=rdot;
446 }

◆ SetEulerAngles()

void SetEulerAngles ( double  phi0,
double  theta0,
double  psi0 
)

Sets Euler angles.

Parameters
phi0,theta0,psi0

Definition at line 432 of file FGTrimAnalysis.cpp.

433 {
434  // feed into private variables
435  _phi = phi; _cphi = cos(_phi); _sphi = sin(_phi);
436  _theta = theta; _ctheta = cos(_theta); _stheta = sin(_theta);
437  _psi = psi; _cpsi = cos(_psi); _spsi = sin(_psi);
438 
439 }
+ Here is the caller graph for this function:

◆ SetGammaFallback()

void SetGammaFallback ( bool  bb)
inline

automatically switch to trimming longitudinal acceleration with flight path angle (gamma) once it becomes apparent that there is not enough/too much thrust.

Parameters
bbtrue to enable fallback

Definition at line 543 of file FGTrimAnalysis.h.

543 { gamma_fallback=bb; }

◆ SetMaxCycles()

void SetMaxCycles ( int  ii)
inline

Set the iteration limit.

DoTrim() will return false if limit iterations are reached before trim is achieved. The default is 60. This does not ordinarily need to be changed.

Parameters
iiinteger iteration limit

Definition at line 555 of file FGTrimAnalysis.h.

555 { max_iterations = ii; }

◆ SetMode()

void SetMode ( TrimAnalysisMode  tam)

Clear all controls and set a predefined trim mode (Note: controls are intended here as those variables to be adjusted for attaining convergence of the trimming algorithm)

Parameters
tamthe set of axes to trim. Can be: taLongitudinal, taFull, taGround, taCustom, or taNone

Definition at line 995 of file FGTrimAnalysis.cpp.

995  {
996 
997  ClearControls();
998 
999  cout << "---------------------------------------------------------------------" << endl;
1000  cout << "Trim analysis performed: ";
1001  mode=tt;
1002  switch(tt) {
1003  case taLongitudinal:
1004  if (debug_lvl > 0)
1005  cout << " Longitudinal Trim" << endl;
1006  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taThrottle ));
1007  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taElevator )); // TODO: taPitchTrim
1008  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taTheta ));
1009  break;
1010  case taFull:
1011  if (debug_lvl > 0)
1012  cout << " Full Trim" << endl;
1013  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taThrottle ));
1014  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taElevator )); // TODO: taPitchTrim
1015  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taAileron )); // TODO: taRollTrim
1016  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taRudder )); // TODO: taYawTrim
1017  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taPhi ));
1018  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taTheta ));
1019  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taHeading ));
1020  break;
1021  case taFullWingsLevel:
1022  if (debug_lvl > 0)
1023  cout << " Full Trim, Wings-Level" << endl;
1024  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taThrottle ));
1025  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taElevator )); // TODO: taPitchTrim
1026  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taAileron )); // TODO: taRollTrim
1027  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taRudder )); // TODO: taYawTrim
1028  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taTheta ));
1029  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taHeading ));
1030  break;
1031  case taTurn:
1032  // ToDo: set target NLF here !!!
1033  // ToDo: assign psiDot here !!
1034  if (debug_lvl > 0)
1035  cout << " Full Trim, Coordinated turn" << endl;
1036  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taThrottle ));
1037  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taElevator )); // TODO: taPitchTrim
1038  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taAileron )); // TODO: taRollTrim
1039  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taRudder )); // TODO: taYawTrim
1040  //vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taPhi ));
1041  //vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taTheta ));
1042  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taHeading ));
1043  break;
1044  case taTurnFull:
1045  if (debug_lvl > 0)
1046  cout << " Non-coordinated Turn Trim" << endl;
1047  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taThrottle ));
1048  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taElevator )); // TODO: taPitchTrim
1049  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taAileron )); // TODO: taRollTrim
1050  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taRudder )); // TODO: taYawTrim
1051  //vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taPhi ));
1052  // calculate this from target nlf
1053  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taTheta ));
1054  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taHeading ));
1055  break;
1056  case taPullup:
1057  // ToDo: set target NLF here !!!
1058  // ToDo: assign qDot here !!
1059  if (debug_lvl > 0)
1060  cout << " Full Trim, Pullup" << endl;
1061  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taThrottle ));
1062  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taElevator )); // TODO: taPitchTrim
1063  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taAileron ));
1064  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taRudder ));
1065  //vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taPhi ));
1066  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taTheta ));
1067  //vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taHeading ));
1068  break;
1069  case taGround:
1070  if (debug_lvl > 0)
1071  cout << " Ground Trim" << endl;
1072  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taAltAGL ));
1073  vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taTheta ));
1074  //vTrimAnalysisControls.push_back(new FGTrimAnalysisControl(fdmex,fgic,taPhi ));
1075  break;
1076  case taCustom:
1077  // agodemar...
1078  // ...agodemar
1079  case taNone:
1080  break;
1081  }
1082 
1083  current_ctrl=0;
1084 }
void ClearControls(void)
Clear all controls from the current configuration.

◆ SetResultsFile()

bool SetResultsFile ( string  name)

Set the file where trim analysis results are written, open and get ready.

Parameters
namethe file name
Returns
true if file open is successful

Definition at line 1087 of file FGTrimAnalysis.cpp.

1088 {
1089  if ( rf.is_open() ) return false;
1090 
1091  rf_name = name;
1092  rf.open(rf_name.c_str(), ios::out);
1093  if ( !rf.is_open() ) {
1094  cerr << "Unable to open " << rf_name << endl;
1095  return false;
1096  }
1097  //rf << "# ... complete this " << endl;
1098  //rf << "# iteration, CostFunc, size, dT, dE, dA, dR, Psi (rad), Theta (rad), Phi (rad)\n";
1099  return true;
1100 }
+ Here is the call graph for this function:

◆ SetState()

void SetState ( double  u0,
double  v0,
double  w0,
double  p0,
double  q0,
double  r0,
double  alpha0,
double  beta0,
double  phi0,
double  theta0,
double  psi0,
double  gamma0 
)

Sets state variables.

Parameters
u0
v0
w0
p0
q0
r0
alpha0
beta0
phi0
psi0
theta0
gamma0

Definition at line 421 of file FGTrimAnalysis.cpp.

423 {
424  _u=u0; _v=v0; _w=w0;
425  _p=p0; _q=q0; _r=r0;
426  _alpha=alpha0; _beta=beta0; _gamma=gamma0;
427  _theta=theta0; _phi=phi0; _psi=psi0;
428 }
+ Here is the caller graph for this function:

◆ SetTargetNlf()

void SetTargetNlf ( double  nlf)
inline

Sets target normal load factor in steady turn.

Parameters
nlftarget normal load factor

Definition at line 658 of file FGTrimAnalysis.h.

658 { _targetNlf=nlf; }

◆ SetTolerance()

void SetTolerance ( double  tt)
inline

Set the tolerance for declaring a state trimmed.

(In the evaluation of the cost function, squares of angular accels are devided by 100) The default is 1e-8.

Parameters
ttuser defined tolerance

Definition at line 563 of file FGTrimAnalysis.h.

563  {
564  tolerance = tt;
565  }

◆ SetTrimFailed()

void SetTrimFailed ( bool  tf)
inline

Sets trim result status.

Parameters
tf(boolean)

Definition at line 574 of file FGTrimAnalysis.h.

574 { trim_failed = tf; }

◆ UpdateRatesPullup()

FGColumnVector3 UpdateRatesPullup ( void  )

Updates angular rates for pull-up trim.

Returns
p, q, r

Definition at line 920 of file FGTrimAnalysis.cpp.

920  {
921  double g,cgamma;
922  g=fdmex->GetInertial()->gravity();
923  cgamma=cos(fgic->GetFlightPathAngleRadIC());
924  _p = 0;
925  _q = g*(_targetNlf-cgamma)/fgic->GetVtrueFpsIC();
926  _r = 0.;
927 
928  fgic->SetQRadpsIC(_q);
929  return FGColumnVector3(_p,_q,_r);
930 }
double GetVtrueFpsIC(void) const
Gets the initial true velocity.
FGInertial * GetInertial(void)
Returns the FGInertial pointer.
Definition: FGFDMExec.h:359
double GetFlightPathAngleRadIC(void) const
Gets the initial flight path angle.
void SetQRadpsIC(double Q)
Sets the initial body axis pitch rate.
+ Here is the caller graph for this function:

◆ UpdateRatesTurn()

FGColumnVector3 UpdateRatesTurn ( double  psi,
double  theta,
double  phi,
double  phiW 
)

Updates angular rates for turn trim according to turning trim constraints.

Parameters
psi,theta,phi
Returns
p, q, r

Definition at line 914 of file FGTrimAnalysis.cpp.

914  {
915  _psi = psi;
916  setupTurn(phiW); // calls updateRates: updates _p,_q,_r
917  return FGColumnVector3(_p,_q,_r);
918 }
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: