JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGTrim Class Reference

Detailed Description

The trimming routine for JSBSim.

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();
FGTrim fgt(FDMExec, fgic, tFull);
fgic->SetVcaibratedKtsIC(100);
fgic->SetAltitudeFtIC(1000);
fgic->SetClimbRate(500);
if( !fgt.DoTrim() ) {
std::cout << "Trim Failed" << std::endl;
}
fgt.Report();
Encapsulates the JSBSim simulation executive.
Definition FGFDMExec.h:185
Initializes the simulation run.
The trimming routine for JSBSim.
Definition FGTrim.h:126
Author
Tony Peden

Definition at line 125 of file FGTrim.h.

#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.
 
- Public Member Functions inherited from FGJSBBase
 FGJSBBase ()
 Constructor for FGJSBBase.
 
virtual ~FGJSBBase ()
 Destructor for FGJSBBase.
 
void disableHighLighting (void)
 Disables highlighting in the console output.
 

Additional Inherited Members

- Public Types inherited from FGJSBBase
enum  { eL = 1 , eM , eN }
 Moments L, M, N. More...
 
enum  { eP = 1 , eQ , eR }
 Rates P, Q, R. More...
 
enum  { eU = 1 , eV , eW }
 Velocities U, V, W. More...
 
enum  { eX = 1 , eY , eZ }
 Positions X, Y, Z. More...
 
enum  { ePhi = 1 , eTht , ePsi }
 Euler angles Phi, Theta, Psi. More...
 
enum  { eDrag = 1 , eSide , eLift }
 Stability axis forces, Drag, Side force, Lift. More...
 
enum  { eRoll = 1 , ePitch , eYaw }
 Local frame orientation Roll, Pitch, Yaw. More...
 
enum  { eNorth = 1 , eEast , eDown }
 Local frame position North, East, Down. More...
 
enum  { eLat = 1 , eLong , eRad }
 Locations Radius, Latitude, Longitude. More...
 
enum  {
  inNone = 0 , inDegrees , inRadians , inMeters ,
  inFeet
}
 Conversion specifiers. More...
 
- Static Public Member Functions inherited from FGJSBBase
static const std::string & GetVersion (void)
 Returns the version number of JSBSim.
 
static constexpr double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit.
 
static constexpr double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine.
 
static constexpr double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius.
 
static constexpr double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine.
 
static constexpr double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin.
 
static constexpr double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius.
 
static constexpr double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit.
 
static constexpr double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin.
 
static constexpr double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius.
 
static constexpr double FeetToMeters (double measure)
 Converts from feet to meters.
 
static bool EqualToRoundoff (double a, double b)
 Finite precision comparison.
 
static bool EqualToRoundoff (float a, float b)
 Finite precision comparison.
 
static bool EqualToRoundoff (float a, double b)
 Finite precision comparison.
 
static bool EqualToRoundoff (double a, float b)
 Finite precision comparison.
 
static constexpr double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
static constexpr double sign (double num)
 
- Static Public Attributes inherited from FGJSBBase
static char highint [5] = {27, '[', '1', 'm', '\0' }
 highlights text
 
static char halfint [5] = {27, '[', '2', 'm', '\0' }
 low intensity text
 
static char normint [6] = {27, '[', '2', '2', 'm', '\0' }
 normal intensity text
 
static char reset [5] = {27, '[', '0', 'm', '\0' }
 resets text properties
 
static char underon [5] = {27, '[', '4', 'm', '\0' }
 underlines text
 
static char underoff [6] = {27, '[', '2', '4', 'm', '\0' }
 underline off
 
static char fgblue [6] = {27, '[', '3', '4', 'm', '\0' }
 blue text
 
static char fgcyan [6] = {27, '[', '3', '6', 'm', '\0' }
 cyan text
 
static char fgred [6] = {27, '[', '3', '1', 'm', '\0' }
 red text
 
static char fggreen [6] = {27, '[', '3', '2', 'm', '\0' }
 green text
 
static char fgdef [6] = {27, '[', '3', '9', 'm', '\0' }
 default text
 
static short debug_lvl = 1
 
- Static Protected Member Functions inherited from FGJSBBase
static std::string CreateIndexedPropertyName (const std::string &Property, int index)
 
- Static Protected Attributes inherited from FGJSBBase
static constexpr double radtodeg = 180. / M_PI
 
static constexpr double degtorad = M_PI / 180.
 
static constexpr double hptoftlbssec = 550.0
 
static constexpr double psftoinhg = 0.014138
 
static constexpr double psftopa = 47.88
 
static constexpr double fttom = 0.3048
 
static constexpr double ktstofps = 1852./(3600*fttom)
 
static constexpr double fpstokts = 1.0 / ktstofps
 
static constexpr double inchtoft = 1.0/12.0
 
static constexpr double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static constexpr double in3tom3 = inchtoft*inchtoft*inchtoft/m3toft3
 
static constexpr double inhgtopa = 3386.38
 
static constexpr double slugtolb = 32.174049
 Note that definition of lbtoslug by the inverse of slugtolb and not to a different constant you can also get from some tables will make lbtoslug*slugtolb == 1 up to the magnitude of roundoff.
 
static constexpr double lbtoslug = 1.0/slugtolb
 
static constexpr double kgtolb = 2.20462
 
static constexpr double kgtoslug = 0.06852168
 
static const std::string needed_cfg_version = "2.0"
 
static const std::string JSBSim_version = JSBSIM_VERSION " " __DATE__ " " __TIME__
 

Constructor & Destructor Documentation

◆ FGTrim()

FGTrim ( FGFDMExec FDMExec,
TrimMode  tm = tGround 
)

Initializes the trimming class.

Parameters
FDMExecpointer to a JSBSim executive object.
tmtrim mode

Definition at line 62 of file FGTrim.cpp.

63 : fgic(FDMExec)
64{
65
66 Nsub=0;
67 max_iterations=60;
68 max_sub_iterations=100;
69 Tolerance=1E-3;
70 A_Tolerance = Tolerance / 10;
71
72 Debug=0;DebugLevel=0;
73 fdmex=FDMExec;
74 fgic = *fdmex->GetIC();
75 total_its=0;
76 gamma_fallback=false;
77 mode=tt;
78 xlo=xhi=alo=ahi=0.0;
79 targetNlf=fgic.GetTargetNlfIC();
80 debug_axis=tAll;
81 SetMode(tt);
82 if (debug_lvl & 2) {
83 FGLogging log(LogLevel::DEBUG);
84 log << "Instantiated: FGTrim\n";
85 }
86}
std::shared_ptr< FGInitialCondition > GetIC(void) const
Returns a pointer to the FGInitialCondition object.
Definition FGFDMExec.h:390
double GetTargetNlfIC(void) const
Gets the target normal load factor set from IC.
void SetMode(TrimMode tm)
Clear all state-control pairs and set a predefined trim mode.
Definition FGTrim.cpp:833
+ Here is the call graph for this function:

◆ ~FGTrim()

~FGTrim ( void  )

Definition at line 90 of file FGTrim.cpp.

90 {
91 if (debug_lvl & 2) {
92 FGLogging log(LogLevel::DEBUG);
93 log << "Destroyed: FGTrim\n";
94 }
95}

Member Function Documentation

◆ AddState()

bool AddState ( State  state,
Control  control 
)

Add a state-control pair to the current configuration.

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 139 of file FGTrim.cpp.

139 {
140 mode = tCustom;
141 vector <FGTrimAxis>::iterator iAxes = TrimAxes.begin();
142 for (; iAxes != TrimAxes.end(); ++iAxes) {
143 if (iAxes->GetStateType() == state)
144 return false;
145 }
146
147 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,state,control));
148 sub_iterations.resize(TrimAxes.size());
149 successful.resize(TrimAxes.size());
150 solution.resize(TrimAxes.size());
151
152 return true;
153}

◆ ClearDebug()

void ClearDebug ( void  )
inline

Definition at line 280 of file FGTrim.h.

280{ DebugLevel = 0; }

◆ ClearStates()

void ClearStates ( void  )

Clear all state-control pairs from the current configuration.

The trimming routine must have at least one state-control pair configured to be useful

Definition at line 130 of file FGTrim.cpp.

