<commit_before>/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 Header:       FGTrim.h
 Author:       <NAME>
 Date started: 7/1/99
 
 ------------- Copyright (C) 1999  <NAME> (<EMAIL>) -------------
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
 Foundation; either version 2 of the License, or (at your option) any later
 version.
 
 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 details.
 
 You should have received a copy of the GNU General Public License along with
 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Further information about the GNU General Public License can also be found on
 the world wide web at http://www.gnu.org.
 
 
 HISTORY
--------------------------------------------------------------------------------
9/8/99   TP   Created
 
 
FUNCTIONAL DESCRIPTION
--------------------------------------------------------------------------------
 
This class takes the given set of IC's and finds the aircraft state required to
maintain a specified flight condition.  This flight condition can be 
steady-level with non-zero sideslip, a steady turn, a pull-up or pushover.
On-ground conditions can be trimmed as well, but this is currently limited to
adjusting altitude and pitch angle only. It is implemented using an iterative,
one-axis-at-a-time scheme.  
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SENTRY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#ifndef FGTRIM_H
#define FGTRIM_H

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#include "FGFDMExec.h"
#include "FGJSBBase.h"
#include "FGTrimAxis.h"

#include <vector>

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#define ID_TRIM "$Id: FGTrim.h,v 1.28 2002/09/07 21:59:14 apeden Exp $"

typedef enum { tLongitudinal, tFull, tGround, tPullup, 
               tCustom, tNone, tTurn 
             } TrimMode;

#ifdef _WIN32
#define snprintf _snprintf
#endif

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS DOCUMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/** FGTrim -- 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:
    <ul>
    <li> tLongitudinal: Trim wdot with alpha, udot with thrust, qdot with elevator</li>
    <li> tFull: tLongitudinal + vdot with phi, pdot with aileron, rdot with rudder
                and heading minus ground track (hmgt) with beta</li>
    <li> tPullup: tLongitudinal but adjust alpha to achieve load factor input
         with SetTargetNlf()

    <li> tGround: wdot with altitude, qdot with theta, and pdot with phi</li>
    
    The remaining modes include <b>tCustom</b>, which is completely user defined and
    <b>tNone</b>.
    </ul>
    
    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->ReportState();  
    @author <NAME>
    @version $Id: FGTrim.h,v 1.28 2002/09/07 21:59:14 apeden Exp $
    @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGTrim.h?rev=HEAD&content-type=text/vnd.viewcvs-markup">
         Header File </a>
    @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGTrim.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">
         Source File </a>
*/       
  
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS DECLARATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

class FGTrim : public FGJSBBase
{
private:

  vector<FGTrimAxis*> TrimAxes;
  unsigned int current_axis;
  int N, Nsub;
  TrimMode mode;
  int DebugLevel, Debug;
  double Tolerance, A_Tolerance;
  double wdot,udot,qdot;<commit_msg>Fixed FGTrim so it doesn't die on the snprintf call<commit_after>/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 Header:       FGTrim.h
 Author:       <NAME>
 Date started: 7/1/99
 
 ------------- Copyright (C) 1999  <NAME> (<EMAIL>) -------------
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
 Foundation; either version 2 of the License, or (at your option) any later
 version.
 
 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 details.
 
 You should have received a copy of the GNU General Public License along with
 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 Place - Suite 330, Boston, MA  02111-1307, USA.
 
 Further information about the GNU General Public License can also be found on
 the world wide web at http://www.gnu.org.
 
 
 HISTORY
--------------------------------------------------------------------------------
9/8/99   TP   Created
 
 
FUNCTIONAL DESCRIPTION
--------------------------------------------------------------------------------
 
This class takes the given set of IC's and finds the aircraft state required to
maintain a specified flight condition.  This flight condition can be 
steady-level with non-zero sideslip, a steady turn, a pull-up or pushover.
On-ground conditions can be trimmed as well, but this is currently limited to
adjusting altitude and pitch angle only. It is implemented using an iterative,
one-axis-at-a-time scheme.  
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SENTRY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#ifndef FGTRIM_H
#define FGTRIM_H

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#include "FGFDMExec.h"
#include "FGJSBBase.h"
#include "FGTrimAxis.h"

#include <vector>

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#define ID_TRIM "$Id: FGTrim.h,v 1.29 2002/11/20 04:27:58 jberndt Exp $"

typedef enum { tLongitudinal, tFull, tGround, tPullup, 
               tCustom, tNone, tTurn 
             } TrimMode;

#if defined(_WIN32) && !defined(__CYGWIN__)
  #define snprintf _snprintf
#endif

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS DOCUMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/** FGTrim -- 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:
    <ul>
    <li> tLongitudinal: Trim wdot with alpha, udot with thrust, qdot with elevator</li>
    <li> tFull: tLongitudinal + vdot with phi, pdot with aileron, rdot with rudder
                and heading minus ground track (hmgt) with beta</li>
    <li> tPullup: tLongitudinal but adjust alpha to achieve load factor input
         with SetTargetNlf()

    <li> tGround: wdot with altitude, qdot with theta, and pdot with phi</li>
    
    The remaining modes include <b>tCustom</b>, which is completely user defined and
    <b>tNone</b>.
    </ul>
    
    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->ReportState();  
    @author <NAME>
    @version $Id: FGTrim.h,v 1.29 2002/11/20 04:27:58 jberndt Exp $
    @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGTrim.h?rev=HEAD&content-type=text/vnd.viewcvs-markup">
         Header File </a>
    @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGTrim.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">
         Source File </a>
*/       
  
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS DECLARATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

class FGTrim : public FGJSBBase
{
private:

  vector<FGTrimAxis*> TrimAxes;
  unsigned int current_axis;
  int N, Nsub;
  TrimMode mode;
  int DebugLevel, Debug;
  double Tolerance, A_Tolerance;
  double wdot,udot,qdot;
{'fraction_non_alphanumeric': 0.2779623477297896, 'fraction_numerical': 0.011548805568739124, 'mean_word_length': 3.763752825923135, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6994810', 'n_tokens_mistral': 3623, 'n_tokens_neox': 3193, 'n_words': 1207}