%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGFDMExec.h"
-#include "FGState.h"
#include "models/FGAtmosphere.h"
#include "models/atmosphere/FGMSIS.h"
#include "models/atmosphere/FGMars.h"
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGFDMExec.cpp,v 1.78 2010/04/12 12:25:19 jberndt Exp $";
static const char *IdHdr = ID_FDMEXEC;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Frame = 0;
Error = 0;
GroundCallback = 0;
- State = 0;
Atmosphere = 0;
FCS = 0;
Propulsion = 0;
Trim = 0;
Script = 0;
+ RootDir = "";
+
modelLoaded = false;
IsChild = false;
holding = false;
Terminate = false;
+ sim_time = 0.0;
+ dT = 1.0/120.0; // a default timestep size. This is needed for when JSBSim is
+ // run in standalone mode with no initialization file.
+
IdFDM = FDMctr; // The main (parent) JSBSim instance is always the "zeroth"
FDMctr++; // instance. "child" instances are loaded last.
instance->Tie("simulation/do_simple_trim", this, (iPMF)0, &FGFDMExec::DoTrim);
instance->Tie("simulation/reset", this, (iPMF)0, &FGFDMExec::ResetToInitialConditions);
instance->Tie("simulation/terminate", (int *)&Terminate);
+ instance->Tie("simulation/sim-time-sec", this, &FGFDMExec::GetSimTime);
+ instance->Tie("simulation/jsbsim-debug", this, &FGFDMExec::GetDebugLevel, &FGFDMExec::SetDebugLevel);
+
Constructing = false;
}
Auxiliary = new FGAuxiliary(this);
Input = new FGInput(this);
- State = new FGState(this); // This must be done here, as the FGState
- // class needs valid pointers to the above
- // model classes
-
// Schedule a model. The second arg (the integer) is the pass number. For
// instance, the atmosphere model could get executed every fifth pass it is called.
Schedule(Input, 1);
- Schedule(Atmosphere, 30);
+ Schedule(Atmosphere, 1);
Schedule(FCS, 1);
Schedule(Propulsion, 1);
Schedule(MassBalance, 1);
delete Aircraft;
delete Propagate;
delete Auxiliary;
- delete State;
delete Script;
for (unsigned i=0; i<Outputs.size(); i++) delete Outputs[i];
Error = 0;
- State = 0;
Input = 0;
Atmosphere = 0;
FCS = 0;
}
// returns true if success, false if complete
- if (Script != 0 && !State->IntegrationSuspended()) success = Script->RunScript();
+ if (Script != 0 && !IntegrationSuspended()) success = Script->RunScript();
vector <FGModel*>::iterator it;
for (it = Models.begin(); it != Models.end(); ++it) (*it)->Run();
Frame++;
- if (!Holding()) State->IncrTime();
+ if (!Holding()) IncrTime();
if (Terminate) success = false;
return (success);
bool FGFDMExec::RunIC(void)
{
- State->SuspendIntegration();
- State->Initialize(IC);
+ SuspendIntegration(); // saves the integration rate, dt, then sets it to 0.0.
+ Initialize(IC);
Run();
- State->ResumeIntegration();
+ ResumeIntegration(); // Restores the integration rate to what it was.
return true;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGFDMExec::Initialize(FGInitialCondition *FGIC)
+{
+ Propagate->SetInitialState( FGIC );
+
+ Atmosphere->Run();
+ Atmosphere->SetWindNED( FGIC->GetWindNFpsIC(),
+ FGIC->GetWindEFpsIC(),
+ FGIC->GetWindDFpsIC() );
+
+ FGColumnVector3 vAeroUVW;
+ vAeroUVW = Propagate->GetUVW() + Propagate->GetTl2b()*Atmosphere->GetTotalWindNED();
+
+ double alpha, beta;
+ if (vAeroUVW(eW) != 0.0)
+ alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
+ else
+ alpha = 0.0;
+ if (vAeroUVW(eV) != 0.0)
+ beta = vAeroUVW(eU)*vAeroUVW(eU)+vAeroUVW(eW)*vAeroUVW(eW) > 0.0 ? atan2(vAeroUVW(eV), (fabs(vAeroUVW(eU))/vAeroUVW(eU))*sqrt(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW))) : 0.0;
+ else
+ beta = 0.0;
+
+ Auxiliary->SetAB(alpha, beta);
+
+ double Vt = vAeroUVW.Magnitude();
+ Auxiliary->SetVt(Vt);
+
+ Auxiliary->SetMach(Vt/Atmosphere->GetSoundSpeed());
+
+ double qbar = 0.5*Vt*Vt*Atmosphere->GetDensity();
+ Auxiliary->Setqbar(qbar);
+}
+
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//
// A private, internal function call for Tie-ing to a property, so it needs an
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-double FGFDMExec::GetSimTime(void)
-{
- return (State->Getsim_time());
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-double FGFDMExec::GetDeltaT(void)
-{
- return (State->Getdt());
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
vector <string> FGFDMExec::EnumerateFDMs(void)
{
vector <string> FDMList;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-bool FGFDMExec::LoadScript(string script)
+bool FGFDMExec::LoadScript(string script, double deltaT)
{
bool result;
Script = new FGScript(this);
- result = Script->LoadScript(script);
+ result = Script->LoadScript(RootDir + script, deltaT);
return result;
}
bool FGFDMExec::LoadModel(string AircraftPath, string EnginePath, string SystemsPath,
string model, bool addModelToPath)
{
- FGFDMExec::AircraftPath = AircraftPath;
- FGFDMExec::EnginePath = EnginePath;
- FGFDMExec::SystemsPath = SystemsPath;
+ FGFDMExec::AircraftPath = RootDir + AircraftPath;
+ FGFDMExec::EnginePath = RootDir + EnginePath;
+ FGFDMExec::SystemsPath = RootDir + SystemsPath;
return LoadModel(model, addModelToPath);
}
{
string token;
string aircraftCfgFileName;
- string separator = "/";
Element* element = 0L;
bool result = false; // initialize result to false, indicating input file not yet read
}
FullAircraftPath = AircraftPath;
- if (addModelToPath) FullAircraftPath += separator + model;
- aircraftCfgFileName = FullAircraftPath + separator + model + ".xml";
+ if (addModelToPath) FullAircraftPath += "/" + model;
+ aircraftCfgFileName = FullAircraftPath + "/" + model + ".xml";
if (modelLoaded) {
DeAllocate();
modelLoaded = true;
+ MassBalance->Run(); // Update all mass properties for the report.
+ MassBalance->GetMassPropertiesReport();
+
if (debug_lvl > 0) {
cout << endl << fgblue << highint
<< "End of vehicle configuration loading." << endl
bool result;
FGOutput* Output = new FGOutput(this);
- Output->SetDirectivesFile(fname);
+ Output->SetDirectivesFile(RootDir + fname);
Output->InitModel();
- Schedule(Output, 1);
+ Schedule(Output, 1);
result = Output->Load(0);
- Outputs.push_back(Output);
- typedef int (FGOutput::*iOPMF)(void) const;
- string outputProp = CreateIndexedPropertyName("simulation/output",Outputs.size()-1);
- instance->Tie(outputProp+"/log_rate_hz", Output, (iOPMF)0, &FGOutput::SetRate);
+ if (result) {
+ Outputs.push_back(Output);
+ typedef int (FGOutput::*iOPMF)(void) const;
+ string outputProp = CreateIndexedPropertyName("simulation/output",Outputs.size()-1);
+ instance->Tie(outputProp+"/log_rate_hz", Output, (iOPMF)0, &FGOutput::SetRate);
+ }
return result;
}
cerr << endl << "Illegal trimming mode!" << endl << endl;
return;
}
- saved_time = State->Getsim_time();
+ saved_time = sim_time;
FGTrim trim(this, (JSBSim::TrimMode)mode);
if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
trim.Report();
- State->Setsim_time(saved_time);
+ sim_time = saved_time;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cerr << endl << "Illegal trimming mode!" << endl << endl;
return;
}
- saved_time = State->Getsim_time();
+ saved_time = sim_time;
FGTrimAnalysis trimAnalysis(this, (JSBSim::TrimAnalysisMode)mode);
if ( !result ) cerr << endl << "Trim Failed" << endl << endl;
trimAnalysis.Report();
- State->Setsim_time(saved_time);
+ Setsim_time(saved_time);
EnableOutput();
cout << "\nOutput: " << GetOutputFileName() << endl;
if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
if (from == 2) {
cout << "================== Frame: " << Frame << " Time: "
- << State->Getsim_time() << " dt: " << State->Getdt() << endl;
+ << sim_time << " dt: " << dT << endl;
}
}
if (debug_lvl & 8 ) { // Runtime state variables
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FDMEXEC "$Id$"
+#define ID_FDMEXEC "$Id: FGFDMExec.h,v 1.52 2010/07/04 13:50:21 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
property actually maps toa function call of DoTrim().
@author Jon S. Berndt
- @version $Revision$
+ @version $Revision: 1.52 $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/** Loads a script
@param Script the full path name and file name for the script to be loaded.
@return true if successfully loadsd; false otherwise. */
- bool LoadScript(string Script);
+ bool LoadScript(string Script, double deltaT);
/** Sets the path to the engine config file directories.
@param path path to the directory under which engine config
files are kept, for instance "engine" */
- bool SetEnginePath(string path) { EnginePath = path; return true; }
+ bool SetEnginePath(string path) { EnginePath = RootDir + path; return true; }
/** Sets the path to the aircraft config file directories.
@param path path to the aircraft directory. For instance:
"aircraft". Under aircraft, then, would be directories for various
modeled aircraft such as C172/, x15/, etc. */
- bool SetAircraftPath(string path) { AircraftPath = path; return true; }
+ bool SetAircraftPath(string path) { AircraftPath = RootDir + path; return true; }
/** Sets the path to the systems config file directories.
@param path path to the directory under which systems config
files are kept, for instance "systems" */
- bool SetSystemsPath(string path) { SystemsPath = path; return true; }
+ bool SetSystemsPath(string path) { SystemsPath = RootDir + path; return true; }
/// @name Top-level executive State and Model retrieval mechanism
//@{
inline FGInput* GetInput(void) {return Input;}
/// Returns the FGGroundCallback pointer.
inline FGGroundCallback* GetGroundCallback(void) {return GroundCallback;}
- /// Returns the FGState pointer.
- inline FGState* GetState(void) {return State;}
/// Retrieves the script object
inline FGScript* GetScript(void) {return Script;}
// Returns a pointer to the FGInitialCondition object
/// Returns the model name.
string GetModelName(void) { return modelName; }
-
+/*
/// Returns the current time.
double GetSimTime(void);
/// Returns the current frame time (delta T).
double GetDeltaT(void);
-
+*/
/// Returns a pointer to the property manager object.
FGPropertyManager* GetPropertyManager(void);
/// Returns a vector of strings representing the names of all loaded models (future)
vector <string> EnumerateFDMs(void);
/// Gets the number of child FDMs.
- int GetFDMCount(void) {return ChildFDMList.size();}
+ int GetFDMCount(void) {return (int)ChildFDMList.size();}
/// Gets a particular child FDM.
childData* GetChildFDM(int i) {return ChildFDMList[i];}
/// Marks this instance of the Exec object as a "child" object.
// Print the contents of the property catalog for the loaded aircraft.
void PrintPropertyCatalog(void);
+ vector<string>& GetPropertyCatalog(void) {return PropertyCatalog;}
+
/// Use the MSIS atmosphere model.
void UseAtmosphereMSIS(void);
void SetTrimMode(int mode){ ta_mode = mode; }
int GetTrimMode(void) const { return ta_mode; }
+ /// Returns the cumulative simulation time in seconds.
+ double GetSimTime(void) const { return sim_time; }
+
+ /// Returns the simulation delta T.
+ double GetDeltaT(void) {return dT;}
+
+ /// Suspends the simulation and sets the delta T to zero.
+ void SuspendIntegration(void) {saved_dT = dT; dT = 0.0;}
+
+ /// Resumes the simulation by resetting delta T to the correct value.
+ void ResumeIntegration(void) {dT = saved_dT;}
+
+ /** Returns the simulation suspension state.
+ @return true if suspended, false if executing */
+ bool IntegrationSuspended(void) {return dT == 0.0;}
+
+ /** Sets the current sim time.
+ @param cur_time the current time
+ @return the current simulation time. */
+ 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. */
+ void Setdt(double delta_t) { dT = delta_t; }
+
+ /** Sets the root directory where JSBSim starts looking for its system directories.
+ @param rootDir the string containing the root directory. */
+ void SetRootDir(string rootDir) {RootDir = rootDir;}
+
+ /** Retrieves teh Root Directory.
+ @return the string representing the root (base) JSBSim directory. */
+ string GetRootDir(void) const {return RootDir;}
+
+ /** Increments the simulation time.
+ @return the new simulation time. */
+ double IncrTime(void) {
+ sim_time += dT;
+ return sim_time;
+ }
+
+ /** Retrieves the current debug level setting. */
+ int GetDebugLevel(void) const {return debug_lvl;};
+
private:
static unsigned int FDMctr;
int Error;
unsigned int Frame;
unsigned int IdFDM;
unsigned short Terminate;
+ double dT;
+ double saved_dT;
+ double sim_time;
bool holding;
bool Constructing;
bool modelLoaded;
string SystemsPath;
string CFGVersion;
string Release;
+ string RootDir;
bool trim_status;
int ta_mode;
static FGPropertyManager *master;
FGGroundCallback* GroundCallback;
- FGState* State;
FGAtmosphere* Atmosphere;
FGFCS* FCS;
FGPropulsion* Propulsion;
void ResetToInitialConditions(int mode);
bool Allocate(void);
bool DeAllocate(void);
+ void Initialize(FGInitialCondition *FGIC);
void Debug(int from);
};
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGJSBBase.cpp,v 1.29 2010/03/18 13:19:21 jberndt Exp $";
static const char *IdHdr = ID_JSBBASE;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
char FGJSBBase::fgdef[6] = {'\0' };
#endif
-const double FGJSBBase::radtodeg = 57.29578;
-const double FGJSBBase::degtorad = 1.745329E-2;
+const double FGJSBBase::radtodeg = 57.295779513082320876798154814105;
+const double FGJSBBase::degtorad = 0.017453292519943295769236907684886;
const double FGJSBBase::hptoftlbssec = 550.0;
const double FGJSBBase::psftoinhg = 0.014138;
const double FGJSBBase::psftopa = 47.88;
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_JSBBASE "$Id$"
+#define ID_JSBBASE "$Id: FGJSBBase.h,v 1.30 2010/07/01 23:13:19 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
* This class provides universal constants, utility functions, messaging
* functions, and enumerated constants to JSBSim.
@author Jon S. Berndt
- @version $Id$
+ @version $Id: FGJSBBase.h,v 1.30 2010/07/01 23:13:19 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
static std::queue <Message> Messages;
- void Debug(int from) {};
+ void Debug(int) {};
static unsigned int messageId;
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGState.cpp,v 1.15 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_STATE;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_STATE "$Id$"
+#define ID_STATE "$Id: FGState.h,v 1.15 2009/10/02 10:30:07 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
<h3>Properties</h3>
@property sim-time-sec (read only) cumulative simulation in seconds.
@author Jon S. Berndt
- @version $Revision$
+ @version $Revision: 1.15 $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
//
// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
+// modify it under the terms of the GNU Lesser 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.
+// Lesser General Public License for more details.
//
-// You should have received a copy of the GNU General Public License
+// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
-// $Id$
+// $Id: JSBSim.cxx,v 1.62 2010/07/14 05:50:40 ehofman Exp $
#ifdef HAVE_CONFIG_H
#include "JSBSim.hxx"
#include <FDM/JSBSim/FGFDMExec.h>
#include <FDM/JSBSim/FGJSBBase.h>
-#include <FDM/JSBSim/FGState.h>
#include <FDM/JSBSim/initialization/FGInitialCondition.h>
#include <FDM/JSBSim/initialization/FGTrim.h>
#include <FDM/JSBSim/models/FGModel.h>
#include <FDM/JSBSim/models/FGMassBalance.h>
#include <FDM/JSBSim/models/FGAerodynamics.h>
#include <FDM/JSBSim/models/FGLGear.h>
+#include <FDM/JSBSim/models/FGGroundReactions.h>
+#include <FDM/JSBSim/models/FGPropulsion.h>
#include <FDM/JSBSim/models/propulsion/FGEngine.h>
#include <FDM/JSBSim/models/propulsion/FGPiston.h>
#include <FDM/JSBSim/models/propulsion/FGTurbine.h>
double contact[3], normal[3], vel[3], agl = 0;
mInterface->get_agl_ft(t, loc_cart, SG_METER_TO_FEET*2, contact, normal,
vel, &agl);
- n = FGColumnVector3( -normal[0], -normal[1], -normal[2] );
+ n = FGColumnVector3( normal[0], normal[1], normal[2] );
v = FGColumnVector3( vel[0], vel[1], vel[2] );
cont = FGColumnVector3( contact[0], contact[1], contact[2] );
return agl;
// Register ground callback.
fdmex->SetGroundCallback( new FGFSGroundCallback(this) );
- State = fdmex->GetState();
Atmosphere = fdmex->GetAtmosphere();
FCS = fdmex->GetFCS();
MassBalance = fdmex->GetMassBalance();
SGPath systems_path( fgGetString("/sim/aircraft-dir") );
systems_path.append( "Systems" );
- State->Setdt( dt );
+// deprecate sim-time-sec for simulation/sim-time-sec
+// remove alias with increased configuration file version number (2.1 or later)
+ SGPropertyNode * node = fgGetNode("/fdm/jsbsim/simulation/sim-time-sec");
+ fgGetNode("/fdm/jsbsim/sim-time-sec", true)->alias( node );
+// end of sim-time-sec deprecation patch
+
+ fdmex->Setdt( dt );
result = fdmex->LoadModel( aircraft_path.str(),
engine_path.str(),
speedbrake_pos_pct->setDoubleValue(0);
spoilers_pos_pct->setDoubleValue(0);
+ ab_brake_engaged = fgGetNode("/autopilot/autobrake/engaged", true);
+ ab_brake_left_pct = fgGetNode("/autopilot/autobrake/brake-left-output", true);
+ ab_brake_right_pct = fgGetNode("/autopilot/autobrake/brake-right-output", true);
+
temperature = fgGetNode("/environment/temperature-degc",true);
pressure = fgGetNode("/environment/pressure-inhg",true);
density = fgGetNode("/environment/density-slugft3",true);
void FGJSBsim::init()
{
- double tmp;
-
SG_LOG( SG_FLIGHT, SG_INFO, "Starting and initializing JSBsim" );
// Explicitly call the superclass's
<< ", " << fdmex->GetAtmosphere()->GetPressure()
<< ", " << fdmex->GetAtmosphere()->GetDensity() );
+// deprecate egt_degf for egt-degf to have consistent naming
+// TODO: raise log-level to ALERT in summer 2010,
+// remove alias in fall 2010,
+// remove this code in winter 2010
+ for (unsigned int i=0; i < Propulsion->GetNumEngines(); i++) {
+ SGPropertyNode * node = fgGetNode("engines/engine", i, true);
+ SGPropertyNode * egtn = node->getNode( "egt_degf" );
+ if( egtn != NULL ) {
+ SG_LOG(SG_FLIGHT,SG_WARN,
+ "Aircraft uses deprecated node egt_degf. Please upgrade to egt-degf");
+ node->getNode("egt-degf", true)->alias( egtn );
+ }
+ }
+// end of egt_degf deprecation patch
+
if (fgGetBool("/sim/presets/running")) {
for (unsigned int i=0; i < Propulsion->GetNumEngines(); i++) {
SGPropertyNode * node = fgGetNode("engines/engine", i, true);
cart = FGLocation(lon, lat, alt+slr);
}
double cart_pos[3] = { cart(1), cart(2), cart(3) };
- double t0 = State->Getsim_time();
+ double t0 = fdmex->GetSimTime();
bool cache_ok = prepare_ground_cache_ft( t0, t0 + dt, cart_pos,
groundCacheRadius );
if (!cache_ok) {
if ( needTrim ) {
if ( startup_trim->getBoolValue() ) {
double contact[3], d[3], agl;
- get_agl_ft(State->Getsim_time(), cart_pos, SG_METER_TO_FEET*2, contact,
+ get_agl_ft(fdmex->GetSimTime(), cart_pos, SG_METER_TO_FEET*2, contact,
d, d, &agl);
double terrain_alt = sqrt(contact[0]*contact[0] + contact[1]*contact[1]
+ contact[2]*contact[2]) - fgic->GetSeaLevelRadiusFtIC();
for ( i=0; i < multiloop; i++ ) {
fdmex->Run();
- update_external_forces(State->Getsim_time() + i * State->Getdt());
+ update_external_forces(fdmex->GetSimTime() + i * fdmex->GetDeltaT());
}
FGJSBBase::Message* msg;
double parking_brake = globals->get_controls()->get_brake_parking();
double left_brake = globals->get_controls()->get_brake_left();
double right_brake = globals->get_controls()->get_brake_right();
+
+ if (ab_brake_engaged->getBoolValue()) {
+ left_brake = ab_brake_left_pct->getDoubleValue();
+ right_brake = ab_brake_right_pct->getDoubleValue();
+ }
+
FCS->SetLBrake(FMAX(left_brake, parking_brake));
FCS->SetRBrake(FMAX(right_brake, parking_brake));
FGTurbine* eng = (FGTurbine*)Propulsion->GetEngine(i);
node->setDoubleValue("n1", eng->GetN1());
node->setDoubleValue("n2", eng->GetN2());
- node->setDoubleValue("egt_degf", 32 + eng->GetEGT()*9/5);
+ node->setDoubleValue("egt-degf", 32 + eng->GetEGT()*9/5);
node->setBoolValue("augmentation", eng->GetAugmentation());
node->setBoolValue("water-injection", eng->GetInjection());
node->setBoolValue("ignition", eng->GetIgnition());
node->setDoubleValue("rpm", eng->getRPM());
} // end FGElectric code block
break;
+ case FGEngine::etUnknown:
+ break;
}
{ // FGEngine code block
// force a sim crashed if crashed (altitude AGL < 0)
if (get_Altitude_AGL() < -100.0) {
- State->SuspendIntegration();
+ fdmex->SuspendIntegration();
crashed = true;
}
} else {
trimmed->setBoolValue(true);
}
-// if (FGJSBBase::debug_lvl > 0)
-// State->ReportState();
-
delete fgtrim;
pitch_trim->setDoubleValue( FCS->GetPitchTrimCmd() );
FGColumnVector3 hook_tip_body = hook_root_body;
hook_tip_body(1) -= hook_length * cos_fi;
hook_tip_body(3) += hook_length * sin_fi;
- bool hook_tip_valid = true;
double contact[3];
double ground_normal[3];
------ Copyright (C) 1999 - 2000 Curtis L. Olson (curt@flightgear.org) ------
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
+ modify it under the terms of the GNU Lesser 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.
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
+ You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
documentation for main for direction on running JSBSim apart from FlightGear.
@author Curtis L. Olson (original)
@author Tony Peden (Maintained and refined)
- @version $Id$
+ @version $Id: JSBSim.hxx,v 1.13 2010/07/07 20:46:36 andgi Exp $
@see main in file JSBSim.cpp (use main() wrapper for standalone usage)
*/
SGPropertyNode_ptr flap_pos_pct;
SGPropertyNode_ptr speedbrake_pos_pct;
SGPropertyNode_ptr spoilers_pos_pct;
+
+ SGPropertyNode_ptr ab_brake_engaged;
+ SGPropertyNode_ptr ab_brake_left_pct;
+ SGPropertyNode_ptr ab_brake_right_pct;
SGPropertyNode_ptr gear_pos_pct;
SGPropertyNode_ptr wing_fold_pos_pct;
#include <iostream>
#include <fstream>
#include <cstdlib>
+#include "input_output/string_utilities.h"
using namespace std;
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGInitialCondition.cpp,v 1.40 2010/06/02 04:05:13 jberndt Exp $";
static const char *IdHdr = ID_INITIALCONDITION;
//******************************************************************************
double psl=fdmex->GetAtmosphere()->GetPressureSL();
double rhosl=fdmex->GetAtmosphere()->GetDensitySL();
double pt,A,B,D,vcas;
- if(Mach < 0) Mach=0;
- if(Mach < 1) //calculate total pressure assuming isentropic flow
+
+ if (Mach < 0) Mach=0;
+ if (Mach < 1) //calculate total pressure assuming isentropic flow
pt=p*pow((1 + 0.2*Mach*Mach),3.5);
else {
// shock in front of pitot tube, we'll assume its normal and use
// the Rayleigh Pitot Tube Formula, i.e. the ratio of total
- // pressure behind the shock to the static pressure in front
-
-
- //the normal shock assumption should not be a bad one -- most supersonic
- //aircraft place the pitot probe out front so that it is the forward
- //most point on the aircraft. The real shock would, of course, take
- //on something like the shape of a rounded-off cone but, here again,
- //the assumption should be good since the opening of the pitot probe
- //is very small and, therefore, the effects of the shock curvature
- //should be small as well. AFAIK, this approach is fairly well accepted
- //within the aerospace community
+ // pressure behind the shock to the static pressure in front of
+ // the normal shock assumption should not be a bad one -- most supersonic
+ // aircraft place the pitot probe out front so that it is the forward
+ // most point on the aircraft. The real shock would, of course, take
+ // on something like the shape of a rounded-off cone but, here again,
+ // the assumption should be good since the opening of the pitot probe
+ // is very small and, therefore, the effects of the shock curvature
+ // should be small as well. AFAIK, this approach is fairly well accepted
+ // within the aerospace community
B = 5.76*Mach*Mach/(5.6*Mach*Mach - 0.8);
bool FGInitialCondition::Load(string rstfile, bool useStoredPath)
{
- int n;
-
string sep = "/";
if( useStoredPath ) {
init_file_name = fdmex->GetFullAircraftPath() + sep + rstfile + ".xml";
exit(-1);
}
+ double version = document->GetAttributeValueAsNumber("version");
+ if (version == HUGE_VAL) {
+ return Load_v1(); // Default to the old version
+ } else if (version >= 3.0) {
+ cerr << "Only initialization file formats 1 and 2 are currently supported" << endl;
+ exit (-1);
+ } else if (version >= 2.0) {
+ return Load_v2();
+ } else if (version >= 1.0) {
+ return Load_v1();
+ }
+
+}
+
+//******************************************************************************
+
+bool FGInitialCondition::Load_v1(void)
+{
+ int n;
+
if (document->FindElement("latitude"))
SetLatitudeDegIC(document->FindElementValueAsNumberConvertTo("latitude", "DEG"));
if (document->FindElement("longitude"))
//******************************************************************************
+bool FGInitialCondition::Load_v2(void)
+{
+ int n;
+ FGColumnVector3 vLoc, vOrient;
+ bool result = true;
+ FGInertial* Inertial = fdmex->GetInertial();
+ FGPropagate* Propagate = fdmex->GetPropagate();
+
+ if (document->FindElement("earth_position_angle")) {
+ double epa = document->FindElementValueAsNumberConvertTo("earth_position_angle", "RAD");
+ Inertial->SetEarthPositionAngle(epa);
+ }
+
+ // Initialize vehicle position
+ //
+ // Allowable frames:
+ // - ECI (Earth Centered Inertial)
+ // - ECEF (Earth Centered, Earth Fixed)
+
+ Element* position = document->FindElement("position");
+ if (position) {
+ vLoc = position->FindElementTripletConvertTo("FT");
+ string frame = position->GetAttributeValue("frame");
+ frame = to_lower(frame);
+ if (frame == "eci") {
+ // Need to transform vLoc to ECEF for storage and use in FGLocation.
+ vLoc = Propagate->GetTi2ec()*vLoc;
+ } else if (frame == "ecef") {
+ // Move vLoc query until after lat/lon/alt query to eliminate spurious warning msgs.
+ if (vLoc.Magnitude() == 0.0) {
+ Propagate->SetLatitudeDeg(position->FindElementValueAsNumberConvertTo("latitude", "DEG"));
+ Propagate->SetLongitudeDeg(position->FindElementValueAsNumberConvertTo("longitude", "DEG"));
+ if (position->FindElement("radius")) {
+ radius_to_vehicle = position->FindElementValueAsNumberConvertTo("radius", "FT");
+ SetAltitudeASLFtIC(radius_to_vehicle - sea_level_radius);
+ } else if (position->FindElement("altitudeAGL")) {
+ SetAltitudeAGLFtIC(position->FindElementValueAsNumberConvertTo("altitudeAGL", "FT"));
+ } else if (position->FindElement("altitudeMSL")) {
+ SetAltitudeASLFtIC(position->FindElementValueAsNumberConvertTo("altitudeMSL", "FT"));
+ } else {
+ cerr << endl << " No altitude or radius initial condition is given." << endl;
+ result = false;
+ }
+ }
+ } else {
+ cerr << endl << " Neither ECI nor ECEF frame is specified for initial position." << endl;
+ result = false;
+ }
+ } else {
+ cerr << endl << " Initial position not specified in this initialization file." << endl;
+ result = false;
+ }
+
+ // End of position initialization
+
+ // Initialize vehicle orientation
+ // Allowable frames
+ // - ECI (Earth Centered Inertial)
+ // - ECEF (Earth Centered, Earth Fixed)
+ // - Local
+ //
+ // Need to convert the provided orientation to an ECI orientation, using
+ // the given orientation and knowledge of the Earth position angle.
+ // This could be done using matrices (where in the subscript "b/a",
+ // it is meant "b with respect to a", and where b=body frame,
+ // i=inertial frame, and e=ecef frame) as:
+ //
+ // C_b/i = C_b/e * C_e/i
+ //
+ // Using quaternions (note reverse ordering compared to matrix representation):
+ //
+ // Q_b/i = Q_e/i * Q_b/e
+ //
+ // Use the specific matrices as needed. The above example of course is for the whole
+ // body to inertial orientation.
+ // The new orientation angles can be extracted from the matrix or the quaternion.
+ // ToDo: Do we need to deal with normalization of the quaternions here?
+
+ Element* orientation_el = document->FindElement("orientation");
+ if (orientation_el) {
+ string frame = orientation_el->GetAttributeValue("frame");
+ frame = to_lower(frame);
+ vOrient = orientation_el->FindElementTripletConvertTo("RAD");
+ FGQuaternion QuatI2Body;
+ if (frame == "eci") {
+
+ QuatI2Body = FGQuaternion(vOrient);
+
+ } else if (frame == "ecef") {
+
+ // In this case we are given the Euler angles representing the orientation of
+ // the body with respect to the ECEF system, represented by the C_b/e Matrix.
+ // We want the body orientation with respect to the inertial system:
+ //
+ // C_b/i = C_b/e * C_e/i
+ //
+ // Using quaternions (note reverse ordering compared to matrix representation):
+ //
+ // Q_b/i = Q_e/i * Q_b/e
+
+ FGQuaternion QuatEC2Body(vOrient); // Store relationship of Body frame wrt ECEF frame, Q_b/e
+ FGQuaternion QuatI2EC = Propagate->GetTi2ec(); // Get Q_e/i from matrix
+ QuatI2Body = QuatI2EC * QuatEC2Body; // Q_b/i = Q_e/i * Q_b/e
+
+ } else if (frame == "local") {
+
+ // In this case, we are supplying the Euler angles for the vehicle with
+ // respect to the local (NED frame), also called the navigation frame.
+ // This is the most common way of initializing the orientation of
+ // aircraft. The matrix representation is:
+ //
+ // C_b/i = C_b/n * C_n/e * C_e/i
+ //
+ // Or, using quaternions (note reverse ordering compared to matrix representation):
+ //
+ // Q_b/i = Q_e/i * Q_n/e * Q_b/n
+
+ FGQuaternion QuatLocal2Body = FGQuaternion(vOrient); // Store relationship of Body frame wrt local (NED) frame, Q_b/n
+ FGQuaternion QuatEC2Local = Propagate->GetTec2l(); // Get Q_n/e from matrix
+ FGQuaternion QuatI2EC = Propagate->GetTi2ec(); // Get Q_e/i from matrix
+ QuatI2Body = QuatI2EC * QuatEC2Local * QuatLocal2Body; // Q_b/i = Q_e/i * Q_n/e * Q_b/n
+
+ } else {
+
+ cerr << endl << fgred << " Orientation frame type: \"" << frame
+ << "\" is not supported!" << reset << endl << endl;
+ result = false;
+
+ }
+
+ Propagate->SetInertialOrientation(QuatI2Body);
+ }
+
+ // Initialize vehicle velocity
+ // Allowable frames
+ // - ECI (Earth Centered Inertial)
+ // - ECEF (Earth Centered, Earth Fixed)
+ // - Local
+ // - Body
+ // The vehicle will be defaulted to (0,0,0) in the Body frame if nothing is provided.
+
+ Element* velocity_el = document->FindElement("velocity");
+ FGColumnVector3 vInertialVelocity;
+ FGColumnVector3 vInitVelocity = FGColumnVector3(0.0, 0.0, 0.0);
+ if (velocity_el) {
+
+ string frame = velocity_el->GetAttributeValue("frame");
+ frame = to_lower(frame);
+ FGColumnVector3 vInitVelocity = velocity_el->FindElementTripletConvertTo("FT/SEC");
+ FGColumnVector3 omega_cross_r = Inertial->omega() * Propagate->GetInertialPosition();
+
+ if (frame == "eci") {
+ vInertialVelocity = vInitVelocity;
+ } else if (frame == "ecef") {
+ FGMatrix33 mTec2i = Propagate->GetTec2i(); // Get C_i/e
+ vInertialVelocity = mTec2i * vInitVelocity + omega_cross_r;
+ } else if (frame == "local") {
+ FGMatrix33 mTl2i = Propagate->GetTl2i();
+ vInertialVelocity = mTl2i * vInitVelocity + omega_cross_r;
+ } else if (frame == "body") {
+ FGMatrix33 mTb2i = Propagate->GetTb2i();
+ vInertialVelocity = mTb2i * vInitVelocity + omega_cross_r;
+ } else {
+
+ cerr << endl << fgred << " Velocity frame type: \"" << frame
+ << "\" is not supported!" << reset << endl << endl;
+ result = false;
+
+ }
+
+ } else {
+
+ FGMatrix33 mTb2i = Propagate->GetTb2i();
+ vInertialVelocity = mTb2i * vInitVelocity + (Inertial->omega() * Propagate->GetInertialPosition());
+
+ }
+
+ Propagate->SetInertialVelocity(vInertialVelocity);
+
+ // Allowable frames
+ // - ECI (Earth Centered Inertial)
+ // - ECEF (Earth Centered, Earth Fixed)
+ // - Body
+
+ FGColumnVector3 vInertialRate;
+ Element* attrate_el = document->FindElement("attitude_rate");
+ if (attrate_el) {
+
+ string frame = attrate_el->GetAttributeValue("frame");
+ frame = to_lower(frame);
+ FGColumnVector3 vAttRate = attrate_el->FindElementTripletConvertTo("RAD/SEC");
+
+ if (frame == "eci") {
+ vInertialRate = vAttRate;
+ } else if (frame == "ecef") {
+// vInertialRate = vAttRate + Inertial->omega();
+ } else if (frame == "body") {
+ //Todo: determine local frame rate
+ FGMatrix33 mTb2l = Propagate->GetTb2l();
+// vInertialRate = mTb2l*vAttRate + Inertial->omega();
+ } else if (!frame.empty()) { // misspelling of frame
+
+ cerr << endl << fgred << " Attitude rate frame type: \"" << frame
+ << "\" is not supported!" << reset << endl << endl;
+ result = false;
+
+ } else if (frame.empty()) {
+
+ }
+
+ } else { // Body frame attitude rate assumed 0 relative to local.
+/*
+ //Todo: determine local frame rate
+
+ FGMatrix33 mTi2l = Propagate->GetTi2l();
+ vVel = mTi2l * vInertialVelocity;
+
+ // Compute the local frame ECEF velocity
+ vVel = Tb2l * VState.vUVW;
+
+ FGColumnVector3 vOmegaLocal = FGColumnVector3(
+ radInv*vVel(eEast),
+ -radInv*vVel(eNorth),
+ -radInv*vVel(eEast)*VState.vLocation.GetTanLatitude() );
+*/
+ }
+
+ // Check to see if any engines are specified to be initialized in a running state
+ FGPropulsion* propulsion = fdmex->GetPropulsion();
+ Element* running_elements = document->FindElement("running");
+ while (running_elements) {
+ n = int(running_elements->GetDataAsNumber());
+ propulsion->InitRunning(n);
+ running_elements = document->FindNextElement("running");
+ }
+
+ // fdmex->RunIC();
+
+ return result;
+}
+
+//******************************************************************************
+
void FGInitialCondition::bind(void){
PropertyManager->Tie("ic/vc-kts", this,
&FGInitialCondition::GetVcalibratedKtsIC,
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_INITIALCONDITION "$Id$"
+#define ID_INITIALCONDITION "$Id: FGInitialCondition.h,v 1.20 2010/02/15 03:22:57 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@property ic/r-rad_sec (read/write) Yaw rate initial condition in radians/second
@author Tony Peden
- @version "$Id$"
+ @version "$Id: FGInitialCondition.h,v 1.20 2010/02/15 03:22:57 jberndt Exp $"
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGFDMExec *fdmex;
FGPropertyManager *PropertyManager;
+ bool Load_v1(void);
+ bool Load_v2(void);
+
bool Constructing;
bool getAlpha(void);
bool getTheta(void);
#include "models/FGGroundReactions.h"
#include "models/FGInertial.h"
#include "models/FGAerodynamics.h"
+#include "models/FGPropulsion.h"
+#include "models/propulsion/FGEngine.h"
#include "math/FGColumnVector3.h"
#if _MSC_VER
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGTrim.cpp,v 1.13 2010/04/23 17:23:40 dpculp Exp $";
static const char *IdHdr = ID_TRIM;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fdmex->DisableOutput();
+ setEngineTrimMode(true);
+
fgic->SetPRadpsIC(0.0);
fgic->SetQRadpsIC(0.0);
fgic->SetRRadpsIC(0.0);
for(i=0;i < fdmex->GetGroundReactions()->GetNumGearUnits();i++){
fdmex->GetGroundReactions()->GetGearUnit(i)->SetReport(true);
}
+ setEngineTrimMode(false);
fdmex->EnableOutput();
return !trim_failed;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+void FGTrim::setEngineTrimMode(bool mode) {
+ FGPropulsion* prop = fdmex->GetPropulsion();
+ for (unsigned int i=0; i<prop->GetNumEngines(); i++) {
+ prop->GetEngine(i)->SetTrimMode(mode);
+ }
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
void FGTrim::SetMode(TrimMode tt) {
ClearStates();
mode=tt;
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_TRIM "$Id$"
+#define ID_TRIM "$Id: FGTrim.h,v 1.7 2010/04/23 17:23:40 dpculp Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@endcode
@author Tony Peden
- @version "$Id$"
+ @version "$Id: FGTrim.h,v 1.7 2010/04/23 17:23:40 dpculp Exp $"
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void setupTurn(void);
void updateRates(void);
-
+ void setEngineTrimMode(bool mode);
void setDebug(void);
public:
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGTrimAxis.cpp,v 1.10 2010/07/08 11:36:28 jberndt Exp $";
static const char *IdHdr = ID_TRIMAXIS;
/*****************************************************************************/
/*****************************************************************************/
void FGTrimAxis::AxisReport(void) {
+ // Save original cout format characteristics
+ std::ios_base::fmtflags originalFormat = cout.flags();
+ std::streamsize originalPrecision = cout.precision();
+ std::streamsize originalWidth = cout.width();
cout << " " << setw(20) << GetControlName() << ": ";
cout << setw(6) << setprecision(2) << GetControl()*control_convert << ' ';
cout << setw(5) << GetStateName() << ": ";
cout << " Passed" << endl;
else
cout << " Failed" << endl;
+ // Restore original cout format characteristics
+ cout.flags(originalFormat);
+ cout.precision(originalPrecision);
+ cout.width(originalWidth);
}
/*****************************************************************************/
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_TRIMAXIS "$Id$"
+#define ID_TRIMAXIS "$Id: FGTrimAxis.h,v 1.4 2006/10/01 22:47:47 jberndt Exp $"
#define DEFAULT_TOLERANCE 0.001
FGColumnVector3& vel) const
{
vel = FGColumnVector3(0.0, 0.0, 0.0);
- normal = (-1/FGColumnVector3(loc).Magnitude())*FGColumnVector3(loc);
- double radius = loc.GetRadius();
- double agl = GetAltitude(loc);
- contact = ((radius-agl)/radius)*FGColumnVector3(loc);
+ normal = FGColumnVector3(loc).Normalize();
+ double loc_radius = loc.GetRadius(); // Get the radius of the given location
+ // (e.g. the CG)
+ double agl = loc_radius - mReferenceRadius;
+ contact = (mReferenceRadius/loc_radius)*FGColumnVector3(loc);
return agl;
}
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_GROUNDCALLBACK "$Id$"
+#define ID_GROUNDCALLBACK "$Id: FGGroundCallback.h,v 1.8 2009/10/02 10:30:09 jberndt Exp $"
namespace JSBSim {
ball formed earth.
@author Mathias Froehlich
- @version $Id$
+ @version $Id: FGGroundCallback.h,v 1.8 2009/10/02 10:30:09 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+string FGPropertyManager::GetRelativeName( const string &path )
+{
+ string temp_string = GetFullyQualifiedName();
+ size_t len = path.length();
+ if ( (len > 0) && (temp_string.substr(0,len) == path) ) {
+ temp_string = temp_string.erase(0,len);
+ }
+ return temp_string;
+}
+
+
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_PROPERTYMANAGER "$Id$"
+#define ID_PROPERTYMANAGER "$Id: FGPropertyManager.h,v 1.17 2010/07/08 11:36:28 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
*/
std::string GetFullyQualifiedName(void);
+ /**
+ * Get the qualified name of a node relative to given base path,
+ * otherwise the fully qualified name.
+ * This function is very slow, so is probably useful for debugging only.
+ *
+ * @param path The path to strip off, if found.
+ */
+ std::string GetRelativeName( const std::string &path = "/fdm/jsbsim/" );
+
/**
* Get a bool value for a property.
*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGScript.h"
+#include "input_output/FGXMLElement.h"
#include "input_output/FGXMLParse.h"
#include "initialization/FGTrim.h"
#include <iostream>
#include <cstdlib>
+#include <iomanip>
using namespace std;
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGScript.cpp,v 1.41 2010/07/08 11:36:28 jberndt Exp $";
static const char *IdHdr = ID_FGSCRIPT;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGScript::FGScript(FGFDMExec* fgex) : FDMExec(fgex)
{
- State = FDMExec->GetState();
PropertyManager=FDMExec->GetPropertyManager();
+
Debug(0);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-bool FGScript::LoadScript( string script )
+bool FGScript::LoadScript(string script, double deltaT)
{
string aircraft="", initialize="", comparison = "", prop_name="";
string notifyPropertyName="";
// Set sim timing
StartTime = run_element->GetAttributeValueAsNumber("start");
- State->Setsim_time(StartTime);
+ FDMExec->Setsim_time(StartTime);
EndTime = run_element->GetAttributeValueAsNumber("end");
- dt = run_element->GetAttributeValueAsNumber("dt");
- State->Setdt(dt);
+
+ if (deltaT == 0.0)
+ dt = run_element->GetAttributeValueAsNumber("dt");
+ else {
+ dt = deltaT;
+ cout << endl << "Overriding simulation step size from the command line. New step size is: "
+ << deltaT << " seconds (" << 1/deltaT << " Hz)" << endl << endl;
+ }
+
+ FDMExec->Setdt(dt);
// read aircraft and initialization files
if (output_file.empty()) {
cerr << "No logging directives file was specified." << endl;
} else {
- FDMExec->SetOutputDirectives(output_file);
+ if (!FDMExec->SetOutputDirectives(output_file)) return false;
}
}
// Process the conditions
condition_element = event_element->FindElement("condition");
if (condition_element != 0) {
- newCondition = new FGCondition(condition_element, PropertyManager);
+ try {
+ newCondition = new FGCondition(condition_element, PropertyManager);
+ } catch(string str) {
+ cout << endl << fgred << str << reset << endl << endl;
+ return false;
+ }
newEvent->Condition = newCondition;
} else {
cerr << "No condition specified in script event " << newEvent->Name << endl;
unsigned i, j;
unsigned event_ctr = 0;
- double currentTime = State->Getsim_time();
+ double currentTime = FDMExec->GetSimTime();
double newSetValue = 0;
if (currentTime > EndTime) return false; //Script done!
cout << endl << " Event " << event_ctr << " (" << Events[ev_ctr].Name << ")"
<< " executed at time: " << currentTime << endl;
for (j=0; j<Events[ev_ctr].NotifyProperties.size();j++) {
- cout << " " << Events[ev_ctr].NotifyProperties[j]->GetName()
+ cout << " " << Events[ev_ctr].NotifyProperties[j]->GetRelativeName()
<< " = " << Events[ev_ctr].NotifyProperties[j]->getDoubleValue() << endl;
}
cout << endl;
cout << endl;
cout << "Script: \"" << ScriptName << "\"" << endl;
cout << " begins at " << StartTime << " seconds and runs to " << EndTime
- << " seconds with dt = " << State->Getdt() << endl;
+ << " seconds with dt = " << setprecision(6) << FDMExec->GetDeltaT() << " (" <<
+ ceil(1.0/FDMExec->GetDeltaT()) << " Hz)" << endl;
cout << endl;
for (unsigned int i=0; i<local_properties.size(); i++) {
Events[i].Condition->PrintCondition();
- cout << endl << " Actions taken:" << endl << " {";
+ cout << endl << " Actions taken";
+ if (Events[i].Delay > 0.0)
+ cout << " (after a delay of " << Events[i].Delay << " secs)";
+ cout << ":" << endl << " {";
for (unsigned j=0; j<Events[i].SetValue.size(); j++) {
if (Events[i].SetValue[j] == 0.0 && Events[i].Functions[j] != 0L) {
if (Events[i].SetParam[j] == 0) {
<< reset << endl;
exit(-1);
}
- cout << endl << " set " << Events[i].SetParam[j]->GetName()
+ cout << endl << " set " << Events[i].SetParam[j]->GetRelativeName("/fdm/jsbsim/")
<< " to function value";
} else {
if (Events[i].SetParam[j] == 0) {
<< reset << endl;
exit(-1);
}
- cout << endl << " set " << Events[i].SetParam[j]->GetName()
+ cout << endl << " set " << Events[i].SetParam[j]->GetRelativeName("/fdm/jsbsim/")
<< " to " << Events[i].SetValue[j];
}
if (Events[i].Action[j] == FG_RAMP || Events[i].Action[j] == FG_EXP)
cout << " with time constant " << Events[i].TC[j] << ")";
}
- cout << endl << " }" << endl << endl;
-
+ cout << endl << " }" << endl;
+
+ // Print notifications
+ if (Events[i].Notify) {
+ if (Events[i].NotifyProperties.size() > 0) {
+ cout << " Notifications" << ":" << endl << " {" << endl;
+ for (unsigned j=0; j<Events[i].NotifyProperties.size();j++) {
+ cout << " "
+ << Events[i].NotifyProperties[j]->GetRelativeName("/fdm/jsbsim/")
+ << endl;
+ }
+ cout << " }" << endl;
+ }
+ }
+ cout << endl;
}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGJSBBase.h"
-#include "FGState.h"
#include "FGFDMExec.h"
#include "math/FGFunction.h"
#include "math/FGCondition.h"
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FGSCRIPT "$Id$"
+#define ID_FGSCRIPT "$Id: FGScript.h,v 1.18 2010/04/11 13:44:42 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
comes the "run" section, where the conditions are
described in "event" clauses.</p>
@author Jon S. Berndt
- @version "$Id$"
+ @version "$Id: FGScript.h,v 1.18 2010/04/11 13:44:42 jberndt Exp $"
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
~FGScript();
/** Loads a script to drive JSBSim (usually in standalone mode).
- The language is the Script Directives for JSBSim.
+ The language is the Script Directives for JSBSim. If a simulation step size
+ has been supplied on the command line, it will be override the script-
+ specified simulation step size.
@param script the filename (including path name, if any) for the script.
+ @param deltaT a simulation step size from the command line
@return true if successful */
- bool LoadScript( string script );
+ bool LoadScript(string script, double deltaT);
/** This function is called each pass through the executive Run() method IF
scripting is enabled.
vector <LocalProps*> local_properties;
FGFDMExec* FDMExec;
- FGState* State;
FGPropertyManager* PropertyManager;
void Debug(int from);
};
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGXMLElement.cpp,v 1.29 2010/03/18 13:18:31 jberndt Exp $";
static const char *IdHdr = ID_XMLELEMENT;
bool Element::converterIsInitialized = false;
convert["KTS"]["FT/SEC"] = 1.68781;
convert["FT/SEC"]["KTS"] = 1.0/convert["KTS"]["FT/SEC"];
convert["M/S"]["FT/S"] = 3.2808399;
+ convert["M/SEC"]["FT/SEC"] = 3.2808399;
convert["FT/S"]["M/S"] = 1.0/convert["M/S"]["FT/S"];
+ convert["M/SEC"]["FT/SEC"] = 3.2808399;
+ convert["FT/SEC"]["M/SEC"] = 1.0/convert["M/SEC"]["FT/SEC"];
// Torque
convert["FT*LBS"]["N*M"] = 1.35581795;
convert["N*M"]["FT*LBS"] = 1/convert["FT*LBS"]["N*M"];
convert["FT/SEC"]["FT/SEC"] = 1.00;
convert["KTS"]["KTS"] = 1.00;
convert["M/S"]["M/S"] = 1.0;
+ convert["M/SEC"]["M/SEC"] = 1.0;
// Torque
convert["FT*LBS"]["FT*LBS"] = 1.00;
convert["N*M"]["N*M"] = 1.00;
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_XMLELEMENT "$Id$"
+#define ID_XMLELEMENT "$Id: FGXMLElement.h,v 1.16 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
- GAL = gallon (U.S. liquid)
@author Jon S. Berndt
- @version $Id$
+ @version $Id: FGXMLElement.h,v 1.16 2009/10/24 22:59:30 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_XMLFILEREAD "$Id$"
+#define ID_XMLFILEREAD "$Id: FGXMLFileRead.h,v 1.5 2009/11/28 20:12:47 andgi Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGXMLParse.cpp,v 1.10 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_XMLPARSE;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_XMLPARSE "$Id$"
+#define ID_XMLPARSE "$Id: FGXMLParse.h,v 1.7 2009/10/24 22:59:30 jberndt Exp $"
#define VALID_CHARS """`!@#$%^&*()_+`1234567890-={}[];':,.<>/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/** Encapsulates an XML parser based on the EasyXML parser from the SimGear library.
@author Jon S. Berndt
- @version $Id$
+ @version $Id: FGXMLParse.h,v 1.7 2009/10/24 22:59:30 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGfdmSocket.cpp,v 1.27 2010/05/13 03:07:59 jberndt Exp $";
static const char *IdHdr = ID_FDMSOCKET;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cout << "Could not get host net address by name..." << endl;
}
} else {
- if ((host = gethostbyaddr(address.c_str(), address.size(), PF_INET)) == NULL) {
+ unsigned int ip;
+ ip = inet_addr(address.c_str());
+ if ((host = gethostbyaddr((char*)&ip, address.size(), PF_INET)) == NULL) {
cout << "Could not get host net address by number..." << endl;
}
}
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
+ #include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <sys/ioctl.h>
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FDMSOCKET "$Id$"
+#define ID_FDMSOCKET "$Id: FGfdmSocket.h,v 1.19 2010/05/13 03:07:59 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_STRINGUTILS "$Id$"
+#define ID_STRINGUTILS "$Id: string_utilities.h,v 1.13 2010/07/07 11:59:48 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
extern std::string& trim_left(std::string& str);
extern std::string& trim_right(std::string& str);
extern std::string& trim(std::string& str);
+ extern std::string& trim_all_space(std::string& str);
extern std::string& to_upper(std::string& str);
extern std::string& to_lower(std::string& str);
extern bool is_number(const std::string& str);
std::vector <std::string> split(std::string str, char d);
#else
- #include <ctype.h>
+ #include <cctype>
using namespace std;
string& trim_left(string& str)
{
- while (str.size() && !isgraph(str[0])) {
+ while (str.size() && isspace((unsigned char)str[0])) {
str = str.erase(0,1);
}
return str;
string& trim_right(string& str)
{
- while (str.size() && !isgraph(str[str.size()-1])) {
+ while (str.size() && isspace((unsigned char)str[str.size()-1])) {
str = str.erase(str.size()-1,1);
}
return str;
return str = trim_left(temp_str);
}
+ string& trim_all_space(string& str)
+ {
+ for (size_t i=0; i<str.size(); i++) {
+ if (isspace((unsigned char)str[i])) {
+ str = str.erase(i,1);
+ --i;
+ }
+ }
+ return str;
+ }
+
string& to_upper(string& str)
{
for (size_t i=0; i<str.size(); i++) str[i] = toupper(str[i]);
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGColumnVector3.cpp,v 1.12 2010/06/30 03:13:40 jberndt Exp $";
static const char *IdHdr = ID_COLUMNVECTOR3;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGColumnVector3::Dump(const string& delimiter) const
{
ostringstream buffer;
- buffer << std::setw(18) << std::setprecision(16) << Entry(1) << delimiter;
- buffer << std::setw(18) << std::setprecision(16) << Entry(2) << delimiter;
- buffer << std::setw(18) << std::setprecision(16) << Entry(3);
+ buffer << std::setw(18) << std::setprecision(16) << data[0] << delimiter;
+ buffer << std::setw(18) << std::setprecision(16) << data[1] << delimiter;
+ buffer << std::setw(18) << std::setprecision(16) << data[2];
return buffer.str();
}
double FGColumnVector3::Magnitude(void) const
{
- if (Entry(1) == 0.0 && Entry(2) == 0.0 && Entry(3) == 0.0)
+ if (data[0] == 0.0 && data[1] == 0.0 && data[2] == 0.0)
return 0.0;
else
- return sqrt( Entry(1)*Entry(1) + Entry(2)*Entry(2) + Entry(3)*Entry(3) );
+ return sqrt( data[0]*data[0] + data[1]*data[1] + data[2]*data[2] );
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_COLUMNVECTOR3 "$Id$"
+#define ID_COLUMNVECTOR3 "$Id: FGColumnVector3.h,v 1.12 2010/06/30 03:13:40 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
/** This class implements a 3 element column vector.
@author Jon S. Berndt, Tony Peden, et. al.
- @version $Id$
+ @version $Id: FGColumnVector3.h,v 1.12 2010/06/30 03:13:40 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data[0] = X;
data[1] = Y;
data[2] = Z;
- Debug(0);
+// Debug(0);
}
/** Copy constructor.
data[0] = v.data[0];
data[1] = v.data[1];
data[2] = v.data[2];
- Debug(0);
+// Debug(0);
}
/// Destructor.
- ~FGColumnVector3(void) { Debug(1); }
+ ~FGColumnVector3(void) { /* Debug(1); */ }
/** Read access the entries of the vector.
@param idx the component index.
Return the value of the matrix entry at the given index.
Indices are counted starting with 1.
Note that the index given in the argument is unchecked. */
- double operator()(unsigned int idx) const { return Entry(idx); }
+ double operator()(unsigned int idx) const { return data[idx-1]; }
/** Write access the entries of the vector.
@param idx the component index.
Return a reference to the vector entry at the given index.
Indices are counted starting with 1.
Note that the index given in the argument is unchecked. */
- double& operator()(unsigned int idx) { return Entry(idx); }
+ double& operator()(unsigned int idx) { return data[idx-1]; }
/** Read access the entries of the vector.
@param idx the component index.
@return The resulting vector from the multiplication with that scalar.
Multiply the vector with the scalar given in the argument. */
FGColumnVector3 operator*(const double scalar) const {
- return FGColumnVector3(scalar*Entry(1), scalar*Entry(2), scalar*Entry(3));
+ return FGColumnVector3(scalar*data[0], scalar*data[1], scalar*data[2]);
}
/** Multiply by 1/scalar.
Compute and return the cross product of the current vector with
the given argument. */
FGColumnVector3 operator*(const FGColumnVector3& V) const {
- return FGColumnVector3( Entry(2) * V(3) - Entry(3) * V(2),
- Entry(3) * V(1) - Entry(1) * V(3),
- Entry(1) * V(2) - Entry(2) * V(1) );
+ return FGColumnVector3( data[1] * V(3) - data[2] * V(2),
+ data[2] * V(1) - data[0] * V(3),
+ data[0] * V(2) - data[1] * V(1) );
}
/// Addition operator.
FGColumnVector3 operator+(const FGColumnVector3& B) const {
- return FGColumnVector3( Entry(1) + B(1), Entry(2) + B(2), Entry(3) + B(3) );
+ return FGColumnVector3( data[0] + B(1), data[1] + B(2), data[2] + B(3) );
}
/// Subtraction operator.
FGColumnVector3 operator-(const FGColumnVector3& B) const {
- return FGColumnVector3( Entry(1) - B(1), Entry(2) - B(2), Entry(3) - B(3) );
+ return FGColumnVector3( data[0] - B(1), data[1] - B(2), data[2] - B(3) );
}
/// Subtract an other vector.
FGColumnVector3& operator-=(const FGColumnVector3 &B) {
- Entry(1) -= B(1);
- Entry(2) -= B(2);
- Entry(3) -= B(3);
+ data[0] -= B(1);
+ data[1] -= B(2);
+ data[2] -= B(3);
return *this;
}
/// Add an other vector.
FGColumnVector3& operator+=(const FGColumnVector3 &B) {
- Entry(1) += B(1);
- Entry(2) += B(2);
- Entry(3) += B(3);
+ data[0] += B(1);
+ data[1] += B(2);
+ data[2] += B(3);
return *this;
}
/// Scale by a scalar.
FGColumnVector3& operator*=(const double scalar) {
- Entry(1) *= scalar;
- Entry(2) *= scalar;
- Entry(3) *= scalar;
+ data[0] *= scalar;
+ data[1] *= scalar;
+ data[2] *= scalar;
return *this;
}
Compute and return the euclidean norm of this vector projected into
the coordinate axis plane idx1-idx2. */
double Magnitude(int idx1, int idx2) const {
- return sqrt( Entry(idx1)*Entry(idx1) + Entry(idx2)*Entry(idx2) );
+ return sqrt( data[idx1-1]*data[idx1-1] + data[idx2-1]*data[idx2-1] );
}
/** Normalize.
is equal to zero it is left untouched. */
FGColumnVector3& Normalize(void);
- // little trick here.
- struct AssignRef {
- AssignRef(FGColumnVector3& r, int i) : Ref(r), idx(i) {}
- AssignRef operator<<(const double ff) {
- Ref.Entry(idx) = ff;
- return AssignRef(Ref, idx+1);
- }
- FGColumnVector3& Ref;
- int idx;
- };
- AssignRef operator<<(const double ff) {
- Entry(1) = ff;
- return AssignRef(*this, 2);
- }
-
private:
double data[3];
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGCondition.cpp,v 1.13 2010/07/14 05:50:40 ehofman Exp $";
static const char *IdHdr = ID_CONDITION;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
exit(-1);
}
- TestParam1 = PropertyManager->GetNode(property1, true);
+ TestParam1 = PropertyManager->GetNode(property1, false);
+ if (!TestParam1) {
+ cerr << fgred << " In condition: " << test << ". Unknown property "
+ << property1 << " referenced." << endl
+ << "Creating property. Check usage." << reset << endl;
+ TestParam1 = PropertyManager->GetNode(property1, true);
+ }
Comparison = mComparison[conditional];
+ if (Comparison == ecUndef) {
+ throw("Comparison operator: \""+conditional+"\" does not exist. Please check the conditional.");
+ }
if (is_number(property2)) {
TestValue = atof(property2.c_str());
} else {
- TestParam2 = PropertyManager->GetNode(property2, true);
+ TestParam2 = PropertyManager->GetNode(property2, false);
+ if (!TestParam2) {
+ cerr << fgred << " In condition: " << test << ". Unknown property "
+ << property2 << " referenced." << endl
+ << "Creating property. Check usage." << reset << endl;
+ TestParam2 = PropertyManager->GetNode(property2, true);
+ }
}
}
} else {
if (TestParam2 != 0L)
- cout << " " << TestParam1->GetName() << " " << conditional << " " << TestParam2->GetName();
+ cout << " " << TestParam1->GetRelativeName() << " "
+ << conditional << " "
+ << TestParam2->GetRelativeName();
else
- cout << " " << TestParam1->GetName() << " " << conditional << " " << TestValue;
+ cout << " " << TestParam1->GetRelativeName() << " "
+ << conditional << " " << TestValue;
}
}
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_CONDITION "$Id$"
+#define ID_CONDITION "$Id: FGCondition.h,v 1.5 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGFunction.cpp,v 1.32 2010/03/18 13:21:24 jberndt Exp $";
static const char *IdHdr = ID_FUNCTION;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
}
break;
case eQuotient:
- temp /= Parameters[1]->GetValue();
+ if (Parameters[1]->GetValue() != 0.0)
+ temp /= Parameters[1]->GetValue();
+ else
+ temp = HUGE_VAL;
break;
case ePow:
temp = pow(temp,Parameters[1]->GetValue());
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FUNCTION "$Id$"
+#define ID_FUNCTION "$Id: FGFunction.h,v 1.21 2009/11/18 04:49:02 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGLocation.cpp,v 1.21 2010/07/02 01:48:12 jberndt Exp $";
static const char *IdHdr = ID_LOCATION;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
e = 1.0;
eps2 = -1.0;
f = 1.0;
+ epa = 0.0;
+
+ mLon = mLat = mRadius = mGeodLat = GeodeticAltitude = 0.0;
+
+// initial_longitude = 0.0;
+
+ mTl2ec.InitMatrix();
+ mTec2l.InitMatrix();
+ mTi2ec.InitMatrix();
+ mTec2i.InitMatrix();
+ mTi2l.InitMatrix();
+ mTl2i.InitMatrix();
+ mECLoc.InitMatrix();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
double cosLat = cos(lat);
double sinLon = sin(lon);
double cosLon = cos(lon);
- initial_longitude = lon;
+
a = 0.0;
b = 0.0;
a2 = 0.0;
e = 1.0;
eps2 = -1.0;
f = 1.0;
+ epa = 0.0;
mECLoc = FGColumnVector3( radius*cosLat*cosLon,
radius*cosLat*sinLon,
radius*sinLat );
+ mLon = mLat = mRadius = mGeodLat = GeodeticAltitude = 0.0;
+
+// initial_longitude = 0.0
+
+ ComputeDerived();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
double cosLat = cos(lat);
double sinLon = sin(lon);
double cosLon = cos(lon);
- initial_longitude = lon;
+// initial_longitude = lon;
mECLoc = FGColumnVector3( radius*cosLat*cosLon,
radius*cosLat*sinLon,
radius*sinLat );
mLon = lon;
GeodeticAltitude = height;
- initial_longitude = mLon;
+// initial_longitude = mLon;
double RN = a / sqrt(1.0 - e2*sin(mGeodLat)*sin(mGeodLat));
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Compute the ECEF to ECI transformation matrix using Stevens and Lewis "Aircraft
-// Control and Simulation", second edition, eqn. 1.4-12, pg. 39
+// Control and Simulation", second edition, eqn. 1.4-12, pg. 39. In Stevens and Lewis
+// notation, this is C_i/e, a transformation from ECEF to ECI.
-const FGMatrix33& FGLocation::GetTec2i(double epa)
+const FGMatrix33& FGLocation::GetTec2i(void)
{
- double mu = epa - initial_longitude;
- mTec2i = FGMatrix33( cos(mu), -sin(mu), 0.0,
- sin(mu), cos(mu), 0.0,
- 0.0, 0.0, 1.0 );
return mTec2i;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+// This is given in Stevens and Lewis "Aircraft
+// Control and Simulation", second edition, eqn. 1.4-12, pg. 39
+// The notation in Stevens and Lewis is: C_e/i. This represents a transformation
+// from ECI to ECEF - and the orientation of the ECEF frame relative to the ECI
+// frame.
-const FGMatrix33& FGLocation::GetTi2ec(double epa)
+const FGMatrix33& FGLocation::GetTi2ec(void)
{
- double mu = epa - initial_longitude;
- mTi2ec = FGMatrix33( cos(mu), sin(mu), 0.0,
- -sin(mu), cos(mu), 0.0,
- 0.0, 0.0, 1.0 );
return mTi2ec;
}
// The distance of the location to the Z-axis, which is the axis
// through the poles.
- double rxy = sqrt(mECLoc(eX)*mECLoc(eX) + mECLoc(eY)*mECLoc(eY));
+ double r02 = mECLoc(eX)*mECLoc(eX) + mECLoc(eY)*mECLoc(eY);
+ double rxy = sqrt(r02);
// Compute the sin/cos values of the longitude
double sinLon, cosLon;
// Compute the transform matrices from and to the earth centered frame.
// See Stevens and Lewis, "Aircraft Control and Simulation", Second Edition,
- // Eqn. 1.4-13, page 40.
+ // Eqn. 1.4-13, page 40. In Stevens and Lewis notation, this is C_n/e - the
+ // orientation of the navigation (local) frame relative to the ECEF frame,
+ // and a transformation from ECEF to nav (local) frame.
+
mTec2l = FGMatrix33( -cosLon*sinLat, -sinLon*sinLat, cosLat,
-sinLon , cosLon , 0.0 ,
-cosLon*cosLat, -sinLon*cosLat, -sinLat );
+ // In Stevens and Lewis notation, this is C_e/n - the
+ // orientation of the ECEF frame relative to the nav (local) frame,
+ // and a transformation from nav (local) to ECEF frame.
+
mTl2ec = mTec2l.Transposed();
-
+
+ // Calculate the inertial to ECEF and transpose matrices
+ double cos_epa = cos(epa);
+ double sin_epa = sin(epa);
+ mTi2ec = FGMatrix33( cos_epa, sin_epa, 0.0,
+ -sin_epa, cos_epa, 0.0,
+ 0.0, 0.0, 1.0 );
+ mTec2i = mTi2ec.Transposed();
+
+ // Now calculate the local (or nav, or ned) frame to inertial transform matrix,
+ // and the inverse.
+ mTl2i = mTec2i * mTl2ec;
+ mTi2l = mTl2i.Transposed();
+
// Calculate the geodetic latitude base on AIAA Journal of Guidance and Control paper,
// "Improved Method for Calculating Exact Geodetic Latitude and Altitude", and
// "Improved Method for Calculating Exact Geodetic Latitude and Altitude, Revisited",
// author: I. Sofair
if (a != 0.0 && b != 0.0) {
- double c, p, q, s, t, u, v, w, z, p2, u2, r02, r0;
+ double c, p, q, s, t, u, v, w, z, p2, u2, r0;
double Ne, P, Q0, Q, signz0, sqrt_q;
p = fabs(mECLoc(eZ))/eps2;
- r02 = mECLoc(eX)*mECLoc(eX) + mECLoc(eY)*mECLoc(eY);
s = r02/(e2*eps2);
p2 = p*p;
q = p2 - b2 + s;
z = signz0*sqrt_q*(w+sqrt(sqrt(t*t+v)-u*w-0.5*t-0.25));
Ne = a*sqrt(1+eps2*z*z/b2);
mGeodLat = asin((eps2+1.0)*(z/Ne));
- r0 = sqrt(r02);
+ r0 = rxy;
GeodeticAltitude = r0*cos(mGeodLat) + mECLoc(eZ)*sin(mGeodLat) - a2/Ne;
}
}
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_LOCATION "$Id$"
+#define ID_LOCATION "$Id: FGLocation.h,v 1.21 2010/07/09 04:11:45 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
CLASS DOCUMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-/** Holds an arbitrary location in the earth centered reference frame.
- This coordinate frame has its center in the middle of the earth.
- Its x-axis points from the center of the earth towards a location
- with zero latitude and longitude on the earths surface. The y-axis
- points from the center of the earth towards a location with zero
- latitude and 90deg longitude on the earths surface. The z-axis
- points from the earths center to the geographic north pole.
-
- This class provides access functions to set and get the location as
- either the simple x, y and z values in ft or longitude/latitude and
- the radial distance of the location from the earth center.
-
- It is common to associate a parent frame with a location. This
- frame is usually called the local horizontal frame or simply the local
- frame. This frame has its x/y plane parallel to the surface of the earth
- (with the assumption of a spherical earth). The x-axis points
- towards north, the y-axis points towards east and the z-axis
- points to the center of the earth.
-
- Since this frame is determined by the location, this class also
- provides the rotation matrices required to transform from the
- earth centered frame to the local horizontal frame and back. There
- are also conversion functions for conversion of position vectors
- given in the one frame to positions in the other frame.
-
- The earth centered reference frame is *NOT* an inertial frame
- since it rotates with the earth.
-
- The coordinates in the earth centered frame are the master values.
- All other values are computed from these master values and are
- cached as long as the location is changed by access through a
- non-const member function. Values are cached to improve performance.
- It is best practice to work with a natural set of master values.
- Other parameters that are derived from these master values are calculated
- only when needed, and IF they are needed and calculated, then they are
- cached (stored and remembered) so they do not need to be re-calculated
- until the master values they are derived from are themselves changed
- (and become stale).
-
- Accuracy and round off:
-
- Given that we model a vehicle near the earth, the earths surface
- radius is about 2*10^7, ft and that we use double values for the
- representation of the location, we have an accuracy of about
- 1e-16*2e7ft/1=2e-9ft left. This should be sufficient for our needs.
- Note that this is the same relative accuracy we would have when we
- compute directly with lon/lat/radius. For the radius value this
- is clear. For the lon/lat pair this is easy to see. Take for
- example KSFO located at about 37.61deg north 122.35deg west, which
- corresponds to 0.65642rad north and 2.13541rad west. Both values
- are of magnitude of about 1. But 1ft corresponds to about
- 1/(2e7*2*pi)=7.9577e-09rad. So the left accuracy with this
- representation is also about 1*1e-16/7.9577e-09=1.2566e-08 which
- is of the same magnitude as the representation chosen here.
-
- The advantage of this representation is that it is a linear space
- without singularities. The singularities are the north and south
- pole and most notably the non-steady jump at -pi to pi. It is
- harder to track this jump correctly especially when we need to
- work with error norms and derivatives of the equations of motion
- within the time-stepping code. Also, the rate of change is of the
- same magnitude for all components in this representation which is
- an advantage for numerical stability in implicit time-stepping too.
-
- Note: The latitude is a GEOCENTRIC value. FlightGear
- converts latitude to a geodetic value and uses that. In order to get best
- matching relative to a map, geocentric latitude must be converted to geodetic.
+/** FGLocation holds an arbitrary location in the Earth centered Earth fixed
+ reference frame (ECEF). This coordinate frame has its center in the middle
+ of the earth. The X-axis points from the center of the Earth towards a
+ location with zero latitude and longitude on the Earth surface. The Y-axis
+ points from the center of the Earth towards a location with zero latitude
+ and 90 deg East longitude on the Earth surface. The Z-axis points from the
+ Earth center to the geographic north pole.
+
+ This class provides access functions to set and get the location as either
+ the simple X, Y and Z values in ft or longitude/latitude and the radial
+ distance of the location from the Earth center.
+
+ It is common to associate a parent frame with a location. This frame is
+ usually called the local horizontal frame or simply the local frame. It is
+ also called the NED frame (North, East, Down), as well as the Navigation
+ frame. This frame has its X/Y plane parallel to the surface of the Earth
+ (with the assumption of a spherical Earth). The X-axis points towards north,
+ the Y-axis points east and the Z-axis points to the center of the Earth.
+
+ Since the local frame is determined by the location (and NOT by the
+ orientation of the vehicle IN any frame), this class also provides the
+ rotation matrices required to transform from the Earth centered (ECEF) frame
+ to the local horizontal frame and back. This class also "owns" the
+ transformations that go from the inertial frame (Earth-centered Inertial, or
+ ECI) to and from the ECEF frame, as well as to and from the local frame.
+ Again, this is because the ECI, ECEF, and local frames do not involve the
+ actual orientation of the vehicle - only the location on the Earth surface,
+ and the angular difference between the ECI and ECEF frames. There are
+ conversion functions for conversion of position vectors given in the one
+ frame to positions in the other frame.
+
+ The Earth centered reference frame is NOT an inertial frame since it rotates
+ with the Earth.
+
+ The coordinates in the Earth centered frame are the master values. All other
+ values are computed from these master values and are cached as long as the
+ location is changed by access through a non-const member function. Values
+ are cached to improve performance. It is best practice to work with a
+ natural set of master values. Other parameters that are derived from these
+ master values are calculated only when needed, and IF they are needed and
+ calculated, then they are cached (stored and remembered) so they do not need
+ to be re-calculated until the master values they are derived from are
+ themselves changed (and become stale).
+
+ Accuracy and round off
+
+ Given,
+
+ -that we model a vehicle near the Earth
+ -that the Earth surface radius is about 2*10^7, ft
+ -that we use double values for the representation of the location
+
+ we have an accuracy of about
+
+ 1e-16*2e7ft/1 = 2e-9 ft
+
+ left. This should be sufficient for our needs. Note that this is the same
+ relative accuracy we would have when we compute directly with
+ lon/lat/radius. For the radius value this is clear. For the lon/lat pair
+ this is easy to see. Take for example KSFO located at about 37.61 deg north
+ 122.35 deg west, which corresponds to 0.65642 rad north and 2.13541 rad
+ west. Both values are of magnitude of about 1. But 1 ft corresponds to about
+ 1/(2e7*2*pi) = 7.9577e-09 rad. So the left accuracy with this representation
+ is also about 1*1e-16/7.9577e-09 = 1.2566e-08 which is of the same magnitude
+ as the representation chosen here.
+
+ The advantage of this representation is that it is a linear space without
+ singularities. The singularities are the north and south pole and most
+ notably the non-steady jump at -pi to pi. It is harder to track this jump
+ correctly especially when we need to work with error norms and derivatives
+ of the equations of motion within the time-stepping code. Also, the rate of
+ change is of the same magnitude for all components in this representation
+ which is an advantage for numerical stability in implicit time-stepping.
+
+ Note: The latitude is a GEOCENTRIC value. FlightGear converts latitude to a
+ geodetic value and uses that. In order to get best matching relative to a
+ map, geocentric latitude must be converted to geodetic.
@see Stevens and Lewis, "Aircraft Control and Simulation", Second edition
@see W. C. Durham "Aircraft Dynamics & Control", section 2.2
@author Mathias Froehlich
- @version $Id$
+ @version $Id: FGLocation.h,v 1.21 2010/07/09 04:11:45 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
and semiminor axis lengths */
void SetEllipse(double semimajor, double semiminor);
+ /** Sets the Earth position angle.
+ This is the relative orientation of the ECEF frame with respect to the
+ Inertial frame.
+ @param EPA Earth fixed frame (ECEF) rotation offset about the axis with
+ respect to the Inertial (ECI) frame in radians. */
+ void SetEarthPositionAngle(double EPA) {epa = EPA; /*mCacheValid = false;*/ ComputeDerived();}
+
/** Get the longitude.
@return the longitude in rad of the location represented with this
class instance. The returned values are in the range between
@return the distance of the location represented with this class
instance to the center of the earth in ft. The radius value is
always positive. */
- double GetRadius() const { ComputeDerived(); return mRadius; }
+ double GetRadius() const { return mECLoc.Magnitude(); }
/** Transform matrix from local horizontal to earth centered frame.
Returns a const reference to the rotation matrix of the transform from
/** Transform matrix from inertial to earth centered frame.
Returns a const reference to the rotation matrix of the transform from
the inertial frame to the earth centered frame (ECI to ECEF). */
- const FGMatrix33& GetTi2ec(double epa);
+ const FGMatrix33& GetTi2ec(void);
/** Transform matrix from the earth centered to inertial frame.
Returns a const reference to the rotation matrix of the transform from
the earth centered frame to the inertial frame (ECEF to ECI). */
- const FGMatrix33& GetTec2i(double epa);
+ const FGMatrix33& GetTec2i(void);
+
+ const FGMatrix33& GetTi2l(void) const {return mTi2l;}
+
+ const FGMatrix33& GetTl2i(void) const {return mTl2i;}
/** Conversion from Local frame coordinates to a location in the
earth centered and fixed frame.
Return the value of the matrix entry at the given index.
Indices are counted starting with 1.
Note that the index given in the argument is unchecked. */
- double operator()(unsigned int idx) const { return Entry(idx); }
+ double operator()(unsigned int idx) const { return mECLoc.Entry(idx); }
/** Write access the entries of the vector.
@param idx the component index.
@return a reference to the vector entry at the given index.
Indices are counted starting with 1.
Note that the index given in the argument is unchecked. */
- double& operator()(unsigned int idx) { return Entry(idx); }
+ double& operator()(unsigned int idx) { mCacheValid = false; return mECLoc.Entry(idx); }
/** Read access the entries of the vector.
@param idx the component index.
mCacheValid = false; return mECLoc.Entry(idx);
}
+ /** Sets this location via the supplied vector.
+ The location can be set by an Earth-centered, Earth-fixed (ECEF) frame
+ position vector. The cache is marked as invalid, so any future requests
+ for selected important data will cause the parameters to be calculated.
+ @param v the ECEF column vector in feet.
+ @return a reference to the FGLocation object. */
const FGLocation& operator=(const FGColumnVector3& v)
{
mECLoc(eX) = v(eX);
return *this;
}
+ /** Sets this location via the supplied location object.
+ @param v A location object reference.
+ @return a reference to the FGLocation object. */
const FGLocation& operator=(const FGLocation& l)
{
mECLoc = l.mECLoc;
return *this;
}
+
+ /** This operator returns true if the ECEF location vectors for the two
+ location objects are equal. */
bool operator==(const FGLocation& l) const {
return mECLoc == l.mECLoc;
}
+
+ /** This operator returns true if the ECEF location vectors for the two
+ location objects are not equal. */
bool operator!=(const FGLocation& l) const { return ! operator==(l); }
+
+ /** This operator adds the ECEF position vectors.
+ The supplied vector (right side) is added to the ECEF position vector
+ on the left side of the equality, and a pointer to this object is
+ returned. */
const FGLocation& operator+=(const FGLocation &l) {
mCacheValid = false;
mECLoc += l.mECLoc;
return *this;
}
+
const FGLocation& operator-=(const FGLocation &l) {
mCacheValid = false;
mECLoc -= l.mECLoc;
return *this;
}
+
const FGLocation& operator*=(double scalar) {
mCacheValid = false;
mECLoc *= scalar;
return *this;
}
+
const FGLocation& operator/=(double scalar) {
return operator*=(1.0/scalar);
}
+
FGLocation operator+(const FGLocation& l) const {
return FGLocation(mECLoc + l.mECLoc);
}
+
FGLocation operator-(const FGLocation& l) const {
return FGLocation(mECLoc - l.mECLoc);
}
mutable FGMatrix33 mTec2l;
mutable FGMatrix33 mTi2ec;
mutable FGMatrix33 mTec2i;
-
+ mutable FGMatrix33 mTi2l;
+ mutable FGMatrix33 mTl2i;
+
+ double epa;
+
/* Terms for geodetic latitude calculation. Values are from WGS84 model */
double a; // Earth semimajor axis in feet (6,378,137.0 meters)
double b; // Earth semiminor axis in feet (6,356,752.3142 meters)
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGMatrix33.cpp,v 1.10 2010/07/01 23:13:19 jberndt Exp $";
static const char *IdHdr = ID_MATRIX33;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGMatrix33::Dump(const string& delimiter) const
{
ostringstream buffer;
- buffer << std::setw(18) << std::setprecision(16) << Entry(1,1) << delimiter;
- buffer << std::setw(18) << std::setprecision(16) << Entry(1,2) << delimiter;
- buffer << std::setw(18) << std::setprecision(16) << Entry(1,3) << delimiter;
- buffer << std::setw(18) << std::setprecision(16) << Entry(2,1) << delimiter;
- buffer << std::setw(18) << std::setprecision(16) << Entry(2,2) << delimiter;
- buffer << std::setw(18) << std::setprecision(16) << Entry(2,3) << delimiter;
- buffer << std::setw(18) << std::setprecision(16) << Entry(3,1) << delimiter;
- buffer << std::setw(18) << std::setprecision(16) << Entry(3,2) << delimiter;
- buffer << std::setw(18) << std::setprecision(16) << Entry(3,3);
+ buffer << setw(12) << setprecision(10) << data[0] << delimiter;
+ buffer << setw(12) << setprecision(10) << data[3] << delimiter;
+ buffer << setw(12) << setprecision(10) << data[6] << delimiter;
+ buffer << setw(12) << setprecision(10) << data[1] << delimiter;
+ buffer << setw(12) << setprecision(10) << data[4] << delimiter;
+ buffer << setw(12) << setprecision(10) << data[7] << delimiter;
+ buffer << setw(12) << setprecision(10) << data[2] << delimiter;
+ buffer << setw(12) << setprecision(10) << data[5] << delimiter;
+ buffer << setw(12) << setprecision(10) << data[8];
return buffer.str();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+string FGMatrix33::Dump(const string& delimiter, const string& prefix) const
+{
+ ostringstream buffer;
+
+ buffer << prefix << right << fixed << setw(9) << setprecision(6) << data[0] << delimiter;
+ buffer << right << fixed << setw(9) << setprecision(6) << data[3] << delimiter;
+ buffer << right << fixed << setw(9) << setprecision(6) << data[6] << endl;
+
+ buffer << prefix << right << fixed << setw(9) << setprecision(6) << data[1] << delimiter;
+ buffer << right << fixed << setw(9) << setprecision(6) << data[4] << delimiter;
+ buffer << right << fixed << setw(9) << setprecision(6) << data[7] << endl;
+
+ buffer << prefix << right << fixed << setw(9) << setprecision(6) << data[2] << delimiter;
+ buffer << right << fixed << setw(9) << setprecision(6) << data[5] << delimiter;
+ buffer << right << fixed << setw(9) << setprecision(6) << data[8];
+
+ buffer << setw(0) << left;
+
+ return buffer.str();
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+FGQuaternion FGMatrix33::GetQuaternion(void)
+{
+ FGQuaternion Q;
+
+ double tempQ[4];
+ int idx;
+
+ tempQ[0] = 1.0 + data[0] + data[4] + data[8];
+ tempQ[1] = 1.0 + data[0] - data[4] - data[8];
+ tempQ[2] = 1.0 - data[0] + data[4] - data[8];
+ tempQ[3] = 1.0 - data[0] - data[4] + data[8];
+
+ // Find largest of the above
+ idx = 0;
+ for (int i=1; i<4; i++) if (tempQ[i] > tempQ[idx]) idx = i;
+
+ switch(idx) {
+ case 0:
+ Q(1) = 0.50*sqrt(tempQ[0]);
+ Q(2) = 0.25*(data[7] - data[5])/Q(1);
+ Q(3) = 0.25*(data[2] - data[6])/Q(1);
+ Q(4) = 0.25*(data[3] - data[1])/Q(1);
+ break;
+ case 1:
+ Q(2) = 0.50*sqrt(tempQ[1]);
+ Q(1) = 0.25*(data[7] - data[5])/Q(2);
+ Q(3) = 0.25*(data[3] + data[1])/Q(2);
+ Q(4) = 0.25*(data[2] + data[6])/Q(2);
+ break;
+ case 2:
+ Q(3) = 0.50*sqrt(tempQ[2]);
+ Q(1) = 0.25*(data[2] - data[6])/Q(3);
+ Q(2) = 0.25*(data[3] + data[1])/Q(3);
+ Q(4) = 0.25*(data[7] + data[5])/Q(3);
+ break;
+ case 3:
+ Q(4) = 0.50*sqrt(tempQ[3]);
+ Q(1) = 0.25*(data[3] - data[1])/Q(4);
+ Q(2) = 0.25*(data[6] + data[2])/Q(4);
+ Q(3) = 0.25*(data[7] + data[5])/Q(4);
+ break;
+ default:
+ //error
+ break;
+ }
+
+ return (Q);
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
ostream& operator<<(ostream& os, const FGMatrix33& M)
{
for (unsigned int i=1; i<=M.Rows(); i++) {
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
double FGMatrix33::Determinant(void) const {
- return Entry(1,1)*Entry(2,2)*Entry(3,3) + Entry(1,2)*Entry(2,3)*Entry(3,1)
- + Entry(1,3)*Entry(2,1)*Entry(3,2) - Entry(1,3)*Entry(2,2)*Entry(3,1)
- - Entry(1,2)*Entry(2,1)*Entry(3,3) - Entry(2,3)*Entry(3,2)*Entry(1,1);
+ return data[0]*data[4]*data[8] + data[3]*data[7]*data[2]
+ + data[6]*data[1]*data[5] - data[6]*data[4]*data[2]
+ - data[3]*data[1]*data[8] - data[7]*data[5]*data[0];
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Compute the inverse of a general matrix using Cramers rule.
// I guess googling for cramers rule gives tons of references
// for this. :)
- double rdet = 1.0/Determinant();
-
- double i11 = rdet*(Entry(2,2)*Entry(3,3)-Entry(2,3)*Entry(3,2));
- double i21 = rdet*(Entry(2,3)*Entry(3,1)-Entry(2,1)*Entry(3,3));
- double i31 = rdet*(Entry(2,1)*Entry(3,2)-Entry(2,2)*Entry(3,1));
- double i12 = rdet*(Entry(1,3)*Entry(3,2)-Entry(1,2)*Entry(3,3));
- double i22 = rdet*(Entry(1,1)*Entry(3,3)-Entry(1,3)*Entry(3,1));
- double i32 = rdet*(Entry(1,2)*Entry(3,1)-Entry(1,1)*Entry(3,2));
- double i13 = rdet*(Entry(1,2)*Entry(2,3)-Entry(1,3)*Entry(2,2));
- double i23 = rdet*(Entry(1,3)*Entry(2,1)-Entry(1,1)*Entry(2,3));
- double i33 = rdet*(Entry(1,1)*Entry(2,2)-Entry(1,2)*Entry(2,1));
-
- return FGMatrix33( i11, i12, i13,
- i21, i22, i23,
- i31, i32, i33 );
+
+ if (Determinant() != 0.0) {
+ double rdet = 1.0/Determinant();
+
+ double i11 = rdet*(data[4]*data[8]-data[7]*data[5]);
+ double i21 = rdet*(data[7]*data[2]-data[1]*data[8]);
+ double i31 = rdet*(data[1]*data[5]-data[4]*data[2]);
+ double i12 = rdet*(data[6]*data[5]-data[3]*data[8]);
+ double i22 = rdet*(data[0]*data[8]-data[6]*data[2]);
+ double i32 = rdet*(data[3]*data[2]-data[0]*data[5]);
+ double i13 = rdet*(data[3]*data[7]-data[6]*data[4]);
+ double i23 = rdet*(data[6]*data[1]-data[0]*data[7]);
+ double i33 = rdet*(data[0]*data[4]-data[3]*data[1]);
+
+ return FGMatrix33( i11, i12, i13,
+ i21, i22, i23,
+ i31, i32, i33 );
+ } else {
+ return FGMatrix33( 0, 0, 0,
+ 0, 0, 0,
+ 0, 0, 0 );
+ }
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGMatrix33 FGMatrix33::operator-(const FGMatrix33& M) const
{
- return FGMatrix33( Entry(1,1) - M(1,1),
- Entry(1,2) - M(1,2),
- Entry(1,3) - M(1,3),
- Entry(2,1) - M(2,1),
- Entry(2,2) - M(2,2),
- Entry(2,3) - M(2,3),
- Entry(3,1) - M(3,1),
- Entry(3,2) - M(3,2),
- Entry(3,3) - M(3,3) );
+ return FGMatrix33( data[0] - M.data[0],
+ data[3] - M.data[3],
+ data[6] - M.data[6],
+ data[1] - M.data[1],
+ data[4] - M.data[4],
+ data[7] - M.data[7],
+ data[2] - M.data[2],
+ data[5] - M.data[5],
+ data[8] - M.data[8] );
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGMatrix33 FGMatrix33::operator+(const FGMatrix33& M) const
{
- return FGMatrix33( Entry(1,1) + M(1,1),
- Entry(1,2) + M(1,2),
- Entry(1,3) + M(1,3),
- Entry(2,1) + M(2,1),
- Entry(2,2) + M(2,2),
- Entry(2,3) + M(2,3),
- Entry(3,1) + M(3,1),
- Entry(3,2) + M(3,2),
- Entry(3,3) + M(3,3) );
+ return FGMatrix33( data[0] + M.data[0],
+ data[3] + M.data[3],
+ data[6] + M.data[6],
+ data[1] + M.data[1],
+ data[4] + M.data[4],
+ data[7] + M.data[7],
+ data[2] + M.data[2],
+ data[5] + M.data[5],
+ data[8] + M.data[8] );
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGMatrix33& FGMatrix33::operator+=(const FGMatrix33 &M)
{
- Entry(1,1) += M(1,1);
- Entry(1,2) += M(1,2);
- Entry(1,3) += M(1,3);
- Entry(2,1) += M(2,1);
- Entry(2,2) += M(2,2);
- Entry(2,3) += M(2,3);
- Entry(3,1) += M(3,1);
- Entry(3,2) += M(3,2);
- Entry(3,3) += M(3,3);
+ data[0] += M.data[0];
+ data[3] += M.data[3];
+ data[6] += M.data[6];
+ data[1] += M.data[1];
+ data[4] += M.data[4];
+ data[7] += M.data[7];
+ data[2] += M.data[2];
+ data[5] += M.data[5];
+ data[8] += M.data[8];
return *this;
}
FGMatrix33 FGMatrix33::operator*(const double scalar) const
{
- return FGMatrix33( scalar * Entry(1,1),
- scalar * Entry(1,2),
- scalar * Entry(1,3),
- scalar * Entry(2,1),
- scalar * Entry(2,2),
- scalar * Entry(2,3),
- scalar * Entry(3,1),
- scalar * Entry(3,2),
- scalar * Entry(3,3) );
+ return FGMatrix33( scalar * data[0],
+ scalar * data[3],
+ scalar * data[6],
+ scalar * data[1],
+ scalar * data[4],
+ scalar * data[7],
+ scalar * data[2],
+ scalar * data[5],
+ scalar * data[8] );
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
+/*
FGMatrix33 operator*(double scalar, FGMatrix33 &M)
{
return FGMatrix33( scalar * M(1,1),
scalar * M(3,2),
scalar * M(3,3) );
}
-
+*/
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGMatrix33& FGMatrix33::operator*=(const double scalar)
{
- Entry(1,1) *= scalar;
- Entry(1,2) *= scalar;
- Entry(1,3) *= scalar;
- Entry(2,1) *= scalar;
- Entry(2,2) *= scalar;
- Entry(2,3) *= scalar;
- Entry(3,1) *= scalar;
- Entry(3,2) *= scalar;
- Entry(3,3) *= scalar;
+ data[0] *= scalar;
+ data[3] *= scalar;
+ data[6] *= scalar;
+ data[1] *= scalar;
+ data[4] *= scalar;
+ data[7] *= scalar;
+ data[2] *= scalar;
+ data[5] *= scalar;
+ data[8] *= scalar;
return *this;
}
FGMatrix33 FGMatrix33::operator*(const FGMatrix33& M) const
{
- // FIXME: Make compiler friendlier
FGMatrix33 Product;
- Product(1,1) = Entry(1,1)*M(1,1) + Entry(1,2)*M(2,1) + Entry(1,3)*M(3,1);
- Product(1,2) = Entry(1,1)*M(1,2) + Entry(1,2)*M(2,2) + Entry(1,3)*M(3,2);
- Product(1,3) = Entry(1,1)*M(1,3) + Entry(1,2)*M(2,3) + Entry(1,3)*M(3,3);
- Product(2,1) = Entry(2,1)*M(1,1) + Entry(2,2)*M(2,1) + Entry(2,3)*M(3,1);
- Product(2,2) = Entry(2,1)*M(1,2) + Entry(2,2)*M(2,2) + Entry(2,3)*M(3,2);
- Product(2,3) = Entry(2,1)*M(1,3) + Entry(2,2)*M(2,3) + Entry(2,3)*M(3,3);
- Product(3,1) = Entry(3,1)*M(1,1) + Entry(3,2)*M(2,1) + Entry(3,3)*M(3,1);
- Product(3,2) = Entry(3,1)*M(1,2) + Entry(3,2)*M(2,2) + Entry(3,3)*M(3,2);
- Product(3,3) = Entry(3,1)*M(1,3) + Entry(3,2)*M(2,3) + Entry(3,3)*M(3,3);
+ Product.data[0] = data[0]*M.data[0] + data[3]*M.data[1] + data[6]*M.data[2];
+ Product.data[3] = data[0]*M.data[3] + data[3]*M.data[4] + data[6]*M.data[5];
+ Product.data[6] = data[0]*M.data[6] + data[3]*M.data[7] + data[6]*M.data[8];
+ Product.data[1] = data[1]*M.data[0] + data[4]*M.data[1] + data[7]*M.data[2];
+ Product.data[4] = data[1]*M.data[3] + data[4]*M.data[4] + data[7]*M.data[5];
+ Product.data[7] = data[1]*M.data[6] + data[4]*M.data[7] + data[7]*M.data[8];
+ Product.data[2] = data[2]*M.data[0] + data[5]*M.data[1] + data[8]*M.data[2];
+ Product.data[5] = data[2]*M.data[3] + data[5]*M.data[4] + data[8]*M.data[5];
+ Product.data[8] = data[2]*M.data[6] + data[5]*M.data[7] + data[8]*M.data[8];
return Product;
}
// FIXME: Make compiler friendlier
double a,b,c;
- a = Entry(1,1); b=Entry(1,2); c=Entry(1,3);
- Entry(1,1) = a*M(1,1) + b*M(2,1) + c*M(3,1);
- Entry(1,2) = a*M(1,2) + b*M(2,2) + c*M(3,2);
- Entry(1,3) = a*M(1,3) + b*M(2,3) + c*M(3,3);
+ a = data[0]; b=data[3]; c=data[6];
+ data[0] = a*M.data[0] + b*M.data[1] + c*M.data[2];
+ data[3] = a*M.data[3] + b*M.data[4] + c*M.data[5];
+ data[6] = a*M.data[6] + b*M.data[7] + c*M.data[8];
- a = Entry(2,1); b=Entry(2,2); c=Entry(2,3);
- Entry(2,1) = a*M(1,1) + b*M(2,1) + c*M(3,1);
- Entry(2,2) = a*M(1,2) + b*M(2,2) + c*M(3,2);
- Entry(2,3) = a*M(1,3) + b*M(2,3) + c*M(3,3);
+ a = data[1]; b=data[4]; c=data[7];
+ data[1] = a*M.data[0] + b*M.data[1] + c*M.data[2];
+ data[4] = a*M.data[3] + b*M.data[4] + c*M.data[5];
+ data[7] = a*M.data[6] + b*M.data[7] + c*M.data[8];
- a = Entry(3,1); b=Entry(3,2); c=Entry(3,3);
- Entry(3,1) = a*M(1,1) + b*M(2,1) + c*M(3,1);
- Entry(3,2) = a*M(1,2) + b*M(2,2) + c*M(3,2);
- Entry(3,3) = a*M(1,3) + b*M(2,3) + c*M(3,3);
+ a = data[2]; b=data[5]; c=data[8];
+ data[2] = a*M.data[0] + b*M.data[1] + c*M.data[2];
+ data[5] = a*M.data[3] + b*M.data[4] + c*M.data[5];
+ data[8] = a*M.data[6] + b*M.data[7] + c*M.data[8];
return *this;
}
if ( scalar != 0 ) {
double tmp = 1.0/scalar;
- Quot(1,1) = Entry(1,1) * tmp;
- Quot(1,2) = Entry(1,2) * tmp;
- Quot(1,3) = Entry(1,3) * tmp;
- Quot(2,1) = Entry(2,1) * tmp;
- Quot(2,2) = Entry(2,2) * tmp;
- Quot(2,3) = Entry(2,3) * tmp;
- Quot(3,1) = Entry(3,1) * tmp;
- Quot(3,2) = Entry(3,2) * tmp;
- Quot(3,3) = Entry(3,3) * tmp;
+ Quot.data[0] = data[0] * tmp;
+ Quot.data[3] = data[3] * tmp;
+ Quot.data[6] = data[6] * tmp;
+ Quot.data[1] = data[1] * tmp;
+ Quot.data[4] = data[4] * tmp;
+ Quot.data[7] = data[7] * tmp;
+ Quot.data[2] = data[2] * tmp;
+ Quot.data[5] = data[5] * tmp;
+ Quot.data[8] = data[8] * tmp;
} else {
MatrixException mE;
mE.Message = "Attempt to divide by zero in method FGMatrix33::operator/(const double scalar)";
{
if ( scalar != 0 ) {
double tmp = 1.0/scalar;
- Entry(1,1) *= tmp;
- Entry(1,2) *= tmp;
- Entry(1,3) *= tmp;
- Entry(2,1) *= tmp;
- Entry(2,2) *= tmp;
- Entry(2,3) *= tmp;
- Entry(3,1) *= tmp;
- Entry(3,2) *= tmp;
- Entry(3,3) *= tmp;
+ data[0] *= tmp;
+ data[3] *= tmp;
+ data[6] *= tmp;
+ data[1] *= tmp;
+ data[4] *= tmp;
+ data[7] *= tmp;
+ data[2] *= tmp;
+ data[5] *= tmp;
+ data[8] *= tmp;
} else {
MatrixException mE;
mE.Message = "Attempt to divide by zero in method FGMatrix33::operator/=(const double scalar)";
void FGMatrix33::T(void)
{
- for (unsigned int i=1; i<=3; i++) {
- for (unsigned int j=i+1; j<=3; j++) {
- double tmp = Entry(i,j);
- Entry(i,j) = Entry(j,i);
- Entry(j,i) = tmp;
- }
- }
+ double tmp;
+
+ tmp = data[3];
+ data[3] = data[1];
+ data[1] = tmp;
+
+ tmp = data[6];
+ data[6] = data[2];
+ data[2] = tmp;
+
+ tmp = data[7];
+ data[7] = data[5];
+ data[5] = tmp;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-FGColumnVector3 FGMatrix33::operator*(const FGColumnVector3& v) const {
- double tmp1 = v(1)*Entry(1,1);
- double tmp2 = v(1)*Entry(2,1);
- double tmp3 = v(1)*Entry(3,1);
+FGColumnVector3 FGMatrix33::operator*(const FGColumnVector3& v) const
+{
+ double v1 = v(1);
+ double v2 = v(2);
+ double v3 = v(3);
+
+ double tmp1 = v1*data[0]; //[(col-1)*eRows+row-1]
+ double tmp2 = v1*data[1];
+ double tmp3 = v1*data[2];
- tmp1 += v(2)*Entry(1,2);
- tmp2 += v(2)*Entry(2,2);
- tmp3 += v(2)*Entry(3,2);
+ tmp1 += v2*data[3];
+ tmp2 += v2*data[4];
+ tmp3 += v2*data[5];
- tmp1 += v(3)*Entry(1,3);
- tmp2 += v(3)*Entry(2,3);
- tmp3 += v(3)*Entry(3,3);
+ tmp1 += v3*data[6];
+ tmp2 += v3*data[7];
+ tmp3 += v3*data[8];
return FGColumnVector3( tmp1, tmp2, tmp3 );
}
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_MATRIX33 "$Id$"
+#define ID_MATRIX33 "$Id: FGMatrix33.h,v 1.11 2010/06/30 03:13:40 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
class FGColumnVector3;
+class FGQuaternion;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS DOCUMENTATION
Create copy of the matrix given in the argument.
*/
FGMatrix33(const FGMatrix33& M) {
- Entry(1,1) = M.Entry(1,1);
- Entry(2,1) = M.Entry(2,1);
- Entry(3,1) = M.Entry(3,1);
- Entry(1,2) = M.Entry(1,2);
- Entry(2,2) = M.Entry(2,2);
- Entry(3,2) = M.Entry(3,2);
- Entry(1,3) = M.Entry(1,3);
- Entry(2,3) = M.Entry(2,3);
- Entry(3,3) = M.Entry(3,3);
-
- Debug(0);
+ data[0] = M.data[0];
+ data[1] = M.data[1];
+ data[2] = M.data[2];
+ data[3] = M.data[3];
+ data[4] = M.data[4];
+ data[5] = M.data[5];
+ data[6] = M.data[6];
+ data[7] = M.data[7];
+ data[8] = M.data[8];
+
+// Debug(0);
}
/** Initialization by given values.
FGMatrix33(double m11, double m12, double m13,
double m21, double m22, double m23,
double m31, double m32, double m33) {
- Entry(1,1) = m11;
- Entry(2,1) = m21;
- Entry(3,1) = m31;
- Entry(1,2) = m12;
- Entry(2,2) = m22;
- Entry(3,2) = m32;
- Entry(1,3) = m13;
- Entry(2,3) = m23;
- Entry(3,3) = m33;
-
- Debug(0);
+ data[0] = m11;
+ data[1] = m21;
+ data[2] = m31;
+ data[3] = m12;
+ data[4] = m22;
+ data[5] = m32;
+ data[6] = m13;
+ data[7] = m23;
+ data[8] = m33;
+
+ // Debug(0);
}
/** Destructor.
*/
- ~FGMatrix33(void) { Debug(1); }
+ ~FGMatrix33(void) { /* Debug(1); */ }
/** Prints the contents of the matrix.
@param delimeter the item separator (tab or comma)
@return a string with the delimeter-separated contents of the matrix */
std::string Dump(const std::string& delimeter) const;
+ /** Prints the contents of the matrix.
+ @param delimeter the item separator (tab or comma, etc.)
+ @param prefix an additional prefix that is used to indent the 3X3 matrix printout
+ @return a string with the delimeter-separated contents of the matrix */
+ std::string Dump(const std::string& delimiter, const std::string& prefix) const;
+
/** Read access the entries of the matrix.
@param row Row index.
@param col Column index.
column indices. Indices are counted starting with 1.
*/
double operator()(unsigned int row, unsigned int col) const {
- return Entry(row, col);
+ return data[(col-1)*eRows+row-1];
}
/** Write access the entries of the matrix.
column indices. Indices are counted starting with 1.
*/
double& operator()(unsigned int row, unsigned int col) {
- return Entry(row, col);
+ return data[(col-1)*eRows+row-1];
}
/** Read access the entries of the matrix.
@return the transposed matrix.
*/
FGMatrix33 Transposed(void) const {
- return FGMatrix33( Entry(1,1), Entry(2,1), Entry(3,1),
- Entry(1,2), Entry(2,2), Entry(3,2),
- Entry(1,3), Entry(2,3), Entry(3,3) );
+ return FGMatrix33( data[0], data[1], data[2],
+ data[3], data[4], data[5],
+ data[6], data[7], data[8] );
}
/** Transposes this matrix.
void InitMatrix(double m11, double m12, double m13,
double m21, double m22, double m23,
double m31, double m32, double m33) {
- Entry(1,1) = m11;
- Entry(2,1) = m21;
- Entry(3,1) = m31;
- Entry(1,2) = m12;
- Entry(2,2) = m22;
- Entry(3,2) = m32;
- Entry(1,3) = m13;
- Entry(2,3) = m23;
- Entry(3,3) = m33;
+ data[0] = m11;
+ data[1] = m21;
+ data[2] = m31;
+ data[3] = m12;
+ data[4] = m22;
+ data[5] = m32;
+ data[6] = m13;
+ data[7] = m23;
+ data[8] = m33;
}
+ /** Returns the quaternion associated with this direction cosine (rotation) matrix.
+ */
+ FGQuaternion GetQuaternion(void);
+
/** Determinant of the matrix.
@return the determinant of the matrix.
*/
} // namespace JSBSim
+#include "FGQuaternion.h"
+
#endif
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_PARAMETER "$Id$"
+#define ID_PARAMETER "$Id: FGParameter.h,v 1.5 2009/08/30 03:51:28 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGPropertyValue.cpp,v 1.4 2009/08/30 03:51:28 jberndt Exp $";
static const char *IdHdr = ID_PROPERTYVALUE;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_PROPERTYVALUE "$Id$"
+#define ID_PROPERTYVALUE "$Id: FGPropertyValue.h,v 1.6 2009/10/02 10:30:09 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
#include <string>
#include <iostream>
+#include <iomanip>
#include <cmath>
using std::cerr;
using std::cout;
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGQuaternion.cpp,v 1.16 2010/06/30 03:13:40 jberndt Exp $";
static const char *IdHdr = ID_QUATERNION;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Initialize from q
-FGQuaternion::FGQuaternion(const FGQuaternion& q)
- : mCacheValid(q.mCacheValid) {
- Entry(1) = q(1);
- Entry(2) = q(2);
- Entry(3) = q(3);
- Entry(4) = q(4);
+FGQuaternion::FGQuaternion(const FGQuaternion& q) : mCacheValid(q.mCacheValid)
+{
+ data[0] = q(1);
+ data[1] = q(2);
+ data[2] = q(3);
+ data[3] = q(4);
if (mCacheValid) {
mT = q.mT;
mTInv = q.mTInv;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Initialize with the three euler angles
-FGQuaternion::FGQuaternion(double phi, double tht, double psi)
- : mCacheValid(false) {
+FGQuaternion::FGQuaternion(double phi, double tht, double psi): mCacheValid(false)
+{
+ InitializeFromEulerAngles(phi, tht, psi);
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+FGQuaternion::FGQuaternion(FGColumnVector3 vOrient): mCacheValid(false)
+{
+ double phi = vOrient(ePhi);
+ double tht = vOrient(eTht);
+ double psi = vOrient(ePsi);
+
+ InitializeFromEulerAngles(phi, tht, psi);
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+//
+// This function computes the quaternion that describes the relationship of the
+// body frame with respect to another frame, such as the ECI or ECEF frames. The
+// Euler angles used represent a 3-2-1 (psi, theta, phi) rotation sequence from
+// the reference frame to the body frame. See "Quaternions and Rotation
+// Sequences", Jack B. Kuipers, sections 9.2 and 7.6.
+
+void FGQuaternion::InitializeFromEulerAngles(double phi, double tht, double psi)
+{
+ mEulerAngles(ePhi) = phi;
+ mEulerAngles(eTht) = tht;
+ mEulerAngles(ePsi) = psi;
+
double thtd2 = 0.5*tht;
double psid2 = 0.5*psi;
double phid2 = 0.5*phi;
double Sphid2Sthtd2 = Sphid2*Sthtd2;
double Sphid2Cthtd2 = Sphid2*Cthtd2;
- Entry(1) = Cphid2Cthtd2*Cpsid2 + Sphid2Sthtd2*Spsid2;
- Entry(2) = Sphid2Cthtd2*Cpsid2 - Cphid2Sthtd2*Spsid2;
- Entry(3) = Cphid2Sthtd2*Cpsid2 + Sphid2Cthtd2*Spsid2;
- Entry(4) = Cphid2Cthtd2*Spsid2 - Sphid2Sthtd2*Cpsid2;
+ data[0] = Cphid2Cthtd2*Cpsid2 + Sphid2Sthtd2*Spsid2;
+ data[1] = Sphid2Cthtd2*Cpsid2 - Cphid2Sthtd2*Spsid2;
+ data[2] = Cphid2Sthtd2*Cpsid2 + Sphid2Cthtd2*Spsid2;
+ data[3] = Cphid2Cthtd2*Spsid2 - Sphid2Sthtd2*Cpsid2;
+
+ Normalize();
+}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+// Initialize with a direction cosine (rotation) matrix
+
+FGQuaternion::FGQuaternion(const FGMatrix33& m) : mCacheValid(false)
+{
+ data[0] = 0.50*sqrt(1.0 + m(1,1) + m(2,2) + m(3,3));
+ double t = 0.25/data[0];
+ data[1] = t*(m(2,3) - m(3,2));
+ data[2] = t*(m(3,1) - m(1,3));
+ data[3] = t*(m(1,2) - m(2,1));
+
+ ComputeDerivedUnconditional();
+
+ Normalize();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
angular velocities PQR.
See Stevens and Lewis, "Aircraft Control and Simulation", Second Edition,
Equation 1.3-36.
+ Also see Jack Kuipers, "Quaternions and Rotation Sequences", Equation 11.12.
*/
-FGQuaternion FGQuaternion::GetQDot(const FGColumnVector3& PQR) const {
- double norm = Magnitude();
- if (norm == 0.0)
- return FGQuaternion::zero();
- double rnorm = 1.0/norm;
-
- FGQuaternion QDot;
- QDot(1) = -0.5*(Entry(2)*PQR(eP) + Entry(3)*PQR(eQ) + Entry(4)*PQR(eR));
- QDot(2) = 0.5*(Entry(1)*PQR(eP) + Entry(3)*PQR(eR) - Entry(4)*PQR(eQ));
- QDot(3) = 0.5*(Entry(1)*PQR(eQ) + Entry(4)*PQR(eP) - Entry(2)*PQR(eR));
- QDot(4) = 0.5*(Entry(1)*PQR(eR) + Entry(2)*PQR(eQ) - Entry(3)*PQR(eP));
- return rnorm*QDot;
+FGQuaternion FGQuaternion::GetQDot(const FGColumnVector3& PQR)
+{
+ return FGQuaternion(
+ -0.5*( data[1]*PQR(eP) + data[2]*PQR(eQ) + data[3]*PQR(eR)),
+ 0.5*( data[0]*PQR(eP) - data[3]*PQR(eQ) + data[2]*PQR(eR)),
+ 0.5*( data[3]*PQR(eP) + data[0]*PQR(eQ) - data[1]*PQR(eR)),
+ 0.5*(-data[2]*PQR(eP) + data[1]*PQR(eQ) + data[0]*PQR(eR))
+ );
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGQuaternion::Normalize()
{
- // Note: this does not touch the cache
- // since it does not change the orientation ...
-
+ // Note: this does not touch the cache since it does not change the orientation
double norm = Magnitude();
- if (norm == 0.0)
- return;
-
+ if (norm == 0.0 || fabs(norm - 1.000) < 1e-10) return;
+
double rnorm = 1.0/norm;
- Entry(1) *= rnorm;
- Entry(2) *= rnorm;
- Entry(3) *= rnorm;
- Entry(4) *= rnorm;
+
+ data[0] *= rnorm;
+ data[1] *= rnorm;
+ data[2] *= rnorm;
+ data[3] *= rnorm;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGQuaternion::ComputeDerivedUnconditional(void) const
{
mCacheValid = true;
-
- // First normalize the 4-vector
- double norm = Magnitude();
- if (norm == 0.0)
- return;
- double rnorm = 1.0/norm;
- double q1 = rnorm*Entry(1);
- double q2 = rnorm*Entry(2);
- double q3 = rnorm*Entry(3);
- double q4 = rnorm*Entry(4);
+ double q0 = data[0]; // use some aliases/shorthand for the quat elements.
+ double q1 = data[1];
+ double q2 = data[2];
+ double q3 = data[3];
// Now compute the transformation matrix.
+ double q0q0 = q0*q0;
double q1q1 = q1*q1;
double q2q2 = q2*q2;
double q3q3 = q3*q3;
- double q4q4 = q4*q4;
+ double q0q1 = q0*q1;
+ double q0q2 = q0*q2;
+ double q0q3 = q0*q3;
double q1q2 = q1*q2;
double q1q3 = q1*q3;
- double q1q4 = q1*q4;
double q2q3 = q2*q3;
- double q2q4 = q2*q4;
- double q3q4 = q3*q4;
- mT(1,1) = q1q1 + q2q2 - q3q3 - q4q4;
- mT(1,2) = 2.0*(q2q3 + q1q4);
- mT(1,3) = 2.0*(q2q4 - q1q3);
- mT(2,1) = 2.0*(q2q3 - q1q4);
- mT(2,2) = q1q1 - q2q2 + q3q3 - q4q4;
- mT(2,3) = 2.0*(q3q4 + q1q2);
- mT(3,1) = 2.0*(q2q4 + q1q3);
- mT(3,2) = 2.0*(q3q4 - q1q2);
- mT(3,3) = q1q1 - q2q2 - q3q3 + q4q4;
- // Since this is an orthogonal matrix, the inverse is simply
- // the transpose.
+ mT(1,1) = q0q0 + q1q1 - q2q2 - q3q3; // This is found from Eqn. 1.3-32 in
+ mT(1,2) = 2.0*(q1q2 + q0q3); // Stevens and Lewis
+ mT(1,3) = 2.0*(q1q3 - q0q2);
+ mT(2,1) = 2.0*(q1q2 - q0q3);
+ mT(2,2) = q0q0 - q1q1 + q2q2 - q3q3;
+ mT(2,3) = 2.0*(q2q3 + q0q1);
+ mT(3,1) = 2.0*(q1q3 + q0q2);
+ mT(3,2) = 2.0*(q2q3 - q0q1);
+ mT(3,3) = q0q0 - q1q1 - q2q2 + q3q3;
+
+ // Since this is an orthogonal matrix, the inverse is simply the transpose.
+
mTInv = mT;
mTInv.T();
// Compute the Euler-angles
+ // Also see Jack Kuipers, "Quaternions and Rotation Sequences", section 7.8..
+
if (mT(3,3) == 0.0)
mEulerAngles(ePhi) = 0.5*M_PI;
else
mEulerCosines(ePhi) = cos(mEulerAngles(ePhi));
mEulerCosines(eTht) = cos(mEulerAngles(eTht));
mEulerCosines(ePsi) = cos(mEulerAngles(ePsi));
+
+// Debug(2);
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+// The bitmasked value choices are as follows:
+// unset: In this case (the default) JSBSim would only print
+// out the normally expected messages, essentially echoing
+// the config files as they are read. If the environment
+// variable is not set, debug_lvl is set to 1 internally
+// 0: This requests JSBSim not to output any messages
+// whatsoever.
+// 1: This value explicity requests the normal JSBSim
+// startup messages
+// 2: This value asks for a message to be printed out when
+// a class is instantiated
+// 4: When this value is set, a message is displayed when a
+// FGModel object executes its Run() method
+// 8: When this value is set, various runtime state variables
+// are printed out periodically
+// 16: When set various parameters are sanity checked and
+// a message is printed out when they go out of bounds
+
+void FGQuaternion::Debug(int from) const
+{
+ if (debug_lvl <= 0) return;
+
+ if (debug_lvl & 1) { // Standard console startup message output
+ }
+ if (debug_lvl & 2 ) { // Instantiation/Destruction notification
+ if (from == 0) cout << "Instantiated: FGQuaternion" << endl;
+ if (from == 1) cout << "Destroyed: FGQuaternion" << endl;
+ }
+ if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
+ }
+ if (debug_lvl & 8 ) { // Runtime state variables
+ }
+ if (debug_lvl & 16) { // Sanity checking
+ if (!EqualToRoundoff(Magnitude(), 1.0)) {
+ cout << "Quaternion magnitude differs from 1.0 !" << endl;
+ cout << "\tdelta from 1.0: " << std::scientific << Magnitude()-1.0 << endl;
+ }
+ }
+ if (debug_lvl & 64) {
+ if (from == 0) { // Constructor
+ cout << IdSrc << endl;
+ cout << IdHdr << endl;
+ }
+ }
}
} // namespace JSBSim
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGJSBBase.h"
-#include "FGMatrix33.h"
#include "FGColumnVector3.h"
-#include "input_output/FGPropertyManager.h"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_QUATERNION "$Id$"
+#define ID_QUATERNION "$Id: FGQuaternion.h,v 1.17 2010/06/30 03:13:40 jberndt Exp $"
namespace JSBSim {
+class FGMatrix33;
+
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS DOCUMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
CLASS DECLARATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-class FGQuaternion
- : virtual FGJSBBase {
+class FGQuaternion : virtual FGJSBBase {
public:
/** Default initializer.
Default initializer, initializes the class with the identity rotation. */
FGQuaternion() : mCacheValid(false) {
- Entry(1) = 1.0;
- Entry(2) = Entry(3) = Entry(4) = 0.0;
+ data[0] = 1.0;
+ data[1] = data[2] = data[3] = 0.0;
}
/** Copy constructor.
@param psi The euler Z axis (heading) angle in radians */
FGQuaternion(double phi, double tht, double psi);
+ /** Initializer by euler angle vector.
+ Initialize the quaternion with the euler angle vector.
+ @param vOrient The euler axis angle vector in radians (phi, tht, psi) */
+ FGQuaternion(FGColumnVector3 vOrient);
+
/** Initializer by one euler angle.
Initialize the quaternion with the single euler angle where its index
is given in the first argument.
@param angle The euler angle in radians */
FGQuaternion(int idx, double angle)
: mCacheValid(false) {
+
double angle2 = 0.5*angle;
double Sangle2 = sin(angle2);
double Cangle2 = cos(angle2);
if (idx == ePhi) {
- Entry(1) = Cangle2;
- Entry(2) = Sangle2;
- Entry(3) = 0.0;
- Entry(4) = 0.0;
+ data[0] = Cangle2;
+ data[1] = Sangle2;
+ data[2] = 0.0;
+ data[3] = 0.0;
} else if (idx == eTht) {
- Entry(1) = Cangle2;
- Entry(2) = 0.0;
- Entry(3) = Sangle2;
- Entry(4) = 0.0;
+ data[0] = Cangle2;
+ data[1] = 0.0;
+ data[2] = Sangle2;
+ data[3] = 0.0;
} else {
- Entry(1) = Cangle2;
- Entry(2) = 0.0;
- Entry(3) = 0.0;
- Entry(4) = Sangle2;
+ data[0] = Cangle2;
+ data[1] = 0.0;
+ data[2] = 0.0;
+ data[3] = Sangle2;
}
}
+ /** Initializer by matrix.
+ Initialize the quaternion with the matrix representing a transform from one frame
+ to another using the standard aerospace sequence, Yaw-Pitch-Roll (3-2-1).
+ @param m the rotation matrix */
+ FGQuaternion(const FGMatrix33& m);
+
/// Destructor.
~FGQuaternion() {}
/** Quaternion derivative for given angular rates.
Computes the quaternion derivative which results from the given
angular velocities
- @param PQR a constant reference to the body rate vector
+ @param PQR a constant reference to a rotation rate vector
@return the quaternion derivative
@see Stevens and Lewis, "Aircraft Control and Simulation", Second Edition,
Equation 1.3-36. */
- FGQuaternion GetQDot(const FGColumnVector3& PQR) const;
+ FGQuaternion GetQDot(const FGColumnVector3& PQR);
/** Transformation matrix.
@return a reference to the transformation/rotation matrix
Note that the index given in the argument is unchecked.
*/
- double operator()(unsigned int idx) const { return Entry(idx); }
+ double operator()(unsigned int idx) const { return data[idx-1]; }
/** Write access the entries of the vector.
Note that the index given in the argument is unchecked.
*/
- double& operator()(unsigned int idx) { return Entry(idx); }
+ double& operator()(unsigned int idx) { mCacheValid = false; return data[idx-1]; }
/** Read access the entries of the vector.
Note that the index given in the argument is unchecked.
*/
- double Entry(unsigned int idx) const { return mData[idx-1]; }
+ double Entry(unsigned int idx) const { return data[idx-1]; }
/** Write access the entries of the vector.
Note that the index given in the argument is unchecked.
*/
- double& Entry(unsigned int idx) { mCacheValid = false; return mData[idx-1]; }
+ double& Entry(unsigned int idx) {
+ mCacheValid = false;
+ return data[idx-1];
+ }
/** Assignment operator "=".
Assign the value of q to the current object. Cached values are
@return reference to a quaternion object */
const FGQuaternion& operator=(const FGQuaternion& q) {
// Copy the master values ...
- Entry(1) = q(1);
- Entry(2) = q(2);
- Entry(3) = q(3);
- Entry(4) = q(4);
+ data[0] = q(1);
+ data[1] = q(2);
+ data[2] = q(3);
+ data[3] = q(4);
+ ComputeDerived();
// .. and copy the derived values if they are valid
mCacheValid = q.mCacheValid;
if (mCacheValid) {
return *this;
}
+ /// Conversion from Quat to Matrix
+ operator FGMatrix33() const { return GetT(); }
+
/** Comparison operator "==".
@param q a quaternion reference
@return true if both quaternions represent the same rotation. */
bool operator==(const FGQuaternion& q) const {
- return Entry(1) == q(1) && Entry(2) == q(2)
- && Entry(3) == q(3) && Entry(4) == q(4);
+ return data[0] == q(1) && data[1] == q(2)
+ && data[2] == q(3) && data[3] == q(4);
}
/** Comparison operator "!=".
bool operator!=(const FGQuaternion& q) const { return ! operator==(q); }
const FGQuaternion& operator+=(const FGQuaternion& q) {
// Copy the master values ...
- Entry(1) += q(1);
- Entry(2) += q(2);
- Entry(3) += q(3);
- Entry(4) += q(4);
+ data[0] += q(1);
+ data[1] += q(2);
+ data[2] += q(3);
+ data[3] += q(4);
mCacheValid = false;
return *this;
}
@return a quaternion reference representing Q, where Q = Q - q. */
const FGQuaternion& operator-=(const FGQuaternion& q) {
// Copy the master values ...
- Entry(1) -= q(1);
- Entry(2) -= q(2);
- Entry(3) -= q(3);
- Entry(4) -= q(4);
+ data[0] -= q(1);
+ data[1] -= q(2);
+ data[2] -= q(3);
+ data[3] -= q(4);
mCacheValid = false;
return *this;
}
@param scalar a multiplicative value.
@return a quaternion reference representing Q, where Q = Q * scalar. */
const FGQuaternion& operator*=(double scalar) {
- Entry(1) *= scalar;
- Entry(2) *= scalar;
- Entry(3) *= scalar;
- Entry(4) *= scalar;
+ data[0] *= scalar;
+ data[1] *= scalar;
+ data[2] *= scalar;
+ data[3] *= scalar;
mCacheValid = false;
return *this;
}
@param q a quaternion to be summed.
@return a quaternion representing Q, where Q = Q + q. */
FGQuaternion operator+(const FGQuaternion& q) const {
- return FGQuaternion(Entry(1)+q(1), Entry(2)+q(2),
- Entry(3)+q(3), Entry(4)+q(4));
+ return FGQuaternion(data[0]+q(1), data[1]+q(2),
+ data[2]+q(3), data[3]+q(4));
}
/** Arithmetic operator "-".
@param q a quaternion to be subtracted.
@return a quaternion representing Q, where Q = Q - q. */
FGQuaternion operator-(const FGQuaternion& q) const {
- return FGQuaternion(Entry(1)-q(1), Entry(2)-q(2),
- Entry(3)-q(3), Entry(4)-q(4));
+ return FGQuaternion(data[0]-q(1), data[1]-q(2),
+ data[2]-q(3), data[3]-q(4));
}
/** Arithmetic operator "*".
@param q a quaternion to be multiplied.
@return a quaternion representing Q, where Q = Q * q. */
FGQuaternion operator*(const FGQuaternion& q) const {
- return FGQuaternion(Entry(1)*q(1)-Entry(2)*q(2)-Entry(3)*q(3)-Entry(4)*q(4),
- Entry(1)*q(2)+Entry(2)*q(1)+Entry(3)*q(4)-Entry(4)*q(3),
- Entry(1)*q(3)-Entry(2)*q(4)+Entry(3)*q(1)+Entry(4)*q(2),
- Entry(1)*q(4)+Entry(2)*q(3)-Entry(3)*q(2)+Entry(4)*q(1));
+ return FGQuaternion(data[0]*q(1)-data[1]*q(2)-data[2]*q(3)-data[3]*q(4),
+ data[0]*q(2)+data[1]*q(1)+data[2]*q(4)-data[3]*q(3),
+ data[0]*q(3)-data[1]*q(4)+data[2]*q(1)+data[3]*q(2),
+ data[0]*q(4)+data[1]*q(3)-data[2]*q(2)+data[3]*q(1));
}
/** Arithmetic operator "*=".
@param q a quaternion to be multiplied.
@return a quaternion reference representing Q, where Q = Q * q. */
const FGQuaternion& operator*=(const FGQuaternion& q) {
- double q0 = Entry(1)*q(1)-Entry(2)*q(2)-Entry(3)*q(3)-Entry(4)*q(4);
- double q1 = Entry(1)*q(2)+Entry(2)*q(1)+Entry(3)*q(4)-Entry(4)*q(3);
- double q2 = Entry(1)*q(3)-Entry(2)*q(4)+Entry(3)*q(1)+Entry(4)*q(2);
- double q3 = Entry(1)*q(4)+Entry(2)*q(3)-Entry(3)*q(2)+Entry(4)*q(1);
- Entry(1) = q0;
- Entry(2) = q1;
- Entry(3) = q2;
- Entry(4) = q3;
+ double q0 = data[0]*q(1)-data[1]*q(2)-data[2]*q(3)-data[3]*q(4);
+ double q1 = data[0]*q(2)+data[1]*q(1)+data[2]*q(4)-data[3]*q(3);
+ double q2 = data[0]*q(3)-data[1]*q(4)+data[2]*q(1)+data[3]*q(2);
+ double q3 = data[0]*q(4)+data[1]*q(3)-data[2]*q(2)+data[3]*q(1);
+ data[0] = q0;
+ data[1] = q1;
+ data[2] = q2;
+ data[3] = q3;
mCacheValid = false;
return *this;
}
the identity orientation.
*/
FGQuaternion Inverse(void) const {
- double norm = Magnitude();
+ double norm = SqrMagnitude();
if (norm == 0.0)
return *this;
double rNorm = 1.0/norm;
- return FGQuaternion( Entry(1)*rNorm, -Entry(2)*rNorm,
- -Entry(3)*rNorm, -Entry(4)*rNorm );
+ return FGQuaternion( data[0]*rNorm, -data[1]*rNorm,
+ -data[2]*rNorm, -data[3]*rNorm );
}
/** Conjugate of the quaternion.
to the inverse iff the quaternion is normalized.
*/
FGQuaternion Conjugate(void) const {
- return FGQuaternion( Entry(1), -Entry(2), -Entry(3), -Entry(4) );
+ return FGQuaternion( data[0], -data[1], -data[2], -data[3] );
}
friend FGQuaternion operator*(double, const FGQuaternion&);
Compute and return the square of the euclidean norm of this vector.
*/
double SqrMagnitude(void) const {
- return Entry(1)*Entry(1)+Entry(2)*Entry(2)
- +Entry(3)*Entry(3)+Entry(4)*Entry(4);
+ return data[0]*data[0] + data[1]*data[1]
+ + data[2]*data[2] + data[3]*data[3];
}
- /** Normialze.
+ /** Normalize.
Normalize the vector to have the Magnitude() == 1.0. If the vector
is equal to zero it is left untouched.
private:
/** Copying by assigning the vector valued components. */
FGQuaternion(double q1, double q2, double q3, double q4) : mCacheValid(false)
- { Entry(1) = q1; Entry(2) = q2; Entry(3) = q3; Entry(4) = q4; }
+ { data[0] = q1; data[1] = q2; data[2] = q3; data[3] = q4; }
/** Computation of derived values.
This function recomputes the derived values like euler angles and
This function checks if the derived values like euler angles and
transformation matrices are already computed. If so, it
returns. If they need to be computed the real worker routine
- \ref FGQuaternion::ComputeDerivedUnconditional(void) const
- is called.
- This function is inlined to avoid function calls in the fast path. */
+ FGQuaternion::ComputeDerivedUnconditional(void) const
+ is called. */
void ComputeDerived(void) const {
if (!mCacheValid)
ComputeDerivedUnconditional();
}
/** The quaternion values itself. This is the master copy. */
- double mData[4];
+ double data[4];
/** A data validity flag.
This class implements caching of the derived values like the
/** The cached sines and cosines of the euler angles. */
mutable FGColumnVector3 mEulerSines;
mutable FGColumnVector3 mEulerCosines;
+
+ void Debug(int from) const;
+
+ void InitializeFromEulerAngles(double phi, double tht, double psi);
};
/** Scalar multiplication.
} // namespace JSBSim
+#include "FGMatrix33.h"
+
#endif
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGRealValue.cpp,v 1.4 2009/08/30 03:51:28 jberndt Exp $";
static const char *IdHdr = ID_REALVALUE;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_REALVALUE "$Id$"
+#define ID_REALVALUE "$Id: FGRealValue.h,v 1.4 2009/08/30 03:51:28 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGTable.cpp,v 1.21 2010/04/07 03:08:37 jberndt Exp $";
static const char *IdHdr = ID_TABLE;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
node = PropertyManager->GetNode(property_string);
if (node == 0) {
- cerr << "IndependenVar property, " << property_string
- << " in Table definition is not defined." << endl;
- abort();
+ throw("IndependenVar property, " + property_string + " in Table definition is not defined.");
}
lookup_axis = axisElement->GetAttributeValue("lookup");
lookupProperty[eColumn] = node;
} else if (lookup_axis == string("table")) {
lookupProperty[eTable] = node;
+ } else if (!lookup_axis.empty()) {
+ throw("Lookup table axis specification not understood: " + lookup_axis);
} else { // assumed single dimension table; row lookup
lookupProperty[eRow] = node;
}
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_TABLE "$Id$"
+#define ID_TABLE "$Id: FGTable.h,v 1.11 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@endcode
@author Jon S. Berndt
-@version $Id$
+@version $Id: FGTable.h,v 1.11 2009/10/24 22:59:30 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGAerodynamics.cpp,v 1.31 2009/11/28 14:30:11 andgi Exp $";
static const char *IdHdr = ID_AERODYNAMICS;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_AERODYNAMICS "$Id$"
+#define ID_AERODYNAMICS "$Id: FGAerodynamics.h,v 1.20 2009/11/12 13:08:11 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
Systems may NOT be combined, or a load error will occur.
@author Jon S. Berndt, Tony Peden
- @version $Revision$
+ @version $Revision: 1.20 $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
typedef std::map<std::string,int> AxisIndex;
AxisIndex AxisIdx;
FGFunction* AeroRPShift;
- std::vector <FGFunction*> variables;
typedef vector <FGFunction*> CoeffArray;
CoeffArray* Coeff;
FGColumnVector3 vFnative;
GLOBAL DATA
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGAircraft.cpp,v 1.26 2010/02/15 03:28:24 jberndt Exp $";
static const char *IdHdr = ID_AIRCRAFT;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
vForces += GroundReactions->GetForces();
vForces += ExternalReactions->GetForces();
vForces += BuoyantForces->GetForces();
+ } else {
+ const FGMatrix33& mTl2b = Propagate->GetTl2b();
+ vForces = mTl2b * FGColumnVector3(0,0,-MassBalance->GetWeight());
}
vMoments.InitMatrix();
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_AIRCRAFT "$Id$"
+#define ID_AIRCRAFT "$Id: FGAircraft.h,v 1.15 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@endcode
@author Jon S. Berndt
- @version $Id$
+ @version $Id: FGAircraft.h,v 1.15 2009/10/24 22:59:30 jberndt Exp $
@see Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
School, January 1994
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGAtmosphere.h"
-#include "FGState.h"
-#include "FGFDMExec.h"
#include "FGAircraft.h"
#include "FGPropagate.h"
#include "FGInertial.h"
+#include "FGAuxiliary.h"
+#include "FGFDMExec.h"
#include "input_output/FGPropertyManager.h"
#include <iostream>
#include <cstdlib>
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGAtmosphere.cpp,v 1.33 2010/02/25 05:21:36 jberndt Exp $";
static const char *IdHdr = ID_ATMOSPHERE;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGAtmosphere::Turbulence(void)
{
- double DeltaT = rate*State->Getdt();
+ double DeltaT = rate*FDMExec->GetDeltaT();
switch (turbType) {
case ttStandard: {
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_ATMOSPHERE "$Id$"
+#define ID_ATMOSPHERE "$Id: FGAtmosphere.h,v 1.22 2009/10/02 10:30:09 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
/** Models the 1976 Standard Atmosphere.
@author Tony Peden, Jon Berndt
- @version $Id$
+ @version $Id: FGAtmosphere.h,v 1.22 2009/10/02 10:30:09 jberndt Exp $
@see Anderson, John D. "Introduction to Flight, Third Edition", McGraw-Hill,
1989, ISBN 0-07-001641-0
*/
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGAuxiliary.cpp,v 1.39 2010/07/09 12:06:11 jberndt Exp $";
static const char *IdHdr = ID_AUXILIARY;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
vPilotAccel.InitMatrix();
if ( Vt > 1.0 ) {
- vAircraftAccel = Aerodynamics->GetForces()
- + Propulsion->GetForces()
- + GroundReactions->GetForces()
- + ExternalReactions->GetForces()
- + BuoyantForces->GetForces();
+ // Use the "+=" operator to avoid the creation of temporary objects.
+ vAircraftAccel = Aerodynamics->GetForces();
+ vAircraftAccel += Propulsion->GetForces();
+ vAircraftAccel += GroundReactions->GetForces();
+ vAircraftAccel += ExternalReactions->GetForces();
+ vAircraftAccel += BuoyantForces->GetForces();
vAircraftAccel /= MassBalance->GetMass();
// Nz is Acceleration in "g's", along normal axis (-Z body axis)
// VRP computation
const FGLocation& vLocation = Propagate->GetLocation();
- FGColumnVector3 vrpStructural = Aircraft->GetXYZvrp();
+ FGColumnVector3& vrpStructural = Aircraft->GetXYZvrp();
FGColumnVector3 vrpBody = MassBalance->StructuralToBody( vrpStructural );
FGColumnVector3 vrpLocal = Propagate->GetTb2l() * vrpBody;
vLocationVRP = vLocation.LocalToLocation( vrpLocal );
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_AUXILIARY "$Id$"
+#define ID_AUXILIARY "$Id: FGAuxiliary.h,v 1.17 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
The radius R is calculated below in the vector vToEyePt.
@author Tony Peden, Jon Berndt
- @version $Id$
+ @version $Id: FGAuxiliary.h,v 1.17 2009/10/24 22:59:30 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Date started: 01/21/08
Purpose: Encapsulates the buoyant forces
- ------------- Copyright (C) 2008 - 2009 Anders Gidenstam -------------
+ ------------- Copyright (C) 2008 - 2010 Anders Gidenstam -------------
------------- Copyright (C) 2008 Jon S. Berndt (jon@jsbsim.org) -------------
This program is free software; you can redistribute it and/or modify it under
#include "FGBuoyantForces.h"
#include "FGMassBalance.h"
-#include "input_output/FGPropertyManager.h" // Need?
+#include "input_output/FGPropertyManager.h"
#include <iostream>
using namespace std;
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGBuoyantForces.cpp,v 1.12 2010/05/07 18:59:55 andgi Exp $";
static const char *IdHdr = ID_BUOYANTFORCES;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
gasCellJ.InitMatrix();
- bind();
-
Debug(0);
}
FGModel::PostLoad(element);
+ if (!NoneDefined) {
+ bind();
+ }
+
return true;
}
void FGBuoyantForces::bind(void)
{
+ typedef double (FGBuoyantForces::*PMF)(int) const;
+ PropertyManager->Tie("moments/l-buoyancy-lbsft", this, eL,
+ (PMF)&FGBuoyantForces::GetMoments);
+ PropertyManager->Tie("moments/m-buoyancy-lbsft", this, eM,
+ (PMF)&FGBuoyantForces::GetMoments);
+ PropertyManager->Tie("moments/n-buoyancy-lbsft", this, eN,
+ (PMF)&FGBuoyantForces::GetMoments);
+ PropertyManager->Tie("forces/fbx-buoyancy-lbs", this, eX,
+ (PMF)&FGBuoyantForces::GetForces);
+ PropertyManager->Tie("forces/fby-buoyancy-lbs", this, eY,
+ (PMF)&FGBuoyantForces::GetForces);
+ PropertyManager->Tie("forces/fbz-buoyancy-lbs", this, eZ,
+ (PMF)&FGBuoyantForces::GetForces);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Author: Anders Gidenstam, Jon S. Berndt
Date started: 01/21/08
- ------------- Copyright (C) 2008 Anders Gidenstam -------------
+ ------------- Copyright (C) 2008 - 2010 Anders Gidenstam -------------
------------- Copyright (C) 2008 Jon S. Berndt (jon@jsbsim.org) -------------
This program is free software; you can redistribute it and/or modify it under
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_BUOYANTFORCES "$Id$"
+#define ID_BUOYANTFORCES "$Id: FGBuoyantForces.h,v 1.11 2010/05/07 20:38:34 andgi Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
See FGGasCell for the full configuration file format for gas cells.
@author Anders Gidenstam, Jon S. Berndt
- @version $Id$
+ @version $Id: FGBuoyantForces.h,v 1.11 2010/05/07 20:38:34 andgi Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@return a force vector. */
const FGColumnVector3& GetForces(void) const {return vTotalForces;}
+ /** Gets a component of the total Buoyant force vector.
+ @return a component of the force vector. */
+ double GetForces(int idx) const {return vTotalForces(idx);}
+
/** Gets the total Buoyancy moment vector.
@return a moment vector. */
const FGColumnVector3& GetMoments(void) const {return vTotalMoments;}
+ /** Gets a component of the total Buoyancy moment vector.
+ @return a component of the moment vector. */
+ double GetMoments(int idx) const {return vTotalMoments(idx);}
+
/** Gets the total gas mass. The gas mass is part of the aircraft's
inertia.
@return mass in slugs. */
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGExternalForce.cpp,v 1.10 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_EXTERNALFORCE;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_EXTERNALFORCE "$Id$"
+#define ID_EXTERNALFORCE "$Id: FGExternalForce.h,v 1.8 2009/10/02 10:30:09 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
GLOBAL DATA
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGExternalReactions.cpp,v 1.8 2009/11/12 13:08:11 jberndt Exp $";
static const char *IdHdr = ID_EXTERNALREACTIONS;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_EXTERNALREACTIONS "$Id$"
+#define ID_EXTERNALREACTIONS "$Id: FGExternalReactions.h,v 1.9 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGFCS.cpp,v 1.68 2010/03/18 13:21:24 jberndt Exp $";
static const char *IdHdr = ID_FCS;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Components=0;
- string separator = "/";
-
// ToDo: The handling of name and file attributes could be improved, here,
// considering that a name can be in the external file, as well.
name = el->GetAttributeValue("name");
- if (name.empty()) {
+ if (name.empty() || !el->GetAttributeValue("file").empty()) {
fname = el->GetAttributeValue("file");
if (systype == stSystem) {
file = FindSystemFullPathname(fname);
} else {
- file = FDMExec->GetFullAircraftPath() + separator + fname + ".xml";
+ file = FDMExec->GetFullAircraftPath() + "/" + fname + ".xml";
}
if (fname.empty()) {
cerr << "FCS, Autopilot, or system does not appear to be defined inline nor in a file" << endl;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-string FGFCS::FindSystemFullPathname(const string& system_filename)
+string FGFCS::FindSystemFullPathname(const string& sysfilename)
{
string fullpath, localpath;
+ string system_filename = sysfilename;
string systemPath = FDMExec->GetSystemsPath();
string aircraftPath = FDMExec->GetFullAircraftPath();
ifstream system_file;
- string separator = "/";
+ fullpath = systemPath + "/";
+ localpath = aircraftPath + "/Systems/";
- fullpath = systemPath + separator;
- localpath = aircraftPath + separator + "Systems" + separator;
+ if (system_filename.length() <=4 || system_filename.substr(system_filename.length()-4, 4) != ".xml") {
+ system_filename.append(".xml");
+ }
- system_file.open(string(fullpath + system_filename + ".xml").c_str());
+ system_file.open(string(fullpath + system_filename).c_str());
if ( !system_file.is_open()) {
- system_file.open(string(localpath + system_filename + ".xml").c_str());
+ system_file.open(string(localpath + system_filename).c_str());
if ( !system_file.is_open()) {
cerr << " Could not open system file: " << system_filename << " in path "
<< fullpath << " or " << localpath << endl;
return string("");
} else {
- return string(localpath + system_filename + ".xml");
+ return string(localpath + system_filename);
}
}
- return string(fullpath + system_filename + ".xml");
+ return string(fullpath + system_filename);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-ifstream* FGFCS::FindSystemFile(const string& system_filename)
+ifstream* FGFCS::FindSystemFile(const string& sysfilename)
{
string fullpath, localpath;
+ string system_filename = sysfilename;
string systemPath = FDMExec->GetSystemsPath();
string aircraftPath = FDMExec->GetFullAircraftPath();
ifstream* system_file = new ifstream();
- string separator = "/";
+ fullpath = systemPath + "/";
+ localpath = aircraftPath + "/Systems/";
- fullpath = systemPath + separator;
- localpath = aircraftPath + separator + "Systems" + separator;
+ if (system_filename.substr(system_filename.length()-4, 4) != ".xml") {
+ system_filename.append(".xml");
+ }
- system_file->open(string(fullpath + system_filename + ".xml").c_str());
+ system_file->open(string(fullpath + system_filename).c_str());
if ( !system_file->is_open()) {
- system_file->open(string(localpath + system_filename + ".xml").c_str());
+ system_file->open(string(localpath + system_filename).c_str());
if ( !system_file->is_open()) {
cerr << " Could not open system file: " << system_filename << " in path "
<< fullpath << " or " << localpath << endl;
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FCS "$Id$"
+#define ID_FCS "$Id: FGFCS.h,v 1.28 2010/01/18 13:12:25 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@property gear/tailhook-pos-norm
@author Jon S. Berndt
- @version $Revision$
+ @version $Revision: 1.28 $
@see FGActuator
@see FGDeadBand
@see FGFCSFunction
/** Sets the throttle command for the specified engine
@param engine engine ID number
- @param cmd throttle command in percent (0 - 100)*/
+ @param cmd normalized throttle command (0.0 - 1.0)*/
void SetThrottleCmd(int engine, double cmd);
/** Sets the mixture command for the specified engine
@param engine engine ID number
- @param cmd mixture command in percent (0 - 100)*/
+ @param cmd normalized mixture command (0.0 - 1.0)*/
void SetMixtureCmd(int engine, double cmd);
/** Set the gear extend/retract command, defaults to down
/** Sets the actual throttle setting for the specified engine
@param engine engine ID number
- @param cmd throttle setting in percent (0 - 100)*/
+ @param cmd normalized throttle setting (0.0 - 1.0)*/
void SetThrottlePos(int engine, double cmd);
/** Sets the actual mixture setting for the specified engine
@param engine engine ID number
- @param cmd mixture setting in percent (0 - 100)*/
+ @param cmd normalized mixture setting (0.0 - 1.0)*/
void SetMixturePos(int engine, double cmd);
/** Sets the steering position
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGGasCell.cpp,v 1.12 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_GASCELL;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_GASCELL "$Id$"
+#define ID_GASCELL "$Id: FGGasCell.h,v 1.10 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGGroundReactions.cpp,v 1.26 2009/11/12 13:08:11 jberndt Exp $";
static const char *IdHdr = ID_GROUNDREACTIONS;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include "math/FGColumnVector3.h"
#include "input_output/FGXMLElement.h"
-#define ID_GROUNDREACTIONS "$Id$"
+#define ID_GROUNDREACTIONS "$Id: FGGroundReactions.h,v 1.15 2009/10/02 10:30:09 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
#include "FGInertial.h"
#include "FGFDMExec.h"
#include "FGPropagate.h"
-#include "FGState.h"
#include "FGMassBalance.h"
#include <iostream>
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGInertial.cpp,v 1.18 2010/03/28 05:57:00 jberndt Exp $";
static const char *IdHdr = ID_INERTIAL;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Gravitation accel
double r = Propagate->GetRadius();
gAccel = GetGAccel(r);
- earthPosAngle += State->Getdt()*RotationRate;
+ earthPosAngle += FDMExec->GetDeltaT()*RotationRate;
RunPostFunctions();
return GM/(r*r);
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+//
+// Calculate the WGS84 gravitation value in ECEF frame. Pass in the ECEF position
+// via the position parameter. The J2Gravity value returned is in ECEF frame,
+// and therefore may need to be expressed (transformed) in another frame,
+// depending on how it is used. See Stevens and Lewis eqn. 1.4-16.
+
+FGColumnVector3 FGInertial::GetGravityJ2(FGColumnVector3 position) const
+{
+ FGColumnVector3 J2Gravity;
+
+ // Gravitation accel
+ double r = position.Magnitude();
+ double lat = Propagate->GetLatitude();
+ double sinLat = sin(lat);
+
+ double preCommon = 1.5*J2*(a/r)*(a/r);
+ double xy = 1.0 - 5.0*(sinLat*sinLat);
+ double z = 3.0 - 5.0*(sinLat*sinLat);
+ double GMOverr2 = GM/(r*r);
+
+ J2Gravity(1) = -GMOverr2 * ((1.0 + (preCommon * xy)) * position(eX)/r);
+ J2Gravity(2) = -GMOverr2 * ((1.0 + (preCommon * xy)) * position(eY)/r);
+ J2Gravity(3) = -GMOverr2 * ((1.0 + (preCommon * z)) * position(eZ)/r);
+
+ return J2Gravity;
+}
+
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGInertial::bind(void)
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_INERTIAL "$Id$"
+#define ID_INERTIAL "$Id: FGInertial.h,v 1.15 2010/01/27 04:01:09 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
double GetEarthPositionAngle(void) const { return earthPosAngle; }
double GetEarthPositionAngleDeg(void) const { return earthPosAngle*radtodeg;}
double GetGAccel(double r) const;
+ FGColumnVector3 GetGravityJ2(FGColumnVector3 position) const;
double GetRefRadius(void) const {return RadiusReference;}
double GetSemimajor(void) const {return a;}
double GetSemiminor(void) const {return b;}
+ void SetEarthPositionAngle(double epa) {earthPosAngle = epa;}
+
private:
double gAccel;
double gAccelReference;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGInput.h"
-#include "FGState.h"
+#include "FGAircraft.h"
#include "FGFDMExec.h"
#include "input_output/FGfdmSocket.h"
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGInput.cpp,v 1.19 2010/02/25 05:21:36 jberndt Exp $";
static const char *IdHdr = ID_INPUT;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
info << "JSBSim version: " << JSBSim_version << endl;
info << "Config File version: " << needed_cfg_version << endl;
info << "Aircraft simulated: " << Aircraft->GetAircraftName() << endl;
- info << "Simulation time: " << setw(8) << setprecision(3) << State->Getsim_time() << endl;
+ info << "Simulation time: " << setw(8) << setprecision(3) << FDMExec->GetSimTime() << endl;
socket->Reply(info.str());
} else if (command == "help") { // HELP
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_INPUT "$Id$"
+#define ID_INPUT "$Id: FGInput.h,v 1.8 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGLGear.h"
-#include "FGState.h"
#include "FGGroundReactions.h"
#include "FGFCS.h"
#include "FGAuxiliary.h"
GLOBAL DATA
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGLGear.cpp,v 1.74 2010/05/18 10:54:14 jberndt Exp $";
static const char *IdHdr = ID_LGEAR;
// Body To Structural (body frame is rotated 180 deg about Y and lengths are given in
FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number) :
FGForce(fdmex),
GearNumber(number),
- SteerAngle(0.0)
+ SteerAngle(0.0),
+ Castered(false)
{
Element *force_table=0;
Element *dampCoeff=0;
if (sSteerType == "STEERABLE") eSteerType = stSteer;
else if (sSteerType == "FIXED" ) eSteerType = stFixed;
- else if (sSteerType == "CASTERED" ) eSteerType = stCaster;
+ else if (sSteerType == "CASTERED" ) {eSteerType = stCaster; Castered = true;}
else if (sSteerType.empty() ) {eSteerType = stFixed;
sSteerType = "FIXED (defaulted)";}
else {
}
}
- State = fdmex->GetState();
Aircraft = fdmex->GetAircraft();
Propagate = fdmex->GetPropagate();
Auxiliary = fdmex->GetAuxiliary();
FCS = fdmex->GetFCS();
MassBalance = fdmex->GetMassBalance();
- LongForceLagFilterCoeff = 1/State->Getdt(); // default longitudinal force filter coefficient
- LatForceLagFilterCoeff = 1/State->Getdt(); // default lateral force filter coefficient
+ LongForceLagFilterCoeff = 1/fdmex->GetDeltaT(); // default longitudinal force filter coefficient
+ LatForceLagFilterCoeff = 1/fdmex->GetDeltaT(); // default lateral force filter coefficient
Element* force_lag_filter_elem = el->FindElement("force_lag_filter");
if (force_lag_filter_elem) {
}
}
- LongForceFilter = Filter(LongForceLagFilterCoeff, State->Getdt());
- LatForceFilter = Filter(LatForceLagFilterCoeff, State->Getdt());
+ LongForceFilter = Filter(LongForceLagFilterCoeff, fdmex->GetDeltaT());
+ LatForceFilter = Filter(LatForceLagFilterCoeff, fdmex->GetDeltaT());
- WheelSlipLagFilterCoeff = 1/State->Getdt();
+ WheelSlipLagFilterCoeff = 1/fdmex->GetDeltaT();
Element *wheel_slip_angle_lag_elem = el->FindElement("wheel_slip_filter");
if (wheel_slip_angle_lag_elem) {
WheelSlipLagFilterCoeff = wheel_slip_angle_lag_elem->GetDataAsNumber();
}
- WheelSlipFilter = Filter(WheelSlipLagFilterCoeff, State->Getdt());
+ WheelSlipFilter = Filter(WheelSlipLagFilterCoeff, fdmex->GetDeltaT());
GearUp = false;
GearDown = true;
FGColumnVector3& FGLGear::GetBodyForces(void)
{
- double t = fdmex->GetState()->Getsim_time();
- dT = State->Getdt()*fdmex->GetGroundReactions()->GetRate();
+ double t = fdmex->GetSimTime();
+ dT = fdmex->GetDeltaT()*fdmex->GetGroundReactions()->GetRate();
vFn.InitMatrix();
// Compute the height of the theoretical location of the wheel (if strut is not compressed) with
// respect to the ground level
double height = fdmex->GetGroundCallback()->GetAGLevel(t, gearLoc, contact, normal, cvel);
- vGroundNormal = -1. * Propagate->GetTec2b() * normal;
+ vGroundNormal = Propagate->GetTec2b() * normal;
// The height returned above is the AGL and is expressed in the Z direction of the local
// coordinate frame. We now need to transform this height in actual compression of the strut (BOGEY)
compressLength = verticalZProj > 0.0 ? -height / verticalZProj : 0.0;
break;
case ctSTRUCTURE:
- verticalZProj = (Propagate->GetTec2l()*normal)(eZ);
+ verticalZProj = -(Propagate->GetTec2l()*normal)(eZ);
compressLength = fabs(verticalZProj) > 0.0 ? -height / verticalZProj : 0.0;
break;
}
SteerAngle = 0.0;
break;
case stCaster:
- SteerAngle = atan2(vWhlVelVec(eY), fabs(vWhlVelVec(eX)));
+ if (!Castered)
+ SteerAngle = degtorad * FCS->GetSteerPosDeg(GearNumber);
+ else {
+ // Check that the speed is non-null otherwise use the current angle
+ if (vWhlVelVec.Magnitude(eX,eY) > 1E-3)
+ SteerAngle = atan2(vWhlVelVec(eY), fabs(vWhlVelVec(eX)));
+ }
break;
default:
cerr << "Improper steering type membership detected for this gear." << endl;
void FGLGear::ReportTakeoffOrLanding(void)
{
- double deltaT = State->Getdt()*fdmex->GetGroundReactions()->GetRate();
+ double deltaT = fdmex->GetDeltaT()*fdmex->GetGroundReactions()->GetRate();
if (FirstContact)
LandingDistanceTraveled += Auxiliary->GetVground()*deltaT;
if ( (compressLength > 500.0 ||
vFn.Magnitude() > 100000000.0 ||
GetMoments().Magnitude() > 5000000000.0 ||
- SinkRate > 1.4666*30 ) && !State->IntegrationSuspended())
+ SinkRate > 1.4666*30 ) && !fdmex->IntegrationSuspended())
{
PutMessage("Crash Detected: Simulation FREEZE.");
- State->SuspendIntegration();
+ fdmex->SuspendIntegration();
}
}
fdmex->GetPropertyManager()->Tie( property_name.c_str(), &staticFCoeff );
if (eSteerType == stCaster) {
- property_name = base_property_name + "/steering-angle-rad";
- fdmex->GetPropertyManager()->Tie( property_name.c_str(), &SteerAngle );
+ property_name = base_property_name + "/steering-angle-deg";
+ fdmex->GetPropertyManager()->Tie( property_name.c_str(), this, &FGLGear::GetSteerAngleDeg );
+ property_name = base_property_name + "/castered";
+ fdmex->GetPropertyManager()->Tie( property_name.c_str(), &Castered);
}
}
switch(repType) {
case erLand:
cout << endl << "Touchdown report for " << name << " (WOW at time: "
- << fdmex->GetState()->Getsim_time() << " seconds)" << endl;
+ << fdmex->GetSimTime() << " seconds)" << endl;
cout << " Sink rate at contact: " << SinkRate << " fps, "
<< SinkRate*0.3048 << " mps" << endl;
cout << " Contact ground speed: " << GroundSpeed*.5925 << " knots, "
break;
case erTakeoff:
cout << endl << "Takeoff report for " << name << " (Liftoff at time: "
- << fdmex->GetState()->Getsim_time() << " seconds)" << endl;
+ << fdmex->GetSimTime() << " seconds)" << endl;
cout << " Distance traveled: " << TakeoffDistanceTraveled
<< " ft, " << TakeoffDistanceTraveled*0.3048 << " meters" << endl;
cout << " Distance traveled (over 50'): " << TakeoffDistanceTraveled50ft
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_LGEAR "$Id$"
+#define ID_LGEAR "$Id: FGLGear.h,v 1.38 2010/03/23 22:44:36 andgi Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
<h3>Operational Properties</h3>
<ol>
<li>Name</li>
- <li>Steerability attribute {one of STEERABLE | FIXED | CASTERED}</li>
<li>Brake Group Membership {one of LEFT | CENTER | RIGHT | NOSE | TAIL | NONE}</li>
<li>Max Steer Angle, in degrees</li>
</ol></p>
</contact>
@endcode
@author Jon S. Berndt
- @version $Id$
+ @version $Id: FGLGear.h,v 1.38 2010/03/23 22:44:36 andgi Exp $
@see Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
NASA-Ames", NASA CR-2497, January 1975
@see Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
double GetWheelVel(int axis) const { return vWhlVelVec(axis);}
bool IsBogey(void) const { return (eContactType == ctBOGEY);}
double GetGearUnitPos(void);
+ double GetSteerAngleDeg(void) const { return radtodeg*SteerAngle; }
void bind(void);
bool isRetractable;
bool GearUp, GearDown;
bool Servicable;
+ bool Castered;
std::string name;
std::string sSteerType;
std::string sBrakeGroup;
#include "FGMassBalance.h"
#include "FGPropulsion.h"
+#include "propulsion/FGTank.h"
#include "FGBuoyantForces.h"
#include "input_output/FGPropertyManager.h"
#include <iostream>
+#include <iomanip>
#include <cstdlib>
using namespace std;
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGMassBalance.cpp,v 1.31 2010/02/19 00:30:00 jberndt Exp $";
static const char *IdHdr = ID_MASSBALANCE;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SetAircraftBaseInertias(FGMatrix33( bixx, -bixy, bixz,
-bixy, biyy, -biyz,
bixz, -biyz, bizz ));
- EmptyWeight = el->FindElementValueAsNumberConvertTo("emptywt", "LBS");
+ if (el->FindElement("emptywt")) {
+ EmptyWeight = el->FindElementValueAsNumberConvertTo("emptywt", "LBS");
+ }
element = el->FindElement("location");
while (element) {
void FGMassBalance::AddPointMass(Element* el)
{
+ double radius=0, length=0;
Element* loc_element = el->FindElement("location");
string pointmass_name = el->GetAttributeValue("name");
if (!loc_element) {
double w = el->FindElementValueAsNumberConvertTo("weight", "LBS");
FGColumnVector3 vXYZ = loc_element->FindElementTripletConvertTo("IN");
- PointMasses.push_back(new PointMass(w, vXYZ));
- PointMasses.back()->bind(PropertyManager, PointMasses.size()-1);
+ PointMass *pm = new PointMass(w, vXYZ);
+ pm->SetName(pointmass_name);
+
+ Element* form_element = el->FindElement("form");
+ if (form_element) {
+ string shape = form_element->GetAttributeValue("shape");
+ Element* radius_element = form_element->FindElement("radius");
+ Element* length_element = form_element->FindElement("length");
+ if (radius_element) radius = form_element->FindElementValueAsNumberConvertTo("radius", "FT");
+ if (length_element) length = form_element->FindElementValueAsNumberConvertTo("length", "FT");
+ if (shape == "tube") {
+ pm->SetPointMassShapeType(PointMass::esTube);
+ pm->SetRadius(radius);
+ pm->SetLength(length);
+ pm->CalculateShapeInertia();
+ } else if (shape == "cylinder") {
+ pm->SetPointMassShapeType(PointMass::esCylinder);
+ pm->SetRadius(radius);
+ pm->SetLength(length);
+ pm->CalculateShapeInertia();
+ } else if (shape == "sphere") {
+ pm->SetPointMassShapeType(PointMass::esSphere);
+ pm->SetRadius(radius);
+ pm->CalculateShapeInertia();
+ } else {
+ }
+ }
+
+ pm->bind(PropertyManager, PointMasses.size());
+ PointMasses.push_back(pm);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pmJ = FGMatrix33();
- for (unsigned int i=0; i<size; i++)
+ for (unsigned int i=0; i<size; i++) {
pmJ += GetPointmassInertia( lbtoslug * PointMasses[i]->Weight, PointMasses[i]->Location );
+ pmJ += PointMasses[i]->GetPointMassInertia();
+ }
return pmJ;
}
PropertyManager->Tie("inertia/weight-lbs", this,
&FGMassBalance::GetWeight);
PropertyManager->Tie("inertia/empty-weight-lbs", this,
- &FGMassBalance::GetWeight, &FGMassBalance::SetEmptyWeight);
+ &FGMassBalance::GetEmptyWeight);
PropertyManager->Tie("inertia/cg-x-in", this,1,
(PMF)&FGMassBalance::GetXYZcg);
PropertyManager->Tie("inertia/cg-y-in", this,2,
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
+//
+// This function binds properties for each pointmass object created.
+//
void FGMassBalance::PointMass::bind(FGPropertyManager* PropertyManager, int num) {
string tmp = CreateIndexedPropertyName("inertia/pointmass-weight-lbs", num);
PropertyManager->Tie( tmp.c_str(), this, &PointMass::GetPointMassWeight,
&PointMass::SetPointMassLocation);
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGMassBalance::GetMassPropertiesReport(void) const
+{
+ cout << endl << fgblue << highint
+ << " Mass Properties Report (English units: lbf, in, slug-ft^2)"
+ << reset << endl;
+ cout << " " << underon << " Weight CG-X CG-Y"
+ << " CG-Z Ixx Iyy Izz" << underoff << endl;
+ cout.precision(1);
+ cout << highint << setw(34) << left << " Base Vehicle " << normint
+ << right << setw(10) << EmptyWeight << setw(8) << vbaseXYZcg(eX) << setw(8)
+ << vbaseXYZcg(eY) << setw(8) << vbaseXYZcg(eZ) << setw(12) << baseJ(1,1)
+ << setw(12) << baseJ(2,2) << setw(12) << baseJ(3,3) << endl;
+
+ for (unsigned int i=0;i<PointMasses.size();i++) {
+ PointMass* pm = PointMasses[i];
+ double pmweight = pm->GetPointMassWeight();
+ cout << highint << left << setw(4) << i << setw(30) << pm->GetName() << normint
+ << right << setw(10) << pmweight << setw(8) << pm->GetLocation()(eX)
+ << setw(8) << pm->GetLocation()(eY) << setw(8) << pm->GetLocation()(eZ)
+ << setw(12) << pm->GetPointMassMoI(1,1) << setw(12) << pm->GetPointMassMoI(2,2)
+ << setw(12) << pm->GetPointMassMoI(3,3) << endl;
+ }
+
+ for (unsigned int i=0;i<Propulsion->GetNumTanks() ;i++) {
+ FGTank* tank = Propulsion->GetTank(i);
+ string tankname="";
+ if (tank->GetType() == FGTank::ttFUEL && tank->GetGrainType() != FGTank::gtUNKNOWN) {
+ tankname = "Solid Fuel";
+ } else if (tank->GetType() == FGTank::ttFUEL) {
+ tankname = "Fuel";
+ } else if (tank->GetType() == FGTank::ttOXIDIZER) {
+ tankname = "Oxidizer";
+ } else {
+ tankname = "(Unknown tank type)";
+ }
+ cout << highint << left << setw(4) << i << setw(30) << tankname << normint
+ << right << setw(10) << tank->GetContents() << setw(8) << tank->GetXYZ(eX)
+ << setw(8) << tank->GetXYZ(eY) << setw(8) << tank->GetXYZ(eZ)
+ << setw(12) << "*" << setw(12) << "*"
+ << setw(12) << "*" << endl;
+ }
+
+ cout << underon << setw(104) << " " << underoff << endl;
+ cout << highint << left << setw(30) << " Total: " << right << setw(14) << Weight
+ << setw(8) << vXYZcg(eX)
+ << setw(8) << vXYZcg(eY)
+ << setw(8) << vXYZcg(eZ)
+ << setw(12) << mJ(1,1)
+ << setw(12) << mJ(2,2)
+ << setw(12) << mJ(3,3)
+ << normint << endl;
+
+ cout.setf(ios_base::fixed);
+}
+
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// The bitmasked value choices are as follows:
// unset: In this case (the default) JSBSim would only print
cout << " baseIxy: " << baseJ(1,2) << " slug-ft2" << endl;
cout << " baseIxz: " << baseJ(1,3) << " slug-ft2" << endl;
cout << " baseIyz: " << baseJ(2,3) << " slug-ft2" << endl;
- cout << " EmptyWeight: " << EmptyWeight << " lbm" << endl;
+ cout << " Empty Weight: " << EmptyWeight << " lbm" << endl;
cout << " CG (x, y, z): " << vbaseXYZcg << endl;
// ToDo: Need to add point mass outputs here
for (unsigned int i=0; i<PointMasses.size(); i++) {
#include "math/FGMatrix33.h"
#include "input_output/FGXMLElement.h"
#include <vector>
+#include <string>
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_MASSBALANCE "$Id$"
+#define ID_MASSBALANCE "$Id: FGMassBalance.h,v 1.20 2010/02/04 13:09:26 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONSS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+using std::string;
+
namespace JSBSim {
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
double GetMass(void) const {return Mass;}
double GetWeight(void) const {return Weight;}
- FGColumnVector3& GetXYZcg(void) {return vXYZcg;}
+ double GetEmptyWeight(void) const {return EmptyWeight;}
+ const FGColumnVector3& GetXYZcg(void) const {return vXYZcg;}
double GetXYZcg(int axis) const {return vXYZcg(axis);}
- FGColumnVector3& GetDeltaXYZcg(void) {return vDeltaXYZcg;}
+ const FGColumnVector3& GetDeltaXYZcg(void) const {return vDeltaXYZcg;}
double GetDeltaXYZcg(int axis) const {return vDeltaXYZcg(axis);}
/** Computes the inertia contribution of a pointmass.
FGMatrix33& GetJ(void) {return mJ;}
FGMatrix33& GetJinv(void) {return mJinv;}
void SetAircraftBaseInertias(FGMatrix33 BaseJ) {baseJ = BaseJ;}
+ void GetMassPropertiesReport(void) const;
private:
double Weight;
FGColumnVector3 PointMassCG;
FGMatrix33& CalculatePMInertias(void);
+
+ /** The PointMass structure encapsulates a point mass object, moments of inertia
+ mass, location, etc. */
struct PointMass {
PointMass(double w, FGColumnVector3& vXYZ) {
Weight = w;
Location = vXYZ;
+ mPMInertia.InitMatrix();
+ Radius = 0.0;
+ Length = 0.0;
}
+
+ void CalculateShapeInertia(void) {
+ switch(eShapeType) {
+ case esTube:
+ mPMInertia(1,1) = (Weight/(32.16))*Radius*Radius; // mr^2
+ mPMInertia(2,2) = (Weight/(32.16*12))*(6*Radius*Radius + Length*Length);
+ mPMInertia(3,3) = mPMInertia(2,2);
+ break;
+ case esCylinder:
+ mPMInertia(1,1) = (Weight/(32.16*2))*Radius*Radius; // 0.5*mr^2
+ mPMInertia(2,2) = (Weight/(32.16*12))*(3*Radius*Radius + Length*Length);
+ mPMInertia(3,3) = mPMInertia(2,2);
+ break;
+ default:
+ break;
+ }
+ }
+
+ enum esShape {esUnspecified, esTube, esCylinder, esSphere} eShapeType;
FGColumnVector3 Location;
- double Weight;
+ double Weight; /// Weight in pounds.
+ double Radius; /// Radius in feet.
+ double Length; /// Length in feet.
+ string Name;
+ FGMatrix33 mPMInertia;
+
double GetPointMassLocation(int axis) const {return Location(axis);}
+ double GetPointMassWeight(void) const {return Weight;}
+ esShape GetShapeType(void) {return eShapeType;}
+ FGColumnVector3 GetLocation(void) {return Location;}
+ FGMatrix33 GetPointMassInertia(void) {return mPMInertia;}
+ string GetName(void) {return Name;}
+
void SetPointMassLocation(int axis, double value) {Location(axis) = value;}
void SetPointMassWeight(double wt) {Weight = wt;}
- double GetPointMassWeight(void) const {return Weight;}
+ void SetPointMassShapeType(esShape st) {eShapeType = st;}
+ void SetRadius(double r) {Radius = r;}
+ void SetLength(double l) {Length = l;}
+ void SetName(string name) {Name = name;}
+ double GetPointMassMoI(int r, int c) {return mPMInertia(r,c);}
void bind(FGPropertyManager* PropertyManager, int num);
};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGModel.h"
-#include "FGState.h"
#include "FGFDMExec.h"
#include "FGAtmosphere.h"
#include "FGFCS.h"
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGModel.cpp,v 1.14 2010/02/25 05:21:36 jberndt Exp $";
static const char *IdHdr = ID_MODEL;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FDMExec = fdmex;
NextModel = 0L;
- State = 0;
Atmosphere = 0;
FCS = 0;
Propulsion = 0;
bool FGModel::InitModel(void)
{
- State = FDMExec->GetState();
Atmosphere = FDMExec->GetAtmosphere();
FCS = FDMExec->GetFCS();
Propulsion = FDMExec->GetPropulsion();
Propagate = FDMExec->GetPropagate();
Auxiliary = FDMExec->GetAuxiliary();
- if (!State ||
- !Atmosphere ||
+ if (!Atmosphere ||
!FCS ||
!Propulsion ||
!MassBalance ||
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_MODEL "$Id$"
+#define ID_MODEL "$Id: FGModel.h,v 1.14 2009/11/12 13:08:11 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGOutput.h"
-#include "FGState.h"
#include "FGFDMExec.h"
#include "FGAtmosphere.h"
#include "FGFCS.h"
#include "FGPropagate.h"
#include "FGAuxiliary.h"
#include "FGInertial.h"
+#include "FGPropulsion.h"
#include "models/propulsion/FGEngine.h"
#include "models/propulsion/FGTank.h"
#include "models/propulsion/FGPiston.h"
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGOutput.cpp,v 1.48 2010/04/12 12:25:19 jberndt Exp $";
static const char *IdHdr = ID_OUTPUT;
// (stolen from FGFS native_fdm.cxx)
{
if (FGModel::Run()) return true;
- if (enabled && !State->IntegrationSuspended()&& !FDMExec->Holding()) {
+ if (enabled && !FDMExec->IntegrationSuspended()&& !FDMExec->Holding()) {
RunPreFunctions();
if (Type == otSocket) {
SocketOutput();
if (SubSystems & ssRates) {
outstream << delimeter;
outstream << "P (deg/s)" + delimeter + "Q (deg/s)" + delimeter + "R (deg/s)" + delimeter;
- outstream << "P dot (deg/s^2)" + delimeter + "Q dot (deg/s^2)" + delimeter + "R dot (deg/s^2)";
+ outstream << "P dot (deg/s^2)" + delimeter + "Q dot (deg/s^2)" + delimeter + "R dot (deg/s^2)" + delimeter;
+ outstream << "P_{inertial} (deg/s)" + delimeter + "Q_{inertial} (deg/s)" + delimeter + "R_{inertial} (deg/s)";
}
if (SubSystems & ssVelocities) {
outstream << delimeter;
outstream << "V_{Inertial} (ft/s)" + delimeter;
outstream << "UBody" + delimeter + "VBody" + delimeter + "WBody" + delimeter;
outstream << "Aero V_{X Body} (ft/s)" + delimeter + "Aero V_{Y Body} (ft/s)" + delimeter + "Aero V_{Z Body} (ft/s)" + delimeter;
+ outstream << "V_{X_{inertial}} (ft/s)" + delimeter + "V_{Y_{inertial}} (ft/s)" + delimeter + "V_{Z_{inertial}} (ft/s)" + delimeter;
outstream << "V_{North} (ft/s)" + delimeter + "V_{East} (ft/s)" + delimeter + "V_{Down} (ft/s)";
}
if (SubSystems & ssForces) {
outstream << "Beta (deg)" + delimeter;
outstream << "Latitude (deg)" + delimeter;
outstream << "Longitude (deg)" + delimeter;
- outstream << "ECEF X (ft)" + delimeter + "ECEF Y (ft)" + delimeter + "ECEF Z (ft)" + delimeter;
- outstream << "EPA (deg)" + delimeter;
+ outstream << "X_{ECI} (ft)" + delimeter + "Y_{ECI} (ft)" + delimeter + "Z_{ECI} (ft)" + delimeter;
+ outstream << "X_{ECEF} (ft)" + delimeter + "Y_{ECEF} (ft)" + delimeter + "Z_{ECEF} (ft)" + delimeter;
+ outstream << "Earth Position Angle (deg)" + delimeter;
outstream << "Distance AGL (ft)" + delimeter;
outstream << "Terrain Elevation (ft)";
}
dFirstPass = false;
}
- outstream << State->Getsim_time();
+ outstream << FDMExec->GetSimTime();
if (SubSystems & ssSimulation) {
}
if (SubSystems & ssAerosurfaces) {
if (SubSystems & ssRates) {
outstream << delimeter;
outstream << (radtodeg*Propagate->GetPQR()).Dump(delimeter) << delimeter;
- outstream << (radtodeg*Propagate->GetPQRdot()).Dump(delimeter);
+ outstream << (radtodeg*Propagate->GetPQRdot()).Dump(delimeter) << delimeter;
+ outstream << (radtodeg*Propagate->GetPQRi()).Dump(delimeter);
}
if (SubSystems & ssVelocities) {
outstream << delimeter;
outstream << Propagate->GetInertialVelocityMagnitude() << delimeter;
outstream << setprecision(12) << Propagate->GetUVW().Dump(delimeter) << delimeter;
outstream << Auxiliary->GetAeroUVW().Dump(delimeter) << delimeter;
+ outstream << Propagate->GetInertialVelocity().Dump(delimeter) << delimeter;
outstream << Propagate->GetVel().Dump(delimeter);
outstream.precision(10);
}
outstream << Propagate->GetLocation().GetLatitudeDeg() << delimeter;
outstream << Propagate->GetLocation().GetLongitudeDeg() << delimeter;
outstream.precision(18);
+ outstream << ((FGColumnVector3)Propagate->GetInertialPosition()).Dump(delimeter) << delimeter;
outstream << ((FGColumnVector3)Propagate->GetLocation()).Dump(delimeter) << delimeter;
outstream.precision(14);
outstream << Inertial->GetEarthPositionAngleDeg() << delimeter;
}
socket->Clear();
- socket->Append(State->Getsim_time());
+ socket->Append(FDMExec->GetSimTime());
if (SubSystems & ssAerosurfaces) {
socket->Append(FCS->GetDaCmd());
output_file_name = DirectivesFile; // one found in the config file.
document = LoadXMLDocument(output_file_name);
} else if (!element->GetAttributeValue("file").empty()) {
- output_file_name = element->GetAttributeValue("file");
+ output_file_name = FDMExec->GetRootDir() + element->GetAttributeValue("file");
document = LoadXMLDocument(output_file_name);
} else {
document = element;
}
- name = document->GetAttributeValue("name");
+ if (!document) return false;
+
+ name = FDMExec->GetRootDir() + document->GetAttributeValue("name");
type = document->GetAttributeValue("type");
SetType(type);
if (!document->GetAttributeValue("port").empty() && type == string("SOCKET")) {
{
rtHz = rtHz>1000?1000:(rtHz<0?0:rtHz);
if (rtHz > 0) {
- rate = (int)(0.5 + 1.0/(State->Getdt()*rtHz));
+ rate = (int)(0.5 + 1.0/(FDMExec->GetDeltaT()*rtHz));
Enable();
} else {
rate = 1;
}
switch (Type) {
case otCSV:
- cout << scratch << " in CSV format output at rate " << 1/(State->Getdt()*rate) << " Hz" << endl;
+ cout << scratch << " in CSV format output at rate " << 1/(FDMExec->GetDeltaT()*rate) << " Hz" << endl;
break;
case otNone:
default:
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_OUTPUT "$Id$"
+#define ID_OUTPUT "$Id: FGOutput.h,v 1.17 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
propulsion ON|OFF
</pre>
NOTE that Time is always output with the data.
- @version $Id$
+ @version $Id: FGOutput.h,v 1.17 2009/10/24 22:59:30 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include <cmath>
#include <cstdlib>
#include <iostream>
+#include <iomanip>
#include "FGPropagate.h"
+#include "FGGroundReactions.h"
#include "FGFDMExec.h"
-#include "FGState.h"
#include "FGAircraft.h"
#include "FGMassBalance.h"
#include "FGInertial.h"
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGPropagate.cpp,v 1.55 2010/07/09 04:11:45 jberndt Exp $";
static const char *IdHdr = ID_PROPAGATE;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{
Debug(0);
Name = "FGPropagate";
-
- last2_vPQRdot.InitMatrix();
- last_vPQRdot.InitMatrix();
+ gravType = gtWGS84;
+
vPQRdot.InitMatrix();
-
- last2_vQtrndot = FGQuaternion(0,0,0);
- last_vQtrndot = FGQuaternion(0,0,0);
vQtrndot = FGQuaternion(0,0,0);
-
- last2_vUVWdot.InitMatrix();
- last_vUVWdot.InitMatrix();
vUVWdot.InitMatrix();
-
- last2_vLocationDot.InitMatrix();
- last_vLocationDot.InitMatrix();
- vLocationDot.InitMatrix();
-
- vOmegaLocal.InitMatrix();
+ vInertialVelocity.InitMatrix();
integrator_rotational_rate = eAdamsBashforth2;
integrator_translational_rate = eTrapezoidal;
integrator_rotational_position = eAdamsBashforth2;
integrator_translational_position = eTrapezoidal;
+ VState.dqPQRdot.resize(4, FGColumnVector3(0.0,0.0,0.0));
+ VState.dqUVWdot.resize(4, FGColumnVector3(0.0,0.0,0.0));
+ VState.dqInertialVelocity.resize(4, FGColumnVector3(0.0,0.0,0.0));
+ VState.dqQtrndot.resize(4, FGQuaternion(0.0,0.0,0.0));
+
bind();
Debug(0);
}
VState.vLocation.SetRadius( LocalTerrainRadius + 4.0 );
VState.vLocation.SetEllipse(Inertial->GetSemimajor(), Inertial->GetSemiminor());
- vOmega = FGColumnVector3( 0.0, 0.0, Inertial->omega() ); // Earth rotation vector
+ vOmegaEarth = FGColumnVector3( 0.0, 0.0, Inertial->omega() ); // Earth rotation vector
- last2_vPQRdot.InitMatrix();
- last_vPQRdot.InitMatrix();
vPQRdot.InitMatrix();
-
- last2_vQtrndot = FGQuaternion(0,0,0);
- last_vQtrndot = FGQuaternion(0,0,0);
vQtrndot = FGQuaternion(0,0,0);
-
- last2_vUVWdot.InitMatrix();
- last_vUVWdot.InitMatrix();
vUVWdot.InitMatrix();
-
- last2_vLocationDot.InitMatrix();
- last_vLocationDot.InitMatrix();
- vLocationDot.InitMatrix();
+ vInertialVelocity.InitMatrix();
- vOmegaLocal.InitMatrix();
+ VState.dqPQRdot.resize(4, FGColumnVector3(0.0,0.0,0.0));
+ VState.dqUVWdot.resize(4, FGColumnVector3(0.0,0.0,0.0));
+ VState.dqInertialVelocity.resize(4, FGColumnVector3(0.0,0.0,0.0));
+ VState.dqQtrndot.resize(4, FGColumnVector3(0.0,0.0,0.0));
integrator_rotational_rate = eAdamsBashforth2;
integrator_translational_rate = eTrapezoidal;
SetSeaLevelRadius(FGIC->GetSeaLevelRadiusFtIC());
SetTerrainElevation(FGIC->GetTerrainElevationFtIC());
+ VehicleRadius = GetRadius();
+ radInv = 1.0/VehicleRadius;
+
+ // Initialize the State Vector elements and the transformation matrices
+
// Set the position lat/lon/radius
VState.vLocation.SetPosition( FGIC->GetLongitudeRadIC(),
- FGIC->GetLatitudeRadIC(),
- FGIC->GetAltitudeASLFtIC() + FGIC->GetSeaLevelRadiusFtIC() );
+ FGIC->GetLatitudeRadIC(),
+ FGIC->GetAltitudeASLFtIC() + FGIC->GetSeaLevelRadiusFtIC() );
- VehicleRadius = GetRadius();
- radInv = 1.0/VehicleRadius;
+ VState.vLocation.SetEarthPositionAngle(Inertial->GetEarthPositionAngle());
- // Set the Orientation from the euler angles
- VState.vQtrn = FGQuaternion( FGIC->GetPhiRadIC(),
- FGIC->GetThetaRadIC(),
- FGIC->GetPsiRadIC() );
+ Ti2ec = GetTi2ec(); // ECI to ECEF transform
+ Tec2i = Ti2ec.Transposed(); // ECEF to ECI frame transform
+
+ Tl2ec = GetTl2ec(); // local to ECEF transform
+ Tec2l = Tl2ec.Transposed(); // ECEF to local frame transform
+
+ Ti2l = GetTi2l();
+ Tl2i = Ti2l.Transposed();
+
+ // Set the orientation from the euler angles (is normalized within the
+ // constructor). The Euler angles represent the orientation of the body
+ // frame relative to the local frame.
+ VState.qAttitudeLocal = FGQuaternion( FGIC->GetPhiRadIC(),
+ FGIC->GetThetaRadIC(),
+ FGIC->GetPsiRadIC() );
+
+ VState.qAttitudeECI = Ti2l.GetQuaternion()*VState.qAttitudeLocal;
+
+ Ti2b = GetTi2b(); // ECI to body frame transform
+ Tb2i = Ti2b.Transposed(); // body to ECI frame transform
+
+ Tl2b = VState.qAttitudeLocal; // local to body frame transform
+ Tb2l = Tl2b.Transposed(); // body to local frame transform
+
+ Tec2b = Tl2b * Tec2l; // ECEF to body frame transform
+ Tb2ec = Tec2b.Transposed(); // body to ECEF frame tranform
// Set the velocities in the instantaneus body frame
VState.vUVW = FGColumnVector3( FGIC->GetUBodyFpsIC(),
- FGIC->GetVBodyFpsIC(),
- FGIC->GetWBodyFpsIC() );
+ FGIC->GetVBodyFpsIC(),
+ FGIC->GetWBodyFpsIC() );
- // Set the angular velocities in the instantaneus body frame.
- VState.vPQR = FGColumnVector3( FGIC->GetPRadpsIC(),
- FGIC->GetQRadpsIC(),
- FGIC->GetRRadpsIC() );
+ VState.vInertialPosition = Tec2i * VState.vLocation;
// Compute the local frame ECEF velocity
- vVel = GetTb2l()*VState.vUVW;
+ vVel = Tb2l * VState.vUVW;
- // Finally, make sure that the quaternion stays normalized.
- VState.vQtrn.Normalize();
+ // Refer to Stevens and Lewis, 1.5-14a, pg. 49.
+ // This is the rotation rate of the "Local" frame, expressed in the local frame.
- // Recompute the LocalTerrainRadius.
- RecomputeLocalTerrainRadius();
+ FGColumnVector3 vOmegaLocal = FGColumnVector3(
+ radInv*vVel(eEast),
+ -radInv*vVel(eNorth),
+ -radInv*vVel(eEast)*VState.vLocation.GetTanLatitude() );
- // These local copies of the transformation matrices are for use for
- // initial conditions only.
+ // Set the angular velocities of the body frame relative to the ECEF frame,
+ // expressed in the body frame. Effectively, this is:
+ // w_b/e = w_b/l + w_l/e
+ VState.vPQR = FGColumnVector3( FGIC->GetPRadpsIC(),
+ FGIC->GetQRadpsIC(),
+ FGIC->GetRRadpsIC() ) + Tl2b*vOmegaLocal;
+
+ VState.vPQRi = VState.vPQR + Ti2b * vOmegaEarth;
+
+ // Make an initial run and set past values
+ CalculatePQRdot(); // Angular rate derivative
+ CalculateUVWdot(); // Translational rate derivative
+ CalculateQuatdot(); // Angular orientation derivative
+ CalculateInertialVelocity(); // Translational position derivative
+
+ // Initialize past values deques
+ VState.dqPQRdot.clear();
+ VState.dqUVWdot.clear();
+ VState.dqInertialVelocity.clear();
+ VState.dqQtrndot.clear();
+ for (int i=0; i<4; i++) {
+ VState.dqPQRdot.push_front(vPQRdot);
+ VState.dqUVWdot.push_front(vUVWdot);
+ VState.dqInertialVelocity.push_front(VState.vInertialVelocity);
+ VState.dqQtrndot.push_front(vQtrndot);
+ }
- Tl2b = GetTl2b(); // local to body frame transform
- Tb2l = Tl2b.Transposed(); // body to local frame transform
- Tl2ec = GetTl2ec(); // local to ECEF transform
- Tec2l = Tl2ec.Transposed(); // ECEF to local frame transform
- Tec2b = Tl2b * Tec2l; // ECEF to body frame transform
- Tb2ec = Tec2b.Transposed(); // body to ECEF frame tranform
- Ti2ec = GetTi2ec(); // ECI to ECEF transform
- Tec2i = Ti2ec.Transposed(); // ECEF to ECI frame transform
- Ti2b = Tec2b*Ti2ec; // ECI to body frame transform
- Tb2i = Ti2b.Transposed(); // body to ECI frame transform
+ // Recompute the LocalTerrainRadius.
+ RecomputeLocalTerrainRadius();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bool FGPropagate::Run(void)
{
+static int ctr;
+
if (FGModel::Run()) return true; // Fast return if we have nothing to do ...
if (FDMExec->Holding()) return false;
- RunPreFunctions();
-
- RecomputeLocalTerrainRadius();
-
- // Calculate current aircraft radius from center of planet
-
- VehicleRadius = GetRadius();
- radInv = 1.0/VehicleRadius;
+ double dt = FDMExec->GetDeltaT()*rate; // The 'stepsize'
- // These local copies of the transformation matrices are for use this
- // pass through Run() only.
-
- Tl2b = GetTl2b(); // local to body frame transform
- Tb2l = Tl2b.Transposed(); // body to local frame transform
- Tl2ec = GetTl2ec(); // local to ECEF transform
- Tec2l = Tl2ec.Transposed(); // ECEF to local frame transform
- Tec2b = Tl2b * Tec2l; // ECEF to body frame transform
- Tb2ec = Tec2b.Transposed(); // body to ECEF frame tranform
- Ti2ec = GetTi2ec(); // ECI to ECEF transform
- Tec2i = Ti2ec.Transposed(); // ECEF to ECI frame transform
- Ti2b = Tec2b*Ti2ec; // ECI to body frame transform
- Tb2i = Ti2b.Transposed(); // body to ECI frame transform
+ RunPreFunctions();
- // Compute vehicle velocity wrt ECEF frame, expressed in Local horizontal frame.
- vVel = Tb2l * VState.vUVW;
+ // Calculate state derivatives
+ CalculatePQRdot(); // Angular rate derivative
+ CalculateUVWdot(); // Translational rate derivative
+ CalculateQuatdot(); // Angular orientation derivative
+ CalculateInertialVelocity(); // Translational position derivative
- // Inertial angular velocity measured in the body frame.
- vPQRi = VState.vPQR + Tec2b*vOmega;
+ // Propagate rotational / translational velocity, angular /translational position, respectively.
+ Integrate(VState.vPQRi, vPQRdot, VState.dqPQRdot, dt, integrator_rotational_rate);
+ Integrate(VState.vUVW, vUVWdot, VState.dqUVWdot, dt, integrator_translational_rate);
+ Integrate(VState.qAttitudeECI, vQtrndot, VState.dqQtrndot, dt, integrator_rotational_position);
+ Integrate(VState.vInertialPosition, VState.vInertialVelocity, VState.dqInertialVelocity, dt, integrator_translational_position);
- // Calculate state derivatives
- CalculatePQRdot(); // Angular rate derivative
- CalculateUVWdot(); // Translational rate derivative
- CalculateQuatdot(); // Angular orientation derivative
- CalculateLocationdot(); // Translational position derivative
+ VState.qAttitudeECI.Normalize(); // Normalize the ECI Attitude quaternion
- // Integrate to propagate the state
+ VState.vLocation.SetEarthPositionAngle(Inertial->GetEarthPositionAngle()); // Update the Earth position angle (EPA)
- double dt = State->Getdt()*rate; // The 'stepsize'
+ // Update the "Location-based" transformation matrices from the vLocation vector.
- // Propagate rotational velocity
+ Ti2ec = GetTi2ec(); // ECI to ECEF transform
+ Tec2i = Ti2ec.Transposed(); // ECEF to ECI frame transform
+ Tl2ec = GetTl2ec(); // local to ECEF transform
+ Tec2l = Tl2ec.Transposed(); // ECEF to local frame transform
+ Ti2l = GetTi2l();
+ Tl2i = Ti2l.Transposed();
- switch(integrator_rotational_rate) {
- case eRectEuler: VState.vPQR += dt*vPQRdot;
- break;
- case eTrapezoidal: VState.vPQR += 0.5*dt*(vPQRdot + last_vPQRdot);
- break;
- case eAdamsBashforth2: VState.vPQR += dt*(1.5*vPQRdot - 0.5*last_vPQRdot);
- break;
- case eAdamsBashforth3: VState.vPQR += (1/12.0)*dt*(23.0*vPQRdot - 16.0*last_vPQRdot + 5.0*last2_vPQRdot);
- break;
- case eNone: // do nothing, freeze angular rate
- break;
- }
-
- // Propagate translational velocity
+ // Update the "Orientation-based" transformation matrices from the orientation quaternion
- switch(integrator_translational_rate) {
- case eRectEuler: VState.vUVW += dt*vUVWdot;
- break;
- case eTrapezoidal: VState.vUVW += 0.5*dt*(vUVWdot + last_vUVWdot);
- break;
- case eAdamsBashforth2: VState.vUVW += dt*(1.5*vUVWdot - 0.5*last_vUVWdot);
- break;
- case eAdamsBashforth3: VState.vUVW += (1/12.0)*dt*(23.0*vUVWdot - 16.0*last_vUVWdot + 5.0*last2_vUVWdot);
- break;
- case eNone: // do nothing, freeze translational rate
- break;
- }
+ Ti2b = GetTi2b(); // ECI to body frame transform
+ Tb2i = Ti2b.Transposed(); // body to ECI frame transform
+ Tl2b = Ti2b*Tl2i; // local to body frame transform
+ Tb2l = Tl2b.Transposed(); // body to local frame transform
+ Tec2b = Tl2b * Tec2l; // ECEF to body frame transform
+ Tb2ec = Tec2b.Transposed(); // body to ECEF frame tranform
- // Propagate angular position
+ // Set auxililary state variables
+ VState.vLocation = Ti2ec*VState.vInertialPosition;
+ RecomputeLocalTerrainRadius();
- switch(integrator_rotational_position) {
- case eRectEuler: VState.vQtrn += dt*vQtrndot;
- break;
- case eTrapezoidal: VState.vQtrn += 0.5*dt*(vQtrndot + last_vQtrndot);
- break;
- case eAdamsBashforth2: VState.vQtrn += dt*(1.5*vQtrndot - 0.5*last_vQtrndot);
- break;
- case eAdamsBashforth3: VState.vQtrn += (1/12.0)*dt*(23.0*vQtrndot - 16.0*last_vQtrndot + 5.0*last2_vQtrndot);
- break;
- case eNone: // do nothing, freeze angular position
- break;
- }
+ // Calculate current aircraft radius from center of planet
+ VehicleRadius = VState.vInertialPosition.Magnitude();
+ radInv = 1.0/VehicleRadius;
- // Propagate translational position
+ VState.vPQR = VState.vPQRi - Ti2b * vOmegaEarth;
- switch(integrator_translational_position) {
- case eRectEuler: VState.vLocation += dt*vLocationDot;
- break;
- case eTrapezoidal: VState.vLocation += 0.5*dt*(vLocationDot + last_vLocationDot);
- break;
- case eAdamsBashforth2: VState.vLocation += dt*(1.5*vLocationDot - 0.5*last_vLocationDot);
- break;
- case eAdamsBashforth3: VState.vLocation += (1/12.0)*dt*(23.0*vLocationDot - 16.0*last_vLocationDot + 5.0*last2_vLocationDot);
- break;
- case eNone: // do nothing, freeze translational position
- break;
- }
-
- // Set past values
-
- last2_vPQRdot = last_vPQRdot;
- last_vPQRdot = vPQRdot;
-
- last2_vUVWdot = last_vUVWdot;
- last_vUVWdot = vUVWdot;
-
- last2_vQtrndot = last_vQtrndot;
- last_vQtrndot = vQtrndot;
+ VState.qAttitudeLocal = Tl2b.GetQuaternion();
- last2_vLocationDot = last_vLocationDot;
- last_vLocationDot = vLocationDot;
+ // Compute vehicle velocity wrt ECEF frame, expressed in Local horizontal frame.
+ vVel = Tb2l * VState.vUVW;
- RunPreFunctions();
+ RunPostFunctions();
Debug(2);
return false;
// J is the inertia matrix
// Jinv is the inverse inertia matrix
// vMoments is the moment vector in the body frame
-// vPQRi is the total inertial angular velocity of the vehicle
+// VState.vPQRi is the total inertial angular velocity of the vehicle
// expressed in the body frame.
// Reference: See Stevens and Lewis, "Aircraft Control and Simulation",
// Second edition (2004), eqn 1.5-16e (page 50)
// moments and the total inertial angular velocity expressed in the body
// frame.
- vPQRdot = Jinv*(vMoments - vPQRi*(J*vPQRi));
+ vPQRdot = Jinv*(vMoments - VState.vPQRi*(J*VState.vPQRi));
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGPropagate::CalculateQuatdot(void)
{
- vOmegaLocal.InitMatrix( radInv*vVel(eEast),
- -radInv*vVel(eNorth),
- -radInv*vVel(eEast)*VState.vLocation.GetTanLatitude() );
-
// Compute quaternion orientation derivative on current body rates
- vQtrndot = VState.vQtrn.GetQDot( VState.vPQR - Tl2b*vOmegaLocal);
+ vQtrndot = VState.qAttitudeECI.GetQDot( VState.vPQRi);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// This set of calculations results in the body frame accelerations being
// computed.
+// Compute body frame accelerations based on the current body forces.
+// Include centripetal and coriolis accelerations.
+// vOmegaEarth is the Earth angular rate - expressed in the inertial frame -
+// so it has to be transformed to the body frame. More completely,
+// vOmegaEarth is the rate of the ECEF frame relative to the Inertial
+// frame (ECI), expressed in the Inertial frame.
+// vForces is the total force on the vehicle in the body frame.
+// VState.vPQR is the vehicle body rate relative to the ECEF frame, expressed
+// in the body frame.
+// VState.vUVW is the vehicle velocity relative to the ECEF frame, expressed
+// in the body frame.
// Reference: See Stevens and Lewis, "Aircraft Control and Simulation",
-// Second edition (2004), eqn 1.5-16d (page 50)
+// Second edition (2004), eqns 1.5-13 (pg 48) and 1.5-16d (page 50)
void FGPropagate::CalculateUVWdot(void)
{
double mass = MassBalance->GetMass(); // mass
const FGColumnVector3& vForces = Aircraft->GetForces(); // current forces
- const FGColumnVector3 vGravAccel( 0.0, 0.0, Inertial->GetGAccel(VehicleRadius) );
-
- // Begin to compute body frame accelerations based on the current body forces
- vUVWdot = vForces/mass - VState.vPQR * VState.vUVW;
+ vUVWdot = vForces/mass - (VState.vPQR + 2.0*(Ti2b *vOmegaEarth)) * VState.vUVW;
- // Include Coriolis acceleration.
- vUVWdot -= 2.0 * (Ti2b *vOmega) * VState.vUVW;
-
- // Include Centrifugal acceleration.
- if (!GroundReactions->GetWOW()) {
- vUVWdot -= Ti2b*(vOmega*(vOmega*(Tec2i*VState.vLocation)));
+ // Include Centripetal acceleration.
+ if (!GroundReactions->GetWOW() && Aircraft->GetHoldDown() == 0) {
+ vUVWdot -= Ti2b * (vOmegaEarth*(vOmegaEarth*VState.vInertialPosition));
}
// Include Gravitation accel
- FGColumnVector3 gravAccel = Tl2b*vGravAccel;
- vUVWdot += gravAccel;
+ switch (gravType) {
+ case gtStandard:
+ vGravAccel = Tl2b * FGColumnVector3( 0.0, 0.0, Inertial->GetGAccel(VehicleRadius) );
+ break;
+ case gtWGS84:
+ vGravAccel = Tec2b * Inertial->GetGravityJ2(VState.vLocation);
+ break;
+ }
+
+ vUVWdot += vGravAccel;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-void FGPropagate::CalculateLocationdot(void)
-{
- // Transform the vehicle velocity relative to the ECEF frame, expressed
- // in the body frame, to be expressed in the ECEF frame.
- vLocationDot = Tb2ec * VState.vUVW;
-
- // Now, transform the velocity vector of the body relative to the origin (Earth
+ // Transform the velocity vector of the body relative to the origin (Earth
// center) to be expressed in the inertial frame, and add the vehicle velocity
- // contribution due to the rotation of the planet. The above velocity is only
- // relative to the rotating ECEF frame.
+ // contribution due to the rotation of the planet.
// Reference: See Stevens and Lewis, "Aircraft Control and Simulation",
// Second edition (2004), eqn 1.5-16c (page 50)
- vInertialVelocity = Tec2i * vLocationDot + (vOmega * (Tec2i * VState.vLocation));
+void FGPropagate::CalculateInertialVelocity(void)
+{
+ VState.vInertialVelocity = Tb2i * VState.vUVW + (vOmegaEarth * VState.vInertialPosition);
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGPropagate::Integrate( FGColumnVector3& Integrand,
+ FGColumnVector3& Val,
+ deque <FGColumnVector3>& ValDot,
+ double dt,
+ eIntegrateType integration_type)
+{
+ ValDot.push_front(Val);
+ ValDot.pop_back();
+
+ switch(integration_type) {
+ case eRectEuler: Integrand += dt*ValDot[0];
+ break;
+ case eTrapezoidal: Integrand += 0.5*dt*(ValDot[0] + ValDot[1]);
+ break;
+ case eAdamsBashforth2: Integrand += dt*(1.5*ValDot[0] - 0.5*ValDot[1]);
+ break;
+ case eAdamsBashforth3: Integrand += (1/12.0)*dt*(23.0*ValDot[0] - 16.0*ValDot[1] + 5.0*ValDot[2]);
+ break;
+ case eAdamsBashforth4: Integrand += (1/24.0)*dt*(55.0*ValDot[0] - 59.0*ValDot[1] + 37.0*ValDot[2] - 9.0*ValDot[3]);
+ break;
+ case eNone: // do nothing, freeze translational rate
+ break;
+ }
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGPropagate::Integrate( FGQuaternion& Integrand,
+ FGQuaternion& Val,
+ deque <FGQuaternion>& ValDot,
+ double dt,
+ eIntegrateType integration_type)
+{
+ ValDot.push_front(Val);
+ ValDot.pop_back();
+
+ switch(integration_type) {
+ case eRectEuler: Integrand += dt*ValDot[0];
+ break;
+ case eTrapezoidal: Integrand += 0.5*dt*(ValDot[0] + ValDot[1]);
+ break;
+ case eAdamsBashforth2: Integrand += dt*(1.5*ValDot[0] - 0.5*ValDot[1]);
+ break;
+ case eAdamsBashforth3: Integrand += (1/12.0)*dt*(23.0*ValDot[0] - 16.0*ValDot[1] + 5.0*ValDot[2]);
+ break;
+ case eAdamsBashforth4: Integrand += (1/24.0)*dt*(55.0*ValDot[0] - 59.0*ValDot[1] + 37.0*ValDot[2] - 9.0*ValDot[3]);
+ break;
+ case eNone: // do nothing, freeze translational rate
+ break;
+ }
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGPropagate::SetInertialOrientation(FGQuaternion Qi) {
+ VState.qAttitudeECI = Qi;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGPropagate::SetInertialVelocity(FGColumnVector3 Vi) {
+ VState.vInertialVelocity = Vi;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGPropagate::RecomputeLocalTerrainRadius(void)
{
- double t = State->Getsim_time();
+ double t = FDMExec->GetSimTime();
// Get the LocalTerrain radius.
- FGLocation contactloc;
- FGColumnVector3 dv;
- FDMExec->GetGroundCallback()->GetAGLevel(t, VState.vLocation, contactloc, dv, dv);
- LocalTerrainRadius = contactloc.GetRadius();
+// FDMExec->GetGroundCallback()->GetAGLevel(t, VState.vLocation, contactloc, dv, dv);
+// LocalTerrainRadius = contactloc.GetRadius();
+ LocalTerrainRadius = FDMExec->GetGroundCallback()->GetTerrainGeoCentRadius();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
+//Todo: when should this be called - when should the new EPA be used to
+// calculate the transformation matrix, so that the matrix is not a step
+// ahead of the sim and the associated calculations?
const FGMatrix33& FGPropagate::GetTi2ec(void)
{
- return VState.vLocation.GetTi2ec(Inertial->GetEarthPositionAngle());
+ return VState.vLocation.GetTi2ec();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
const FGMatrix33& FGPropagate::GetTec2i(void)
{
- return VState.vLocation.GetTec2i(Inertial->GetEarthPositionAngle());
+ return VState.vLocation.GetTec2i();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGPropagate::bind(void)
{
typedef double (FGPropagate::*PMF)(int) const;
-// typedef double (FGPropagate::*dPMF)() const;
+
PropertyManager->Tie("velocities/h-dot-fps", this, &FGPropagate::Gethdot);
PropertyManager->Tie("velocities/v-north-fps", this, eNorth, (PMF)&FGPropagate::GetVel);
PropertyManager->Tie("attitude/pitch-rad", this, (int)eTht, (PMF)&FGPropagate::GetEuler);
PropertyManager->Tie("attitude/heading-true-rad", this, (int)ePsi, (PMF)&FGPropagate::GetEuler);
- PropertyManager->Tie("simulation/integrator/rate/rotational", &integrator_rotational_rate);
- PropertyManager->Tie("simulation/integrator/rate/translational", &integrator_translational_rate);
- PropertyManager->Tie("simulation/integrator/position/rotational", &integrator_rotational_position);
- PropertyManager->Tie("simulation/integrator/position/translational", &integrator_translational_position);
+ PropertyManager->Tie("simulation/integrator/rate/rotational", (int*)&integrator_rotational_rate);
+ PropertyManager->Tie("simulation/integrator/rate/translational", (int*)&integrator_translational_rate);
+ PropertyManager->Tie("simulation/integrator/position/rotational", (int*)&integrator_rotational_position);
+ PropertyManager->Tie("simulation/integrator/position/translational", (int*)&integrator_translational_position);
+ PropertyManager->Tie("simulation/gravity-model", &gravType);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
}
if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
}
- if (debug_lvl & 8 ) { // Runtime state variables
+ if (debug_lvl & 8 && from == 2) { // Runtime state variables
+ cout << endl << fgblue << highint << left
+ << " Propagation Report (English units: ft, degrees) at simulation time " << FDMExec->GetSimTime() << " seconds"
+ << reset << endl;
+ cout << endl;
+ cout << highint << " Earth Position Angle (deg): " << setw(8) << setprecision(3) << reset
+ << Inertial->GetEarthPositionAngleDeg() << endl;
+ cout << endl;
+ cout << highint << " Body velocity (ft/sec): " << setw(8) << setprecision(3) << reset << VState.vUVW << endl;
+ cout << highint << " Local velocity (ft/sec): " << setw(8) << setprecision(3) << reset << vVel << endl;
+ cout << highint << " Inertial velocity (ft/sec): " << setw(8) << setprecision(3) << reset << VState.vInertialVelocity << endl;
+ cout << highint << " Inertial Position (ft): " << setw(10) << setprecision(3) << reset << VState.vInertialPosition << endl;
+ cout << highint << " Latitude (deg): " << setw(8) << setprecision(3) << reset << VState.vLocation.GetLatitudeDeg() << endl;
+ cout << highint << " Longitude (deg): " << setw(8) << setprecision(3) << reset << VState.vLocation.GetLongitudeDeg() << endl;
+ cout << highint << " Altitude ASL (ft): " << setw(8) << setprecision(3) << reset << GetAltitudeASL() << endl;
+ cout << highint << " Acceleration (NED, ft/sec^2): " << setw(8) << setprecision(3) << reset << Tb2l*GetUVWdot() << endl;
+ cout << endl;
+ cout << highint << " Matrix ECEF to Body (Orientation of Body with respect to ECEF): "
+ << reset << endl << Tec2b.Dump("\t", " ") << endl;
+ cout << highint << " Associated Euler angles (deg): " << setw(8)
+ << setprecision(3) << reset << (Tec2b.GetQuaternion().GetEuler()*radtodeg)
+ << endl << endl;
+
+ cout << highint << " Matrix Body to ECEF (Orientation of ECEF with respect to Body):"
+ << reset << endl << Tb2ec.Dump("\t", " ") << endl;
+ cout << highint << " Associated Euler angles (deg): " << setw(8)
+ << setprecision(3) << reset << (Tb2ec.GetQuaternion().GetEuler()*radtodeg)
+ << endl << endl;
+
+ cout << highint << " Matrix Local to Body (Orientation of Body with respect to Local):"
+ << reset << endl << Tl2b.Dump("\t", " ") << endl;
+ cout << highint << " Associated Euler angles (deg): " << setw(8)
+ << setprecision(3) << reset << (Tl2b.GetQuaternion().GetEuler()*radtodeg)
+ << endl << endl;
+
+ cout << highint << " Matrix Body to Local (Orientation of Local with respect to Body):"
+ << reset << endl << Tb2l.Dump("\t", " ") << endl;
+ cout << highint << " Associated Euler angles (deg): " << setw(8)
+ << setprecision(3) << reset << (Tb2l.GetQuaternion().GetEuler()*radtodeg)
+ << endl << endl;
+
+ cout << highint << " Matrix Local to ECEF (Orientation of ECEF with respect to Local):"
+ << reset << endl << Tl2ec.Dump("\t", " ") << endl;
+ cout << highint << " Associated Euler angles (deg): " << setw(8)
+ << setprecision(3) << reset << (Tl2ec.GetQuaternion().GetEuler()*radtodeg)
+ << endl << endl;
+
+ cout << highint << " Matrix ECEF to Local (Orientation of Local with respect to ECEF):"
+ << reset << endl << Tec2l.Dump("\t", " ") << endl;
+ cout << highint << " Associated Euler angles (deg): " << setw(8)
+ << setprecision(3) << reset << (Tec2l.GetQuaternion().GetEuler()*radtodeg)
+ << endl << endl;
+
+ cout << highint << " Matrix ECEF to Inertial (Orientation of Inertial with respect to ECEF):"
+ << reset << endl << Tec2i.Dump("\t", " ") << endl;
+ cout << highint << " Associated Euler angles (deg): " << setw(8)
+ << setprecision(3) << reset << (Tec2i.GetQuaternion().GetEuler()*radtodeg)
+ << endl << endl;
+
+ cout << highint << " Matrix Inertial to ECEF (Orientation of ECEF with respect to Inertial):"
+ << reset << endl << Ti2ec.Dump("\t", " ") << endl;
+ cout << highint << " Associated Euler angles (deg): " << setw(8)
+ << setprecision(3) << reset << (Ti2ec.GetQuaternion().GetEuler()*radtodeg)
+ << endl << endl;
+
+ cout << highint << " Matrix Inertial to Body (Orientation of Body with respect to Inertial):"
+ << reset << endl << Ti2b.Dump("\t", " ") << endl;
+ cout << highint << " Associated Euler angles (deg): " << setw(8)
+ << setprecision(3) << reset << (Ti2b.GetQuaternion().GetEuler()*radtodeg)
+ << endl << endl;
+
+ cout << highint << " Matrix Body to Inertial (Orientation of Inertial with respect to Body):"
+ << reset << endl << Tb2i.Dump("\t", " ") << endl;
+ cout << highint << " Associated Euler angles (deg): " << setw(8)
+ << setprecision(3) << reset << (Tb2i.GetQuaternion().GetEuler()*radtodeg)
+ << endl << endl;
+
+ cout << highint << " Matrix Inertial to Local (Orientation of Local with respect to Inertial):"
+ << reset << endl << Ti2l.Dump("\t", " ") << endl;
+ cout << highint << " Associated Euler angles (deg): " << setw(8)
+ << setprecision(3) << reset << (Ti2l.GetQuaternion().GetEuler()*radtodeg)
+ << endl << endl;
+
+ cout << highint << " Matrix Local to Inertial (Orientation of Inertial with respect to Local):"
+ << reset << endl << Tl2i.Dump("\t", " ") << endl;
+ cout << highint << " Associated Euler angles (deg): " << setw(8)
+ << setprecision(3) << reset << (Tl2i.GetQuaternion().GetEuler()*radtodeg)
+ << endl << endl;
+
+ cout << setprecision(6); // reset the output stream
}
if (debug_lvl & 16) { // Sanity checking
if (from == 2) { // State sanity checking
#include "math/FGLocation.h"
#include "math/FGQuaternion.h"
#include "math/FGMatrix33.h"
+#include <deque>
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_PROPAGATE "$Id$"
+#define ID_PROPAGATE "$Id: FGPropagate.h,v 1.41 2010/07/09 04:11:45 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
+using std::deque;
class FGInitialCondition;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The Equations of Motion (EOM) for JSBSim are integrated to propagate the
state of the vehicle given the forces and moments that act on it. The
integration accounts for a rotating Earth.
+
+ The general execution of this model follows this process:
+
+ -Calculate the angular accelerations
+ -Calculate the translational accelerations
+ -Calculate the angular rate
+ -Calculate the translational velocity
+
+ -Integrate accelerations and rates
+
Integration of rotational and translation position and rate can be
customized as needed or frozen by the selection of no integrator. The
selection of which integrator to use is done through the setting of
2: Trapezoidal
3: Adams Bashforth 2
4: Adams Bashforth 3
+ 5: Adams Bashforth 4
@endcode
@author Jon S. Berndt, Mathias Froehlich
- @version $Id$
+ @version $Id: FGPropagate.h,v 1.41 2010/07/09 04:11:45 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fixed (ECEF) frame.
units ft */
FGLocation vLocation;
+
/** The velocity vector of the vehicle with respect to the ECEF frame,
expressed in the body system.
units ft/sec */
FGColumnVector3 vUVW;
+
/** The angular velocity vector for the vehicle relative to the ECEF frame,
expressed in the body frame.
units rad/sec */
FGColumnVector3 vPQR;
+
+ /** The angular velocity vector for the vehicle body frame relative to the
+ ECI frame, expressed in the body frame.
+ units rad/sec */
+ FGColumnVector3 vPQRi;
+
/** The current orientation of the vehicle, that is, the orientation of the
- body frame relative to the local, vehilce-carried, NED frame. */
- FGQuaternion vQtrn;
+ body frame relative to the local, NED frame. */
+ FGQuaternion qAttitudeLocal;
+
+ /** The current orientation of the vehicle, that is, the orientation of the
+ body frame relative to the inertial (ECI) frame. */
+ FGQuaternion qAttitudeECI;
+
+ FGColumnVector3 vInertialVelocity;
+
+ FGColumnVector3 vInertialPosition;
+
+ deque <FGColumnVector3> dqPQRdot;
+ deque <FGColumnVector3> dqUVWdot;
+ deque <FGColumnVector3> dqInertialVelocity;
+ deque <FGQuaternion> dqQtrndot;
};
/** Constructor.
~FGPropagate();
/// These define the indices use to select the various integrators.
- enum eIntegrateType {eNone = 0, eRectEuler, eTrapezoidal, eAdamsBashforth2, eAdamsBashforth3};
+ enum eIntegrateType {eNone = 0, eRectEuler, eTrapezoidal, eAdamsBashforth2, eAdamsBashforth3, eAdamsBashforth4};
+
+ /// These define the indices use to select the gravitation models.
+ enum eGravType {gtStandard, gtWGS84};
/** Initializes the FGPropagate class after instantiation and prior to first execution.
The base class FGModel::InitModel is called first, initializing pointers to the
@return false if no error */
bool Run(void);
+ void CalculatePQRdot(void);
+ void CalculateQuatdot(void);
+ void CalculateInertialVelocity(void);
+ void CalculateUVWdot(void);
+ const FGQuaternion& GetQuaterniondot(void) const {return vQtrndot;}
+
/** Retrieves the velocity vector.
The vector returned is represented by an FGColumnVector reference. The vector
for the velocity in Local frame is organized (Vnorth, Veast, Vdown). The vector
in FGJSBBase. The relevant enumerators for the vector returned by this call are,
eP=1, eQ=2, eR=3.
units rad/sec
- @return The body frame angular rates in rad/sec.
+ @return The body frame inertial angular rates in rad/sec.
*/
- const FGColumnVector3& GetPQRi(void) const {return vPQRi;}
+ const FGColumnVector3& GetPQRi(void) const {return VState.vPQRi;}
/** Retrieves the body axis angular acceleration vector.
Retrieves the body axis angular acceleration vector in rad/sec^2. The
angle about the Y axis, and the third item is the angle
about the Z axis (Phi, Theta, Psi).
*/
- const FGColumnVector3& GetEuler(void) const { return VState.vQtrn.GetEuler(); }
+ const FGColumnVector3& GetEuler(void) const { return VState.qAttitudeLocal.GetEuler(); }
/** Retrieves a body frame velocity component.
Retrieves a body frame velocity component. The velocity returned is
/** Retrieves the total inertial velocity in ft/sec.
*/
- double GetInertialVelocityMagnitude(void) const { return vInertialVelocity.Magnitude(); }
+ double GetInertialVelocityMagnitude(void) const { return VState.vInertialVelocity.Magnitude(); }
+
+ /** Retrieves the inertial velocity vector in ft/sec.
+ */
+ const FGColumnVector3& GetInertialVelocity(void) const { return VState.vInertialVelocity; }
+
+ /** Retrieves the inertial position vector.
+ */
+ const FGColumnVector3& GetInertialPosition(void) const { return VState.vInertialPosition; }
/** Returns the current altitude above sea level.
This function returns the altitude above sea level.
@param axis the index of the angular velocity component desired (1-based).
@return The body frame angular velocity component.
*/
- double GetPQRi(int axis) const {return vPQRi(axis);}
+ double GetPQRi(int axis) const {return VState.vPQRi(axis);}
/** Retrieves a body frame angular acceleration component.
Retrieves a body frame angular acceleration component. The angular
units radians
@return An Euler angle.
*/
- double GetEuler(int axis) const { return VState.vQtrn.GetEuler(axis); }
+ double GetEuler(int axis) const { return VState.qAttitudeLocal.GetEuler(axis); }
/** Retrieves the cosine of a vehicle Euler angle component.
Retrieves the cosine of an Euler angle (Phi, Theta, or Psi) from the
units none
@return The cosine of an Euler angle.
*/
- double GetCosEuler(int idx) const { return VState.vQtrn.GetCosEuler(idx); }
+ double GetCosEuler(int idx) const { return VState.qAttitudeLocal.GetCosEuler(idx); }
/** Retrieves the sine of a vehicle Euler angle component.
Retrieves the sine of an Euler angle (Phi, Theta, or Psi) from the
units none
@return The sine of an Euler angle.
*/
- double GetSinEuler(int idx) const { return VState.vQtrn.GetSinEuler(idx); }
+ double GetSinEuler(int idx) const { return VState.qAttitudeLocal.GetSinEuler(idx); }
/** Returns the current altitude rate.
Returns the current altitude rate (rate of climb).
The quaternion class, being the means by which the orientation of the
vehicle is stored, manages the local-to-body transformation matrix.
@return a reference to the local-to-body transformation matrix. */
- const FGMatrix33& GetTl2b(void) const { return VState.vQtrn.GetT(); }
+ const FGMatrix33& GetTl2b(void) const { return VState.qAttitudeLocal.GetT(); }
/** Retrieves the body-to-local transformation matrix.
The quaternion class, being the means by which the orientation of the
vehicle is stored, manages the body-to-local transformation matrix.
@return a reference to the body-to-local matrix. */
- const FGMatrix33& GetTb2l(void) const { return VState.vQtrn.GetTInv(); }
+ const FGMatrix33& GetTb2l(void) const { return VState.qAttitudeLocal.GetTInv(); }
/** Retrieves the ECEF-to-body transformation matrix.
@return a reference to the ECEF-to-body transformation matrix. */
@return a reference to the body-to-ECEF matrix. */
const FGMatrix33& GetTb2ec(void) const { return Tb2ec; }
+ /** Retrieves the ECI-to-body transformation matrix.
+ @return a reference to the ECI-to-body transformation matrix. */
+ const FGMatrix33& GetTi2b(void) const { return VState.qAttitudeECI.GetT(); }
+
+ /** Retrieves the body-to-ECI transformation matrix.
+ @return a reference to the body-to-ECI matrix. */
+ const FGMatrix33& GetTb2i(void) const { return VState.qAttitudeECI.GetTInv(); }
+
/** Retrieves the ECEF-to-ECI transformation matrix.
@return a reference to the ECEF-to-ECI transformation matrix. */
const FGMatrix33& GetTec2i(void);
@return a reference to the local-to-ECEF matrix. */
const FGMatrix33& GetTl2ec(void) const { return VState.vLocation.GetTl2ec(); }
+ /** Retrieves the local-to-inertial transformation matrix.
+ @return a reference to the local-to-inertial transformation matrix. */
+ const FGMatrix33& GetTl2i(void) { return VState.vLocation.GetTl2i(); }
+
+ /** Retrieves the inertial-to-local transformation matrix.
+ @return a reference to the inertial-to-local matrix. */
+ const FGMatrix33& GetTi2l(void) { return VState.vLocation.GetTi2l(); }
+
VehicleState* GetVState(void) { return &VState; }
void SetVState(VehicleState* vstate) {
VState.vLocation = vstate->vLocation;
VState.vUVW = vstate->vUVW;
VState.vPQR = vstate->vPQR;
- VState.vQtrn = vstate->vQtrn; // ... mmh
+ VState.qAttitudeLocal = vstate->qAttitudeLocal;
+ VState.qAttitudeECI = vstate->qAttitudeECI;
+
+ VState.dqPQRdot.resize(4, FGColumnVector3(0.0,0.0,0.0));
+ VState.dqUVWdot.resize(4, FGColumnVector3(0.0,0.0,0.0));
+ VState.dqInertialVelocity.resize(4, FGColumnVector3(0.0,0.0,0.0));
+ VState.dqQtrndot.resize(4, FGColumnVector3(0.0,0.0,0.0));
}
- const FGQuaternion GetQuaternion(void) const { return VState.vQtrn; }
+ void SetInertialOrientation(FGQuaternion Qi);
+ void SetInertialVelocity(FGColumnVector3 Vi);
+
+ const FGQuaternion GetQuaternion(void) const { return VState.qAttitudeLocal; }
void SetPQR(unsigned int i, double val) {
if ((i>=1) && (i<=3) )
VState.vLocation -= vDeltaXYZEC;
}
- void CalculatePQRdot(void);
- void CalculateQuatdot(void);
- void CalculateLocationdot(void);
- void CalculateUVWdot(void);
-
private:
// state vector
struct VehicleState VState;
FGColumnVector3 vVel;
+ FGColumnVector3 vPQRdot;
+ FGColumnVector3 vUVWdot;
FGColumnVector3 vInertialVelocity;
- FGColumnVector3 vPQRdot, last_vPQRdot, last2_vPQRdot;
- FGColumnVector3 vUVWdot, last_vUVWdot, last2_vUVWdot;
- FGColumnVector3 vLocationDot, last_vLocationDot, last2_vLocationDot;
FGColumnVector3 vLocation;
FGColumnVector3 vDeltaXYZEC;
- FGColumnVector3 vPQRi; // Inertial frame angular velocity
- FGColumnVector3 vOmega; // The Earth angular velocity vector
- FGColumnVector3 vOmegaLocal; // The local frame angular velocity vector
- FGQuaternion vQtrndot, last_vQtrndot, last2_vQtrndot;
+ FGColumnVector3 vGravAccel;
+ FGColumnVector3 vOmegaEarth; // The Earth angular velocity vector
+ FGQuaternion vQtrndot;
FGMatrix33 Tec2b;
FGMatrix33 Tb2ec;
FGMatrix33 Tl2b; // local to body frame matrix copy for immediate local use
FGMatrix33 Ti2ec; // ECI to ECEF frame matrix copy for immediate local use
FGMatrix33 Ti2b; // ECI to body frame rotation matrix
FGMatrix33 Tb2i; // body to ECI frame rotation matrix
+ FGMatrix33 Ti2l;
+ FGMatrix33 Tl2i;
+ FGLocation contactloc;
+ FGColumnVector3 dv;
double LocalTerrainRadius, SeaLevelRadius, VehicleRadius;
double radInv;
- int integrator_rotational_rate;
- int integrator_translational_rate;
- int integrator_rotational_position;
- int integrator_translational_position;
+ eIntegrateType integrator_rotational_rate;
+ eIntegrateType integrator_translational_rate;
+ eIntegrateType integrator_rotational_position;
+ eIntegrateType integrator_translational_position;
+ int gravType;
+
+ void Integrate( FGColumnVector3& Integrand,
+ FGColumnVector3& Val,
+ deque <FGColumnVector3>& ValDot,
+ double dt,
+ eIntegrateType integration_type);
+
+ void Integrate( FGQuaternion& Integrand,
+ FGQuaternion& Val,
+ deque <FGQuaternion>& ValDot,
+ double dt,
+ eIntegrateType integration_type);
void bind(void);
void Debug(int from);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGPropulsion.h"
-#include "FGState.h"
#include "models/FGFCS.h"
#include "models/FGMassBalance.h"
#include "models/propulsion/FGThruster.h"
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGPropulsion.cpp,v 1.39 2010/02/25 05:21:36 jberndt Exp $";
static const char *IdHdr = ID_PROPULSION;
extern short debug_lvl;
RunPreFunctions();
- double dt = State->Getdt();
+ double dt = FDMExec->GetDeltaT();
vForces.InitMatrix();
vMoments.InitMatrix();
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_PROPULSION "$Id$"
+#define ID_PROPULSION "$Id: FGPropulsion.h,v 1.25 2010/01/02 17:58:01 andgi Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@endcode
@author Jon S. Berndt
- @version $Id$
+ @version $Id: FGPropulsion.h,v 1.25 2010/01/02 17:58:01 andgi Exp $
@see
FGEngine
FGTank
@return the address of the specific engine, or zero if no such engine is
available */
inline FGEngine* GetEngine(unsigned int index) {
- if (index <= Engines.size()-1) return Engines[index];
- else return 0L; }
+ if (index < Engines.size()) return Engines[index];
+ else return 0L; }
/// Retrieves the number of tanks defined for the aircraft.
inline unsigned int GetNumTanks(void) const {return (unsigned int)Tanks.size();}
@return the address of the specific tank, or zero if no such tank is
available */
inline FGTank* GetTank(unsigned int index) {
- if (index <= Tanks.size()-1) return Tanks[index];
- else return 0L; }
+ if (index < Tanks.size()) return Tanks[index];
+ else return 0L; }
/** Returns the number of fuel tanks currently actively supplying fuel */
inline int GetnumSelectedFuelTanks(void) const {return numSelectedFuelTanks;}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGMSIS.h"
-#include "FGState.h"
+#include "models/FGAuxiliary.h"
#include <cmath> /* maths functions */
#include <iostream> // for cout, endl
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGMSIS.cpp,v 1.13 2010/02/25 05:21:36 jberndt Exp $";
static const char *IdHdr = ID_MSIS;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "models/FGAtmosphere.h"
+#include "FGFDMExec.h"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_MSIS "$Id$"
+#define ID_MSIS "$Id: FGMSIS.h,v 1.7 2010/02/25 05:21:36 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
and check http://www.brodo.de/english/pub/nrlmsise/index.html for
updated releases of this package.
@author David Culp
- @version $Id$
+ @version $Id: FGMSIS.h,v 1.7 2010/02/25 05:21:36 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGMars.h"
-#include "FGState.h"
#include <iostream>
using namespace std;
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGMars.cpp,v 1.10 2010/02/25 05:21:36 jberndt Exp $";
static const char *IdHdr = ID_MARS;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_MARS "$Id$"
+#define ID_MARS "$Id: FGMars.h,v 1.8 2009/10/02 10:30:09 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
/** Models the Martian atmosphere.
@author Jon Berndt
- @version $Id$
+ @version $Id: FGMars.h,v 1.8 2009/10/02 10:30:09 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGAccelerometer.cpp,v 1.8 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_ACCELEROMETER;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_ACCELEROMETER "$Id$"
+#define ID_ACCELEROMETER "$Id: FGAccelerometer.h,v 1.4 2009/10/02 10:30:09 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
time.
@author Jon S. Berndt
-@version $Revision$
+@version $Revision: 1.4 $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGActuator.cpp,v 1.14 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_ACTUATOR;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_ACTUATOR "$Id$"
+#define ID_ACTUATOR "$Id: FGActuator.h,v 1.11 2009/10/02 10:30:09 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@endcode
@author Jon S. Berndt
-@version $Revision$
+@version $Revision: 1.11 $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGDeadBand.cpp,v 1.9 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_DEADBAND;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_DEADBAND "$Id$"
+#define ID_DEADBAND "$Id: FGDeadBand.h,v 1.9 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
produce no output. For example, say that the width value is 2.0. If the
input is between -1.0 and +1.0, the output will be zero.
@author Jon S. Berndt
- @version $Id$
+ @version $Id: FGDeadBand.h,v 1.9 2009/10/24 22:59:30 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGFCSComponent.cpp,v 1.27 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_FCSCOMPONENT;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FCSCOMPONENT "$Id$"
+#define ID_FCSCOMPONENT "$Id: FGFCSComponent.h,v 1.16 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
- FGActuator
@author Jon S. Berndt
- @version $Id$
+ @version $Id: FGFCSComponent.h,v 1.16 2009/10/24 22:59:30 jberndt Exp $
@see Documentation for the FGFCS class, and for the configuration file class
*/
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGFCSFunction.cpp,v 1.9 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_FCSFUNCTION;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FCSFUNCTION "$Id$"
+#define ID_FCSFUNCTION "$Id: FGFCSFunction.h,v 1.7 2009/10/02 10:30:09 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
</function>
@endcode
- @version $Id$
+ @version $Id: FGFCSFunction.h,v 1.7 2009/10/02 10:30:09 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGFilter.cpp,v 1.15 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_FILTER;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FILTER "$Id$"
+#define ID_FILTER "$Id: FGFilter.h,v 1.12 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
output, such as the elevator, or speedbrake, etc.
@author Jon S. Berndt
-@version $Revision$
+@version $Revision: 1.12 $
*/
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGGain.cpp,v 1.20 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_GAIN;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_GAIN "$Id$"
+#define ID_GAIN "$Id: FGGain.h,v 1.14 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@endcode
@author Jon S. Berndt
- @version $Revision$
+ @version $Revision: 1.14 $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGGradient.cpp,v 1.4 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_GRADIENT;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_GRADIENT "$Id$"
+#define ID_GRADIENT "$Id: FGGradient.h,v 1.5 2009/10/02 10:30:09 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGGyro.cpp,v 1.5 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_GYRO;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_GYRO "$Id$"
+#define ID_GYRO "$Id: FGGyro.h,v 1.5 2009/12/11 06:03:06 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@code
<gyro name="name">
- <input> property </input>
<lag> number </lag>
<noise variation="PERCENT|ABSOLUTE"> number </noise>
<quantization name="name">
Example:
@code
-<gyro name="aero/gyro/qbar">
- <input> aero/qbar </input>
+<gyro name="aero/gyro/roll">
+ <axis> X </axis>
<lag> 0.5 </lag>
<noise variation="PERCENT"> 2 </noise>
<quantization name="aero/gyro/quantized/qbar">
</gyro>
@endcode
-The only required element in the gyro definition is the input element. In that
-case, no degradation would be modeled, and the output would simply be the input.
-
For noise, if the type is PERCENT, then the value supplied is understood to be a
percentage variance. That is, if the number given is 0.05, the the variance is
understood to be +/-0.05 percent maximum variance. So, the actual value for the gyro
time.
@author Jon S. Berndt
-@version $Revision$
+@version $Revision: 1.5 $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGKinemat.cpp,v 1.10 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_FLAPS;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FLAPS "$Id$"
+#define ID_FLAPS "$Id: FGKinemat.h,v 1.10 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGMagnetometer.cpp,v 1.5 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_MAGNETOMETER;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_MAGNETOMETER "$Id$"
+#define ID_MAGNETOMETER "$Id: FGMagnetometer.h,v 1.4 2009/12/11 06:03:06 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@code
<magnetometer name="name">
- <input> property </input>
+ <axis> {X|Y|Z} </axis>
<lag> number </lag>
+ <orientation unit=DEG">
+ <x> number </x>
+ <y> number </y>
+ <z> number </z>
+ </orientation>
<noise variation="PERCENT|ABSOLUTE"> number </noise>
<quantization name="name">
<bits> number </bits>
Example:
@code
-<magnetometer name="aero/magnetometer/qbar">
- <input> aero/qbar </input>
+<magnetometer name="aero/magnetometer/X">
+ <axis> X </axis>
<lag> 0.5 </lag>
<noise variation="PERCENT"> 2 </noise>
<quantization name="aero/magnetometer/quantized/qbar">
</magnetometer>
@endcode
-The only required element in the magnetometer definition is the input element. In that
-case, no degradation would be modeled, and the output would simply be the input.
+The only required element in the magnetometer definition is the axis element. In
+the default case, no degradation would be modeled, and the output would simply be
+the input.
For noise, if the type is PERCENT, then the value supplied is understood to be a
percentage variance. That is, if the number given is 0.05, the the variance is
time.
@author Jon S. Berndt
-@version $Revision$
+@version $Revision: 1.4 $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGPID.cpp,v 1.16 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_PID;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_PID "$Id$"
+#define ID_PID "$Id: FGPID.h,v 1.12 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
</pre>
@author Jon S. Berndt
- @version $Revision$
+ @version $Revision: 1.12 $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGSensor.cpp,v 1.20 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_SENSOR;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_SENSOR "$Id$"
+#define ID_SENSOR "$Id: FGSensor.h,v 1.19 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
the number of frames to delay the output signal.
@author Jon S. Berndt
-@version $Revision$
+@version $Revision: 1.19 $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_SensorOrientation "$Id$"
+#define ID_SensorOrientation "$Id: FGSensorOrientation.h,v 1.3 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
Syntax:
@author Jon S. Berndt
-@version $Revision$
+@version $Revision: 1.3 $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGSummer.cpp,v 1.7 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_SUMMER;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_SUMMER "$Id$"
+#define ID_SUMMER "$Id: FGSummer.h,v 1.9 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
</pre>
@author Jon S. Berndt
- @version $Id$
+ @version $Id: FGSummer.h,v 1.9 2009/10/24 22:59:30 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGSwitch.cpp,v 1.19 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_SWITCH;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_SWITCH "$Id$"
+#define ID_SWITCH "$Id: FGSwitch.h,v 1.13 2009/10/02 10:30:09 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
whatever value fcs/roll-ap-error-summer is.
@author Jon S. Berndt
-@version $Id$
+@version $Id: FGSwitch.h,v 1.13 2009/10/02 10:30:09 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGElectric.h"
-#include "FGState.h"
#include "models/FGPropulsion.h"
#include "models/propulsion/FGThruster.h"
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGElectric.cpp,v 1.8 2010/02/25 05:21:36 jberndt Exp $";
static const char *IdHdr = ID_ELECTRIC;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PowerWatts = 745.7;
hptowatts = 745.7;
- dt = State->Getdt();
+ dt = FDMExec->GetDeltaT();
if (el->FindElement("power"))
PowerWatts = el->FindElementValueAsNumberConvertTo("power","WATTS");
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_ELECTRIC "$Id$";
+#define ID_ELECTRIC "$Id: FGElectric.h,v 1.8 2009/10/24 22:59:30 jberndt Exp $";
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
there is no battery model available, so this motor does not consume any
energy. There is no internal friction.
@author David Culp
- @version "$Id$"
+ @version "$Id: FGElectric.h,v 1.8 2009/10/24 22:59:30 jberndt Exp $"
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include "FGTank.h"
#include "FGPropeller.h"
#include "FGNozzle.h"
-#include "FGState.h"
+#include "FGRotor.h"
#include "models/FGPropulsion.h"
#include "input_output/FGXMLParse.h"
#include "math/FGColumnVector3.h"
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGEngine.cpp,v 1.38 2010/06/02 04:05:13 jberndt Exp $";
static const char *IdHdr = ID_ENGINE;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ResetToIC(); // initialize dynamic terms
FDMExec = exec;
- State = FDMExec->GetState();
Atmosphere = FDMExec->GetAtmosphere();
FCS = FDMExec->GetFCS();
Propulsion = FDMExec->GetPropulsion();
while (local_element) {
int tankID = (int)local_element->GetDataAsNumber();
FGTank* tank = Propulsion->GetTank(tankID);
- AddFeedTank( tankID , tank->GetPriority());
- FuelDensity = tank->GetDensity();
+ if (tank) {
+ AddFeedTank(tankID, tank->GetPriority());
+ FuelDensity = tank->GetDensity();
+ } else {
+ cerr << "Feed tank " << tankID <<
+ " specified in engine definition does not exist." << endl;
+ }
local_element = engine_element->GetParent()->FindNextElement("feed");
}
} else {
TrimMode = false;
FuelFlow_gph = 0.0;
FuelFlow_pph = 0.0;
+ FuelFlowRate = 0.0;
FuelFreeze = false;
}
double FGEngine::CalcFuelNeed(void)
{
- double dT = State->Getdt()*Propulsion->GetRate();
+ double dT = FDMExec->GetDeltaT()*Propulsion->GetRate();
FuelFlowRate = SLFuelFlowMax*PctPower;
FuelExpended = FuelFlowRate*dT;
return FuelExpended;
Thruster = new FGPropeller(FDMExec, document, EngineNumber);
} else if (thrType == "nozzle") {
Thruster = new FGNozzle(FDMExec, document, EngineNumber);
+ } else if (thrType == "rotor") {
+ Thruster = new FGRotor(FDMExec, document, EngineNumber);
} else if (thrType == "direct") {
Thruster = new FGThruster( FDMExec, document, EngineNumber);
}
- Thruster->SetdeltaT(State->Getdt() * Propulsion->GetRate());
+ Thruster->SetdeltaT(FDMExec->GetDeltaT() * Propulsion->GetRate());
Debug(2);
return true;
#include "FGJSBBase.h"
#include "input_output/FGXMLFileRead.h"
+#include "input_output/FGXMLElement.h"
+#include "models/FGFCS.h"
#include "math/FGColumnVector3.h"
#include <vector>
#include <string>
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_ENGINE "$Id$"
+#define ID_ENGINE "$Id: FGEngine.h,v 1.20 2010/02/25 05:21:36 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
class FGFDMExec;
-class FGState;
class FGAtmosphere;
-class FGFCS;
class FGAircraft;
class FGPropagate;
class FGPropulsion;
documentation for engine and thruster classes.
</pre>
@author Jon S. Berndt
- @version $Id$
+ @version $Id: FGEngine.h,v 1.20 2010/02/25 05:21:36 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
double FuelDensity;
FGFDMExec* FDMExec;
- FGState* State;
FGAtmosphere* Atmosphere;
FGFCS* FCS;
FGPropulsion* Propulsion;
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGForce.cpp,v 1.14 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_FORCE;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FORCE "$Id$"
+#define ID_FORCE "$Id: FGForce.h,v 1.13 2009/10/05 04:48:03 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
<br><br></p>
@author Tony Peden
- @version $Id$
+ @version $Id: FGForce.h,v 1.13 2009/10/05 04:48:03 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGNozzle.cpp,v 1.13 2009/10/26 03:49:58 jberndt Exp $";
static const char *IdHdr = ID_NOZZLE;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_NOZZLE "$Id$";
+#define ID_NOZZLE "$Id: FGNozzle.h,v 1.8 2009/10/26 03:49:58 jberndt Exp $";
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
All parameters MUST be specified.
@author Jon S. Berndt
- @version $Id$
+ @version $Id: FGNozzle.h,v 1.8 2009/10/26 03:49:58 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include <sstream>
#include "FGPiston.h"
-#include "FGState.h"
#include "models/FGAtmosphere.h"
+#include "models/FGAuxiliary.h"
#include "models/FGPropulsion.h"
#include "FGPropeller.h"
#include <iostream>
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGPiston.cpp,v 1.52 2010/06/05 12:12:34 jberndt Exp $";
static const char *IdHdr = ID_PISTON;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Defaults and initializations
Type = etPiston;
- dt = State->Getdt();
+ dt = FDMExec->GetDeltaT();
// These items are read from the configuration file
// Defaults are from a Lycoming O-360, more or less
Z_airbox = -999;
Ram_Air_Factor = 1;
PeakMeanPistonSpeed_fps = 100;
+ FMEPDynamic= 18400;
+ FMEPStatic = 46500;
+
// These are internal program variables
Z_airbox = el->FindElementValueAsNumber("air-intake-impedance-factor");
if (el->FindElement("ram-air-factor"))
Ram_Air_Factor = el->FindElementValueAsNumber("ram-air-factor");
+ if (el->FindElement("dynamic-fmep"))
+ FMEPDynamic= el->FindElementValueAsNumberConvertTo("dynamic-fmep","PA");
+ if (el->FindElement("static-fmep"))
+ FMEPStatic = el->FindElementValueAsNumberConvertTo("static-fmep","PA");
if (el->FindElement("peak-piston-speed"))
PeakMeanPistonSpeed_fps = el->FindElementValueAsNumber("peak-piston-speed");
if (el->FindElement("numboostspeeds")) { // Turbo- and super-charging parameters
// Create IFSC to match the engine if not provided
if (ISFC < 0) {
double pmep = 29.92 - MaxManifoldPressure_inHg;
- pmep *= inhgtopa;
- double fmep = (18400 * RatedMeanPistonSpeed_fps * fttom + 46500);
+ pmep *= inhgtopa * volumetric_efficiency;
+ double fmep = (FMEPDynamic * RatedMeanPistonSpeed_fps * fttom + FMEPStatic);
double hp_loss = ((pmep + fmep) * displacement_SI * MaxRPM)/(Cycles*22371);
ISFC = ( 1.1*Displacement * MaxRPM * volumetric_efficiency *(MaxManifoldPressure_inHg / 29.92) ) / (9411 * (MaxHP+hp_loss));
// cout <<"FMEP: "<< fmep <<" PMEP: "<< pmep << " hp_loss: " <<hp_loss <<endl;
* Where:
* Pm = Manifold Pressure
* Pa = Ambient Pressre
- * Ze = engine impedance, Ze is effectively 1 / Mean Piston Speed
+ * Ze = engine impedance, Ze is effectively 1 / Mean Piston Speed
* Zi = airbox impedance
* Zt = throttle impedance
- *
+ *
* For the calculation below throttle is fully open or Zt = 0
*
- *
+ *
*
*/
double Ze=PeakMeanPistonSpeed_fps/RatedMeanPistonSpeed_fps; // engine impedence
Z_airbox = (standard_pressure *Ze / maxMAP) - Ze; // impedence of airbox
}
- Z_throttle=(((MaxRPM * Stroke) / 360)/((IdleRPM * Stroke) / 360))*(standard_pressure/minMAP - 1) - Z_airbox; // Constant for Throttle impedence
+ // Constant for Throttle impedence
+ Z_throttle=(PeakMeanPistonSpeed_fps/((IdleRPM * Stroke) / 360))*(standard_pressure/minMAP - 1) - Z_airbox;
+ // Z_throttle=(MaxRPM/IdleRPM )*(standard_pressure/minMAP+2); // Constant for Throttle impedence
string property_name, base_property_name;
base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
double FGPiston::Calculate(void)
{
if (FuelFlow_gph > 0.0) ConsumeFuel();
Throttle = FCS->GetThrottlePos(EngineNumber);
- // calculate the throttle plate angle. 1 unit is approx pi/2 radians.
- ThrottleAngle = MinThrottle+((MaxThrottle-MinThrottle)*Throttle );
Mixture = FCS->GetMixturePos(EngineNumber);
//
double FGPiston::CalcFuelNeed(void)
{
- double dT = State->Getdt() * Propulsion->GetRate();
+ double dT = FDMExec->GetDeltaT() * Propulsion->GetRate();
FuelExpended = FuelFlowRate * dT;
return FuelExpended;
}
int FGPiston::InitRunning(void) {
Magnetos=3;
- //Thruster->SetRPM( 1.1*IdleRPM/Thruster->GetGearRatio() );
- Thruster->SetRPM( 1000 );
+ p_amb = Atmosphere->GetPressure() * psftopa;
+ double mix= p_amb / (101325.0*1.3);
+ FCS->SetMixturePos(EngineNumber, mix);
+ Thruster->SetRPM( 2.*IdleRPM/Thruster->GetGearRatio() );
+ //Thruster->SetRPM( 1000 );
Running=true;
+// cout <<"Set Running in FGPiston. RPM:" << Thruster->GetRPM()*Thruster->GetGearRatio() <<" Pressure:"<<p_amb<<" Mixture:"<< mix <<endl;
return 1;
}
// (spark, fuel, starter motor etc)
bool spark;
bool fuel;
-
// Check for spark
Magneto_Left = false;
Magneto_Right = false;
if(p_amb < BoostSwitchPressure[BoostSpeed] - BoostSwitchHysteresis) {
BoostSpeed++;
}
- } else if(BoostSpeed > 0) {
+ } if(BoostSpeed > 0) {
// Check if we need to change to a lower boost speed
if(p_amb > BoostSwitchPressure[BoostSpeed - 1] + BoostSwitchHysteresis) {
BoostSpeed--;
* from the throttle position, turbo/supercharger boost control
* system, engine speed and local ambient air density.
*
- * Inputs: p_amb, Throttle, ThrottleAngle,
+ * Inputs: p_amb, Throttle,
* MeanPistonSpeed_fps, dt
*
* Outputs: MAP, ManifoldPressure_inHg, TMAP
void FGPiston::doMAP(void)
{
- double Zt =(1-Throttle)*(1-Throttle)*Z_throttle; // throttle impedence
+ double Zt = (1-Throttle)*(1-Throttle)*Z_throttle; // throttle impedence
double Ze= MeanPistonSpeed_fps > 0 ? PeakMeanPistonSpeed_fps/MeanPistonSpeed_fps : 999999; // engine impedence
double map_coefficient = Ze/(Ze+Z_airbox+Zt);
// Find the mean effective pressure required to achieve this manifold pressure
// Fixme: determine the HP consumed by the supercharger
- PMEP = TMAP - p_amb; // Fixme: p_amb should be exhaust manifold pressure
+ PMEP = (TMAP - p_amb) * volumetric_efficiency; // Fixme: p_amb should be exhaust manifold pressure
if (Boosted) {
// If takeoff boost is fitted, we currently assume the following throttle map:
* (used in CHT calculation for air-cooled engines).
*
* Inputs: p_amb, R_air, T_amb, MAP, Displacement,
- * RPM, volumetric_efficiency, ThrottleAngle
+ * RPM, volumetric_efficiency,
*
* TODO: Model inlet manifold air temperature.
*
void FGPiston::doAirFlow(void)
{
- double gamma = 1.1; // specific heat constants
+ double gamma = 1.3; // specific heat constants
// loss of volumentric efficiency due to difference between MAP and exhaust pressure
- double ve =((gamma-1)/gamma)+( CompressionRatio -(p_amb/MAP))/(gamma*( CompressionRatio - 1));
+// Eq 6-10 from The Internal Combustion Engine - Charles Taylor Vol 1
+ double ve =((gamma-1)/gamma) +( CompressionRatio -(p_amb/MAP))/(gamma*( CompressionRatio - 1));
rho_air = p_amb / (R_air * T_amb);
double swept_volume = (displacement_SI * (RPM/60)) / 2;
/**
* Calculate the power produced by the engine.
*
- * Currently, the JSBSim propellor model does not allow the
- * engine to produce enough RPMs to get up to a high horsepower.
- * When tested with sufficient RPM, it has no trouble reaching
- * 200HP.
- *
- * Inputs: ManifoldPressure_inHg, p_amb, RPM, T_amb,
+ * Inputs: ManifoldPressure_inHg, p_amb, RPM, T_amb, ISFC,
* Mixture_Efficiency_Correlation, Cycles, MaxHP, PMEP,
+ * MeanPistonSpeed_fps
*
- * Outputs: PctPower, HP
+ * Outputs: PctPower, HP, FMEP, IndicatedHorsePower
*/
void FGPiston::doEnginePower(void)
ME = Mixture_Efficiency_Correlation->GetValue(m_dot_fuel/m_dot_air);
percent_RPM = RPM/MaxRPM;
-// Guestimate engine friction as a percentage of rated HP + a percentage of rpm + a percentage of Indicted HP
-// friction = 1 - (percent_RPM * percent_RPM * percent_RPM/10);
- FMEP = (-18400 * MeanPistonSpeed_fps * fttom - 46500);
+// Guestimate engine friction losses from Figure 4.4 of "Engines: An Introduction", John Lumley
+ FMEP = (-FMEPDynamic * MeanPistonSpeed_fps * fttom - FMEPStatic);
power = 1;
double h2 = -3.95;
double h3 = -140.0; // -0.05 * 2800 (default maxrpm)
- double arbitary_area = 1.0;
+ double arbitary_area = Displacement/360.0;
double CpCylinderHead = 800.0;
double MassCylinderHead = 8.0;
if (OilPressure_psi > 5.0 ) {
time_constant = 5000 / OilPressure_psi; // Guess at a time constant for circulated oil.
// The higher the pressure the faster it reaches
- // target temperature. Oil pressure should be about
- // 60 PSI yielding a TC of about 80.
+ // target temperature. Oil pressure should be about
+ // 60 PSI yielding a TC of about 80.
} else {
time_constant = 1000; // Time constant for engine-off; reflects the fact
// that oil is no longer getting circulated
cout << " Cycles: " << Cycles << endl;
cout << " IdleRPM: " << IdleRPM << endl;
cout << " MaxRPM: " << MaxRPM << endl;
- cout << " MaxThrottle: " << MaxThrottle << endl;
- cout << " MinThrottle: " << MinThrottle << endl;
+ cout << " Throttle Constant: " << Z_throttle << endl;
cout << " ISFC: " << ISFC << endl;
cout << " Volumetric Efficiency: " << volumetric_efficiency << endl;
cout << " PeakMeanPistonSpeed_fps: " << PeakMeanPistonSpeed_fps << endl;
cout << " Intake Impedance Factor: " << Z_airbox << endl;
+ cout << " Dynamic FMEP Factor: " << FMEPDynamic << endl;
+ cout << " Static FMEP Factor: " << FMEPStatic << endl;
cout << endl;
cout << " Combustion Efficiency table:" << endl;
#include "FGEngine.h"
#include "math/FGTable.h"
-#include "input_output/FGXMLElement.h"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_PISTON "$Id$";
+#define ID_PISTON "$Id: FGPiston.h,v 1.23 2010/02/25 05:21:36 jberndt Exp $";
#define FG_MAX_BOOST_SPEEDS 3
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@code
<piston_engine name="{string}">
- <minmp unit="{INHG | PA | ATM}"> {number} </minmp> <!-- Depricated -->
+ <minmp unit="{INHG | PA | ATM}"> {number} </minmp>
<maxmp unit="{INHG | PA | ATM}"> {number} </maxmp>
<displacement unit="{IN3 | LTR | CC}"> {number} </displacement>
<bore unit="{IN | M}"> {number} </bore>
<minthrottle> {number} </minthrottle>
<bsfc unit="{LBS/HP*HR | "KG/KW*HR"}"> {number} </bsfc>
<volumetric-efficiency> {number} </volumetric-efficiency>
+ <dynamic-fmep unit="{INHG | PA | ATM}"> {number} </dynamic-fmep>
+ <static-fmep unit="{INHG | PA | ATM}"> {number} </static-fmep>
<numboostspeeds> {number} </numboostspeeds>
<boostoverride> {0 | 1} </boostoverride>
<boostmanual> {0 | 1} </boostmanual>
@author Dave Luff (engine operational code)
@author David Megginson (initial porting and additional code)
@author Ron Jensen (additional engine code)
- @version $Id$
+ @version $Id: FGPiston.h,v 1.23 2010/02/25 05:21:36 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
double getRPM(void) {return RPM;}
protected:
- double ThrottleAngle;
private:
int crank_counter;
double IndicatedHorsePower;
double PMEP;
double FMEP;
- double SpeedSlope;
- double SpeedIntercept;
- double AltitudeSlope;
+ double FMEPDynamic;
+ double FMEPStatic;
double PowerAvailable;
// timestep
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGPropeller.cpp,v 1.30 2010/05/02 15:10:07 jberndt Exp $";
static const char *IdHdr = ID_PROPELLER;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Reverse_coef = 0.0;
GearRatio = 1.0;
CtFactor = CpFactor = 1.0;
+ ConstantSpeed = 0;
+ cThrust = cPower = CtMach = CpMach = 0;
+ Vinduced = 0.0;
if (prop_element->FindElement("ixx"))
Ixx = prop_element->FindElementValueAsNumberConvertTo("ixx", "SLUG*FT2");
MaxPitch = prop_element->FindElementValueAsNumber("maxpitch");
if (prop_element->FindElement("minrpm"))
MinRPM = prop_element->FindElementValueAsNumber("minrpm");
- if (prop_element->FindElement("maxrpm"))
+ if (prop_element->FindElement("maxrpm")) {
MaxRPM = prop_element->FindElementValueAsNumber("maxrpm");
+ ConstantSpeed = 1;
+ }
+ if (prop_element->FindElement("constspeed"))
+ ConstantSpeed = (int)prop_element->FindElementValueAsNumber("constspeed");
if (prop_element->FindElement("reversepitch"))
ReversePitch = prop_element->FindElementValueAsNumber("reversepitch");
for (int i=0; i<2; i++) {
cThrust = new FGTable(PropertyManager, table_element);
} else if (name == "C_POWER") {
cPower = new FGTable(PropertyManager, table_element);
+ } else if (name == "CT_MACH") {
+ CtMach = new FGTable(PropertyManager, table_element);
+ } else if (name == "CP_MACH") {
+ CpMach = new FGTable(PropertyManager, table_element);
} else {
cerr << "Unknown table type: " << name << " in propeller definition." << endl;
}
vTorque.InitMatrix();
D4 = Diameter*Diameter*Diameter*Diameter;
D5 = D4*Diameter;
+ Pitch = MinPitch;
string property_name, base_property_name;
base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNum);
PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetThrustCoefficient );
property_name = base_property_name + "/propeller-rpm";
PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetRPM );
+ property_name = base_property_name + "/helical-tip-Mach";
+ PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetHelicalTipMach );
+ property_name = base_property_name + "/constant-speed-mode";
+ PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetConstantSpeed,
+ &FGPropeller::SetConstantSpeed );
+ property_name = base_property_name + "/prop-induced-velocity_fps";
+ PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetInducedVelocity,
+ &FGPropeller::SetInducedVelocity );
Debug(0);
}
{
delete cThrust;
delete cPower;
+ delete CtMach;
+ delete CpMach;
Debug(1);
}
double rho = fdmex->GetAtmosphere()->GetDensity();
double RPS = RPM/60.0;
- if (RPS > 0.00) J = Vel / (Diameter * RPS); // Calculate J normally
- else J = 1000.0; // Set J to a high number
+ // Calculate helical tip Mach
+ double Area = 0.25*Diameter*Diameter*M_PI;
+ double Vtip = RPS * Diameter * M_PI;
+ HelicalTipMach = sqrt(Vtip*Vtip + Vel*Vel) /
+ fdmex->GetAtmosphere()->GetSoundSpeed();
+
+ if (RPS > 0.0) J = Vel / (Diameter * RPS); // Calculate J normally
+ else J = Vel / Diameter;
- if (MaxPitch == MinPitch) ThrustCoeff = cThrust->GetValue(J);
- else ThrustCoeff = cThrust->GetValue(J, Pitch);
+ if (MaxPitch == MinPitch) { // Fixed pitch prop
+ ThrustCoeff = cThrust->GetValue(J);
+ } else { // Variable pitch prop
+ ThrustCoeff = cThrust->GetValue(J, Pitch);
+ }
+
+ // Apply optional scaling factor to Ct (default value = 1)
ThrustCoeff *= CtFactor;
+ // Apply optional Mach effects from CT_MACH table
+ if (CtMach) ThrustCoeff *= CtMach->GetValue(HelicalTipMach);
+
if (P_Factor > 0.0001) {
alpha = fdmex->GetAuxiliary()->Getalpha();
beta = fdmex->GetAuxiliary()->Getbeta();
}
Thrust = ThrustCoeff*RPS*RPS*D4*rho;
+
+ // From B. W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics"
+ // first edition, eqn. 6.15 (propeller analysis chapter).
+ Vinduced = 0.5 * (-Vel + sqrt(Vel*Vel + 2.0*Thrust/(rho*Area)));
+
omega = RPS*2.0*M_PI;
vFn(1) = Thrust;
vH(eY) = 0.0;
vH(eZ) = 0.0;
- if (omega > 0.0) ExcessTorque = GearRatio * PowerAvailable / omega;
- else ExcessTorque = GearRatio * PowerAvailable / 1.0;
+ if (omega > 0.0) ExcessTorque = PowerAvailable / omega;
+ else ExcessTorque = PowerAvailable / 1.0;
RPM = (RPS + ((ExcessTorque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
- if (RPM < 1.0) RPM = 0; // Engine friction stops rotation arbitrarily at 1 RPM.
+ if (RPM < 0.0) RPM = 0.0; // Engine won't turn backwards
// Transform Torque and momentum first, as PQR is used in this
// equation and cannot be transformed itself.
{
double cPReq, J;
double rho = fdmex->GetAtmosphere()->GetDensity();
+ double Vel = fdmex->GetAuxiliary()->GetAeroUVW(eU);
double RPS = RPM / 60.0;
- if (RPS != 0) J = fdmex->GetAuxiliary()->GetAeroUVW(eU) / (Diameter * RPS);
- else J = 1000.0; // Set J to a high number
+ if (RPS != 0.0) J = Vel / (Diameter * RPS);
+ else J = Vel / Diameter;
- if (MaxPitch == MinPitch) { // Fixed pitch prop
- Pitch = MinPitch;
+ if (MaxPitch == MinPitch) { // Fixed pitch prop
cPReq = cPower->GetValue(J);
+
} else { // Variable pitch prop
- if (MaxRPM != MinRPM) { // fixed-speed prop
+ if (ConstantSpeed != 0) { // Constant Speed Mode
// do normal calculation when propeller is neither feathered nor reversed
+ // Note: This method of feathering and reversing was added to support the
+ // turboprop model. It's left here for backward compatablity, but
+ // now feathering and reversing should be done in Manual Pitch Mode.
if (!Feathered) {
if (!Reversed) {
Pitch += (MaxPitch - Pitch) / 300; // just a guess (about 5 sec to fully feathered)
}
- } else { // Variable Speed Prop
- Pitch = MinPitch + (MaxPitch - MinPitch) * Advance;
+ } else { // Manual Pitch Mode, pitch is controlled externally
+
}
+
cPReq = cPower->GetValue(J, Pitch);
}
+
+ // Apply optional scaling factor to Cp (default value = 1)
cPReq *= CpFactor;
- if (RPS > 0) {
+ // Apply optional Mach effects from CP_MACH table
+ if (CpMach) cPReq *= CpMach->GetValue(HelicalTipMach);
+
+ if (RPS > 0.1) {
PowerRequired = cPReq*RPS*RPS*RPS*D5*rho;
vTorque(eX) = -Sense*PowerRequired / (RPS*2.0*M_PI);
} else {
- PowerRequired = 0.0;
- vTorque(eX) = 0.0;
+ // For a stationary prop we have to estimate torque first.
+ double CL = (90.0 - Pitch) / 20.0;
+ if (CL > 1.5) CL = 1.5;
+ double BladeArea = Diameter * Diameter / 32.0 * numBlades;
+ vTorque(eX) = -Sense*BladeArea*Diameter*Vel*Vel*rho*0.19*CL;
+ PowerRequired = vTorque(eX)*0.2*M_PI;
}
return PowerRequired;
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_PROPELLER "$Id$"
+#define ID_PROPELLER "$Id: FGPropeller.h,v 1.16 2010/04/09 12:44:06 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
<maxpitch> {number} </maxpitch>
<minrpm> {number} </minrpm>
<maxrpm> {number} </maxrpm>
+ <constspeed> {number} </constspeed>
<reversepitch> {number} </reversepitch>
<sense> {1 | -1} </sense>
<p_factor> {number} </p_factor>
</tableData>
</table>
+ <table name="CT_MACH" type="internal">
+ <tableData>
+ {numbers}
+ </tableData>
+ </table>
+
+ <table name="CP_MACH" type="internal">
+ <tableData>
+ {numbers}
+ </tableData>
+ </table>
+
+
</propeller>
@endcode
\<maxpitch> - Maximum blade pitch angle.
\<minrpm> - Minimum rpm target for constant speed propeller.
\<maxrpm> - Maximum rpm target for constant speed propeller.
+ \<constspeed> - 1 = constant speed mode, 0 = manual pitch mode.
\<reversepitch> - Blade pitch angle for reverse.
\<sense> - Direction of rotation (1=clockwise as viewed from cockpit,
-1=anti-clockwise as viewed from cockpit).
</pre>
Two tables are needed. One for coefficient of thrust (Ct) and one for
- coefficient of power (Cp).
+ coefficient of power (Cp).
+
+ Two tables are optional. They apply a factor to Ct and Cp based on the
+ helical tip Mach.
<br>
Several references were helpful, here:<ul>
<li>Various NACA Technical Notes and Reports</li>
</ul>
@author Jon S. Berndt
- @version $Id$
+ @version $Id: FGPropeller.h,v 1.16 2010/04/09 12:44:06 jberndt Exp $
@see FGEngine
@see FGThruster
*/
/// Sets the P-Factor constant
void SetPFactor(double pf) {P_Factor = pf;}
+ /// Sets propeller into constant speed mode, or manual pitch mode
+ void SetConstantSpeed(int mode) {ConstantSpeed = mode;}
+
/// Sets coefficient of thrust multiplier
void SetCtFactor(double ctf) {CtFactor = ctf;}
/// Retrieves propeller power table
FGTable* GetCPowerTable(void) const { return cPower; }
+ /// Retrieves propeller thrust Mach effects factor
+ FGTable* GetCtMachTable(void) const { return CtMach; }
+ /// Retrieves propeller power Mach effects factor
+ FGTable* GetCpMachTable(void) const { return CpMach; }
+
/// Retrieves the Torque in foot-pounds (Don't you love the English system?)
double GetTorque(void) { return vTorque(eX); }
void SetFeather (bool f) { Feathered = f; }
bool GetFeather (void) { return Feathered; }
double GetThrustCoefficient(void) const {return ThrustCoeff;}
+ double GetHelicalTipMach(void) const {return HelicalTipMach;}
+ int GetConstantSpeed(void) const {return ConstantSpeed;}
+ void SetInducedVelocity(double Vi) {Vinduced = Vi;}
+ double GetInducedVelocity(void) const {return Vinduced;}
private:
int numBlades;
double ExcessTorque;
double D4;
double D5;
+ double HelicalTipMach;
+ double Vinduced;
FGColumnVector3 vTorque;
FGTable *cThrust;
FGTable *cPower;
+ FGTable *CtMach;
+ FGTable *CpMach;
double CtFactor;
double CpFactor;
+ int ConstantSpeed;
void Debug(int from);
double ReversePitch; // Pitch, when fully reversed
- bool Reversed; // true, when propeller is reversed
+ bool Reversed; // true, when propeller is reversed
double Reverse_coef; // 0 - 1 defines AdvancePitch (0=MIN_PITCH 1=REVERSE_PITCH)
bool Feathered; // true, if feather command
};
#include <iostream>
#include <sstream>
#include "FGRocket.h"
-#include "FGState.h"
#include "models/FGPropulsion.h"
#include "FGThruster.h"
#include "FGTank.h"
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGRocket.cpp,v 1.19 2010/02/25 05:21:36 jberndt Exp $";
static const char *IdHdr = ID_ROCKET;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
previousFuelNeedPerTank = 0.0;
previousOxiNeedPerTank = 0.0;
PropellantFlowRate = 0.0;
- FuelFlowRate = 0.0;
- OxidizerFlowRate = 0.0;
- SLOxiFlowMax = 0.0;
+ FuelFlowRate = FuelExpended = 0.0;
+ OxidizerFlowRate = OxidizerExpended = 0.0;
+ SLOxiFlowMax = SLFuelFlowMax = 0.0;
BuildupTime = 0.0;
It = 0.0;
ThrustVariation = 0.0;
double FGRocket::Calculate(void)
{
- double dT = State->Getdt()*Propulsion->GetRate();
+ double dT = FDMExec->GetDeltaT()*Propulsion->GetRate();
double thrust;
if (!Flameout && !Starved) ConsumeFuel();
VacThrust *= sin((BurnTime/BuildupTime)*M_PI/2.0);
// VacThrust *= (1-cos((BurnTime/BuildupTime)*M_PI))/2.0; // 1 - cos approach
}
- BurnTime += State->Getdt(); // Increment burn time
+ BurnTime += FDMExec->GetDeltaT(); // Increment burn time
} else {
VacThrust = 0.0;
}
// a solid rocket is being modeled.
for (i=0; i<SourceTanks.size(); i++) {
- Tank = Propulsion->GetTank(SourceTanks[i]);
+ Tank = Propulsion->GetTank(i);
switch(Tank->GetType()) {
case FGTank::ttFUEL:
- if (Tank->GetContents() > 0.0 && Tank->GetSelected()) ++TanksWithFuel;
+ if (Tank->GetContents() > 0.0 && Tank->GetSelected() && SourceTanks[i] > 0) ++TanksWithFuel;
break;
case FGTank::ttOXIDIZER:
- haveOxTanks = true;
- if (Tank->GetContents() > 0.0 && Tank->GetSelected()) ++TanksWithOxidizer;
+ if (Tank->GetContents() > 0.0 && Tank->GetSelected() && SourceTanks[i] > 0) {
+ haveOxTanks = true;
+ ++TanksWithOxidizer;
+ }
break;
}
}
// Expend fuel from the engine's tanks if the tank is selected as a source
// for this engine.
- double fuelNeedPerTank = CalcFuelNeed()/TanksWithFuel;
- double oxiNeedPerTank = CalcOxidizerNeed()/TanksWithOxidizer;
+ double fuelNeedPerTank = 0;
+ double oxiNeedPerTank = 0;
+
+ if (TanksWithFuel > 0) fuelNeedPerTank = CalcFuelNeed()/TanksWithFuel;
+ if (TanksWithOxidizer > 0) oxiNeedPerTank = CalcOxidizerNeed()/TanksWithOxidizer;
for (i=0; i<SourceTanks.size(); i++) {
- Tank = Propulsion->GetTank(SourceTanks[i]);
- if ( ! Tank->GetSelected()) continue; // If this tank is not selected as a source, skip it.
+ Tank = Propulsion->GetTank(i);
+ if ( ! Tank->GetSelected() || SourceTanks[i] == 0) continue; // If this tank is not selected as a source, skip it.
switch(Tank->GetType()) {
case FGTank::ttFUEL:
Fshortage += Tank->Drain(2.0*fuelNeedPerTank - previousFuelNeedPerTank);
double FGRocket::CalcFuelNeed(void)
{
- double dT = State->Getdt()*Propulsion->GetRate();
+ double dT = FDMExec->GetDeltaT()*Propulsion->GetRate();
if (ThrustTable != 0L) { // Thrust table given - infers solid fuel
FuelFlowRate = VacThrust/Isp; // This calculates wdot (weight flow rate in lbs/sec)
double FGRocket::CalcOxidizerNeed(void)
{
- double dT = State->Getdt()*Propulsion->GetRate();
+ double dT = FDMExec->GetDeltaT()*Propulsion->GetRate();
OxidizerFlowRate = SLOxiFlowMax*PctPower;
OxidizerExpended = OxidizerFlowRate*dT;
return OxidizerExpended;
cout << " Minimum Throttle = " << MinThrottle << endl;
cout << " Fuel Flow (max) = " << SLFuelFlowMax << endl;
cout << " Oxidizer Flow (max) = " << SLOxiFlowMax << endl;
- cout << " Mixture ratio = " << SLOxiFlowMax/SLFuelFlowMax << endl;
+ if (SLFuelFlowMax > 0)
+ cout << " Mixture ratio = " << SLOxiFlowMax/SLFuelFlowMax << endl;
}
}
if (debug_lvl & 2 ) { // Instantiation/Destruction notification
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_ROCKET "$Id$"
+#define ID_ROCKET "$Id: FGRocket.h,v 1.12 2009/11/08 02:24:17 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
fuel begins burning and thrust is provided.
@author Jon S. Berndt
- $Id$
+ $Id: FGRocket.h,v 1.12 2009/11/08 02:24:17 jberndt Exp $
@see FGNozzle,
FGThruster,
FGForce,
Date started: 08/24/00
Purpose: Encapsulates the rotor object
- ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) -------------
+ ------------- Copyright (C) 2000 Jon S. Berndt (jsb@hal-pc.org) -------------
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
HISTORY
--------------------------------------------------------------------------------
08/24/00 JSB Created
+01/01/10 T.Kreitler test implementation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#include "FGRotor.h"
#include <iostream>
+#include <sstream>
+
+#include "FGRotor.h"
+
+#include "models/FGPropagate.h"
+#include "models/FGAtmosphere.h"
+#include "models/FGAuxiliary.h"
+#include "models/FGMassBalance.h"
+
+#include "input_output/FGXMLElement.h"
+
+#include "math/FGRungeKutta.h"
using namespace std;
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGRotor.cpp,v 1.9 2010/06/05 12:12:34 jberndt Exp $";
static const char *IdHdr = ID_ROTOR;
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+MISC
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+static int dump_req; // debug schwafel flag
+
+static inline double sqr(double x) { return x*x; }
+
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+// starting with 'inner' rotor, FGRotor constructor is further down
+
+FGRotor::rotor::~rotor() { }
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// hmm, not a real alternative to a pretty long initializer list
+
+void FGRotor::rotor::zero() {
+ FGColumnVector3 zero_vec(0.0, 0.0, 0.0);
+
+ flags = 0;
+ parent = NULL ;
+
+ reports = 0;
+
+ // configuration
+ Radius = 0.0 ;
+ BladeNum = 0 ;
+ RelDistance_xhub = 0.0 ;
+ RelShift_yhub = 0.0 ;
+ RelHeight_zhub = 0.0 ;
+ NominalRPM = 0.0 ;
+ MinRPM = 0.0 ;
+ BladeChord = 0.0 ;
+ LiftCurveSlope = 0.0 ;
+ BladeFlappingMoment = 0.0 ;
+ BladeTwist = 0.0 ;
+ BladeMassMoment = 0.0 ;
+ TipLossB = 0.0 ;
+ PolarMoment = 0.0 ;
+ InflowLag = 0.0 ;
+ ShaftTilt = 0.0 ;
+ HingeOffset = 0.0 ;
+ HingeOffset_hover = 0.0 ;
+ CantAngleD3 = 0.0 ;
+
+ theta_shaft = 0.0 ;
+ phi_shaft = 0.0 ;
+
+ // derived parameters
+ LockNumberByRho = 0.0 ;
+ solidity = 0.0 ;
+ RpmRatio = 0.0 ;
-FGRotor::FGRotor(FGFDMExec *FDMExec, Element* rotor_element, int num)
- : FGThruster(FDMExec, rotor_element, num)
+ for (int i=0; i<5; i++) R[i] = 0.0;
+ for (int i=0; i<6; i++) B[i] = 0.0;
+
+ BodyToShaft.InitMatrix();
+ ShaftToBody.InitMatrix();
+
+ // dynamic values
+ ActualRPM = 0.0 ;
+ Omega = 0.0 ;
+ beta_orient = 0.0 ;
+ a0 = 0.0 ;
+ a_1 = b_1 = a_dw = 0.0 ;
+ a1s = b1s = 0.0 ;
+ H_drag = J_side = 0.0 ;
+
+ Torque = 0.0 ;
+ Thrust = 0.0 ;
+ Ct = 0.0 ;
+ lambda = 0.0 ;
+ mu = 0.0 ;
+ nu = 0.0 ;
+ v_induced = 0.0 ;
+
+ force = zero_vec ;
+ moment = zero_vec ;
+
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// 5in1: value-fetch-convert-default-return function
+
+double FGRotor::rotor::cnf_elem( const string& ename, double default_val,
+ const string& unit, bool tell)
{
- Debug(0);
+
+ Element *e = NULL;
+ double val=default_val;
+
+ std::string pname = "*No parent element*";
+
+ if (parent) {
+ e = parent->FindElement(ename);
+ pname = parent->GetName();
+ }
+
+ if (e) {
+ if (unit.empty()) {
+ // val = e->FindElementValueAsNumber(ename);
+ // yields to: Attempting to get single data value from multiple lines
+ val = parent->FindElementValueAsNumber(ename);
+ } else {
+ // val = e->FindElementValueAsNumberConvertTo(ename,unit);
+ // yields to: Attempting to get non-existent element diameter + crash, why ?
+ val = parent->FindElementValueAsNumberConvertTo(ename,unit);
+ }
+ } else {
+ if (tell) {
+ cerr << pname << ": missing element '" << ename <<"' using estimated value: " << default_val << endl;
+ }
+ }
+
+ return val;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGRotor::rotor::cnf_elem(const string& ename, double default_val, bool tell)
+{
+ return cnf_elem(ename, default_val, "", tell);
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// 1. read configuration and try to fill holes, ymmv
+// 2. calculate derived parameters and transforms
+void FGRotor::rotor::configure(int f, const rotor *xmain)
+{
+
+ double estimate;
+ const bool yell = true;
+ const bool silent = false;
+
+ flags = f;
+
+ estimate = (xmain) ? 2.0 * xmain->Radius * 0.2 : 42.0;
+ Radius = 0.5 * cnf_elem("diameter", estimate, "FT", yell);
+
+ estimate = (xmain) ? xmain->BladeNum : 2.0;
+ estimate = Constrain(1.0,estimate,4.0);
+ BladeNum = (int) cnf_elem("numblades", estimate, yell);
+
+ estimate = (xmain) ? - xmain->Radius * 1.05 - Radius : - 0.025 * Radius ;
+ RelDistance_xhub = cnf_elem("xhub", estimate, "FT", yell);
+
+ RelShift_yhub = cnf_elem("yhub", 0.0, "FT", silent);
+
+ estimate = - 0.1 * Radius - 4.0;
+ RelHeight_zhub = cnf_elem("zhub", estimate, "FT", yell);
+
+ // make sure that v_tip (omega*r) is below 0.7mach ~ 750ft/s
+ estimate = (750.0/Radius)/(2.0*M_PI) * 60.0; // 7160/Radius
+ NominalRPM = cnf_elem("nominalrpm", estimate, yell);
+
+ MinRPM = cnf_elem("minrpm", 1.0, silent);
+ MinRPM = Constrain(1.0, MinRPM, NominalRPM-1.0);
+
+ estimate = (xmain) ? 0.12 : 0.07; // guess solidity
+ estimate = estimate * M_PI*Radius/BladeNum;
+ BladeChord = cnf_elem("chord", estimate, "FT", yell);
+
+ LiftCurveSlope = cnf_elem("liftcurveslope", 6.0, yell); // "1/RAD"
+
+ estimate = sqr(BladeChord) * sqr(Radius) * 0.57;
+ BladeFlappingMoment = cnf_elem("flappingmoment", estimate, "SLUG*FT2", yell);
+ BladeFlappingMoment = Constrain(0.1, BladeFlappingMoment, 1e9);
+
+ BladeTwist = cnf_elem("twist", -0.17, "RAD", yell);
+
+ estimate = sqr(BladeChord) * BladeChord * 15.66; // might be really wrong!
+ BladeMassMoment = cnf_elem("massmoment", estimate, yell); // slug-ft
+ BladeMassMoment = Constrain(0.1, BladeMassMoment, 1e9);
+
+ TipLossB = cnf_elem("tiplossfactor", 0.98, silent);
+
+ estimate = 1.1 * BladeFlappingMoment * BladeNum;
+ PolarMoment = cnf_elem("polarmoment", estimate, "SLUG*FT2", silent);
+ PolarMoment = Constrain(0.1, PolarMoment, 1e9);
+
+ InflowLag = cnf_elem("inflowlag", 0.2, silent); // fixme, depends on size
+
+ estimate = (xmain) ? 0.0 : -0.06;
+ ShaftTilt = cnf_elem("shafttilt", estimate, "RAD", silent);
+
+ // ignore differences between teeter/hingeless/fully-articulated constructions
+ estimate = 0.05 * Radius;
+ HingeOffset = cnf_elem("hingeoffset", estimate, "FT", (xmain) ? silent : yell);
+
+ CantAngleD3 = cnf_elem("cantangle", 0.0, "RAD", silent);
+
+ // derived parameters
+
+ // precalc often used powers
+ R[0]=1.0; R[1]=Radius; R[2]=R[1]*R[1]; R[3]=R[2]*R[1]; R[4]=R[3]*R[1];
+ B[0]=1.0; B[1]=TipLossB; B[2]=B[1]*B[1]; B[3]=B[2]*B[1]; B[4]=B[3]*B[1]; B[5]=B[4]*B[1];
+
+ LockNumberByRho = LiftCurveSlope * BladeChord * R[4] / BladeFlappingMoment;
+ solidity = BladeNum * BladeChord / (M_PI * Radius);
+
+ // use simple orientations at the moment
+ if (flags & eTail) { // axis parallel to Y_body
+ theta_shaft = 0.0; // no tilt
+ phi_shaft = 0.5*M_PI;
+
+ // opposite direction if main rotor is spinning CW
+ if (xmain && (xmain->flags & eRotCW) ) {
+ phi_shaft = -phi_shaft;
+ }
+ } else { // more or less upright
+ theta_shaft = ShaftTilt;
+ phi_shaft = 0.0;
+ }
+
+ // setup Shaft-Body transforms, see /SH79/ eqn(17,18)
+ double st = sin(theta_shaft);
+ double ct = cos(theta_shaft);
+ double sp = sin(phi_shaft);
+ double cp = cos(phi_shaft);
+
+ ShaftToBody.InitMatrix( ct, st*sp, st*cp,
+ 0.0, cp, -sp,
+ -st, ct*sp, ct*cp );
+
+ BodyToShaft = ShaftToBody.Inverse();
+
+ // misc defaults
+ nu = 0.001; // help the flow solver by providing some moving molecules
+
+ return;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// calculate control-axes components of total airspeed at the hub.
+// sets rotor orientation angle (beta) as side effect. /SH79/ eqn(19-22)
+
+FGColumnVector3 FGRotor::rotor::hub_vel_body2ca( const FGColumnVector3 &uvw,
+ const FGColumnVector3 &pqr,
+ double a_ic, double b_ic)
+{
+
+ FGColumnVector3 v_r, v_shaft, v_w;
+ FGColumnVector3 pos(RelDistance_xhub,0.0,RelHeight_zhub);
+
+ v_r = uvw + pqr*pos;
+ v_shaft = BodyToShaft * v_r;
+
+ beta_orient = atan2(v_shaft(eV),v_shaft(eU));
+
+ v_w(eU) = v_shaft(eU)*cos(beta_orient) + v_shaft(eV)*sin(beta_orient);
+ v_w(eV) = 0.0;
+ v_w(eW) = v_shaft(eW) - b_ic*v_shaft(eU) - a_ic*v_shaft(eV);
+
+ return v_w;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// express fuselage angular velocity in control axes /SH79/ eqn(30,31)
+
+FGColumnVector3 FGRotor::rotor::fus_angvel_body2ca( const FGColumnVector3 &pqr)
+{
+ FGColumnVector3 av_s_fus, av_w_fus;
+
+ av_s_fus = BodyToShaft * pqr;
+
+ av_w_fus(eP)= av_s_fus(eP)*cos(beta_orient) + av_s_fus(eQ)*sin(beta_orient);
+ av_w_fus(eQ)= - av_s_fus(eP)*sin(beta_orient) + av_s_fus(eQ)*cos(beta_orient);
+ av_w_fus(eR)= av_s_fus(eR);
+
+ return av_w_fus;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// problem function passed to rk solver
+
+ double FGRotor::rotor::dnuFunction::pFunc(double x, double nu) {
+ double d_nu;
+ d_nu = k_sat * (ct_lambda * (k_wor - nu) + k_theta) /
+ (2.0 * sqrt( mu2 + sqr(k_wor - nu)) );
+ d_nu = d_nu * k_flowscale - nu;
+ return d_nu;
+ };
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+ // merge params to keep the equation short
+ void FGRotor::rotor::dnuFunction::update_params(rotor *r, double ct_t01, double fs, double w) {
+ k_sat = 0.5* r->solidity * r->LiftCurveSlope;
+ ct_lambda = 1.0/2.0*r->B[2] + 1.0/4.0 * r->mu*r->mu;
+ k_wor = w/(r->Omega*r->Radius);
+ k_theta = ct_t01;
+ mu2 = r->mu * r->mu;
+ k_flowscale = fs;
+ };
+
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// Calculate rotor thrust and inflow-ratio (lambda), this is achieved by
+// approximating a solution for the differential equation:
+//
+// dnu/dt = 1/tau ( Ct / (2*sqrt(mu^2+lambda^2)) - nu ) , /SH79/ eqn(26).
+//
+// Propper calculation of the inflow-ratio (lambda) is vital for the
+// following calculations. Simple implementations (i.e. Newton-Raphson w/o
+// checking) tend to oscillate or overshoot in the low speed region,
+// therefore a more expensive solver is used.
+//
+// The flow_scale parameter is used to approximate a reduction of inflow
+// if the helicopter is close to the ground, yielding to higher thrust,
+// see /TA77/ eqn(10a). Doing the ground effect calculation here seems
+// more favorable then to code it in the fdm_config.
+
+void FGRotor::rotor::calc_flow_and_thrust(
+ double dt, double rho, double theta_0,
+ double Uw, double Ww, double flow_scale)
+{
+
+ double ct_over_sigma = 0.0;
+ double ct_l, ct_t0, ct_t1;
+ double nu_ret = 0.0;
+
+ mu = Uw/(Omega*Radius); // /SH79/ eqn(24)
+
+ ct_t0 = (1.0/3.0*B[3] + 1.0/2.0 * TipLossB*mu*mu - 4.0/(9.0*M_PI) * mu*mu*mu )*theta_0;
+ ct_t1 = (1.0/4.0*B[4] + 1.0/4.0 * B[2]*mu*mu)*BladeTwist;
+
+ // merge params together
+ flowEquation.update_params(this, ct_t0+ct_t1, flow_scale, Ww);
+
+ nu_ret = rk.evolve(nu, &flowEquation);
+
+ if (rk.getStatus() != FGRungeKutta::eNoError) { // never observed so far
+ cerr << "# IEHHHH [" << flags << "]: Solver Error - resetting!" << endl;
+ rk.clearStatus();
+ nu_ret = nu; // use old value and keep fingers crossed.
+ }
+
+ // keep an eye on the solver, but be quiet after a hundred messages
+ if (reports < 100 && rk.getIterations()>6) {
+ cerr << "# LOOK [" << flags << "]: Solver took "
+ << rk.getIterations() << " rounds." << endl;
+ reports++;
+ if (reports==100) {
+ cerr << "# stopped babbling after 100 notifications." << endl;
+ }
+ }
+
+ // now from nu to lambda, Ct, and Thrust
+
+ nu = nu_ret;
+ lambda = Ww/(Omega*Radius) - nu; // /SH79/ eqn(25)
+
+ ct_l = (1.0/2.0*B[2] + 1.0/4.0 * mu*mu)*lambda;
+ ct_over_sigma = (LiftCurveSlope/2.0)*(ct_l + ct_t0 + ct_t1); // /SH79/ eqn(27)
+
+ Thrust = BladeNum*BladeChord*Radius*rho*sqr(Omega*Radius) * ct_over_sigma;
+
+ Ct = ct_over_sigma * solidity;
+ v_induced = nu * (Omega*Radius);
+
+ if (dump_req && (flags & eMain) ) {
+ printf("# mu %f : nu %f lambda %f vi %f\n", mu, nu, lambda, v_induced);
+ }
+
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// this is the most arcane part in the calculation chain the
+// constants used should be reverted to more general parameters.
+// otoh: it works also for smaller rotors, sigh!
+// See /SH79/ eqn(36), and /BA41/ for a richer set of equations.
+
+void FGRotor::rotor::calc_torque(double rho, double theta_0)
+{
+ double Qa0;
+ double cq_s_m[5], cq_over_sigma;
+ double l,m,t075; // shortcuts
+
+ t075 = theta_0 + 0.75 * BladeTwist;
+
+ m = mu;
+ l = lambda;
+
+ cq_s_m[0] = 0.00109 - 0.0036*l - 0.0027*t075 - 1.10*sqr(l) - 0.545*l*t075 + 0.122*sqr(t075);
+ cq_s_m[2] = ( 0.00109 - 0.0027*t075 - 3.13*sqr(l) - 6.35*l*t075 - 1.93*sqr(t075) ) * sqr(m);
+ cq_s_m[3] = - 0.133*l*t075 * sqr(m)*m;
+ cq_s_m[4] = ( - 0.976*sqr(l) - 6.38*l*t075 - 5.26*sqr(t075) ) * sqr(m)*sqr(m);
+
+ cq_over_sigma = cq_s_m[0] + cq_s_m[2] + cq_s_m[3] + cq_s_m[4];
+ // guess an a (LiftCurveSlope) is included in eqn above, so check if there is a large
+ // influence when a_'other-model'/ a_'ch54' diverts from 1.0.
+
+ Qa0 = BladeNum * BladeChord * R[2] * rho * sqr(Omega*Radius);
+
+// TODO: figure out how to handle negative cq_over_sigma/torque
+
+ Torque = Qa0 * cq_over_sigma;
+
+ return;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// The coning angle doesn't apply for teetering rotors, but calculating
+// doesn't hurt. /SH79/ eqn(29)
+
+void FGRotor::rotor::calc_coning_angle(double rho, double theta_0)
+{
+ double lock_gamma = LockNumberByRho * rho;
+
+ double a0_l = (1.0/6.0 * B[3] + 0.04 * mu*mu*mu) * lambda;
+ double a0_t0 = (1.0/8.0 * B[4] + 1.0/8.0 * B[2]*mu*mu) * theta_0;
+ double a0_t1 = (1.0/10.0 * B[5] + 1.0/12.0 * B[3]*mu*mu) * BladeTwist;
+ a0 = lock_gamma * ( a0_l + a0_t0 + a0_t1);
+ return;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// Flapping angles relative to control axes /SH79/ eqn(32)
+
+void FGRotor::rotor::calc_flapping_angles( double rho, double theta_0,
+ const FGColumnVector3 &pqr_fus_w)
+{
+ double lock_gamma = LockNumberByRho * rho;
+
+ double mu2_2B2 = sqr(mu)/(2.0*B[2]);
+ double t075 = theta_0 + 0.75 * BladeTwist; // common approximation for rectangular blades
+
+ a_1 = 1.0/(1.0 - mu2_2B2) * (
+ (2.0*lambda + (8.0/3.0)*t075)*mu
+ + pqr_fus_w(eP)/Omega
+ - 16.0 * pqr_fus_w(eQ)/(B[4]*lock_gamma*Omega)
+ );
+
+ b_1 = 1.0/(1.0 + mu2_2B2) * (
+ (4.0/3.0)*mu*a0
+ - pqr_fus_w(eQ)/Omega
+ - 16.0 * pqr_fus_w(eP)/(B[4]*lock_gamma*Omega)
+ );
+
+ // used in force calc
+ a_dw = 1.0/(1.0 - mu2_2B2) * (
+ (2.0*lambda + (8.0/3.0)*t075)*mu
+ - 24.0 * pqr_fus_w(eQ)/(B[4]*lock_gamma*Omega)
+ * ( 1.0 - ( 0.29 * t075 / (Ct/solidity) ) )
+ );
+
+ return;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// /SH79/ eqn(38,39)
+
+void FGRotor::rotor::calc_drag_and_side_forces(double rho, double theta_0)
+{
+ double cy_over_sigma ;
+ double t075 = theta_0 + 0.75 * BladeTwist;
+
+ H_drag = Thrust * a_dw;
+
+ cy_over_sigma = (
+ 0.75*b_1*lambda - 1.5*a0*mu*lambda + 0.25*a_1*b_1*mu
+ - a0*a_1*sqr(mu) + (1.0/6.0)*a0*a_1
+ - (0.75*mu*a0 - (1.0/3.0)*b_1 - 0.5*sqr(mu)*b_1)*t075
+ );
+ cy_over_sigma *= LiftCurveSlope/2.0;
+
+ J_side = BladeNum * BladeChord * Radius * rho * sqr(Omega*Radius) * cy_over_sigma;
+
+ return;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// transform rotor forces from control axes to shaft axes, and express
+// in body axes /SH79/ eqn(40,41)
+
+FGColumnVector3 FGRotor::rotor::body_forces(double a_ic, double b_ic)
+{
+ FGColumnVector3 F_s(
+ - H_drag*cos(beta_orient) - J_side*sin(beta_orient) + Thrust*b_ic,
+ - H_drag*sin(beta_orient) + J_side*cos(beta_orient) + Thrust*a_ic,
+ - Thrust);
+
+ if (dump_req && (flags & eMain) ) {
+ printf("# abß: % f % f % f\n", a_ic, b_ic, beta_orient );
+ printf("# HJT: % .2f % .2f % .2f\n", H_drag, J_side, Thrust );
+ printf("# F_s: % .2f % .2f % .2f\n", F_s(1), F_s(2), F_s(3) );
+ FGColumnVector3 F_h;
+ F_h = ShaftToBody * F_s;
+ printf("# F_h: % .2f % .2f % .2f\n", F_h(1), F_h(2), F_h(3) );
+ }
+
+ return ShaftToBody * F_s;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// rotational sense is handled here
+// still a todo: how to get propper values for 'BladeMassMoment'
+// here might be a good place to tweak hovering stability, check /AM50/.
+
+FGColumnVector3 FGRotor::rotor::body_moments(FGColumnVector3 F_h, double a_ic, double b_ic)
+{
+ FGColumnVector3 M_s, M_hub, M_h;
+
+ FGColumnVector3 h_pos(RelDistance_xhub, 0.0, RelHeight_zhub);
+
+ // vermutlich ein biege moment, bzw.widerstands moment ~ d^3
+ double M_w_tilde = 0.0 ;
+ double mf = 0.0 ;
+
+ M_w_tilde = BladeMassMoment;
+
+ // cyclic flapping relative to shaft axes /SH79/ eqn(43)
+ a1s = a_1*cos(beta_orient) + b_1*sin(beta_orient) - b_ic;
+ b1s = b_1*cos(beta_orient) - a_1*sin(beta_orient) + a_ic;
+
+ // mind this: no HingeOffset, no additional pitch/roll moments
+ mf = 0.5 * (HingeOffset+HingeOffset_hover) * BladeNum * Omega*Omega * M_w_tilde;
+ M_s(eL) = mf*b1s;
+ M_s(eM) = mf*a1s;
+ M_s(eN) = Torque;
+
+ if (flags & eRotCW) {
+ M_s(eN) = -M_s(eN);
+ }
+
+ if (flags & eCoaxial) {
+ M_s(eN) = 0.0;
+ }
+
+ M_hub = ShaftToBody * M_s;
+
+ M_h = M_hub + (h_pos * F_h);
+
+ return M_h;
}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// Constructor
+
+FGRotor::FGRotor(FGFDMExec *exec, Element* rotor_element, int num)
+ : FGThruster(exec, rotor_element, num)
+{
+
+ FGColumnVector3 location, orientation;
+ Element *thruster_element;
+
+ PropertyManager = fdmex->GetPropertyManager();
+ dt = fdmex->GetDeltaT();
+
+ /* apply defaults */
+
+ rho = 0.002356; // just a sane value
+
+ RPM = 0.0;
+ Sense = 1.0;
+ tailRotorPresent = false;
+
+ effective_tail_col = 0.001; // just a sane value
+
+ prop_inflow_ratio_lambda = 0.0;
+ prop_advance_ratio_mu = 0.0;
+ prop_inflow_ratio_induced_nu = 0.0;
+ prop_mr_torque = 0.0;
+ prop_thrust_coefficient = 0.0;
+ prop_coning_angle = 0.0;
+
+ prop_theta_downwash = prop_phi_downwash = 0.0;
+
+ hover_threshold = 0.0;
+ hover_scale = 0.0;
+
+ mr.zero();
+ tr.zero();
+
+ // debug stuff
+ prop_DumpFlag = 0;
+
+ /* configure */
+
+ Type = ttRotor;
+ SetTransformType(FGForce::tCustom);
+
+ // get data from parent and 'mount' the rotor system
+
+ thruster_element = rotor_element->GetParent()->FindElement("sense");
+ if (thruster_element) {
+ Sense = thruster_element->GetDataAsNumber() >= 0.0 ? 1.0: -1.0;
+ }
+
+ thruster_element = rotor_element->GetParent()->FindElement("location");
+ if (thruster_element) location = thruster_element->FindElementTripletConvertTo("IN");
+ else cerr << "No thruster location found." << endl;
+
+ thruster_element = rotor_element->GetParent()->FindElement("orient");
+ if (thruster_element) orientation = thruster_element->FindElementTripletConvertTo("RAD");
+ else cerr << "No thruster orientation found." << endl;
+
+ SetLocation(location);
+ SetAnglesToBody(orientation);
+
+ // get main rotor parameters
+ mr.parent = rotor_element;
+
+ int flags = eMain;
+
+ string a_val="";
+ a_val = rotor_element->GetAttributeValue("variant");
+ if ( a_val == "coaxial" ) {
+ flags += eCoaxial;
+ cerr << "# found 'coaxial' variant" << endl;
+ }
+
+ if (Sense<0.0) {
+ flags += eRotCW;
+ }
+
+ mr.configure(flags);
+
+ mr.rk.init(0,dt,6);
+
+ // get tail rotor parameters
+ tr.parent=rotor_element->FindElement("tailrotor");
+ if (tr.parent) {
+ tailRotorPresent = true;
+ } else {
+ tailRotorPresent = false;
+ cerr << "# No tailrotor found, assuming a single rotor." << endl;
+ }
+
+ if (tailRotorPresent) {
+ int flags = eTail;
+ if (Sense<0.0) {
+ flags += eRotCW;
+ }
+ tr.configure(flags, &mr);
+ tr.rk.init(0,dt,6);
+ tr.RpmRatio = tr.NominalRPM/mr.NominalRPM; // 'connect'
+ }
+
+ /* remaining parameters */
+
+ // ground effect
+ double c_ground_effect = 0.0; // uh1 ~ 0.28 , larger values increase the effect
+ ground_effect_exp = 0.0;
+ ground_effect_shift = 0.0;
+
+ if (rotor_element->FindElement("cgroundeffect"))
+ c_ground_effect = rotor_element->FindElementValueAsNumber("cgroundeffect");
+
+ if (rotor_element->FindElement("groundeffectshift"))
+ ground_effect_shift = rotor_element->FindElementValueAsNumberConvertTo("groundeffectshift","FT");
+
+ // prepare calculations, see /TA77/
+ if (c_ground_effect > 1e-5) {
+ ground_effect_exp = 1.0 / ( 2.0*mr.Radius * c_ground_effect );
+ } else {
+ ground_effect_exp = 0.0; // disable
+ }
+
+ // smooth out jumps in hagl reported, otherwise the ground effect
+ // calculation would cause jumps too. 1Hz seems sufficient.
+ damp_hagl = Filter(1.0,dt);
+
+
+ // misc, experimental
+ if (rotor_element->FindElement("hoverthreshold"))
+ hover_threshold = rotor_element->FindElementValueAsNumberConvertTo("hoverthreshold", "FT/SEC");
+
+ if (rotor_element->FindElement("hoverscale"))
+ hover_scale = rotor_element->FindElementValueAsNumber("hoverscale");
+
+ // enable import-export
+ bind();
+
+ // unused right now
+ prop_rotorbrake->setDoubleValue(0.0);
+ prop_freewheel_factor->setDoubleValue(1.0);
+
+ Debug(0);
+
+} // Constructor
+
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGRotor::~FGRotor()
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+// mea-culpa - the connection to the engine might be wrong, but the calling
+// convention appears to be 'variable' too.
+// piston call:
+// return Thruster->Calculate((Eng_HP * hptoftlbssec)-Thruster->GetPowerRequired());
+// turbine call:
+// Thrust = Thruster->Calculate(Thrust); // allow thruster to modify thrust (i.e. reversing)
+//
+// Here 'Calculate' takes thrust and estimates the power provided.
+
double FGRotor::Calculate(double PowerAvailable)
{
- return 0.0;
+ // controls
+ double A_IC; // lateral (roll) control in radians
+ double B_IC; // longitudinal (pitch) control in radians
+ double theta_col; // main rotor collective pitch in radians
+ double tail_col; // tail rotor collective in radians
+
+ // state
+ double h_agl_ft = 0.0;
+ double Vt ;
+
+ FGColumnVector3 UVW_h;
+ FGColumnVector3 PQR_h;
+
+ /* total vehicle velocity including wind effects in feet per second. */
+ Vt = fdmex->GetAuxiliary()->GetVt();
+
+ dt = fdmex->GetDeltaT(); // might be variable ?
+
+ dump_req = prop_DumpFlag;
+ prop_DumpFlag = 0;
+
+ // fetch often used values
+ rho = fdmex->GetAtmosphere()->GetDensity(); // slugs/ft^3.
+
+ UVW_h = fdmex->GetAuxiliary()->GetAeroUVW();
+ PQR_h = fdmex->GetAuxiliary()->GetAeroPQR();
+
+ // handle present RPM now, calc omega values.
+
+ if (RPM < mr.MinRPM) { // kludge, otherwise calculations go bananas
+ RPM = mr.MinRPM;
+ }
+
+ mr.ActualRPM = RPM;
+ mr.Omega = (RPM/60.0)*2.0*M_PI;
+
+ if (tailRotorPresent) {
+ tr.ActualRPM = RPM*tr.RpmRatio;
+ tr.Omega = (RPM*tr.RpmRatio/60.0)*2.0*M_PI;
+ }
+
+ // read control inputs
+
+ A_IC = prop_lateral_ctrl->getDoubleValue();
+ B_IC = prop_longitudinal_ctrl->getDoubleValue();
+ theta_col = prop_collective_ctrl->getDoubleValue();
+ tail_col = 0.0;
+ if (tailRotorPresent) {
+ tail_col = prop_antitorque_ctrl->getDoubleValue();
+ }
+
+
+ FGColumnVector3 vHub_ca = mr.hub_vel_body2ca(UVW_h,PQR_h,A_IC,B_IC);
+ FGColumnVector3 avFus_ca = mr.fus_angvel_body2ca(PQR_h);
+
+
+ h_agl_ft = fdmex->GetPropagate()->GetDistanceAGL();
+
+ double filtered_hagl;
+ filtered_hagl = damp_hagl.execute( h_agl_ft + ground_effect_shift );
+
+ // gnuplot> plot [-1:50] 1 - exp((-x/44)/.28)
+ double ge_factor = 1.0;
+ if (ground_effect_exp > 1e-5) {
+ ge_factor -= exp(-filtered_hagl*ground_effect_exp);
+ }
+ // clamp
+ if (ge_factor<0.5) ge_factor=0.5;
+
+ if (dump_req) {
+ printf("# GE h: %.3f (%.3f) f: %f\n", filtered_hagl, h_agl_ft + ground_effect_shift, ge_factor);
+ }
+
+
+ // EXPERIMENTAL: modify rotor for hover, see rotor::body_moments for the consequences
+ if (hover_threshold > 1e-5 && Vt < hover_threshold) {
+ double scale = 1.0 - Vt/hover_threshold;
+ mr.HingeOffset_hover = scale*hover_scale*mr.Radius;
+ } else {
+ mr.HingeOffset_hover = 0.0;
+ }
+
+ // all set, start calculations
+
+ /* MAIN ROTOR */
+
+ mr.calc_flow_and_thrust(dt, rho, theta_col, vHub_ca(eU), vHub_ca(eW), ge_factor);
+
+ prop_inflow_ratio_lambda = mr.lambda;
+ prop_advance_ratio_mu = mr.mu;
+ prop_inflow_ratio_induced_nu = mr.nu;
+ prop_thrust_coefficient = mr.Ct;
+
+ mr.calc_coning_angle(rho, theta_col);
+ prop_coning_angle = mr.a0;
+
+ mr.calc_torque(rho, theta_col);
+ prop_mr_torque = mr.Torque;
+
+ mr.calc_flapping_angles(rho, theta_col, avFus_ca);
+ mr.calc_drag_and_side_forces(rho, theta_col);
+
+ FGColumnVector3 F_h_mr = mr.body_forces(A_IC,B_IC);
+ FGColumnVector3 M_h_mr = mr.body_moments(F_h_mr, A_IC, B_IC);
+
+ // export downwash angles
+ // theta: positive for downwash moving from +z_h towards +x_h
+ // phi: positive for downwash moving from +z_h towards -y_h
+
+ prop_theta_downwash = atan2( - UVW_h(eU), mr.v_induced - UVW_h(eW));
+ prop_phi_downwash = atan2( UVW_h(eV), mr.v_induced - UVW_h(eW));
+
+ mr.force(eX) = F_h_mr(1);
+ mr.force(eY) = F_h_mr(2);
+ mr.force(eZ) = F_h_mr(3);
+
+ mr.moment(eL) = M_h_mr(1);
+ mr.moment(eM) = M_h_mr(2);
+ mr.moment(eN) = M_h_mr(3);
+
+ /* TAIL ROTOR */
+
+ FGColumnVector3 F_h_tr(0.0, 0.0, 0.0);
+ FGColumnVector3 M_h_tr(0.0, 0.0, 0.0);
+
+ if (tailRotorPresent) {
+ FGColumnVector3 vHub_ca_tr = tr.hub_vel_body2ca(UVW_h,PQR_h);
+ FGColumnVector3 avFus_ca_tr = tr.fus_angvel_body2ca(PQR_h);
+
+ tr.calc_flow_and_thrust(dt, rho, tail_col, vHub_ca_tr(eU), vHub_ca_tr(eW));
+ tr.calc_coning_angle(rho, tail_col);
+
+ // test code for cantered tail rotor, see if it has a notable effect. /SH79/ eqn(47)
+ if (fabs(tr.CantAngleD3)>1e-5) {
+ double tan_d3 = tan(tr.CantAngleD3);
+ double d_t0t;
+ double ca_dt = dt/12.0;
+ for (int i = 0; i<12; i++) {
+ d_t0t = 1/0.1*(tail_col - tr.a0 * tan_d3 - effective_tail_col);
+ effective_tail_col += d_t0t*ca_dt;
+ }
+ } else {
+ effective_tail_col = tail_col;
+ }
+
+ tr.calc_torque(rho, effective_tail_col);
+ tr.calc_flapping_angles(rho, effective_tail_col, avFus_ca_tr);
+ tr.calc_drag_and_side_forces(rho, effective_tail_col);
+
+ F_h_tr = tr.body_forces();
+ M_h_tr = tr.body_moments(F_h_tr);
+ }
+
+ tr.force(eX) = F_h_tr(1) ;
+ tr.force(eY) = F_h_tr(2) ;
+ tr.force(eZ) = F_h_tr(3) ;
+ tr.moment(eL) = M_h_tr(1) ;
+ tr.moment(eM) = M_h_tr(2) ;
+ tr.moment(eN) = M_h_tr(3) ;
+
+/*
+ TODO:
+ check negative mr.Torque conditions
+ freewheel factor: assure [0..1] just multiply with available power
+ rotorbrake: just steal from available power
+
+*/
+
+ // calculate new RPM, assuming a stiff connection between engine and rotor.
+
+ double engine_hp = PowerAvailable/2.24; // 'undo' force via the estimation factor used in aeromatic
+ double engine_torque = 550.0*engine_hp/mr.Omega;
+ double Omega_dot = (engine_torque - mr.Torque) / mr.PolarMoment;
+
+ RPM += ( Omega_dot * dt )/(2.0*M_PI) * 60.0;
+
+ if (0 && dump_req) {
+ printf("# SENSE : % d % d\n", mr.flags & eRotCW ? -1 : 1, tr.flags & eRotCW ? -1 : 1);
+ printf("# vi : % f % f\n", mr.v_induced, tr.v_induced);
+ printf("# a0 a1 b1 : % f % f % f\n", mr.a0, mr.a_1, mr.b_1 );
+ printf("# m forces : % f % f % f\n", mr.force(eX), mr.force(eY), mr.force(eZ) );
+ printf("# m moments : % f % f % f\n", mr.moment(eL), mr.moment(eM), mr.moment(eN) );
+ printf("# t forces : % f % f % f\n", tr.force(eX), tr.force(eY), tr.force(eZ) );
+ printf("# t moments : % f % f % f\n", tr.moment(eL), tr.moment(eM), tr.moment(eN) );
+ }
+
+ // finally set vFn & vMn
+ vFn = mr.force + tr.force;
+ vMn = mr.moment + tr.moment;
+
+ // and just lie here
+ Thrust = 0.0;
+
+ // return unmodified thrust to the turbine.
+ // :TK: As far as I can see the return value is unused.
+ return PowerAvailable;
+
+} // Calculate
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+// FGThruster does return 0.0 (the implicit direct thruster)
+// piston CALL: return Thruster->Calculate((Eng_HP * hptoftlbssec)-Thruster->GetPowerRequired());
+
+double FGRotor::GetPowerRequired(void)
+{
+ PowerRequired = 0.0;
+ return PowerRequired;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+bool FGRotor::bind(void) {
+
+ string property_name, base_property_name;
+ base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNum);
+
+ PropertyManager->Tie( base_property_name + "/rotor-rpm", this, &FGRotor::GetRPM );
+ PropertyManager->Tie( base_property_name + "/thrust-mr-lbs", &mr.Thrust );
+ PropertyManager->Tie( base_property_name + "/vi-mr-fps", &mr.v_induced );
+ PropertyManager->Tie( base_property_name + "/a0-mr-rad", &mr.a0 );
+ PropertyManager->Tie( base_property_name + "/a1-mr-rad", &mr.a1s ); // s means shaft axes
+ PropertyManager->Tie( base_property_name + "/b1-mr-rad", &mr.b1s );
+ PropertyManager->Tie( base_property_name + "/thrust-tr-lbs", &tr.Thrust );
+ PropertyManager->Tie( base_property_name + "/vi-tr-fps", &tr.v_induced );
+
+ // lambda
+ PropertyManager->Tie( base_property_name + "/inflow-ratio", &prop_inflow_ratio_lambda );
+ // mu
+ PropertyManager->Tie( base_property_name + "/advance-ratio", &prop_advance_ratio_mu );
+ // nu
+ PropertyManager->Tie( base_property_name + "/induced-inflow-ratio", &prop_inflow_ratio_induced_nu );
+
+ PropertyManager->Tie( base_property_name + "/torque-mr-lbsft", &prop_mr_torque );
+ PropertyManager->Tie( base_property_name + "/thrust-coefficient", &prop_thrust_coefficient );
+ PropertyManager->Tie( base_property_name + "/main-rotor-rpm", &mr.ActualRPM );
+ PropertyManager->Tie( base_property_name + "/tail-rotor-rpm", &tr.ActualRPM );
+
+ // position of the downwash
+ PropertyManager->Tie( base_property_name + "/theta-downwash-rad", &prop_theta_downwash );
+ PropertyManager->Tie( base_property_name + "/phi-downwash-rad", &prop_phi_downwash );
+
+ // nodes to use via get<xyz>Value
+ prop_collective_ctrl = PropertyManager->GetNode(base_property_name + "/collective-ctrl-rad",true);
+ prop_lateral_ctrl = PropertyManager->GetNode(base_property_name + "/lateral-ctrl-rad",true);
+ prop_longitudinal_ctrl = PropertyManager->GetNode(base_property_name + "/longitudinal-ctrl-rad",true);
+ prop_antitorque_ctrl = PropertyManager->GetNode(base_property_name + "/antitorque-ctrl-rad",true);
+
+ prop_rotorbrake = PropertyManager->GetNode(base_property_name + "/rotorbrake-hp", true);
+ prop_freewheel_factor = PropertyManager->GetNode(base_property_name + "/freewheel-factor", true);
+
+ PropertyManager->Tie( base_property_name + "/dump-flag", &prop_DumpFlag );
+
+ return true;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGRotor::GetThrusterLabels(int id, string delimeter)
{
- return "";
+
+ std::ostringstream buf;
+
+ buf << Name << " RPM (engine " << id << ")";
+
+ return buf.str();
+
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGRotor::GetThrusterValues(int id, string delimeter)
{
- return "";
+ std::ostringstream buf;
+
+ buf << RPM;
+
+ return buf.str();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (debug_lvl & 1) { // Standard console startup message output
if (from == 0) { // Constructor
-
+ cout << "\n Rotor Name: " << Name << endl;
}
}
if (debug_lvl & 2 ) { // Instantiation/Destruction notification
}
}
}
-}
+
+} // namespace JSBSim
+
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Header: FGRotor.h
- Author: Jon S. Berndt
+ Author: T. Kreitler
Date started: 08/24/00
- ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) -------------
+ ------------- Copyright (C) 2010 T. Kreitler -------------
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
HISTORY
--------------------------------------------------------------------------------
-08/24/00 JSB Created
+01/01/10 T.Kreitler test implementation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SENTRY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGThruster.h"
+#include "math/FGTable.h"
+#include "math/FGRungeKutta.h"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_ROTOR "$Id$"
+#define ID_ROTOR "$Id: FGRotor.h,v 1.6 2010/06/02 04:05:13 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
CLASS DOCUMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-/** Models a rotor (such as for a helicopter); NOT YET IMPLEMENTED.
+/** Models a rotor system. The default configuration consists of main and
+ tail rotor. A practical way to define the positions is to start with an
+ imaginary gear-box near the cg of the vehicle.
+
+ In this case the location in the thruster definition should be
+ approximately equal to the cg defined in the <tt>fdm_config/mass_balance</tt>
+ section. If the default orientation (roll=pitch=yaw=0) is used the
+ positions of the rotor hubs are now defined relative to the location
+ of the thruster (i.e. the cg-centered body coordinate system).
+
+
+<h3>Configuration File Format:</h3>
+@code
+<rotor name="{string}" variant="{string}">
+ <diameter unit="{LENGTH}"> {number} </diameter>
+ <numblades> {number} </numblades>
+ <xhub unit="{LENGTH}"> {number} </xhub>
+ <zhub unit="{LENGTH}"> {number} </zhub>
+ <nominalrpm> {number} </nominalrpm>
+ <minrpm> {number} </minrpm>
+ <chord unit="{LENGTH}"> {number} </chord>
+ <liftcurveslope Xunit="1/RAD"> {number} </liftcurveslope>
+ <flappingmoment unit="{MOMENT}"> {number} </flappingmoment>
+ <twist unit="{ANGLE}"> {number} </twist>
+ <massmoment Xunit="SLUG*FT"> {number} </massmoment>
+ <tiplossfactor> {number} </tiplossfactor>
+ <polarmoment unit="{MOMENT}"> {number}</polarmoment>
+ <inflowlag> {number} </inflowlag>
+ <shafttilt unit="{ANGLE}"> {number} </shafttilt>
+ <hingeoffset unit="{LENGTH}"> {number} </hingeoffset>
+ <tailrotor>
+ <diameter unit="{LENGTH}"> {number} </diameter>
+ <numblades> {number} </numblades>
+ <xhub unit="{LENGTH}">{number} </xhub>
+ <zhub unit="{LENGTH}">{number} </zhub>
+ <nominalrpm> {number} </nominalrpm>
+ <chord unit="{LENGTH}"> {number} </chord>
+ <liftcurveslope Xunit="1/RAD"> {number} </liftcurveslope>
+ <flappingmoment unit="{MOMENT}"> {number} </flappingmoment>
+ <twist unit="RAD"> {number} </twist>
+ <massmoment Xunit="SLUG*FT"> {number} </massmoment>
+ <tiplossfactor> {number} </tiplossfactor>
+ <inflowlag> {number} </inflowlag>
+ <hingeoffset unit="{LENGTH}"> {number} </hingeoffset>
+ <cantangle unit="{ANGLE}"> {number} </cantangle>
+ </tailrotor>
+ <cgroundeffect> {number} </cgroundeffect>
+ <groundeffectshift unit="{LENGTH}"> {number} </groundeffectshift>
+</rotor>
+
+// LENGTH means any of the supported units, same for ANGLE and MOMENT.
+// Xunit-attributes are a hint for currently unsupported units, so
+// values must be provided accordingly.
+
+@endcode
+
+<h3>Configuration Parameters:</h3>
+
+ Brief description and the symbol frequently found in the literature.
+
+<pre>
+ \<diameter> - Rotor disk diameter (R).
+ \<numblades> - Number of blades (b).
+ \<xhub> - Relative height in body coordinate system, thus usually negative.
+ \<zhub> - Relative distance in body coordinate system, close to zero
+ for main rotor, and usually negative for the tail rotor.
+ \<nominalrpm> - RPM at which the rotor usally operates.
+ \<minrpm> - Lowest RPM generated by the code, optional.
+ \<chord> - Blade chord, (c).
+ \<liftcurveslope> - Slope of curve of section lift against section angle of attack,
+ per rad (a).
+ \<flappingmoment> - Flapping moment of inertia (I_b).
+ \<twist> - Blade twist from root to tip, (theta_1).
+ \<massmoment> - Blade mass moment. (Biege/Widerstands-moment)
+ \<tiplossfactor> - Tip-loss factor. The Blade fraction that produces lift.
+ Value usually ranges between 0.95 - 1.0, optional (B).
+ \<polarmoment> - Moment of inertia for the whole rotor disk, optional.
+ \<inflowlag> - Rotor inflow time constant, sec.
+ \<shafttilt> - Orientation of the rotor shaft, negative angles define
+ a 'forward' tilt. Used by main rotor, optional.
+ \<hingeoffset> - Rotor flapping-hinge offset (e).
+
+ Experimental properties
+
+ \<cantangle> - Flapping hinge cantangle used by tail rotor, optional.
+ \<cgroundeffect> - Parameter for exponent in ground effect approximation. Value should
+ be in the range 0.2 - 0.35, 0.0 disables, optional.
+ \<groundeffectshift> - Further adjustment of ground effect.
+
+</pre>
+
+<h3>Notes:</h3>
+
+ The behavior of the rotor is controlled/influenced by 5 inputs.<ul>
+ <li> The power provided by the engine. This is handled by the regular engine controls.</li>
+ <li> The collective control input. This is read from the <tt>fdm</tt> property
+ <tt>propulsion/engine[x]/collective-ctrl-rad</tt>.</li>
+ <li> The lateral cyclic input. Read from
+ <tt>propulsion/engine[x]/lateral-ctrl-rad</tt>.</li>
+ <li> The longitudinal cyclic input. Read from
+ <tt>propulsion/engine[x]/longitudinal-ctrl-rad</tt>.</li>
+ <li> The tail collective (aka antitorque, aka pedal) control input. Read from
+ <tt>propulsion/engine[x]/antitorque-ctrl-rad</tt>.</li>
+
+ </ul>
+
+ In order to keep the rotor speed constant, use of a RPM-Governor system is encouraged.
+
+ It is possible to use different orientation/locations for the rotor system, but then xhub
+ and zhub are no longer aligned to the body frame and need proper recalculation.
+
+ To model a standalone main rotor just omit the <tailrotor/> element. If you provide
+ a plain <tailrotor/> element all tail rotor parameters are estimated.
+
+ The 'sense' parameter from the thruster is interpreted as follows, sense=1 means
+ counter clockwise rotation of the main rotor, as viewed from above. This is as a far
+ as I know more popular than clockwise rotation, which is defined by setting sense to
+ -1 (to be honest, I'm just 99.9% sure that the orientation is handled properly).
+
+ Concerning coaxial designs: By providing the 'variant' attribute with value 'coaxial'
+ a Kamov-style rotor is modeled - i.e. the rotor produces no torque.
+
+
+<h3>References:</h3>
+
+ <dl>
+ <dt>/SH79/</dt><dd>Shaugnessy, J. D., Deaux, Thomas N., and Yenni, Kenneth R.,
+ "Development and Validation of a Piloted Simulation of a
+ Helicopter and External Sling Load", NASA TP-1285, 1979.</dd>
+ <dt>/BA41/</dt><dd>Bailey,F.J.,Jr., "A Simplified Theoretical Method of Determining
+ the Characteristics of a Lifting Rotor in Forward Flight", NACA Rep.716, 1941.</dd>
+ <dt>/AM50/</dt><dd>Amer, Kenneth B.,"Theory of Helicopter Damping in Pitch or Roll and a
+ Comparison With Flight Measurements", NACA TN-2136, 1950.</dd>
+ <dt>/TA77/</dt><dd>Talbot, Peter D., Corliss, Lloyd D., "A Mathematical Force and Moment
+ Model of a UH-1H Helicopter for Flight Dynamics Simulations", NASA TM-73,254, 1977.</dd>
+ </dl>
+
+ @author Thomas Kreitler
+ @version $Id: FGRotor.h,v 1.6 2010/06/02 04:05:13 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
class FGRotor : public FGThruster {
+ enum eRotorFlags {eNone=0, eMain=1, eTail=2, eCoaxial=4, eRotCW=8} ;
+ struct rotor {
+
+ virtual ~rotor();
+ void zero();
+ void configure(int f, const rotor *xmain = NULL);
+
+ // assist in parameter retrieval
+ double cnf_elem(const string& ename, double default_val=0.0, const string& unit = "", bool tell=false);
+ double cnf_elem(const string& ename, double default_val=0.0, bool tell=false);
+
+ // rotor dynamics
+ void calc_flow_and_thrust(double dt, double rho, double theta_0, double Uw, double Ww, double flow_scale = 1.0);
+
+ void calc_torque(double rho, double theta_0);
+ void calc_coning_angle(double rho, double theta_0);
+ void calc_flapping_angles(double rho, double theta_0, const FGColumnVector3 &pqr_fus_w);
+ void calc_drag_and_side_forces(double rho, double theta_0);
+
+ // transformations
+ FGColumnVector3 hub_vel_body2ca( const FGColumnVector3 &uvw, const FGColumnVector3 &pqr,
+ double a_ic = 0.0 , double b_ic = 0.0 );
+ FGColumnVector3 fus_angvel_body2ca( const FGColumnVector3 &pqr);
+
+ FGColumnVector3 body_forces(double a_ic = 0.0 , double b_ic = 0.0 );
+ FGColumnVector3 body_moments(FGColumnVector3 F_h, double a_ic = 0.0 , double b_ic = 0.0 );
+
+ // bookkeeping
+ int flags ;
+ Element *parent ;
+
+ // used in flow calculation
+ // FGRK4 rk ; // use this after checking
+ FGRKFehlberg rk ;
+ int reports ;
+
+ // configuration parameters
+ double Radius ;
+ int BladeNum ;
+ double RelDistance_xhub ;
+ double RelShift_yhub ;
+ double RelHeight_zhub ;
+ double NominalRPM ;
+ double MinRPM ;
+ double BladeChord ;
+ double LiftCurveSlope ;
+ double BladeFlappingMoment ;
+ double BladeTwist ;
+ double BladeMassMoment ;
+ double TipLossB ;
+ double PolarMoment ;
+ double InflowLag ;
+ double ShaftTilt ;
+ double HingeOffset ;
+ double HingeOffset_hover ;
+ double CantAngleD3 ;
+
+ double theta_shaft ;
+ double phi_shaft ;
+
+ // derived parameters
+ double LockNumberByRho ;
+ double solidity ; // aka sigma
+ double RpmRatio ; // main_to_tail, hmm
+ double R[5] ; // Radius powers
+ double B[6] ; // TipLossB powers
+
+ FGMatrix33 BodyToShaft ; // [S]T, see /SH79/ eqn(17,18)
+ FGMatrix33 ShaftToBody ; // [S]
+
+ // dynamic values
+ double ActualRPM ;
+ double Omega ; // must be > 0
+ double beta_orient ;
+ double a0 ; // coning angle (rad)
+ double a_1, b_1, a_dw ;
+ double a1s, b1s ; // cyclic flapping relative to shaft axes, /SH79/ eqn(43)
+ double H_drag, J_side ;
+
+ double Torque ;
+ double Thrust ;
+ double Ct ;
+ double lambda ; // inflow ratio
+ double mu ; // tip-speed ratio
+ double nu ; // induced inflow ratio
+ double v_induced ; // always positive [ft/s]
+
+ // results
+ FGColumnVector3 force ;
+ FGColumnVector3 moment ;
+
+
+ // declare the problem function
+ class dnuFunction : public FGRungeKuttaProblem {
+ public:
+ void update_params(rotor *r, double ct_t01, double fs, double w);
+ private:
+ double pFunc(double x, double y);
+ // some shortcuts
+ double k_sat, ct_lambda, k_wor, k_theta, mu2, k_flowscale;
+ } flowEquation;
+
+
+ };
+
+
public:
- /// Constructor
- FGRotor(FGFDMExec *FDMExec, Element* rotor_element, int num);
+ /** Constructor
+ @param exec pointer to executive structure
+ @param rotor_element pointer to XML element in the config file
+ @param num the number of this rotor */
+ FGRotor(FGFDMExec *exec, Element* rotor_element, int num);
+
/// Destructor
~FGRotor();
+ void SetRPM(double rpm) {RPM = rpm;}
+
+ /** Calculates forces and moments created by the rotor(s) and updates
+ vFn,vMn state variables. RPM changes are handled inside, too.
+ The RPM change is based on estimating the torque provided by the engine.
+
+ @param PowerAvailable here this is the thrust (not power) provided by a turbine
+ @return PowerAvailable */
double Calculate(double);
+
+ double GetRPM(void) const { return RPM; }
+ double GetDiameter(void) { return mr.Radius*2.0; }
+
+ // Stubs. Right now this rotor-to-engine interface is just a hack.
+ double GetTorque(void) { return 0.0; /* return mr.Torque;*/ }
+ double GetPowerRequired(void);
+
+ // Stubs. Only main rotor RPM is returned
string GetThrusterLabels(int id, string delimeter);
string GetThrusterValues(int id, string delimeter);
private:
+
+ bool bind(void);
+
+ double RPM;
+ double Sense; // default is counter clockwise rotation of the main rotor (viewed from above)
+ bool tailRotorPresent;
+
void Debug(int from);
+
+ FGPropertyManager* PropertyManager;
+
+ rotor mr;
+ rotor tr;
+
+ Filter damp_hagl;
+
+ double rho;
+
+ double effective_tail_col; // /SH79/ eqn(47)
+
+ double ground_effect_exp;
+ double ground_effect_shift;
+
+ double hover_threshold;
+ double hover_scale;
+
+ // fdm imported controls
+ FGPropertyManager* prop_collective_ctrl;
+ FGPropertyManager* prop_lateral_ctrl;
+ FGPropertyManager* prop_longitudinal_ctrl;
+ FGPropertyManager* prop_antitorque_ctrl;
+
+ FGPropertyManager* prop_freewheel_factor;
+ FGPropertyManager* prop_rotorbrake;
+
+ // fdm export ...
+ double prop_inflow_ratio_lambda;
+ double prop_advance_ratio_mu;
+ double prop_inflow_ratio_induced_nu;
+ double prop_mr_torque;
+ double prop_coning_angle;
+
+ double prop_theta_downwash;
+ double prop_phi_downwash;
+
+ double prop_thrust_coefficient;
+ double prop_lift_coefficient;
+
+ double dt; // deltaT doesn't do the thing
+
+ // devel/debug stuff
+ int prop_DumpFlag; // causes 1-time dump on stdout
+
};
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGTank.cpp,v 1.28 2010/01/24 19:26:04 jberndt Exp $";
static const char *IdHdr = ID_TANK;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
InitialTemperature = Temperature = -9999.0;
Ixx = Iyy = Izz = 0.0;
Radius = Contents = Standpipe = Length = InnerRadius = 0.0;
+ InitialStandpipe = 0.0;
Capacity = 0.00001;
Priority = InitialPriority = 1;
PropertyManager = Exec->GetPropertyManager();
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_TANK "$Id$"
+#define ID_TANK "$Id: FGTank.h,v 1.21 2010/02/05 05:53:00 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
/// Destructor
~FGTank();
+ enum TankType {ttUNKNOWN, ttFUEL, ttOXIDIZER};
+ enum GrainType {gtUNKNOWN, gtCYLINDRICAL, gtENDBURNING};
+
/** Removes fuel from the tank.
This function removes fuel from a tank. If the tank empties, it is
deselected.
const FGColumnVector3 GetXYZ(void);
const double GetXYZ(int idx);
+ const GrainType GetGrainType(void) {return grainType;}
+
double Fill(double amount);
void SetContents(double amount);
void SetContentsGallons(double gallons);
void SetStandpipe(double amount) { Standpipe = amount; }
void SetSelected(bool sel) { sel==true ? SetPriority(1):SetPriority(0); }
- enum TankType {ttUNKNOWN, ttFUEL, ttOXIDIZER};
- enum GrainType {gtUNKNOWN, gtCYLINDRICAL, gtENDBURNING};
-
private:
TankType Type;
GrainType grainType;
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGThruster.cpp,v 1.12 2009/10/24 22:59:30 jberndt Exp $";
static const char *IdHdr = ID_THRUSTER;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_THRUSTER "$Id$"
+#define ID_THRUSTER "$Id: FGThruster.h,v 1.15 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
1.57 (pi/2) results in no thrust at all.
@author Jon Berndt
- @version $Id$
+ @version $Id: FGThruster.h,v 1.15 2009/10/24 22:59:30 jberndt Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include <iostream>
#include <sstream>
#include "FGTurbine.h"
-#include "FGState.h"
-#include "models/FGPropulsion.h"
#include "FGThruster.h"
+#include "models/FGPropulsion.h"
+#include "models/FGAuxiliary.h"
+#include "models/FGAtmosphere.h"
using namespace std;
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGTurbine.cpp,v 1.27 2010/05/24 11:26:37 jberndt Exp $";
static const char *IdHdr = ID_TURBINE;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
double qbar = Auxiliary->Getqbar();
- dt = State->Getdt() * Propulsion->GetRate();
+ dt = FDMExec->GetDeltaT() * Propulsion->GetRate();
ThrottlePos = FCS->GetThrottlePos(EngineNumber);
if (ThrottlePos > 1.0) {
AugmentCmd = ThrottlePos - 1.0;
if (!Running && Cutoff && Starter) {
if (phase == tpOff) phase = tpSpinUp;
- }
+ }
// start
if ((Starter == true) || (qbar > 30.0)) {
if (!Augmentation) {
correctedTSFC = TSFC * sqrt(T/389.7) * (0.84 + (1-N2norm)*(1-N2norm));
- FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 100000);
+ FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 10000.0);
if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
thrust = thrust * (1.0 - BleedDemand);
double FGTurbine::CalcFuelNeed(void)
{
- double dT = State->Getdt() * Propulsion->GetRate();
+ double dT = FDMExec->GetDeltaT() * Propulsion->GetRate();
FuelFlowRate = FuelFlow_pph / 3600.0; // Calculates flow in lbs/sec from lbs/hr
FuelExpended = FuelFlowRate * dT; // Calculates fuel expended in this time step
return FuelExpended;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int FGTurbine::InitRunning(void) {
- State->SuspendIntegration();
+ FDMExec->SuspendIntegration();
Cutoff=false;
Running=true;
N2=IdleN2;
Calculate();
- State->ResumeIntegration();
+ FDMExec->ResumeIntegration();
return phase==tpRun;
}
#include "FGEngine.h"
-#define ID_TURBINE "$Id$"
+#define ID_TURBINE "$Id: FGTurbine.h,v 1.18 2009/10/24 22:59:30 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
/engine/direct.xml
</pre>
@author David P. Culp
- @version "$Id$"
+ @version "$Id: FGTurbine.h,v 1.18 2009/10/24 22:59:30 jberndt Exp $"
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include <iostream>
#include <sstream>
#include "FGTurboProp.h"
-
#include "FGPropeller.h"
-#include "FGState.h"
+#include "models/FGPropulsion.h"
#include "models/FGAuxiliary.h"
using namespace std;
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGTurboProp.cpp,v 1.16 2010/02/25 05:21:36 jberndt Exp $";
static const char *IdHdr = ID_TURBOPROP;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
double FGTurboProp::Calculate(void)
{
TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
- dt = State->Getdt() * Propulsion->GetRate();
+ dt = FDMExec->GetDeltaT() * Propulsion->GetRate();
ThrottleCmd = FCS->GetThrottleCmd(EngineNumber);
double FGTurboProp::CalcFuelNeed(void)
{
- double dT = State->Getdt() * Propulsion->GetRate();
+ double dT = FDMExec->GetDeltaT() * Propulsion->GetRate();
FuelFlowRate = FuelFlow_pph / 3600.0;
FuelExpended = FuelFlowRate * dT;
return FuelExpended;
int FGTurboProp::InitRunning(void)
{
- State->SuspendIntegration();
+ FDMExec->SuspendIntegration();
Cutoff=false;
Running=true;
N2=16.0;
Calculate();
- State->ResumeIntegration();
+ FDMExec->ResumeIntegration();
return phase==tpRun;
}
#include "input_output/FGXMLElement.h"
#include "math/FGTable.h"
-#define ID_TURBOPROP "$Id$"
+#define ID_TURBOPROP "$Id: FGTurboProp.h,v 1.11 2009/10/26 03:48:42 jberndt Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS