#include <string>
#include <map>
-#include "FGDefs.h"
#include "FGJSBBase.h"
#include "FGInitialCondition.h"
#include "FGMatrix33.h"
#include "FGColumnVector3.h"
#include "FGColumnVector4.h"
+#include "FGFDMExec.h"
+#include "FGAtmosphere.h"
+#include "FGFCS.h"
+#include "FGTranslation.h"
+#include "FGRotation.h"
+#include "FGPosition.h"
+#include "FGAerodynamics.h"
+#include "FGOutput.h"
+#include "FGAircraft.h"
+#include "FGGroundReactions.h"
+#include "FGPropulsion.h"
+
+
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
FORWARD DECLARATIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-class FGAircraft;
-class FGTranslation;
-class FGRotation;
-class FGAtmosphere;
-class FGOutput;
-class FGPosition;
-class FGFDMExec;
-class FGGroundReactions;
-
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/** Encapsulates the calculation of aircraft state.
@author Jon S. Berndt
@version $Id$
+ @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGState.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/FGState.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">
+ Source File </a>
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS DECLARATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+namespace JSBSim {
+
class FGState : public FGJSBBase
{
public:
/// Destructor
~FGState();
- /** Specifies the Reset file to use.
- The reset file normally resides in the same directory as an aircraft config file.
- it includes the following information:
- <ul>
- <li>U, the body X-Axis velocity</li>
- <li>V, the body Y-Axis velocity</li>
- <li>W, the body Z-Axis velocity</li>
- <li>Latitude measured in radians from the equator, negative values are south.</li>
- <li>Longitude, measured in radians from the Greenwich meridian, negative values are west.</li>
- <li>Phi, the roll angle in radians.</li>
- <li>Theta, the pitch attitude in radians.</li>
- <li>Psi, the heading angle in radians.</li>
- <li>H, the altitude in feet</li>
- <li>Wind Direction, the direction the wind is coming <u>from</u>.</li>
- <li>Wind magnitude, the wind speed in fps.</li>
- </ul>
- @param path the path string leading to the specific aircraft file, i.e. "aircraft".
- @param aircraft the name of the aircraft, i.e. "c172".
- @param filename the name of the reset file without an extension, i.e. "reset00".
- @return true if successful, false if the file could not be opened.
- */
- bool Reset(string path, string aircraft, string filename);
-
- /** Initializes the simulation state based on the passed-in parameters.
+ /** Initializes the simulation state based on the passed-in parameters.
@param U the body X-Axis velocity in fps.
@param V the body Y-Axis velocity in fps.
@param W the body Z-Axis velocity in fps.
@param weast eastward velocity in feet per second
@param wdown downward velocity in feet per second
*/
- void Initialize(float U,
- float V,
- float W,
- float lat,
- float lon,
- float phi,
- float tht,
- float psi,
- float h,
- float wnorth,
- float weast,
- float wdown);
+ void Initialize(double U,
+ double V,
+ double W,
+ double lat,
+ double lon,
+ double phi,
+ double tht,
+ double psi,
+ double h,
+ double wnorth,
+ double weast,
+ double wdown);
/** Initializes the simulation state based on parameters from an Initial Conditions object.
@param FGIC pointer to an initial conditions object.
*/
void Initialize(FGInitialCondition *FGIC);
- /** Stores state data in the supplied file name.
- @param filename the file to store the data in.
- @return true if successful.
- */
- bool StoreData(string filename);
-
/// returns the speed of sound in feet per second.
- inline float Geta(void) { return a; }
+ inline double Geta(void) { return a; }
/// Returns the simulation time in seconds.
- inline float Getsim_time(void) { return sim_time; }
+ inline double Getsim_time(void) const { return sim_time; }
/// Returns the simulation delta T.
- inline float Getdt(void) { return dt; }
+ inline double Getdt(void) { return dt; }
/// Suspends the simulation and sets the delta T to zero.
inline void Suspend(void) {saved_dt = dt; dt = 0.0;}
/// Resumes the simulation by resetting delta T to the correct value.
inline void Resume(void) {dt = saved_dt;}
- /** Retrieves a parameter.
- The parameters that can be retrieved are enumerated in FGDefs.h.
- @param val_idx one of the enumerated JSBSim parameters.
- @return the value of the parameter.
- */
- float GetParameter(eParam val_idx);
-
- /** Retrieves a parameter.
- The parameters that can be retrieved are enumerated in FGDefs.h.
- @param val_string a string representing one of the enumerated JSBSim parameters,
- i.e. "FG_QBAR".
- @return the value of the parameter.
- */
- float GetParameter(string val_string);
-
- /** Retrieves the JSBSim parameter enumerated item given the text string.
- @param val_string the parameter string, i.e. "FG_QBAR".
- @return the JSBSim parameter index (an enumerated type) for the supplied string.
- */
- eParam GetParameterIndex(string val_string);
-
/** Sets the speed of sound.
@param speed the speed of sound in feet per second.
*/
- inline void Seta(float speed) { a = speed; }
+ inline void Seta(double speed) { a = speed; }
/** Sets the current sim time.
@param cur_time the current time
@return the current time.
*/
- inline float Setsim_time(float cur_time) {
+ inline double Setsim_time(double cur_time) {
sim_time = cur_time;
return sim_time;
}
/** Sets the integration time step for the simulation executive.
@param delta_t the time step in seconds.
*/
- inline void Setdt(float delta_t) { dt = delta_t; }
-
- /** Sets the JSBSim parameter to the supplied value.
- @param prm the JSBSim parameter to set, i.e. FG_RUDDER_POS.
- @param val the value to give the parameter.
- */
- void SetParameter(eParam prm, float val);
+ inline void Setdt(double delta_t) { dt = delta_t; }
/** Increments the simulation time.
@return the new simulation time.
*/
- inline float IncrTime(void) {
+ inline double IncrTime(void) {
sim_time+=dt;
return sim_time;
}
@param tht the pitch angle in radians.
@param psi the heading angle in radians
*/
- void InitMatrices(float phi, float tht, float psi);
+ void InitMatrices(double phi, double tht, double psi);
/** Calculates the local-to-body and body-to-local conversion matrices.
*/
@param rate the integration rate in seconds.
*/
void IntegrateQuat(FGColumnVector3 vPQR, int rate);
+
+ // ======================================= General Purpose INTEGRATOR
+
+ enum iType {AB4, AB3, AB2, AM3, EULER, TRAPZ};
+
+ /** Multi-method integrator.
+ @param type Type of intergation scheme to use. Can be one of:
+ <ul>
+ <li>AB4 - Adams-Bashforth, fourth order</li>
+ <li>AB3 - Adams-Bashforth, third order</li>
+ <li>AB2 - Adams-Bashforth, second order</li>
+ <li>AM3 - Adams Moulton, third order</li>
+ <li>EULER - Euler</li>
+ <li>TRAPZ - Trapezoidal</li>
+ </ul>
+ @param delta_t the integration time step in seconds
+ @param vTDeriv a reference to the current value of the time derivative of
+ the quantity being integrated (i.e. if vUVW is being integrated
+ vTDeriv is the current value of vUVWdot)
+ @param vLastArray an array of previously calculated and saved values of
+ the quantity being integrated (i.e. if vUVW is being integrated
+ vLastArray[0] is the past value of vUVWdot, vLastArray[1] is the value of
+ vUVWdot prior to that, etc.)
+ @return the current, incremental value of the item integrated to add to the
+ previous value. */
+
+ template <class T> T Integrate(iType type, double delta_t, T& vTDeriv, T *vLastArray)
+ {
+ T vResult;
+
+ switch (type) {
+ case AB4:
+ vResult = (delta_t/24.0)*( 55.0 * vTDeriv
+ - 59.0 * vLastArray[0]
+ + 37.0 * vLastArray[1]
+ - 9.0 * vLastArray[2] );
+ vLastArray[2] = vLastArray[1];
+ vLastArray[1] = vLastArray[0];
+ vLastArray[0] = vTDeriv;
+ break;
+ case AB3:
+ vResult = (delta_t/12.0)*( 23.0 * vTDeriv
+ - 16.0 * vLastArray[0]
+ + 5.0 * vLastArray[1] );
+ vLastArray[1] = vLastArray[0];
+ vLastArray[0] = vTDeriv;
+ break;
+ case AB2:
+ vResult = (delta_t/2.0)*( 3.0 * vTDeriv - vLastArray[0] );
+ vLastArray[0] = vTDeriv;
+ break;
+ case AM3:
+ vResult = (delta_t/12.0)*( 5.0 * vTDeriv
+ + 8.0 * vLastArray[0]
+ - 1.0 * vLastArray[1] );
+ vLastArray[1] = vLastArray[0];
+ vLastArray[0] = vTDeriv;
+ break;
+ case EULER:
+ vResult = delta_t * vTDeriv;
+ break;
+ case TRAPZ:
+ vResult = (delta_t*0.5) * (vTDeriv + vLastArray[0]);
+ vLastArray[0] = vTDeriv;
+ break;
+ }
+
+ return vResult;
+ }
+
+ // =======================================
/** Calculates Euler angles from the local-to-body matrix.
@return a reference to the vEuler column vector.
FGColumnVector3& CalcEuler(void);
/** Calculates and returns the stability-to-body axis transformation matrix.
- @param alpha angle of attack in radians.
- @param beta angle of sideslip in radians.
@return a reference to the stability-to-body transformation matrix.
*/
- FGMatrix33& GetTs2b(float alpha, float beta);
+ FGMatrix33& GetTs2b(void);
+
+ /** Calculates and returns the body-to-stability axis transformation matrix.
+ @return a reference to the stability-to-body transformation matrix.
+ */
+ FGMatrix33& GetTb2s(void);
/** Retrieves the local-to-body transformation matrix.
@return a reference to the local-to-body transformation matrix.
@param c matrix column index.
@return the matrix element described by the row and column supplied.
*/
- float GetTl2b(int r, int c) { return mTl2b(r,c);}
+ double GetTl2b(int r, int c) { return mTl2b(r,c);}
/** Retrieves the body-to-local transformation matrix.
@return a reference to the body-to-local matrix.
@param c matrix column index.
@return the matrix element described by the row and column supplied.
*/
- float GetTb2l(int i, int j) { return mTb2l(i,j);}
+ double GetTb2l(int i, int j) { return mTb2l(i,j);}
/** Prints a summary of simulator state (speed, altitude,
configuration, etc.)
*/
void ReportState(void);
-
-
- typedef map<eParam, string> ParamMap;
- ParamMap paramdef;
+
+ void bind();
+ void unbind();
private:
- float a; // speed of sound
- float sim_time, dt;
- float saved_dt;
+ double a; // speed of sound
+ double sim_time, dt;
+ double saved_dt;
FGFDMExec* FDMExec;
FGMatrix33 mTb2l;
FGMatrix33 mTl2b;
FGMatrix33 mTs2b;
+ FGMatrix33 mTb2s;
FGColumnVector4 vQtrn;
- FGColumnVector4 vlastQdot;
+ FGColumnVector4 vQdot_prev[3];
+ FGColumnVector4 vQdot;
FGColumnVector3 vUVW;
FGColumnVector3 vLocalVelNED;
FGColumnVector3 vLocalEuler;
- FGColumnVector4 vQdot;
+
FGColumnVector4 vTmp;
FGColumnVector3 vEuler;
FGFCS* FCS;
FGAerodynamics* Aerodynamics;
FGGroundReactions* GroundReactions;
+ FGPropulsion* Propulsion;
+ FGPropertyManager* PropertyManager;
- typedef map<string, eParam> CoeffMap;
- CoeffMap coeffdef;
- void Debug(void);
- int ActiveEngine;
+ void Debug(int from);
};
-
+}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-#include "FGFDMExec.h"
-#include "FGAtmosphere.h"
-#include "FGFCS.h"
-#include "FGTranslation.h"
-#include "FGRotation.h"
-#include "FGPosition.h"
-#include "FGAerodynamics.h"
-#include "FGOutput.h"
-#include "FGAircraft.h"
-#include "FGGroundReactions.h"
#endif