1 /*******************************************************************************
7 ------------- Copyright (C) 1999 Anthony K. Peden (apeden@earthlink.net) -------------
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
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
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.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
28 --------------------------------------------------------------------------------
32 FUNCTIONAL DESCRIPTION
33 --------------------------------------------------------------------------------
35 This class takes the given set of IC's and finds the angle of attack, elevator,
36 and throttle setting required to fly steady level. This is currently for in-air
37 conditions only. It is implemented using an iterative, one-axis-at-a-time
42 ********************************************************************************
44 *******************************************************************************/
49 /*******************************************************************************
51 *******************************************************************************/
53 #include "FGFDMExec.h"
54 #include "FGRotation.h"
55 #include "FGAtmosphere.h"
58 #include "FGAircraft.h"
59 #include "FGTranslation.h"
60 #include "FGPosition.h"
61 #include "FGAuxiliary.h"
63 #include "FGTrimLong.h"
68 #define THROTTLE_MIN 0
69 #define THROTTLE_MAX 1
71 /*******************************************************************************
73 *******************************************************************************/
78 typedef float (FGTrimLong::*trimfp)(float);
79 int Ncycles,Naxis,Debug;
80 float Tolerance, A_Tolerance;
81 float alphaMin, alphaMax;
84 float udot_subits, wdot_subits, qdot_subits;
89 trimfp udotf,wdotf,qdotf;
91 FGInitialCondition* fgic;
93 void setThrottlesPct(float tt);
94 int checkLimits(trimfp fp,float current,float min, float max);
95 // returns false if no sign change in fp(min)*fp(max) => no solution
96 bool solve(trimfp fp,float guess,float desired,float *result,float eps,float min, float max,int max_iterations,int *actual_its );
97 bool findInterval(trimfp fp, float *lo, float *hi,float guess,float desired,int max_iterations);
99 float udot_func(float x);
100 float wdot_func(float x);
101 float qdot_func(float x);
104 FGTrimLong(FGFDMExec *FDMExec, FGInitialCondition *FGIC);
110 void ReportState(void);
113 inline void SetUdotTrim(bool bb) { trimudot=bb; }
115 inline bool GetUdotTrim(void) { return trimudot; }
117 inline void SetMaxCycles(int ii) { Ncycles = ii; }
118 inline void SetMaxCyclesPerAxis(int ii) { Naxis = ii; }
119 inline void SetTolerance(float tt) {
121 A_Tolerance = tt / 10;
123 //Debug level 1 shows results of each top-level iteration
124 //Debug level 2 shows level 1 & results of each per-axis iteration
125 inline void SetDebug(int level) { Debug = level; }
126 inline void ClearDebug(void) { Debug = 0; }