1
0
Fork 0
flightgear/src/FDM/JSBSim/FGFCS.h

490 lines
17 KiB
C
Raw Normal View History

2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-05 21:26:01 +00:00
Header: FGGFCS.h
Author: Jon S. Berndt
Date started: 12/12/98
1999-02-05 21:26:01 +00:00
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
1999-02-05 21:26:01 +00:00
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.
1999-02-05 21:26:01 +00:00
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.
1999-02-05 21:26:01 +00:00
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.
1999-02-05 21:26:01 +00:00
Further information about the GNU General Public License can also be found on
the world wide web at http://www.gnu.org.
1999-02-05 21:26:01 +00:00
HISTORY
--------------------------------------------------------------------------------
12/12/98 JSB Created
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-05 21:26:01 +00:00
SENTRY
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
1999-02-05 21:26:01 +00:00
#ifndef FGFCS_H
#define FGFCS_H
2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-05 21:26:01 +00:00
INCLUDES
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
1999-02-05 21:26:01 +00:00
2000-04-24 23:49:06 +00:00
#ifdef FGFS
# include <simgear/compiler.h>
# ifdef SG_HAVE_STD_INCLUDES
2000-04-24 23:49:06 +00:00
# include <vector>
# else
# include <vector.h>
# endif
#else
# include <vector>
#endif
#include <string>
2000-04-24 23:49:06 +00:00
#include "filtersjb/FGFCSComponent.h"
1999-02-05 21:26:01 +00:00
#include "FGModel.h"
2000-11-03 23:02:47 +00:00
#include "FGLGear.h"
2000-04-24 23:49:06 +00:00
#include "FGConfigFile.h"
2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
2001-03-30 01:04:50 +00:00
#define ID_FCS "$Id$"
2000-11-03 23:02:47 +00:00
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS DOCUMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/** Encapsulates the Flight Control System (FCS) functionality.
<ul><li>\URL[Source Code]{FGFCS.cpp.html}</li>
<li>\URL[Header File]{FGFCS.h.html}</li></ul>
This class owns and contains the list of \URL[components]{FGFCSComponent.html}
that define the control system for this aircraft. The config file for the
aircraft contains a description of the control path that starts at an input
or command and ends at an effector, e.g. an aerosurface. The FCS components
which comprise the control laws for an axis are defined sequentially in
the configuration file. For instance, for the X-15:
<pre>
&lt FLIGHT_CONTROL NAME="X-15 SAS"&gt
&lt COMPONENT NAME="Pitch Trim Sum" TYPE="SUMMER"&gt
ID 0
INPUT FG_ELEVATOR_CMD
2001-03-30 01:04:50 +00:00
INPUT FG_PITCH_TRIM_CMD
2000-11-03 23:02:47 +00:00
CLIPTO -1 1
&lt/COMPONENT&gt
&lt COMPONENT NAME="Pitch Command Scale" TYPE="AEROSURFACE_SCALE"&gt
ID 1
INPUT 0
MIN -50
MAX 50
&lt/COMPONENT&gt
&lt COMPONENT NAME="Pitch Gain 1" TYPE="PURE_GAIN"&gt
ID 2
INPUT 1
GAIN -0.36
&lt/COMPONENT&gt
&lt COMPONENT NAME="Pitch Scheduled Gain 1" TYPE="SCHEDULED_GAIN"&gt
ID 3
INPUT 2
GAIN 0.017
SCHEDULED_BY FG_ELEVATOR_POS
-0.35 -6.0
-0.17 -3.0
0.00 -2.0
0.09 -3.0
0.17 -5.0
0.60 -12.0
&lt/COMPONENT&gt
... etc.
</pre>
In the above case we can see the first few components of the pitch channel
defined. The input to the first component, as can be seen in the "Pitch trim
sum" component, is really the sum of two parameters: elevator command (from
the stick - a pilot input), and pitch trim. The type of this component is
"Summer". Its ID is 0 - the ID is used by other components to reference it.
The next component created is an aerosurface scale component - a type of
gain (see the LoadFCS() method for insight on how the various types of
components map into the actual component classes). You can see the input of
the "Pitch Command Scale" component takes "0" as input. When a number is
specified as an input, it refers to the ID of another FCS component. In this
case, ID 0 refers to the previously defined and discussed "Pitch Trim Sum"
component. This continues until the final component for an axis when the
OUTPUT keyword specifies where the output is supposed to go. See the
individual components for more information on how they are mechanized.
@author Jon S. Berndt
@version $Id$
@see FGFCSComponent
@see FGConfigFile
@see FGGain
@see FGSummer
@see FGSwitch
@see FGGradient
@see FGFilter
@see FGDeadBand
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1999-02-05 21:26:01 +00:00
CLASS DECLARATION
2000-11-03 23:02:47 +00:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
1999-02-05 21:26:01 +00:00
typedef enum { iDe=0, iDaL, iDaR, iDr, iDsb, iDsp, iDf } FcIdx;
int const NNorm=7;
typedef enum { ofRad=0, ofNorm, ofMag } OutputForm;
int const NForms=3;
class FGFCS : public FGModel {
2000-04-24 23:49:06 +00:00
1999-02-05 21:26:01 +00:00
public:
2000-11-03 23:02:47 +00:00
/** Constructor
@param Executive a pointer to the parent executive object */
FGFCS(FGFDMExec*);
2000-11-03 23:02:47 +00:00
/// Destructor
2001-03-30 01:04:50 +00:00
~FGFCS();
2000-11-03 23:02:47 +00:00
/** Runs the Flight Controls model; called by the Executive
@return false if no error */
bool Run(void);
2000-11-03 23:02:47 +00:00
/// @name Pilot input command retrieval
//@{
/** Gets the aileron command.
@return aileron command in percent */
inline double GetDaCmd(void) const { return DaCmd; }
2000-11-03 23:02:47 +00:00
/** Gets the elevator command.
@return elevator command in percent */
inline double GetDeCmd(void) const { return DeCmd; }
2000-11-03 23:02:47 +00:00
/** Gets the rudder command.
@return rudder command in percent */
inline double GetDrCmd(void) const { return DrCmd; }
2000-11-03 23:02:47 +00:00
/** Gets the flaps command.
@return flaps command in percent */
inline double GetDfCmd(void) const { return DfCmd; }
2000-11-03 23:02:47 +00:00
/** Gets the speedbrake command.
@return speedbrake command in percent */
inline double GetDsbCmd(void) const { return DsbCmd; }
2000-11-03 23:02:47 +00:00
/** Gets the spoiler command.
@return spoiler command in percent */
inline double GetDspCmd(void) const { return DspCmd; }
2000-11-03 23:02:47 +00:00
/** Gets the throttle command.
@param engine engine ID number
@return throttle command in percent ( 0 - 100) for the given engine */
2001-11-20 22:34:24 +00:00
double GetThrottleCmd(int engine);
2001-11-12 16:06:29 +00:00
/** Gets the mixture command.
@param engine engine ID number
@return mixture command in percent ( 0 - 100) for the given engine */
inline double GetMixtureCmd(int engine) const { return MixtureCmd[engine]; }
2001-11-12 16:06:29 +00:00
/** Gets the prop pitch command.
@param engine engine ID number
@return pitch command in percent ( 0.0 - 1.0) for the given engine */
inline double GetPropAdvanceCmd(int engine) const { return PropAdvanceCmd[engine]; }
2000-11-03 23:02:47 +00:00
/** Gets the pitch trim command.
@return pitch trim command in percent */
inline double GetPitchTrimCmd(void) const { return PTrimCmd; }
/** Gets the rudder trim command.
@return rudder trim command in percent */
inline double GetYawTrimCmd(void) const { return YTrimCmd; }
/** Gets the aileron trim command.
@return aileron trim command in percent */
inline double GetRollTrimCmd(void) const { return RTrimCmd; }
/** Get the gear extend/retract command. 0 commands gear up, 1 down.
defaults to down.
@return the current value of the gear extend/retract command*/
inline double GetGearCmd(void) const { return GearCmd; }
2000-11-03 23:02:47 +00:00
//@}
2000-11-03 23:02:47 +00:00
/// @name Aerosurface position retrieval
//@{
/** Gets the left aileron position.
@return aileron position in radians */
inline double GetDaLPos( int form = ofRad )
const { return DaLPos[form]; }
/// @name Aerosurface position retrieval
//@{
/** Gets the right aileron position.
@return aileron position in radians */
inline double GetDaRPos( int form = ofRad )
const { return DaRPos[form]; }
2000-11-03 23:02:47 +00:00
/** Gets the elevator position.
@return elevator position in radians */
inline double GetDePos( int form = ofRad )
const { return DePos[form]; }
2000-11-03 23:02:47 +00:00
/** Gets the rudder position.
@return rudder position in radians */
inline double GetDrPos( int form = ofRad )
const { return DrPos[form]; }
2000-11-03 23:02:47 +00:00
/** Gets the speedbrake position.
@return speedbrake position in radians */
inline double GetDsbPos( int form = ofRad )
const { return DsbPos[form]; }
2000-11-03 23:02:47 +00:00
/** Gets the spoiler position.
@return spoiler position in radians */
inline double GetDspPos( int form = ofRad )
const { return DspPos[form]; }
/** Gets the flaps position.
@return flaps position in radians */
inline double GetDfPos( int form = ofRad )
const { return DspPos[form]; }
2000-11-03 23:02:47 +00:00
/** Gets the throttle position.
@param engine engine ID number
@return throttle position for the given engine in percent ( 0 - 100)*/
2001-11-20 22:34:24 +00:00
double GetThrottlePos(int engine);
2001-11-12 16:06:29 +00:00
/** Gets the mixture position.
@param engine engine ID number
@return mixture position for the given engine in percent ( 0 - 100)*/
inline double GetMixturePos(int engine) const { return MixturePos[engine]; }
/** Gets the gear position (0 up, 1 down), defaults to down
@return gear position (0 up, 1 down) */
inline double GetGearPos(void) const { return GearPos; }
/** Gets the prop pitch position.
@param engine engine ID number
@return prop pitch position for the given engine in percent ( 0.0-1.0)*/
inline double GetPropAdvance(int engine) const { return PropAdvance[engine]; }
2000-11-03 23:02:47 +00:00
//@}
2000-11-03 23:02:47 +00:00
/** Retrieves the State object pointer.
This is used by the FGFCS-owned components.
@return pointer to the State object */
inline FGState* GetState(void) { return State; }
2000-11-03 23:02:47 +00:00
/** Retrieves a components output value
@param idx the index of the component (the component ID)
@return output value from the component */
2001-11-20 22:34:24 +00:00
double GetComponentOutput(eParam idx);
2000-11-03 23:02:47 +00:00
/** Retrieves the component name
@param idx the index of the component (the component ID)
@return name of the component */
2000-04-24 23:49:06 +00:00
string GetComponentName(int idx);
2000-11-14 20:31:58 +00:00
/** Retrieves all component names for inclusion in output stream */
string GetComponentStrings(void);
2000-11-14 20:31:58 +00:00
/** Retrieves all component outputs for inclusion in output stream */
string GetComponentValues(void);
2000-04-24 23:49:06 +00:00
2000-11-03 23:02:47 +00:00
/// @name Pilot input command setting
//@{
/** Sets the aileron command
@param cmd aileron command in percent*/
inline void SetDaCmd( double cmd ) { DaCmd = cmd; }
2000-11-03 23:02:47 +00:00
/** Sets the elevator command
@param cmd elevator command in percent*/
inline void SetDeCmd(double cmd ) { DeCmd = cmd; }
2000-11-03 23:02:47 +00:00
/** Sets the rudder command
@param cmd rudder command in percent*/
2001-11-20 22:34:24 +00:00
inline void SetDrCmd(double cmd) { DrCmd = cmd; }
2000-11-03 23:02:47 +00:00
/** Sets the flaps command
@param cmd flaps command in percent*/
2001-11-20 22:34:24 +00:00
inline void SetDfCmd(double cmd) { DfCmd = cmd; }
2000-11-03 23:02:47 +00:00
/** Sets the speedbrake command
@param cmd speedbrake command in percent*/
2001-11-20 22:34:24 +00:00
inline void SetDsbCmd(double cmd) { DsbCmd = cmd; }
2000-11-03 23:02:47 +00:00
/** Sets the spoilers command
@param cmd spoilers command in percent*/
2001-11-20 22:34:24 +00:00
inline void SetDspCmd(double cmd) { DspCmd = cmd; }
2000-11-03 23:02:47 +00:00
/** Sets the pitch trim command
@param cmd pitch trim command in percent*/
2001-11-20 22:34:24 +00:00
inline void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
/** Sets the rudder trim command
@param cmd rudder trim command in percent*/
inline void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
/** Sets the aileron trim command
@param cmd aileron trim command in percent*/
inline void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
2000-11-03 23:02:47 +00:00
/** Sets the throttle command for the specified engine
@param engine engine ID number
2000-11-03 23:02:47 +00:00
@param cmd throttle command in percent (0 - 100)*/
2001-11-20 22:34:24 +00:00
void SetThrottleCmd(int engine, double cmd);
2001-11-12 16:06:29 +00:00
/** Sets the mixture command for the specified engine
@param engine engine ID number
@param cmd mixture command in percent (0 - 100)*/
2001-11-20 22:34:24 +00:00
void SetMixtureCmd(int engine, double cmd);
/** Set the gear extend/retract command, defaults to down
@param gear command 0 for up, 1 for down */
void SetGearCmd(double gearcmd) { GearCmd = gearcmd; }
/** Sets the propeller pitch command for the specified engine
@param engine engine ID number
@param cmd mixture command in percent (0.0 - 1.0)*/
2001-12-05 03:10:20 +00:00
void SetPropAdvanceCmd(int engine, double cmd);
2000-11-03 23:02:47 +00:00
//@}
2000-11-03 23:02:47 +00:00
/// @name Aerosurface position setting
//@{
/** Sets the left aileron position
@param cmd left aileron position in radians*/
inline void SetDaLPos( int form , double pos )
{ DaLPos[form] = pos; }
/** Sets the right aileron position
@param cmd right aileron position in radians*/
inline void SetDaRPos( int form , double pos )
{ DaRPos[form] = pos; }
2000-11-03 23:02:47 +00:00
/** Sets the elevator position
@param cmd elevator position in radians*/
inline void SetDePos( int form , double pos )
{ DePos[form] = pos; }
2000-11-03 23:02:47 +00:00
/** Sets the rudder position
@param cmd rudder position in radians*/
inline void SetDrPos( int form , double pos )
{ DrPos[form] = pos; }
/** Sets the flaps position
2000-11-03 23:02:47 +00:00
@param cmd flaps position in radians*/
inline void SetDfPos( int form , double pos )
{ DfPos[form] = pos; }
2000-11-03 23:02:47 +00:00
/** Sets the speedbrake position
@param cmd speedbrake position in radians*/
inline void SetDsbPos( int form , double pos )
{ DsbPos[form] = pos; }
2000-11-03 23:02:47 +00:00
/** Sets the spoiler position
@param cmd spoiler position in radians*/
inline void SetDspPos( int form , double pos )
{ DspPos[form] = pos; }
2000-11-03 23:02:47 +00:00
/** Sets the actual throttle setting for the specified engine
@param engine engine ID number
2000-11-03 23:02:47 +00:00
@param cmd throttle setting in percent (0 - 100)*/
2001-11-20 22:34:24 +00:00
void SetThrottlePos(int engine, double cmd);
2001-11-12 16:06:29 +00:00
/** Sets the actual mixture setting for the specified engine
@param engine engine ID number
@param cmd mixture setting in percent (0 - 100)*/
2001-11-20 22:34:24 +00:00
void SetMixturePos(int engine, double cmd);
/** Set the gear extend/retract position, defaults to down
@param gear position 0 up, 1 down */
void SetGearPos(double gearpos) { GearPos = gearpos; }
/** Sets the actual prop pitch setting for the specified engine
@param engine engine ID number
@param cmd prop pitch setting in percent (0.0 - 1.0)*/
2001-12-05 03:10:20 +00:00
void SetPropAdvance(int engine, double cmd);
2000-11-03 23:02:47 +00:00
//@}
2000-11-03 23:02:47 +00:00
/// @name Landing Gear brakes
//@{
/** Sets the left brake group
@param cmd brake setting in percent (0.0 - 1.0) */
2001-11-20 22:34:24 +00:00
void SetLBrake(double cmd) {LeftBrake = cmd;}
2000-11-03 23:02:47 +00:00
/** Sets the right brake group
@param cmd brake setting in percent (0.0 - 1.0) */
2001-11-20 22:34:24 +00:00
void SetRBrake(double cmd) {RightBrake = cmd;}
2000-11-03 23:02:47 +00:00
/** Sets the center brake group
@param cmd brake setting in percent (0.0 - 1.0) */
2001-11-20 22:34:24 +00:00
void SetCBrake(double cmd) {CenterBrake = cmd;}
2000-11-03 23:02:47 +00:00
/** Gets the brake for a specified group.
@param bg which brakegroup to retrieve the command for
@return the brake setting for the supplied brake group argument */
2001-11-20 22:34:24 +00:00
double GetBrake(FGLGear::BrakeGroup bg);
2000-11-03 23:02:47 +00:00
//@}
2000-04-24 23:49:06 +00:00
2000-11-03 23:02:47 +00:00
/** Loads the Flight Control System.
The FGAircraft instance is actually responsible for reading the config file
and calling the various Loadxx() methods of the other systems, passing in
the config file instance pointer. LoadFCS() is called from FGAircraft.
@param AC_cfg pointer to the config file instance
@return true if succesful */
2001-07-10 15:56:38 +00:00
bool Load(FGConfigFile* AC_cfg);
2001-03-30 01:04:50 +00:00
void AddThrottle(void);
void bind(void);
void unbind(void);
2001-03-30 01:04:50 +00:00
2000-11-03 23:02:47 +00:00
private:
double DaCmd, DeCmd, DrCmd, DfCmd, DsbCmd, DspCmd;
double DePos[NForms], DaLPos[NForms], DaRPos[NForms], DrPos[NForms];
double DfPos[NForms], DsbPos[NForms], DspPos[NForms];
double PTrimCmd, YTrimCmd, RTrimCmd;
2001-11-20 22:34:24 +00:00
vector <double> ThrottleCmd;
vector <double> ThrottlePos;
vector <double> MixtureCmd;
vector <double> MixturePos;
2001-12-05 03:10:20 +00:00
vector <double> PropAdvanceCmd;
vector <double> PropAdvance;
2001-11-20 22:34:24 +00:00
double LeftBrake, RightBrake, CenterBrake; // Brake settings
double GearCmd,GearPos;
bool DoNormalize;
void Normalize(void);
2000-11-03 23:02:47 +00:00
vector <FGFCSComponent*> Components;
int ToNormalize[NNorm];
2001-12-13 04:48:34 +00:00
void Debug(int from);
1999-02-05 21:26:01 +00:00
};
2000-04-24 23:49:06 +00:00
#include "FGState.h"
2000-01-10 21:07:00 +00:00
#endif
2001-03-30 01:04:50 +00:00