JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++

FGTrimAxis.h

00001 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00002  
00003  Header:       FGTrimAxis.h
00004  Author:       Tony Peden
00005  Date started: 7/3/00
00006  
00007  ------------- Copyright (C) 1999  Anthony K. Peden (apeden@earthlink.net) -------------
00008  
00009  This program is free software; you can redistribute it and/or modify it under
00010  the terms of the GNU Lesser General Public License as published by the Free Software
00011  Foundation; either version 2 of the License, or (at your option) any later
00012  version.
00013  
00014  This program is distributed in the hope that it will be useful, but WITHOUT
00015  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00016  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00017  details.
00018  
00019  You should have received a copy of the GNU Lesser General Public License along with
00020  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021  Place - Suite 330, Boston, MA  02111-1307, USA.
00022  
00023  Further information about the GNU Lesser General Public License can also be found on
00024  the world wide web at http://www.gnu.org.
00025  
00026  HISTORY
00027 --------------------------------------------------------------------------------
00028 7/3/00  TP   Created
00029  
00030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00031 SENTRY
00032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00033 
00034 #ifndef FGTRIMAXIS_H
00035 #define FGTRIMAXIS_H
00036 
00037 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00038 INCLUDES
00039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00040 
00041 #include <string>
00042 
00043 #include "FGFDMExec.h"
00044 #include "FGJSBBase.h"
00045 #include "FGInitialCondition.h"
00046 
00047 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00048 DEFINITIONS
00049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00050 
00051 #define ID_TRIMAXIS "$Id: FGTrimAxis.h,v 1.5 2010/09/07 18:36:29 andgi Exp $"
00052 
00053 #define DEFAULT_TOLERANCE 0.001
00054 
00055 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00056 FORWARD DECLARATIONS
00057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00058 
00059 namespace JSBSim {
00060 
00061 const string StateNames[] =   { "all","udot","vdot","wdot","qdot","pdot","rdot",
00062                                 "hmgt","nlf" 
00063                               };
00064 const string ControlNames[] =  { "Throttle","Sideslip","Angle of Attack",
00065                                  "Elevator","Ailerons","Rudder",
00066                                  "Altitude AGL", "Pitch Angle",
00067                                  "Roll Angle", "Flight Path Angle", 
00068                                  "Pitch Trim", "Roll Trim", "Yaw Trim",
00069                                  "Heading"
00070                                };
00071 
00072 class FGInitialCondition;
00073 
00074 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00075 CLASS DOCUMENTATION
00076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00077 
00081 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00082 CLASS DECLARATION
00083 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
00084 
00085 enum State { tAll,tUdot,tVdot,tWdot,tQdot,tPdot,tRdot,tHmgt,tNlf };
00086 enum Control { tThrottle, tBeta, tAlpha, tElevator, tAileron, tRudder, tAltAGL,
00087                tTheta, tPhi, tGamma, tPitchTrim, tRollTrim, tYawTrim, tHeading };
00088 
00089 class FGTrimAxis : public FGJSBBase
00090 {
00091 public:
00097   FGTrimAxis(FGFDMExec* fdmex, 
00098              FGInitialCondition *IC, 
00099              State state,
00100              Control control );
00102   ~FGTrimAxis();
00103 
00106   void Run(void);
00107  
00108   double GetState(void) { getState(); return state_value; }
00109   //Accels are not settable
00110   inline void SetControl(double value ) { control_value=value; }
00111   inline double GetControl(void) { return control_value; }
00112 
00113   inline State GetStateType(void) { return state; }
00114   inline Control GetControlType(void) { return control; }
00115 
00116   inline string GetStateName(void) { return StateNames[state]; }
00117   inline string GetControlName(void) { return ControlNames[control]; }
00118 
00119   inline double GetControlMin(void) { return control_min; }
00120   inline double GetControlMax(void) { return control_max; }
00121 
00122   inline void SetControlToMin(void) { control_value=control_min; }
00123   inline void SetControlToMax(void) { control_value=control_max; }
00124   
00125   inline void SetControlLimits(double min, double max) { 
00126       control_min=min;
00127       control_max=max;
00128   }    
00129 
00130   inline void  SetTolerance(double ff) { tolerance=ff;}
00131   inline double GetTolerance(void) { return tolerance; }
00132 
00133   inline double GetSolverEps(void) { return solver_eps; }
00134   inline void SetSolverEps(double ff) { solver_eps=ff; }
00135 
00136   inline int  GetIterationLimit(void) { return max_iterations; }
00137   inline void SetIterationLimit(int ii) { max_iterations=ii; }
00138 
00139   inline int GetStability(void) { return its_to_stable_value; }
00140   inline int GetRunCount(void) { return total_stability_iterations; }
00141   double GetAvgStability( void );
00142   
00143   void SetThetaOnGround(double ff);
00144   void SetPhiOnGround(double ff);
00145   
00146   inline void SetStateTarget(double target) { state_target=target; }
00147   inline double GetStateTarget(void) { return state_target; }
00148   
00149   bool initTheta(void);
00150   
00151   void AxisReport(void);
00152   
00153   bool InTolerance(void) { getState(); return (fabs(state_value) <= tolerance); }
00154 
00155 private:
00156   FGFDMExec *fdmex;
00157   FGInitialCondition *fgic;
00158 
00159   State   state;
00160   Control control;
00161   
00162   double state_target;
00163   
00164   double state_value;
00165   double control_value;
00166 
00167   double control_min;
00168   double control_max;
00169 
00170   double tolerance;
00171 
00172   double solver_eps;
00173 
00174   double state_convert;
00175   double control_convert;
00176 
00177   int max_iterations;
00178 
00179   int its_to_stable_value;
00180   int total_stability_iterations;
00181   int total_iterations;
00182 
00183   void setThrottlesPct(void);
00184 
00185   void getState(void);
00186   void getControl(void);
00187   void setControl(void);
00188   
00189   double computeHmgt(void);
00190   
00191   void Debug(int from);
00192 };
00193 }
00194 #endif