]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGTrimAxis.h
Latest round of JSBSim updates.
[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 "FGRotation.h"
45 #include "FGAtmosphere.h"
46 #include "FGState.h"
47 #include "FGFCS.h"
48 #include "FGAircraft.h"
49 #include "FGTranslation.h"
50 #include "FGPosition.h"
51 #include "FGAuxiliary.h"
52 #include "FGOutput.h"
53
54 #define ID_TRIMAXIS "$Id$"
55
56 #define DEFAULT_TOLERANCE 0.001
57
58 const string StateNames[7]=   { "udot","vdot","wdot","qdot","pdot","rdot","hmgt" };
59 const string ControlNames[14]= { "Throttle","Sideslip","Angle of Attack",
60                                  "Elevator","Ailerons","Rudder",
61                                  "Altitude AGL", "Pitch Angle",
62                                  "Roll Angle", "Flight Path Angle", 
63                                  "Pitch Trim", "Roll Trim", "Yaw Trim",
64                                  "Heading"
65                                };
66
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 CLASS DECLARATION
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70
71 enum State { tUdot,tVdot,tWdot,tQdot,tPdot,tRdot,tHmgt };
72 enum Control { tThrottle, tBeta, tAlpha, tElevator, tAileron, tRudder, tAltAGL,
73                tTheta, tPhi, tGamma, tPitchTrim, tRollTrim, tYawTrim, tHeading };
74
75 class FGTrimAxis {
76 public:
77   FGTrimAxis(FGFDMExec* fdmex, FGInitialCondition *ic, State st,
78              Control ctrl );
79   ~FGTrimAxis();
80
81   void Run(void);
82  
83   float GetState(void) { getState(); return state_value; }
84   //Accels are not settable
85   inline void SetControl(float value ) { control_value=value; }
86   inline float GetControl(void) { return control_value; }
87
88   inline State GetStateType(void) { return state; }
89   inline Control GetControlType(void) { return control; }
90
91   inline string GetStateName(void) { return StateNames[state]; }
92   inline string GetControlName(void) { return ControlNames[control]; }
93
94   inline float GetControlMin(void) { return control_min; }
95   inline float GetControlMax(void) { return control_max; }
96
97   inline void SetControlToMin(void) { control_value=control_min; }
98   inline void SetControlToMax(void) { control_value=control_max; }
99   
100   inline void SetControlLimits(float min, float max) { 
101       control_min=min;
102       control_max=max;
103   }    
104
105   inline void  SetTolerance(float ff) { tolerance=ff;}
106   inline float GetTolerance(void) { return tolerance; }
107
108   inline float GetSolverEps(void) { return solver_eps; }
109   inline void SetSolverEps(float ff) { solver_eps=ff; }
110
111   inline int  GetIterationLimit(void) { return max_iterations; }
112   inline void SetIterationLimit(int ii) { max_iterations=ii; }
113
114   inline int GetStability(void) { return its_to_stable_value; }
115   inline int GetRunCount(void) { return total_stability_iterations; }
116   float GetAvgStability( void );
117   
118   void SetThetaOnGround(float ff);
119   void SetPhiOnGround(float ff);
120   
121   bool initTheta(void);
122   
123   void AxisReport(void);
124   
125   bool InTolerance(void) { getState(); return (fabs(state_value) <= tolerance); }
126
127 private:
128   FGFDMExec *fdmex;
129   FGInitialCondition *fgic;
130
131   State   state;
132   Control control;
133
134   float state_value;
135   float control_value;
136
137   float control_min;
138   float control_max;
139
140   float tolerance;
141
142   float solver_eps;
143
144   float state_convert;
145   float control_convert;
146
147   int max_iterations;
148
149   int its_to_stable_value;
150   int total_stability_iterations;
151   int total_iterations;
152
153   void setThrottlesPct(void);
154
155   void getState(void);
156   void getControl(void);
157   void setControl(void);
158   
159   float computeHmgt(void);
160   
161   void Debug(void);
162 };
163
164 #endif