45 #ifndef FGTRIMANAlYSIS_H 46 #define FGTRIMANAlYSIS_H 52 #include "FGFDMExec.h" 53 #include "FGJSBBase.h" 54 #include "FGTrimAnalysisControl.h" 56 #include "models/FGAtmosphere.h" 57 #include "initialization/FGInitialCondition.h" 58 #include "models/FGAircraft.h" 59 #include "models/FGMassBalance.h" 60 #include "models/FGGroundReactions.h" 61 #include "models/FGInertial.h" 62 #include "models/FGAerodynamics.h" 63 #include "math/FGColumnVector3.h" 64 #include "models/FGAuxiliary.h" 65 #include "models/FGPropulsion.h" 71 #include "math/direct_search/vec.h" 77 #define ID_FGTRIMANALYSIS "$Id: FGTrimAnalysis.h,v 1.8 2009/10/02 10:30:09 jberndt Exp $" 79 #if defined(_WIN32) && !defined(__CYGWIN__) 80 #define snprintf _snprintf 89 typedef enum { taLongitudinal=0, taFull, taFullWingsLevel, taTurn, taPullup, taTurnFull,
90 taGround, taCustom, taNone } TrimAnalysisMode;
127 class FGTrimAnalysis;
201 bool & success,
void* t_ptr);
217 bool & success,
void* t_ptr);
233 bool & success,
void* t_ptr);
249 bool & success,
void* t_ptr);
265 bool & success,
void* t_ptr);
281 bool & success,
void* t_ptr);
284 void Set_x_val(
double new_x);
285 double Get_x_val()
const {
return _x;}
289 typedef void (*
PF)(
long vars, Vector<double> &v,
double & f,
bool & success,
void* t_ptr);
291 map<TrimAnalysisMode,PF> mpCostFunctions;
297 void calculateDottedStates(
double delta_cmd_T,
double delta_cmd_E,
double delta_cmd_A,
double delta_cmd_R,
298 double phi,
double theta,
double psi,
299 TrimAnalysisMode trimMode,
300 double& alpha,
double& beta,
double& gamma,
307 double myCostFunctionFull (Vector<double> & vec1);
310 double myCostFunctionFullWingsLevel (Vector<double> & vec1);
313 double myCostFunctionLongitudinal (Vector<double> & vec1);
316 double myCostFunctionFullCoordinatedTurn (Vector<double> & vec1);
319 double myCostFunctionFullTurn (Vector<double> & vec1);
322 double myCostFunctionPullUp (Vector<double> & vec1);
333 vector<FGTrimAnalysisControl*> vTrimAnalysisControls;
334 double cost_function_value;
335 unsigned int current_ctrl;
337 TrimAnalysisMode mode;
338 int DebugLevel, Debug;
345 unsigned int ctrl_count;
355 vector<double> vAlphaDeg, vAlphaTrimDeg;
356 vector<double> vCL, vCD, vCm;
357 vector<double> vCLE, vCDE, vCmE;
358 vector<vector <double> > mCL, mCD, mCm, mTa;
359 vector<double> vThrottleCmd, vElevatorCmd;
360 vector<double> vVn, vTn, vTa, vVnE, vTE;
361 vector<double> vCt, vCq, vRPM;
362 vector<vector <double> > mCt, mCq, mRPM;
363 vector<bool> hasThrustTrim, hasCmTrim;
369 double sigma_nm, alpha_nm, beta_nm, gamma_nm;
372 string stop_criterion;
385 double _alpha, _beta, _theta, _phi, _psi, _psiW, _gamma, _phiW;
387 double _stheta, _sphi, _spsi;
388 double _ctheta, _cphi, _cpsi;
390 double _vtIC, _hIC, _gammaIC, _rocIC, _vdownIC, _psiIC, _psigtIC, _vgIC,
391 _vnorthIC, _veastIC, wnorthIC, _weastIC, _wdownIC;
393 double _udot, _vdot, _wdot, _pdot, _qdot, _rdot;
395 double _psiWdot, _phiWdot, _gammadot, _psidot, _thetadot;
397 double C1, C2, C3, _calpha, _salpha, _cbeta, _sbeta;
399 void setupPullup(
void);
400 void setupTurn(
void);
401 void setupTurn(
double phiW);
402 void setupTurnPhi(
double psi,
double theta);
404 void updateRates(
void);
408 bool ensureRunning(
void);
409 bool ensureRunning(
unsigned int i);
410 bool runForAWhile(
int nruns);
412 bool populateVecAlphaDeg(
double vmin,
double vmax,
int n);
413 bool populateVecThrottleCmd(
double vmin,
double vmax,
int n);
414 bool populateVecElevatorCmd(
double vmin,
double vmax,
int n);
416 bool calculateAerodynamics(
422 double S,
double mac,
double bw,
423 double& CL,
double& CD,
double& Cm);
426 bool getSteadyState(
int nrepeat);
427 bool InitializeTrimControl(
double default_value,
Element* el,
428 string unit, TaControl type);
446 bool Load(
string fname,
bool useStoredPath =
true );
468 bool SetResultsFile(
string name);
473 ofstream*
GetResultsFile()
const {
if (rf.is_open())
return &rf;
else return 0; }
490 void SetMode(TrimAnalysisMode tam);
495 inline TrimAnalysisMode
GetMode()
const {
return mode;};
497 inline vector<FGTrimAnalysisControl*>* GetControls(){
return &vTrimAnalysisControls;}
505 void ClearControls(
void);
515 bool AddControl( TaControl control );
521 bool RemoveControl( TaControl control );
530 bool EditState( TaControl new_control,
double new_initvalue,
double new_step,
double new_min,
double new_max );
579 inline void SetTrimSuccessfull() { trim_failed =
false; }
596 void SetState(
double u0,
double v0,
double w0,
double p0,
double q0,
double r0,
597 double alpha0,
double beta0,
double phi0,
double theta0,
double psi0,
double gamma0);
601 void SetEulerAngles(
double phi0,
double theta0,
double psi0);
632 void CalculatePhiWFromTargetNlfTurn(
double nlf);
638 FGColumnVector3 UpdateRatesTurn(
double psi,
double theta,
double phi,
double phiW);
647 void SetDottedValues(
double udot,
double vdot,
double wdot,
double pdot,
double qdot,
double rdot);
653 inline void SetDebug(
int level) { DebugLevel = level; }
654 inline void ClearDebug(
void) { DebugLevel = 0; }
bool GetGammaFallback(void)
query the fallback state
double GetPhiRad()
Gets Euler angle phi.
double GetGamma()
Return the current flight path angle in TrimAnalysis object.
double GetPhiWRad()
Gets Euler angle phiW (wind axes)
TrimAnalysisMode GetMode() const
void SetDebug(int level)
Debug level 1 shows results of each top-level iteration Debug level 2 shows level 1 & results of each...
friend void find_CostFunctionFullWingsLevel(long vars, Vector< double > &v, double &f, bool &success, void *t_ptr)
Wrapping function for the effective Wings Level Trim cost function, to be called by optimization meth...
void SetMaxCycles(int ii)
Set the iteration limit.
ofstream * GetResultsFile() const
Get the pointer to the file where trim analysis results are written,.
void SetCostFunctionValue(double value)
Set the value of the cost function.
Encapsulates the aerodynamic calculations.
friend void find_CostFunctionLongitudinal(long vars, Vector< double > &v, double &f, bool &success, void *t_ptr)
Wrapping function for the effective Longitudinal Trim cost function, to be called by optimization met...
double GetThetaRad()
Gets Euler angle theta.
void SetTrimFailed(bool tf)
Sets trim result status.
The current vehicle state vector structure contains the translational and angular position...
void CostFunctionFullTurn(long vars, Vector< double > &v, double &f)
Steady Turn Trim cost function.
friend void find_CostFunctionPullUp(long vars, Vector< double > &v, double &f, bool &success, void *t_ptr)
Wrapping function for the effective Pullup Trim cost function, to be called by optimization method...
Objective(FGFDMExec *fdmex, FGTrimAnalysis *ta, double x)
Constructor.
void CostFunctionFullCoordinatedTurn(long vars, Vector< double > &v, double &f)
Steady Turn Trim cost function, NON-coordinated.
double GetVtFps()
Gets true speed [fps] from IC.
Propulsion management class.
double GetTargetNlf(void)
Gets target normal load factor in steady turn.
void(* PF)(long vars, Vector< double > &v, double &f, bool &success, void *t_ptr)
Pointer to cost function implementation.
void CostFunctionLongitudinal(long vars, Vector< double > &v, double &f)
Longitudinal Trim cost function.
void CostFunctionFullWingsLevel(long vars, Vector< double > &v, double &f)
Wings Level Trim cost function.
void SetGammaFallback(bool bb)
automatically switch to trimming longitudinal acceleration with flight path angle (gamma) once it bec...
This class implements a 3 element column vector.
double GetPsiRad()
Gets Euler angle psi.
void CostFunctionPullUp(long vars, Vector< double > &v, double &f)
Pullup Trim cost function.
Initializes the simulation run.
Encapsulates the Flight Control System (FCS) functionality.
double GetGammaRad()
Gets flight path angle.
friend void find_CostFunctionFull(long vars, Vector< double > &v, double &f, bool &success, void *t_ptr)
Wrapping function for the effective Full Trim cost function, to be called by optimization method...
Encapsulates various uncategorized scheduled functions.
bool GetTrimFailed(void)
Gets trim result status.
void SetTolerance(double tt)
Set the tolerance for declaring a state trimmed.
void CostFunctionFull(long vars, Vector< double > &v, double &f)
Full Trim cost function.
Encapsulates the JSBSim simulation executive.
double GetCostFunctionValue() const
double GetTolerance(void)
Get the tolerance for declaring a state trimmed.
void SetTargetNlf(double nlf)
Sets target normal load factor in steady turn.
friend void find_CostFunctionFullCoordinatedTurn(long vars, Vector< double > &v, double &f, bool &success, void *t_ptr)
Wrapping function for the effective Steady Turn Trim cost function, to be called by optimization meth...
friend void find_CostFunctionFullTurn(long vars, Vector< double > &v, double &f, bool &success, void *t_ptr)
Wrapping function for the effective Steady Turn Trim cost function, to be called by optimization meth...