]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGInitialCondition.cpp
Fix stall widths for the "auxilliary" (reverse flow) stalls so they
[flightgear.git] / src / FDM / JSBSim / FGInitialCondition.cpp
index e8f381a8b1c1150fc8af9684b588377c0e688061..b913e5be57932488cf914ce2d832023505c2dc1a 100644 (file)
@@ -1,61 +1,58 @@
 /*******************************************************************************
+
  Header:       FGInitialCondition.cpp
  Author:       Tony Peden
  Date started: 7/1/99
+
  ------------- Copyright (C) 1999  Anthony K. Peden (apeden@earthlink.net) -------------
+
  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free Software
  Foundation; either version 2 of the License, or (at your option) any later
  version.
+
  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  details.
+
  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  Place - Suite 330, Boston, MA  02111-1307, USA.
+
  Further information about the GNU General Public License can also be found on
  the world wide web at http://www.gnu.org.
+
+
  HISTORY
 --------------------------------------------------------------------------------
 7/1/99   TP   Created
+
+
 FUNCTIONAL DESCRIPTION
 --------------------------------------------------------------------------------
+
 The purpose of this class is to take a set of initial conditions and provide
 a kinematically consistent set of body axis velocity components, euler
 angles, and altitude.  This class does not attempt to trim the model i.e.
 the sim will most likely start in a very dynamic state (unless, of course,
 you have chosen your IC's wisely) even after setting it up with this class.
+
 ********************************************************************************
 INCLUDES
 *******************************************************************************/
 
 #include "FGInitialCondition.h"
 #include "FGFDMExec.h"
-#include "FGState.h"
+#include "FGInertial.h"
 #include "FGAtmosphere.h"
-#include "FGFCS.h"
-#include "FGAircraft.h"
-#include "FGTranslation.h"
-#include "FGRotation.h"
-#include "FGPosition.h"
-#include "FGAuxiliary.h"
-#include "FGOutput.h"
+#include "FGAerodynamics.h"
+#include "FGPropagate.h"
 #include "FGConfigFile.h"
 #include "FGPropertyManager.h"
 
+namespace JSBSim {
+
 static const char *IdSrc = "$Id$";
 static const char *IdHdr = ID_INITIALCONDITION;
 
@@ -70,6 +67,7 @@ FGInitialCondition::FGInitialCondition(FGFDMExec *FDMExec)
   altitude=hdot=0;
   latitude=longitude=0;
   u=v=w=0;
+  p=q=r=0;
   uw=vw=ww=0;
   vnorth=veast=vdown=0;
   wnorth=weast=wdown=0;
@@ -86,14 +84,14 @@ FGInitialCondition::FGInitialCondition(FGFDMExec *FDMExec)
 
   if(FDMExec != NULL ) {
     fdmex=FDMExec;
-    fdmex->GetPosition()->Seth(altitude);
+    fdmex->GetPropagate()->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);
 }
 
@@ -223,7 +221,7 @@ void FGInitialCondition::SetBetaRadIC(double tt) {
   beta=tt;
   sbeta=sin(beta); cbeta=cos(beta);
   getTheta();
-  
+
 }
 
 //******************************************************************************