130 {
131 mode=tCustom;
132 TrimAxes.clear();
133 //FGLogging log(LogLevel::INFO);
134 //log << "TrimAxes.size(): " << TrimAxes.size() << "\n";
135}
+ Here is the caller graph for this function:

◆ DebugState()

void DebugState ( State  state)
inline

Output debug data for one of the axes The State enum is defined in FGTrimAxis.h.

Definition at line 286 of file FGTrim.h.

286{ debug_axis=state; }

◆ DoTrim()

bool DoTrim ( void  )

Execute the trim.

Definition at line 195 of file FGTrim.cpp.

195 {
196 bool trim_failed=false;
197 unsigned int N = 0;
198 unsigned int axis_count = 0;
199 auto FCS = fdmex->GetFCS();
200 auto GroundReactions = fdmex->GetGroundReactions();
201 vector<double> throttle0 = FCS->GetThrottleCmd();
202 double elevator0 = FCS->GetDeCmd();
203 double aileron0 = FCS->GetDaCmd();
204 double rudder0 = FCS->GetDrCmd();
205 double PitchTrim0 = FCS->GetPitchTrimCmd();
206
207 for(int i=0;i < GroundReactions->GetNumGearUnits();i++)
208 GroundReactions->GetGearUnit(i)->SetReport(false);
209
210 fdmex->SetTrimStatus(true);
211 fdmex->SuspendIntegration();
212
213 fgic.SetPRadpsIC(0.0);
214 fgic.SetQRadpsIC(0.0);
215 fgic.SetRRadpsIC(0.0);
216
217 if (mode == tGround) {
218 fdmex->Initialize(&fgic);
219 fdmex->Run();
220 trimOnGround();
221 double theta = fgic.GetThetaRadIC();
222 double phi = fgic.GetPhiRadIC();
223 // Take opportunity of the first approx. found by trimOnGround() to
224 // refine the control limits.
225 TrimAxes[0].SetControlLimits(0., fgic.GetAltitudeAGLFtIC());
226 TrimAxes[1].SetControlLimits(theta - 5.0 * degtorad, theta + 5.0 * degtorad);
227 TrimAxes[2].SetControlLimits(phi - 30.0 * degtorad, phi + 30.0 * degtorad);
228 }
229
230 //clear the sub iterations counts & zero out the controls
231 for(unsigned int current_axis=0;current_axis<TrimAxes.size();current_axis++) {
232 //FGLogging log(LogLevel::INFO);
233 //log << current_axis << " " << TrimAxes[current_axis]->GetStateName()
234 //<< " " << TrimAxes[current_axis]->GetControlName()<< "\n";
235 xlo=TrimAxes[current_axis].GetControlMin();
236 xhi=TrimAxes[current_axis].GetControlMax();
237 TrimAxes[current_axis].SetControl((xlo+xhi)/2);
238 TrimAxes[current_axis].Run();
239 //TrimAxes[current_axis].AxisReport();
240 sub_iterations[current_axis]=0;
241 successful[current_axis]=0;
242 solution[current_axis]=false;
243 }
244
245 if(mode == tPullup ) {
246 FGLogging log(LogLevel::INFO);
247 log << "Setting pitch rate and nlf...\n";
248 setupPullup();
249 log << "pitch rate done ...\n";
250 TrimAxes[0].SetStateTarget(targetNlf);
251 log << "nlf done\n";
252 } else if (mode == tTurn) {
253 setupTurn();
254 //TrimAxes[0].SetStateTarget(targetNlf);
255 }
256
257 do {
258 axis_count=0;
259 for(unsigned int current_axis=0;current_axis<TrimAxes.size();current_axis++) {
260 setDebug(TrimAxes[current_axis]);
261 updateRates();
262 Nsub=0;
263 if(!solution[current_axis]) {
264 if(checkLimits(TrimAxes[current_axis])) {
265 solution[current_axis]=true;
266 solve(TrimAxes[current_axis]);
267 }
268 } else if(findInterval(TrimAxes[current_axis])) {
269 solve(TrimAxes[current_axis]);
270 } else {
271 solution[current_axis]=false;
272 }
273 sub_iterations[current_axis]+=Nsub;
274 }
275 for(unsigned int current_axis=0;current_axis<TrimAxes.size();current_axis++) {
276 //these checks need to be done after all the axes have run
277 if(Debug > 0) TrimAxes[current_axis].AxisReport();
278 if(TrimAxes[current_axis].InTolerance()) {
279 axis_count++;
280 successful[current_axis]++;
281 }
282 }
283
284 if((axis_count == TrimAxes.size()-1) && (TrimAxes.size() > 1)) {
285 //FGLogging log(LogLevel::INFO);
286 //log << TrimAxes.size()-1 << " out of " << TrimAxes.size() << "!" << "\n";
287 //At this point we can check the input limits of the failed axis
288 //and declare the trim failed if there is no sign change. If there
289 //is, keep going until success or max iteration count
290
291 //Oh, well: two out of three ain't bad
292 for(unsigned int current_axis=0;current_axis<TrimAxes.size();current_axis++) {
293 //these checks need to be done after all the axes have run
294 if(!TrimAxes[current_axis].InTolerance()) {
295 if(!checkLimits(TrimAxes[current_axis])) {
296 // special case this for now -- if other cases arise proper
297 // support can be added to FGTrimAxis
298 if( (gamma_fallback) &&
299 (TrimAxes[current_axis].GetStateType() == tUdot) &&
300 (TrimAxes[current_axis].GetControlType() == tThrottle)) {
301 FGLogging log(LogLevel::WARN);
302 log << " Can't trim udot with throttle, trying flight"
303 << " path angle. (" << N << ")\n";
304 if(TrimAxes[current_axis].GetState() > 0)
305 TrimAxes[current_axis].SetControlToMin();
306 else
307 TrimAxes[current_axis].SetControlToMax();
308 TrimAxes[current_axis].Run();
309 TrimAxes[current_axis]=FGTrimAxis(fdmex,&fgic,tUdot,tGamma);
310 } else {
311 FGLogging log(LogLevel::ERROR);
312 log << " Sorry, " << TrimAxes[current_axis].GetStateName()
313 << " doesn't appear to be trimmable\n";
314 //total_its=k;
315 trim_failed=true; //force the trim to fail
316 } //gamma_fallback
317 }
318 } //solution check
319 } //for loop
320 } //all-but-one check
321 N++;
322 if(N > max_iterations)
323 trim_failed=true;
324 } while((axis_count < TrimAxes.size()) && (!trim_failed));
325
326 if((!trim_failed) && (axis_count >= TrimAxes.size())) {
327 total_its=N;
328 if (debug_lvl > 0) {
329 FGLogging log(LogLevel::DEBUG);
330 log << "\n Trim successful\n";
331 }
332 } else { // The trim has failed
333 total_its=N;
334
335 // Restore the aircraft parameters to their initial values
336 fgic = *fdmex->GetIC();
337 FCS->SetDeCmd(elevator0);
338 FCS->SetDaCmd(aileron0);
339 FCS->SetDrCmd(rudder0);
340 FCS->SetPitchTrimCmd(PitchTrim0);
341 for (unsigned int i=0; i < throttle0.size(); i++)
342 FCS->SetThrottleCmd(i, throttle0[i]);
343
344 fdmex->Initialize(&fgic);
345 fdmex->Run();
346
347 // If WOW is true we must make sure there are no gears into the ground.
348 if (GroundReactions->GetWOW())
349 trimOnGround();
350
351 if (debug_lvl > 0) {
352 FGLogging log(LogLevel::DEBUG);
353 log << "\n Trim failed\n";
354 }
355 }
356
357 fdmex->GetPropagate()->InitializeDerivatives();
358 fdmex->ResumeIntegration();
359 fdmex->SetTrimStatus(false);
360
361 for(int i=0;i < GroundReactions->GetNumGearUnits();i++)
362 GroundReactions->GetGearUnit(i)->SetReport(true);
363
364 return !trim_failed;
365}
std::shared_ptr< FGFCS > GetFCS(void) const
Returns the FGFCS pointer.
std::shared_ptr< FGPropagate > GetPropagate(void) const
Returns the FGPropagate pointer.
bool Run(void)
This function executes each scheduled model in succession.
std::shared_ptr< FGGroundReactions > GetGroundReactions(void) const
Returns the FGGroundReactions pointer.
void SuspendIntegration(void)
Suspends the simulation and sets the delta T to zero.
Definition FGFDMExec.h:556
void Initialize(const FGInitialCondition *FGIC)
Initializes the simulation with initial conditions.
void ResumeIntegration(void)
Resumes the simulation by resetting delta T to the correct value.
Definition FGFDMExec.h:559
double GetPhiRadIC(void) const
Gets the initial roll angle.
void SetPRadpsIC(double P)
Sets the initial body axis roll rate.
double GetAltitudeAGLFtIC(void) const
Gets the initial altitude above ground level.
void SetRRadpsIC(double R)
Sets the initial body axis yaw rate.
void SetQRadpsIC(double Q)
Sets the initial body axis pitch rate.
double GetThetaRadIC(void) const
Gets the initial pitch angle.
+ Here is the call graph for this function:

