#include "models/FGAuxiliary.h"
#include "models/FGInput.h"
#include "models/FGOutput.h"
-#include "initialization/FGInitialCondition.h"
#include "initialization/FGTrim.h"
#include "initialization/FGSimplexTrim.h"
#include "initialization/FGLinearization.h"
-#include "input_output/FGPropertyManager.h"
#include "input_output/FGScript.h"
#include "input_output/FGXMLFileRead.h"
-#include "input_output/FGXMLElement.h"
using namespace std;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGFDMExec.cpp,v 1.171 2015/02/15 12:03:21 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGFDMExec.cpp,v 1.181 2015/10/25 21:18:29 dpculp Exp $");
IDENT(IdHdr,ID_FDMEXEC);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
trim_status = false;
ta_mode = 99;
+ trim_completed = 0;
Constructing = true;
typedef int (FGFDMExec::*iPMF)(void) const;
instance->Tie("simulation/dt", this, &FGFDMExec::GetDeltaT);
instance->Tie("simulation/jsbsim-debug", this, &FGFDMExec::GetDebugLevel, &FGFDMExec::SetDebugLevel);
instance->Tie("simulation/frame", (int *)&Frame, false);
+ instance->Tie("simulation/trim-completed", (int *)&trim_completed, false);
// simplex trim properties
instanceRoot->SetDouble("trim/solver/rtol",0.0001);
// Dynamic inputs come into the components that FCS manages through properties
break;
case ePropulsion:
- Propulsion->in.SLPressure = Atmosphere->GetPressureSL();
Propulsion->in.Pressure = Atmosphere->GetPressure();
Propulsion->in.PressureRatio = Atmosphere->GetPressureRatio();
Propulsion->in.Temperature = Atmosphere->GetTemperature();
Propulsion->in.Density = Atmosphere->GetDensity();
Propulsion->in.Soundspeed = Atmosphere->GetSoundSpeed();
Propulsion->in.TotalPressure = Auxiliary->GetTotalPressure();
- Propulsion->in.TotalTempearture = Auxiliary->GetTotalTemperature();
Propulsion->in.Vc = Auxiliary->GetVcalibratedKTS();
Propulsion->in.Vt = Auxiliary->GetVt();
Propulsion->in.qbar = Auxiliary->Getqbar();
Propagate->in.SemiMajor = Inertial->GetSemimajor();
Propagate->in.SemiMinor = Inertial->GetSemiminor();
Auxiliary->in.SLGravity = Inertial->SLgravity();
- Auxiliary->in.ReferenceRadius = Inertial->GetRefRadius();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGFDMExec::LoadModelConstants(void)
{
Winds->in.wingspan = Aircraft->GetWingSpan();
- FCS->in.NumGear = GroundReactions->GetNumGearUnits();
Aerodynamics->in.Wingarea = Aircraft->GetWingArea();
Aerodynamics->in.Wingchord = Aircraft->Getcbar();
Aerodynamics->in.Wingincidence = Aircraft->GetWingIncidence();
{
FGPropulsion* propulsion = (FGPropulsion*)Models[ePropulsion];
+ SuspendIntegration(); // saves the integration rate, dt, then sets it to 0.0.
+ Initialize(IC);
+
Models[eInput]->InitModel();
Models[eOutput]->InitModel();
- SuspendIntegration(); // saves the integration rate, dt, then sets it to 0.0.
- Initialize(IC);
Run();
ResumeIntegration(); // Restores the integration rate to what it was.
+ if (debug_lvl > 0) {
+ MassBalance->GetMassPropertiesReport(0);
+
+ cout << endl << fgblue << highint
+ << "End of vehicle configuration loading." << endl
+ << "-------------------------------------------------------------------------------"
+ << reset << setprecision(6) << endl;
+ }
+
for (unsigned int n=0; n < propulsion->GetNumEngines(); ++n) {
if (IC->IsEngineRunning(n)) {
try {
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGFDMExec::Initialize(FGInitialCondition *FGIC)
+void FGFDMExec::Initialize(FGInitialCondition* FGIC)
{
- Setsim_time(0.0);
-
- Propagate->SetInitialState( FGIC );
- LoadInputs(eInertial);
- Inertial->Run(false);
- LoadInputs(eAccelerations);
- Accelerations->Run(false);
- LoadInputs(ePropagate);
- Propagate->InitializeDerivatives();
+ Propagate->SetInitialState(FGIC);
Winds->SetWindNED(FGIC->GetWindNEDFpsIC());
- LoadInputs(eMassBalance);
- MassBalance->Run(false);
+ Run();
+ Propagate->InitializeDerivatives();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Models[i]->InitModel();
}
- if (Script) Script->ResetEvents();
-
RunIC();
+
+ if (Script)
+ Script->ResetEvents();
+ else
+ Setsim_time(0.0);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Process the system element[s]. This element is OPTIONAL, and there may be more than one.
element = document->FindElement("system");
while (element) {
- result = ((FGFCS*)Models[eSystems])->Load(element, FGFCS::stSystem);
+ result = ((FGFCS*)Models[eSystems])->Load(element);
if (!result) {
cerr << endl << "Aircraft system element has problems in file " << aircraftCfgFileName << endl;
return result;
// Process the autopilot element. This element is OPTIONAL.
element = document->FindElement("autopilot");
if (element) {
- result = ((FGFCS*)Models[eSystems])->Load(element, FGFCS::stAutoPilot);
+ result = ((FGFCS*)Models[eSystems])->Load(element);
if (!result) {
cerr << endl << "Aircraft autopilot element has problems in file " << aircraftCfgFileName << endl;
return result;
// Process the flight_control element. This element is OPTIONAL.
element = document->FindElement("flight_control");
if (element) {
- result = ((FGFCS*)Models[eSystems])->Load(element, FGFCS::stFCS);
+ result = ((FGFCS*)Models[eSystems])->Load(element);
if (!result) {
cerr << endl << "Aircraft flight_control element has problems in file " << aircraftCfgFileName << endl;
return result;
modelLoaded = true;
- if (debug_lvl > 0) {
- LoadInputs(eMassBalance); // Update all input mass properties for the report.
- Models[eMassBalance]->Run(false); // Update all mass properties for the report.
- LoadInputs(ePropulsion); // Update propulsion properties for the report.
- Models[ePropulsion]->Run(false); // Update propulsion properties for the report.
- LoadInputs(eMassBalance); // Update all (one more time) input mass properties for the report.
- Models[eMassBalance]->Run(false); // Update all (one more time) mass properties for the report.
- ((FGMassBalance*)Models[eMassBalance])->GetMassPropertiesReport(0);
-
- cout << endl << fgblue << highint
- << "End of vehicle configuration loading." << endl
- << "-------------------------------------------------------------------------------"
- << reset << endl;
- }
-
if (IsChild) debug_lvl = saved_debug_lvl;
} else {
void FGFDMExec::DoTrim(int mode)
{
- double saved_time;
-
if (Constructing) return;
if (mode < 0 || mode > JSBSim::tNone) {
cerr << endl << "Illegal trimming mode!" << endl << endl;
return;
}
- saved_time = sim_time;
+
+
FGTrim trim(this, (JSBSim::TrimMode)mode);
if ( !trim.DoTrim() ) cerr << endl << "Trim Failed" << endl << endl;
trim.Report();
- Setsim_time(saved_time);
+ trim_completed = 1;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGSimplexTrim trim(this, (JSBSim::TrimMode)mode);
Setsim_time(saved_time);
std::cout << "dT: " << dT << std::endl;
+ trim_completed = 1;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FDMEXEC "$Id: FGFDMExec.h,v 1.95 2015/02/07 17:52:36 bcoconni Exp $"
+#define ID_FDMEXEC "$Id: FGFDMExec.h,v 1.102 2015/10/25 21:18:29 dpculp Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
property actually maps toa function call of DoTrim().
@author Jon S. Berndt
- @version $Revision: 1.95 $
+ @version $Revision: 1.102 $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGAuxiliary* GetAuxiliary(void) {return (FGAuxiliary*)Models[eAuxiliary];}
/// Returns the FGInput pointer.
FGInput* GetInput(void) {return (FGInput*)Models[eInput];}
+ /// Returns the FGOutput pointer.
+ FGOutput* GetOutput(void) {return (FGOutput*)Models[eOutput];}
/** Get a pointer to the ground callback currently used. It is recommanded
to store the returned pointer in a 'smart pointer' FGGroundCallback_ptr.
@return A pointer to the current ground callback object.
/** Forces the specified output object to print its items once */
void ForceOutput(int idx=0) { Output->ForceOutput(idx); }
- /** Sets the logging rate for all output objects (if any). */
- void SetLoggingRate(double rate) { Output->SetRate(rate); }
+ /** Sets the logging rate in Hz for all output objects (if any). */
+ void SetLoggingRate(double rate) { Output->SetRateHz(rate); }
/** Sets (or overrides) the output filename
@param n index of file
is also incremented.
@return the new simulation time. */
double IncrTime(void) {
- if (!holding) sim_time += dT;
- GetGroundCallback()->SetTime(sim_time);
- Frame++;
+ if (!holding && !IntegrationSuspended()) {
+ sim_time += dT;
+ GetGroundCallback()->SetTime(sim_time);
+ Frame++;
+ }
return sim_time;
}
+ /** Retrieves the current frame count. */
+ unsigned int GetFrame(void) const {return Frame;}
+
/** Retrieves the current debug level setting. */
int GetDebugLevel(void) const {return debug_lvl;};
bool trim_status;
int ta_mode;
unsigned int ResetMode;
+ int trim_completed;
FGScript* Script;
FGInitialCondition* IC;
#include <sstream>
#include <cstdlib>
+using namespace std;
+
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGJSBBase.cpp,v 1.39 2014/09/03 17:35:04 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGJSBBase.cpp,v 1.40 2015/07/12 19:34:08 bcoconni Exp $");
IDENT(IdHdr,ID_JSBBASE);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
const string FGJSBBase::needed_cfg_version = "2.0";
const string FGJSBBase::JSBSim_version = "1.0 " __DATE__ " " __TIME__ ;
-std::queue <FGJSBBase::Message> FGJSBBase::Messages;
+queue <FGJSBBase::Message> FGJSBBase::Messages;
FGJSBBase::Message FGJSBBase::localMsg;
unsigned int FGJSBBase::messageId = 0;
short FGJSBBase::debug_lvl = 1;
-using std::cerr;
-using std::cout;
-using std::endl;
-
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGJSBBase::PutMessage(const Message& msg)
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-int FGJSBBase::SomeMessages(void)
-{
- return !Messages.empty();
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
void FGJSBBase::ProcessMessage(void)
{
if (Messages.empty()) return;
localMsg = Messages.front();
- while (Messages.size() > 0) {
+ while (SomeMessages()) {
switch (localMsg.type) {
case JSBSim::FGJSBBase::Message::eText:
cout << localMsg.messageId << ": " << localMsg.text << endl;
break;
}
Messages.pop();
- if (Messages.size() > 0) localMsg = Messages.front();
+ if (SomeMessages()) localMsg = Messages.front();
else break;
}
string FGJSBBase::CreateIndexedPropertyName(const string& Property, int index)
{
- std::ostringstream buf;
+ ostringstream buf;
buf << Property << '[' << index << ']';
return buf.str();
}
#include <string>
#include <cmath>
-using std::min;
-using std::max;
-
#include "input_output/string_utilities.h"
#ifndef M_PI
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_JSBBASE "$Id: FGJSBBase.h,v 1.41 2014/09/03 17:35:04 bcoconni Exp $"
+#define ID_JSBBASE "$Id: FGJSBBase.h,v 1.44 2015/09/17 19:44:13 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
* This class provides universal constants, utility functions, messaging
* functions, and enumerated constants to JSBSim.
@author Jon S. Berndt
- @version $Id: FGJSBBase.h,v 1.41 2014/09/03 17:35:04 bcoconni Exp $
+ @version $Id: FGJSBBase.h,v 1.44 2015/09/17 19:44:13 bcoconni Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void PutMessage(const std::string& text, double dVal);
/** Reads the message on the queue (but does not delete it).
@return 1 if some messages */
- int SomeMessages(void);
+ int SomeMessages(void) { return !Messages.empty(); }
/** Reads the message on the queue and removes it from the queue.
This function also prints out the message.*/
void ProcessMessage(void);
@return if the two values can be considered equal up to roundoff */
static bool EqualToRoundoff(double a, double b) {
double eps = 2.0*DBL_EPSILON;
- return std::fabs(a - b) <= eps * max(std::fabs(a), std::fabs(b));
+ return std::fabs(a - b) <= eps * std::max<double>(std::fabs(a), std::fabs(b));
}
/** Finite precision comparison.
@return if the two values can be considered equal up to roundoff */
static bool EqualToRoundoff(float a, float b) {
float eps = 2.0*FLT_EPSILON;
- return std::fabs(a - b) <= eps * max(std::fabs(a), std::fabs(b));
+ return std::fabs(a - b) <= eps * std::max<double>(std::fabs(a), std::fabs(b));
}
/** Finite precision comparison.
INCLUDES
*******************************************************************************/
-#include <iostream>
-#include <fstream>
#include <cstdlib>
#include "FGInitialCondition.h"
#include "FGFDMExec.h"
-#include "math/FGQuaternion.h"
#include "models/FGInertial.h"
#include "models/FGAtmosphere.h"
-#include "models/FGPropagate.h"
-#include "models/FGPropulsion.h"
#include "models/FGAccelerations.h"
-#include "models/FGFCS.h"
-#include "input_output/FGPropertyManager.h"
-#include "input_output/string_utilities.h"
#include "input_output/FGXMLFileRead.h"
-#include "input_output/FGXMLElement.h"
using namespace std;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGInitialCondition.cpp,v 1.99 2015/02/19 05:18:45 dpculp Exp $");
+IDENT(IdSrc,"$Id: FGInitialCondition.cpp,v 1.101 2015/09/27 15:45:31 bcoconni Exp $");
IDENT(IdHdr,ID_INITIALCONDITION);
//******************************************************************************
{
bool result = true;
- if (document->FindElement("latitude")) {
+ Element* latitude_el = document->FindElement("latitude");
+ if (latitude_el) {
double latitude = document->FindElementValueAsNumberConvertTo("latitude", "RAD");
- string lat_type = document->FindElement("latitude")->GetAttributeValue("type");
+ if (fabs(latitude) > 0.5*M_PI) {
+ string unit_type = latitude_el->GetAttributeValue("unit");
+ if (unit_type.empty()) unit_type="RAD";
+ cerr << latitude_el->ReadFrom() << "The latitude value "
+ << latitude_el->GetDataAsNumber() << " " << unit_type
+ << " is outside the range [";
+ if (unit_type == "DEG")
+ cerr << "-90 DEG ; +90 DEG]" << endl;
+ else
+ cerr << "-PI/2 RAD; +PI/2 RAD]" << endl;
+ result = false;
+ }
+
+ string lat_type = latitude_el->GetAttributeValue("type");
if (lat_type == "geod" || lat_type == "geodetic")
position.SetPositionGeodetic(0.0, latitude, 0.0); // Longitude and altitude will be set later on
else
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGTrim.cpp,v 1.24 2014/11/30 12:35:32 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGTrim.cpp,v 1.28 2015/09/28 20:50:41 bcoconni Exp $");
IDENT(IdHdr,ID_TRIM);
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fdmex->GetGroundReactions()->GetGearUnit(i)->SetReport(false);
}
- fdmex->DisableOutput();
-
fdmex->SetTrimStatus(true);
fdmex->SuspendIntegration();
fdmex->ResumeIntegration();
fdmex->SetTrimStatus(false);
- fdmex->EnableOutput();
for(int i=0;i < fdmex->GetGroundReactions()->GetNumGearUnits();i++){
fdmex->GetGroundReactions()->GetGearUnit(i)->SetReport(true);
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGTrimAxis.cpp,v 1.17 2014/01/13 10:46:00 ehofman Exp $");
+IDENT(IdSrc,"$Id: FGTrimAxis.cpp,v 1.19 2015/09/28 20:50:41 bcoconni Exp $");
IDENT(IdHdr,ID_TRIMAXIS);
/*****************************************************************************/
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGInputType.cpp,v 1.2 2015/03/28 14:49:01 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGInputType.cpp,v 1.4 2015/08/23 09:43:31 bcoconni Exp $");
IDENT(IdHdr,ID_INPUTTYPE);
using namespace std;
bool FGInputType::Run(bool Holding)
{
- if (!enabled) return true;
if (FGModel::Run(Holding)) return true;
- // if (Holding) return false;
+ if (!enabled) return true;
RunPreFunctions();
Read(Holding);
void FGInputType::Debug(int from)
{
- string scratch="";
-
if (debug_lvl <= 0) return;
if (debug_lvl & 1) { // Standard console startup message input
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_INPUTTYPE "$Id: FGInputType.h,v 1.2 2015/03/28 14:49:01 bcoconni Exp $"
+#define ID_INPUTTYPE "$Id: FGInputType.h,v 1.3 2015/08/23 09:37:16 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
/// Destructor
virtual ~FGInputType();
- /** Set the idx for this output instance
- @param idx ID of the output instance that is constructed
+ /** Set the idx for this input instance
+ @param idx ID of the input instance that is constructed
*/
void SetIdx(unsigned int idx);
*/
virtual void Read(bool Holding) = 0;
- /// Enables the output generation.
+ /// Enables the input generation.
void Enable(void) { enabled = true; }
- /// Disables the output generation.
+ /// Disables the input generation.
void Disable(void) { enabled = false; }
- /** Toggles the output generation.
- @result the output generation status i.e. true if the output has been
- enabled, false if the output has been disabled. */
+ /** Toggles the input generation.
+ @result the input generation status i.e. true if the input has been
+ enabled, false if the input has been disabled. */
bool Toggle(void) {enabled = !enabled; return enabled;}
/** Overwrites the name identifier under which the input will be read.
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGOutputType.cpp,v 1.12 2015/03/28 14:49:01 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGOutputType.cpp,v 1.17 2015/08/23 09:43:31 bcoconni Exp $");
IDENT(IdHdr,ID_OUTPUTTYPE);
using namespace std;
void FGOutputType::SetIdx(unsigned int idx)
{
- typedef double (FGOutputType::*iOPMF)(void) const;
- string outputProp = CreateIndexedPropertyName("simulation/output", idx) + "/log_rate_hz";
+ string outputProp = CreateIndexedPropertyName("simulation/output", idx);
- PropertyManager->Tie(outputProp, this, (iOPMF)0, &FGOutputType::SetRate, false);
+ PropertyManager->Tie(outputProp + "/log_rate_hz", this, &FGOutputType::GetRateHz, &FGOutputType::SetRateHz, false);
+ PropertyManager->Tie(outputProp + "/enabled", &enabled);
OutputIdx = idx;
}
Element *property_element = element->FindElement("property");
while (property_element) {
- string caption="";
string property_str = property_element->GetDataLine();
FGPropertyNode* node = PropertyManager->GetNode(property_str);
if (!node) {
if (!element->GetAttributeValue("rate").empty()) {
outRate = element->GetAttributeValueAsNumber("rate");
}
- SetRate(outRate);
+ SetRateHz(outRate);
return true;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-bool FGOutputType::Run(bool Holding)
+bool FGOutputType::Run(void)
{
+ if (FGModel::Run(false)) return true;
if (!enabled) return true;
- if (FGModel::Run(Holding)) return true;
- if (Holding) return false;
RunPreFunctions();
Print();
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGOutputType::SetRate(double rtHz)
+void FGOutputType::SetRateHz(double rtHz)
{
rtHz = rtHz>1000?1000:(rtHz<0?0:rtHz);
if (rtHz > 0) {
- FGModel::SetRate(0.5 + 1.0/(FDMExec->GetDeltaT()*rtHz));
+ SetRate(0.5 + 1.0/(FDMExec->GetDeltaT()*rtHz));
Enable();
} else {
- FGModel::SetRate(1);
+ SetRate(1);
Disable();
}
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGOutputType::GetRateHz(void) const
+{
+ return 1.0 / (rate * FDMExec->GetDeltaT());
+}
+
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// The bitmasked value choices are as follows:
// unset: In this case (the default) JSBSim would only print
void FGOutputType::Debug(int from)
{
- string scratch="";
-
if (debug_lvl <= 0) return;
if (debug_lvl & 1) { // Standard console startup message output
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_OUTPUTTYPE "$Id: FGOutputType.h,v 1.6 2015/03/28 14:49:01 bcoconni Exp $"
+#define ID_OUTPUTTYPE "$Id: FGOutputType.h,v 1.11 2015/08/23 09:43:31 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
/** Set the output rate for this output instances.
@param rtHz new output rate in Hz */
- void SetRate(double rtHz);
+ void SetRateHz(double rtHz);
+
+ /// Get the output rate in Hz for this output.
+ double GetRateHz(void) const;
/** Set the activated subsystems for this output instance.
@param subSystems bitfield that describes the activated subsystems
generation and finally the "post" functions.
@result false if no error.
*/
- bool Run(bool Holding);
+ bool Run(void);
/** Generate the output. This is a pure method so it must be implemented by
the classes that inherits from FGOutputType. The Print name may not be
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGScript.cpp,v 1.60 2014/06/08 12:50:05 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGScript.cpp,v 1.63 2015/09/28 21:14:15 bcoconni Exp $");
IDENT(IdHdr,ID_FGSCRIPT);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-bool FGScript::LoadScript(string script, double deltaT, const string initfile)
+bool FGScript::LoadScript(const string& script, double default_dT,
+ const string& initfile)
{
- string aircraft="", initialize="", comparison = "", prop_name="";
+ string aircraft="", initialize="", prop_name="";
string notifyPropertyName="";
Element *element=0, *run_element=0, *event_element=0;
- Element *condition_element=0, *set_element=0, *delay_element=0;
+ Element *set_element=0;
Element *notify_element = 0L, *notify_property_element = 0L;
- Element *output_element = 0L;
- Element *input_element = 0L;
- bool result = false;
double dt = 0.0, value = 0.0;
- struct event *newEvent;
FGCondition *newCondition;
FGXMLFileRead XMLFileRead;
return false;
}
- // Set up input and output files if specified
-
- output_element = document->FindElement("output");
- input_element = document->FindElement("input");
-
if (document->GetName() != string("runscript")) {
cerr << "File: " << script << " is not a script file" << endl;
return false;
// Set sim timing
- if (run_element->HasAttribute("start")) StartTime = run_element->GetAttributeValueAsNumber("start");
+ if (run_element->HasAttribute("start"))
+ StartTime = run_element->GetAttributeValueAsNumber("start");
+ else
+ StartTime = 0.0;
FDMExec->Setsim_time(StartTime);
if (run_element->HasAttribute("end")) {
EndTime = run_element->GetAttributeValueAsNumber("end");
// Make sure that the desired time is reached and executed.
EndTime += 0.99*FDMExec->GetDeltaT();
- if (deltaT == 0.0)
+ if (default_dT == 0.0)
dt = run_element->GetAttributeValueAsNumber("dt");
else {
- dt = deltaT;
+ dt = default_dT;
cout << endl << "Overriding simulation step size from the command line. New step size is: "
- << deltaT << " seconds (" << 1/deltaT << " Hz)" << endl << endl;
+ << default_dT << " seconds (" << 1/default_dT << " Hz)" << endl << endl;
}
FDMExec->Setdt(dt);
if (element) {
aircraft = element->GetAttributeValue("aircraft");
if (!aircraft.empty()) {
- result = FDMExec->LoadModel(aircraft);
- if (!result) return false;
+ if (!FDMExec->LoadModel(aircraft))
+ return false;
} else {
cerr << "Aircraft must be specified in use element." << endl;
return false;
FGInitialCondition *IC=FDMExec->GetIC();
if ( ! IC->Load( initialize )) {
cerr << "Initialization unsuccessful" << endl;
- exit(-1);
+ return false;
}
// Now, read input spec if given.
- if (input_element > 0) {
- FDMExec->GetInput()->Load(input_element);
+ element = document->FindElement("input");
+ while (element) {
+ if (!FDMExec->GetInput()->Load(element))
+ return false;
+
+ element = document->FindNextElement("input");
}
// Now, read output spec if given.
- if (output_element > 0) {
- string output_file = output_element->GetAttributeValue("file");
- if (output_file.empty()) {
- cerr << "No logging directives file was specified." << endl;
- } else {
- if (!FDMExec->SetOutputDirectives(output_file)) return false;
- }
+ element = document->FindElement("output");
+ while (element) {
+ if (!FDMExec->GetOutput()->Load(element))
+ return false;
+
+ element = document->FindNextElement("output");
}
// Read local property/value declarations
while (event_element) { // event processing
// Create the event structure
- newEvent = new struct event();
+ struct event *newEvent = new struct event();
// Retrieve the event name if given
newEvent->Name = event_element->GetAttributeValue("name");
}
// Process the conditions
- condition_element = event_element->FindElement("condition");
+ Element* condition_element = event_element->FindElement("condition");
if (condition_element != 0) {
try {
newCondition = new FGCondition(condition_element, PropertyManager);
- } catch(string str) {
+ } catch(string& str) {
cout << endl << fgred << str << reset << endl << endl;
delete newEvent;
return false;
// Is there a delay between the time this event is triggered, and when the event
// actions are executed?
- delay_element = event_element->FindElement("delay");
- if (delay_element) newEvent->Delay = event_element->FindElementValueAsNumber("delay");
- else newEvent->Delay = 0.0;
+ Element* delay_element = event_element->FindElement("delay");
+ if (delay_element)
+ newEvent->Delay = event_element->FindElementValueAsNumber("delay");
+ else
+ newEvent->Delay = 0.0;
// Notify about when this event is triggered?
if ((notify_element = event_element->FindElement("notify")) != 0) {
while (set_element) {
prop_name = set_element->GetAttributeValue("name");
if (PropertyManager->HasNode(prop_name)) {
- newEvent->SetParam.push_back( PropertyManager->GetNode(prop_name) );
+ newEvent->SetParam.push_back( PropertyManager->GetNode(prop_name) );
} else {
newEvent->SetParam.push_back( 0L );
}
void FGScript::ResetEvents(void)
{
//LocalProperties.ResetToIC();
+ FDMExec->Setsim_time(StartTime);
for (unsigned int i=0; i<Events.size(); i++)
Events[i].reset();
if (thisEvent.Functions[i] != 0) { // Parameter should be set to a function value
try {
thisEvent.SetValue[i] = thisEvent.Functions[i]->GetValue();
- } catch (string msg) {
+ } catch (string& msg) {
std::cerr << std::endl << "A problem occurred in the execution of the script. " << msg << endl;
throw;
}
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FGSCRIPT "$Id: FGScript.h,v 1.29 2014/05/29 18:46:44 bcoconni Exp $"
+#define ID_FGSCRIPT "$Id: FGScript.h,v 1.30 2015/09/20 16:32:11 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
comes the "run" section, where the conditions are
described in "event" clauses.</p>
@author Jon S. Berndt
- @version "$Id: FGScript.h,v 1.29 2014/05/29 18:46:44 bcoconni Exp $"
+ @version "$Id: FGScript.h,v 1.30 2015/09/20 16:32:11 bcoconni Exp $"
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
~FGScript();
/** Loads a script to drive JSBSim (usually in standalone mode).
- 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-
+ The language is the Script Directives for JSBSim. If a simulation step
+ size has been supplied on the command line, it will 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.
+ @param default_dT the default simulation step size if no value is specified
+ in the script
@param initfile An optional initialization file name passed in, empty by
default. If a file name is passed in, it will override the
one present in the script.
@return true if successful */
- bool LoadScript(std::string script, double deltaT, const std::string initfile);
+ bool LoadScript(const std::string& script, double default_dT,
+ const std::string& initfile);
/** This function is called each pass through the executive Run() method IF
scripting is enabled.
return false;
rate = atoi(el->GetAttributeValue("rate").c_str());
- FGModel::SetRate(0.5 + 1.0/(FDMExec->GetDeltaT()*rate));
+ SetRate(0.5 + 1.0/(FDMExec->GetDeltaT()*rate));
SockPort = atoi(el->GetAttributeValue("port").c_str());
if (SockPort == 0) {
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGUDPOutputSocket.cpp,v 1.1 2015/04/02 02:23:33 dpculp Exp $");
+IDENT(IdSrc,"$Id: FGUDPOutputSocket.cpp,v 1.2 2015/08/16 13:19:52 bcoconni Exp $");
IDENT(IdHdr,ID_UDPOUTPUTSOCKET);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Element *property_element = el->FindElement("property");
while (property_element) {
- string caption="";
string property_str = property_element->GetDataLine();
FGPropertyNode* node = PropertyManager->GetNode(property_str);
if (!node) {
if (!el->GetAttributeValue("rate").empty()) {
outRate = el->GetAttributeValueAsNumber("rate");
}
- SetRate(outRate);
+ SetRateHz(outRate);
SockPort = atoi(el->GetAttributeValue("port").c_str());
if (SockPort == 0) {
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGXMLElement.cpp,v 1.52 2014/06/29 10:13:18 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGXMLElement.cpp,v 1.54 2015/09/27 15:39:45 bcoconni Exp $");
IDENT(IdHdr,ID_XMLELEMENT);
bool Element::converterIsInitialized = false;
}
double value = element->GetDataAsNumber();
+
+ // Sanity check for angular values
+ if ((supplied_units == "RAD") && (fabs(value) > 2 * M_PI)) {
+ cerr << element->ReadFrom() << "The value " << value
+ << " RAD is outside the range [ -2*M_PI RAD ; +2*M_PI RAD ]" << endl;
+ }
+ if ((supplied_units == "DEG") && (fabs(value) > 360.0)) {
+ cerr << element->ReadFrom() << "The value " << value
+ << " DEG is outside the range [ -360 DEG ; +360 DEG ]" << endl;
+ }
+
+
if (!supplied_units.empty()) {
value *= convert[supplied_units][target_units];
}
+ if ((target_units == "RAD") && (fabs(value) > 2 * M_PI)) {
+ cerr << element->ReadFrom() << "The value " << value
+ << " RAD is outside the range [ -2*M_PI RAD ; +2*M_PI RAD ]" << endl;
+ }
+ if ((target_units == "DEG") && (fabs(value) > 360.0)) {
+ cerr << element->ReadFrom() << "The value " << value
+ << " DEG is outside the range [ -360 DEG ; +360 DEG ]" << endl;
+ }
+
value = DisperseValue(element, value, supplied_units, target_units);
return value;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-double Element::DisperseValue(Element *e, double val, const std::string supplied_units, const std::string target_units)
+double Element::DisperseValue(Element *e, double val, const std::string& supplied_units,
+ const std::string& target_units)
{
double value=val;
- double disp=0.0;
bool disperse = false;
try {
}
if (e->HasAttribute("dispersion") && disperse) {
- disp = e->GetAttributeValueAsNumber("dispersion");
+ double disp = e->GetAttributeValueAsNumber("dispersion");
if (!supplied_units.empty()) disp *= convert[supplied_units][target_units];
string attType = e->GetAttributeValue("type");
if (attType == "gaussian" || attType == "gaussiansigned") {
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_XMLELEMENT "$Id: FGXMLElement.h,v 1.24 2014/06/29 10:13:18 bcoconni Exp $"
+#define ID_XMLELEMENT "$Id: FGXMLElement.h,v 1.25 2015/07/12 19:34:08 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
- GAL = gallon (U.S. liquid)
@author Jon S. Berndt
- @version $Id: FGXMLElement.h,v 1.24 2014/06/29 10:13:18 bcoconni Exp $
+ @version $Id: FGXMLElement.h,v 1.25 2015/07/12 19:34:08 bcoconni Exp $
*/
class Element;
@return a column vector object built from the LOCATION or ORIENT components. */
FGColumnVector3 FindElementTripletConvertTo( const std::string& target_units);
- double DisperseValue(Element *e, double val, const std::string supplied_units="", const std::string target_units="");
+ double DisperseValue(Element *e, double val, const std::string& supplied_units="",
+ const std::string& target_units="");
/** This function sets the value of the parent class attribute to the supplied
Element pointer.
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_STRINGUTILS "$Id: string_utilities.h,v 1.22 2015/03/28 14:49:01 bcoconni Exp $"
+#define ID_STRINGUTILS "$Id: string_utilities.h,v 1.24 2015/08/16 16:06:28 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
#else
#include <cctype>
- using namespace std;
-
- string& trim_left(string& str)
+ std::string& trim_left(std::string& str)
{
- while (str.size() && isspace((unsigned char)str[0])) {
+ while (!str.empty() && isspace((unsigned char)str[0])) {
str = str.erase(0,1);
}
return str;
}
- string& trim_right(string& str)
+ std::string& trim_right(std::string& str)
{
- while (str.size() && isspace((unsigned char)str[str.size()-1])) {
+ while (!str.empty() && isspace((unsigned char)str[str.size()-1])) {
str = str.erase(str.size()-1,1);
}
return str;
}
- string& trim(string& str)
+ std::string& trim(std::string& str)
{
- if (str.size() == 0) return str;
- string temp_str = trim_right(str);
+ if (str.empty()) return str;
+ std::string temp_str = trim_right(str);
return str = trim_left(temp_str);
}
- string& trim_all_space(string& str)
+ std::string& trim_all_space(std::string& str)
{
for (size_t i=0; i<str.size(); i++) {
if (isspace((unsigned char)str[i])) {
return str;
}
- string& to_upper(string& str)
+ std::string& to_upper(std::string& str)
{
for (size_t i=0; i<str.size(); i++) str[i] = toupper(str[i]);
return str;
}
- string& to_lower(string& str)
+ std::string& to_lower(std::string& str)
{
for (size_t i=0; i<str.size(); i++) str[i] = tolower(str[i]);
return str;
}
- bool is_number(const string& str)
+ bool is_number(const std::string& str)
{
- if (str.size())
- return (str.find_first_not_of("+-.0123456789Ee") == string::npos);
- else
+ if (str.empty())
return false;
+ else
+ return (str.find_first_not_of("+-.0123456789Ee") == std::string::npos);
}
- vector <string> split(string str, char d)
+ std::vector <std::string> split(std::string str, char d)
{
- vector <string> str_array;
+ std::vector <std::string> str_array;
size_t index=0;
- string temp = "";
+ std::string temp = "";
trim(str);
index = str.find(d);
- while (index != string::npos) {
+ while (index != std::string::npos) {
temp = str.substr(0,index);
trim(temp);
- if (temp.size() > 0) str_array.push_back(temp);
+ if (!temp.empty()) str_array.push_back(temp);
str = str.erase(0,index+1);
index = str.find(d);
}
- if (str.size() > 0) {
+ if (!str.empty()) {
temp = trim(str);
- if (temp.size() > 0) str_array.push_back(temp);
+ if (!temp.empty()) str_array.push_back(temp);
}
return str_array;
// * libc++ for all C++ language versions
// * Visual Studio for versions greater than 2010 (1700 -> MSVC++ 11.0 and VS 2012)
#if !defined(_LIBCPP_VERSION) && _MSC_VER < 1700 && __cplusplus < 201103L
- string to_string(int i)
+ std::string to_string(int i)
{
char buffer[32];
sprintf(buffer, "%d", i);
- return string(buffer);
+ return std::string(buffer);
}
- string to_string(float x)
+ std::string to_string(float x)
{
std::ostringstream o;
- if (!(o << x)) cerr << "Bad float to string conversion" << endl;
+ if (!(o << x)) std::cerr << "Bad float to string conversion" << std::endl;
return o.str();
}
- string to_string(double x)
+ std::string to_string(double x)
{
std::ostringstream o;
- if (!(o << x)) cerr << "Bad double to string conversion" << endl;
+ if (!(o << x)) std::cerr << "Bad double to string conversion" << std::endl;
return o.str();
}
#endif
- string replace(string str, const string& oldstr, const string& newstr)
+ std::string replace(std::string str, const std::string& oldstr, const std::string& newstr)
{
- string temp;
+ std::string temp = str;
size_t old_idx = str.find(oldstr);
- if (old_idx != string::npos) {
+ if (old_idx != std::string::npos) {
temp = str.replace(old_idx, 1, newstr);
}
return temp;
#include <iomanip>
#include <cstdlib>
#include <cmath>
+
#include "FGFunction.h"
#include "FGTable.h"
#include "FGPropertyValue.h"
#include "FGRealValue.h"
#include "input_output/FGXMLElement.h"
-#include "input_output/FGPropertyManager.h"
using namespace std;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGFunction.cpp,v 1.57 2015/03/28 14:49:01 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGFunction.cpp,v 1.58 2015/07/12 19:34:08 bcoconni Exp $");
IDENT(IdHdr,ID_FUNCTION);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
property_name = replace(property_name,"#",Prefix);
}
}
- FGPropertyNode* newNode = 0L;
if (PropertyManager->HasNode(property_name)) {
- newNode = PropertyManager->GetNode(property_name);
+ FGPropertyNode* newNode = PropertyManager->GetNode(property_name);
Parameters.push_back(new FGPropertyValue( newNode ));
} else {
// cerr << fgcyan << "Warning: The property " + property_name + " is initially undefined."
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FUNCTION "$Id: FGFunction.h,v 1.31 2013/06/20 04:37:27 jberndt Exp $"
+#define ID_FUNCTION "$Id: FGFunction.h,v 1.32 2015/07/12 13:03:23 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
- log2 (takes 1 arg)
- ln (takes 1 arg)
- log10 (takes 1 arg)
-- abs (takes n args)
+- abs (takes 1 arg)
- sin (takes 1 arg)
- cos (takes 1 arg)
- tan (takes 1 arg)
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGLocation.cpp,v 1.33 2014/08/28 11:46:11 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGLocation.cpp,v 1.34 2015/09/20 20:53:13 bcoconni Exp $");
IDENT(IdHdr,ID_LOCATION);
// Set up the default ground callback object.
mCacheValid = true;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+// The calculations, below, implement the Haversine formulas to calculate
+// heading and distance to a set of lat/long coordinates from the current
+// position.
+//
+// The basic equations are (lat1, long1 are source positions; lat2
+// long2 are target positions):
+//
+// R = earth’s radius
+// Δlat = lat2 − lat1
+// Δlong = long2 − long1
+//
+// For the waypoint distance calculation:
+//
+// a = sin²(Δlat/2) + cos(lat1)∙cos(lat2)∙sin²(Δlong/2)
+// c = 2∙atan2(√a, √(1−a))
+// d = R∙c
+
+double FGLocation::GetDistanceTo(double target_longitude,
+ double target_latitude) const
+{
+ double delta_lat_rad = target_latitude - GetLatitude();
+ double delta_lon_rad = target_longitude - GetLongitude();
+
+ double distance_a = pow(sin(0.5*delta_lat_rad), 2.0)
+ + (GetCosLatitude() * cos(target_latitude)
+ * (pow(sin(0.5*delta_lon_rad), 2.0)));
+
+ return 2.0 * GetRadius() * atan2(sqrt(distance_a), sqrt(1.0 - distance_a));
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+// The calculations, below, implement the Haversine formulas to calculate
+// heading and distance to a set of lat/long coordinates from the current
+// position.
+//
+// The basic equations are (lat1, long1 are source positions; lat2
+// long2 are target positions):
+//
+// R = earth’s radius
+// Δlat = lat2 − lat1
+// Δlong = long2 − long1
+//
+// For the heading angle calculation:
+//
+// θ = atan2(sin(Δlong)∙cos(lat2), cos(lat1)∙sin(lat2) − sin(lat1)∙cos(lat2)∙cos(Δlong))
+
+double FGLocation::GetHeadingTo(double target_longitude,
+ double target_latitude) const
+{
+ double delta_lon_rad = target_longitude - GetLongitude();
+
+ double Y = sin(delta_lon_rad) * cos(target_latitude);
+ double X = GetCosLatitude() * sin(target_latitude)
+ - GetSinLatitude() * cos(target_latitude) * cos(delta_lon_rad);
+
+ double heading_to_waypoint_rad = atan2(Y, X);
+ if (heading_to_waypoint_rad < 0) heading_to_waypoint_rad += 2.0*M_PI;
+
+ return heading_to_waypoint_rad;
+}
+
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
} // namespace JSBSim
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_LOCATION "$Id: FGLocation.h,v 1.34 2014/11/30 12:35:32 bcoconni Exp $"
+#define ID_LOCATION "$Id: FGLocation.h,v 1.35 2015/09/20 20:53:13 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@see W. C. Durham "Aircraft Dynamics & Control", section 2.2
@author Mathias Froehlich
- @version $Id: FGLocation.h,v 1.34 2014/11/30 12:35:32 bcoconni Exp $
+ @version $Id: FGLocation.h,v 1.35 2015/09/20 20:53:13 bcoconni Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@see IncrementEarthPositionAngle */
const FGMatrix33& GetTl2i(void) const {ComputeDerived(); return mTl2i;}
+ /** Get the geodetic distance between the current location and a given
+ location. This corresponds to the shortest distance between the two
+ locations. Earth curvature is taken into account.
+ @param target_longitude the target longitude
+ @param target_latitude the target latitude
+ @return The geodetic distance between the two locations */
+ double GetDistanceTo(double target_longitude, double target_latitude) const;
+
+ /** Get the heading that should be followed from the current location to
+ a given location along the shortest path. Earth curvature is
+ taken into account.
+ @param target_longitude the target longitude
+ @param target_latitude the target latitude
+ @return The heading that should be followed to reach the targeted
+ location along the shortest path */
+ double GetHeadingTo(double target_longitude, double target_latitude) const;
+
/** Conversion from Local frame coordinates to a location in the
earth centered and fixed frame.
This function calculates the FGLocation of an object which position
void run() {
// initialize
- m_fdm->Initialize(m_fdm->GetIC());
+ m_fdm->Initialize(m_fdm->GetIC());
for (unsigned int i=0; i<m_fdm->GetPropulsion()->GetNumEngines(); i++) {
m_fdm->GetPropulsion()->GetEngine(i)->InitRunning();
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include <string>
-#include <vector>
#include "FGModel.h"
-#include "math/FGColumnVector3.h"
#include "math/FGMatrix33.h"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_AIRCRAFT "$Id: FGAircraft.h,v 1.24 2015/01/31 14:56:21 bcoconni Exp $"
+#define ID_AIRCRAFT "$Id: FGAircraft.h,v 1.25 2015/07/12 19:34:08 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@endcode
@author Jon S. Berndt
- @version $Id: FGAircraft.h,v 1.24 2015/01/31 14:56:21 bcoconni Exp $
+ @version $Id: FGAircraft.h,v 1.25 2015/07/12 19:34:08 bcoconni 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
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGAuxiliary.cpp,v 1.68 2014/12/27 05:41:11 dpculp Exp $");
+IDENT(IdSrc,"$Id: FGAuxiliary.cpp,v 1.70 2015/09/20 20:53:13 bcoconni Exp $");
IDENT(IdHdr,ID_AUXILIARY);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hoverbmac = hoverbcg = 0.0;
Re = 0.0;
Nz = Ny = 0.0;
- lon_relative_position = lat_relative_position = relative_position = 0.0;
vPilotAccel.InitMatrix();
vPilotAccelN.InitMatrix();
hoverbmac = hoverbcg = 0.0;
Re = 0.0;
Nz = Ny = 0.0;
- lon_relative_position = lat_relative_position = relative_position = 0.0;
vPilotAccel.InitMatrix();
vPilotAccelN.InitMatrix();
FGColumnVector3 vMac = in.Tb2l * in.RPBody;
hoverbmac = (in.DistanceAGL + vMac(3)) / in.Wingspan;
- // When all models are executed calculate the distance from the initial point.
- CalculateRelativePosition();
-
return false;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-double FGAuxiliary::GethVRP(void) const
-{
- return vLocationVRP.GetRadius() - in.ReferenceRadius;
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
double FGAuxiliary::GetNlf(void) const
{
if (in.Mass != 0)
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGAuxiliary::CalculateRelativePosition(void) //ToDo: This belongs elsewhere - perhaps in FGPropagate or Exec
+double FGAuxiliary::GetLongitudeRelativePosition(void) const
{
- const double earth_radius_mt = in.ReferenceRadius*fttom;
- lat_relative_position=(in.vLocation.GetLatitude() - FDMExec->GetIC()->GetLatitudeDegIC() *degtorad)*earth_radius_mt;
- lon_relative_position=(in.vLocation.GetLongitude() - FDMExec->GetIC()->GetLongitudeDegIC()*degtorad)*earth_radius_mt;
- relative_position = sqrt(lat_relative_position*lat_relative_position + lon_relative_position*lon_relative_position);
-};
+ FGLocation source(FDMExec->GetIC()->GetLongitudeRadIC(),
+ FDMExec->GetIC()->GetLatitudeRadIC(),
+ in.vLocation.GetSeaLevelRadius());
+ return source.GetDistanceTo(in.vLocation.GetLongitude(),
+ FDMExec->GetIC()->GetLatitudeRadIC()) * fttom;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGAuxiliary::GetLatitudeRelativePosition(void) const
+{
+ FGLocation source(FDMExec->GetIC()->GetLongitudeRadIC(),
+ FDMExec->GetIC()->GetLatitudeRadIC(),
+ in.vLocation.GetSeaLevelRadius());
+ return source.GetDistanceTo(FDMExec->GetIC()->GetLongitudeRadIC(),
+ in.vLocation.GetLatitude()) * fttom;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGAuxiliary::GetDistanceRelativePosition(void) const
+{
+ FGLocation source(FDMExec->GetIC()->GetLongitudeRadIC(),
+ FDMExec->GetIC()->GetLatitudeRadIC(),
+ in.vLocation.GetSeaLevelRadius());
+ return source.GetDistanceTo(in.vLocation.GetLongitude(),
+ in.vLocation.GetLatitude()) * fttom;
+}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_AUXILIARY "$Id: FGAuxiliary.h,v 1.29 2014/12/27 05:41:11 dpculp Exp $"
+#define ID_AUXILIARY "$Id: FGAuxiliary.h,v 1.31 2015/09/20 20:53:13 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
to the JSBSim vPQRdot vector, and the w parameter is equivalent to vPQR.
@author Tony Peden, Jon Berndt
- @version $Id: FGAuxiliary.h,v 1.29 2014/12/27 05:41:11 dpculp Exp $
+ @version $Id: FGAuxiliary.h,v 1.31 2015/09/20 20:53:13 bcoconni Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
const FGColumnVector3& GetAeroUVW (void) const { return vAeroUVW; }
const FGLocation& GetLocationVRP(void) const { return vLocationVRP; }
- double GethVRP(void) const;
+ double GethVRP(void) const { return vLocationVRP.GetAltitudeASL(); }
double GetAeroUVW (int idx) const { return vAeroUVW(idx); }
double Getalpha (void) const { return alpha; }
double Getbeta (void) const { return beta; }
int GetDayOfYear (void) const { return day_of_year; }
double GetSecondsInDay (void) const { return seconds_in_day; }
- double GetLongitudeRelativePosition (void) const { return lon_relative_position; }
- double GetLatitudeRelativePosition (void) const { return lat_relative_position; }
- double GetDistanceRelativePosition (void) const { return relative_position; }
+ double GetLongitudeRelativePosition (void) const;
+ double GetLatitudeRelativePosition (void) const;
+ double GetDistanceRelativePosition (void) const;
void SetAeroPQR(const FGColumnVector3& tt) { vAeroPQR = tt; }
FGColumnVector3 VRPBody;
FGColumnVector3 vFw;
FGLocation vLocation;
- double ReferenceRadius;
double CosTht;
double SinTht;
double CosPhi;
double hoverbcg, hoverbmac;
- // helper data, calculation of distance from initial position
-
- double lon_relative_position;
- double lat_relative_position;
- double relative_position;
-
void UpdateWindMatrices(void);
void CalculateRelativePosition(void);
#include "FGFCS.h"
#include "FGFDMExec.h"
#include "FGGroundReactions.h"
-#include "input_output/FGPropertyManager.h"
#include "input_output/FGXMLElement.h"
#include "input_output/FGModelLoader.h"
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGFCS.cpp,v 1.90 2014/06/09 11:52:07 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGFCS.cpp,v 1.92 2015/07/12 19:34:08 bcoconni Exp $");
IDENT(IdHdr,ID_FCS);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{
int i;
Name = "FGFCS";
+ systype = stFCS;
DaCmd = DeCmd = DrCmd = DsCmd = DfCmd = DsbCmd = DspCmd = 0;
PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
void FGFCS::SetThrottleCmd(int engineNum, double setting)
{
- unsigned int ctr;
-
if (engineNum < (int)ThrottlePos.size()) {
if (engineNum < 0) {
- for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
+ for (unsigned int ctr=0; ctr<ThrottleCmd.size(); ctr++)
+ ThrottleCmd[ctr] = setting;
} else {
ThrottleCmd[engineNum] = setting;
}
void FGFCS::SetThrottlePos(int engineNum, double setting)
{
- unsigned int ctr;
-
if (engineNum < (int)ThrottlePos.size()) {
if (engineNum < 0) {
- for (ctr=0;ctr<ThrottlePos.size();ctr++) ThrottlePos[ctr] = setting;
+ for (unsigned int ctr=0; ctr<ThrottlePos.size(); ctr++)
+ ThrottlePos[ctr] = setting;
} else {
ThrottlePos[engineNum] = setting;
}
void FGFCS::SetMixtureCmd(int engineNum, double setting)
{
- unsigned int ctr;
-
if (engineNum < (int)ThrottlePos.size()) {
if (engineNum < 0) {
- for (ctr=0;ctr<MixtureCmd.size();ctr++) MixtureCmd[ctr] = setting;
+ for (unsigned int ctr=0; ctr<MixtureCmd.size(); ctr++)
+ MixtureCmd[ctr] = setting;
} else {
MixtureCmd[engineNum] = setting;
}
void FGFCS::SetMixturePos(int engineNum, double setting)
{
- unsigned int ctr;
-
if (engineNum < (int)ThrottlePos.size()) {
if (engineNum < 0) {
- for (ctr=0;ctr<MixtureCmd.size();ctr++) MixturePos[ctr] = MixtureCmd[ctr];
+ for (unsigned int ctr=0; ctr<MixtureCmd.size(); ctr++)
+ MixturePos[ctr] = MixtureCmd[ctr];
} else {
MixturePos[engineNum] = setting;
}
void FGFCS::SetPropAdvanceCmd(int engineNum, double setting)
{
- unsigned int ctr;
-
if (engineNum < (int)ThrottlePos.size()) {
if (engineNum < 0) {
- for (ctr=0;ctr<PropAdvanceCmd.size();ctr++) PropAdvanceCmd[ctr] = setting;
+ for (unsigned int ctr=0; ctr<PropAdvanceCmd.size(); ctr++)
+ PropAdvanceCmd[ctr] = setting;
} else {
PropAdvanceCmd[engineNum] = setting;
}
void FGFCS::SetPropAdvance(int engineNum, double setting)
{
- unsigned int ctr;
-
if (engineNum < (int)ThrottlePos.size()) {
if (engineNum < 0) {
- for (ctr=0;ctr<PropAdvanceCmd.size();ctr++) PropAdvance[ctr] = PropAdvanceCmd[ctr];
+ for (unsigned int ctr=0; ctr<PropAdvanceCmd.size(); ctr++)
+ PropAdvance[ctr] = PropAdvanceCmd[ctr];
} else {
PropAdvance[engineNum] = setting;
}
void FGFCS::SetFeatherCmd(int engineNum, bool setting)
{
- unsigned int ctr;
-
if (engineNum < (int)ThrottlePos.size()) {
if (engineNum < 0) {
- for (ctr=0;ctr<PropFeatherCmd.size();ctr++) PropFeatherCmd[ctr] = setting;
+ for (unsigned int ctr=0; ctr<PropFeatherCmd.size(); ctr++)
+ PropFeatherCmd[ctr] = setting;
} else {
PropFeatherCmd[engineNum] = setting;
}
void FGFCS::SetPropFeather(int engineNum, bool setting)
{
- unsigned int ctr;
-
if (engineNum < (int)ThrottlePos.size()) {
if (engineNum < 0) {
- for (ctr=0;ctr<PropFeatherCmd.size();ctr++) PropFeather[ctr] = PropFeatherCmd[ctr];
+ for (unsigned int ctr=0; ctr<PropFeatherCmd.size(); ctr++)
+ PropFeather[ctr] = PropFeatherCmd[ctr];
} else {
PropFeather[engineNum] = setting;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-bool FGFCS::Load(Element* document, SystemType type)
+bool FGFCS::Load(Element* document)
{
- string name, parent_name;
- Element *component_element;
- Element *channel_element;
-
- systype = type;
+ if (document->GetName() == "autopilot") {
+ Name = "Autopilot: ";
+ systype = stAutoPilot;
+ } else if (document->GetName() == "flight_control") {
+ Name = "FCS: ";
+ systype = stFCS;
+ } else if (document->GetName() == "system") {
+ Name = "System: ";
+ systype = stSystem;
+ }
// Load interface properties from document
if (!FGModel::Load(document))
return false;
- name = document->GetAttributeValue("name");
-
- Name = "Flight Control Systems Model: " + document->GetAttributeValue("name");
+ Name += document->GetAttributeValue("name");
- if (document->GetName() == "autopilot") {
- Name = "Autopilot: " + document->GetAttributeValue("name");
- } else if (document->GetName() == "flight_control") {
- Name = "FCS: " + document->GetAttributeValue("name");
- } else if (document->GetName() == "system") {
- Name = "System: " + document->GetAttributeValue("name");
- }
Debug(2);
- if (document->GetName() == "flight_control") bindModel();
+ if (systype == stFCS) bindModel();
- channel_element = document->FindElement("channel");
+ Element* channel_element = document->FindElement("channel");
while (channel_element) {
string sOnOffProperty = channel_element->GetAttributeValue("execute");
string sChannelName = channel_element->GetAttributeValue("name");
- FGPropertyNode* OnOffPropertyNode = 0;
if (sOnOffProperty.length() > 0) {
- OnOffPropertyNode = PropertyManager->GetNode(sOnOffProperty);
+ FGPropertyNode* OnOffPropertyNode = PropertyManager->GetNode(sOnOffProperty);
if (OnOffPropertyNode == 0) {
cerr << highint << fgred
<< "The On/Off property, " << sOnOffProperty << " specified for channel "
cout << endl << highint << fgblue << " Channel "
<< normint << channel_element->GetAttributeValue("name") << reset << endl;
- component_element = channel_element->GetElement();
+ Element* component_element = channel_element->GetElement();
while (component_element) {
try {
if ((component_element->GetName() == string("lag_filter")) ||
} else {
cerr << "Unknown FCS component: " << component_element->GetName() << endl;
}
- } catch(string s) {
+ } catch(string& s) {
cerr << highint << fgred << endl << " " << s << endl;
cerr << reset << endl;
return false;
#include <iosfwd>
#include <vector>
-
#include <string>
-#include "models/flight_control/FGFCSComponent.h"
+
#include "models/FGModel.h"
#include "models/FGLGear.h"
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FCS "$Id: FGFCS.h,v 1.47 2015/02/27 20:36:47 bcoconni Exp $"
+#define ID_FCS "$Id: FGFCS.h,v 1.49 2015/07/12 19:34:08 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@property gear/tailhook-pos-norm
@author Jon S. Berndt
- @version $Revision: 1.47 $
+ @version $Revision: 1.49 $
@see FGActuator
@see FGDeadBand
@see FGFCSFunction
/** Loads the Flight Control System.
Load() is called from FGFDMExec.
@param el pointer to the Element instance
- @param systype type of system (FCS, Autopilot, System)
@return true if succesful */
- bool Load(Element* el, SystemType systype);
+ bool Load(Element* el);
std::string FindFullPathName(const std::string& system_filename) const;
bool GetTrimStatus(void) const { return FDMExec->GetTrimStatus(); }
- struct Inputs {
- unsigned int NumGear;
- } in;
-
private:
double DaCmd, DeCmd, DrCmd, DsCmd, DfCmd, DsbCmd, DspCmd;
double DePos[NForms], DaLPos[NForms], DaRPos[NForms], DrPos[NForms];
class FGFCSChannel {
public:
/// Constructor
- FGFCSChannel(string name, FGPropertyNode* node=0) :
+ FGFCSChannel(std::string name, FGPropertyNode* node=0) :
OnOffNode(node), Name(name)
{
}
FCSComponents.clear();
}
/// Retrieves the name of the channel
- string GetName() {return Name;}
+ std::string GetName() {return Name;}
/// Adds a component to a channel
void Add(FGFCSComponent* comp) {FCSComponents.push_back(comp);}
private:
FCSCompVec FCSComponents;
FGConstPropertyNode_ptr OnOffNode;
- string Name;
+ std::string Name;
};
}
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGInput.cpp,v 1.33 2015/04/08 19:35:00 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGInput.cpp,v 1.34 2015/08/23 09:43:31 bcoconni Exp $");
IDENT(IdHdr,ID_INPUT);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGInput::FGInput(FGFDMExec* fdmex) : FGModel(fdmex)
{
Name = "FGInput";
+ enabled = true;
Debug(0);
}
bool FGInput::Run(bool Holding)
{
+ if (FDMExec->GetTrimStatus()) return true;
if (FGModel::Run(Holding)) return true;
+ if (!enabled) return true;
vector<FGInputType*>::iterator it;
for (it = InputTypes.begin(); it != InputTypes.end(); ++it)
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGInput::Enable(void)
-{
- vector<FGInputType*>::iterator it;
- for (it = InputTypes.begin(); it != InputTypes.end(); ++it)
- (*it)->Enable();
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-void FGInput::Disable(void)
-{
- vector<FGInputType*>::iterator it;
- for (it = InputTypes.begin(); it != InputTypes.end(); ++it)
- (*it)->Disable();
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
bool FGInput::Toggle(int idx)
{
if (idx >= (int)0 && idx < (int)InputTypes.size())
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_INPUT "$Id: FGInput.h,v 1.11 2015/02/15 12:03:21 bcoconni Exp $"
+#define ID_INPUT "$Id: FGInput.h,v 1.13 2015/08/23 09:43:31 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
The class FGInput is the manager of the inputs requested by the user. It
manages a list of instances derived from the abstract class FGInputType.
- @version $Id: FGInput.h,v 1.11 2015/02/15 12:03:21 bcoconni Exp $
+ @version $Id: FGInput.h,v 1.13 2015/08/23 09:43:31 bcoconni Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bool SetDirectivesFile(const std::string& fname);
/// Enables the input generation for all input instances.
- void Enable(void);
+ void Enable(void) { enabled = true; }
/// Disables the input generation for all input instances.
- void Disable(void);
- /** Toggles the input generation for an ouput instances.
+ void Disable(void) { enabled = false; }
+ /** Toggles the input generation of each input instance.
@param idx ID of the input instance which input generation will be
toggled.
@result false if the instance does not exist otherwise returns the status
private:
std::vector<FGInputType*> InputTypes;
+ bool enabled;
void Debug(int from);
};
#include <cstdlib>
#include <cstring>
-#include <sstream>
#include "math/FGFunction.h"
#include "FGLGear.h"
-#include "input_output/FGPropertyManager.h"
#include "models/FGGroundReactions.h"
#include "math/FGTable.h"
#include "input_output/FGXMLElement.h"
GLOBAL DATA
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-IDENT(IdSrc,"$Id: FGLGear.cpp,v 1.118 2014/11/30 12:35:32 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGLGear.cpp,v 1.120 2015/08/16 16:13:31 bcoconni Exp $");
IDENT(IdHdr,ID_LGEAR);
// Body To Structural (body frame is rotated 180 deg about Y and lengths are given in
else
eSteerType = stSteer;
+ Element* castering = el->FindElement("castered");
+ if (castering) {
+ if (castering->GetDataAsNumber() != 0.0) {
+ eSteerType = stCaster;
+ Castered = true;
+ }
+ else {
+ if (maxSteerAngle == 0.0) {
+ eSteerType = stFixed;
+ }
+ else {
+ eSteerType = stSteer;
+ }
+ Castered = false;
+ }
+ }
+
GroundReactions = fdmex->GetGroundReactions();
ForceY_Table = 0;
WheelSlip = 0.0;
// Initialize Lagrange multipliers
- memset(LMultiplier, 0, sizeof(LMultiplier));
+ for (int i=0; i < 3; i++) {
+ LMultiplier[i].ForceJacobian.InitMatrix();
+ LMultiplier[i].MomentJacobian.InitMatrix();
+ LMultiplier[i].Min = 0.0;
+ LMultiplier[i].Max = 0.0;
+ LMultiplier[i].value = 0.0;
+ }
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_MASSBALANCE "$Id: FGMassBalance.h,v 1.35 2015/03/28 14:49:02 bcoconni Exp $"
+#define ID_MASSBALANCE "$Id: FGMassBalance.h,v 1.36 2015/08/22 18:09:00 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONSS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-using std::string;
-
namespace JSBSim {
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
double Weight; /// Weight in pounds.
double Radius; /// Radius in feet.
double Length; /// Length in feet.
- string Name;
+ std::string Name;
FGMatrix33 mPMInertia;
double GetPointMassLocation(int axis) const {return Location(axis);}
esShape GetShapeType(void) {return eShapeType;}
const FGColumnVector3& GetLocation(void) {return Location;}
const FGMatrix33& GetPointMassInertia(void) {return mPMInertia;}
- const string& GetName(void) {return Name;}
+ const std::string& GetName(void) {return Name;}
void SetPointMassLocation(int axis, double value) {Location(axis) = value;}
void SetPointMassWeight(double wt) {
void SetPointMassShapeType(esShape st) {eShapeType = st;}
void SetRadius(double r) {Radius = r;}
void SetLength(double l) {Length = l;}
- void SetName(string name) {Name = name;}
+ void SetName(const std::string& name) {Name = name;}
void SetPointMassMoI(const FGMatrix33& MoI) { mPMInertia = MoI; }
double GetPointMassMoI(int r, int c) {return mPMInertia(r,c);}
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGModel.cpp,v 1.25 2014/06/09 11:52:07 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGModel.cpp,v 1.26 2015/07/12 19:34:08 bcoconni Exp $");
IDENT(IdHdr,ID_MODEL);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
element->SetParent(el);
element = document->FindNextElement();
}
-
- document = el;
}
return result;
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_MODEL "$Id: FGModel.h,v 1.22 2014/06/09 11:52:07 bcoconni Exp $"
+#define ID_MODEL "$Id: FGModel.h,v 1.25 2015/08/16 13:19:52 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
virtual bool Run(bool Holding);
virtual bool InitModel(void);
- virtual void SetRate(int tt) {rate = tt;}
- virtual int GetRate(void) {return rate;}
+ /// Set the ouput rate for the model in frames
+ void SetRate(unsigned int tt) {rate = tt;}
+ /// Get the output rate for the model in frames
+ unsigned int GetRate(void) {return rate;}
FGFDMExec* GetExec(void) {return FDMExec;}
void SetPropertyManager(FGPropertyManager *fgpm) { PropertyManager=fgpm;}
virtual std::string FindFullPathName(const std::string& filename) const;
protected:
- int exe_ctr;
- int rate;
+ unsigned int exe_ctr;
+ unsigned int rate;
/** Loads this model.
@param el a pointer to the element
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGOutput.cpp,v 1.82 2015/04/02 02:20:50 dpculp Exp $");
+IDENT(IdSrc,"$Id: FGOutput.cpp,v 1.86 2015/08/23 09:43:31 bcoconni Exp $");
IDENT(IdHdr,ID_OUTPUT);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
typedef int (FGOutput::*iOPV)(void) const;
Name = "FGOutput";
+ enabled = true;
PropertyManager->Tie("simulation/force-output", this, (iOPV)0, &FGOutput::ForceOutput, false);
bool FGOutput::Run(bool Holding)
{
+ if (FDMExec->GetTrimStatus()) return true;
if (FGModel::Run(Holding)) return true;
+ if (Holding) return false;
+ if (!enabled) return true;
vector<FGOutputType*>::iterator it;
for (it = OutputTypes.begin(); it != OutputTypes.end(); ++it)
- (*it)->Run(Holding);
+ (*it)->Run();
return false;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGOutput::Enable(void)
-{
- vector<FGOutputType*>::iterator it;
- for (it = OutputTypes.begin(); it != OutputTypes.end(); ++it)
- (*it)->Enable();
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-void FGOutput::Disable(void)
-{
- vector<FGOutputType*>::iterator it;
- for (it = OutputTypes.begin(); it != OutputTypes.end(); ++it)
- (*it)->Disable();
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
bool FGOutput::Toggle(int idx)
{
if (idx >= (int)0 && idx < (int)OutputTypes.size())
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGOutput::SetRate(double rate)
+void FGOutput::SetRateHz(double rate)
{
vector<FGOutputType*>::iterator it;
for (it = OutputTypes.begin(); it != OutputTypes.end(); ++it)
- (*it)->SetRate(rate);
+ (*it)->SetRateHz(rate);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Output->SetIdx(idx);
Output->SetOutputName(name);
- Output->SetRate(outRate);
+ Output->SetRateHz(outRate);
Output->SetSubSystems(subSystems);
Output->SetOutputProperties(outputProperties);
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_OUTPUT "$Id: FGOutput.h,v 1.29 2013/11/24 11:40:56 bcoconni Exp $"
+#define ID_OUTPUT "$Id: FGOutput.h,v 1.33 2015/08/23 09:43:31 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
The class FGOutput is the manager of the outputs requested by the user. It
manages a list of instances derived from the abstract class FGOutputType.
- @version $Id: FGOutput.h,v 1.29 2013/11/24 11:40:56 bcoconni Exp $
+ @version $Id: FGOutput.h,v 1.33 2015/08/23 09:43:31 bcoconni Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@return true if the execution succeeded. */
bool SetDirectivesFile(const std::string& fname);
/// Enables the output generation for all output instances.
- void Enable(void);
+ void Enable(void) { enabled = true; }
/// Disables the output generation for all output instances.
- void Disable(void);
- /** Toggles the output generation for an ouput instances.
+ void Disable(void) { enabled = false; }
+ /** Toggles the output generation of each ouput instance.
@param idx ID of the output instance which output generation will be
toggled.
@result false if the instance does not exist otherwise returns the status
bool Toggle(int idx);
/** Modifies the output rate for all output instances.
@param rate new output rate in Hz */
- void SetRate(double rate);
+ void SetRateHz(double rate);
/** Load the output directives and adds a new output instance to the Output
Manager list.
@param el XMLElement that is pointing to the output directives
private:
std::vector<FGOutputType*> OutputTypes;
+ bool enabled;
void Debug(int from);
};
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGPropagate.cpp,v 1.126 2014/11/30 12:35:32 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGPropagate.cpp,v 1.127 2015/08/22 18:09:00 bcoconni Exp $");
IDENT(IdHdr,ID_PROPAGATE);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGPropagate::InitializeDerivatives()
{
- for (int i=0; i<5; i++) {
- VState.dqPQRidot[i] = in.vPQRidot;
- VState.dqUVWidot[i] = in.vUVWidot;
- VState.dqInertialVelocity[i] = VState.vInertialVelocity;
- VState.dqQtrndot[i] = in.vQtrndot;
- }
+ VState.dqPQRidot.assign(5, in.vPQRidot);
+ VState.dqUVWidot.assign(5, in.vUVWidot);
+ VState.dqInertialVelocity.assign(5, VState.vInertialVelocity);
+ VState.dqQtrndot.assign(5, in.vQtrndot);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string filename = FDMExec->GetFullAircraftPath();
- string sim_time = to_string((double)FDMExec->GetSimTime());
if (filename.empty()) filename = "initfile.";
else filename.append("/initfile.");
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_PROPAGATE "$Id: FGPropagate.h,v 1.81 2014/05/17 15:15:53 jberndt Exp $"
+#define ID_PROPAGATE "$Id: FGPropagate.h,v 1.82 2015/08/22 18:09:00 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
namespace JSBSim {
-using std::deque;
class FGInitialCondition;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@endcode
@author Jon S. Berndt, Mathias Froehlich, Bertrand Coconnier
- @version $Id: FGPropagate.h,v 1.81 2014/05/17 15:15:53 jberndt Exp $
+ @version $Id: FGPropagate.h,v 1.82 2015/08/22 18:09:00 bcoconni Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGColumnVector3 vInertialPosition;
- deque <FGColumnVector3> dqPQRidot;
- deque <FGColumnVector3> dqUVWidot;
- deque <FGColumnVector3> dqInertialVelocity;
- deque <FGQuaternion> dqQtrndot;
+ std::deque <FGColumnVector3> dqPQRidot;
+ std::deque <FGColumnVector3> dqUVWidot;
+ std::deque <FGColumnVector3> dqInertialVelocity;
+ std::deque <FGQuaternion> dqQtrndot;
};
/** Constructor.
void SetDistanceAGL(double tt);
void SetDistanceAGLKm(double tt);
- void SetInitialState(const FGInitialCondition *);
+ void SetInitialState(const FGInitialCondition*);
void SetLocation(const FGLocation& l);
void SetLocation(const FGColumnVector3& lv)
{
void Integrate( FGColumnVector3& Integrand,
FGColumnVector3& Val,
- deque <FGColumnVector3>& ValDot,
+ std::deque <FGColumnVector3>& ValDot,
double dt,
eIntegrateType integration_type);
void Integrate( FGQuaternion& Integrand,
FGQuaternion& Val,
- deque <FGQuaternion>& ValDot,
+ std::deque <FGQuaternion>& ValDot,
double dt,
eIntegrateType integration_type);
#include "models/FGPropagate.h"
#include "models/FGAccelerations.h"
#include "models/FGMassBalance.h"
-#include "models/FGInertial.h"
#include "input_output/FGXMLElement.h"
+#include "models/FGFCS.h"
using namespace std;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGAccelerometer.cpp,v 1.15 2014/01/13 10:46:07 ehofman Exp $");
+IDENT(IdSrc,"$Id: FGAccelerometer.cpp,v 1.17 2015/08/09 17:29:48 bcoconni Exp $");
IDENT(IdHdr,ID_ACCELEROMETER);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//aircraft forces
vAccel = (Accelerations->GetBodyAccel()
- + Accelerations->GetPQRidot() * vRadius
- + Propagate->GetPQRi() * (Propagate->GetPQRi() * vRadius));
+ + Accelerations->GetPQRidot() * vRadius
+ + Propagate->GetPQRi() * (Propagate->GetPQRi() * vRadius));
// transform to the specified orientation
vAccel = mT * vAccel;
#include "FGActuator.h"
#include "input_output/FGXMLElement.h"
#include "math/FGRealValue.h"
+#include "models/FGFCS.h"
using namespace std;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGActuator.cpp,v 1.37 2014/08/28 13:44:28 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGActuator.cpp,v 1.38 2015/07/12 19:34:08 bcoconni Exp $");
IDENT(IdHdr,ID_ACTUATOR);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGActuator::FGActuator(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
{
- double denom;
-
// inputs are read from the base class constructor
PreviousOutput = 0.0;
}
if ( element->FindElement("lag") ) {
lag = element->FindElementValueAsNumber("lag");
- denom = 2.00 + dt*lag;
+ double denom = 2.00 + dt*lag;
ca = dt*lag / denom;
cb = (2.00 - dt*lag) / denom;
}
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#include <iostream>
+#include <cstdlib>
+
#include "FGFCSComponent.h"
-#include "input_output/FGPropertyManager.h"
#include "input_output/FGXMLElement.h"
#include "math/FGPropertyValue.h"
-#include <iostream>
-#include <cstdlib>
+#include "models/FGFCS.h"
using namespace std;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGFCSComponent.cpp,v 1.40 2014/01/13 10:46:08 ehofman Exp $");
+IDENT(IdSrc,"$Id: FGFCSComponent.cpp,v 1.41 2015/07/12 19:34:08 bcoconni Exp $");
IDENT(IdHdr,ID_FCSCOMPONENT);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
} else {
InitSigns.push_back( 1.0);
}
- FGPropertyNode* node = 0L;
+
if (PropertyManager->HasNode(init)) {
- node = PropertyManager->GetNode(init);
+ FGPropertyNode* node = PropertyManager->GetNode(init);
InitNodes.push_back(new FGPropertyValue( node ));
} else {
InitNodes.push_back(new FGPropertyValue( init,
} else {
InputSigns.push_back( 1.0);
}
- FGPropertyNode* node = 0L;
+
if (PropertyManager->HasNode(input)) {
- node = PropertyManager->GetNode(input);
+ FGPropertyNode* node = PropertyManager->GetNode(input);
InputNodes.push_back(new FGPropertyValue( node ));
} else {
InputNodes.push_back(new FGPropertyValue( input,
void FGFCSComponent::Debug(int from)
{
- string propsign="";
-
if (debug_lvl <= 0) return;
if (debug_lvl & 1) { // Standard console startup message output
<< "\" of type: " << Type << endl;
if (clip) {
+ string propsign;
+
if (ClipMinPropertyNode != 0L) {
if (clipMinSign < 0.0) propsign="-";
cout << " Minimum limit: " << propsign << ClipMinPropertyNode->GetName() << endl;
- propsign="";
} else {
cout << " Minimum limit: " << clipmin << endl;
}
+
+ propsign="";
+
if (ClipMaxPropertyNode != 0L) {
if (clipMaxSign < 0.0) propsign="-";
cout << " Maximum limit: " << propsign << ClipMaxPropertyNode->GetName() << endl;
- propsign="";
} else {
cout << " Maximum limit: " << clipmax << endl;
}
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#include "FGJSBBase.h"
-#include "math/FGPropertyValue.h"
#include <string>
#include <vector>
+#include "FGJSBBase.h"
+#include "math/FGPropertyValue.h"
+
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_FCSCOMPONENT "$Id: FGFCSComponent.h,v 1.26 2014/02/17 05:33:25 jberndt Exp $"
+#define ID_FCSCOMPONENT "$Id: FGFCSComponent.h,v 1.27 2015/07/12 19:34:08 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
- FGAngle
@author Jon S. Berndt
- @version $Id: FGFCSComponent.h,v 1.26 2014/02/17 05:33:25 jberndt Exp $
+ @version $Id: FGFCSComponent.h,v 1.27 2015/07/12 19:34:08 bcoconni Exp $
@see Documentation for the FGFCS class, and for the configuration file class
*/
} //namespace JSBSim
-#include "../FGFCS.h"
-
#endif
-
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGFilter.cpp,v 1.20 2014/01/13 10:46:09 ehofman Exp $");
+IDENT(IdSrc,"$Id: FGFilter.cpp,v 1.21 2015/09/27 20:26:23 bcoconni Exp $");
IDENT(IdHdr,ID_FILTER);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bool FGFilter::Run(void)
{
- double test = 0.0;
-
if (Initialize) {
- PreviousOutput1 = PreviousInput1 = Output = Input;
+ PreviousOutput2 = PreviousInput2 = PreviousOutput1 = PreviousInput1 = Output = Input;
Initialize = false;
} else {
break;
case eIntegrator:
if (Trigger != 0) {
- test = Trigger->getDoubleValue();
+ double test = Trigger->getDoubleValue();
if (fabs(test) > 0.000001) {
Input = PreviousInput1 = PreviousInput2 = 0.0;
}
#include "FGGyro.h"
#include "models/FGAccelerations.h"
#include "input_output/FGXMLElement.h"
+#include "models/FGFCS.h"
using namespace std;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGGyro.cpp,v 1.10 2014/01/13 10:46:09 ehofman Exp $");
+IDENT(IdSrc,"$Id: FGGyro.cpp,v 1.11 2015/07/12 19:34:08 bcoconni Exp $");
IDENT(IdHdr,ID_GYRO);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include "FGMagnetometer.h"
#include "simgear/magvar/coremag.hxx"
#include "input_output/FGXMLElement.h"
+#include "models/FGFCS.h"
using namespace std;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGMagnetometer.cpp,v 1.9 2014/01/13 10:46:09 ehofman Exp $");
+IDENT(IdSrc,"$Id: FGMagnetometer.cpp,v 1.10 2015/07/12 19:34:08 bcoconni Exp $");
IDENT(IdHdr,ID_MAGNETOMETER);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#include "FGSensor.h"
-#include "input_output/FGXMLElement.h"
#include <iostream>
#include <cstdlib>
+#include "FGSensor.h"
+#include "input_output/FGXMLElement.h"
+
using namespace std;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGSensor.cpp,v 1.27 2014/01/13 10:46:10 ehofman Exp $");
+IDENT(IdSrc,"$Id: FGSensor.cpp,v 1.28 2015/07/12 19:34:08 bcoconni Exp $");
IDENT(IdHdr,ID_SENSOR);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGSensor::FGSensor(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
{
- double denom;
-
// inputs are read from the base class constructor
bits = quantized = divisions = 0;
}
if ( element->FindElement("lag") ) {
lag = element->FindElementValueAsNumber("lag");
- denom = 2.00 + dt*lag;
+ double denom = 2.00 + dt*lag;
ca = dt*lag / denom;
cb = (2.00 - dt*lag) / denom;
}
#include "FGWaypoint.h"
#include "input_output/FGXMLElement.h"
#include "input_output/FGPropertyManager.h"
+#include "math/FGLocation.h"
using namespace std;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGWaypoint.cpp,v 1.5 2014/01/13 10:46:10 ehofman Exp $");
+IDENT(IdSrc,"$Id: FGWaypoint.cpp,v 1.6 2015/09/20 20:53:13 bcoconni Exp $");
IDENT(IdHdr,ID_WAYPOINT);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
target_latitude_unit = 0.017453293;
}
}
- } else {
+ } else
throw("Target latitude is required for waypoint component: "+Name);
- }
if (element->FindElement("target_longitude") ) {
target_longitude_pNode = PropertyManager->GetNode(element->FindElementValue("target_longitude"));
target_longitude_unit = 0.017453293;
}
}
- } else {
+ } else
throw("Target longitude is required for waypoint component: "+Name);
- }
if (element->FindElement("source_latitude") ) {
source_latitude_pNode = PropertyManager->GetNode(element->FindElementValue("source_latitude"));
source_latitude_unit = 0.017453293;
}
}
- } else {
+ } else
throw("Source latitude is required for waypoint component: "+Name);
- }
if (element->FindElement("source_longitude") ) {
source_longitude_pNode = PropertyManager->GetNode(element->FindElementValue("source_longitude"));
source_longitude_unit = 0.017453293;
}
}
- } else {
+ } else
throw("Source longitude is required for waypoint component: "+Name);
- }
- if (element->FindElement("radius")) {
+ if (element->FindElement("radius"))
radius = element->FindElementValueAsNumberConvertTo("radius", "FT");
- } else {
+ else
radius = 21144000; // Radius of Earth in feet.
- }
unit = element->GetAttributeValue("unit");
if (WaypointType == eHeading) {
if (!unit.empty()) {
- if (unit == "DEG") eUnit = eDeg;
- else if (unit == "RAD") eUnit = eRad;
- else throw("Unknown unit "+unit+" in HEADING waypoint component, "+Name);
- } else {
+ if (unit == "DEG") eUnit = eDeg;
+ else if (unit == "RAD") eUnit = eRad;
+ else throw("Unknown unit "+unit+" in HEADING waypoint component, "+Name);
+ } else {
eUnit = eRad; // Default is radians if unspecified
}
} else {
if (!unit.empty()) {
- if (unit == "FT") eUnit = eFeet;
- else if (unit == "M") eUnit = eMeters;
- else throw("Unknown unit "+unit+" in DISTANCE waypoint component, "+Name);
+ if (unit == "FT") eUnit = eFeet;
+ else if (unit == "M") eUnit = eMeters;
+ else throw("Unknown unit "+unit+" in DISTANCE waypoint component, "+Name);
} else {
eUnit = eFeet; // Default is feet if unspecified
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-// The calculations, below, implement the Haversine formulas to calculate
-// heading and distance to a set of lat/long coordinates from the current
-// position. The latitude and longitude are expected to be in radian units
-// and are measured from the 0 meridian and the equator, with positive
-// longitude being east from there, and positive latitude being north.
-//
-// The basic equations are (lat1, long1 are source positions; lat2
-// long2 are target positions):
-//
-// R = earth’s radius
-// Δlat = lat2 − lat1
-// Δlong = long2 − long1
-//
-// For the heading angle calculation:
-//
-// θ = atan2(sin(Δlong)∙cos(lat2), cos(lat1)∙sin(lat2) − sin(lat1) ∙cos(lat2)∙cos(Δlong) )
-//
-// For the waypoint distance calculation:
-//
-// a = sin²(Δlat/2) + cos(lat1)∙cos(lat2)∙sin²(Δlong/2)
-// c = 2∙atan2(√a, √(1−a))
-// d = R∙c
bool FGWaypoint::Run(void )
{
- target_latitude = target_latitude_pNode->getDoubleValue() * target_latitude_unit;
- target_longitude = target_longitude_pNode->getDoubleValue() * target_longitude_unit;
- source_latitude = source_latitude_pNode->getDoubleValue() * source_latitude_unit;
- source_longitude = source_longitude_pNode->getDoubleValue() * source_longitude_unit;
-
- double delta_lat_rad = target_latitude - source_latitude;
- double delta_lon_rad = target_longitude - source_longitude;
+ double target_latitude = target_latitude_pNode->getDoubleValue() * target_latitude_unit;
+ double target_longitude = target_longitude_pNode->getDoubleValue() * target_longitude_unit;
+ double source_latitude = source_latitude_pNode->getDoubleValue() * source_latitude_unit;
+ double source_longitude = source_longitude_pNode->getDoubleValue() * source_longitude_unit;
+ FGLocation source(source_longitude, source_latitude, radius);
if (WaypointType == eHeading) { // Calculate Heading
-
- double Y = sin(delta_lon_rad) * cos(target_latitude);
- double X = (cos(source_latitude) * sin(target_latitude))
- - (sin(source_latitude) * cos(target_latitude) * cos(delta_lon_rad));
-
- double heading_to_waypoint_rad = atan2(Y, X);
- if (heading_to_waypoint_rad < 0) heading_to_waypoint_rad += 2.0*M_PI;
+ double heading_to_waypoint_rad = source.GetHeadingTo(target_longitude,
+ target_latitude);
double heading_to_waypoint = 0;
if (eUnit == eDeg) heading_to_waypoint = heading_to_waypoint_rad * radtodeg;
Output = heading_to_waypoint;
} else { // Calculate Distance
-
- double distance_a = pow(sin(delta_lat_rad/2.0), 2.0)
- + (cos(source_latitude) * cos(target_latitude)
- * (pow(sin(delta_lon_rad/2.0), 2.0)));
-
- double wp_distance = 2.0 * radius * atan2(pow(distance_a, 0.5), pow((1.0 - distance_a), 0.5));
+ double wp_distance = source.GetDistanceTo(target_longitude, target_latitude);
if (eUnit == eMeters) {
Output = FeetToMeters(wp_distance);
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_WAYPOINT "$Id: FGWaypoint.h,v 1.1 2013/06/20 04:37:28 jberndt Exp $"
+#define ID_WAYPOINT "$Id: FGWaypoint.h,v 1.3 2015/09/20 20:53:13 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
@endcode
@author Jon S. Berndt
- @version $Id: FGWaypoint.h,v 1.1 2013/06/20 04:37:28 jberndt Exp $
+ @version $Id: FGWaypoint.h,v 1.3 2015/09/20 20:53:13 bcoconni Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGPropertyNode_ptr target_longitude_pNode;
FGPropertyNode_ptr source_latitude_pNode;
FGPropertyNode_ptr source_longitude_pNode;
- double target_latitude;
- double target_longitude;
- double source_latitude;
- double source_longitude;
double target_latitude_unit;
double target_longitude_unit;
double source_latitude_unit;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGElectric.cpp,v 1.18 2014/06/08 12:00:35 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGElectric.cpp,v 1.20 2015/09/27 09:54:21 bcoconni Exp $");
IDENT(IdHdr,ID_ELECTRIC);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
FGElectric::FGElectric(FGFDMExec* exec, Element *el, int engine_number, struct FGEngine::Inputs& input)
- : FGEngine(exec, engine_number, input)
+ : FGEngine(engine_number, input)
{
- string token;
-
Load(exec,el);
Type = etElectric;
if (el->FindElement("power"))
PowerWatts = el->FindElementValueAsNumberConvertTo("power","WATTS");
- string property_name, base_property_name;
- base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
- property_name = base_property_name + "/power-hp";
- PropertyManager->Tie(property_name, &HP);
+ string base_property_name = CreateIndexedPropertyName("propulsion/engine",
+ EngineNumber);
+ exec->GetPropertyManager()->Tie(base_property_name + "/power-hp", &HP);
Debug(0); // Call Debug() routine from constructor if needed
}
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGEngine.cpp,v 1.62 2015/02/27 20:42:55 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGEngine.cpp,v 1.67 2015/09/27 09:54:21 bcoconni Exp $");
IDENT(IdHdr,ID_ENGINE);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-FGEngine::FGEngine(FGFDMExec* exec, int engine_number, struct Inputs& input)
+FGEngine::FGEngine(int engine_number, struct Inputs& input)
: in(input), EngineNumber(engine_number)
{
- Name = "";
Type = etUnknown;
X = Y = Z = 0.0;
EnginePitch = EngineYaw = 0.0;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGEngine::LoadThruster(Element *thruster_element)
+void FGEngine::LoadThruster(FGFDMExec* exec, Element *thruster_element)
{
if (thruster_element->FindElement("propeller")) {
Element *document = thruster_element->FindElement("propeller");
- Thruster = new FGPropeller(FDMExec, document, EngineNumber);
+ Thruster = new FGPropeller(exec, document, EngineNumber);
} else if (thruster_element->FindElement("nozzle")) {
Element *document = thruster_element->FindElement("nozzle");
- Thruster = new FGNozzle(FDMExec, document, EngineNumber);
+ Thruster = new FGNozzle(exec, document, EngineNumber);
} else if (thruster_element->FindElement("rotor")) {
Element *document = thruster_element->FindElement("rotor");
- Thruster = new FGRotor(FDMExec, document, EngineNumber);
+ Thruster = new FGRotor(exec, document, EngineNumber);
} else if (thruster_element->FindElement("direct")) {
Element *document = thruster_element->FindElement("direct");
- Thruster = new FGThruster( FDMExec, document, EngineNumber);
+ Thruster = new FGThruster(exec, document, EngineNumber);
} else {
cerr << thruster_element->ReadFrom() << " Unknown thruster type" << endl;
throw("Failed to load the thruster");
}
- Thruster->SetdeltaT(in.TotalDeltaT);
-
Debug(2);
}
Element* local_element;
FGColumnVector3 location, orientation;
- FDMExec = exec;
-
- PropertyManager = FDMExec->GetPropertyManager();
+ FGPropertyManager* PropertyManager = exec->GetPropertyManager();
Name = engine_element->GetAttributeValue("name");
local_element = parent_element->FindElement("thruster");
if (local_element) {
try {
- LoadThruster(local_element);
- } catch (std::string str) {
+ LoadThruster(exec, local_element);
+ } catch (std::string& str) {
throw("Error loading engine " + Name + ". " + str);
}
} else {
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_ENGINE "$Id: FGEngine.h,v 1.44 2015/03/28 14:49:02 bcoconni Exp $"
+#define ID_ENGINE "$Id: FGEngine.h,v 1.47 2015/09/27 10:16:57 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
documentation for engine and thruster classes.
</pre>
@author Jon S. Berndt
- @version $Id: FGEngine.h,v 1.44 2015/03/28 14:49:02 bcoconni Exp $
+ @version $Id: FGEngine.h,v 1.47 2015/09/27 10:16:57 bcoconni Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{
public:
struct Inputs {
- double SLPressure;
double Pressure;
double PressureRatio;
double Temperature;
double DensityRatio;
double Soundspeed;
double TotalPressure;
- double TotalTempearture;
double TAT_c;
double Vt;
double Vc;
double TotalDeltaT;
};
- FGEngine(FGFDMExec* exec, int engine_number, struct Inputs& input);
+ FGEngine(int engine_number, struct Inputs& input);
virtual ~FGEngine();
enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etTurboprop, etElectric};
virtual const FGColumnVector3& GetBodyForces(void);
virtual const FGColumnVector3& GetMoments(void);
- void LoadThruster(Element *el);
+ void LoadThruster(FGFDMExec* exec, Element *el);
FGThruster* GetThruster(void) const {return Thruster;}
unsigned int GetSourceTank(unsigned int i) const;
void LoadThrusterInputs();
protected:
- /** Reduces the fuel in the active tanks by the amount required.
- This function should be called from within the
- derived class' Calculate() function before any other calculations are
- done. This base class method removes fuel from the fuel tanks as
- appropriate, and sets the starved flag if necessary. * /
- virtual void ConsumeFuel(void); */
-
- FGPropertyManager* PropertyManager;
+
std::string Name;
const int EngineNumber;
EngineType Type;
double FuelUsedLbs;
double FuelDensity;
- FGFDMExec* FDMExec;
- FGThruster* Thruster;
+ FGThruster* Thruster;
std::vector <int> SourceTanks;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGPiston.cpp,v 1.79 2015/02/27 20:36:47 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGPiston.cpp,v 1.81 2015/09/27 09:54:21 bcoconni Exp $");
IDENT(IdHdr,ID_PISTON);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number, struct Inputs& input)
- : FGEngine(exec, engine_number, input),
+ : FGEngine(engine_number, input),
R_air(287.3), // Gas constant for air J/Kg/K
calorific_value_fuel(47.3e6), // J/Kg
Cp_air(1005), // Specific heat (constant pressure) J/Kg/K
Load(exec, el);
Element *table_element;
- string token;
- string name="";
+ FGPropertyManager* PropertyManager = exec->GetPropertyManager();
// Defaults and initializations
}
while((table_element = el->FindNextElement("table")) != 0) {
- name = table_element->GetAttributeValue("name");
+ string name = table_element->GetAttributeValue("name");
try {
if (name == "COMBUSTION") {
Lookup_Combustion_Efficiency = new FGTable(PropertyManager, table_element);
} else {
cerr << "Unknown table type: " << name << " in piston engine definition." << endl;
}
- } catch (std::string str) {
+ } catch (std::string& str) {
// Make sure allocated resources are freed before rethrowing.
// (C++ standard guarantees that a null pointer deletion is no-op).
delete Lookup_Combustion_Efficiency;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGPropeller.cpp,v 1.51 2015/04/20 12:12:49 ehofman Exp $");
+IDENT(IdSrc,"$Id: FGPropeller.cpp,v 1.54 2015/09/27 09:29:41 bcoconni Exp $");
IDENT(IdHdr,ID_PROPELLER);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGPropeller::FGPropeller(FGFDMExec* exec, Element* prop_element, int num)
: FGThruster(exec, prop_element, num)
{
- string token;
Element *table_element, *local_element;
string name="";
FGPropertyManager* PropertyManager = exec->GetPropertyManager();
Vinduced = 0.0;
if (prop_element->FindElement("ixx"))
- Ixx = prop_element->FindElementValueAsNumberConvertTo("ixx", "SLUG*FT2");
+ Ixx = max(prop_element->FindElementValueAsNumberConvertTo("ixx", "SLUG*FT2"), 0.001);
Sense_multiplier = 1.0;
if (prop_element->HasAttribute("version"))
Sense_multiplier = -1.0;
if (prop_element->FindElement("diameter"))
- Diameter = prop_element->FindElementValueAsNumberConvertTo("diameter", "FT");
+ Diameter = max(prop_element->FindElementValueAsNumberConvertTo("diameter", "FT"), 0.001);
if (prop_element->FindElement("numblades"))
numBlades = (int)prop_element->FindElementValueAsNumber("numblades");
if (prop_element->FindElement("gearratio"))
- GearRatio = prop_element->FindElementValueAsNumber("gearratio");
+ GearRatio = max(prop_element->FindElementValueAsNumber("gearratio"), 0.001);
if (prop_element->FindElement("minpitch"))
MinPitch = prop_element->FindElementValueAsNumber("minpitch");
if (prop_element->FindElement("maxpitch"))
} else {
cerr << "Unknown table type: " << name << " in propeller definition." << endl;
}
- } catch (std::string str) {
+ } catch (std::string& str) {
throw("Error loading propeller table:" + name + ". " + str);
}
}
FGColumnVector3 localAeroVel = Transform().Transposed() * in.AeroUVW;
double omega, PowerAvailable;
- double Vel = localAeroVel(eU);
+ double Vel = localAeroVel(eU) + Vinduced;
double rho = in.Density;
double RPS = RPM/60.0;
if (omega > 0.0) ExcessTorque = PowerAvailable / omega;
else ExcessTorque = PowerAvailable / 1.0;
- RPM = (RPS + ((ExcessTorque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
+ RPM = (RPS + ((ExcessTorque / Ixx) / (2.0 * M_PI)) * in.TotalDeltaT) * 60.0;
if (RPM < 0.0) RPM = 0.0; // Engine won't turn backwards
{
double cPReq, J;
double rho = in.Density;
- double Vel = in.AeroUVW(eU);
+ double Vel = in.AeroUVW(eU) + Vinduced;
double RPS = RPM / 60.0;
if (RPS != 0.0) J = Vel / (Diameter * RPS);
double dRPM = rpmReq - RPM;
// The pitch of a variable propeller cannot be changed when the RPMs are
// too low - the oil pump does not work.
- if (RPM > 200) Pitch -= dRPM * deltaT;
+ if (RPM > 200) Pitch -= dRPM * in.TotalDeltaT;
if (Pitch < MinPitch) Pitch = MinPitch;
else if (Pitch > MaxPitch) Pitch = MaxPitch;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGRocket.cpp,v 1.37 2014/06/08 12:00:35 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGRocket.cpp,v 1.39 2015/09/27 09:54:21 bcoconni Exp $");
IDENT(IdHdr,ID_ROCKET);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
FGRocket::FGRocket(FGFDMExec* exec, Element *el, int engine_number, struct Inputs& input)
- : FGEngine(exec, engine_number, input), isp_function(0L)
+ : FGEngine(engine_number, input), isp_function(0L), FDMExec(exec)
{
Load(exec, el);
MinThrottle = 0.0;
MaxThrottle = 1.0;
- string base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
-
std::stringstream strEngineNumber;
strEngineNumber << EngineNumber;
- Element* isp_el = el->FindElement("isp");
- Element* isp_func_el=0;
+ FGPropertyManager* PropertyManager = exec->GetPropertyManager();
+ bindmodel(PropertyManager); // Bind model properties first, since they might be needed in functions.
- bindmodel(); // Bind model properties first, since they might be needed in functions.
+ Element* isp_el = el->FindElement("isp");
// Specific impulse may be specified as a constant value or as a function - perhaps as a function of mixture ratio.
if (isp_el) {
- isp_func_el = isp_el->FindElement("function");
+ Element* isp_func_el = isp_el->FindElement("function");
if (isp_func_el) {
isp_function = new FGFunction(exec->GetPropertyManager(),isp_func_el, strEngineNumber.str());
} else {
// This function should tie properties to rocket engine specific properties
// that are not bound in the base class (FGEngine) code.
//
-void FGRocket::bindmodel()
+void FGRocket::bindmodel(FGPropertyManager* PropertyManager)
{
string property_name, base_property_name;
base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_ROCKET "$Id: FGRocket.h,v 1.20 2013/11/24 11:40:57 bcoconni Exp $"
+#define ID_ROCKET "$Id: FGRocket.h,v 1.22 2015/09/27 09:54:21 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
fuel begins burning and thrust is provided.
@author Jon S. Berndt
- $Id: FGRocket.h,v 1.20 2013/11/24 11:40:57 bcoconni Exp $
+ $Id: FGRocket.h,v 1.22 2015/09/27 09:54:21 bcoconni Exp $
@see FGNozzle,
FGThruster,
FGForce,
@return The vacuum thrust in lbs. */
double GetVacThrust(void) const {return VacThrust;}
- void bindmodel(void);
+ void bindmodel(FGPropertyManager* pm);
double Isp; // Vacuum Isp
double It; // Total actual Isp
double BuildupTime;
FGTable* ThrustTable;
FGFunction* isp_function;
+ FGFDMExec* FDMExec;
void Debug(int from);
};
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#include <string>
#include <sstream>
#include "FGRotor.h"
using std::cerr;
using std::cout;
using std::endl;
+using std::string;
using std::ostringstream;
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGRotor.cpp,v 1.23 2014/01/13 10:46:10 ehofman Exp $");
+IDENT(IdSrc,"$Id: FGRotor.cpp,v 1.24 2015/09/27 10:03:53 bcoconni Exp $");
IDENT(IdHdr,ID_ROTOR);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// initialise/set remaining variables
SetTransformType(FGForce::tCustom);
- PropertyManager = exec->GetPropertyManager();
Type = ttRotor;
GearRatio = 1.0;
damp_hagl = Filter(1.0, dt);
// enable import-export
- BindModel();
+ bindmodel(exec->GetPropertyManager());
Debug(0);
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-bool FGRotor::BindModel(void)
+bool FGRotor::bindmodel(FGPropertyManager* PropertyManager)
{
string property_name, base_property_name;
base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNum);
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_ROTOR "$Id: FGRotor.h,v 1.15 2013/01/26 17:06:50 bcoconni Exp $"
+#define ID_ROTOR "$Id: FGRotor.h,v 1.17 2015/09/27 10:03:53 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
</dl>
@author Thomas Kreitler
- @version $Id: FGRotor.h,v 1.15 2013/01/26 17:06:50 bcoconni Exp $
+ @version $Id: FGRotor.h,v 1.17 2015/09/27 10:03:53 bcoconni Exp $
*/
FGColumnVector3 body_moments(double a_ic = 0.0 , double b_ic = 0.0 );
// interface
- bool BindModel(void);
+ bool bindmodel(FGPropertyManager* pm);
void Debug(int from);
// environment
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGThruster.cpp,v 1.21 2014/01/13 10:46:10 ehofman Exp $");
+IDENT(IdSrc,"$Id: FGThruster.cpp,v 1.22 2015/09/27 10:03:53 bcoconni Exp $");
IDENT(IdHdr,ID_THRUSTER);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GearRatio = 1.0;
EngineNum = num;
- PropertyManager = FDMExec->GetPropertyManager();
+ FGPropertyManager* PropertyManager = FDMExec->GetPropertyManager();
// Determine the initial location and orientation of this thruster and load the
// thruster with this information.
DEFINITIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-#define ID_THRUSTER "$Id: FGThruster.h,v 1.22 2013/12/22 17:14:37 bcoconni Exp $"
+#define ID_THRUSTER "$Id: FGThruster.h,v 1.26 2015/09/27 10:03:53 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
1.57 (pi/2) results in no thrust at all.
@author Jon Berndt
- @version $Id: FGThruster.h,v 1.22 2013/12/22 17:14:37 bcoconni Exp $
+ @version $Id: FGThruster.h,v 1.26 2015/09/27 10:03:53 bcoconni Exp $
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
virtual void SetRPM(double rpm) {};
virtual void SetEngineRPM(double rpm) {};
virtual double GetPowerRequired(void) {return 0.0;}
- virtual void SetdeltaT(double dt) {deltaT = dt;}
double GetThrust(void) const {return Thrust;}
eType GetType(void) {return Type;}
std::string GetName(void) {return Name;}
std::string Name;
double Thrust;
double PowerRequired;
- double deltaT;
double GearRatio;
double ThrustCoeff;
double ReverserAngle;
int EngineNum;
- FGPropertyManager* PropertyManager;
virtual void Debug(int from);
};
}
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGTurbine.cpp,v 1.44 2014/12/12 01:21:17 dpculp Exp $");
+IDENT(IdSrc,"$Id: FGTurbine.cpp,v 1.47 2015/09/27 10:07:53 bcoconni Exp $");
IDENT(IdHdr,ID_TURBINE);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FGTurbine::FGTurbine(FGFDMExec* exec, Element *el, int engine_number, struct Inputs& input)
- : FGEngine(exec, engine_number, input)
+ : FGEngine(engine_number, input), FDMExec(exec)
{
Type = etTurbine;
Stalled = Seized = Overtemp = Fire = Augmentation = Injection = Reversed = false;
Cutoff = true;
phase = tpOff;
- TAT = (in.TotalTempearture - 491.69) * 0.5555556;
- EGT_degC = TAT;
- OilTemp_degK = TAT + 273.0;
+ EGT_degC = in.TAT_c;
+ OilTemp_degK = in.TAT_c + 273.0;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ThrottlePos = in.ThrottlePos[EngineNumber];
- TAT = (in.TotalTempearture - 491.69) * 0.5555556;
if (ThrottlePos > 1.0) {
AugmentCmd = ThrottlePos - 1.0;
ThrottlePos -= AugmentCmd;
} else {
phase = tpOff;
Cutoff = true;
- EGT_degC = TAT;
+ EGT_degC = in.TAT_c;
}
}
FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
N1 = Seek(&N1, in.qbar/10.0, N1/2.0, N1/2.0);
N2 = Seek(&N2, in.qbar/15.0, N2/2.0, N2/2.0);
- EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
- OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
+ EGT_degC = Seek(&EGT_degC, in.TAT_c, 11.7, 7.3);
+ OilTemp_degK = Seek(&OilTemp_degK, in.TAT_c + 273.0, 0.2, 0.2);
OilPressure_psi = N2 * 0.62;
NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
EPR = Seek(&EPR, 1.0, 0.2, 0.2);
N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, spoolup, spoolup * 2.4);
N2norm = (N2 - IdleN2) / N2_factor;
thrust = idlethrust + (milthrust * N2norm * N2norm);
- EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
+ EGT_degC = in.TAT_c + 363.1 + ThrottlePos * 357.1;
OilPressure_psi = N2 * 0.62;
OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
FuelFlow_pph = 0.0;
N2 = Seek(&N2, 25.18, N2_spinup, N2/2.0);
N1 = Seek(&N1, 5.21, N1_spinup, N1/2.0);
- EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
+ EGT_degC = Seek(&EGT_degC, in.TAT_c, 11.7, 7.3);
OilPressure_psi = N2 * 0.62;
- OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
+ OilTemp_degK = Seek(&OilTemp_degK, in.TAT_c + 273.0, 0.2, 0.2);
EPR = 1.0;
NozzlePosition = 1.0;
if (Starter == false) phase = tpOff;
if (N2 < IdleN2) {
N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
- EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
+ EGT_degC = Seek(&EGT_degC, in.TAT_c + 363.1, 21.3, 7.3);
FuelFlow_pph = IdleFF * N2 / IdleN2;
OilPressure_psi = N2 * 0.62;
if ((Starter == false) && (in.qbar < 30.0)) phase = tpOff; // aborted start
double FGTurbine::Stall(void)
{
- EGT_degC = TAT + 903.14;
+ EGT_degC = in.TAT_c + 903.14;
FuelFlow_pph = IdleFF;
N1 = Seek(&N1, in.qbar/10.0, 0, N1/10.0);
N2 = Seek(&N2, in.qbar/15.0, 0, N2/10.0);
N1 = Seek(&N1, in.qbar/20.0, 0, N1/15.0);
FuelFlow_pph = Cutoff ? 0.0 : IdleFF;
OilPressure_psi = 0.0;
- OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
+ OilTemp_degK = Seek(&OilTemp_degK, in.TAT_c + 273.0, 0, 0.2);
Running = false;
return 0.0;
}
double FGTurbine::Trim()
{
- double idlethrust, milthrust, thrust, tdiff, N2, N2norm;
- idlethrust = MilThrust * IdleThrustLookup->GetValue();
- milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
- N2 = IdleN2 + ThrottlePos * N2_factor;
- N2norm = (N2 - IdleN2) / N2_factor;
- thrust = (idlethrust + (milthrust * N2norm * N2norm))
+ double idlethrust = MilThrust * IdleThrustLookup->GetValue();
+ double milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
+ double N2 = IdleN2 + ThrottlePos * N2_factor;
+ double N2norm = (N2 - IdleN2) / N2_factor;
+ double thrust = (idlethrust + (milthrust * N2norm * N2norm))
* (1.0 - BleedDemand);
if (AugMethod == 1) {
if (AugMethod == 2) {
if (AugmentCmd > 0.0) {
- tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
+ double tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
thrust += (tdiff * AugmentCmd);
}
}
delay = 90.0 / (BypassRatio + 3.0);
N1_factor = MaxN1 - IdleN1;
N2_factor = MaxN2 - IdleN2;
- OilTemp_degK = (in.TotalTempearture - 491.69) * 0.5555556 + 273.0;
+ OilTemp_degK = in.TAT_c + 273.0;
IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
- bindmodel();
+ bindmodel(exec->GetPropertyManager());
return true;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGTurbine::bindmodel()
+void FGTurbine::bindmodel(FGPropertyManager* PropertyManager)
{
string property_name, base_property_name;
base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
#include "FGEngine.h"
-#define ID_TURBINE "$Id: FGTurbine.h,v 1.23 2014/12/12 01:21:17 dpculp Exp $"
+#define ID_TURBINE "$Id: FGTurbine.h,v 1.26 2015/09/27 10:07:53 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
/engine/direct.xml
</pre>
@author David P. Culp
- @version "$Id: FGTurbine.h,v 1.23 2014/12/12 01:21:17 dpculp Exp $"
+ @version "$Id: FGTurbine.h,v 1.26 2015/09/27 10:07:53 bcoconni Exp $"
*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
double N2_factor; ///< factor to tie N2 and throttle
double ThrottlePos; ///< FCS-supplied throttle position - modified for local use!
double AugmentCmd; ///< modulated afterburner command (0.0 to 1.0)
- double TAT; ///< total air temperature (deg C)
double N1_spinup; ///< N1 spin up rate from starter (per second)
double N2_spinup; ///< N2 spin up rate from starter (per second)
bool Stalled; ///< true if engine is compressor-stalled
FGFunction *MilThrustLookup;
FGFunction *MaxThrustLookup;
FGFunction *InjectionLookup;
+ FGFDMExec* FDMExec;
bool Load(FGFDMExec *exec, Element *el);
- void bindmodel(void);
+ void bindmodel(FGPropertyManager* pm);
void Debug(int from);
};
namespace JSBSim {
-IDENT(IdSrc,"$Id: FGTurboProp.cpp,v 1.30 2014/06/08 12:00:35 bcoconni Exp $");
+IDENT(IdSrc,"$Id: FGTurboProp.cpp,v 1.32 2015/09/27 09:54:21 bcoconni Exp $");
IDENT(IdHdr,ID_TURBOPROP);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
FGTurboProp::FGTurboProp(FGFDMExec* exec, Element *el, int engine_number, struct Inputs& input)
- : FGEngine(exec, engine_number, input),
- ITT_N1(NULL), EnginePowerRPM_N1(NULL), EnginePowerVC(NULL), CombustionEfficiency_N1(NULL)
+ : FGEngine(engine_number, input),
+ ITT_N1(NULL), EnginePowerRPM_N1(NULL), EnginePowerVC(NULL), CombustionEfficiency_N1(NULL),
+ FDMExec(exec)
{
FGEngine::Load(exec, el);
SetDefaults();
thrusterType = Thruster->GetType();
Load(exec, el);
- bindmodel();
+ bindmodel(exec->GetPropertyManager());
Debug(0);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGTurboProp::bindmodel()
+void FGTurboProp::bindmodel(FGPropertyManager* PropertyManager)
{
string property_name, base_property_name;
base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
#include "FGEngine.h"
#include "math/FGTable.h"
-#define ID_TURBOPROP "$Id: FGTurboProp.h,v 1.19 2015/02/27 20:36:48 bcoconni Exp $"
+#define ID_TURBOPROP "$Id: FGTurboProp.h,v 1.21 2015/09/27 09:54:21 bcoconni Exp $"
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FORWARD DECLARATIONS
void SetDefaults(void);
bool Load(FGFDMExec *exec, Element *el);
- void bindmodel(void);
+ void bindmodel(FGPropertyManager* pm);
void Debug(int from);
FGTable* ITT_N1; // ITT temperature depending on throttle command
FGTable* EnginePowerRPM_N1;
FGTable* EnginePowerVC;
FGTable* CombustionEfficiency_N1;
+ FGFDMExec* FDMExec;
};
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%