From 317d794f5c23a8952906d84a02cceda6626e854a Mon Sep 17 00:00:00 2001 From: tony Date: Wed, 20 Mar 2002 12:45:02 +0000 Subject: [PATCH] First commit of properties code. JSBSim now has a basic property tree all under /fdm/jsbsim --- src/FDM/JSBSim/FGAerodynamics.cpp | 104 ++++++++++- src/FDM/JSBSim/FGAerodynamics.h | 17 +- src/FDM/JSBSim/FGAircraft.cpp | 116 ++++++++++++ src/FDM/JSBSim/FGAircraft.h | 49 ++--- src/FDM/JSBSim/FGAtmosphere.cpp | 58 +++++- src/FDM/JSBSim/FGAtmosphere.h | 32 ++-- src/FDM/JSBSim/FGAuxiliary.cpp | 66 +++++-- src/FDM/JSBSim/FGAuxiliary.h | 22 ++- src/FDM/JSBSim/FGCoefficient.cpp | 94 ++++++++-- src/FDM/JSBSim/FGCoefficient.h | 21 ++- src/FDM/JSBSim/FGFCS.cpp | 249 +++++++++++++++++++++++--- src/FDM/JSBSim/FGFCS.h | 162 +++++++---------- src/FDM/JSBSim/FGFDMExec.cpp | 35 +++- src/FDM/JSBSim/FGFDMExec.h | 14 +- src/FDM/JSBSim/FGFactorGroup.cpp | 11 +- src/FDM/JSBSim/FGFactorGroup.h | 2 + src/FDM/JSBSim/FGGroundReactions.cpp | 32 ++++ src/FDM/JSBSim/FGGroundReactions.h | 7 +- src/FDM/JSBSim/FGInertial.cpp | 17 ++ src/FDM/JSBSim/FGInertial.h | 14 +- src/FDM/JSBSim/FGInitialCondition.cpp | 198 +++++++++++++++++++- src/FDM/JSBSim/FGInitialCondition.h | 85 ++++----- src/FDM/JSBSim/FGMassBalance.cpp | 48 ++++- src/FDM/JSBSim/FGMassBalance.h | 19 +- src/FDM/JSBSim/FGModel.cpp | 10 +- src/FDM/JSBSim/FGModel.h | 4 + src/FDM/JSBSim/FGPosition.cpp | 69 ++++++- src/FDM/JSBSim/FGPosition.h | 37 ++-- src/FDM/JSBSim/FGPropulsion.cpp | 43 ++++- src/FDM/JSBSim/FGPropulsion.h | 17 +- src/FDM/JSBSim/FGRotation.cpp | 64 +++++++ src/FDM/JSBSim/FGRotation.h | 32 ++-- src/FDM/JSBSim/FGState.cpp | 235 ++++++++++++++++++++---- src/FDM/JSBSim/FGState.h | 15 +- src/FDM/JSBSim/FGTranslation.cpp | 83 ++++++++- src/FDM/JSBSim/FGTranslation.h | 26 +-- src/FDM/JSBSim/FGTrim.cpp | 33 ++-- src/FDM/JSBSim/FGTrim.h | 16 +- src/FDM/JSBSim/JSBSim.cxx | 27 +-- src/FDM/JSBSim/Makefile.am | 1 + 40 files changed, 1771 insertions(+), 413 deletions(-) diff --git a/src/FDM/JSBSim/FGAerodynamics.cpp b/src/FDM/JSBSim/FGAerodynamics.cpp index c8466f42d..b956f43cb 100644 --- a/src/FDM/JSBSim/FGAerodynamics.cpp +++ b/src/FDM/JSBSim/FGAerodynamics.cpp @@ -39,10 +39,15 @@ INCLUDES #include "FGAerodynamics.h" #include "FGFactorGroup.h" #include "FGCoefficient.h" +#include "FGPropertyManager.h" static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_AERODYNAMICS; +const unsigned NAxes=6; +const char* AxisNames[] = { "drag", "side-force", "lift", "rolling-moment", + "pitching-moment","yawing-moment" }; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -60,6 +65,10 @@ FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec) AxisIdx["YAW"] = 5; Coeff = new CoeffArray[6]; + + clsq=lod=0; + + bind(); Debug(0); } @@ -69,13 +78,16 @@ FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec) FGAerodynamics::~FGAerodynamics() { unsigned int i,j; + + unbind(); + for (i=0; i<6; i++) { for (j=0; jRun(); vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue(); + //cout << Coeff[axis_ctr][ctr]->Getname() << "= " + // << Coeff[axis_ctr][ctr]->TotalValue() << endl; } } //correct signs of drag and lift to wind axes convention //positive forward, right, down - vFs(1)*=-1; vFs(3)*=-1; + if( Translation->Getqbar() > 0) { + clsq = vFs(eLift) / (Aircraft->GetWingArea()*Translation->Getqbar()); + clsq *= clsq; + } + if ( vFs(eDrag) > 0) { + lod = vFs(eLift) / vFs(eDrag); + } + + //correct signs of drag and lift to wind axes convention + //positive forward, right, down + vFs(eDrag)*=-1; vFs(eLift)*=-1; //cout << "Aircraft::vFs: " << vFs << endl; vForces = State->GetTs2b()*vFs; @@ -112,6 +137,7 @@ bool FGAerodynamics::Run(void) for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) { for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) { + //Coeff[axis_ctr+3][ctr]->Run(); vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue(); } } @@ -150,6 +176,8 @@ bool FGAerodynamics::Load(FGConfigFile* AC_cfg) } } + bindModel(); + return true; } @@ -197,11 +225,75 @@ string FGAerodynamics::GetCoefficientValues(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -double FGAerodynamics::GetLoD(void) -{ - if (vFs(1) != 0.00) return vFs(3)/vFs(1); - else return 0.00; +void FGAerodynamics::bind(void){ + + PropertyManager->Tie("forces/fbx-aero-lbs", this,1, + &FGAerodynamics::GetForces); + PropertyManager->Tie("forces/fby-aero-lbs", this,2, + &FGAerodynamics::GetForces); + PropertyManager->Tie("forces/fbz-aero-lbs", this,3, + &FGAerodynamics::GetForces); + PropertyManager->Tie("moments/l-aero-lbsft", this,1, + &FGAerodynamics::GetMoments); + PropertyManager->Tie("moments/m-aero-lbsft", this,2, + &FGAerodynamics::GetMoments); + PropertyManager->Tie("moments/n-aero-lbsft", this,3, + &FGAerodynamics::GetMoments); + PropertyManager->Tie("forces/fwx-aero-lbs", this,1, + &FGAerodynamics::GetvFs); + PropertyManager->Tie("forces/fwy-aero-lbs", this,2, + &FGAerodynamics::GetvFs); + PropertyManager->Tie("forces/fwz-aero-lbs", this,3, + &FGAerodynamics::GetvFs); + PropertyManager->Tie("forces/lod-norm", this, + &FGAerodynamics::GetLoD); + PropertyManager->Tie("aero/cl-squared-norm", this, + &FGAerodynamics::GetClSquared); } + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGAerodynamics::bindModel(void) { + + unsigned i,j; + FGPropertyManager* node; + string prop_name; + + for(i=0;iGetname(); + node= PropertyManager->GetNode(prop_name,true); + Coeff[i][j]->bind(node); + } + } +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGAerodynamics::unbind(void){ + unsigned i,j; + + PropertyManager->Untie("forces/fbx-aero-lbs"); + PropertyManager->Untie("forces/fby-aero-lbs"); + PropertyManager->Untie("forces/fbz-aero-lbs"); + PropertyManager->Untie("moments/l-aero-lbsft"); + PropertyManager->Untie("moments/m-aero-lbsft"); + PropertyManager->Untie("moments/n-aero-lbsft"); + PropertyManager->Untie("forces/fwx-aero-lbs"); + PropertyManager->Untie("forces/fwy-aero-lbs"); + PropertyManager->Untie("forces/fwz-aero-lbs"); + PropertyManager->Untie("forces/lod-norm"); + PropertyManager->Untie("aero/cl-squared-norm"); + + for( i=0; iunbind(); + + } + } +} + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print diff --git a/src/FDM/JSBSim/FGAerodynamics.h b/src/FDM/JSBSim/FGAerodynamics.h index 55905a57f..6d3698e13 100644 --- a/src/FDM/JSBSim/FGAerodynamics.h +++ b/src/FDM/JSBSim/FGAerodynamics.h @@ -112,18 +112,19 @@ public: /** Gets the total aerodynamic force vector. @return a force vector reference. */ FGColumnVector3& GetForces(void) {return vForces;} - inline double GetForces(int n) {return vForces(n);} + inline double GetForces(int n) const {return vForces(n);} /** Gets the total aerodynamic moment vector. @return a moment vector reference. */ FGColumnVector3& GetMoments(void) {return vMoments;} - inline double GetMoments(int n) {return vMoments(n);} + inline double GetMoments(int n) const {return vMoments(n);} inline FGColumnVector3& GetvLastFs(void) { return vLastFs; } - inline double GetvLastFs(int axis) { return vLastFs(axis); } + inline double GetvLastFs(int axis) const { return vLastFs(axis); } inline FGColumnVector3& GetvFs(void) { return vFs; } - inline double GetvFs(int axis) { return vFs(axis); } - double GetLoD(void); + inline double GetvFs(int axis) const { return vFs(axis); } + inline double GetLoD(void) const { return lod; } + inline double GetClSquared(void) const { return clsq; } /** Gets the strings for the current set of coefficients. @return a string containing the descriptive names for all coefficients */ @@ -136,7 +137,10 @@ public: inline FGCoefficient* GetCoefficient(string name) { return cm[name]; } - + void bind(void); + void bindModel(void); + void unbind(void); + private: typedef map AxisIndex; AxisIndex AxisIdx; @@ -149,6 +153,7 @@ private: FGColumnVector3 vMoments; FGColumnVector3 vLastFs; FGColumnVector3 vDXYZcg; + double clsq,lod; void Debug(int from); }; diff --git a/src/FDM/JSBSim/FGAircraft.cpp b/src/FDM/JSBSim/FGAircraft.cpp index 20dd46854..f3e242b32 100644 --- a/src/FDM/JSBSim/FGAircraft.cpp +++ b/src/FDM/JSBSim/FGAircraft.cpp @@ -82,6 +82,7 @@ INCLUDES #include "FGPosition.h" #include "FGAuxiliary.h" #include "FGOutput.h" +#include "FGPropertyManager.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -100,12 +101,16 @@ CLASS IMPLEMENTATION FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex) { + Name = "FGAircraft"; alphaclmin = alphaclmax = 0; HTailArea = VTailArea = HTailArm = VTailArm = 0.0; lbarh = lbarv = vbarh = vbarv = 0.0; WingIncidence=0; impending_stall = 0; + bi2vel=ci2vel=alphaw=0; + + bind(); Debug(0); } @@ -114,6 +119,7 @@ FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex) FGAircraft::~FGAircraft() { + unbind(); Debug(1); } @@ -121,6 +127,8 @@ FGAircraft::~FGAircraft() bool FGAircraft::Run(void) { + double twovel; + if (!FGModel::Run()) { // if false then execute this Run() vForces.InitMatrix(); vForces += Aerodynamics->GetForces(); @@ -140,6 +148,14 @@ bool FGAircraft::Run(void) vNwcg = State->GetTb2s() * vNcg; vNwcg(3) = -1*vNwcg(3) + 1; + twovel=2*Translation->GetVt(); + if(twovel > 0) { + bi2vel = WingSpan / twovel; + ci2vel = cbar / twovel; + } + + alphaw = Translation->Getalpha() + WingIncidence; + if (alphaclmax != 0) { if (Translation->Getalpha() > 0.85*alphaclmax) { impending_stall = 10*(Translation->Getalpha()/alphaclmax - 0.85); @@ -240,6 +256,7 @@ bool FGAircraft::Load(FGConfigFile* AC_cfg) << endl; } else if (parameter == "AC_POINTMASS") { *AC_cfg >> pmWt >> pmX >> pmY >> pmZ; + MassBalance->AddPointMass(pmWt, pmX, pmY, pmZ); if (debug_lvl > 0) cout << " Point Mass Object: " << pmWt << " lbs. at " << "X, Y, Z (in.): " << pmX << " " << pmY << " " << pmZ << endl; @@ -303,3 +320,102 @@ void FGAircraft::Debug(int from) } } +void FGAircraft::bind(void){ + PropertyManager->Tie("metrics/Sw-sqft", this, + &FGAircraft::GetWingArea); + PropertyManager->Tie("metrics/bw-ft", this, + &FGAircraft::GetWingSpan); + PropertyManager->Tie("metrics/cbarw-ft", this, + &FGAircraft::Getcbar); + PropertyManager->Tie("metrics/iw-deg", this, + &FGAircraft::GetWingIncidence); + PropertyManager->Tie("metrics/Sh-sqft", this, + &FGAircraft::GetHTailArea); + PropertyManager->Tie("metrics/lh-ft", this, + &FGAircraft::GetHTailArm); + PropertyManager->Tie("metrics/Sv-sqft", this, + &FGAircraft::GetVTailArea); + PropertyManager->Tie("metrics/lv-ft", this, + &FGAircraft::GetVTailArm); + PropertyManager->Tie("metrics/lh-norm", this, + &FGAircraft::Getlbarh); + PropertyManager->Tie("metrics/lv-norm", this, + &FGAircraft::Getlbarv); + PropertyManager->Tie("metrics/vbarh-norm", this, + &FGAircraft::Getvbarh); + PropertyManager->Tie("metrics/vbarv-norm", this, + &FGAircraft::Getvbarv); + PropertyManager->Tie("moments/l-total-lbsft", this,1, + &FGAircraft::GetMoments); + PropertyManager->Tie("moments/m-total-lbsft", this,2, + &FGAircraft::GetMoments); + PropertyManager->Tie("moments/n-total-lbsft", this,3, + &FGAircraft::GetMoments); + PropertyManager->Tie("forces/fbx-total-lbs", this,1, + &FGAircraft::GetForces); + PropertyManager->Tie("forces/fby-total-lbs", this,2, + &FGAircraft::GetForces); + PropertyManager->Tie("forces/fbz-total-lbs", this,3, + &FGAircraft::GetForces); + PropertyManager->Tie("metrics/aero-rp-x-ft", this,1, + &FGAircraft::GetXYZrp); + PropertyManager->Tie("metrics/aero-rp-y-ft", this,2, + &FGAircraft::GetXYZrp); + PropertyManager->Tie("metrics/aero-rp-z-ft", this,3, + &FGAircraft::GetXYZrp); + PropertyManager->Tie("metrics/eyepoint-x-ft", this,1, + &FGAircraft::GetXYZep); + PropertyManager->Tie("metrics/eyepoint-y-ft", this,2, + &FGAircraft::GetXYZep); + PropertyManager->Tie("metrics/eyepoint-z-ft", this,3, + &FGAircraft::GetXYZep); + PropertyManager->Tie("metrics/alpha-max-deg", this, + &FGAircraft::GetAlphaCLMax, + &FGAircraft::SetAlphaCLMax, + true); + PropertyManager->Tie("metrics/alpha-min-deg", this, + &FGAircraft::GetAlphaCLMin, + &FGAircraft::SetAlphaCLMin, + true); + PropertyManager->Tie("aero/bi2vel", this, + &FGAircraft::GetBI2Vel); + PropertyManager->Tie("aero/ci2vel", this, + &FGAircraft::GetCI2Vel); + PropertyManager->Tie("aero/alpha-wing-rad", this, + &FGAircraft::GetAlphaW); + PropertyManager->Tie("systems/stall-warn-norm", this, + &FGAircraft::GetStallWarn); +} + +void FGAircraft::unbind(void){ + PropertyManager->Untie("metrics/Sw-sqft"); + PropertyManager->Untie("metrics/bw-ft"); + PropertyManager->Untie("metrics/cbarw-ft"); + PropertyManager->Untie("metrics/iw-deg"); + PropertyManager->Untie("metrics/Sh-sqft"); + PropertyManager->Untie("metrics/lh-ft"); + PropertyManager->Untie("metrics/Sv-sqft"); + PropertyManager->Untie("metrics/lv-ft"); + PropertyManager->Untie("metrics/lh-norm"); + PropertyManager->Untie("metrics/lv-norm"); + PropertyManager->Untie("metrics/vbarh-norm"); + PropertyManager->Untie("metrics/vbarv-norm"); + PropertyManager->Untie("moments/l-total-lbsft"); + PropertyManager->Untie("moments/m-total-lbsft"); + PropertyManager->Untie("moments/n-total-lbsft"); + PropertyManager->Untie("forces/fbx-total-lbs"); + PropertyManager->Untie("forces/fby-total-lbs"); + PropertyManager->Untie("forces/fbz-total-lbs"); + PropertyManager->Untie("metrics/aero-rp-x-ft"); + PropertyManager->Untie("metrics/aero-rp-y-ft"); + PropertyManager->Untie("metrics/aero-rp-z-ft"); + PropertyManager->Untie("metrics/eyepoint-x-ft"); + PropertyManager->Untie("metrics/eyepoint-y-ft"); + PropertyManager->Untie("metrics/eyepoint-z-ft"); + PropertyManager->Untie("metrics/alpha-max-deg"); + PropertyManager->Untie("metrics/alpha-min-deg"); + PropertyManager->Untie("aero/bi2vel"); + PropertyManager->Untie("aero/ci2vel"); + PropertyManager->Untie("aero/alpha-wing-rad"); + PropertyManager->Untie("systems/stall-warn-norm"); +} diff --git a/src/FDM/JSBSim/FGAircraft.h b/src/FDM/JSBSim/FGAircraft.h index b9624792d..1a4870c43 100644 --- a/src/FDM/JSBSim/FGAircraft.h +++ b/src/FDM/JSBSim/FGAircraft.h @@ -130,42 +130,50 @@ public: inline string GetAircraftName(void) { return AircraftName; } /// Gets the wing area - inline double GetWingArea(void) { return WingArea; } + double GetWingArea(void) const { return WingArea; } /// Gets the wing span - inline double GetWingSpan(void) { return WingSpan; } + double GetWingSpan(void) const { return WingSpan; } /// Gets the average wing chord - inline double Getcbar(void) { return cbar; } - inline double GetWingIncidence(void) { return WingIncidence; } - inline double GetHTailArea(void) { return HTailArea; } - inline double GetHTailArm(void) { return HTailArm; } - inline double GetVTailArea(void) { return VTailArea; } - inline double GetVTailArm(void) { return VTailArm; } - inline double Getlbarh(void) { return lbarh; } // HTailArm / cbar - inline double Getlbarv(void) { return lbarv; } // VTailArm / cbar - inline double Getvbarh(void) { return vbarh; } // H. Tail Volume - inline double Getvbarv(void) { return vbarv; } // V. Tail Volume + double Getcbar(void) const { return cbar; } + inline double GetWingIncidence(void) const { return WingIncidence; } + inline double GetHTailArea(void) const { return HTailArea; } + inline double GetHTailArm(void) const { return HTailArm; } + inline double GetVTailArea(void) const { return VTailArea; } + inline double GetVTailArm(void) const { return VTailArm; } + inline double Getlbarh(void) const { return lbarh; } // HTailArm / cbar + inline double Getlbarv(void) const { return lbarv; } // VTailArm / cbar + inline double Getvbarh(void) const { return vbarh; } // H. Tail Volume + inline double Getvbarv(void) const { return vbarv; } // V. Tail Volume inline FGColumnVector3& GetMoments(void) { return vMoments; } - inline double GetMoments(int idx) { return vMoments(idx); } + inline double GetMoments(int idx) const { return vMoments(idx); } inline FGColumnVector3& GetForces(void) { return vForces; } - inline double GetForces(int idx) { return vForces(idx); } + inline double GetForces(int idx) const { return vForces(idx); } inline FGColumnVector3& GetBodyAccel(void) { return vBodyAccel; } - inline FGColumnVector3& GetNcg (void) { return vNcg; } + inline FGColumnVector3& GetNcg (void) { return vNcg; } inline FGColumnVector3& GetXYZrp(void) { return vXYZrp; } inline FGColumnVector3& GetXYZep(void) { return vXYZep; } - inline double GetXYZrp(int idx) { return vXYZrp(idx); } - inline double GetXYZep(int idx) { return vXYZep(idx); } - inline double GetAlphaCLMax(void) { return alphaclmax; } - inline double GetAlphaCLMin(void) { return alphaclmin; } + inline double GetXYZrp(int idx) const { return vXYZrp(idx); } + inline double GetXYZep(int idx) const { return vXYZep(idx); } + inline double GetAlphaCLMax(void) const { return alphaclmax; } + inline double GetAlphaCLMin(void) const { return alphaclmin; } inline void SetAlphaCLMax(double tt) { alphaclmax=tt; } inline void SetAlphaCLMin(double tt) { alphaclmin=tt; } inline void SetAircraftName(string name) {AircraftName = name;} - inline double GetStallWarn(void) { return impending_stall; } + inline double GetStallWarn(void) const { return impending_stall; } + + double GetBI2Vel(void) const { return bi2vel; } + double GetCI2Vel(void) const { return ci2vel; } + double GetAlphaW(void) const { return alphaw; } + float GetNlf(void); inline FGColumnVector3& GetNwcg(void) { return vNwcg; } + + void bind(void); + void unbind(void); private: FGColumnVector3 vMoments; @@ -183,6 +191,7 @@ private: double lbarh,lbarv,vbarh,vbarv; double alphaclmax,alphaclmin; double impending_stall; + double bi2vel, ci2vel,alphaw; string AircraftName; void Debug(int from); diff --git a/src/FDM/JSBSim/FGAtmosphere.cpp b/src/FDM/JSBSim/FGAtmosphere.cpp index 3f6f9f2e8..f9094b464 100644 --- a/src/FDM/JSBSim/FGAtmosphere.cpp +++ b/src/FDM/JSBSim/FGAtmosphere.cpp @@ -59,6 +59,7 @@ INCLUDES #include "FGMatrix33.h" #include "FGColumnVector3.h" #include "FGColumnVector4.h" +#include "FGPropertyManager.h" static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_ATMOSPHERE; @@ -86,7 +87,8 @@ FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex) turbType = ttNone; // turbType = ttBerndt; // temporarily disable turbulence until fully tested TurbGain = 100.0; - + + bind(); Debug(0); } @@ -94,6 +96,7 @@ FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex) FGAtmosphere::~FGAtmosphere() { + unbind(); Debug(1); } @@ -346,3 +349,56 @@ void FGAtmosphere::Debug(int from) } } +void FGAtmosphere::bind(void){ + PropertyManager->Tie("atmosphere/T-R", this, + &FGAtmosphere::GetTemperature); + PropertyManager->Tie("atmosphere/rho-slugs_ft3", this, + &FGAtmosphere::GetDensity); + PropertyManager->Tie("atmosphere/P-psf", this, + &FGAtmosphere::GetPressure); + PropertyManager->Tie("atmosphere/a-fps", this, + &FGAtmosphere::GetSoundSpeed); + PropertyManager->Tie("atmosphere/T-sl-R", this, + &FGAtmosphere::GetTemperatureSL); + PropertyManager->Tie("atmosphere/rho-sl-slugs_ft3", this, + &FGAtmosphere::GetDensitySL); + PropertyManager->Tie("atmosphere/P-sl-psf", this, + &FGAtmosphere::GetPressureSL); + PropertyManager->Tie("atmosphere/a-sl-fps", this, + &FGAtmosphere::GetSoundSpeedSL); + PropertyManager->Tie("atmosphere/theta-norm", this, + &FGAtmosphere::GetTemperatureRatio); + PropertyManager->Tie("atmosphere/sigma-norm", this, + &FGAtmosphere::GetDensityRatio); + PropertyManager->Tie("atmosphere/delta-norm", this, + &FGAtmosphere::GetPressureRatio); + PropertyManager->Tie("atmosphere/a-norm", this, + &FGAtmosphere::GetSoundSpeedRatio); + PropertyManager->Tie("atmosphere/psiw-rad", this, + &FGAtmosphere::GetWindPsi); + PropertyManager->Tie("atmosphere/p-turb-rad_sec", this,1, + &FGAtmosphere::GetTurbPQR); + PropertyManager->Tie("atmosphere/q-turb-rad_sec", this,2, + &FGAtmosphere::GetTurbPQR); + PropertyManager->Tie("atmosphere/r-turb-rad_sec", this,3, + &FGAtmosphere::GetTurbPQR); +} + +void FGAtmosphere::unbind(void){ + PropertyManager->Untie("atmosphere/T-R"); + PropertyManager->Untie("atmosphere/rho-slugs_ft3"); + PropertyManager->Untie("atmosphere/P-psf"); + PropertyManager->Untie("atmosphere/a-fps"); + PropertyManager->Untie("atmosphere/T-sl-R"); + PropertyManager->Untie("atmosphere/rho-sl-slugs_ft3"); + PropertyManager->Untie("atmosphere/P-sl-psf"); + PropertyManager->Untie("atmosphere/a-sl-fps"); + PropertyManager->Untie("atmosphere/theta-norm"); + PropertyManager->Untie("atmosphere/sigma-norm"); + PropertyManager->Untie("atmosphere/delta-norm"); + PropertyManager->Untie("atmosphere/a-norm"); + PropertyManager->Untie("atmosphere/psiw-rad"); + PropertyManager->Untie("atmosphere/p-turb-rad_sec"); + PropertyManager->Untie("atmosphere/q-turb-rad_sec"); + PropertyManager->Untie("atmosphere/r-turb-rad_sec"); +} diff --git a/src/FDM/JSBSim/FGAtmosphere.h b/src/FDM/JSBSim/FGAtmosphere.h index f88031280..7cc30a5fa 100644 --- a/src/FDM/JSBSim/FGAtmosphere.h +++ b/src/FDM/JSBSim/FGAtmosphere.h @@ -91,32 +91,32 @@ public: bool InitModel(void); /// Returns the temperature in degrees Rankine. - inline double GetTemperature(void) {return temperature;} + inline double GetTemperature(void) const {return temperature;} /** Returns the density in slugs/ft^3. This function may only be used if Run() is called first. */ - inline double GetDensity(void) {return density;} + inline double GetDensity(void) const {return density;} /// Returns the pressure in psf. - inline double GetPressure(void) {return pressure;} + inline double GetPressure(void) const {return pressure;} /// Returns the speed of sound in ft/sec. - inline double GetSoundSpeed(void) {return soundspeed;} + inline double GetSoundSpeed(void) const {return soundspeed;} /// Returns the sea level temperature in degrees Rankine. - inline double GetTemperatureSL(void) { return SLtemperature; } + inline double GetTemperatureSL(void) const { return SLtemperature; } /// Returns the sea level density in slugs/ft^3 - inline double GetDensitySL(void) { return SLdensity; } + inline double GetDensitySL(void) const { return SLdensity; } /// Returns the sea level pressure in psf. - inline double GetPressureSL(void) { return SLpressure; } + inline double GetPressureSL(void) const { return SLpressure; } /// Returns the sea level speed of sound in ft/sec. - inline double GetSoundSpeedSL(void) { return SLsoundspeed; } + inline double GetSoundSpeedSL(void) const { return SLsoundspeed; } /// Returns the ratio of at-altitude temperature over the sea level value. - inline double GetTemperatureRatio(void) { return temperature*rSLtemperature; } + inline double GetTemperatureRatio(void) const { return temperature*rSLtemperature; } /// Returns the ratio of at-altitude density over the sea level value. - inline double GetDensityRatio(void) { return density*rSLdensity; } + inline double GetDensityRatio(void) const { return density*rSLdensity; } /// Returns the ratio of at-altitude pressure over the sea level value. - inline double GetPressureRatio(void) { return pressure*rSLpressure; } + inline double GetPressureRatio(void) const { return pressure*rSLpressure; } /// Returns the ratio of at-altitude sound speed over the sea level value. - inline double GetSoundSpeedRatio(void) { return soundspeed*rSLsoundspeed; } + inline double GetSoundSpeedRatio(void) const { return soundspeed*rSLsoundspeed; } /// Tells the simulator to use an externally calculated atmosphere model. inline void UseExternal(void) { useExternal=true; } @@ -140,13 +140,17 @@ public: /** Retrieves the wind direction. The direction is defined as north=0 and increases counterclockwise. The wind heading is returned in radians.*/ - inline double GetWindPsi(void) { return psiw; } + inline double GetWindPsi(void) const { return psiw; } inline void SetTurbGain(double tt) {TurbGain = tt;} - inline double GetTurbPQR(int idx) {return vTurbPQR(idx);} + inline double GetTurbPQR(int idx) const {return vTurbPQR(idx);} inline FGColumnVector3& GetTurbPQR(void) {return vTurbPQR;} + void bind(void); + void unbind(void); + + private: double rho; diff --git a/src/FDM/JSBSim/FGAuxiliary.cpp b/src/FDM/JSBSim/FGAuxiliary.cpp index fd8e65a3f..8bdcaffe3 100644 --- a/src/FDM/JSBSim/FGAuxiliary.cpp +++ b/src/FDM/JSBSim/FGAuxiliary.cpp @@ -54,6 +54,7 @@ INCLUDES #include "FGMatrix33.h" #include "FGColumnVector3.h" #include "FGColumnVector4.h" +#include "FGPropertyManager.h" static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_AUXILIARY; @@ -70,6 +71,8 @@ FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex) psl = rhosl = 1; earthPosAngle = 0.0; + vPilotAccelN.InitMatrix(); + Debug(0); } @@ -157,6 +160,7 @@ bool FGAuxiliary::Run() vPilotAccel += Rotation->GetPQRdot() * vToEyePt; vPilotAccel += Rotation->GetPQR() * (Rotation->GetPQR() * vToEyePt); //vPilotAccel(2)*=-1; + vPilotAccelN = vPilotAccel/Inertial->gravity(); } earthPosAngle += State->Getdt()*Inertial->omega(); return false; @@ -193,20 +197,6 @@ double FGAuxiliary::GetCrossWind(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGColumnVector3 FGAuxiliary::GetNpilot(void) -{ - return vPilotAccel/Inertial->gravity(); -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -double FGAuxiliary::GetNpilot(int idx) -{ - return (vPilotAccel/Inertial->gravity())(idx); -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - void FGAuxiliary::GetState(void) { qbar = Translation->Getqbar(); @@ -262,3 +252,51 @@ void FGAuxiliary::Debug(int from) } } +void FGAuxiliary::bind(void){ + PropertyManager->Tie("velocities/vc-fps", this, + &FGAuxiliary::GetVcalibratedFPS); + PropertyManager->Tie("velocities/vc-kts", this, + &FGAuxiliary::GetVcalibratedKTS); + PropertyManager->Tie("velocities/ve-fps", this, + &FGAuxiliary::GetVequivalentFPS); + PropertyManager->Tie("velocities/ve-kts", this, + &FGAuxiliary::GetVequivalentKTS); + PropertyManager->Tie("accelerations/a-pilot-x-ft_sec2", this,1, + &FGAuxiliary::GetPilotAccel); + PropertyManager->Tie("accelerations/a-pilot-y-ft_sec2", this,2, + &FGAuxiliary::GetPilotAccel); + PropertyManager->Tie("accelerations/a-pilot-z-ft_sec2", this,3, + &FGAuxiliary::GetPilotAccel); + PropertyManager->Tie("accelerations/n-pilot-x-norm", this,1, + &FGAuxiliary::GetNpilot); + PropertyManager->Tie("accelerations/n-pilot-y-norm", this,2, + &FGAuxiliary::GetNpilot); + PropertyManager->Tie("accelerations/n-pilot-z-norm", this,3, + &FGAuxiliary::GetNpilot); + PropertyManager->Tie("position/epa-rad", this, + &FGAuxiliary::GetEarthPositionAngle); + /* PropertyManager->Tie("atmosphere/headwind-fps", this, + &FGAuxiliary::GetHeadWind, + true); + PropertyManager->Tie("atmosphere/crosswind-fps", this, + &FGAuxiliary::GetCrossWind, + true); */ + +} + +void FGAuxiliary::unbind(void){ + PropertyManager->Untie("velocities/vc-fps"); + PropertyManager->Untie("velocities/vc-kts"); + PropertyManager->Untie("velocities/ve-fps"); + PropertyManager->Untie("velocities/ve-kts"); + PropertyManager->Untie("accelerations/a-pilot-x-ft_sec2"); + PropertyManager->Untie("accelerations/a-pilot-y-ft_sec2"); + PropertyManager->Untie("accelerations/a-pilot-z-ft_sec2"); + PropertyManager->Untie("accelerations/n-pilot-x-norm"); + PropertyManager->Untie("accelerations/n-pilot-y-norm"); + PropertyManager->Untie("accelerations/n-pilot-z-norm"); + PropertyManager->Untie("position/epa-rad"); + /* PropertyManager->Untie("atmosphere/headwind-fps"); + PropertyManager->Untie("atmosphere/crosswind-fps"); */ + +} diff --git a/src/FDM/JSBSim/FGAuxiliary.h b/src/FDM/JSBSim/FGAuxiliary.h index e0b8a575a..3fed37c1f 100644 --- a/src/FDM/JSBSim/FGAuxiliary.h +++ b/src/FDM/JSBSim/FGAuxiliary.h @@ -85,21 +85,24 @@ public: bool Run(void); // Use FGInitialCondition to set these speeds - inline double GetVcalibratedFPS(void) { return vcas; } - inline double GetVcalibratedKTS(void) { return vcas*fpstokts; } - inline double GetVequivalentFPS(void) { return veas; } - inline double GetVequivalentKTS(void) { return veas*fpstokts; } + inline double GetVcalibratedFPS(void) const { return vcas; } + inline double GetVcalibratedKTS(void) const { return vcas*fpstokts; } + inline double GetVequivalentFPS(void) const { return veas; } + inline double GetVequivalentKTS(void) const { return veas*fpstokts; } inline FGColumnVector3& GetPilotAccel(void) { return vPilotAccel; } - inline double GetPilotAccel(int idx) { return vPilotAccel(idx); } - FGColumnVector3 GetNpilot(void); - double GetNpilot(int idx); + inline double GetPilotAccel(int idx) const { return vPilotAccel(idx); } + FGColumnVector3 GetNpilot(void) const { return vPilotAccelN; } + double GetNpilot(int idx) const { return vPilotAccelN(idx); } - inline double GetEarthPositionAngle(void) { return earthPosAngle; } + inline double GetEarthPositionAngle(void) const { return earthPosAngle; } double GetHeadWind(void); double GetCrossWind(void); - + + void bind(void); + void unbind(void); + private: double vcas; double veas; @@ -114,6 +117,7 @@ private: // isentropic flow equations FGColumnVector3 vPilotAccel; + FGColumnVector3 vPilotAccelN; FGColumnVector3 vToEyePt; double earthPosAngle; diff --git a/src/FDM/JSBSim/FGCoefficient.cpp b/src/FDM/JSBSim/FGCoefficient.cpp index 55639c31f..c75221381 100644 --- a/src/FDM/JSBSim/FGCoefficient.cpp +++ b/src/FDM/JSBSim/FGCoefficient.cpp @@ -47,6 +47,7 @@ INCLUDES #include "FGCoefficient.h" #include "FGState.h" #include "FGFDMExec.h" +#include "FGPropertyManager.h" #ifndef FGFS # if defined(sgi) && !defined(__GNUC__) @@ -72,8 +73,14 @@ FGCoefficient::FGCoefficient( FGFDMExec* fdex ) State = FDMExec->GetState(); Table = 0; + PropertyManager = FDMExec->GetPropertyManager(); + bias=0; gain=1; + + LookupR = LookupC = 0; + + totalValue = 0; if (debug_lvl & 2) cout << "Instantiated: FGCoefficient" << endl; } @@ -91,7 +98,7 @@ FGCoefficient::~FGCoefficient() bool FGCoefficient::Load(FGConfigFile *AC_cfg) { int start, end, n; - string mult; + string mult,prop; if (AC_cfg) { name = AC_cfg->GetValue("NAME"); @@ -115,12 +122,15 @@ bool FGCoefficient::Load(FGConfigFile *AC_cfg) } *AC_cfg >> multparmsRow; - LookupR = State->GetParameterIndex(multparmsRow); + prop = State->GetPropertyName( State->GetParameterIndex(multparmsRow) ); + LookupR = PropertyManager->GetNode( prop ); } if (type == TABLE) { *AC_cfg >> multparmsCol; - LookupC = State->GetParameterIndex(multparmsCol); + prop = State->GetPropertyName( State->GetParameterIndex(multparmsCol) ); + + LookupC = PropertyManager->GetNode( prop ); } // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA @@ -137,11 +147,15 @@ bool FGCoefficient::Load(FGConfigFile *AC_cfg) while (n < end && n >= 0) { n -= start; mult = multparms.substr(start,n); - multipliers.push_back( State->GetParameterIndex(mult) ); + prop= State->GetPropertyName( State->GetParameterIndex(mult) ); + multipliers.push_back( PropertyManager->GetNode(prop) ); start += n+1; n = multparms.find("|",start); } - multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n))); + prop=State->GetPropertyName( + State->GetParameterIndex( multparms.substr(start,n) ) ); + mult = multparms.substr(start,n); + multipliers.push_back( PropertyManager->GetNode(prop) ); // End of non-dimensionalizing parameter read-in } @@ -175,7 +189,7 @@ double FGCoefficient::Value(double rVal, double cVal) for (midx=0; midx < multipliers.size(); midx++) { - Value *= State->GetParameter(multipliers[midx]); + Value *= multipliers[midx]->getDoubleValue(); } return Value; } @@ -189,7 +203,7 @@ double FGCoefficient::Value(double Val) SD = Value = gain*Table->GetValue(Val) + bias; for (unsigned int midx=0; midx < multipliers.size(); midx++) - Value *= State->GetParameter(multipliers[midx]); + Value *= multipliers[midx]->getDoubleValue(); return Value; } @@ -203,28 +217,34 @@ double FGCoefficient::Value(void) SD = Value = gain*StaticValue + bias; for (unsigned int midx=0; midx < multipliers.size(); midx++) - Value *= State->GetParameter(multipliers[midx]); + Value *= multipliers[midx]->getDoubleValue(); return Value; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -double FGCoefficient::TotalValue() +double FGCoefficient::TotalValue(void) { switch(type) { case 0: - return -1; + totalValue=-1; + return totalValue; case 1: - return (Value()); + totalValue=Value(); + return totalValue; case 2: - return (Value(State->GetParameter(LookupR))); + totalValue=Value( LookupR->getDoubleValue() ); + return totalValue; case 3: - return (Value(State->GetParameter(LookupR),State->GetParameter(LookupC))); + totalValue=Value( LookupR->getDoubleValue(), + LookupC->getDoubleValue() ); + return totalValue; case 4: - return 0.0; + totalValue=0.0; + return totalValue; } - return 0; + return totalValue; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -246,7 +266,7 @@ void FGCoefficient::DisplayCoeffFactors(void) cout << "none" << endl; } else { for (i=0; iGetParameterName(multipliers[i]); + cout << multipliers[i]->getName() << " "; } cout << endl; } @@ -263,6 +283,44 @@ string FGCoefficient::GetCoefficientValues(void) return value; } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGCoefficient::bind(FGPropertyManager *node) { + string mult; + unsigned i; + + FGCoefficient::node=node; + + node->SetString("description",description); + if(LookupR) node->SetString("row-parm",LookupR->getName() ); + if(LookupC) node->SetString("column-parm",LookupC->getName() ); + + mult=""; + for (i=0; igetName(); + if( i < multipliers.size()-1 ) mult += "|"; + } + node->SetString("multipliers",mult); + + node->Tie("SD-norm",this,&FGCoefficient::GetSD ); + node->Tie("value-lbs",this,&FGCoefficient::GetValue ); + + node->Tie("bias", this, &FGCoefficient::getBias, + &FGCoefficient::setBias ); + + node->Tie("gain", this, &FGCoefficient::getGain, + &FGCoefficient::setGain ); + +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGCoefficient::unbind(void) { + node->Untie("SD-norm"); + node->Untie("value-lbs"); + node->Untie("bias"); + node->Untie("gain"); +} //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print @@ -298,11 +356,11 @@ void FGCoefficient::Debug(int from) if (type == TABLE) { cout << "Cols: " << columns; } - cout << endl << " Row indexing parameter: " << multparmsRow << endl; + cout << endl << " Row indexing parameter: " << LookupR->getName() << endl; } if (type == TABLE) { - cout << " Column indexing parameter: " << multparmsCol << endl; + cout << " Column indexing parameter: " << LookupC->getName() << endl; } if (type == VALUE) { diff --git a/src/FDM/JSBSim/FGCoefficient.h b/src/FDM/JSBSim/FGCoefficient.h index 7c7083d0b..69e3d1d04 100644 --- a/src/FDM/JSBSim/FGCoefficient.h +++ b/src/FDM/JSBSim/FGCoefficient.h @@ -47,6 +47,7 @@ INCLUDES #include "FGConfigFile.h" #include "FGTable.h" #include "FGJSBBase.h" +#include "FGPropertyManager.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS @@ -103,10 +104,11 @@ public: virtual bool Load(FGConfigFile* AC_cfg); - typedef vector MultVec; + typedef vector MultVec; virtual double TotalValue(void); - virtual inline string Getname(void) {return name;} - virtual inline double GetSD(void) { return SD;} + virtual inline double GetValue(void) const { return totalValue; } + virtual inline string Getname(void) const {return name;} + virtual inline double GetSD(void) const { return SD;} inline MultVec Getmultipliers(void) {return multipliers;} void DumpSD(void); @@ -120,8 +122,11 @@ public: inline void setBias(double b) { bias=b; } inline void setGain(double g) { gain=g; }; - inline double getBias(void) { return bias; } - inline double getGain(void) { return gain; } + inline double getBias(void) const { return bias; } + inline double getGain(void) const { return gain; } + + void bind(FGPropertyManager *node); + void unbind(void); private: enum Type {UNKNOWN, VALUE, VECTOR, TABLE, EQUATION}; @@ -138,8 +143,11 @@ private: double Value(double); double Value(void); double StaticValue; + double totalValue; double bias,gain; - eParam LookupR, LookupC; + FGPropertyManager *LookupR, *LookupC; + FGPropertyManager *node; + MultVec multipliers; int rows, columns; Type type; @@ -156,6 +164,7 @@ private: FGPosition* Position; FGAuxiliary* Auxiliary; FGOutput* Output; + FGPropertyManager* PropertyManager; virtual void Debug(int from); }; diff --git a/src/FDM/JSBSim/FGFCS.cpp b/src/FDM/JSBSim/FGFCS.cpp index a16be4006..adcf66554 100644 --- a/src/FDM/JSBSim/FGFCS.cpp +++ b/src/FDM/JSBSim/FGFCS.cpp @@ -47,6 +47,7 @@ INCLUDES #include "FGPosition.h" #include "FGAuxiliary.h" #include "FGOutput.h" +#include "FGPropertyManager.h" #include "filtersjb/FGFilter.h" #include "filtersjb/FGDeadBand.h" @@ -70,12 +71,17 @@ FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex) DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = 0.0; PTrimCmd = YTrimCmd = RTrimCmd = 0.0; - DaLPos = DaRPos = DePos = DrPos = DfPos = DsbPos = DspPos = 0.0; GearCmd = GearPos = 1; // default to gear down LeftBrake = RightBrake = CenterBrake = 0.0; DoNormalize=true; - for(i=0;i<6;i++) { ToNormalize[i]=-1;} + bind(); + for(i=0;i<=NForms;i++) { + DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0; + DfPos[i] = DsbPos[i] = DspPos[i] = 0.0; + } + + for(i=0;iGetType() == "AEROSURFACE_SCALE" || Components[i]->GetType() == "KINEMAT" ) { if( Components[i]->GetOutputIdx() == FG_ELEVATOR_POS ) { - ToNormalize[iNDe]=i; + ToNormalize[iDe]=i; } else if ( Components[i]->GetOutputIdx() == FG_LEFT_AILERON_POS || Components[i]->GetOutputIdx() == FG_AILERON_POS ) { - ToNormalize[iNDaL]=i; + ToNormalize[iDaL]=i; } else if ( Components[i]->GetOutputIdx() == FG_RIGHT_AILERON_POS ) { - ToNormalize[iNDaR]=i; + ToNormalize[iDaR]=i; } else if ( Components[i]->GetOutputIdx() == FG_RUDDER_POS ) { - ToNormalize[iNDr]=i; + ToNormalize[iDr]=i; } else if ( Components[i]->GetOutputIdx() == FG_SPDBRAKE_POS ) { - ToNormalize[iNDsb]=i; + ToNormalize[iDsb]=i; } else if ( Components[i]->GetOutputIdx() == FG_SPOILERS_POS ) { - ToNormalize[iNDsp]=i; + ToNormalize[iDsp]=i; } else if ( Components[i]->GetOutputIdx() == FG_FLAPS_POS ) { - ToNormalize[iNDf]=i; + ToNormalize[iDf]=i; } } } @@ -407,29 +415,224 @@ void FGFCS::AddThrottle(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGFCS::Normalize(void) { - if( ToNormalize[iNDe] > -1 ) - DePosN = Components[ToNormalize[iNDe]]->GetOutputPct(); - if( ToNormalize[iNDaL] > -1 ) - DaLPosN = Components[ToNormalize[iNDaL]]->GetOutputPct(); + //not all of these are guaranteed to be defined for every model + //those that are have an index >=0 in the ToNormalize array + //ToNormalize is filled in Load() - if( ToNormalize[iNDaR] > -1 ) - DaRPosN = Components[ToNormalize[iNDaR]]->GetOutputPct(); + if( ToNormalize[iDe] > -1 ) { + DePos[ofNorm] = Components[ToNormalize[iDe]]->GetOutputPct(); + } - if( ToNormalize[iNDr] > -1 ) - DrPosN = Components[ToNormalize[iNDr]]->GetOutputPct(); + if( ToNormalize[iDaL] > -1 ) { + DaLPos[ofNorm] = Components[ToNormalize[iDaL]]->GetOutputPct(); + } + + if( ToNormalize[iDaR] > -1 ) { + DaRPos[ofNorm] = Components[ToNormalize[iDaR]]->GetOutputPct(); + } + + if( ToNormalize[iDr] > -1 ) { + DrPos[ofNorm] = Components[ToNormalize[iDr]]->GetOutputPct(); + } - if( ToNormalize[iNDsb] > -1 ) - DsbPosN = Components[ToNormalize[iNDsb]]->GetOutputPct(); + if( ToNormalize[iDsb] > -1 ) { + DsbPos[ofNorm] = Components[ToNormalize[iDsb]]->GetOutputPct(); + } - if( ToNormalize[iNDsp] > -1 ) - DspPosN = Components[ToNormalize[iNDsp]]->GetOutputPct(); + if( ToNormalize[iDsp] > -1 ) { + DspPos[ofNorm] = Components[ToNormalize[iDsp]]->GetOutputPct(); + } - if( ToNormalize[iNDf] > -1 ) - DfPosN = Components[ToNormalize[iNDf]]->GetOutputPct(); + if( ToNormalize[iDf] > -1 ) { + DfPos[ofNorm] = Components[ToNormalize[iDf]]->GetOutputPct(); + } + + DePos[ofMag] = fabs(DePos[ofRad]); + DaLPos[ofMag] = fabs(DaLPos[ofRad]); + DaRPos[ofMag] = fabs(DaRPos[ofRad]); + DrPos[ofMag] = fabs(DrPos[ofRad]); + DsbPos[ofMag] = fabs(DsbPos[ofRad]); + DspPos[ofMag] = fabs(DspPos[ofRad]); + DfPos[ofMag] = fabs(DfPos[ofRad]); } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGFCS::bind(void){ + PropertyManager->Tie("fcs/aileron-cmd-norm", this, + &FGFCS::GetDaCmd, + &FGFCS::SetDaCmd, + true); + PropertyManager->Tie("fcs/elevator-cmd-norm", this, + &FGFCS::GetDeCmd, + &FGFCS::SetDeCmd, + true); + PropertyManager->Tie("fcs/rudder-cmd-norm", this, + &FGFCS::GetDrCmd, + &FGFCS::SetDrCmd, + true); + PropertyManager->Tie("fcs/flap-cmd-norm", this, + &FGFCS::GetDfCmd, + &FGFCS::SetDfCmd, + true); + PropertyManager->Tie("fcs/speedbrake-cmd-norm", this, + &FGFCS::GetDsbCmd, + &FGFCS::SetDsbCmd, + true); + PropertyManager->Tie("fcs/spoiler-cmd-norm", this, + &FGFCS::GetDspCmd, + &FGFCS::SetDspCmd, + true); + PropertyManager->Tie("fcs/pitch-trim-cmd-norm", this, + &FGFCS::GetPitchTrimCmd, + &FGFCS::SetPitchTrimCmd, + true); + PropertyManager->Tie("fcs/roll-trim-cmd-norm", this, + &FGFCS::GetYawTrimCmd, + &FGFCS::SetYawTrimCmd, + true); + PropertyManager->Tie("fcs/yaw-trim-cmd-norm", this, + &FGFCS::GetRollTrimCmd, + &FGFCS::SetRollTrimCmd, + true); + PropertyManager->Tie("gear/gear-cmd-norm", this, + &FGFCS::GetGearCmd, + &FGFCS::SetGearCmd, + true); + + PropertyManager->Tie("fcs/left-aileron-pos-rad", this,ofRad, + &FGFCS::GetDaLPos, + &FGFCS::SetDaLPos, + true); + PropertyManager->Tie("fcs/left-aileron-pos-norm", this,ofNorm, + &FGFCS::GetDaLPos, + &FGFCS::SetDaLPos, + true); + PropertyManager->Tie("fcs/mag-left-aileron-pos-rad", this,ofMag, + &FGFCS::GetDaLPos, + &FGFCS::SetDaLPos, + true); + + PropertyManager->Tie("fcs/right-aileron-pos-rad", this,ofRad, + &FGFCS::GetDaRPos, + &FGFCS::SetDaRPos, + true); + PropertyManager->Tie("fcs/right-aileron-pos-norm", this,ofNorm, + &FGFCS::GetDaRPos, + &FGFCS::SetDaRPos, + true); + PropertyManager->Tie("fcs/mag-right-aileron-pos-rad", this,ofMag, + &FGFCS::GetDaRPos, + &FGFCS::SetDaRPos, + true); + + PropertyManager->Tie("fcs/elevator-pos-rad", this, ofRad, + &FGFCS::GetDePos, + &FGFCS::SetDePos, + true ); + PropertyManager->Tie("fcs/elevator-pos-norm", this,ofNorm, + &FGFCS::GetDePos, + &FGFCS::SetDePos, + true ); + PropertyManager->Tie("fcs/mag-elevator-pos-rad", this,ofMag, + &FGFCS::GetDePos, + &FGFCS::SetDePos, + true ); + + PropertyManager->Tie("fcs/rudder-pos-rad", this,ofRad, + &FGFCS::GetDrPos, + &FGFCS::SetDrPos, + true); + PropertyManager->Tie("fcs/rudder-pos-norm", this,ofNorm, + &FGFCS::GetDrPos, + &FGFCS::SetDrPos, + true); + PropertyManager->Tie("fcs/mag-rudder-pos-rad", this,ofMag, + &FGFCS::GetDrPos, + &FGFCS::SetDrPos, + true); + + PropertyManager->Tie("fcs/flap-pos-deg", this,ofRad, + &FGFCS::GetDfPos, + &FGFCS::SetDfPos, + true); + PropertyManager->Tie("fcs/flap-pos-norm", this,ofNorm, + &FGFCS::GetDfPos, + &FGFCS::SetDfPos, + true); + + PropertyManager->Tie("fcs/speedbrake-pos-rad", this,ofRad, + &FGFCS::GetDsbPos, + &FGFCS::SetDsbPos, + true); + PropertyManager->Tie("fcs/speedbrake-pos-norm", this,ofNorm, + &FGFCS::GetDsbPos, + &FGFCS::SetDsbPos, + true); + PropertyManager->Tie("fcs/mag-speedbrake-pos-rad", this,ofMag, + &FGFCS::GetDsbPos, + &FGFCS::SetDsbPos, + true); + + PropertyManager->Tie("fcs/spoiler-pos-rad", this,ofRad, + &FGFCS::GetDspPos, + &FGFCS::SetDspPos, + true); + PropertyManager->Tie("fcs/spoiler-pos-norm", this,ofNorm, + &FGFCS::GetDspPos, + &FGFCS::SetDspPos, + true); + PropertyManager->Tie("fcs/mag-spoiler-pos-rad", this,ofMag, + &FGFCS::GetDspPos, + &FGFCS::SetDspPos, + true); + + PropertyManager->Tie("gear/gear-pos-norm", this, + &FGFCS::GetGearPos, + &FGFCS::SetGearPos, + true); +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGFCS::unbind(void){ + PropertyManager->Untie("fcs/aileron-cmd-norm"); + PropertyManager->Untie("fcs/elevator-cmd-norm"); + PropertyManager->Untie("fcs/rudder-cmd-norm"); + PropertyManager->Untie("fcs/flap-cmd-norm"); + PropertyManager->Untie("fcs/speedbrake-cmd-norm"); + PropertyManager->Untie("fcs/spoiler-cmd-norm"); + PropertyManager->Untie("fcs/pitch-trim-cmd-norm"); + PropertyManager->Untie("fcs/roll-trim-cmd-norm"); + PropertyManager->Untie("fcs/yaw-trim-cmd-norm"); + PropertyManager->Untie("gear/gear-cmd-norm"); + PropertyManager->Untie("fcs/left-aileron-pos-rad"); + PropertyManager->Untie("fcs/mag-left-aileron-pos-rad"); + PropertyManager->Untie("fcs/left-aileron-pos-norm"); + PropertyManager->Untie("fcs/right-aileron-pos-rad"); + PropertyManager->Untie("fcs/mag-right-aileron-pos-rad"); + PropertyManager->Untie("fcs/right-aileron-pos-norm"); + PropertyManager->Untie("fcs/elevator-pos-rad"); + PropertyManager->Untie("fcs/mag-elevator-pos-rad"); + PropertyManager->Untie("fcs/elevator-pos-norm"); + PropertyManager->Untie("fcs/rudder-pos-rad"); + PropertyManager->Untie("fcs/mag-rudder-pos-rad"); + PropertyManager->Untie("fcs/rudder-pos-norm"); + PropertyManager->Untie("fcs/flap-pos-deg"); + PropertyManager->Untie("fcs/flap-pos-norm"); + PropertyManager->Untie("fcs/speedbrake-pos-rad"); + PropertyManager->Untie("fcs/mag-speedbrake-pos-rad"); + PropertyManager->Untie("fcs/speedbrake-pos-norm"); + PropertyManager->Untie("fcs/spoiler-pos-rad"); + PropertyManager->Untie("fcs/mag-spoiler-pos-rad"); + PropertyManager->Untie("fcs/spoiler-pos-norm"); + PropertyManager->Untie("gear/gear-pos-norm"); +} + + + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print diff --git a/src/FDM/JSBSim/FGFCS.h b/src/FDM/JSBSim/FGFCS.h index 03d5c4eba..3bed31dd0 100644 --- a/src/FDM/JSBSim/FGFCS.h +++ b/src/FDM/JSBSim/FGFCS.h @@ -153,7 +153,10 @@ CLASS DOCUMENTATION CLASS DECLARATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -typedef enum { iNDe=0, iNDaL, iNDaR, iNDr, iNDsb, iNDsp, iNDf } NormalizeIdx; +typedef enum { iDe=0, iDaL, iDaR, iDr, iDsb, iDsp, iDf } FcIdx; +int const NNorm=7; +typedef enum { ofRad=0, ofNorm, ofMag } OutputForm; +int const NForms=3; class FGFCS : public FGModel { @@ -172,27 +175,27 @@ public: //@{ /** Gets the aileron command. @return aileron command in percent */ - inline double GetDaCmd(void) { return DaCmd; } + inline double GetDaCmd(void) const { return DaCmd; } /** Gets the elevator command. @return elevator command in percent */ - inline double GetDeCmd(void) { return DeCmd; } + inline double GetDeCmd(void) const { return DeCmd; } /** Gets the rudder command. @return rudder command in percent */ - inline double GetDrCmd(void) { return DrCmd; } + inline double GetDrCmd(void) const { return DrCmd; } /** Gets the flaps command. @return flaps command in percent */ - inline double GetDfCmd(void) { return DfCmd; } + inline double GetDfCmd(void) const { return DfCmd; } /** Gets the speedbrake command. @return speedbrake command in percent */ - inline double GetDsbCmd(void) { return DsbCmd; } + inline double GetDsbCmd(void) const { return DsbCmd; } /** Gets the spoiler command. @return spoiler command in percent */ - inline double GetDspCmd(void) { return DspCmd; } + inline double GetDspCmd(void) const { return DspCmd; } /** Gets the throttle command. @param engine engine ID number @@ -202,95 +205,71 @@ public: /** Gets the mixture command. @param engine engine ID number @return mixture command in percent ( 0 - 100) for the given engine */ - inline double GetMixtureCmd(int engine) { return MixtureCmd[engine]; } + inline double GetMixtureCmd(int engine) const { return MixtureCmd[engine]; } /** Gets the prop pitch command. @param engine engine ID number @return pitch command in percent ( 0.0 - 1.0) for the given engine */ - inline double GetPropAdvanceCmd(int engine) { return PropAdvanceCmd[engine]; } + inline double GetPropAdvanceCmd(int engine) const { return PropAdvanceCmd[engine]; } /** Gets the pitch trim command. @return pitch trim command in percent */ - inline double GetPitchTrimCmd(void) { return PTrimCmd; } + inline double GetPitchTrimCmd(void) const { return PTrimCmd; } /** Gets the rudder trim command. @return rudder trim command in percent */ - inline double GetYawTrimCmd(void) { return YTrimCmd; } + inline double GetYawTrimCmd(void) const { return YTrimCmd; } /** Gets the aileron trim command. @return aileron trim command in percent */ - inline double GetRollTrimCmd(void) { return RTrimCmd; } + inline double GetRollTrimCmd(void) const { return RTrimCmd; } /** Get the gear extend/retract command. 0 commands gear up, 1 down. defaults to down. @return the current value of the gear extend/retract command*/ - inline double GetGearCmd(void) { return GearCmd; } + inline double GetGearCmd(void) const { return GearCmd; } //@} /// @name Aerosurface position retrieval //@{ /** Gets the left aileron position. @return aileron position in radians */ - inline double GetDaLPos(void) { return DaLPos; } - - /// @name Aerosurface position retrieval - //@{ - /** Gets the normalized left aileron position. - @return aileron position in radians */ - inline double GetDaLPosN(void) { return DaLPosN; } + inline double GetDaLPos( int form = ofRad ) + const { return DaLPos[form]; } /// @name Aerosurface position retrieval //@{ /** Gets the right aileron position. @return aileron position in radians */ - inline double GetDaRPos(void) { return DaRPos; } - - /// @name Aerosurface position retrieval - //@{ - /** Gets the normalized right aileron position. - @return right aileron position in percent (-1..1) */ - inline double GetDaRPosN(void) { return DaRPosN; } + inline double GetDaRPos( int form = ofRad ) + const { return DaRPos[form]; } /** Gets the elevator position. @return elevator position in radians */ - inline double GetDePos(void) { return DePos; } + inline double GetDePos( int form = ofRad ) + const { return DePos[form]; } - /** Gets the normalized elevator position. - @return elevator position in percent (-1..1) */ - inline double GetDePosN(void) { return DePosN; } - /** Gets the rudder position. @return rudder position in radians */ - inline double GetDrPos(void) { return DrPos; } - - /** Gets the normalized rudder position. - @return rudder position in percent (-1..1) */ - inline double GetDrPosN(void) { return DrPosN; } - - /** Gets the flaps position. - @return flaps position in radians */ - inline double GetDfPos(void) { return DfPos; } - - /** Gets the normalized flaps position. - @return flaps position in percent (-1..1) */ - inline double GetDfPosN(void) { return DfPosN; } + inline double GetDrPos( int form = ofRad ) + const { return DrPos[form]; } /** Gets the speedbrake position. @return speedbrake position in radians */ - inline double GetDsbPos(void) { return DsbPos; } - - /** Gets the normalized speedbrake position. - @return speedbrake position in percent (-1..1) */ - inline double GetDsbPosN(void) { return DsbPosN; } + inline double GetDsbPos( int form = ofRad ) + const { return DsbPos[form]; } /** Gets the spoiler position. @return spoiler position in radians */ - inline double GetDspPos(void) { return DspPos; } + inline double GetDspPos( int form = ofRad ) + const { return DspPos[form]; } + + /** Gets the flaps position. + @return flaps position in radians */ + inline double GetDfPos( int form = ofRad ) + const { return DspPos[form]; } + - /** Gets the normalized spoiler position. - @return spoiler position in percent (-1..1) */ - inline double GetDspPosN(void) { return DspPosN; } - /** Gets the throttle position. @param engine engine ID number @return throttle position for the given engine in percent ( 0 - 100)*/ @@ -299,16 +278,16 @@ public: /** Gets the mixture position. @param engine engine ID number @return mixture position for the given engine in percent ( 0 - 100)*/ - inline double GetMixturePos(int engine) { return MixturePos[engine]; } + inline double GetMixturePos(int engine) const { return MixturePos[engine]; } /** Gets the gear position (0 up, 1 down), defaults to down @return gear position (0 up, 1 down) */ - inline double GetGearPos(void) { return GearPos; } + inline double GetGearPos(void) const { return GearPos; } /** Gets the prop pitch position. @param engine engine ID number @return prop pitch position for the given engine in percent ( 0.0-1.0)*/ - inline double GetPropAdvance(int engine) { return PropAdvance[engine]; } + inline double GetPropAdvance(int engine) const { return PropAdvance[engine]; } //@} /** Retrieves the State object pointer. @@ -336,11 +315,11 @@ public: //@{ /** Sets the aileron command @param cmd aileron command in percent*/ - inline void SetDaCmd(double cmd) { DaCmd = cmd; } + inline void SetDaCmd( double cmd ) { DaCmd = cmd; } /** Sets the elevator command @param cmd elevator command in percent*/ - inline void SetDeCmd(double cmd) { DeCmd = cmd; } + inline void SetDeCmd(double cmd ) { DeCmd = cmd; } /** Sets the rudder command @param cmd rudder command in percent*/ @@ -394,60 +373,39 @@ public: //@{ /** Sets the left aileron position @param cmd left aileron position in radians*/ - inline void SetDaLPos(double cmd) { DaLPos = cmd; } - - /** Sets the normalized left aileron position - @param cmd left aileron position in percent (-1..1)*/ - inline void SetDaLPosN(double cmd) { DaLPosN = cmd; } + inline void SetDaLPos( int form , double pos ) + { DaLPos[form] = pos; } /** Sets the right aileron position @param cmd right aileron position in radians*/ - inline void SetDaRPos(double cmd) { DaRPos = cmd; } - - /** Sets the normalized right aileron position - @param cmd right aileron position in percent (-1..1)*/ - inline void SetDaRPosN(double cmd) { DaRPosN = cmd; } + inline void SetDaRPos( int form , double pos ) + { DaRPos[form] = pos; } /** Sets the elevator position @param cmd elevator position in radians*/ - inline void SetDePos(double cmd) { DePos = cmd; } - - /** Sets the normalized elevator position - @param cmd elevator position in percent (-1..1) */ - inline void SetDePosN(double cmd) { DePosN = cmd; } + inline void SetDePos( int form , double pos ) + { DePos[form] = pos; } /** Sets the rudder position @param cmd rudder position in radians*/ - inline void SetDrPos(double cmd) { DrPos = cmd; } + inline void SetDrPos( int form , double pos ) + { DrPos[form] = pos; } - /** Sets the normalized rudder position - @param cmd rudder position in percent (-1..1)*/ - inline void SetDrPosN(double cmd) { DrPosN = cmd; } - - /** Sets the flaps position + /** Sets the flaps position @param cmd flaps position in radians*/ - inline void SetDfPos(double cmd) { DfPos = cmd; } + inline void SetDfPos( int form , double pos ) + { DfPos[form] = pos; } - /** Sets the flaps position - @param cmd flaps position in radians*/ - inline void SetDfPosN(double cmd) { DfPosN = cmd; } - /** Sets the speedbrake position @param cmd speedbrake position in radians*/ - inline void SetDsbPos(double cmd) { DsbPos = cmd; } - - /** Sets the normalized speedbrake position - @param cmd normalized speedbrake position in percent (-1..1)*/ - inline void SetDsbPosN(double cmd) { DsbPosN = cmd; } + inline void SetDsbPos( int form , double pos ) + { DsbPos[form] = pos; } /** Sets the spoiler position @param cmd spoiler position in radians*/ - inline void SetDspPos(double cmd) { DspPos = cmd; } + inline void SetDspPos( int form , double pos ) + { DspPos[form] = pos; } - /** Sets the normalized spoiler position - @param cmd normalized spoiler position in percent (-1..1)*/ - inline void SetDspPosN(double cmd) { DspPosN = cmd; } - /** Sets the actual throttle setting for the specified engine @param engine engine ID number @param cmd throttle setting in percent (0 - 100)*/ @@ -498,11 +456,15 @@ public: bool Load(FGConfigFile* AC_cfg); void AddThrottle(void); + + void bind(void); + void unbind(void); + private: - double DaCmd, DeCmd, DrCmd, DfCmd, DsbCmd, DspCmd; - double DaLPos, DaRPos, DePos, DrPos, DfPos, DsbPos, DspPos; - double DaLPosN, DaRPosN, DePosN, DrPosN, DfPosN, DsbPosN, DspPosN; + double DaCmd, DeCmd, DrCmd, DfCmd, DsbCmd, DspCmd; + double DePos[NForms], DaLPos[NForms], DaRPos[NForms], DrPos[NForms]; + double DfPos[NForms], DsbPos[NForms], DspPos[NForms]; double PTrimCmd, YTrimCmd, RTrimCmd; vector ThrottleCmd; vector ThrottlePos; @@ -517,7 +479,7 @@ private: void Normalize(void); vector Components; - int ToNormalize[7]; + int ToNormalize[NNorm]; void Debug(int from); }; diff --git a/src/FDM/JSBSim/FGFDMExec.cpp b/src/FDM/JSBSim/FGFDMExec.cpp index fdf6eaf2c..d918a9d64 100644 --- a/src/FDM/JSBSim/FGFDMExec.cpp +++ b/src/FDM/JSBSim/FGFDMExec.cpp @@ -71,6 +71,7 @@ INCLUDES #include "FGOutput.h" #include "FGConfigFile.h" #include "FGInitialCondition.h" +#include "FGPropertyManager.h" static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_FDMEXEC; @@ -87,8 +88,9 @@ CLASS IMPLEMENTATION // Constructor -FGFDMExec::FGFDMExec(void) +FGFDMExec::FGFDMExec(FGPropertyManager* root) { + Frame = 0; FirstModel = 0; Error = 0; @@ -122,16 +124,35 @@ FGFDMExec::FGFDMExec(void) debug_lvl = 1; } - Debug(0); - Allocate(); + if(root == 0) + master= new FGPropertyManager; + else + master = root; + instance = master->GetNode("/fdm/jsbsim",IdFDM,true); + instance->SetDouble("zero",0); + + Debug(0); + + // this is here to catch errors in binding member functions + // to the property tree. + try { + Allocate(); + } catch ( string msg ) { + cout << "Caught error: " << msg << endl; + exit(1); + } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FGFDMExec::~FGFDMExec() { - DeAllocate(); + try { + DeAllocate(); + } catch ( string msg ) { + cout << "Caught error: " << msg << endl; + } Debug(1); } @@ -488,6 +509,12 @@ bool FGFDMExec::ReadOutput(FGConfigFile* AC_cfg) return true; } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +FGPropertyManager* FGFDMExec::GetPropertyManager(void) { + return instance; +} + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print diff --git a/src/FDM/JSBSim/FGFDMExec.h b/src/FDM/JSBSim/FGFDMExec.h index c7a8c7b50..365efb29d 100644 --- a/src/FDM/JSBSim/FGFDMExec.h +++ b/src/FDM/JSBSim/FGFDMExec.h @@ -43,8 +43,9 @@ INCLUDES #include "FGModel.h" #include "FGInitialCondition.h" #include "FGJSBBase.h" -#include +#include "FGPropertyManager.h" +#include /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -111,9 +112,11 @@ CLASS DECLARATION class FGFDMExec : public FGJSBBase { public: - /// Default constructor - FGFDMExec(void); + + /// Default constructor + FGFDMExec(FGPropertyManager* root = 0); + /// Default destructor ~FGFDMExec(); @@ -197,6 +200,8 @@ public: inline string GetEnginePath(void) {return EnginePath;} /// Retrieves the aircraft path. inline string GetAircraftPath(void) {return AircraftPath;} + + FGPropertyManager* GetPropertyManager(void); private: FGModel* FirstModel; @@ -208,6 +213,9 @@ private: unsigned int IdFDM; static unsigned int FDMctr; bool modelLoaded; + + FGPropertyManager *master; + FGPropertyManager *instance; string AircraftPath; string EnginePath; diff --git a/src/FDM/JSBSim/FGFactorGroup.cpp b/src/FDM/JSBSim/FGFactorGroup.cpp index 497250284..796bcb94e 100644 --- a/src/FDM/JSBSim/FGFactorGroup.cpp +++ b/src/FDM/JSBSim/FGFactorGroup.cpp @@ -70,7 +70,7 @@ CLASS IMPLEMENTATION FGFactorGroup::FGFactorGroup( FGFDMExec* fdmex ) : FGCoefficient( fdmex) { FDMExec = fdmex; - + totalValue = 0; Debug(0); } @@ -115,16 +115,17 @@ bool FGFactorGroup::Load(FGConfigFile *AC_cfg) double FGFactorGroup::TotalValue(void) { unsigned int i; - double totalsum = 0; SDtotal = 0.0; + totalValue = 0.0; for (i=0; iTotalValue(); + totalValue += sum[i]->TotalValue(); SDtotal += sum[i]->GetSD(); } - totalsum *= FGCoefficient::TotalValue(); + //cout << totalValue << " " << FGCoefficient::TotalValue() << endl; + totalValue *= FGCoefficient::TotalValue(); SDtotal *= FGCoefficient::GetSD(); Debug(2); - return totalsum; + return totalValue; } /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ diff --git a/src/FDM/JSBSim/FGFactorGroup.h b/src/FDM/JSBSim/FGFactorGroup.h index 0484119a1..d3e2afd2a 100644 --- a/src/FDM/JSBSim/FGFactorGroup.h +++ b/src/FDM/JSBSim/FGFactorGroup.h @@ -99,6 +99,7 @@ class FGFactorGroup: public FGCoefficient { bool Load(FGConfigFile *AC_cfg); double TotalValue(void); + inline double GetValue(void) const { return totalValue; } //string GetCoefficientStrings(void); //string GetCoefficientValues(void); inline double GetSD(void) { return SDtotal; } @@ -111,6 +112,7 @@ class FGFactorGroup: public FGCoefficient { typedef vector CoeffArray; CoeffArray sum; double SDtotal; + double totalValue; void Debug(int from); }; diff --git a/src/FDM/JSBSim/FGGroundReactions.cpp b/src/FDM/JSBSim/FGGroundReactions.cpp index dde442afd..db38bd24d 100644 --- a/src/FDM/JSBSim/FGGroundReactions.cpp +++ b/src/FDM/JSBSim/FGGroundReactions.cpp @@ -36,6 +36,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGGroundReactions.h" +#include "FGPropertyManager.h" static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_GROUNDREACTIONS; @@ -48,6 +49,8 @@ CLASS IMPLEMENTATION FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex) { Name = "FGGroundReactions"; + + bind(); Debug(0); } @@ -56,6 +59,8 @@ FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex) FGGroundReactions::~FGGroundReactions(void) { + unbind(); + Debug(1); } @@ -204,3 +209,30 @@ void FGGroundReactions::Debug(int from) } } +void FGGroundReactions::bind(void){ + + PropertyManager->Tie("gear/num-units", this, + &FGGroundReactions::GetNumGearUnits); + PropertyManager->Tie("moments/l-gear-lbsft", this,1, + &FGGroundReactions::GetMoments); + PropertyManager->Tie("moments/m-gear-lbsft", this,2, + &FGGroundReactions::GetMoments); + PropertyManager->Tie("moments/n-gear-lbsft", this,3, + &FGGroundReactions::GetMoments); + PropertyManager->Tie("forces/fbx-gear-lbs", this,1, + &FGGroundReactions::GetForces); + PropertyManager->Tie("forces/fby-gear-lbs", this,2, + &FGGroundReactions::GetForces); + PropertyManager->Tie("forces/fbz-gear-lbs", this,3, + &FGGroundReactions::GetForces); +} + +void FGGroundReactions::unbind(void){ + PropertyManager->Untie("gear/num-units"); + PropertyManager->Untie("moments/l-gear-lbsft"); + PropertyManager->Untie("moments/m-gear-lbsft"); + PropertyManager->Untie("moments/n-gear-lbsft"); + PropertyManager->Untie("forces/fbx-gear-lbs"); + PropertyManager->Untie("forces/fby-gear-lbs"); + PropertyManager->Untie("forces/fbz-gear-lbs"); +} diff --git a/src/FDM/JSBSim/FGGroundReactions.h b/src/FDM/JSBSim/FGGroundReactions.h index 21b774ab5..842d70837 100644 --- a/src/FDM/JSBSim/FGGroundReactions.h +++ b/src/FDM/JSBSim/FGGroundReactions.h @@ -74,11 +74,13 @@ public: bool Run(void); bool Load(FGConfigFile* AC_cfg); FGColumnVector3& GetForces(void) {return vForces;} + double GetForces(int idx) const {return vForces(idx);} FGColumnVector3& GetMoments(void) {return vMoments;} + double GetMoments(int idx) const {return vMoments(idx);} string GetGroundReactionStrings(void); string GetGroundReactionValues(void); - inline int GetNumGearUnits(void) { return lGear.size(); } + inline int GetNumGearUnits(void) const { return lGear.size(); } /** Gets a gear instance @param gear index of gear instance @return a pointer to the FGLGear instance of the gear unit requested */ @@ -86,6 +88,9 @@ public: inline FGLGear* GetGearUnit(int gear) { return &(lGear[gear]); } + void bind(void); + void unbind(void); + private: vector lGear; FGColumnVector3 vForces; diff --git a/src/FDM/JSBSim/FGInertial.cpp b/src/FDM/JSBSim/FGInertial.cpp index 3afa4677d..1475a6b93 100644 --- a/src/FDM/JSBSim/FGInertial.cpp +++ b/src/FDM/JSBSim/FGInertial.cpp @@ -59,6 +59,8 @@ FGInertial::FGInertial(FGFDMExec* fgex) : FGModel(fgex) RadiusReference = 20925650.00; gAccelReference = GM/(RadiusReference*RadiusReference); gAccel = GM/(RadiusReference*RadiusReference); + + bind(); Debug(0); } @@ -67,6 +69,7 @@ FGInertial::FGInertial(FGFDMExec* fgex) : FGModel(fgex) FGInertial::~FGInertial(void) { + unbind(); Debug(1); } @@ -168,3 +171,17 @@ void FGInertial::Debug(int from) } } +void FGInertial::bind(void){ + PropertyManager->Tie("forces/fbx-inertial-lbs", this,1, + &FGInertial::GetForces); + PropertyManager->Tie("forces/fby-inertial-lbs", this,2, + &FGInertial::GetForces); + PropertyManager->Tie("forces/fbz-inertial-lbs", this,3, + &FGInertial::GetForces); +} + +void FGInertial::unbind(void){ + PropertyManager->Untie("forces/fbx-inertial-lbs"); + PropertyManager->Untie("forces/fby-inertial-lbs"); + PropertyManager->Untie("forces/fbz-inertial-lbs"); +} diff --git a/src/FDM/JSBSim/FGInertial.h b/src/FDM/JSBSim/FGInertial.h index 7a1da74cf..569074301 100644 --- a/src/FDM/JSBSim/FGInertial.h +++ b/src/FDM/JSBSim/FGInertial.h @@ -75,13 +75,17 @@ public: bool Run(void); FGColumnVector3& GetForces(void) {return vForces;} FGColumnVector3& GetGravity(void) {return vGravity;} - double GetForces(int n) {return vForces(n);} + double GetForces(int n) const {return vForces(n);} bool LoadInertial(FGConfigFile* AC_cfg); - double SLgravity(void) {return gAccelReference;} - double gravity(void) {return gAccel;} - double omega(void) {return RotationRate;} - double RefRadius(void) {return RadiusReference;} + double SLgravity(void) const {return gAccelReference;} + double gravity(void) const {return gAccel;} + double omega(void) const {return RotationRate;} + double RefRadius(void) const {return RadiusReference;} + + void bind(void); + void unbind(void); + private: FGColumnVector3 vOmegaLocal; FGColumnVector3 vForces; diff --git a/src/FDM/JSBSim/FGInitialCondition.cpp b/src/FDM/JSBSim/FGInitialCondition.cpp index 1b70824ad..7cfa23030 100644 --- a/src/FDM/JSBSim/FGInitialCondition.cpp +++ b/src/FDM/JSBSim/FGInitialCondition.cpp @@ -54,6 +54,7 @@ INCLUDES #include "FGAuxiliary.h" #include "FGOutput.h" #include "FGConfigFile.h" +#include "FGPropertyManager.h" static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_INITIALCONDITION; @@ -87,10 +88,12 @@ FGInitialCondition::FGInitialCondition(FGFDMExec *FDMExec) fdmex=FDMExec; fdmex->GetPosition()->Seth(altitude); fdmex->GetAtmosphere()->Run(); + PropertyManager=fdmex->GetPropertyManager(); + bind(); } else { cout << "FGInitialCondition: This class requires a pointer to a valid FGFDMExec object" << endl; } - + Debug(0); } @@ -98,6 +101,7 @@ FGInitialCondition::FGInitialCondition(FGFDMExec *FDMExec) FGInitialCondition::~FGInitialCondition() { + unbind(); Debug(1); } @@ -814,3 +818,195 @@ void FGInitialCondition::Debug(int from) } } +void FGInitialCondition::bind(void){ + PropertyManager->Tie("ic/vc-kts", this, + &FGInitialCondition::GetVcalibratedKtsIC, + &FGInitialCondition::SetVcalibratedKtsIC, + true); + PropertyManager->Tie("ic/ve-kts", this, + &FGInitialCondition::GetVequivalentKtsIC, + &FGInitialCondition::SetVequivalentKtsIC, + true); + PropertyManager->Tie("ic/vg-kts", this, + &FGInitialCondition::GetVgroundKtsIC, + &FGInitialCondition::SetVgroundKtsIC, + true); + PropertyManager->Tie("ic/vt-kts", this, + &FGInitialCondition::GetVtrueKtsIC, + &FGInitialCondition::SetVtrueKtsIC, + true); + PropertyManager->Tie("ic/mach-norm", this, + &FGInitialCondition::GetMachIC, + &FGInitialCondition::SetMachIC, + true); + PropertyManager->Tie("ic/roc-fpm", this, + &FGInitialCondition::GetClimbRateFpmIC, + &FGInitialCondition::SetClimbRateFpmIC, + true); + PropertyManager->Tie("ic/gamma-deg", this, + &FGInitialCondition::GetFlightPathAngleDegIC, + &FGInitialCondition::SetFlightPathAngleDegIC, + true); + PropertyManager->Tie("ic/alpha-deg", this, + &FGInitialCondition::GetAlphaDegIC, + &FGInitialCondition::SetAlphaDegIC, + true); + PropertyManager->Tie("ic/beta-deg", this, + &FGInitialCondition::GetBetaDegIC, + &FGInitialCondition::SetBetaDegIC, + true); + PropertyManager->Tie("ic/theta-deg", this, + &FGInitialCondition::GetPitchAngleDegIC, + &FGInitialCondition::SetPitchAngleDegIC, + true); + PropertyManager->Tie("ic/phi-deg", this, + &FGInitialCondition::GetRollAngleDegIC, + &FGInitialCondition::SetRollAngleDegIC, + true); + PropertyManager->Tie("ic/psi-true-deg", this, + &FGInitialCondition::GetHeadingDegIC ); + PropertyManager->Tie("ic/lat-gc-deg", this, + &FGInitialCondition::GetLatitudeDegIC, + &FGInitialCondition::SetLatitudeDegIC, + true); + PropertyManager->Tie("ic/long-gc-deg", this, + &FGInitialCondition::GetLongitudeDegIC, + &FGInitialCondition::SetLongitudeDegIC, + true); + PropertyManager->Tie("ic/h-sl-ft", this, + &FGInitialCondition::GetAltitudeFtIC, + &FGInitialCondition::SetAltitudeFtIC, + true); + PropertyManager->Tie("ic/h-agl-ft", this, + &FGInitialCondition::GetAltitudeAGLFtIC, + &FGInitialCondition::SetAltitudeAGLFtIC, + true); + PropertyManager->Tie("ic/sea-level-radius-ft", this, + &FGInitialCondition::GetSeaLevelRadiusFtIC, + &FGInitialCondition::SetSeaLevelRadiusFtIC, + true); + PropertyManager->Tie("ic/terrain-altitude-ft", this, + &FGInitialCondition::GetTerrainAltitudeFtIC, + &FGInitialCondition::SetTerrainAltitudeFtIC, + true); + PropertyManager->Tie("ic/vg-fps", this, + &FGInitialCondition::GetVgroundFpsIC, + &FGInitialCondition::SetVgroundFpsIC, + true); + PropertyManager->Tie("ic/vt-fps", this, + &FGInitialCondition::GetVtrueFpsIC, + &FGInitialCondition::SetVtrueFpsIC, + true); + PropertyManager->Tie("ic/vw-bx-fps", this, + &FGInitialCondition::GetWindUFpsIC); + PropertyManager->Tie("ic/vw-by-fps", this, + &FGInitialCondition::GetWindVFpsIC); + PropertyManager->Tie("ic/vw-bz-fps", this, + &FGInitialCondition::GetWindWFpsIC); + PropertyManager->Tie("ic/vw-north-fps", this, + &FGInitialCondition::GetWindNFpsIC); + PropertyManager->Tie("ic/vw-east-fps", this, + &FGInitialCondition::GetWindEFpsIC); + PropertyManager->Tie("ic/vw-down-fps", this, + &FGInitialCondition::GetWindDFpsIC); + PropertyManager->Tie("ic/vw-mag-fps", this, + &FGInitialCondition::GetWindFpsIC); + /* PropertyManager->Tie("ic/vw-dir-deg", this, + &FGInitialCondition::GetWindDirDegIC, + &FGInitialCondition::SetWindDirDegIC, + true); */ + + PropertyManager->Tie("ic/roc-fps", this, + &FGInitialCondition::GetClimbRateFpsIC, + &FGInitialCondition::SetClimbRateFpsIC, + true); + /* PropertyManager->Tie("ic/u-fps", this, + &FGInitialCondition::GetUBodyFpsIC, + &FGInitialCondition::SetUBodyFpsIC, + true); + PropertyManager->Tie("ic/v-fps", this, + &FGInitialCondition::GetVBodyFpsIC, + &FGInitialCondition::SetVBodyFpsIC, + true); + PropertyManager->Tie("ic/w-fps", this, + &FGInitialCondition::GetWBodyFpsIC, + &FGInitialCondition::SetWBodyFpsIC, + true); */ + + PropertyManager->Tie("ic/gamma-rad", this, + &FGInitialCondition::GetFlightPathAngleRadIC, + &FGInitialCondition::SetFlightPathAngleRadIC, + true); + PropertyManager->Tie("ic/alpha-rad", this, + &FGInitialCondition::GetAlphaRadIC, + &FGInitialCondition::SetAlphaRadIC, + true); + PropertyManager->Tie("ic/theta-rad", this, + &FGInitialCondition::GetPitchAngleRadIC, + &FGInitialCondition::SetPitchAngleRadIC, + true); + PropertyManager->Tie("ic/beta-rad", this, + &FGInitialCondition::GetBetaRadIC, + &FGInitialCondition::SetBetaRadIC, + true); + PropertyManager->Tie("ic/phi-rad", this, + &FGInitialCondition::GetRollAngleRadIC, + &FGInitialCondition::SetRollAngleRadIC, + true); + PropertyManager->Tie("ic/psi-true-rad", this, + &FGInitialCondition::GetHeadingRadIC); + PropertyManager->Tie("ic/lat-gc-rad", this, + &FGInitialCondition::GetLatitudeRadIC, + &FGInitialCondition::SetLatitudeRadIC, + true); + PropertyManager->Tie("ic/long-gc-rad", this, + &FGInitialCondition::GetLongitudeRadIC, + &FGInitialCondition::SetLongitudeRadIC, + true); +} + +void FGInitialCondition::unbind(void){ + PropertyManager->Untie("ic/vc-kts"); + PropertyManager->Untie("ic/ve-kts"); + PropertyManager->Untie("ic/vg-kts"); + PropertyManager->Untie("ic/vt-kts"); + PropertyManager->Untie("ic/mach-norm"); + PropertyManager->Untie("ic/roc-fpm"); + PropertyManager->Untie("ic/gamma-deg"); + PropertyManager->Untie("ic/alpha-deg"); + PropertyManager->Untie("ic/beta-deg"); + PropertyManager->Untie("ic/theta-deg"); + PropertyManager->Untie("ic/phi-deg"); + PropertyManager->Untie("ic/psi-true-deg"); + PropertyManager->Untie("ic/lat-gc-deg"); + PropertyManager->Untie("ic/long-gc-deg"); + PropertyManager->Untie("ic/h-sl-ft"); + PropertyManager->Untie("ic/h-agl-ft"); + PropertyManager->Untie("ic/sea-level-radius-ft"); + PropertyManager->Untie("ic/terrain-altitude-ft"); + PropertyManager->Untie("ic/vg-fps"); + PropertyManager->Untie("ic/vt-fps"); + PropertyManager->Untie("ic/vw-bx-fps"); + PropertyManager->Untie("ic/vw-by-fps"); + PropertyManager->Untie("ic/vw-bz-fps"); + PropertyManager->Untie("ic/vw-north-fps"); + PropertyManager->Untie("ic/vw-east-fps"); + PropertyManager->Untie("ic/vw-down-fps"); + PropertyManager->Untie("ic/vw-mag-fps"); + /* PropertyManager->Untie("ic/vw-dir-deg"); */ + + PropertyManager->Untie("ic/roc-fps"); + + /* PropertyManager->Untie("ic/u-fps"); + PropertyManager->Untie("ic/v-fps"); + PropertyManager->Untie("ic/w-fps"); */ + + PropertyManager->Untie("ic/gamma-rad"); + PropertyManager->Untie("ic/alpha-rad"); + PropertyManager->Untie("ic/theta-rad"); + PropertyManager->Untie("ic/beta-rad"); + PropertyManager->Untie("ic/phi-rad"); + PropertyManager->Untie("ic/psi-true-rad"); + PropertyManager->Untie("ic/lat-gc-rad"); + PropertyManager->Untie("ic/long-gc-rad"); +} diff --git a/src/FDM/JSBSim/FGInitialCondition.h b/src/FDM/JSBSim/FGInitialCondition.h index b8806fd11..042cdedac 100644 --- a/src/FDM/JSBSim/FGInitialCondition.h +++ b/src/FDM/JSBSim/FGInitialCondition.h @@ -166,30 +166,30 @@ public: inline void SetLongitudeDegIC(double tt) { longitude=tt*degtorad; } - inline double GetVcalibratedKtsIC(void) { return vc*fpstokts; } - inline double GetVequivalentKtsIC(void) { return ve*fpstokts; } - inline double GetVgroundKtsIC(void) { return vg*fpstokts; } - inline double GetVtrueKtsIC(void) { return vt*fpstokts; } - inline double GetMachIC(void) { return mach; } + inline double GetVcalibratedKtsIC(void) const { return vc*fpstokts; } + inline double GetVequivalentKtsIC(void) const { return ve*fpstokts; } + inline double GetVgroundKtsIC(void) const { return vg*fpstokts; } + inline double GetVtrueKtsIC(void) const { return vt*fpstokts; } + inline double GetMachIC(void) const { return mach; } - inline double GetClimbRateFpmIC(void) { return hdot*60; } - inline double GetFlightPathAngleDegIC(void) { return gamma*radtodeg; } + inline double GetClimbRateFpmIC(void) const { return hdot*60; } + inline double GetFlightPathAngleDegIC(void)const { return gamma*radtodeg; } - inline double GetAlphaDegIC(void) { return alpha*radtodeg; } - inline double GetBetaDegIC(void) { return beta*radtodeg; } + inline double GetAlphaDegIC(void) const { return alpha*radtodeg; } + inline double GetBetaDegIC(void) const { return beta*radtodeg; } - inline double GetPitchAngleDegIC(void) { return theta*radtodeg; } - inline double GetRollAngleDegIC(void) { return phi*radtodeg; } - inline double GetHeadingDegIC(void) { return psi*radtodeg; } + inline double GetPitchAngleDegIC(void) const { return theta*radtodeg; } + inline double GetRollAngleDegIC(void) const { return phi*radtodeg; } + inline double GetHeadingDegIC(void) const { return psi*radtodeg; } - inline double GetLatitudeDegIC(void) { return latitude*radtodeg; } - inline double GetLongitudeDegIC(void) { return longitude*radtodeg; } + inline double GetLatitudeDegIC(void) const { return latitude*radtodeg; } + inline double GetLongitudeDegIC(void) const { return longitude*radtodeg; } - inline double GetAltitudeFtIC(void) { return altitude; } - inline double GetAltitudeAGLFtIC(void) { return altitude - terrain_altitude; } + inline double GetAltitudeFtIC(void) const { return altitude; } + inline double GetAltitudeAGLFtIC(void) const { return altitude - terrain_altitude; } - inline double GetSeaLevelRadiusFtIC(void) { return sea_level_radius; } - inline double GetTerrainAltitudeFtIC(void) { return terrain_altitude; } + inline double GetSeaLevelRadiusFtIC(void) const { return sea_level_radius; } + inline double GetTerrainAltitudeFtIC(void) const { return terrain_altitude; } void SetVgroundFpsIC(double tt); void SetVtrueFpsIC(double tt); @@ -211,17 +211,17 @@ public: void SetWindDownKtsIC(double wD); void SetClimbRateFpsIC(double tt); - inline double GetVgroundFpsIC(void) { return vg; } - inline double GetVtrueFpsIC(void) { return vt; } - inline double GetWindUFpsIC(void) { return uw; } - inline double GetWindVFpsIC(void) { return vw; } - inline double GetWindWFpsIC(void) { return ww; } - inline double GetWindNFpsIC(void) { return wnorth; } - inline double GetWindEFpsIC(void) { return weast; } - inline double GetWindDFpsIC(void) { return wdown; } - inline double GetWindFpsIC(void) { return sqrt(wnorth*wnorth + weast*weast); } + inline double GetVgroundFpsIC(void) const { return vg; } + inline double GetVtrueFpsIC(void) const { return vt; } + inline double GetWindUFpsIC(void) const { return uw; } + inline double GetWindVFpsIC(void) const { return vw; } + inline double GetWindWFpsIC(void) const { return ww; } + inline double GetWindNFpsIC(void) const { return wnorth; } + inline double GetWindEFpsIC(void) const { return weast; } + inline double GetWindDFpsIC(void) const { return wdown; } + inline double GetWindFpsIC(void) const { return sqrt(wnorth*wnorth + weast*weast); } double GetWindDirDegIC(void); - inline double GetClimbRateFpsIC(void) { return hdot; } + inline double GetClimbRateFpsIC(void) const { return hdot; } double GetUBodyFpsIC(void); double GetVBodyFpsIC(void); double GetWBodyFpsIC(void); @@ -231,25 +231,29 @@ public: void SetBetaRadIC(double tt); void SetRollAngleRadIC(double tt); void SetTrueHeadingRadIC(double tt); - inline void SetLatitudeRadIC(double tt) { latitude=tt; } + inline void SetLatitudeRadIC(double tt) { latitude=tt; } inline void SetLongitudeRadIC(double tt) { longitude=tt; } - inline double GetFlightPathAngleRadIC(void) { return gamma; } - inline double GetAlphaRadIC(void) { return alpha; } - inline double GetPitchAngleRadIC(void) { return theta; } - inline double GetBetaRadIC(void) { return beta; } - inline double GetRollAngleRadIC(void) { return phi; } - inline double GetHeadingRadIC(void) { return psi; } - inline double GetLatitudeRadIC(void) { return latitude; } - inline double GetLongitudeRadIC(void) { return longitude; } - inline double GetThetaRadIC(void) { return theta; } - inline double GetPhiRadIC(void) { return phi; } - inline double GetPsiRadIC(void) { return psi; } + inline double GetFlightPathAngleRadIC(void) const { return gamma; } + inline double GetAlphaRadIC(void) const { return alpha; } + inline double GetPitchAngleRadIC(void) const { return theta; } + inline double GetBetaRadIC(void) const { return beta; } + inline double GetRollAngleRadIC(void) const { return phi; } + inline double GetHeadingRadIC(void) const { return psi; } + inline double GetLatitudeRadIC(void) const { return latitude; } + inline double GetLongitudeRadIC(void) const { return longitude; } + inline double GetThetaRadIC(void) const { return theta; } + inline double GetPhiRadIC(void) const { return phi; } + inline double GetPsiRadIC(void) const { return psi; } inline speedset GetSpeedSet(void) { return lastSpeedSet; } inline windset GetWindSet(void) { return lastWindSet; } bool Load(string acpath, string acname, string rstname); + + void bind(void); + void unbind(void); + private: double vt,vc,ve,vg; double mach; @@ -277,6 +281,7 @@ private: windset lastWindSet; FGFDMExec *fdmex; + FGPropertyManager *PropertyManager; bool getAlpha(void); bool getTheta(void); diff --git a/src/FDM/JSBSim/FGMassBalance.cpp b/src/FDM/JSBSim/FGMassBalance.cpp index b6a4619d9..5d14dae02 100644 --- a/src/FDM/JSBSim/FGMassBalance.cpp +++ b/src/FDM/JSBSim/FGMassBalance.cpp @@ -39,6 +39,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGMassBalance.h" +#include "FGPropertyManager.h" static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_MASSBALANCE; @@ -51,6 +52,7 @@ CLASS IMPLEMENTATION FGMassBalance::FGMassBalance(FGFDMExec* fdmex) : FGModel(fdmex) { Name = "FGMassBalance"; + bind(); Debug(0); } @@ -59,6 +61,7 @@ FGMassBalance::FGMassBalance(FGFDMExec* fdmex) : FGModel(fdmex) FGMassBalance::~FGMassBalance() { + unbind(); Debug(1); } @@ -131,7 +134,7 @@ double FGMassBalance::GetPMIxx(void) { double I = 0.0; for (unsigned int i=0; igravity()); return I; @@ -143,7 +146,7 @@ double FGMassBalance::GetPMIyy(void) { double I = 0.0; for (unsigned int i=0; igravity()); return I; @@ -155,7 +158,7 @@ double FGMassBalance::GetPMIzz(void) { double I = 0.0; for (unsigned int i=0; igravity()); return I; @@ -167,7 +170,7 @@ double FGMassBalance::GetPMIxy(void) { double I = 0.0; for (unsigned int i=0; igravity()); return I; @@ -179,7 +182,7 @@ double FGMassBalance::GetPMIxz(void) { double I = 0.0; for (unsigned int i=0; igravity()); return I; @@ -239,3 +242,38 @@ void FGMassBalance::Debug(int from) } } +void FGMassBalance::bind(void){ + PropertyManager->Tie("inertia/mass-slugs", this, + &FGMassBalance::GetMass); + PropertyManager->Tie("inertia/weight-lbs", this, + &FGMassBalance::GetWeight); + PropertyManager->Tie("inertia/ixx-lbsft2", this, + &FGMassBalance::GetIxx); + PropertyManager->Tie("inertia/iyy-lbsft2", this, + &FGMassBalance::GetIyy); + PropertyManager->Tie("inertia/izz-lbsft2", this, + &FGMassBalance::GetIzz); + PropertyManager->Tie("inertia/ixy-lbsft2", this, + &FGMassBalance::GetIxy); + PropertyManager->Tie("inertia/ixz-lbsft2", this, + &FGMassBalance::GetIxz); + PropertyManager->Tie("inertia/cg-x-ft", this,1, + &FGMassBalance::GetXYZcg); + PropertyManager->Tie("inertia/cg-y-ft", this,2, + &FGMassBalance::GetXYZcg); + PropertyManager->Tie("inertia/cg-z-ft", this,3, + &FGMassBalance::GetXYZcg); +} + +void FGMassBalance::unbind(void){ + PropertyManager->Untie("inertia/mass-slugs"); + PropertyManager->Untie("inertia/weight-lbs"); + PropertyManager->Untie("inertia/ixx-lbsft2"); + PropertyManager->Untie("inertia/iyy-lbsft2"); + PropertyManager->Untie("inertia/izz-lbsft2"); + PropertyManager->Untie("inertia/ixy-lbsft2"); + PropertyManager->Untie("inertia/ixz-lbsft2"); + PropertyManager->Untie("inertia/cg-x-ft"); + PropertyManager->Untie("inertia/cg-y-ft"); + PropertyManager->Untie("inertia/cg-z-ft"); +} diff --git a/src/FDM/JSBSim/FGMassBalance.h b/src/FDM/JSBSim/FGMassBalance.h index 69c84fd46..c33d99506 100644 --- a/src/FDM/JSBSim/FGMassBalance.h +++ b/src/FDM/JSBSim/FGMassBalance.h @@ -61,15 +61,15 @@ public: bool Run(void); - inline double GetMass(void) {return Mass;} - inline double GetWeight(void) {return Weight;} - inline double GetIxx(void) {return Ixx;} - inline double GetIyy(void) {return Iyy;} - inline double GetIzz(void) {return Izz;} - inline double GetIxy(void) {return Ixy;} - inline double GetIxz(void) {return Ixz;} + inline double GetMass(void) const {return Mass;} + inline double GetWeight(void) const {return Weight;} + inline double GetIxx(void) const {return Ixx;} + inline double GetIyy(void) const {return Iyy;} + inline double GetIzz(void) const {return Izz;} + inline double GetIxy(void) const {return Ixy;} + inline double GetIxz(void) const {return Ixz;} inline FGColumnVector3& GetXYZcg(void) {return vXYZcg;} - inline double GetXYZcg(int axis) {return vXYZcg(axis);} + inline double GetXYZcg(int axis) const {return vXYZcg(axis);} inline void SetEmptyWeight(double EW) { EmptyWeight = EW;} inline void SetBaseIxx(double bixx) { baseIxx = bixx;} @@ -87,6 +87,9 @@ public: double GetPMIzz(void); double GetPMIxy(void); double GetPMIxz(void); + + void bind(void); + void unbind(void); private: double Weight; diff --git a/src/FDM/JSBSim/FGModel.cpp b/src/FDM/JSBSim/FGModel.cpp index 9462fe795..d8b019381 100644 --- a/src/FDM/JSBSim/FGModel.cpp +++ b/src/FDM/JSBSim/FGModel.cpp @@ -85,7 +85,13 @@ FGModel::FGModel(FGFDMExec* fdmex) Position = 0; Auxiliary = 0; Output = 0; - + + //in order for FGModel derived classes to self-bind (that is, call + //their bind function in the constructor, the PropertyManager pointer + //must be brought up now. + PropertyManager = FDMExec->GetPropertyManager(); + + exe_ctr = 1; if (debug_lvl & 2) cout << " FGModel Base Class" << endl; @@ -116,7 +122,7 @@ bool FGModel::InitModel(void) Position = FDMExec->GetPosition(); Auxiliary = FDMExec->GetAuxiliary(); Output = FDMExec->GetOutput(); - + if (!State || !Atmosphere || !FCS || diff --git a/src/FDM/JSBSim/FGModel.h b/src/FDM/JSBSim/FGModel.h index 189169c65..f9bf7e86f 100644 --- a/src/FDM/JSBSim/FGModel.h +++ b/src/FDM/JSBSim/FGModel.h @@ -39,6 +39,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGJSBBase.h" +#include "FGPropertyManager.h" #ifdef FGFS # include @@ -126,6 +127,8 @@ public: virtual bool InitModel(void); virtual void SetRate(int tt) {rate = tt;} virtual int GetRate(void) {return rate;} + + void SetPropertyManager(FGPropertyManager *fgpm) { PropertyManager=fgpm;} protected: int exe_ctr; @@ -148,6 +151,7 @@ protected: FGPosition* Position; FGAuxiliary* Auxiliary; FGOutput* Output; + FGPropertyManager* PropertyManager; }; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/FGPosition.cpp b/src/FDM/JSBSim/FGPosition.cpp index a5a278af0..d19af1d27 100644 --- a/src/FDM/JSBSim/FGPosition.cpp +++ b/src/FDM/JSBSim/FGPosition.cpp @@ -83,6 +83,8 @@ INCLUDES #include "FGRotation.h" #include "FGAuxiliary.h" #include "FGOutput.h" +#include "FGPropertyManager.h" + static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_POSITION; @@ -104,7 +106,7 @@ FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex) gamma = Vt = Vground = 0.0; hoverbmac = hoverbcg = 0.0; psigt = 0.0; - + bind(); Debug(0); } @@ -112,6 +114,7 @@ FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex) FGPosition::~FGPosition(void) { + unbind(); Debug(1); } @@ -271,3 +274,67 @@ void FGPosition::Debug(int from) } } +void FGPosition::bind(void){ + PropertyManager->Tie("velocities/v-north-fps", this, + &FGPosition::GetVn); + PropertyManager->Tie("velocities/v-east-fps", this, + &FGPosition::GetVe); + PropertyManager->Tie("velocities/v-down-fps", this, + &FGPosition::GetVd); + PropertyManager->Tie("velocities/vg-fps", this, + &FGPosition::GetVground); + PropertyManager->Tie("flight-path/psi-gt-rad", this, + &FGPosition::GetGroundTrack); + PropertyManager->Tie("position/h-sl-ft", this, + &FGPosition::Geth, + &FGPosition::Seth, + true); + PropertyManager->Tie("postition/h-dot-fps", this, + &FGPosition::Gethdot); + PropertyManager->Tie("postition/lat-gc-rad", this, + &FGPosition::GetLatitude, + &FGPosition::SetLatitude); + PropertyManager->Tie("postition/lat-dot-gc-rad", this, + &FGPosition::GetLatitudeDot); + PropertyManager->Tie("postition/long-gc-rad", this, + &FGPosition::GetLongitude, + &FGPosition::SetLongitude, + true); + PropertyManager->Tie("postition/long-dot-gc-rad", this, + &FGPosition::GetLongitudeDot); + PropertyManager->Tie("metrics/runway-radius", this, + &FGPosition::GetRunwayRadius, + &FGPosition::SetRunwayRadius); + PropertyManager->Tie("position/h-agl-ft", this, + &FGPosition::GetDistanceAGL, + &FGPosition::SetDistanceAGL); + PropertyManager->Tie("position/radius-to-vehicle-ft", this, + &FGPosition::GetRadius); + PropertyManager->Tie("flight-path/gamma-rad", this, + &FGPosition::GetGamma, + &FGPosition::SetGamma); + PropertyManager->Tie("position/h_b-cg-ft", this, + &FGPosition::GetHOverBCG); + PropertyManager->Tie("position/h_b-mac-ft", this, + &FGPosition::GetHOverBMAC); +} + +void FGPosition::unbind(void){ + PropertyManager->Untie("velocities/v-north-fps"); + PropertyManager->Untie("velocities/v-east-fps"); + PropertyManager->Untie("velocities/v-down-fps"); + PropertyManager->Untie("velocities/vg-fps"); + PropertyManager->Untie("flight-path/psi-gt-rad"); + PropertyManager->Untie("position/h-sl-ft"); + PropertyManager->Untie("postition/h-dot-fps"); + PropertyManager->Untie("postition/lat-gc-rad"); + PropertyManager->Untie("postition/lat-dot-gc-rad"); + PropertyManager->Untie("postition/long-gc-rad"); + PropertyManager->Untie("postition/long-dot-gc-rad"); + PropertyManager->Untie("metrics/runway-radius"); + PropertyManager->Untie("position/h-agl-ft"); + PropertyManager->Untie("position/radius-to-vehicle-ft"); + PropertyManager->Untie("flight-path/gamma-rad"); + PropertyManager->Untie("position/h_b-cg-ft"); + PropertyManager->Untie("position/h_b-mac-ft"); +} diff --git a/src/FDM/JSBSim/FGPosition.h b/src/FDM/JSBSim/FGPosition.h index 7287ff993..00b95c24a 100644 --- a/src/FDM/JSBSim/FGPosition.h +++ b/src/FDM/JSBSim/FGPosition.h @@ -87,26 +87,26 @@ public: inline FGColumnVector3& GetVel(void) { return vVel; } inline FGColumnVector3& GetVelDot(void) { return vVelDot; } - inline double GetVn(void) { return vVel(eX); } - inline double GetVe(void) { return vVel(eY); } - inline double GetVd(void) { return vVel(eZ); } - inline double GetVground(void) { return Vground; } - inline double GetGroundTrack(void) { return psigt; } - inline double Geth(void) { return h; } - inline double Gethdot(void) { return RadiusDot; } - inline double GetLatitude(void) { return Latitude; } - inline double GetLatitudeDot(void) { return LatitudeDot; } - inline double GetLongitude(void) { return Longitude; } - inline double GetLongitudeDot(void) { return LongitudeDot; } - inline double GetRunwayRadius(void) { return RunwayRadius; } - inline double GetDistanceAGL(void) { return DistanceAGL; } - inline double GetRadius(void) { return Radius; } + inline double GetVn(void) const { return vVel(eX); } + inline double GetVe(void) const { return vVel(eY); } + inline double GetVd(void) const { return vVel(eZ); } + inline double GetVground(void) const { return Vground; } + inline double GetGroundTrack(void) const { return psigt; } + inline double Geth(void) const { return h; } + inline double Gethdot(void) const { return RadiusDot; } + inline double GetLatitude(void) const { return Latitude; } + inline double GetLatitudeDot(void) const { return LatitudeDot; } + inline double GetLongitude(void) const { return Longitude; } + inline double GetLongitudeDot(void) const { return LongitudeDot; } + inline double GetRunwayRadius(void) const { return RunwayRadius; } + inline double GetDistanceAGL(void) const { return DistanceAGL; } + inline double GetRadius(void) const { return Radius; } inline FGColumnVector3& GetRunwayNormal(void) { return vRunwayNormal; } - inline double GetGamma(void) { return gamma; } + inline double GetGamma(void) const { return gamma; } inline void SetGamma(double tt) { gamma = tt; } - inline double GetHOverBCG(void) { return hoverbcg; } - inline double GetHOverBMAC(void){ return hoverbmac; } + inline double GetHOverBCG(void) const { return hoverbcg; } + inline double GetHOverBMAC(void) const { return hoverbmac; } void SetvVel(const FGColumnVector3& v) { vVel = v; } void SetLatitude(double tt) { Latitude = tt; } void SetLongitude(double tt) { Longitude = tt; } @@ -118,6 +118,9 @@ public: vRunwayNormal << fgx << fgy << fgz; } + void bind(void); + void unbind(void); + private: FGColumnVector3 vVel; FGColumnVector3 vVelDot; diff --git a/src/FDM/JSBSim/FGPropulsion.cpp b/src/FDM/JSBSim/FGPropulsion.cpp index 054753263..df614a6ee 100644 --- a/src/FDM/JSBSim/FGPropulsion.cpp +++ b/src/FDM/JSBSim/FGPropulsion.cpp @@ -53,6 +53,8 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGPropulsion.h" +#include "FGPropertyManager.h" + static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_PROPULSION; @@ -67,7 +69,7 @@ FGPropulsion::FGPropulsion(FGFDMExec* exec) : FGModel(exec) numSelectedFuelTanks = numSelectedOxiTanks = 0; numTanks = numEngines = numThrusters = 0; numOxiTanks = numFuelTanks = 0; - + bind(); Debug(0); } @@ -77,6 +79,7 @@ FGPropulsion::~FGPropulsion() { for (unsigned int i=0; iTie("propulsion/num-engines", this, + &FGPropulsion::GetNumEngines); + PropertyManager->Tie("propulsion/num-tanks", this, + &FGPropulsion::GetNumTanks); */ + PropertyManager->Tie("propulsion/num-sel-fuel-tanks", this, + &FGPropulsion::GetnumSelectedFuelTanks); + PropertyManager->Tie("propulsion/num-sel-ox-tanks", this, + &FGPropulsion::GetnumSelectedOxiTanks); + PropertyManager->Tie("propulsion/fbx-prop-lbs", this,1, + &FGPropulsion::GetForces); + PropertyManager->Tie("propulsion/fby-prop-lbs", this,2, + &FGPropulsion::GetForces); + PropertyManager->Tie("propulsion/fbz-prop-lbs", this,3, + &FGPropulsion::GetForces); + PropertyManager->Tie("propulsion/l-prop-lbsft", this,1, + &FGPropulsion::GetMoments); + PropertyManager->Tie("propulsion/m-prop-lbsft", this,2, + &FGPropulsion::GetMoments); + PropertyManager->Tie("propulsion/n-prop-lbsft", this,3, + &FGPropulsion::GetMoments); + //PropertyManager->Tie("propulsion/tanks-weight-lbs", this, + // &FGPropulsion::GetTanksWeight); +} + +void FGPropulsion::unbind(void){ + /* PropertyManager->Untie("propulsion/num-engines"); + PropertyManager->Untie("propulsion/num-tanks"); */ + PropertyManager->Untie("propulsion/num-sel-fuel-tanks"); + PropertyManager->Untie("propulsion/num-sel-ox-tanks"); + PropertyManager->Untie("propulsion/fbx-prop-lbs"); + PropertyManager->Untie("propulsion/fby-prop-lbs"); + PropertyManager->Untie("propulsion/fbz-prop-lbs"); + PropertyManager->Untie("propulsion/l-prop-lbsft"); + PropertyManager->Untie("propulsion/m-prop-lbsft"); + PropertyManager->Untie("propulsion/n-prop-lbsft"); + //PropertyManager->Untie("propulsion/tanks-weight-lbs"); +} diff --git a/src/FDM/JSBSim/FGPropulsion.h b/src/FDM/JSBSim/FGPropulsion.h index ba1747a1c..08f6efd2b 100644 --- a/src/FDM/JSBSim/FGPropulsion.h +++ b/src/FDM/JSBSim/FGPropulsion.h @@ -126,7 +126,7 @@ public: bool Load(FGConfigFile* AC_cfg); /// Retrieves the number of engines defined for the aircraft. - inline unsigned int GetNumEngines(void) {return Engines.size();} + inline unsigned int GetNumEngines(void) const {return Engines.size();} /** Retrieves an engine object pointer from the list of engines. @param index the engine index within the vector container @@ -137,7 +137,7 @@ public: else return 0L; } // Retrieves the number of tanks defined for the aircraft. - inline unsigned int GetNumTanks(void) {return Tanks.size();} + inline unsigned int GetNumTanks(void) const {return Tanks.size();} /** Retrieves a tank object pointer from the list of tanks. @param index the tank index within the vector container @@ -156,10 +156,10 @@ public: else return 0L; } /** Returns the number of fuel tanks currently actively supplying fuel */ - inline int GetnumSelectedFuelTanks(void) {return numSelectedFuelTanks;} + inline int GetnumSelectedFuelTanks(void) const {return numSelectedFuelTanks;} /** Returns the number of oxidizer tanks currently actively supplying oxidizer */ - inline int GetnumSelectedOxiTanks(void) {return numSelectedOxiTanks;} + inline int GetnumSelectedOxiTanks(void) const {return numSelectedOxiTanks;} /** Loops the engines/thrusters until thrust output steady (used for trimming) */ bool GetSteadyState(void); @@ -172,9 +172,9 @@ public: string GetPropulsionValues(void); inline FGColumnVector3& GetForces(void) {return vForces; } - inline double GetForces(int n) { return vForces(n);} + inline double GetForces(int n) const { return vForces(n);} inline FGColumnVector3& GetMoments(void) {return vMoments;} - inline double GetMoments(int n) {return vMoments(n);} + inline double GetMoments(int n) const {return vMoments(n);} FGColumnVector3& GetTanksCG(void); double GetTanksWeight(void); @@ -184,7 +184,10 @@ public: double GetTanksIzz(const FGColumnVector3& vXYZcg); double GetTanksIxz(const FGColumnVector3& vXYZcg); double GetTanksIxy(const FGColumnVector3& vXYZcg); - + + void bind(); + void unbind(); + private: vector Engines; vector Tanks; diff --git a/src/FDM/JSBSim/FGRotation.cpp b/src/FDM/JSBSim/FGRotation.cpp index 73763e5a0..d07c973e5 100644 --- a/src/FDM/JSBSim/FGRotation.cpp +++ b/src/FDM/JSBSim/FGRotation.cpp @@ -66,6 +66,8 @@ INCLUDES #include "FGPosition.h" #include "FGAuxiliary.h" #include "FGOutput.h" +#include "FGPropertyManager.h" + static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_ROTATION; @@ -81,6 +83,8 @@ FGRotation::FGRotation(FGFDMExec* fdmex) : FGModel(fdmex) cTht=cPhi=cPsi=1.0; sTht=sPhi=sPsi=0.0; + bind(); + Debug(0); } @@ -88,6 +92,7 @@ FGRotation::FGRotation(FGFDMExec* fdmex) : FGModel(fdmex) FGRotation::~FGRotation() { + unbind(); Debug(1); } @@ -203,3 +208,62 @@ void FGRotation::Debug(int from) } } +void FGRotation::bind(void){ + PropertyManager->Tie("velocities/p-rad_sec", this,1, + &FGRotation::GetPQR); + PropertyManager->Tie("velocities/q-rad_sec", this,2, + &FGRotation::GetPQR); + PropertyManager->Tie("velocities/r-rad_sec", this,3, + &FGRotation::GetPQR); + PropertyManager->Tie("velocities/p-aero-rad_sec", this,1, + &FGRotation::GetAeroPQR); + PropertyManager->Tie("velocities/q-aero-rad_sec", this,2, + &FGRotation::GetAeroPQR); + PropertyManager->Tie("velocities/r-aero-rad_sec", this,3, + &FGRotation::GetAeroPQR); + PropertyManager->Tie("accelerations/pdot-rad_sec", this,1, + &FGRotation::GetPQRdot); + PropertyManager->Tie("accelerations/qdot-rad_sec", this,2, + &FGRotation::GetPQRdot); + PropertyManager->Tie("accelerations/rdot-rad_sec", this,3, + &FGRotation::GetPQRdot); + PropertyManager->Tie("attitude/roll-rad", this,1, + &FGRotation::GetEuler); + PropertyManager->Tie("attitude/pitch-rad", this,2, + &FGRotation::GetEuler); + PropertyManager->Tie("attitude/heading-true-rad", this,3, + &FGRotation::GetEuler); + PropertyManager->Tie("velocities/phidot-rad_sec", this,1, + &FGRotation::GetEulerRates); + PropertyManager->Tie("velocities/thetadot-rad_sec", this,2, + &FGRotation::GetEulerRates); + PropertyManager->Tie("velocities/psidot-rad_sec", this,3, + &FGRotation::GetEulerRates); + PropertyManager->Tie("attitude/phi-rad", this, + &FGRotation::Getphi); + PropertyManager->Tie("attitude/theta-rad", this, + &FGRotation::Gettht); + PropertyManager->Tie("attitude/psi-true-rad", this, + &FGRotation::Getpsi); +} + +void FGRotation::unbind(void){ + PropertyManager->Untie("velocities/p-rad_sec"); + PropertyManager->Untie("velocities/q-rad_sec"); + PropertyManager->Untie("velocities/r-rad_sec"); + PropertyManager->Untie("velocities/p-aero-rad_sec"); + PropertyManager->Untie("velocities/q-aero-rad_sec"); + PropertyManager->Untie("velocities/r-aero-rad_sec"); + PropertyManager->Untie("accelerations/pdot-rad_sec"); + PropertyManager->Untie("accelerations/qdot-rad_sec"); + PropertyManager->Untie("accelerations/rdot-rad_sec"); + PropertyManager->Untie("attitude/roll-rad"); + PropertyManager->Untie("attitude/pitch-rad"); + PropertyManager->Untie("attitude/heading-true-rad"); + PropertyManager->Untie("velocities/phidot-rad_sec"); + PropertyManager->Untie("velocities/thetadot-rad_sec"); + PropertyManager->Untie("velocities/psidot-rad_sec"); + PropertyManager->Untie("attitude/phi-rad"); + PropertyManager->Untie("attitude/theta-rad"); + PropertyManager->Untie("attitude/psi-true-rad"); +} diff --git a/src/FDM/JSBSim/FGRotation.h b/src/FDM/JSBSim/FGRotation.h index 50989e8ef..c20887184 100644 --- a/src/FDM/JSBSim/FGRotation.h +++ b/src/FDM/JSBSim/FGRotation.h @@ -87,32 +87,36 @@ public: bool Run(void); inline FGColumnVector3& GetPQR(void) {return vPQR;} - inline double GetPQR(int axis) {return vPQR(axis);} + inline double GetPQR(int axis) const {return vPQR(axis);} inline FGColumnVector3& GetAeroPQR(void) {return vAeroPQR;} - inline double GetAeroPQR(int axis) {return vAeroPQR(axis);} + inline double GetAeroPQR(int axis) const {return vAeroPQR(axis);} inline FGColumnVector3& GetPQRdot(void) {return vPQRdot;} - inline double GetPQRdot(int idx) {return vPQRdot(idx);} + inline double GetPQRdot(int idx) const {return vPQRdot(idx);} inline FGColumnVector3& GetEuler(void) {return vEuler;} - inline double GetEuler(int axis) {return vEuler(axis);} + inline double GetEuler(int axis) const {return vEuler(axis);} inline FGColumnVector3& GetEulerRates(void) { return vEulerRates; } - inline double GetEulerRates(int axis) { return vEulerRates(axis); } + inline double GetEulerRates(int axis) const { return vEulerRates(axis); } inline void SetPQR(FGColumnVector3 tt) {vPQR = tt;} inline void SetPQR(double p, double q, double r) {vPQR(eP)=p; vPQR(eQ)=q; vPQR(eR)=r;} inline void SetEuler(FGColumnVector3 tt) {vEuler = tt;} - inline double Getphi(void) {return vEuler(1);} - inline double Gettht(void) {return vEuler(2);} - inline double Getpsi(void) {return vEuler(3);} + inline double Getphi(void) const {return vEuler(1);} + inline double Gettht(void) const {return vEuler(2);} + inline double Getpsi(void) const {return vEuler(3);} - inline double GetCosphi(void) {return cPhi;} - inline double GetCostht(void) {return cTht;} - inline double GetCospsi(void) {return cPsi;} + inline double GetCosphi(void) const {return cPhi;} + inline double GetCostht(void) const {return cTht;} + inline double GetCospsi(void) const {return cPsi;} + + inline double GetSinphi(void) const {return sPhi;} + inline double GetSintht(void) const {return sTht;} + inline double GetSinpsi(void) const {return sPsi;} + + void bind(void); + void unbind(void); - inline double GetSinphi(void) {return sPhi;} - inline double GetSintht(void) {return sTht;} - inline double GetSinpsi(void) {return sPsi;} private: FGColumnVector3 vPQR; diff --git a/src/FDM/JSBSim/FGState.cpp b/src/FDM/JSBSim/FGState.cpp index b4366d5dd..11cdbfcac 100644 --- a/src/FDM/JSBSim/FGState.cpp +++ b/src/FDM/JSBSim/FGState.cpp @@ -47,7 +47,8 @@ INCLUDES # endif #endif -#ifdef _MSC_VER +#if defined(_MSC_VER)||defined(__BORLANDCPP__) +#pragma message("\n\nRedefining snprintf\n") #define snprintf _snprintf #endif @@ -92,7 +93,10 @@ FGState::FGState(FGFDMExec* fdex) Aerodynamics = FDMExec->GetAerodynamics(); GroundReactions = FDMExec->GetGroundReactions(); Propulsion = FDMExec->GetPropulsion(); + PropertyManager = FDMExec->GetPropertyManager(); + InitPropertyMaps(); + RegisterVariable(FG_TIME, " time " ); RegisterVariable(FG_QBAR, " qbar " ); RegisterVariable(FG_WINGAREA, " wing_area " ); @@ -169,7 +173,9 @@ FGState::FGState(FGFDMExec* fdex) RegisterVariable(FG_VBARH, " h-tail volume " ); RegisterVariable(FG_VBARV, " v-tail volume " ); RegisterVariable(FG_SET_LOGGING, " data_logging " ); - + + bind(); + Debug(0); } @@ -177,6 +183,7 @@ FGState::FGState(FGFDMExec* fdex) FGState::~FGState() { + unbind(); Debug(1); } @@ -249,43 +256,43 @@ double FGState::GetParameter(eParam val_idx) { case FG_AELEVATOR_POS: return fabs(FCS->GetDePos()); case FG_NELEVATOR_POS: - return FCS->GetDePosN(); + return FCS->GetDePos(ofNorm); case FG_AILERON_POS: return FCS->GetDaLPos(); case FG_AAILERON_POS: return fabs(FCS->GetDaLPos()); case FG_NAILERON_POS: - return FCS->GetDaLPosN(); + return FCS->GetDaLPos(ofNorm); case FG_LEFT_AILERON_POS: return FCS->GetDaLPos(); case FG_ALEFT_AILERON_POS: - return fabs(FCS->GetDaLPos()); + return FCS->GetDaLPos(ofMag); case FG_NLEFT_AILERON_POS: - return FCS->GetDaLPosN(); + return FCS->GetDaLPos(ofNorm); case FG_RIGHT_AILERON_POS: return FCS->GetDaRPos(); case FG_ARIGHT_AILERON_POS: - return fabs(FCS->GetDaRPos()); + return FCS->GetDaRPos(ofMag); case FG_NRIGHT_AILERON_POS: - return FCS->GetDaRPosN(); + return FCS->GetDaRPos(ofNorm); case FG_RUDDER_POS: return FCS->GetDrPos(); case FG_ARUDDER_POS: - return fabs(FCS->GetDrPos()); + return FCS->GetDrPos(ofMag); case FG_NRUDDER_POS: - return FCS->GetDrPosN(); + return FCS->GetDrPos(ofNorm); case FG_SPDBRAKE_POS: return FCS->GetDsbPos(); case FG_NSPDBRAKE_POS: - return FCS->GetDsbPosN(); + return FCS->GetDsbPos(ofNorm); case FG_SPOILERS_POS: return FCS->GetDspPos(); case FG_NSPOILERS_POS: - return FCS->GetDspPosN(); + return FCS->GetDspPos(ofNorm); case FG_FLAPS_POS: return FCS->GetDfPos(); case FG_NFLAPS_POS: - return FCS->GetDfPosN(); + return FCS->GetDfPos(ofNorm); case FG_ELEVATOR_CMD: return FCS->GetDeCmd(); case FG_AILERON_CMD: @@ -375,52 +382,52 @@ void FGState::SetParameter(eParam val_idx, double val) switch(val_idx) { case FG_ELEVATOR_POS: - FCS->SetDePos(val); + FCS->SetDePos(ofRad,val); break; case FG_NELEVATOR_POS: - FCS->SetDePosN(val); + FCS->SetDePos(ofNorm,val); break; case FG_AILERON_POS: - FCS->SetDaLPos(val); + FCS->SetDaLPos(ofRad,val); break; case FG_NAILERON_POS: - FCS->SetDaLPosN(val); + FCS->SetDaLPos(ofNorm,val); break; case FG_LEFT_AILERON_POS: - FCS->SetDaLPos(val); + FCS->SetDaLPos(ofRad,val); break; case FG_NLEFT_AILERON_POS: - FCS->SetDaLPosN(val); + FCS->SetDaLPos(ofNorm,val); break; case FG_RIGHT_AILERON_POS: - FCS->SetDaRPos(val); + FCS->SetDaRPos(ofRad,val); break; case FG_NRIGHT_AILERON_POS: - FCS->SetDaRPosN(val); + FCS->SetDaRPos(ofNorm,val); break; case FG_RUDDER_POS: - FCS->SetDrPos(val); + FCS->SetDrPos(ofRad,val); break; case FG_NRUDDER_POS: - FCS->SetDrPosN(val); + FCS->SetDrPos(ofNorm,val); break; case FG_SPDBRAKE_POS: - FCS->SetDsbPos(val); + FCS->SetDsbPos(ofRad,val); break; case FG_NSPDBRAKE_POS: - FCS->SetDsbPosN(val); + FCS->SetDsbPos(ofNorm,val); break; case FG_SPOILERS_POS: - FCS->SetDspPos(val); + FCS->SetDspPos(ofRad,val); break; case FG_NSPOILERS_POS: - FCS->SetDspPosN(val); + FCS->SetDspPos(ofNorm,val); break; case FG_FLAPS_POS: - FCS->SetDfPos(val); + FCS->SetDfPos(ofRad,val); break; case FG_NFLAPS_POS: - FCS->SetDfPosN(val); + FCS->SetDfPos(ofNorm,val); break; case FG_THROTTLE_POS: if (ActiveEngine == -1) { @@ -856,7 +863,9 @@ FGMatrix33& FGState::GetTb2s(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGState::ReportState(void) { +void FGState::ReportState(void) +{ +#if !defined(__BORLANDCPP__) char out[80], flap[10], gear[12]; cout << endl << " JSBSim State" << endl; @@ -925,8 +934,172 @@ void FGState::ReportState(void) { Position->GetVground()*fpstokts, Position->GetGroundTrack()*radtodeg ); cout << out; - +#endif } + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGState::InitPropertyMaps(void) { + ParamToProp[ FG_TIME ]="sim-time-sec"; + ParamToProp[ FG_QBAR ]="aero/qbar-psf"; + ParamToProp[ FG_WINGAREA ]="metrics/Sw-sqft"; + ParamToProp[ FG_WINGSPAN ]="metrics/bw-ft"; + ParamToProp[ FG_CBAR ]="metrics/cbarw-ft"; + ParamToProp[ FG_ALPHA ]="aero/alpha-rad"; + ParamToProp[ FG_ALPHADOT ]="aero/alphadot-rad_sec"; + ParamToProp[ FG_BETA ]="aero/beta-rad"; + ParamToProp[ FG_ABETA ]="aero/mag-beta-rad"; + ParamToProp[ FG_BETADOT ]="aero/betadot-rad_sec"; + ParamToProp[ FG_PHI ]="attitude/phi-rad"; + ParamToProp[ FG_THT ]="attitude/theta-rad"; + ParamToProp[ FG_PSI ]="attitude/psi-true-rad"; + ParamToProp[ FG_PITCHRATE ]="velocities/q-rad_sec"; + ParamToProp[ FG_ROLLRATE ]="velocities/p-rad_sec"; + ParamToProp[ FG_YAWRATE ]="velocities/r-rad_sec"; + ParamToProp[ FG_AEROP ]="velocities/p-aero-rad_sec"; + ParamToProp[ FG_AEROQ ]="velocities/q-aero-rad_sec"; + ParamToProp[ FG_AEROR ]="velocities/r-aero-rad_sec"; + ParamToProp[ FG_CL_SQRD ]="aero/cl-squared-norm"; + ParamToProp[ FG_MACH ]="velocities/mach-norm"; + ParamToProp[ FG_ALTITUDE ]="position/h-sl-ft"; + ParamToProp[ FG_BI2VEL ]="aero/bi2vel"; + ParamToProp[ FG_CI2VEL ]="aero/ci2vel"; + ParamToProp[ FG_ELEVATOR_POS ]="fcs/elevator-pos-rad"; + ParamToProp[ FG_AELEVATOR_POS ]="fcs/mag-elevator-pos-rad"; + ParamToProp[ FG_NELEVATOR_POS ]="fcs/elevator-pos-norm"; + ParamToProp[ FG_AILERON_POS ]="fcs/left-aileron-pos-rad"; + ParamToProp[ FG_AAILERON_POS ]="fcs/mag-aileron-pos-rad"; + ParamToProp[ FG_NAILERON_POS ]="fcs/left-aileron-pos-norm"; + ParamToProp[ FG_LEFT_AILERON_POS ]="fcs/left-aileron-pos-rad"; + ParamToProp[ FG_ALEFT_AILERON_POS ]="fcs/mag-left-aileron-pos-rad"; + ParamToProp[ FG_NLEFT_AILERON_POS ]="fcs/left-aileron-pos-norm"; + ParamToProp[ FG_RIGHT_AILERON_POS ]="fcs/right-aileron-pos-rad"; + ParamToProp[ FG_ARIGHT_AILERON_POS ]="fcs/mag-aileron-pos-rad"; + ParamToProp[ FG_NRIGHT_AILERON_POS ]="fcs/right-aileron-pos-norm"; + ParamToProp[ FG_RUDDER_POS ]="fcs/rudder-pos-rad"; + ParamToProp[ FG_ARUDDER_POS ]="fcs/mag-rudder-pos-rad"; + ParamToProp[ FG_NRUDDER_POS ]="fcs/rudder-pos-norm"; + ParamToProp[ FG_SPDBRAKE_POS ]="fcs/speedbrake-pos-rad"; + ParamToProp[ FG_NSPDBRAKE_POS ]="fcs/speedbrake-pos-norm"; + ParamToProp[ FG_SPOILERS_POS ]="fcs/spoiler-pos-rad"; + ParamToProp[ FG_NSPOILERS_POS ]="fcs/spoiler-pos-norm"; + ParamToProp[ FG_FLAPS_POS ]="fcs/flap-pos-deg"; + ParamToProp[ FG_NFLAPS_POS ]="fcs/flap-pos-norm"; + ParamToProp[ FG_ELEVATOR_CMD ]="fcs/elevator-cmd-norm"; + ParamToProp[ FG_AILERON_CMD ]="fcs/aileron-cmd-norm"; + ParamToProp[ FG_RUDDER_CMD ]="fcs/rudder-cmd-norm"; + ParamToProp[ FG_SPDBRAKE_CMD ]="fcs/speedbrake-cmd-norm"; + ParamToProp[ FG_SPOILERS_CMD ]="fcs/spoiler-cmd-norm"; + ParamToProp[ FG_FLAPS_CMD ]="fcs/flap-cmd-norm"; + ParamToProp[ FG_THROTTLE_CMD ]="zero"; + ParamToProp[ FG_THROTTLE_POS ]="zero"; + ParamToProp[ FG_MIXTURE_CMD ]="zero"; + ParamToProp[ FG_MIXTURE_POS ]="zero"; + ParamToProp[ FG_MAGNETO_CMD ]="zero"; + ParamToProp[ FG_STARTER_CMD ]="zero"; + ParamToProp[ FG_ACTIVE_ENGINE ]="zero"; + ParamToProp[ FG_HOVERB ]="position/h_b-mac-ft"; + ParamToProp[ FG_PITCH_TRIM_CMD ]="fcs/pitch-trim-cmd-norm"; + ParamToProp[ FG_YAW_TRIM_CMD ]="fcs/yaw-trim-cmd-norm"; + ParamToProp[ FG_ROLL_TRIM_CMD ]="fcs/roll-trim-cmd-norm"; + ParamToProp[ FG_LEFT_BRAKE_CMD ]="zero"; + ParamToProp[ FG_CENTER_BRAKE_CMD ]="zero"; + ParamToProp[ FG_RIGHT_BRAKE_CMD ]="zero"; + ParamToProp[ FG_SET_LOGGING ]="zero"; + ParamToProp[ FG_ALPHAH ]="aero/alpha-rad"; + ParamToProp[ FG_ALPHAW ]="aero/alpha-wing-rad"; + ParamToProp[ FG_LBARH ]="metrics/lh-norm"; + ParamToProp[ FG_LBARV ]="metrics/lv-norm"; + ParamToProp[ FG_HTAILAREA ]="metrics/Sh-sqft"; + ParamToProp[ FG_VTAILAREA ]="metrics/Sv-sqft"; + ParamToProp[ FG_VBARH ]="metrics/vbarh-norm"; + ParamToProp[ FG_VBARV ]="metrics/vbarv-norm"; + ParamToProp[ FG_GEAR_CMD ]="gear/gear-cmd-norm"; + ParamToProp[ FG_GEAR_POS ]="gear/gear-pos-norm"; + + PropToParam[ "sim-time-sec" ] = FG_TIME; + PropToParam[ "aero/qbar-psf" ] = FG_QBAR; + PropToParam[ "metrics/Sw-sqft" ] = FG_WINGAREA; + PropToParam[ "metrics/bw-ft" ] = FG_WINGSPAN; + PropToParam[ "metrics/cbarw-ft" ] = FG_CBAR; + PropToParam[ "aero/alpha-rad" ] = FG_ALPHA; + PropToParam[ "aero/alphadot-rad_sec" ] = FG_ALPHADOT; + PropToParam[ "aero/beta-rad" ] = FG_BETA; + PropToParam[ "aero/mag-beta-rad" ] = FG_ABETA; + PropToParam[ "aero/betadot-rad_sec" ] = FG_BETADOT; + PropToParam[ "attitude/phi-rad" ] = FG_PHI; + PropToParam[ "attitude/theta-rad" ] = FG_THT; + PropToParam[ "attitude/psi-true-rad" ] = FG_PSI; + PropToParam[ "velocities/q-rad_sec" ] = FG_PITCHRATE; + PropToParam[ "velocities/p-rad_sec" ] = FG_ROLLRATE; + PropToParam[ "velocities/r-rad_sec" ] = FG_YAWRATE; + PropToParam[ "velocities/p-aero-rad_sec" ] = FG_AEROP; + PropToParam[ "velocities/q-aero-rad_sec" ] = FG_AEROQ; + PropToParam[ "velocities/r-aero-rad_sec" ] = FG_AEROR; + PropToParam[ "aero/cl-squared-norm" ] = FG_CL_SQRD; + PropToParam[ "velocities/mach-norm" ] = FG_MACH; + PropToParam[ "position/h-sl-ft" ] = FG_ALTITUDE; + PropToParam[ "aero/bi2vel" ] = FG_BI2VEL; + PropToParam[ "aero/ci2vel" ] = FG_CI2VEL; + PropToParam[ "fcs/elevator-pos-rad" ] = FG_ELEVATOR_POS; + PropToParam[ "fcs/mag-elevator-pos-rad" ] = FG_AELEVATOR_POS; + PropToParam[ "fcs/elevator-pos-norm" ] = FG_NELEVATOR_POS; + PropToParam[ "fcs/left-aileron-pos-rad" ] = FG_AILERON_POS; + PropToParam[ "fcs/mag-aileron-pos-rad" ] = FG_AAILERON_POS; + PropToParam[ "fcs/left-aileron-pos-norm" ] = FG_NAILERON_POS; + PropToParam[ "fcs/left-aileron-pos-rad" ] = FG_LEFT_AILERON_POS; + PropToParam[ "fcs/mag-left-aileron-pos-rad" ] = FG_ALEFT_AILERON_POS; + PropToParam[ "fcs/left-aileron-pos-norm" ] = FG_NLEFT_AILERON_POS; + PropToParam[ "fcs/right-aileron-pos-rad" ] = FG_RIGHT_AILERON_POS; + PropToParam[ "fcs/mag-aileron-pos-rad" ] = FG_ARIGHT_AILERON_POS; + PropToParam[ "fcs/right-aileron-pos-norm" ] = FG_NRIGHT_AILERON_POS; + PropToParam[ "fcs/rudder-pos-rad" ] = FG_RUDDER_POS; + PropToParam[ "fcs/mag-rudder-pos-rad" ] = FG_ARUDDER_POS; + PropToParam[ "fcs/rudder-pos-norm" ] = FG_NRUDDER_POS; + PropToParam[ "fcs/speedbrake-pos-rad" ] = FG_SPDBRAKE_POS; + PropToParam[ "fcs/speedbrake-pos-norm" ] = FG_NSPDBRAKE_POS; + PropToParam[ "fcs/spoiler-pos-rad" ] = FG_SPOILERS_POS; + PropToParam[ "fcs/spoiler-pos-norm" ] = FG_NSPOILERS_POS; + PropToParam[ "fcs/flap-pos-deg" ] = FG_FLAPS_POS; + PropToParam[ "fcs/flap-pos-norm" ] = FG_NFLAPS_POS; + PropToParam[ "fcs/elevator-cmd-norm" ] = FG_ELEVATOR_CMD; + PropToParam[ "fcs/aileron-cmd-norm" ] = FG_AILERON_CMD; + PropToParam[ "fcs/rudder-cmd-norm" ] = FG_RUDDER_CMD; + PropToParam[ "fcs/speedbrake-cmd-norm" ] = FG_SPDBRAKE_CMD; + PropToParam[ "fcs/spoiler-cmd-norm" ] = FG_SPOILERS_CMD; + PropToParam[ "fcs/flap-cmd-norm" ] = FG_FLAPS_CMD; + PropToParam[ "position/h_b-mac-ft" ] = FG_HOVERB; + PropToParam[ "fcs/pitch-trim-cmd-norm" ] = FG_PITCH_TRIM_CMD; + PropToParam[ "fcs/yaw-trim-cmd-norm" ] = FG_YAW_TRIM_CMD; + PropToParam[ "fcs/roll-trim-cmd-norm" ] = FG_ROLL_TRIM_CMD; + PropToParam[ "aero/alpha-rad" ] = FG_ALPHAH; + PropToParam[ "aero/alpha-wing-rad" ] = FG_ALPHAW; + PropToParam[ "metrics/lh-norm" ] = FG_LBARH; + PropToParam[ "metrics/lv-norm" ] = FG_LBARV; + PropToParam[ "metrics/Sh-sqft" ] = FG_HTAILAREA; + PropToParam[ "metrics/Sv-sqft" ] = FG_VTAILAREA; + PropToParam[ "metrics/vbarh-norm" ] = FG_VBARH; + PropToParam[ "metrics/vbarv-norm" ] = FG_VBARV; + PropToParam[ "gear/gear-cmd-norm" ] = FG_GEAR_CMD; + PropToParam[ "gear/gear-pos-norm" ] = FG_GEAR_POS; + +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGState::bind(void) { + PropertyManager->Tie("sim-time-sec",this, + &FGState::Getsim_time); +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGState::unbind(void) { + PropertyManager->Untie("sim-time-sec"); +} + + + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print diff --git a/src/FDM/JSBSim/FGState.h b/src/FDM/JSBSim/FGState.h index 05c9a6025..ea6ab9d9a 100644 --- a/src/FDM/JSBSim/FGState.h +++ b/src/FDM/JSBSim/FGState.h @@ -176,7 +176,7 @@ public: inline double Geta(void) { return a; } /// Returns the simulation time in seconds. - inline double Getsim_time(void) { return sim_time; } + inline double Getsim_time(void) const { return sim_time; } /// Returns the simulation delta T. inline double Getdt(void) { return dt; } @@ -308,6 +308,12 @@ public: configuration, etc.) */ void ReportState(void); + + inline string GetPropertyName(eParam prm) { return ParamToProp[prm]; } + inline eParam GetParam(string property) { return PropToParam[property]; } + + void bind(); + void unbind(); private: double a; // speed of sound @@ -339,14 +345,21 @@ private: FGAerodynamics* Aerodynamics; FGGroundReactions* GroundReactions; FGPropulsion* Propulsion; + FGPropertyManager* PropertyManager; typedef map CoeffMap; CoeffMap coeffdef; typedef map ParamMap; ParamMap paramdef; + + ParamMap ParamToProp; + CoeffMap PropToParam; int ActiveEngine; + + void InitPropertyMaps(void); + void Debug(int from); }; diff --git a/src/FDM/JSBSim/FGTranslation.cpp b/src/FDM/JSBSim/FGTranslation.cpp index 9b36f81cf..51bcb3146 100644 --- a/src/FDM/JSBSim/FGTranslation.cpp +++ b/src/FDM/JSBSim/FGTranslation.cpp @@ -68,6 +68,7 @@ INCLUDES #include "FGPosition.h" #include "FGAuxiliary.h" #include "FGOutput.h" +#include "FGPropertyManager.h" static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_TRANSLATION; @@ -85,7 +86,7 @@ FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex) Mach = 0.0; alpha = beta = 0.0; adot = bdot = 0.0; - + bind(); Debug(0); } @@ -93,6 +94,7 @@ FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex) FGTranslation::~FGTranslation(void) { + unbind(); Debug(1); } @@ -221,3 +223,82 @@ void FGTranslation::Debug(int from) } } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGTranslation::bind(void){ + PropertyManager->Tie("velocities/u-fps", this,1, + &FGTranslation::GetUVW /*, + &FGTranslation::SetUVW, + true */); + PropertyManager->Tie("velocities/v-fps", this,2, + &FGTranslation::GetUVW /*, + &FGTranslation::SetUVW, + true*/); + PropertyManager->Tie("velocities/w-fps", this,3, + &FGTranslation::GetUVW /*, + &FGTranslation::SetUVW, + true*/); + PropertyManager->Tie("accelerations/udot-fps", this,1, + &FGTranslation::GetUVWdot); + PropertyManager->Tie("accelerations/vdot-fps", this,2, + &FGTranslation::GetUVWdot); + PropertyManager->Tie("accelerations/wdot-fps", this,3, + &FGTranslation::GetUVWdot); + PropertyManager->Tie("velocities/u-aero-fps", this,1, + &FGTranslation::GetvAeroUVW); + PropertyManager->Tie("velocities/v-aero-fps", this,2, + &FGTranslation::GetvAeroUVW); + PropertyManager->Tie("velocities/w-aero-fps", this,3, + &FGTranslation::GetvAeroUVW); + PropertyManager->Tie("aero/alpha-rad", this, + &FGTranslation::Getalpha, + &FGTranslation::Setalpha, + true); + PropertyManager->Tie("aero/beta-rad", this, + &FGTranslation::Getbeta, + &FGTranslation::Setbeta, + true); + PropertyManager->Tie("aero/mag-beta-rad", this, + &FGTranslation::GetMagBeta); + PropertyManager->Tie("aero/qbar-psf", this, + &FGTranslation::Getqbar, + &FGTranslation::Setqbar, + true); + PropertyManager->Tie("velocities/vt-fps", this, + &FGTranslation::GetVt, + &FGTranslation::SetVt, + true); + PropertyManager->Tie("velocities/mach-norm", this, + &FGTranslation::GetMach, + &FGTranslation::SetMach, + true); + PropertyManager->Tie("aero/alphadot-rad_sec", this, + &FGTranslation::Getadot, + &FGTranslation::Setadot, + true); + PropertyManager->Tie("aero/betadot-rad_sec", this, + &FGTranslation::Getbdot, + &FGTranslation::Setbdot, + true); +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGTranslation::unbind(void){ + PropertyManager->Untie("velocities/u-fps"); + PropertyManager->Untie("velocities/v-fps"); + PropertyManager->Untie("velocities/w-fps"); + PropertyManager->Untie("accelerations/udot-fps"); + PropertyManager->Untie("accelerations/vdot-fps"); + PropertyManager->Untie("accelerations/wdot-fps"); + PropertyManager->Untie("velocities/u-aero-fps"); + PropertyManager->Untie("velocities/v-aero-fps"); + PropertyManager->Untie("velocities/w-aero-fps"); + PropertyManager->Untie("aero/alpha-rad"); + PropertyManager->Untie("aero/beta-rad"); + PropertyManager->Untie("aero/qbar-psf"); + PropertyManager->Untie("velocities/vt-fps"); + PropertyManager->Untie("velocities/mach-norm"); + PropertyManager->Untie("aero/alphadot-rad_sec"); + PropertyManager->Untie("aero/betadot-rad_sec"); +} diff --git a/src/FDM/JSBSim/FGTranslation.h b/src/FDM/JSBSim/FGTranslation.h index faac818d2..25bd748b5 100644 --- a/src/FDM/JSBSim/FGTranslation.h +++ b/src/FDM/JSBSim/FGTranslation.h @@ -86,21 +86,22 @@ class FGTranslation : public FGModel { public: FGTranslation(FGFDMExec*); ~FGTranslation(); - + + inline double GetUVW (int idx) const { return vUVW(idx); } inline FGColumnVector3& GetUVW (void) { return vUVW; } - inline double GetUVW (int idx) { return vUVW(idx); } inline FGColumnVector3& GetUVWdot(void) { return vUVWdot; } - inline double GetUVWdot(int idx) { return vUVWdot(idx); } + inline double GetUVWdot(int idx) const { return vUVWdot(idx); } inline FGColumnVector3& GetvAeroUVW (void) { return vAeroUVW; } - inline double GetvAeroUVW (int idx) { return vAeroUVW(idx); } + inline double GetvAeroUVW (int idx) const { return vAeroUVW(idx); } - inline double Getalpha(void) { return alpha; } - inline double Getbeta (void) { return beta; } - inline double Getqbar (void) { return qbar; } - inline double GetVt (void) { return Vt; } - inline double GetMach (void) { return Mach; } - inline double Getadot (void) { return adot; } - inline double Getbdot (void) { return bdot; } + double Getalpha(void) const { return alpha; } + double Getbeta (void) const { return beta; } + inline double GetMagBeta(void) const { return fabs(beta); } + double Getqbar (void) const { return qbar; } + inline double GetVt (void) const { return Vt; } + double GetMach (void) const { return Mach; } + double Getadot (void) const { return adot; } + double Getbdot (void) const { return bdot; } void SetUVW(FGColumnVector3 tt) { vUVW = tt; } @@ -116,6 +117,9 @@ public: bool Run(void); + void bind(void); + void unbind(void); + private: FGColumnVector3 vUVW; FGColumnVector3 vUVWdot; diff --git a/src/FDM/JSBSim/FGTrim.cpp b/src/FDM/JSBSim/FGTrim.cpp index c3adc62c2..3b974f61a 100644 --- a/src/FDM/JSBSim/FGTrim.cpp +++ b/src/FDM/JSBSim/FGTrim.cpp @@ -614,18 +614,27 @@ void FGTrim::setupTurn(void){ } void FGTrim::updateRates(void){ - double phi = fgic->GetRollAngleRadIC(); - double g = fdmex->GetInertial()->gravity(); - if(fabs(phi) > 0.001 && fabs(phi) < 1.56 ) { - double p,q,r,theta,phi; - theta=fgic->GetPitchAngleRadIC(); - phi=fgic->GetRollAngleRadIC(); - psidot = g*tan(phi) / fgic->GetUBodyFpsIC(); - p=-psidot*sin(theta); - q=psidot*cos(theta)*sin(phi); - r=psidot*cos(theta)*cos(phi); - fdmex->GetRotation()->SetPQR(p,q,r); - } + if( mode == tTurn ) { + double phi = fgic->GetRollAngleRadIC(); + double g = fdmex->GetInertial()->gravity(); + if(fabs(phi) > 0.001 && fabs(phi) < 1.56 ) { + double p,q,r,theta,phi; + theta=fgic->GetPitchAngleRadIC(); + phi=fgic->GetRollAngleRadIC(); + psidot = g*tan(phi) / fgic->GetUBodyFpsIC(); + p=-psidot*sin(theta); + q=psidot*cos(theta)*sin(phi); + r=psidot*cos(theta)*cos(phi); + fdmex->GetRotation()->SetPQR(p,q,r); + } + } else if( mode == tPullup && fabs(targetNlf-1) > 0.01) { + float g,q,cgamma; + FGColumnVector3 vPQR; + g=fdmex->GetInertial()->gravity(); + cgamma=cos(fgic->GetFlightPathAngleRadIC()); + q=g*(targetNlf-cgamma)/fgic->GetVtrueFpsIC(); + fdmex->GetRotation()->SetPQR(0,q,0); + } } void FGTrim::setDebug(void) { diff --git a/src/FDM/JSBSim/FGTrim.h b/src/FDM/JSBSim/FGTrim.h index 0e6019efc..4c5221ff3 100644 --- a/src/FDM/JSBSim/FGTrim.h +++ b/src/FDM/JSBSim/FGTrim.h @@ -32,10 +32,12 @@ FUNCTIONAL DESCRIPTION -------------------------------------------------------------------------------- -This class takes the given set of IC's and finds the angle of attack, elevator, -and throttle setting required to fly steady level. This is currently for in-air -conditions only. It is implemented using an iterative, one-axis-at-a-time -scheme. +This class takes the given set of IC's and finds the aircraft state required to +maintain a specified flight condition. This flight condition can be +steady-level with non-zero sideslip, a steady turn, a pull-up or pushover. +On-ground conditions can be trimmed as well, but this is currently limited to +adjusting altitude and pitch angle only. It is implemented using an iterative, +one-axis-at-a-time scheme. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SENTRY @@ -107,12 +109,14 @@ CLASS DOCUMENTATION
  • tLongitudinal: Trim wdot with alpha, udot with thrust, qdot with elevator
  • tFull: tLongitudinal + vdot with phi, pdot with aileron, rdot with rudder and heading minus ground track (hmgt) with beta
  • +
  • tPullup: tLongitudinal but adjust alpha to achieve load factor input + with SetTargetNlf() +
  • tGround: wdot with altitude, qdot with theta, and pdot with phi
  • + The remaining modes include tCustom, which is completely user defined and tNone. - Currently, this class cannot trim a non-1g condition and is limited to - trimming for constant true airspeed in climbs and descents. Note that trims can (and do) fail for reasons that are completely outside the control of the trimming routine itself. The most common problem is the diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index baed61cc3..39686f17c 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -55,6 +55,7 @@ #include #include #include +#include #include "JSBSim.hxx" /******************************************************************************/ @@ -64,7 +65,7 @@ FGJSBsim::FGJSBsim( double dt ) { bool result; - fdmex = new FGFDMExec; + fdmex = new FGFDMExec( (FGPropertyManager*)globals->get_props() ); State = fdmex->GetState(); Atmosphere = fdmex->GetAtmosphere(); @@ -151,15 +152,7 @@ FGJSBsim::FGJSBsim( double dt ) stall_warning = fgGetNode("/sim/aero/alarms/stall-warning",true); stall_warning->setDoubleValue(0); - /* elevator_pos_deg=fgGetNode("/surface-positions/elevator-pos-deg",true); - left_aileron_pos_deg - =fgGetNode("/surface-positions/left-aileron-pos-deg",true); - right_aileron_pos_deg - =fgGetNode("/surface-positions/right-aileron-pos-deg",true); - rudder_pos_deg=fgGetNode("/surface-positions/rudder-pos-deg",true); - flap_pos_deg=fgGetNode("/surface-positions/flap-pos-deg",true); */ - flap_pos_pct=fgGetNode("/surface-positions/flap-pos-norm",true); elevator_pos_pct=fgGetNode("/surface-positions/elevator-pos-norm",true); left_aileron_pos_pct @@ -169,13 +162,7 @@ FGJSBsim::FGJSBsim( double dt ) rudder_pos_pct=fgGetNode("/surface-positions/rudder-pos-norm",true); - /* elevator_pos_deg->setDoubleValue(0); - left_aileron_pos_deg->setDoubleValue(0); - right_aileron_pos_deg->setDoubleValue(0); - rudder_pos_deg->setDoubleValue(0); - flap_pos_deg->setDoubleValue(0); */ - elevator_pos_pct->setDoubleValue(0); left_aileron_pos_pct->setDoubleValue(0); right_aileron_pos_pct->setDoubleValue(0); @@ -527,11 +514,11 @@ bool FGJSBsim::copy_from_JSBsim() { flap_pos_deg->setDoubleValue( FCS->GetDfPos() ); */ - elevator_pos_pct->setDoubleValue( FCS->GetDePosN() ); - left_aileron_pos_pct->setDoubleValue( FCS->GetDaLPosN() ); - right_aileron_pos_pct->setDoubleValue( -1*FCS->GetDaLPosN() ); - rudder_pos_pct->setDoubleValue( FCS->GetDrPosN() ); - flap_pos_pct->setDoubleValue( FCS->GetDfPosN() ); + elevator_pos_pct->setDoubleValue( FCS->GetDePos(ofNorm) ); + left_aileron_pos_pct->setDoubleValue( FCS->GetDaLPos(ofNorm) ); + right_aileron_pos_pct->setDoubleValue( -1*FCS->GetDaLPos(ofNorm) ); + rudder_pos_pct->setDoubleValue( FCS->GetDrPos(ofNorm) ); + flap_pos_pct->setDoubleValue( FCS->GetDfPos(ofNorm) ); return true; diff --git a/src/FDM/JSBSim/Makefile.am b/src/FDM/JSBSim/Makefile.am index 514b83b58..a1552a0b7 100644 --- a/src/FDM/JSBSim/Makefile.am +++ b/src/FDM/JSBSim/Makefile.am @@ -48,6 +48,7 @@ libJSBSim_a_SOURCES = \ FGEngine.cpp FGEngine.h \ FGTank.cpp FGTank.h \ FGfdmSocket.cpp FGfdmSocket.h \ + FGPropertyManager.h \ JSBSim.cxx JSBSim.hxx