◆ EditState()

bool EditState ( State  state,
Control  new_control 
)

Change the control used to zero a state previously configured.

Parameters
statethe accel or other condition to zero
new_controlthe control used to zero the state

Definition at line 180 of file FGTrim.cpp.

180 {
181 mode = tCustom;
182 vector <FGTrimAxis>::iterator iAxes = TrimAxes.begin();
183 while (iAxes != TrimAxes.end()) {
184 if( iAxes->GetStateType() == state ) {
185 *iAxes = FGTrimAxis(fdmex,&fgic,state,new_control);
186 return true;
187 }
188 ++iAxes;
189 }
190 return false;
191}

◆ GetGammaFallback()

bool GetGammaFallback ( void  )
inline

query the fallback state

Returns
true if fallback is enabled.

Definition at line 249 of file FGTrim.h.

249{ return gamma_fallback; }

◆ GetTargetNlf()

double GetTargetNlf ( void  )
inline

Definition at line 289 of file FGTrim.h.

289{ return targetNlf; }

◆ RemoveState()

bool RemoveState ( State  state)

Remove a specific state-control pair from the current configuration.

Parameters
statethe state to remove
Returns
true if removal is successful

Definition at line 157 of file FGTrim.cpp.

157 {
158 bool result=false;
159
160 mode = tCustom;
161 vector <FGTrimAxis>::iterator iAxes = TrimAxes.begin();
162 while (iAxes != TrimAxes.end()) {
163 if( iAxes->GetStateType() == state ) {
164 iAxes = TrimAxes.erase(iAxes);
165 result=true;
166 continue;
167 }
168 ++iAxes;
169 }
170 if(result) {
171 sub_iterations.resize(TrimAxes.size());
172 successful.resize(TrimAxes.size());
173 solution.resize(TrimAxes.size());
174 }
175 return result;
176}

◆ Report()

void Report ( void  )

Print the results of the trim.

For each axis trimmed, this includes the final state value, control value, and tolerance used.

Returns
true if trim succeeds

Definition at line 121 of file FGTrim.cpp.

121 {
122 FGLogging out(LogLevel::STDOUT);
123 out << " Trim Results:\n";
124 for(unsigned int current_axis=0; current_axis<TrimAxes.size(); current_axis++)
125 TrimAxes[current_axis].AxisReport();
126}

◆ SetDebug()

void SetDebug ( int  level)
inline

Debug level 1 shows results of each top-level iteration Debug level 2 shows level 1 & results of each per-axis iteration.

Definition at line 279 of file FGTrim.h.

279{ DebugLevel = level; }

◆ SetGammaFallback()

void SetGammaFallback ( bool  bb)
inline

automatically switch to trimming longitudinal acceleration with flight path angle (gamma) once it becomes apparent that there is not enough/too much thrust.

Parameters
bbtrue to enable fallback

Definition at line 244 of file FGTrim.h.

244{ gamma_fallback=bb; }

◆ SetMaxCycles()

void SetMaxCycles ( int  ii)
inline

Set the iteration limit.

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 256 of file FGTrim.h.

256{ max_iterations = ii; }

◆ SetMaxCyclesPerAxis()

void SetMaxCyclesPerAxis ( int  ii)
inline

Set the per-axis iteration limit.

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 264 of file FGTrim.h.

264{ max_sub_iterations = ii; }

◆ SetMode()

void SetMode ( TrimMode  tm)

Clear all state-control pairs and set a predefined trim mode.

Parameters
tmthe set of axes to trim. Can be: tLongitudinal, tFull, tGround, tCustom, or tNone

Definition at line 833 of file FGTrim.cpp.

833 {
834 ClearStates();
835 mode=tt;
836 switch(tt) {
837 case tFull:
838 if (debug_lvl > 0) {
839 FGLogging log(LogLevel::DEBUG);
840 log << " Full Trim\n";
841 }
842 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tWdot,tAlpha));
843 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tUdot,tThrottle ));
844 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tQdot,tPitchTrim ));
845 //TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tHmgt,tBeta ));
846 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tVdot,tPhi ));
847 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tPdot,tAileron ));
848 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tRdot,tRudder ));
849 break;
850 case tLongitudinal:
851 if (debug_lvl > 0) {
852 FGLogging log(LogLevel::DEBUG);
853 log << " Longitudinal Trim\n";
854 }
855 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tWdot,tAlpha ));
856 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tUdot,tThrottle ));
857 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tQdot,tPitchTrim ));
858 break;
859 case tGround:
860 if (debug_lvl > 0) {
861 FGLogging log(LogLevel::DEBUG);
862 log << " Ground Trim\n";
863 }
864 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tWdot,tAltAGL ));
865 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tQdot,tTheta ));
866 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tPdot,tPhi ));
867 break;
868 case tPullup:
869 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tNlf,tAlpha ));
870 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tUdot,tThrottle ));
871 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tQdot,tPitchTrim ));
872 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tHmgt,tBeta ));
873 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tVdot,tPhi ));
874 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tPdot,tAileron ));
875 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tRdot,tRudder ));
876 break;
877 case tTurn:
878 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tWdot,tAlpha ));
879 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tUdot,tThrottle ));
880 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tQdot,tPitchTrim ));
881 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tVdot,tBeta ));
882 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tPdot,tAileron ));
883 TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tRdot,tRudder ));
884 break;
885 case tCustom:
886 case tNone:
887 break;
888 }
889 //FGLogging log(LogLevel::INFO);
890 //log << "TrimAxes.size(): " << TrimAxes.size() << "\n";
891 sub_iterations.resize(TrimAxes.size());
892 successful.resize(TrimAxes.size());
893 solution.resize(TrimAxes.size());
894}
void ClearStates(void)
Clear all state-control pairs from the current configuration.
Definition FGTrim.cpp:130
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetTargetNlf()

void SetTargetNlf ( double  nlf)
inline

Definition at line 288 of file FGTrim.h.

288{ targetNlf=nlf; }

◆ SetTolerance()

void SetTolerance ( double  tt)
inline

Set the tolerance for declaring a state trimmed.

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 270 of file FGTrim.h.

270 {
271 Tolerance = tt;
272 A_Tolerance = tt / 10;
273 }

◆ TrimStats()

void TrimStats ( )

Iteration statistics.

Definition at line 99 of file FGTrim.cpp.

99 {
100 int run_sum=0;
101 FGLogging out(LogLevel::STDOUT);
102 out << "\n Trim Statistics:\n";
103 out << " Total Iterations: " << total_its << "\n";
104 if( total_its > 0) {
105 out << " Sub-iterations:\n";
106 for (unsigned int current_axis=0; current_axis<TrimAxes.size(); current_axis++) {
107 run_sum += TrimAxes[current_axis].GetRunCount();
108 out << " " << setw(5) << TrimAxes[current_axis].GetStateName().c_str()
109 << ": " << setprecision(3) << sub_iterations[current_axis]
110 << " average: " << setprecision(5) << sub_iterations[current_axis]/double(total_its)
111 << " successful: " << setprecision(3) << successful[current_axis]
112 << " stability: " << setprecision(5) << TrimAxes[current_axis].GetAvgStability()
113 << "\n";
114 }
115 out << " Run Count: " << run_sum << "\n";
116 }
117}

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