JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
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 DEFAULT_TOLERANCE 0.001
52 
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 FORWARD DECLARATIONS
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 
57 namespace JSBSim {
58 
59 const std::string StateNames[] = { "all","udot","vdot","wdot","qdot","pdot",
60  "rdot","hmgt","nlf"
61  };
62 const std::string ControlNames[] = { "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 class FGInitialCondition;
71 
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 CLASS DOCUMENTATION
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
75 
79 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 CLASS DECLARATION
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
82 
83 enum State { tAll,tUdot,tVdot,tWdot,tQdot,tPdot,tRdot,tHmgt,tNlf };
84 enum Control { tThrottle, tBeta, tAlpha, tElevator, tAileron, tRudder, tAltAGL,
85  tTheta, tPhi, tGamma, tPitchTrim, tRollTrim, tYawTrim, tHeading };
86 
87 class FGTrimAxis : public FGJSBBase
88 {
89 public:
95  FGTrimAxis(FGFDMExec* fdmex,
96  FGInitialCondition *IC,
97  State state,
98  Control control );
100  ~FGTrimAxis();
101 
104  void Run(void);
105 
106  double GetState(void) { getState(); return state_value; }
107  //Accels are not settable
108  inline void SetControl(double value ) { control_value=value; }
109  inline double GetControl(void) { return control_value; }
110 
111  inline State GetStateType(void) { return state; }
112  inline Control GetControlType(void) { return control; }
113 
114  inline std::string GetStateName(void) { return StateNames[state]; }
115  inline std::string GetControlName(void) { return ControlNames[control]; }
116 
117  inline double GetControlMin(void) { return control_min; }
118  inline double GetControlMax(void) { return control_max; }
119 
120  inline void SetControlToMin(void) { control_value=control_min; }
121  inline void SetControlToMax(void) { control_value=control_max; }
122 
123  inline void SetControlLimits(double min, double max) {
124  control_min=min;
125  control_max=max;
126  }
127 
128  inline void SetTolerance(double ff) { tolerance=ff;}
129  inline double GetTolerance(void) { return tolerance; }
130 
131  inline double GetSolverEps(void) { return solver_eps; }
132  inline void SetSolverEps(double ff) { solver_eps=ff; }
133 
134  inline int GetIterationLimit(void) { return max_iterations; }
135  inline void SetIterationLimit(int ii) { max_iterations=ii; }
136 
137  inline int GetStability(void) { return its_to_stable_value; }
138  inline int GetRunCount(void) { return total_stability_iterations; }
139  double GetAvgStability( void );
140 
141  inline void SetStateTarget(double target) { state_target=target; }
142  inline double GetStateTarget(void) { return state_target; }
143 
144  void AxisReport(void);
145 
146  bool InTolerance(void) { getState(); return (fabs(state_value) <= tolerance); }
147 
148 private:
149  FGFDMExec *fdmex;
150  FGInitialCondition *fgic;
151 
152  State state;
153  Control control;
154 
155  double state_target;
156 
157  double state_value;
158  double control_value;
159 
160  double control_min;
161  double control_max;
162 
163  double tolerance;
164 
165  double solver_eps;
166 
167  double state_convert;
168  double control_convert;
169 
170  int max_iterations;
171 
172  int its_to_stable_value;
173  int total_stability_iterations;
174  int total_iterations;
175 
176  void setThrottlesPct(void);
177 
178  void getState(void);
179  void getControl(void);
180  void setControl(void);
181 
182  double computeHmgt(void);
183 
184  void Debug(int from);
185 };
186 }
187 #endif
JSBSim::FGFDMExec
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:185
JSBSim::FGTrimAxis::~FGTrimAxis
~FGTrimAxis()
Destructor.
Definition: FGTrimAxis.cpp:159
JSBSim::FGJSBBase
JSBSim Base class.
Definition: FGJSBBase.h:78
JSBSim::FGInitialCondition
Initializes the simulation run.
Definition: FGInitialCondition.h:224
JSBSim::FGTrimAxis::FGTrimAxis
FGTrimAxis(FGFDMExec *fdmex, FGInitialCondition *IC, State state, Control control)
Constructor for Trim Axis class.
Definition: FGTrimAxis.cpp:61
JSBSim::FGTrimAxis
Definition: FGTrimAxis.h:87
JSBSim::FGTrimAxis::Run
void Run(void)
This function iterates through a call to the FGFDMExec::RunIC() function until the desired trimming c...
Definition: FGTrimAxis.cpp:245