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