/*******************************************************************************
-
+
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 "FGAerodynamics.h"
-#include "FGFCS.h"
-#include "FGAircraft.h"
-#include "FGTranslation.h"
-#include "FGRotation.h"
-#include "FGPosition.h"
-#include "FGAuxiliary.h"
-#include "FGOutput.h"
+#include "FGPropagate.h"
#include "FGConfigFile.h"
#include "FGPropertyManager.h"
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;
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);
}
beta=tt;
sbeta=sin(beta); cbeta=cos(beta);
getTheta();
-
+
}
//******************************************************************************
//******************************************************************************
-double FGInitialCondition::GetUBodyFpsIC(void) {
+double FGInitialCondition::GetUBodyFpsIC(void) const {
if(lastSpeedSet == setvg )
return u;
else
//******************************************************************************
-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;
}
//******************************************************************************
// 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);
}
void FGInitialCondition::SetWindDirDegIC(double dir) {
wdir=dir*degtorad;
lastWindSet=setwmd;
- calcWindUVW();
+ calcWindUVW();
if(lastSpeedSet == setvg)
SetVgroundFpsIC(vg);
}
//******************************************************************************
void FGInitialCondition::calcWindUVW(void) {
-
+
switch(lastWindSet) {
case setwmd:
wnorth=wmag*cos(wdir);
break;
case setwned:
break;
- }
+ }
uw=wnorth*ctheta*cpsi +
weast*ctheta*spsi -
wdown*stheta;
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; */
}
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
//******************************************************************************
void FGInitialCondition::SetAltitudeAGLFtIC(double tt) {
- fdmex->GetPosition()->SetDistanceAGL(tt);
- altitude=fdmex->GetPosition()->Geth();
+ fdmex->GetPropagate()->SetDistanceAGL(tt);
+ altitude=fdmex->GetPropagate()->Geth();
SetAltitudeFtIC(altitude);
}
bool FGInitialCondition::getAlpha(void) {
bool result=false;
double guess=theta-gamma;
-
+
if(vt < 0.01) return 0;
-
+
xlo=xhi=0;
xmin=fdmex->GetAerodynamics()->GetAlphaCLMin();
xmax=fdmex->GetAerodynamics()->GetAlphaCLMax();
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;
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;
//******************************************************************************
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 rstfile, bool useStoredPath)
{
- string resetDef;
+ string resetDef, acpath;
string token="";
double temp;
string sep = "/";
# else
string sep = ";";
- #endif
-
+ #endif
+
if( useStoredPath ) {
- string acpath = fdmex->GetAircraftPath() + sep + fdmex->GetModelName();
+ 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();
<< " 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); }
}
fdmex->RunIC();
-
+
return true;
}
&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);
+
}
//******************************************************************************
/* 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/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");
+
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%