Skip to content

Commit

Permalink
Modifications and cleanups; moved FGInertial execution to just after …
Browse files Browse the repository at this point in the history
…FGPropagate (resulted in slightly improved stability); solidified the execution order of models and ability to control that; continued making models more independent;
  • Loading branch information
jberndt committed Aug 4, 2011
1 parent 4e47d8d commit 51f8b3e
Show file tree
Hide file tree
Showing 18 changed files with 295 additions and 306 deletions.
217 changes: 93 additions & 124 deletions src/FGFDMExec.cpp

Large diffs are not rendered by default.

102 changes: 55 additions & 47 deletions src/FGFDMExec.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ INCLUDES
#include <vector>
#include <string>

#include "models/FGOutput.h"
#include "models/FGInput.h"
#include "initialization/FGTrim.h"
#include "FGJSBBase.h"
#include "input_output/FGPropertyManager.h"
Expand All @@ -58,7 +56,7 @@ INCLUDES
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#define ID_FDMEXEC "$Id: FGFDMExec.h,v 1.69 2011/07/18 04:37:34 jberndt Exp $"
#define ID_FDMEXEC "$Id: FGFDMExec.h,v 1.70 2011/08/04 12:46:32 jberndt Exp $"

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
Expand Down Expand Up @@ -183,7 +181,7 @@ CLASS DOCUMENTATION
property actually maps toa function call of DoTrim().
@author Jon S. Berndt
@version $Revision: 1.69 $
@version $Revision: 1.70 $
*/

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -226,9 +224,24 @@ class FGFDMExec : public FGJSBBase, public FGXMLFileRead
/// Default destructor
~FGFDMExec();

enum eModels { ePropagate, eInput, eAtmosphere, eWinds, eAuxiliary, eSystems,
ePropulsion, eAerodynamics, eGroundReactions, eExternalReactions,
eBuoyantForces, eMassBalance, eAircraft, eInertial, eAccelerations };
// This list of enums is very important! The order in which models are listed here
// determines the order of execution of the models.
enum eModels { ePropagate=0,
eInput,
eInertial,
eAtmosphere,
eWinds,
eAuxiliary,
eSystems,
ePropulsion,
eAerodynamics,
eGroundReactions,
eExternalReactions,
eBuoyantForces,
eMassBalance,
eAircraft,
eAccelerations,
eNumStandardModels };

/** Unbind all tied JSBSim properties. */
void Unbind(void) {instance->Unbind();}
Expand All @@ -242,8 +255,9 @@ class FGFDMExec : public FGJSBBase, public FGXMLFileRead
one is at this time not recommended.
@param model A pointer to the model being scheduled.
@param rate The rate at which to execute the model as described above.
Default is every frame (rate=1).
@return Currently returns 0 always. */
void Schedule(FGModel* model, int rate);
void Schedule(FGModel* model, int rate=1);

