]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGTrimAxis.h
Syncing with the very latest JSBSim development code.
[flightgear.git] / src / FDM / JSBSim / FGTrimAxis.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2  
3  Header:       FGTrimAxis.h
4  Author:       Tony Peden
5  Date started: 7/3/00
6  
7  ------------- Copyright (C) 1999  Anthony K. Peden (apeden@earthlink.net) -------------
8  
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13  
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  details.
18  
19  You should have received a copy of the GNU General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22  
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25  
26  HISTORY
27 --------------------------------------------------------------------------------
28 7/3/00  TP   Created
29  
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGTRIMAXIS_H
35 #define FGTRIMAXIS_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include <string>
42
43 #include "FGFDMExec.h"
44 #include "FGJSBBase.h"
45 #include "FGRotation.h"
46 #include "FGAtmosphere.h"
47 #include "FGState.h"
48 #include "FGFCS.h"
49 #include "FGAircraft.h"
50 #include "FGTranslation.h"
51 #include "FGPosition.h"
52 #include "FGAuxiliary.h"
53 #include "FGOutput.h"
54
55 #define ID_TRIMAXIS "$Id$"
56
57 #define DEFAULT_TOLERANCE 0.001
58
59 const string StateNames[7]=   { "udot","vdot","wdot","qdot","pdot","rdot","hmgt" };
60 const string ControlNames[14]= { "Throttle","Sideslip","Angle of Attack",
61                                  "Elevator","Ailerons","Rudder",
62                                  "Altitude AGL", "Pitch Angle",
63                                  "Roll Angle", "Flight Path Angle", 
64                                  "Pitch Trim", "Roll Trim", "Yaw Trim",
65                                  "Heading"
66                                };
67
68 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 CLASS DECLARATION
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
71
72 enum State { tUdot,tVdot,tWdot,tQdot,tPdot,tRdot,tHmgt };
73 enum Control { tThrottle, tBeta, tAlpha, tElevator, tAileron, tRudder, tAltAGL,
74                tTheta, tPhi, tGamma, tPitchTrim, tRollTrim, tYawTrim, tHeading };
75
76 class FGTrimAxis : public FGJSBBase
77 {
78 public:
79   FGTrimAxis(FGFDMExec* fdmex, FGInitialCondition *ic, State st,
80              Control ctrl );
81   ~FGTrimAxis();
82
83   void Run(void);
84  
85   float GetState(void) { getState(); return state_value; }
86   //Accels are not settable
87   inline void SetControl(float value ) { control_value=value; }
88   inline float GetControl(void) { return control_value; }
89
90   inline State GetStateType(void) { return state; }
91   inline Control GetControlType(void) { return control; }
92
93   inline string GetStateName(void) { return StateNames[state]; }
94   inline string GetControlName(void) { return ControlNames[control]; }
95
96   inline float GetControlMin(void) { return control_min; }
97   inline float GetControlMax(void) { return control_max; }
98
99   inline void SetControlToMin(void) { control_value=control_min; }
100   inline void SetControlToMax(void) { control_value=control_max; }
101   
102   inline void SetControlLimits(float min, float max) { 
103       control_min=min;
104       control_max=max;
105   }    
106
107   inline void  SetTolerance(float ff) { tolerance=ff;}
108   inline float GetTolerance(void) { return tolerance; }
109
110   inline float GetSolverEps(void) { return solver_eps; }
111   inline void SetSolverEps(float ff) { solver_eps=ff; }
112
113   inline int  GetIterationLimit(void) { return max_iterations; }
114   inline void SetIterationLimit(int ii) { max_iterations=ii; }
115
116   inline int GetStability(void) { return its_to_stable_value; }
117   inline int GetRunCount(void) { return total_stability_iterations; }
118   float GetAvgStability( void );
119   
120   void SetThetaOnGround(float ff);
121   void SetPhiOnGround(float ff);
122   
123   bool initTheta(void);
124   
125   void AxisReport(void);
126   
127   bool InTolerance(void) { getState(); return (fabs(state_value) <= tolerance); }
128
129 private:
130   FGFDMExec *fdmex;
131   FGInitialCondition *fgic;
132
133   State   state;
134   Control control;
135
136   float state_value;
137   float control_value;
138
139   float control_min;
140   float control_max;
141
142   float tolerance;
143
144   float solver_eps;
145
146   float state_convert;
147   float control_convert;
148
149   int max_iterations;
150
151   int its_to_stable_value;
152   int total_stability_iterations;
153   int total_iterations;
154
155   void setThrottlesPct(void);
156
157   void getState(void);
158   void getControl(void);
159   void setControl(void);
160   
161   float computeHmgt(void);
162   
163   void Debug(void);
164 };
165
166 #endif