JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGTrim.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Header: FGTrim.h
4  Author: Tony Peden
5  Date started: 7/1/99
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 
27  HISTORY
28 --------------------------------------------------------------------------------
29 9/8/99 TP Created
30 
31 
32 FUNCTIONAL DESCRIPTION
33 --------------------------------------------------------------------------------
34 
35 This class takes the given set of IC's and finds the aircraft state required to
36 maintain a specified flight condition. This flight condition can be
37 steady-level with non-zero sideslip, a steady turn, a pull-up or pushover.
38 On-ground conditions can be trimmed as well, but this is currently limited to
39 adjusting altitude and pitch angle only. It is implemented using an iterative,
40 one-axis-at-a-time scheme.
41 
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 SENTRY
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 
46 #ifndef FGTRIM_H
47 #define FGTRIM_H
48 
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 INCLUDES
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52 
53 #include "FGFDMExec.h"
54 #include "FGJSBBase.h"
55 #include "FGTrimAxis.h"
56 
57 #include <vector>
58 
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 DEFINITIONS
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 
63 #define ID_TRIM "$Id: FGTrim.h,v 1.11 2014/05/01 18:32:54 bcoconni Exp $"
64 
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 FORWARD DECLARATIONS
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68 
69 namespace JSBSim {
70 
71 typedef enum { tLongitudinal=0, tFull, tGround, tPullup,
72  tCustom, tTurn, tNone } TrimMode;
73 
74 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 CLASS DOCUMENTATION
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
77 
126 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 CLASS DECLARATION
128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
129 
130 class FGTrim : public FGJSBBase
131 {
132 private:
133 
134  std::vector<FGTrimAxis> TrimAxes;
135  unsigned int Nsub;
136  TrimMode mode;
137  int DebugLevel, Debug;
138  double Tolerance, A_Tolerance;
139  std::vector<double> sub_iterations, successful;
140  std::vector<bool> solution;
141  unsigned int max_sub_iterations;
142  unsigned int max_iterations;
143  unsigned int total_its;
144  bool gamma_fallback;
145  int solutionDomain;
146  double xlo,xhi,alo,ahi;
147  double targetNlf;
148  int debug_axis;
149 
150  double psidot;
151 
152  FGFDMExec* fdmex;
153  FGInitialCondition fgic;
154 
155  bool solve(FGTrimAxis& axis);
156 
164  bool findInterval(FGTrimAxis& axis);
165 
166  bool checkLimits(FGTrimAxis& axis);
167 
168  void setupPullup(void);
169  void setupTurn(void);
170 
171  void updateRates(void);
172  void setDebug(FGTrimAxis& axis);
173 
174  struct ContactPoints {
175  FGColumnVector3 location;
176  FGColumnVector3 normal;
177  };
178 
179  struct RotationParameters {
180  double angleMin;
181  std::vector<ContactPoints>::iterator contactRef;
182  };
183 
184  void trimOnGround(void);
185  RotationParameters calcRotation(std::vector<ContactPoints>& contacts,
186  const FGColumnVector3& rotationAxis,
187  const FGColumnVector3& contact0);
188 
189 public:
194  FGTrim(FGFDMExec *FDMExec, TrimMode tm=tGround );
195 
196  ~FGTrim(void);
197 
200  bool DoTrim(void);
201 
207  void Report(void);
208 
211  void TrimStats();
212 
217  void SetMode(TrimMode tm);
218 
223  void ClearStates(void);
224 
232  bool AddState( State state, Control control );
233 
238  bool RemoveState( State state );
239 
244  bool EditState( State state, Control new_control );
245 
251  inline void SetGammaFallback(bool bb) { gamma_fallback=bb; }
252 
256  inline bool GetGammaFallback(void) { return gamma_fallback; }
257 
263  inline void SetMaxCycles(int ii) { max_iterations = ii; }
264 
271  inline void SetMaxCyclesPerAxis(int ii) { max_sub_iterations = ii; }
272 
277  inline void SetTolerance(double tt) {
278  Tolerance = tt;
279  A_Tolerance = tt / 10;
280  }
281 
286  inline void SetDebug(int level) { DebugLevel = level; }
287  inline void ClearDebug(void) { DebugLevel = 0; }
288 
293  inline void DebugState(State state) { debug_axis=state; }
294 
295  inline void SetTargetNlf(double nlf) { targetNlf=nlf; }
296  inline double GetTargetNlf(void) { return targetNlf; }
297 
298 };
299 }
300 
301 #endif
bool AddState(State state, Control control)
Add a state-control pair to the current configuration.
Definition: FGTrim.cpp:134
void SetTolerance(double tt)
Set the tolerance for declaring a state trimmed.
Definition: FGTrim.h:277
void Report(void)
Print the results of the trim.
Definition: FGTrim.cpp:117
bool GetGammaFallback(void)
query the fallback state
Definition: FGTrim.h:256
void SetMaxCyclesPerAxis(int ii)
Set the per-axis iteration limit.
Definition: FGTrim.h:271
void SetMode(TrimMode tm)
Clear all state-control pairs and set a predefined trim mode.
Definition: FGTrim.cpp:796
JSBSim Base class.
Definition: FGJSBBase.h:80
This class implements a 3 element column vector.
bool EditState(State state, Control new_control)
Change the control used to zero a state previously configured.
Definition: FGTrim.cpp:175
The trimming routine for JSBSim.
Definition: FGTrim.h:130
void SetDebug(int level)
Debug level 1 shows results of each top-level iteration Debug level 2 shows level 1 & results of each...
Definition: FGTrim.h:286
void SetGammaFallback(bool bb)
automatically switch to trimming longitudinal acceleration with flight path angle (gamma) once it bec...
Definition: FGTrim.h:251
Initializes the simulation run.
bool RemoveState(State state)
Remove a specific state-control pair from the current configuration.
Definition: FGTrim.cpp:152
FGTrim(FGFDMExec *FDMExec, TrimMode tm=tGround)
Initializes the trimming class.
Definition: FGTrim.cpp:65
void DebugState(State state)
Output debug data for one of the axes The State enum is defined in FGTrimAxis.h.
Definition: FGTrim.h:293
void ClearStates(void)
Clear all state-control pairs from the current configuration.
Definition: FGTrim.cpp:126
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:189
void SetMaxCycles(int ii)
Set the iteration limit.
Definition: FGTrim.h:263
bool DoTrim(void)
Execute the trim.
Definition: FGTrim.cpp:190
void TrimStats()
Iteration statistics.
Definition: FGTrim.cpp:96