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.
27 --------------------------------------------------------------------------------
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43 #include "FGFDMExec.h"
44 #include "FGJSBBase.h"
45 #include "FGInitialCondition.h"
47 #define ID_TRIMAXIS "$Id$"
49 #define DEFAULT_TOLERANCE 0.001
53 const string StateNames[10]= { "all","udot","vdot","wdot","qdot","pdot","rdot",
56 const string ControlNames[14]= { "Throttle","Sideslip","Angle of Attack",
57 "Elevator","Ailerons","Rudder",
58 "Altitude AGL", "Pitch Angle",
59 "Roll Angle", "Flight Path Angle",
60 "Pitch Trim", "Roll Trim", "Yaw Trim",
64 class FGInitialCondition;
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70 enum State { tAll,tUdot,tVdot,tWdot,tQdot,tPdot,tRdot,tHmgt,tNlf };
71 enum Control { tThrottle, tBeta, tAlpha, tElevator, tAileron, tRudder, tAltAGL,
72 tTheta, tPhi, tGamma, tPitchTrim, tRollTrim, tYawTrim, tHeading };
74 class FGTrimAxis : public FGJSBBase
77 FGTrimAxis(FGFDMExec* fdmex,
78 FGInitialCondition *ic,
85 double GetState(void) { getState(); return state_value; }
86 //Accels are not settable
87 inline void SetControl(double value ) { control_value=value; }
88 inline double GetControl(void) { return control_value; }
90 inline State GetStateType(void) { return state; }
91 inline Control GetControlType(void) { return control; }
93 inline string GetStateName(void) { return StateNames[state]; }
94 inline string GetControlName(void) { return ControlNames[control]; }
96 inline double GetControlMin(void) { return control_min; }
97 inline double GetControlMax(void) { return control_max; }
99 inline void SetControlToMin(void) { control_value=control_min; }
100 inline void SetControlToMax(void) { control_value=control_max; }
102 inline void SetControlLimits(double min, double max) {
107 inline void SetTolerance(double ff) { tolerance=ff;}
108 inline double GetTolerance(void) { return tolerance; }
110 inline double GetSolverEps(void) { return solver_eps; }
111 inline void SetSolverEps(double ff) { solver_eps=ff; }
113 inline int GetIterationLimit(void) { return max_iterations; }
114 inline void SetIterationLimit(int ii) { max_iterations=ii; }
116 inline int GetStability(void) { return its_to_stable_value; }
117 inline int GetRunCount(void) { return total_stability_iterations; }
118 double GetAvgStability( void );
120 void SetThetaOnGround(double ff);
121 void SetPhiOnGround(double ff);
123 inline void SetStateTarget(float target) { state_target=target; }
124 inline float GetStateTarget(void) { return state_target; }
126 bool initTheta(void);
128 void AxisReport(void);
130 bool InTolerance(void) { getState(); return (fabs(state_value) <= tolerance); }
134 FGInitialCondition *fgic;
151 double state_convert;
152 double control_convert;
156 int its_to_stable_value;
157 int total_stability_iterations;
158 int total_iterations;
160 void setThrottlesPct(void);
163 void getControl(void);
164 void setControl(void);
166 double computeHmgt(void);
168 void Debug(int from);