/** This function executes each scheduled model in succession.
@return true if successful, false if sim should be ended */
Expand Down Expand Up @@ -315,35 +329,35 @@ class FGFDMExec : public FGJSBBase, public FGXMLFileRead
/// @name Top-level executive State and Model retrieval mechanism
//@{
/// Returns the FGAtmosphere pointer.
FGAtmosphere* GetAtmosphere(void) {return Atmosphere;}
FGAtmosphere* GetAtmosphere(void) {return (FGAtmosphere*)Models[eAtmosphere];}
/// Returns the FGAccelerations pointer.
FGAccelerations* GetAccelerations(void) {return Accelerations;}
FGAccelerations* GetAccelerations(void) {return (FGAccelerations*)Models[eAccelerations];}
/// Returns the FGWinds pointer.
FGWinds* GetWinds(void) {return Winds;}
FGWinds* GetWinds(void) {return (FGWinds*)Models[eWinds];}
/// Returns the FGFCS pointer.
FGFCS* GetFCS(void) {return FCS;}
FGFCS* GetFCS(void) {return (FGFCS*)Models[eSystems];}
/// Returns the FGPropulsion pointer.
FGPropulsion* GetPropulsion(void) {return Propulsion;}
FGPropulsion* GetPropulsion(void) {return (FGPropulsion*)Models[ePropulsion];}
/// Returns the FGAircraft pointer.
FGMassBalance* GetMassBalance(void) {return MassBalance;}
FGMassBalance* GetMassBalance(void) {return (FGMassBalance*)Models[eMassBalance];}
/// Returns the FGAerodynamics pointer
FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
FGAerodynamics* GetAerodynamics(void){return (FGAerodynamics*)Models[eAerodynamics];}
/// Returns the FGInertial pointer.
FGInertial* GetInertial(void) {return Inertial;}
FGInertial* GetInertial(void) {return (FGInertial*)Models[eInertial];}
/// Returns the FGGroundReactions pointer.
FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
FGGroundReactions* GetGroundReactions(void) {return (FGGroundReactions*)Models[eGroundReactions];}
/// Returns the FGExternalReactions pointer.
FGExternalReactions* GetExternalReactions(void) {return ExternalReactions;}
FGExternalReactions* GetExternalReactions(void) {return (FGExternalReactions*)Models[eExternalReactions];}
/// Returns the FGBuoyantForces pointer.
FGBuoyantForces* GetBuoyantForces(void) {return BuoyantForces;}
FGBuoyantForces* GetBuoyantForces(void) {return (FGBuoyantForces*)Models[eBuoyantForces];}
/// Returns the FGAircraft pointer.
FGAircraft* GetAircraft(void) {return Aircraft;}
FGAircraft* GetAircraft(void) {return (FGAircraft*)Models[eAircraft];}
/// Returns the FGPropagate pointer.
FGPropagate* GetPropagate(void) {return Propagate;}
FGPropagate* GetPropagate(void) {return (FGPropagate*)Models[ePropagate];}
/// Returns the FGAuxiliary pointer.
FGAuxiliary* GetAuxiliary(void) {return Auxiliary;}
FGAuxiliary* GetAuxiliary(void) {return (FGAuxiliary*)Models[eAuxiliary];}
/// Returns the FGInput pointer.
FGInput* GetInput(void) {return Input;}
FGInput* GetInput(void) {return (FGInput*)Models[eInput];}
/// Returns the FGGroundCallback pointer.
FGGroundCallback* GetGroundCallback(void) {return GroundCallback;}
/// Retrieves the script object
Expand Down Expand Up @@ -418,19 +432,12 @@ class FGFDMExec : public FGJSBBase, public FGXMLFileRead
/** Sets (or overrides) the output filename
@param fname the name of the file to output data to
@return true if successful, false if there is no output specified for the flight model */
bool SetOutputFileName(const string& fname) {
if (Outputs.size() > 0) Outputs[0]->SetOutputFileName(fname);
else return false;
return true;
}
bool SetOutputFileName(const string& fname);

/** Retrieves the current output filename.
@return the name of the output file for the first output specified by the flight model.
If none is specified, the empty string is returned. */
string GetOutputFileName(void) {
if (Outputs.size() > 0) return Outputs[0]->GetOutputFileName();
else return string("");
}
string GetOutputFileName(void);

