From 02174a1df6d4de4e374f1aa847219d5257e6fb24 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Wed, 6 Apr 2016 14:26:30 +0200 Subject: [PATCH] Add the latest fixes and expose all inertias in the property tree --- src/FDM/JSBSim/FGFDMExec.cpp | 6 +-- src/FDM/JSBSim/input_output/FGScript.cpp | 4 +- src/FDM/JSBSim/input_output/FGfdmSocket.h | 2 +- src/FDM/JSBSim/models/FGAccelerations.cpp | 4 +- src/FDM/JSBSim/models/FGFCS.cpp | 27 ++++++---- src/FDM/JSBSim/models/FGFCS.h | 8 +-- src/FDM/JSBSim/models/FGFCSChannel.h | 52 ++++++++++++++++--- src/FDM/JSBSim/models/FGMassBalance.cpp | 19 +++++-- src/FDM/JSBSim/models/FGMassBalance.h | 9 +++- .../models/flight_control/FGFCSComponent.cpp | 17 +++--- .../models/flight_control/FGFCSComponent.h | 7 +-- 11 files changed, 111 insertions(+), 44 deletions(-) mode change 100644 => 100755 src/FDM/JSBSim/input_output/FGScript.cpp mode change 100644 => 100755 src/FDM/JSBSim/models/FGFCSChannel.h diff --git a/src/FDM/JSBSim/FGFDMExec.cpp b/src/FDM/JSBSim/FGFDMExec.cpp index 14a9b2f4f..2aaf597dd 100644 --- a/src/FDM/JSBSim/FGFDMExec.cpp +++ b/src/FDM/JSBSim/FGFDMExec.cpp @@ -72,7 +72,7 @@ using namespace std; namespace JSBSim { -IDENT(IdSrc,"$Id: FGFDMExec.cpp,v 1.186 2016/01/10 16:32:26 bcoconni Exp $"); +IDENT(IdSrc,"$Id: FGFDMExec.cpp,v 1.187 2016/01/31 11:12:59 bcoconni Exp $"); IDENT(IdHdr,ID_FDMEXEC); /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -612,12 +612,12 @@ void FGFDMExec::ResetToInitialConditions(int mode) Models[i]->InitModel(); } - RunIC(); - if (Script) Script->ResetEvents(); else Setsim_time(0.0); + + RunIC(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/input_output/FGScript.cpp b/src/FDM/JSBSim/input_output/FGScript.cpp old mode 100644 new mode 100755 index 61b5acdf7..a3a7e32aa --- a/src/FDM/JSBSim/input_output/FGScript.cpp +++ b/src/FDM/JSBSim/input_output/FGScript.cpp @@ -58,7 +58,7 @@ using namespace std; namespace JSBSim { -IDENT(IdSrc,"$Id: FGScript.cpp,v 1.63 2015/09/28 21:14:15 bcoconni Exp $"); +IDENT(IdSrc,"$Id: FGScript.cpp,v 1.64 2016/04/03 17:10:46 bcoconni Exp $"); IDENT(IdHdr,ID_FGSCRIPT); /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -353,7 +353,7 @@ bool FGScript::LoadScript(const string& script, double default_dT, void FGScript::ResetEvents(void) { - //LocalProperties.ResetToIC(); + LocalProperties.ResetToIC(); FDMExec->Setsim_time(StartTime); for (unsigned int i=0; iGetName() << endl; + ChannelRate = SystemChannels[i]->GetRate(); SystemChannels[i]->Execute(); } + ChannelRate = 1; RunPostFunctions(); @@ -511,20 +513,24 @@ bool FGFCS::Load(Element* document) string sOnOffProperty = channel_element->GetAttributeValue("execute"); string sChannelName = channel_element->GetAttributeValue("name"); + + int Rate = 0; + if (!channel_element->GetAttributeValue("execrate").empty()) + Rate = channel_element->GetAttributeValueAsNumber("execrate"); + if (sOnOffProperty.length() > 0) { FGPropertyNode* OnOffPropertyNode = PropertyManager->GetNode(sOnOffProperty); if (OnOffPropertyNode == 0) { - cerr << highint << fgred + cerr << channel_element->ReadFrom() << highint << fgred << "The On/Off property, " << sOnOffProperty << " specified for channel " << channel_element->GetAttributeValue("name") << " is undefined or not " << "understood. The simulation will abort" << reset << endl; throw("Bad system definition"); - } else { - newChannel = new FGFCSChannel(sChannelName, OnOffPropertyNode); - } - } else { - newChannel = new FGFCSChannel(sChannelName); - } + } else + newChannel = new FGFCSChannel(this, sChannelName, Rate, + OnOffPropertyNode); + } else + newChannel = new FGFCSChannel(this, sChannelName, Rate); SystemChannels.push_back(newChannel); @@ -690,7 +696,7 @@ void FGFCS::AddGear(unsigned int NumGear) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -double FGFCS::GetDt(void) +double FGFCS::GetDt(void) const { return FDMExec->GetDeltaT()*rate; } @@ -752,6 +758,7 @@ void FGFCS::bind(void) PropertyManager->Tie("gear/tailhook-pos-norm", this, &FGFCS::GetTailhookPos, &FGFCS::SetTailhookPos); PropertyManager->Tie("fcs/wing-fold-pos-norm", this, &FGFCS::GetWingFoldPos, &FGFCS::SetWingFoldPos); + PropertyManager->Tie("simulation/channel-dt", this, &FGFCS::GetChannelDeltaT); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/models/FGFCS.h b/src/FDM/JSBSim/models/FGFCS.h index 9f6543f99..ed291188f 100644 --- a/src/FDM/JSBSim/models/FGFCS.h +++ b/src/FDM/JSBSim/models/FGFCS.h @@ -49,7 +49,7 @@ INCLUDES DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#define ID_FCS "$Id: FGFCS.h,v 1.49 2015/07/12 19:34:08 bcoconni Exp $" +#define ID_FCS "$Id: FGFCS.h,v 1.50 2016/02/27 16:54:15 bcoconni Exp $" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS @@ -167,7 +167,7 @@ CLASS DOCUMENTATION @property gear/tailhook-pos-norm @author Jon S. Berndt - @version $Revision: 1.49 $ + @version $Revision: 1.50 $ @see FGActuator @see FGDeadBand @see FGFCSFunction @@ -557,11 +557,12 @@ public: void AddThrottle(void); void AddGear(unsigned int NumGear); - double GetDt(void); + double GetDt(void) const; FGPropertyManager* GetPropertyManager(void) { return PropertyManager; } bool GetTrimStatus(void) const { return FDMExec->GetTrimStatus(); } + double GetChannelDeltaT(void) const { return GetDt() * ChannelRate; } private: double DaCmd, DeCmd, DrCmd, DsCmd, DfCmd, DsbCmd, DspCmd; @@ -582,6 +583,7 @@ private: double GearCmd,GearPos; double TailhookPos, WingFoldPos; SystemType systype; + int ChannelRate; typedef std::vector Channels; Channels SystemChannels; diff --git a/src/FDM/JSBSim/models/FGFCSChannel.h b/src/FDM/JSBSim/models/FGFCSChannel.h old mode 100644 new mode 100755 index 0eda6711b..154760972 --- a/src/FDM/JSBSim/models/FGFCSChannel.h +++ b/src/FDM/JSBSim/models/FGFCSChannel.h @@ -44,7 +44,7 @@ INCLUDES DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#define ID_FCSCHANNEL "$Id: FGFCSChannel.h,v 1.5 2015/03/28 14:49:02 bcoconni Exp $" +#define ID_FCSCHANNEL "$Id: FGFCSChannel.h,v 1.9 2016/04/03 17:06:24 bcoconni Exp $" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS @@ -59,7 +59,15 @@ CLASS DOCUMENTATION /** Represents a in a control system definition. The may be defined within a , or element. Channels are a way to group sets of components that perform - a specific purpose or algorithm. */ + a specific purpose or algorithm. + Created within a tag, the channel is defined as follows + + name is the name of the channel - in the old way this would also be used to bind elements + execute [optional] is the property that defines when to execute this channel; an on/off switch + execrate [optional] is the rate at which the channel should execute. + A value of 0 or 1 will execute the channel every frame, a value of 2 + every other frame (half rate), a value of 4 is every 4th frame (quarter rate) + */ /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DECLARATION @@ -70,10 +78,15 @@ typedef std::vector FCSCompVec; class FGFCSChannel { public: /// Constructor - FGFCSChannel(std::string name, FGPropertyNode* node=0) : - OnOffNode(node), Name(name) + FGFCSChannel(FGFCS* FCS, const std::string &name, int execRate, + FGPropertyNode* node=0) + : fcs(FCS), OnOffNode(node), Name(name) { + ExecRate = execRate < 1 ? 1 : execRate; + // Set ExecFrameCountSinceLastRun so that each components are initialized + ExecFrameCountSinceLastRun = ExecRate; } + /// Destructor ~FGFCSChannel() { for (unsigned int i=0; iSetDtForFrameCount(ExecRate); + } /// Returns the number of components in the channel. size_t GetNumComponents() {return FCSComponents.size();} /// Retrieves a specific component. @@ -99,22 +115,42 @@ public: void Reset() { for (unsigned int i=0; iResetPastStates(); + + // Set ExecFrameCountSinceLastRun so that each components are initialized + // after a reset. + ExecFrameCountSinceLastRun = ExecRate; } /// Executes all the components in a channel. void Execute() { // If there is an on/off property supplied for this channel, check // the value. If it is true, permit execution to continue. If not, return // and do not execute the channel. - if (OnOffNode != 0) - if (!OnOffNode->getBoolValue()) return; + if (OnOffNode && !OnOffNode->getBoolValue()) return; - for (unsigned int i=0; iRun(); + if (fcs->GetDt() != 0.0) + ++ExecFrameCountSinceLastRun; + + // channel will be run at rate 1 if trimming, or when the next execrate + // frame is reached + if (fcs->GetTrimStatus() || ExecFrameCountSinceLastRun >= ExecRate) { + for (unsigned int i=0; iRun(); + } + + if (ExecFrameCountSinceLastRun >= ExecRate) + ExecFrameCountSinceLastRun = 0; } + /// Get the channel rate + int GetRate(void) const { return ExecRate; } private: + FGFCS* fcs; FCSCompVec FCSComponents; FGConstPropertyNode_ptr OnOffNode; std::string Name; + + int ExecRate; // rate at which this system executes, 0 or 1 every frame, 2 every second frame etc.. + int ExecFrameCountSinceLastRun; }; } diff --git a/src/FDM/JSBSim/models/FGMassBalance.cpp b/src/FDM/JSBSim/models/FGMassBalance.cpp index 7c19bcdaf..33eb377f7 100644 --- a/src/FDM/JSBSim/models/FGMassBalance.cpp +++ b/src/FDM/JSBSim/models/FGMassBalance.cpp @@ -51,7 +51,7 @@ using namespace std; namespace JSBSim { -IDENT(IdSrc,"$Id: FGMassBalance.cpp,v 1.54 2015/12/09 04:28:18 jberndt Exp $"); +IDENT(IdSrc,"$Id: FGMassBalance.cpp,v 1.55 2016/03/26 18:54:27 bcoconni Exp $"); IDENT(IdHdr,ID_MASSBALANCE); /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -258,11 +258,11 @@ bool FGMassBalance::Run(bool Holding) void FGMassBalance::AddPointMass(Element* el) { - double radius=0, length=0; Element* loc_element = el->FindElement("location"); string pointmass_name = el->GetAttributeValue("name"); if (!loc_element) { - cerr << "Pointmass " << pointmass_name << " has no location." << endl; + cerr << el->ReadFrom() << "Pointmass " << pointmass_name + << " has no location." << endl; exit(-1); } @@ -274,6 +274,7 @@ void FGMassBalance::AddPointMass(Element* el) Element* form_element = el->FindElement("form"); if (form_element) { + double radius=0, length=0; string shape = form_element->GetAttributeValue("shape"); Element* radius_element = form_element->FindElement("radius"); Element* length_element = form_element->FindElement("length"); @@ -401,6 +402,18 @@ void FGMassBalance::bind(void) (PMF)&FGMassBalance::GetXYZcg); PropertyManager->Tie("inertia/cg-z-in", this,3, (PMF)&FGMassBalance::GetXYZcg); + PropertyManager->Tie("inertia/ixx-slugs_ft2", this, + &FGMassBalance::GetIxx); + PropertyManager->Tie("inertia/iyy-slugs_ft2", this, + &FGMassBalance::GetIyy); + PropertyManager->Tie("inertia/izz-slugs_ft2", this, + &FGMassBalance::GetIzz); + PropertyManager->Tie("inertia/ixy-slugs_ft2", this, + &FGMassBalance::GetIxy); + PropertyManager->Tie("inertia/ixz-slugs_ft2", this, + &FGMassBalance::GetIxz); + PropertyManager->Tie("inertia/iyz-slugs_ft2", this, + &FGMassBalance::GetIyz); typedef int (FGMassBalance::*iOPV)() const; PropertyManager->Tie("inertia/print-mass-properties", this, (iOPV)0, &FGMassBalance::GetMassPropertiesReport, false); diff --git a/src/FDM/JSBSim/models/FGMassBalance.h b/src/FDM/JSBSim/models/FGMassBalance.h index 56b1f6849..9185322ad 100644 --- a/src/FDM/JSBSim/models/FGMassBalance.h +++ b/src/FDM/JSBSim/models/FGMassBalance.h @@ -48,7 +48,7 @@ INCLUDES DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#define ID_MASSBALANCE "$Id: FGMassBalance.h,v 1.36 2015/08/22 18:09:00 bcoconni Exp $" +#define ID_MASSBALANCE "$Id: FGMassBalance.h,v 1.37 2016/03/26 18:54:27 bcoconni Exp $" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONSS @@ -202,7 +202,12 @@ private: FGColumnVector3 vPMxyz; FGColumnVector3 PointMassCG; const FGMatrix33& CalculatePMInertias(void); - + double GetIxx(void) const { return mJ(1,1); } + double GetIyy(void) const { return mJ(2,2); } + double GetIzz(void) const { return mJ(3,3); } + double GetIxy(void) const { return -mJ(1,2); } + double GetIxz(void) const { return -mJ(1,3); } + double GetIyz(void) const { return -mJ(2,3); } /** The PointMass structure encapsulates a point mass object, moments of inertia mass, location, etc. */ diff --git a/src/FDM/JSBSim/models/flight_control/FGFCSComponent.cpp b/src/FDM/JSBSim/models/flight_control/FGFCSComponent.cpp index 5152a558b..c753259a6 100644 --- a/src/FDM/JSBSim/models/flight_control/FGFCSComponent.cpp +++ b/src/FDM/JSBSim/models/flight_control/FGFCSComponent.cpp @@ -49,7 +49,7 @@ using namespace std; namespace JSBSim { -IDENT(IdSrc,"$Id: FGFCSComponent.cpp,v 1.41 2015/07/12 19:34:08 bcoconni Exp $"); +IDENT(IdSrc,"$Id: FGFCSComponent.cpp,v 1.42 2016/02/27 16:54:15 bcoconni Exp $"); IDENT(IdHdr,ID_FCSCOMPONENT); /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -253,9 +253,9 @@ void FGFCSComponent::SetOutput(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -bool FGFCSComponent::Run(void) +void FGFCSComponent::SetDtForFrameCount(int FrameCount) { - return true; + dt = fcs->GetDt() * FrameCount; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -282,11 +282,12 @@ void FGFCSComponent::Clip(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // -// The old way of naming FCS components allowed upper or lower case, spaces, etc. -// but then the names were modified to fit into a property name heirarchy. This -// was confusing (it wasn't done intentionally - it was a carryover from the early -// design). We now support the direct naming of properties in the FCS component -// name attribute. The old way is supported in code at this time, but deprecated. +// The old way of naming FCS components allowed upper or lower case, spaces, +// etc. but then the names were modified to fit into a property name +// hierarchy. This was confusing (it wasn't done intentionally - it was a +// carryover from the early design). We now support the direct naming of +// properties in the FCS component name attribute. The old way is supported in +// code at this time, but deprecated. void FGFCSComponent::bind(void) { diff --git a/src/FDM/JSBSim/models/flight_control/FGFCSComponent.h b/src/FDM/JSBSim/models/flight_control/FGFCSComponent.h index 70ae0b6e6..18af1ff38 100644 --- a/src/FDM/JSBSim/models/flight_control/FGFCSComponent.h +++ b/src/FDM/JSBSim/models/flight_control/FGFCSComponent.h @@ -47,7 +47,7 @@ INCLUDES DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#define ID_FCSCOMPONENT "$Id: FGFCSComponent.h,v 1.27 2015/07/12 19:34:08 bcoconni Exp $" +#define ID_FCSCOMPONENT "$Id: FGFCSComponent.h,v 1.28 2016/02/27 16:54:16 bcoconni Exp $" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS @@ -83,7 +83,7 @@ CLASS DOCUMENTATION - FGAngle @author Jon S. Berndt - @version $Id: FGFCSComponent.h,v 1.27 2015/07/12 19:34:08 bcoconni Exp $ + @version $Id: FGFCSComponent.h,v 1.28 2016/02/27 16:54:16 bcoconni Exp $ @see Documentation for the FGFCS class, and for the configuration file class */ @@ -99,8 +99,9 @@ public: /// Destructor virtual ~FGFCSComponent(); - virtual bool Run(void); + virtual bool Run(void) { return true; } virtual void SetOutput(void); + void SetDtForFrameCount(int FrameCount); double GetOutput (void) const {return Output;} std::string GetName(void) const {return Name;} std::string GetType(void) const { return Type; }