@@ -268,7 +266,7 @@ void FGInitialCondition::SetWBodyFpsIC(double tt) {
 
 //******************************************************************************
 
-double FGInitialCondition::GetUBodyFpsIC(void) {
+double FGInitialCondition::GetUBodyFpsIC(void) const {
     if(lastSpeedSet == setvg )
       return u;
     else
@@ -277,20 +275,20 @@ double FGInitialCondition::GetUBodyFpsIC(void) {
 
 //******************************************************************************
 
-double FGInitialCondition::GetVBodyFpsIC(void) {
+double FGInitialCondition::GetVBodyFpsIC(void) const {
     if( lastSpeedSet == setvg )
       return v;
     else {
       return vt*sbeta - vw;
-    }  
+    }
 }
 
 //******************************************************************************
 
-double FGInitialCondition::GetWBodyFpsIC(void) {
+double FGInitialCondition::GetWBodyFpsIC(void) const {
     if( lastSpeedSet == setvg )
       return w;
-    else 
+    else
       return vt*salpha*cbeta -ww;
 }
 
@@ -307,41 +305,41 @@ void FGInitialCondition::SetWindNEDFpsIC(double wN, double wE, double wD ) {
 //******************************************************************************
 
 // positive from left
-void FGInitialCondition::SetHeadWindKtsIC(double head){ 
+void FGInitialCondition::SetHeadWindKtsIC(double head){
     whead=head*ktstofps;
-    lastWindSet=setwhc; 
+    lastWindSet=setwhc;
     calcWindUVW();
     if(lastSpeedSet == setvg)
       SetVgroundFpsIC(vg);
 
-} 
+}
 
 //******************************************************************************
 
-void FGInitialCondition::SetCrossWindKtsIC(double cross){ 
-    wcross=cross*ktstofps; 
-    lastWindSet=setwhc; 
+void FGInitialCondition::SetCrossWindKtsIC(double cross){
+    wcross=cross*ktstofps;
+    lastWindSet=setwhc;
     calcWindUVW();
     if(lastSpeedSet == setvg)
       SetVgroundFpsIC(vg);
 
-} 
+}
 
 //******************************************************************************
 
-void FGInitialCondition::SetWindDownKtsIC(double wD) { 
-    wdown=wD; 
+void FGInitialCondition::SetWindDownKtsIC(double wD) {
+    wdown=wD;
     calcWindUVW();
     if(lastSpeedSet == setvg)
       SetVgroundFpsIC(vg);
-} 
+}
 
 //******************************************************************************
 
 void FGInitialCondition::SetWindMagKtsIC(double mag) {
   wmag=mag*ktstofps;
   lastWindSet=setwmd;
-  calcWindUVW();    
+  calcWindUVW();
   if(lastSpeedSet == setvg)
       SetVgroundFpsIC(vg);
 }
@@ -351,7 +349,7 @@ void FGInitialCondition::SetWindMagKtsIC(double mag) {
 void FGInitialCondition::SetWindDirDegIC(double dir) {
   wdir=dir*degtorad;
   lastWindSet=setwmd;
-  calcWindUVW();    
+  calcWindUVW();
   if(lastSpeedSet == setvg)
       SetVgroundFpsIC(vg);
 }
@@ -360,7 +358,7 @@ void FGInitialCondition::SetWindDirDegIC(double dir) {
 //******************************************************************************
 
 void FGInitialCondition::calcWindUVW(void) {
-    
+
     switch(lastWindSet) {
       case setwmd:
         wnorth=wmag*cos(wdir);
@@ -372,7 +370,7 @@ void FGInitialCondition::calcWindUVW(void) {
       break;
       case setwned:
       break;
-    }    
+    }
     uw=wnorth*ctheta*cpsi +
        weast*ctheta*spsi -
        wdown*stheta;
@@ -382,14 +380,14 @@ void FGInitialCondition::calcWindUVW(void) {
     ww=wnorth*(cphi*stheta*cpsi + sphi*spsi) +
        weast*(cphi*stheta*spsi - sphi*cpsi) +
        wdown*cphi*ctheta;
-            
-   
+
+
     /* cout << "FGInitialCondition::calcWindUVW: wnorth, weast, wdown "
          << wnorth << ", " << weast << ", " << wdown << endl;
     cout << "FGInitialCondition::calcWindUVW: theta, phi, psi "
           << theta << ", " << phi << ", " << psi << endl;
     cout << "FGInitialCondition::calcWindUVW: uw, vw, ww "
-          << uw << ", " << vw << ", " << ww << endl;   */
+          << uw << ", " << vw << ", " << ww << endl; */
 
 }
 
@@ -397,7 +395,7 @@ void FGInitialCondition::calcWindUVW(void) {
 
 void FGInitialCondition::SetAltitudeFtIC(double tt) {
   altitude=tt;
-  fdmex->GetPosition()->Seth(altitude);
+  fdmex->GetPropagate()->Seth(altitude);
   fdmex->GetAtmosphere()->Run();
   //lets try to make sure the user gets what they intended
 
@@ -425,9 +423,7 @@ void FGInitialCondition::SetAltitudeFtIC(double tt) {
 //******************************************************************************
 
 void FGInitialCondition::SetAltitudeAGLFtIC(double tt) {
-  fdmex->GetPosition()->SetDistanceAGL(tt);
-  altitude=fdmex->GetPosition()->Geth();
-  SetAltitudeFtIC(altitude);
+  SetAltitudeFtIC(terrain_altitude + tt);
 }
 
 //******************************************************************************
@@ -505,12 +501,12 @@ bool FGInitialCondition::getMachFromVcas(double *Mach,double vcas) {
 bool FGInitialCondition::getAlpha(void) {
   bool result=false;
   double guess=theta-gamma;
-  
+
   if(vt < 0.01) return 0;
-  
+
   xlo=xhi=0;
-  xmin=fdmex->GetAircraft()->GetAlphaCLMin();
-  xmax=fdmex->GetAircraft()->GetAlphaCLMax();
+  xmin=fdmex->GetAerodynamics()->GetAlphaCLMin();
+  xmax=fdmex->GetAerodynamics()->GetAlphaCLMax();
   sfunc=&FGInitialCondition::GammaEqOfAlpha;
   if(findInterval(0,guess)){
     if(solve(&alpha,0)){
@@ -528,9 +524,9 @@ bool FGInitialCondition::getAlpha(void) {
 bool FGInitialCondition::getTheta(void) {
   bool result=false;
   double guess=alpha+gamma;
-  
+
   if(vt < 0.01) return 0;
-  
+
   xlo=xhi=0;
   xmin=-89;xmax=89;
   sfunc=&FGInitialCondition::GammaEqOfTheta;
@@ -676,7 +672,7 @@ bool FGInitialCondition::solve(double *y,double x)
   while ((fabs(d) > eps) && (i < 100)) {
     d=(x3-x1)/d0;
     x2 = x1-d*d0*f1/(f3-f1);
-    
+
     f2=(this->*sfunc)(x2)-x;
     //cout << "solve x1,x2,x3: " << x1 << "," << x2 << "," << x3 << endl;
     //cout << "                " << f1 << "," << f2 << "," << f3 << endl;
@@ -707,34 +703,40 @@ bool FGInitialCondition::solve(double *y,double x)
 //******************************************************************************
 
 double FGInitialCondition::GetWindDirDegIC(void) {
-  if(weast != 0.0) 
+  if(weast != 0.0)
     return atan2(weast,wnorth)*radtodeg;
-  else if(wnorth > 0) 
+  else if(wnorth > 0)
     return 0.0;
   else
     return 180.0;
-}        
+}
 
 //******************************************************************************
 
-bool FGInitialCondition::Load(string acpath, string acname, string rstfile)
+bool FGInitialCondition::Load(string rstfile, bool useStoredPath)
 {
-  string resetDef;
+  string resetDef, acpath;
   string token="";
 
   double temp;
-
-# ifndef macintosh
-  resetDef = acpath + "/" + acname + "/" + rstfile + ".xml";
-# else
-  resetDef = acpath + ";" + acname + ";" + rstfile + ".xml";
-# endif
+  # ifndef macintosh
+    string sep = "/";
+  # else
+    string sep = ";";
+  #endif
+
+  if( useStoredPath ) {
+    acpath = fdmex->GetAircraftPath() + sep + fdmex->GetModelName();
+    resetDef = acpath + sep + rstfile + ".xml";
+  } else {
+    resetDef = rstfile;
+  }
 
   FGConfigFile resetfile(resetDef);
   if (!resetfile.IsOpen()) {
     cerr << "Failed to open reset file: " << resetDef << endl;
     return false;
-  }  
+  }
 
   resetfile.GetNextConfigLine();
   token = resetfile.GetValue();
@@ -743,13 +745,13 @@ bool FGInitialCondition::Load(string acpath, string acname, string rstfile)
          << " does not appear to be a reset file" << endl;
     return false;
   }
-  
+
   resetfile.GetNextConfigLine();
   resetfile >> token;
   while (token != string("/initialize") && token != string("EOF")) {
-    if (token == "UBODY" ) { resetfile >> temp; SetUBodyFpsIC(temp); } 
-    if (token == "VBODY" ) { resetfile >> temp; SetVBodyFpsIC(temp); } 
-    if (token == "WBODY" ) { resetfile >> temp; SetWBodyFpsIC(temp); }  
+    if (token == "UBODY" ) { resetfile >> temp; SetUBodyFpsIC(temp); }
+    if (token == "VBODY" ) { resetfile >> temp; SetVBodyFpsIC(temp); }
+    if (token == "WBODY" ) { resetfile >> temp; SetWBodyFpsIC(temp); }
     if (token == "LATITUDE" ) { resetfile >> temp; SetLatitudeDegIC(temp); }
     if (token == "LONGITUDE" ) { resetfile >> temp; SetLongitudeDegIC(temp); }
     if (token == "PHI" ) { resetfile >> temp; SetRollAngleDegIC(temp); }
@@ -770,8 +772,8 @@ bool FGInitialCondition::Load(string acpath, string acname, string rstfile)
     resetfile >> token;
   }
 
-  fdmex->RunIC(this);
-  
+  fdmex->RunIC();
+
   return true;
 }
 
@@ -922,6 +924,19 @@ void FGInitialCondition::bind(void){
                        &FGInitialCondition::GetLongitudeRadIC,
                        &FGInitialCondition::SetLongitudeRadIC,
                        true);
+  PropertyManager->Tie("ic/p-rad_sec", this,
+                       &FGInitialCondition::GetPRadpsIC,
+                       &FGInitialCondition::SetPRadpsIC,
+                       true);
+  PropertyManager->Tie("ic/q-rad_sec", this,
+                       &FGInitialCondition::GetQRadpsIC,
+                       &FGInitialCondition::SetQRadpsIC,
+                       true);
+  PropertyManager->Tie("ic/r-rad_sec", this,
+                       &FGInitialCondition::GetRRadpsIC,
+                       &FGInitialCondition::SetRRadpsIC,
+                       true);
+
 }
 
 //******************************************************************************
@@ -957,7 +972,7 @@ void FGInitialCondition::unbind(void){
   /* 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"); */
@@ -970,6 +985,10 @@ void FGInitialCondition::unbind(void){
   PropertyManager->Untie("ic/psi-true-rad");
   PropertyManager->Untie("ic/lat-gc-rad");
   PropertyManager->Untie("ic/long-gc-rad");
+  PropertyManager->Untie("ic/p-rad_sec");
+  PropertyManager->Untie("ic/q-rad_sec");
+  PropertyManager->Untie("ic/r-rad_sec");
+
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -1014,4 +1033,4 @@ void FGInitialCondition::Debug(int from)
     }
   }
 }
-
+}