/** Executes trimming in the selected mode.
* @param mode Specifies how to trim:
Expand Down Expand Up @@ -560,25 +567,26 @@ class FGFDMExec : public FGJSBBase, public FGXMLFileRead
string Release;
string RootDir;

// Standard Model pointers - shortcuts for internal executive use only.
FGPropagate* Propagate;
FGInertial* Inertial;
FGAtmosphere* Atmosphere;
FGWinds* Winds;
FGAuxiliary* Auxiliary;
FGFCS* FCS;
FGPropulsion* Propulsion;
FGAerodynamics* Aerodynamics;
FGGroundReactions* GroundReactions;
FGExternalReactions* ExternalReactions;
FGBuoyantForces* BuoyantForces;
FGMassBalance* MassBalance;
FGAircraft* Aircraft;
FGAccelerations* Accelerations;

bool trim_status;
int ta_mode;

FGGroundCallback* GroundCallback;
FGAtmosphere* Atmosphere;
FGAccelerations* Accelerations;
FGWinds* Winds;
FGFCS* FCS;
FGPropulsion* Propulsion;
FGMassBalance* MassBalance;
FGAerodynamics* Aerodynamics;
FGInertial* Inertial;
FGGroundReactions* GroundReactions;
FGExternalReactions* ExternalReactions;
FGBuoyantForces* BuoyantForces;
FGAircraft* Aircraft;
FGPropagate* Propagate;
FGAuxiliary* Auxiliary;
FGInput* Input;
FGScript* Script;
FGInitialCondition* IC;
FGTrim* Trim;
Expand Down
4 changes: 2 additions & 2 deletions src/initialization/FGInitialCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ using namespace std;

namespace JSBSim {

static const char *IdSrc = "$Id: FGInitialCondition.cpp,v 1.68 2011/07/28 12:57:27 jberndt Exp $";
static const char *IdSrc = "$Id: FGInitialCondition.cpp,v 1.69 2011/08/04 12:46:32 jberndt Exp $";
static const char *IdHdr = ID_INITIALCONDITION;

//******************************************************************************
Expand Down Expand Up @@ -136,7 +136,7 @@ void FGInitialCondition::InitializeIC(void)
terrain_elevation = 0;
sea_level_radius = fdmex->GetInertial()->GetRefRadius();
position.SetPosition(0., 0., sea_level_radius);
position.SetEarthPositionAngle(fdmex->GetInertial()->GetEarthPositionAngle());
position.SetEarthPositionAngle(fdmex->GetPropagate()->GetEarthPositionAngle());
vUVW_NED.InitMatrix();
p=q=r=0;
vt=0;
Expand Down
11 changes: 6 additions & 5 deletions src/input_output/FGScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,21 @@ COMMENTS, REFERENCES, and NOTES
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#include <iostream>
#include <cstdlib>
#include <iomanip>

#include "FGScript.h"
#include "input_output/FGXMLElement.h"
#include "input_output/FGXMLParse.h"
#include "initialization/FGTrim.h"

#include <iostream>
#include <cstdlib>
#include <iomanip>
#include "models/FGInput.h"

using namespace std;

namespace JSBSim {

static const char *IdSrc = "$Id: FGScript.cpp,v 1.46 2011/02/18 12:44:16 jberndt Exp $";
static const char *IdSrc = "$Id: FGScript.cpp,v 1.47 2011/08/04 12:46:32 jberndt Exp $";
static const char *IdHdr = ID_FGSCRIPT;

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
9 changes: 5 additions & 4 deletions src/input_output/FGScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ SENTRY
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#include "FGJSBBase.h"
#include <vector>

#include "FGFDMExec.h"
#include "FGJSBBase.h"
#include "math/FGFunction.h"
#include "math/FGCondition.h"
#include <vector>
#include "input_output/FGXMLFileRead.h"

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

#define ID_FGSCRIPT "$Id: FGScript.h,v 1.20 2011/02/11 12:43:28 jberndt Exp $"
#define ID_FGSCRIPT "$Id: FGScript.h,v 1.21 2011/08/04 12:46:32 jberndt Exp $"

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
Expand Down Expand Up @@ -157,7 +158,7 @@ CLASS DOCUMENTATION
comes the &quot;run&quot; section, where the conditions are
described in &quot;event&quot; clauses.</p>
@author Jon S. Berndt
@version "$Id: FGScript.h,v 1.20 2011/02/11 12:43:28 jberndt Exp $"
@version "$Id: FGScript.h,v 1.21 2011/08/04 12:46:32 jberndt Exp $"
*/

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
13 changes: 11 additions & 2 deletions src/math/FGLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ INCLUDES
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#define ID_LOCATION "$Id: FGLocation.h,v 1.27 2010/11/29 12:33:58 jberndt Exp $"
#define ID_LOCATION "$Id: FGLocation.h,v 1.28 2011/08/04 12:46:32 jberndt Exp $"

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
Expand Down Expand Up @@ -142,7 +142,7 @@ CLASS DOCUMENTATION
@see W. C. Durham "Aircraft Dynamics & Control", section 2.2
@author Mathias Froehlich
@version $Id: FGLocation.h,v 1.27 2010/11/29 12:33:58 jberndt Exp $
@version $Id: FGLocation.h,v 1.28 2011/08/04 12:46:32 jberndt Exp $
*/

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -229,6 +229,13 @@ class FGLocation : public FGJSBBase
respect to the Inertial (ECI) frame in radians. */
void SetEarthPositionAngle(double EPA) {epa = EPA; mCacheValid = false;}

