| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#ifndef FGTRIMAXIS_H |
| 35 |
#define FGTRIMAXIS_H |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
#include <string> |
| 42 |
|
| 43 |
#include "FGFDMExec.h" |
| 44 |
#include "FGJSBBase.h" |
| 45 |
#include "FGInitialCondition.h" |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
#define DEFAULT_TOLERANCE 0.001 |
| 52 |
|
| 53 |
|
| 54 |
|
| 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 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 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: |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
FGTrimAxis(FGFDMExec* fdmex, |
| 96 |
FGInitialCondition *IC, |
| 97 |
State state, |
| 98 |
Control control ); |
| 99 |
|
| 100 |
~FGTrimAxis(); |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
void Run(void); |
| 105 |
|
| 106 |
double GetState(void) { getState(); return state_value; } |
| 107 |
|
| 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 |