36# pragma warning (disable : 4786)
70 its_to_stable_value=0;
72 total_stability_iterations=0;
84 case tHmgt: tolerance = 0.01;
break;
85 case tNlf: state_target=1.0; tolerance = 1E-5;
break;
102 control_min=fdmex->GetAerodynamics()->GetAlphaCLMin();
103 control_max=fdmex->GetAerodynamics()->GetAlphaCLMax();
104 if(control_max <= control_min) {
108 control_value= (control_min+control_max)/2;
110 solver_eps=tolerance/100;
121 solver_eps=tolerance/100;
127 solver_eps=tolerance/100;
141 solver_eps=tolerance/100;
166void FGTrimAxis::getState(
void) {
174 case tHmgt: state_value=computeHmgt()-state_target;
break;
184void FGTrimAxis::getControl(
void) {
186 case tThrottle: control_value=fdmex->GetFCS()->GetThrottleCmd(0);
break;
187 case tBeta: control_value=fdmex->GetAuxiliary()->Getbeta();
break;
188 case tAlpha: control_value=fdmex->GetAuxiliary()->Getalpha();
break;
189 case tPitchTrim: control_value=fdmex->GetFCS() -> GetPitchTrimCmd();
break;
190 case tElevator: control_value=fdmex->GetFCS() -> GetDeCmd();
break;
192 case tAileron: control_value=fdmex->GetFCS() -> GetDaCmd();
break;
194 case tRudder: control_value=fdmex->GetFCS() -> GetDrCmd();
break;
195 case tAltAGL: control_value=fdmex->GetPropagate()->GetDistanceAGL();
break;
196 case tTheta: control_value=fdmex->GetPropagate()->GetEuler(
eTht);
break;
197 case tPhi: control_value=fdmex->GetPropagate()->GetEuler(
ePhi);
break;
198 case tGamma: control_value=fdmex->GetAuxiliary()->GetGamma();
break;
199 case tHeading: control_value=fdmex->GetPropagate()->GetEuler(
ePsi);
break;
205double FGTrimAxis::computeHmgt(
void) {
208 diff = fdmex->GetPropagate()->GetEuler(
ePsi) -
209 fdmex->GetAuxiliary()->GetGroundTrack();
212 return (diff + 2*
M_PI);
213 }
else if( diff >
M_PI ) {
214 return (diff - 2*
M_PI);
224void FGTrimAxis::setControl(
void) {
226 case tThrottle: setThrottlesPct();
break;
227 case tBeta: fgic->SetBetaRadIC(control_value);
break;
228 case tAlpha: fgic->SetAlphaRadIC(control_value);
break;
229 case tPitchTrim: fdmex->GetFCS()->SetPitchTrimCmd(control_value);
break;
230 case tElevator: fdmex->GetFCS()->SetDeCmd(control_value);
break;
232 case tAileron: fdmex->GetFCS()->SetDaCmd(control_value);
break;
234 case tRudder: fdmex->GetFCS()->SetDrCmd(control_value);
break;
235 case tAltAGL: fgic->SetAltitudeAGLFtIC(control_value);
break;
236 case tTheta: fgic->SetThetaRadIC(control_value);
break;
237 case tPhi: fgic->SetPhiRadIC(control_value);
break;
238 case tGamma: fgic->SetFlightPathAngleRadIC(control_value);
break;
239 case tHeading: fgic->SetPsiRadIC(control_value);
break;
247 double last_state_value;
255 last_state_value=state_value;
256 fdmex->Initialize(fgic);
260 if((fabs(last_state_value - state_value) < tolerance) || (
i >= 100) )
265 its_to_stable_value=
i;
266 total_stability_iterations+=its_to_stable_value;
272void FGTrimAxis::setThrottlesPct(
void) {
293 std::ios_base::fmtflags originalFormat = cout.flags();
294 std::streamsize originalPrecision = cout.precision();
295 std::streamsize originalWidth = cout.width();
297 cout << setw(6) << setprecision(2) <<
GetControl()*control_convert <<
' ';
299 cout << setw(9) << setprecision(2) << scientific <<
GetState()+state_target;
300 cout <<
" Tolerance: " << setw(3) << setprecision(0) << scientific <<
GetTolerance();
303 cout <<
" Passed" << endl;
305 cout <<
" Failed" << endl;
307 cout.flags(originalFormat);
308 cout.precision(originalPrecision);
309 cout.width(originalWidth);
315 if(total_iterations > 0) {
316 return double(total_stability_iterations)/double(total_iterations);
340void FGTrimAxis::Debug(
int from)
350 if (from == 0) cout <<
"Instantiated: FGTrimAxis" << endl;
351 if (from == 1) cout <<
"Destroyed: FGTrimAxis" << endl;
#define DEFAULT_TOLERANCE
const FGColumnVector3 & GetUVWdot(void) const
Retrieves the body axis acceleration.
const FGColumnVector3 & GetPQRdot(void) const
Retrieves the body axis angular acceleration vector.
double GetNlf(void) const
virtual double GetThrottleMax(void) const
virtual double GetThrottleMin(void) const
void SetThrottleCmd(int engine, double cmd)
Sets the throttle command for the specified engine.
FGPropulsion * GetPropulsion(void)
Returns the FGPropulsion pointer.
FGFCS * GetFCS(void)
Returns the FGFCS pointer.
void Initialize(FGInitialCondition *FGIC)
Initializes the simulation with initial conditions.
FGAccelerations * GetAccelerations(void)
Returns the FGAccelerations pointer.
bool Run(void)
This function executes each scheduled model in succession.
FGAuxiliary * GetAuxiliary(void)
Returns the FGAuxiliary pointer.
double GetPhiRadIC(void) const
Gets the initial roll angle.
double GetAltitudeAGLFtIC(void) const
Gets the initial altitude above ground level.
double GetThetaRadIC(void) const
Gets the initial pitch angle.
double GetPsiRadIC(void) const
Gets the initial heading angle.
static constexpr double radtodeg
static constexpr double degtorad
struct FGEngine::Inputs in
bool GetSteadyState(void)
Loops the engines until thrust output steady (used for trimming)
FGEngine * GetEngine(unsigned int index) const
Retrieves an engine object pointer from the list of engines.
std::string GetStateName(void)
double GetAvgStability(void)
std::string GetControlName(void)
FGTrimAxis(FGFDMExec *fdmex, FGInitialCondition *IC, State state, Control control)
Constructor for Trim Axis class.
double GetTolerance(void)
void Run(void)
This function iterates through a call to the FGFDMExec::RunIC() function until the desired trimming c...
State
Models an aircraft axis for purposes of trimming.