/** Increments the Earth position angle.
This is the relative orientation of the ECEF frame with respect to the
Inertial frame.
@param delta delta to the Earth fixed frame (ECEF) rotation offset about the axis with
respect to the Inertial (ECI) frame in radians. */
void IncrementEarthPositionAngle(double delta) {epa += delta; mCacheValid = false;}

/** Get the longitude.
@return the longitude in rad of the location represented with this
class instance. The returned values are in the range between
Expand Down Expand Up @@ -290,6 +297,8 @@ class FGLocation : public FGJSBBase
return -mTec2l(3,3)/cLat;
}

double GetEPA() const {return epa;}

/** Get the distance from the center of the earth.
@return the distance of the location represented with this class
instance to the center of the earth in ft. The radius value is
Expand Down
70 changes: 4 additions & 66 deletions src/models/FGAerodynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ using namespace std;

namespace JSBSim {

static const char *IdSrc = "$Id: FGAerodynamics.cpp,v 1.40 2011/07/20 12:26:41 jberndt Exp $";
static const char *IdSrc = "$Id: FGAerodynamics.cpp,v 1.41 2011/08/04 12:46:32 jberndt Exp $";
static const char *IdHdr = ID_AERODYNAMICS;

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -179,16 +179,16 @@ bool FGAerodynamics::Run(bool Holding)

switch (axisType) {
case atBodyXYZ: // Forces already in body axes; no manipulation needed
vFw = GetTb2w()*vFnative;
vFw = in.Tb2w*vFnative;
vForces = vFnative;
break;
case atLiftDrag: // Copy forces into wind axes
vFw = vFnative;
vFw(eDrag)*=-1; vFw(eLift)*=-1;
vForces = GetTw2b()*vFw;
vForces = in.Tw2b*vFw;
break;
case atAxialNormal: // Convert native forces into Axial|Normal|Side system
vFw = GetTb2w()*vFnative;
vFw = in.Tb2w*vFnative;
vFnative(eX)*=-1; vFnative(eZ)*=-1;
vForces = vFnative;
break;
Expand Down Expand Up @@ -229,68 +229,6 @@ bool FGAerodynamics::Run(bool Holding)
return false;
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//
// From Stevens and Lewis, "Aircraft Control and Simulation", 3rd Ed., the
// transformation from body to wind axes is defined (where "a" is alpha and "B"
// is beta):
//
// cos(a)*cos(B) sin(B) sin(a)*cos(B)
// -cos(a)*sin(B) cos(B) -sin(a)*sin(B)
// -sin(a) 0 cos(a)
//
// The transform from wind to body axes is then,
//
// cos(a)*cos(B) -cos(a)*sin(B) -sin(a)
// sin(B) cos(B) 0
// sin(a)*cos(B) -sin(a)*sin(B) cos(a)

FGMatrix33& FGAerodynamics::GetTw2b(void)
{
double ca, cb, sa, sb;

ca = cos(in.Alpha);
sa = sin(in.Alpha);
cb = cos(in.Beta);
sb = sin(in.Beta);

mTw2b(1,1) = ca*cb;
mTw2b(1,2) = -ca*sb;
mTw2b(1,3) = -sa;
mTw2b(2,1) = sb;
mTw2b(2,2) = cb;
mTw2b(2,3) = 0.0;
mTw2b(3,1) = sa*cb;
mTw2b(3,2) = -sa*sb;
mTw2b(3,3) = ca;

return mTw2b;
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FGMatrix33& FGAerodynamics::GetTb2w(void)
{
double ca, cb, sa, sb;

ca = cos(in.Alpha);
sa = sin(in.Alpha);
cb = cos(in.Beta);
sb = sin(in.Beta);

mTb2w(1,1) = ca*cb;
mTb2w(1,2) = sb;
mTb2w(1,3) = sa*cb;
mTb2w(2,1) = -ca*sb;
mTb2w(2,2) = cb;
mTb2w(2,3) = -sa*sb;
mTb2w(3,1) = -sa;
mTb2w(3,2) = 0.0;
mTb2w(3,3) = ca;

return mTb2w;
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

bool FGAerodynamics::Load(Element *element)
Expand Down
Loading

0 comments on commit 51f8b3e

Please sign in to comment.