JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++

FGTrim Class Reference

The trimming routine for JSBSim. More...

#include <FGTrim.h>

Inheritance diagram for FGTrim:
Collaboration diagram for FGTrim:

List of all members.

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.

Detailed Description

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:

  • tLongitudinal: Trim wdot with alpha, udot with thrust, qdot with elevator
  • tFull: tLongitudinal + vdot with phi, pdot with aileron, rdot with rudder and heading minus ground track (hmgt) with beta
  • tPullup: tLongitudinal but adjust alpha to achieve load factor input with SetTargetNlf()
  • tGround: wdot with altitude, qdot with theta, and pdot with phi

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();
Author:
Tony Peden
Version:
"$Id: FGTrim.h,v 1.8 2011/01/24 13:01:55 jberndt Exp $"

Definition at line 130 of file FGTrim.h.


Constructor & Destructor Documentation

FGTrim ( FGFDMExec FDMExec,
TrimMode  tm = tGround 
)
Parameters:
FDMExecpointer to a JSBSim executive object.
tmtrim 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:


Member Function Documentation

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.

Parameters:
statethe accel or other condition to zero
controlthe control used to zero the state
Returns:
true if add is successful

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 
)
Parameters:
statethe accel or other condition to zero
new_controlthe 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]
Returns:
true if fallback is enabled.

Definition at line 248 of file FGTrim.h.

{ return gamma_fallback; }
bool RemoveState ( State  state)
Parameters:
statethe state to remove
Returns:
true if removal is successful

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.

Returns:
true if trim succeeds

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]
Parameters:
bbtrue to enable fallback

Definition at line 243 of file FGTrim.h.

{ gamma_fallback=bb; }
void SetMaxCycles ( int  ii) [inline]

DoTrim() will return false if limit iterations are reached before trim is achieved. The default is 60. This does not ordinarily need to be changed.

Parameters:
iiinteger iteration limit

Definition at line 255 of file FGTrim.h.

{ max_iterations = ii; }
void SetMaxCyclesPerAxis ( int  ii) [inline]

Attempt to zero each state by iterating limit times before moving on to the next. The default limit is 100 and also does not ordinarily need to be changed.

Parameters:
iiinteger iteration limit

Definition at line 263 of file FGTrim.h.

{ max_sub_iterations = ii; }
void SetMode ( TrimMode  tm)
Parameters:
tmthe 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]

Angular accels are held to a tolerance of 1/10th of the given. The default is 0.001 for the recti-linear accelerations and 0.0001 for the angular.

Definition at line 269 of file FGTrim.h.

                                      {
    Tolerance = tt;
    A_Tolerance = tt / 10;
  }

The documentation for this class was generated from the following files: