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 Lesser 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 Lesser General Public License for more
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.
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.
27 --------------------------------------------------------------------------------
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43 #include "FGFDMExec.h"
44 #include "FGJSBBase.h"
45 #include "FGInitialCondition.h"
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 #define ID_TRIMAXIS "$Id: FGTrimAxis.h,v 1.5 2010/09/07 18:36:29 andgi Exp $"
53 #define DEFAULT_TOLERANCE 0.001
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 const string StateNames[] = { "all","udot","vdot","wdot","qdot","pdot","rdot",
64 const 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",
72 class FGInitialCondition;
74 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
78 /** Models an aircraft axis for purposes of trimming.
81 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
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 };
89 class FGTrimAxis : public FGJSBBase
92 /** Constructor for Trim Axis class.
93 @param fdmex FGFDMExec pointer
94 @param IC pointer to initial conditions instance
95 @param state a State type (enum)
96 @param control a Control type (enum) */
97 FGTrimAxis(FGFDMExec* fdmex,
98 FGInitialCondition *IC,
104 /** This function iterates through a call to the FGFDMExec::RunIC()
105 function until the desired trimming condition falls inside a tolerance.*/
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; }
113 inline State GetStateType(void) { return state; }
114 inline Control GetControlType(void) { return control; }
116 inline string GetStateName(void) { return StateNames[state]; }
117 inline string GetControlName(void) { return ControlNames[control]; }
119 inline double GetControlMin(void) { return control_min; }
120 inline double GetControlMax(void) { return control_max; }
122 inline void SetControlToMin(void) { control_value=control_min; }
123 inline void SetControlToMax(void) { control_value=control_max; }
125 inline void SetControlLimits(double min, double max) {
130 inline void SetTolerance(double ff) { tolerance=ff;}
131 inline double GetTolerance(void) { return tolerance; }
133 inline double GetSolverEps(void) { return solver_eps; }
134 inline void SetSolverEps(double ff) { solver_eps=ff; }
136 inline int GetIterationLimit(void) { return max_iterations; }
137 inline void SetIterationLimit(int ii) { max_iterations=ii; }
139 inline int GetStability(void) { return its_to_stable_value; }
140 inline int GetRunCount(void) { return total_stability_iterations; }
141 double GetAvgStability( void );
143 void SetThetaOnGround(double ff);
144 void SetPhiOnGround(double ff);
146 inline void SetStateTarget(double target) { state_target=target; }
147 inline double GetStateTarget(void) { return state_target; }
149 bool initTheta(void);
151 void AxisReport(void);
153 bool InTolerance(void) { getState(); return (fabs(state_value) <= tolerance); }
157 FGInitialCondition *fgic;
165 double control_value;
174 double state_convert;
175 double control_convert;
179 int its_to_stable_value;
180 int total_stability_iterations;
181 int total_iterations;
183 void setThrottlesPct(void);
186 void getControl(void);
187 void setControl(void);
189 double computeHmgt(void);
191 void Debug(int from);