![]() |
JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++
|
The trimming routine for JSBSim. More...
#include <FGTrim.h>
Inheritance diagram for FGTrim:
Collaboration diagram for FGTrim:Public Member Functions | |
| FGTrim (FGFDMExec *FDMExec, TrimMode tm=tGround) | |
| Initializes the trimming class. | |
| bool | AddState (State state, Control control) |
| Add a state-control pair to the current configuration. | |
| void | ClearDebug (void) |
| void | ClearStates (void) |
| Clear all state-control pairs from the current configuration. | |
| void | DebugState (State state) |
| Output debug data for one of the axes The State enum is defined in FGTrimAxis.h. | |
| bool | DoTrim (void) |
| Execute the trim. | |
| bool | EditState (State state, Control new_control) |
| Change the control used to zero a state previously configured. | |
| bool | GetGammaFallback (void) |
| query the fallback state | |
| double | GetTargetNlf (void) |
| bool | RemoveState (State state) |
| Remove a specific state-control pair from the current configuration. | |
| void | Report (void) |
| Print the results of the trim. | |
| void | SetDebug (int level) |
| Debug level 1 shows results of each top-level iteration Debug level 2 shows level 1 & results of each per-axis iteration. | |
| void | SetGammaFallback (bool bb) |
| automatically switch to trimming longitudinal acceleration with flight path angle (gamma) once it becomes apparent that there is not enough/too much thrust. | |
| void | SetMaxCycles (int ii) |
| Set the iteration limit. | |
| void | SetMaxCyclesPerAxis (int ii) |
| Set the per-axis iteration limit. | |
| void | SetMode (TrimMode tm) |
| Clear all state-control pairs and set a predefined trim mode. | |
| void | SetTargetNlf (double nlf) |
| void | SetTolerance (double tt) |
| Set the tolerance for declaring a state trimmed. | |
| void | TrimStats () |
| Iteration statistics. | |
FGTrim finds the aircraft attitude and control settings needed to maintain the steady state described by the FGInitialCondition object . It does this iteratively by assigning a control to each state and adjusting that control until the state is within a specified tolerance of zero. States include the recti-linear accelerations udot, vdot, and wdot, the angular accelerations qdot, pdot, and rdot, and the difference between heading and ground track. Controls include the usual flight deck controls available to the pilot plus angle of attack (alpha), sideslip angle(beta), flight path angle (gamma), pitch attitude(theta), roll attitude(phi), and altitude above ground. The last three are used for on-ground trimming. The state-control pairs used in a given trim are completely user configurable and several pre-defined modes are provided as well. They are:
The remaining modes include tCustom, which is completely user defined and tNone.
Note that trims can (and do) fail for reasons that are completely outside the control of the trimming routine itself. The most common problem is the initial conditions: is the model capable of steady state flight at those conditions? Check the speed, altitude, configuration (flaps, gear, etc.), weight, cg, and anything else that may be relevant.
Example usage:
FGFDMExec* FDMExec = new FGFDMExec(); FGInitialCondition* fgic = new FGInitialCondition(FDMExec); FGTrim fgt(FDMExec, fgic, tFull); fgic->SetVcaibratedKtsIC(100); fgic->SetAltitudeFtIC(1000); fgic->SetClimbRate(500); if( !fgt.DoTrim() ) { cout << "Trim Failed" << endl; } fgt.Report();
| FDMExec | pointer to a JSBSim executive object. |
| tm | trim mode |
Definition at line 62 of file FGTrim.cpp.
References FGFDMExec::GetIC().
{
N=Nsub=0;
max_iterations=60;
max_sub_iterations=100;
Tolerance=1E-3;
A_Tolerance = Tolerance / 10;
Debug=0;DebugLevel=0;
fdmex=FDMExec;
fgic=fdmex->GetIC();
total_its=0;
trimudot=true;
gamma_fallback=false;
axis_count=0;
mode=tt;
xlo=xhi=alo=ahi=0.0;
targetNlf=1.0;
debug_axis=tAll;
SetMode(tt);
if (debug_lvl & 2) cout << "Instantiated: FGTrim" << endl;
}
Here is the call graph for this function:| bool AddState | ( | State | state, |
| Control | control | ||
| ) |
See the enums State and Control in FGTrimAxis.h for the available options. Will fail if the given state is already configured.
| state | the accel or other condition to zero |
| control | the control used to zero the state |
Definition at line 146 of file FGTrim.cpp.
{
FGTrimAxis* ta;
bool result=true;
mode = tCustom;
vector <FGTrimAxis*>::iterator iAxes = TrimAxes.begin();
while (iAxes != TrimAxes.end()) {
ta=*iAxes;
if( ta->GetStateType() == state )
result=false;
iAxes++;
}
if(result) {
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,state,control));
delete[] sub_iterations;
delete[] successful;
delete[] solution;
sub_iterations=new double[TrimAxes.size()];
successful=new double[TrimAxes.size()];
solution=new bool[TrimAxes.size()];
}
return result;
}
| void ClearStates | ( | void | ) |
The trimming routine must have at least one state-control pair configured to be useful
Definition at line 129 of file FGTrim.cpp.
{
FGTrimAxis* ta;
mode=tCustom;
vector<FGTrimAxis*>::iterator iAxes;
iAxes = TrimAxes.begin();
while (iAxes != TrimAxes.end()) {
ta=*iAxes;
delete ta;
iAxes++;
}
TrimAxes.clear();
//cout << "TrimAxes.size(): " << TrimAxes.size() << endl;
}
| bool EditState | ( | State | state, |
| Control | new_control | ||
| ) |
| state | the accel or other condition to zero |
| new_control | the control used to zero the state |
Definition at line 201 of file FGTrim.cpp.
{
FGTrimAxis* ta;
bool result=false;
mode = tCustom;
vector <FGTrimAxis*>::iterator iAxes = TrimAxes.begin();
while (iAxes != TrimAxes.end()) {
ta=*iAxes;
if( ta->GetStateType() == state ) {
TrimAxes.insert(iAxes,1,new FGTrimAxis(fdmex,fgic,state,new_control));
delete ta;
TrimAxes.erase(iAxes+1);
result=true;
break;
}
iAxes++;
}
return result;
}
| bool GetGammaFallback | ( | void | ) | [inline] |
| bool RemoveState | ( | State | state | ) |
| state | the state to remove |
Definition at line 172 of file FGTrim.cpp.
{
FGTrimAxis* ta;
bool result=false;
mode = tCustom;
vector <FGTrimAxis*>::iterator iAxes = TrimAxes.begin();
while (iAxes != TrimAxes.end()) {
ta=*iAxes;
if( ta->GetStateType() == state ) {
delete ta;
iAxes = TrimAxes.erase(iAxes);
result=true;
continue;
}
iAxes++;
}
if(result) {
delete[] sub_iterations;
delete[] successful;
delete[] solution;
sub_iterations=new double[TrimAxes.size()];
successful=new double[TrimAxes.size()];
solution=new bool[TrimAxes.size()];
}
return result;
}
| void Report | ( | void | ) |
For each axis trimmed, this includes the final state value, control value, and tolerance used.
Definition at line 120 of file FGTrim.cpp.
Referenced by FGFDMExec::DoTrim().
{
cout << " Trim Results: " << endl;
for(current_axis=0; current_axis<TrimAxes.size(); current_axis++)
TrimAxes[current_axis]->AxisReport();
}
Here is the caller graph for this function:| void SetGammaFallback | ( | bool | bb | ) | [inline] |
| void SetMaxCycles | ( | int | ii | ) | [inline] |
| void SetMaxCyclesPerAxis | ( | int | ii | ) | [inline] |
| void SetMode | ( | TrimMode | tm | ) |
| tm | the set of axes to trim. Can be: tLongitudinal, tFull, tGround, tCustom, or tNone |
Definition at line 621 of file FGTrim.cpp.
{
ClearStates();
mode=tt;
switch(tt) {
case tFull:
if (debug_lvl > 0)
cout << " Full Trim" << endl;
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tWdot,tAlpha ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tUdot,tThrottle ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tQdot,tPitchTrim ));
//TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tHmgt,tBeta ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tVdot,tPhi ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tPdot,tAileron ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tRdot,tRudder ));
break;
case tLongitudinal:
if (debug_lvl > 0)
cout << " Longitudinal Trim" << endl;
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tWdot,tAlpha ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tUdot,tThrottle ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tQdot,tPitchTrim ));
break;
case tGround:
if (debug_lvl > 0)
cout << " Ground Trim" << endl;
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tWdot,tAltAGL ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tQdot,tTheta ));
//TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tPdot,tPhi ));
break;
case tPullup:
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tNlf,tAlpha ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tUdot,tThrottle ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tQdot,tPitchTrim ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tHmgt,tBeta ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tVdot,tPhi ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tPdot,tAileron ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tRdot,tRudder ));
break;
case tTurn:
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tWdot,tAlpha ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tUdot,tThrottle ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tQdot,tPitchTrim ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tVdot,tBeta ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tPdot,tAileron ));
TrimAxes.push_back(new FGTrimAxis(fdmex,fgic,tRdot,tRudder ));
break;
case tCustom:
case tNone:
break;
}
//cout << "TrimAxes.size(): " << TrimAxes.size() << endl;
sub_iterations=new double[TrimAxes.size()];
successful=new double[TrimAxes.size()];
solution=new bool[TrimAxes.size()];
current_axis=0;
}
| void SetTolerance | ( | double | tt | ) | [inline] |