JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
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 Lesser 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 Lesser General Public License for more
17  details.
18 
19  You should have received a copy of the GNU Lesser 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 Lesser 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 "FGInitialCondition.h"
46 
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 DEFINITIONS
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50 
51 #define ID_TRIMAXIS "$Id: FGTrimAxis.h,v 1.7 2013/11/24 16:53:15 bcoconni Exp $"
52 
53 #define DEFAULT_TOLERANCE 0.001
54 
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 FORWARD DECLARATIONS
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 
59 namespace JSBSim {
60 
61 const std::string StateNames[] = { "all","udot","vdot","wdot","qdot","pdot",
62  "rdot","hmgt","nlf"
63  };
64 const std::string ControlNames[] = { "Throttle","Sideslip","Angle of Attack",
65  "Elevator","Ailerons","Rudder",
66  "Altitude AGL", "Pitch Angle",
67  "Roll Angle", "Flight Path Angle",
68  "Pitch Trim", "Roll Trim", "Yaw Trim",
69  "Heading"
70  };
71 
72 class FGInitialCondition;
73 
74 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 CLASS DOCUMENTATION
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
77 
81 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 CLASS DECLARATION
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
84 
85 enum State { tAll,tUdot,tVdot,tWdot,tQdot,tPdot,tRdot,tHmgt,tNlf };
86 enum Control { tThrottle, tBeta, tAlpha, tElevator, tAileron, tRudder, tAltAGL,
87  tTheta, tPhi, tGamma, tPitchTrim, tRollTrim, tYawTrim, tHeading };
88 
89 class FGTrimAxis : public FGJSBBase
90 {
91 public:
97  FGTrimAxis(FGFDMExec* fdmex,
98  FGInitialCondition *IC,
99  State state,
100  Control control );
102  ~FGTrimAxis();
103 
106  void Run(void);
107 
108  double GetState(void) { getState(); return state_value; }
109  //Accels are not settable
110  inline void SetControl(double value ) { control_value=value; }
111  inline double GetControl(void) { return control_value; }
112 
113  inline State GetStateType(void) { return state; }
114  inline Control GetControlType(void) { return control; }
115 
116  inline std::string GetStateName(void) { return StateNames[state]; }
117  inline std::string GetControlName(void) { return ControlNames[control]; }
118 
119  inline double GetControlMin(void) { return control_min; }
120  inline double GetControlMax(void) { return control_max; }
121 
122  inline void SetControlToMin(void) { control_value=control_min; }
123  inline void SetControlToMax(void) { control_value=control_max; }
124 
125  inline void SetControlLimits(double min, double max) {
126  control_min=min;
127  control_max=max;
128  }
129 
130  inline void SetTolerance(double ff) { tolerance=ff;}
131  inline double GetTolerance(void) { return tolerance; }
132 
133  inline double GetSolverEps(void) { return solver_eps; }
134  inline void SetSolverEps(double ff) { solver_eps=ff; }
135 
136  inline int GetIterationLimit(void) { return max_iterations; }
137  inline void SetIterationLimit(int ii) { max_iterations=ii; }
138 
139  inline int GetStability(void) { return its_to_stable_value; }
140  inline int GetRunCount(void) { return total_stability_iterations; }
141  double GetAvgStability( void );
142 
143  inline void SetStateTarget(double target) { state_target=target; }
144  inline double GetStateTarget(void) { return state_target; }
145 
146  void AxisReport(void);
147 
148  bool InTolerance(void) { getState(); return (fabs(state_value) <= tolerance); }
149 
150 private:
151  FGFDMExec *fdmex;
152  FGInitialCondition *fgic;
153 
154  State state;
155  Control control;
156 
157  double state_target;
158 
159  double state_value;
160  double control_value;
161 
162  double control_min;
163  double control_max;
164 
165  double tolerance;
166 
167  double solver_eps;
168 
169  double state_convert;
170  double control_convert;
171 
172  int max_iterations;
173 
174  int its_to_stable_value;
175  int total_stability_iterations;
176  int total_iterations;
177 
178  void setThrottlesPct(void);
179 
180  void getState(void);
181  void getControl(void);
182  void setControl(void);
183 
184  double computeHmgt(void);
185 
186  void Debug(int from);
187 };
188 }
189 #endif
JSBSim Base class.
Definition: FGJSBBase.h:80
void Run(void)
This function iterates through a call to the FGFDMExec::RunIC() function until the desired trimming c...
Definition: FGTrimAxis.cpp:248
Initializes the simulation run.
~FGTrimAxis()
Destructor.
Definition: FGTrimAxis.cpp:162
FGTrimAxis(FGFDMExec *fdmex, FGInitialCondition *IC, State state, Control control)
Constructor for Trim Axis class.
Definition: FGTrimAxis.cpp:64
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:189