]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGAircraft.cpp
Friday the 13th JSBSim update ... :-0 !!!
[flightgear.git] / src / FDM / JSBSim / FGAircraft.cpp
index 316356337b7228e305daa2ac94f3d251f28b8cc8..debb1d9eedab2e263e25900bd298c4cf9ad95bf7 100644 (file)
@@ -128,6 +128,9 @@ INCLUDES
 #include "FGAuxiliary.h"
 #include "FGOutput.h"
 
+static const char *IdSrc = "$Header$";
+static const char *IdHdr = ID_AIRCRAFT;
+
 /*******************************************************************************
 ************************************ CODE **************************************
 *******************************************************************************/
@@ -135,12 +138,13 @@ INCLUDES
 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex),
     vMoments(3),
     vForces(3),
+    vFs(3),
     vXYZrp(3),
     vbaseXYZcg(3),
     vXYZcg(3),
     vXYZep(3),
-    vEuler(3),
-    vFs(3)
+    vEuler(3)
+    
 {
   Name = "FGAircraft";
 
@@ -150,8 +154,12 @@ FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex),
   AxisIdx["ROLL"]  = 3;
   AxisIdx["PITCH"] = 4;
   AxisIdx["YAW"]   = 5;
+  
+  Coeff = new CoeffArray[6];
 
   GearUp = false;
+  
+  alphaclmin = alphaclmax = 0;
 
   numTanks = numEngines = numSelectedFuelTanks = numSelectedOxiTanks = 0;
 }
@@ -160,7 +168,24 @@ FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex),
 /******************************************************************************/
 
 
-FGAircraft::~FGAircraft(void) {}
+FGAircraft::~FGAircraft(void) { 
+  unsigned int i,j;
+
+  if (Engine != NULL) {
+    for (i=0; i<numEngines; i++)
+      delete Engine[i];
+  }    
+  if (Tank != NULL) {
+    for (i=0; i<numTanks; i++)
+      delete Tank[i];
+  }    
+  for (i=0; i<6; i++) {
+    for (j=0; j<Coeff[i].size(); j++) {
+      delete Coeff[i][j];
+    }
+  }
+  delete[] Coeff;
+}
 
 /******************************************************************************/
 
@@ -173,7 +198,11 @@ bool FGAircraft::LoadAircraft(string aircraft_path, string engine_path, string f
   AircraftPath = aircraft_path;
   EnginePath = engine_path;
 
-  aircraftCfgFileName = AircraftPath + "/" + fname + "/" + fname + ".cfg";
+# ifndef macintosh
+  aircraftCfgFileName = AircraftPath + "/" + fname + "/" + fname + ".xml";
+# else  
+  aircraftCfgFileName = AircraftPath + ";" + fname + ";" + fname + ".xml";
+# endif
 
   FGConfigFile AC_cfg(aircraftCfgFileName);
   if (!AC_cfg.IsOpen()) return false;
@@ -214,13 +243,16 @@ bool FGAircraft::Run(void) {
     for (int i = 1; i <= 3; i++)  vForces(i) = vMoments(i) = 0.0;
 
     MassChange();
-
     FMProp();
     FMAero();
     FMGear();
     FMMass();
 
-    nlf=vFs(eZ)/Weight;
+    nlf = 0;
+    if (fabs(Position->GetGamma()) < 1.57) {
+        nlf = vFs(eZ)/(Weight*cos(Position->GetGamma()));
+    }    
+        
   } else {                               // skip Run() execution this time
   }
 
@@ -234,7 +266,7 @@ void FGAircraft::MassChange() {
   static FGColumnVector vXYZtank(3);
   float Tw;
   float IXXt, IYYt, IZZt, IXZt;
-  int t;
+  unsigned int t;
   unsigned int axis_ctr;
 
   for (axis_ctr=1; axis_ctr<=3; axis_ctr++) vXYZtank(axis_ctr) = 0.0;
@@ -250,7 +282,7 @@ void FGAircraft::MassChange() {
 
   float Oshortage, Fshortage;
 
-  for (int e=0; e<numEngines; e++) {
+  for (unsigned int e=0; e<numEngines; e++) {
     Fshortage = Oshortage = 0.0;
     for (t=0; t<numTanks; t++) {
       switch(Engine[e]->GetType()) {
@@ -326,17 +358,19 @@ void FGAircraft::MassChange() {
 
 void FGAircraft::FMAero(void) {
   static FGColumnVector vDXYZcg(3);
+  static FGColumnVector vAeroBodyForces(3);
   unsigned int axis_ctr,ctr;
 
   for (axis_ctr=1; axis_ctr<=3; axis_ctr++) vFs(axis_ctr) = 0.0;
 
   for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
     for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
-      vFs(axis_ctr+1) += Coeff[axis_ctr][ctr].TotalValue();
+      vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
     }
   }
 
-  vForces += State->GetTs2b(alpha, beta)*vFs;
+  vAeroBodyForces = State->GetTs2b(alpha, beta)*vFs;
+  vForces += vAeroBodyForces;
 
   // The d*cg distances below, given in inches, are the distances FROM the c.g.
   // TO the reference point. Since the c.g. and ref point are given in inches in
@@ -348,13 +382,13 @@ void FGAircraft::FMAero(void) {
   vDXYZcg(eY) =  (vXYZrp(eY) - vXYZcg(eY))/12.0;
   vDXYZcg(eZ) = -(vXYZrp(eZ) - vXYZcg(eZ))/12.0;
 
-  vMoments(eL) += vForces(eZ)*vDXYZcg(eY) - vForces(eY)*vDXYZcg(eZ); // rolling moment
-  vMoments(eM) += vForces(eX)*vDXYZcg(eZ) - vForces(eZ)*vDXYZcg(eX); // pitching moment
-  vMoments(eN) += vForces(eY)*vDXYZcg(eX) - vForces(eX)*vDXYZcg(eY); // yawing moment
-
+  vMoments(eL) += vAeroBodyForces(eZ)*vDXYZcg(eY) - vAeroBodyForces(eY)*vDXYZcg(eZ); // rolling moment
+  vMoments(eM) += vAeroBodyForces(eX)*vDXYZcg(eZ) - vAeroBodyForces(eZ)*vDXYZcg(eX); // pitching moment
+  vMoments(eN) += vAeroBodyForces(eY)*vDXYZcg(eX) - vAeroBodyForces(eX)*vDXYZcg(eY); // yawing moment
+  
   for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
     for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
-      vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr].TotalValue();
+      vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
     }
   }
 }
@@ -362,14 +396,16 @@ void FGAircraft::FMAero(void) {
 /******************************************************************************/
 
 void FGAircraft::FMGear(void) {
-  if (GearUp) {
-    // crash routine
-  }
-  else {
-    for (unsigned int i=0;i<lGear.size();i++) {
-      vForces  += lGear[i]->Force();
-      vMoments += lGear[i]->Moment();
+
+  if ( !GearUp ) {
+    vector <FGLGear>::iterator iGear = lGear.begin();
+    while (iGear != lGear.end()) {
+      vForces  += iGear->Force();
+      vMoments += iGear->Moment();
+      iGear++;
     }
+  } else {
+    // Crash Routine
   }
 }
 
@@ -384,9 +420,13 @@ void FGAircraft::FMMass(void) {
 /******************************************************************************/
 
 void FGAircraft::FMProp(void) {
-  for (int i=0;i<numEngines;i++) {
+  for (unsigned int i=0;i<numEngines;i++) {
+
+    // Changes required here for new engine placement parameters (i.e. location and direction)
+
     vForces(eX) += Engine[i]->CalcThrust();
   }
+  
 }
 
 /******************************************************************************/
@@ -409,18 +449,45 @@ void FGAircraft::ReadMetrics(FGConfigFile* AC_cfg) {
 
   while ((token = AC_cfg->GetValue()) != "/METRICS") {
     *AC_cfg >> parameter;
-    if (parameter == "AC_WINGAREA") *AC_cfg >> WingArea;
-    else if (parameter == "AC_WINGSPAN") *AC_cfg >> WingSpan;
-    else if (parameter == "AC_CHORD") *AC_cfg >> cbar;
-    else if (parameter == "AC_IXX") *AC_cfg >> baseIxx;
-    else if (parameter == "AC_IYY") *AC_cfg >> baseIyy;
-    else if (parameter == "AC_IZZ") *AC_cfg >> baseIzz;
-    else if (parameter == "AC_IXZ") *AC_cfg >> baseIxz;
-    else if (parameter == "AC_EMPTYWT") *AC_cfg >> EmptyWeight;
-    else if (parameter == "AC_CGLOC") *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
-    else if (parameter == "AC_EYEPTLOC") *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
-    else if (parameter == "AC_AERORP") *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
-    else if (parameter == "AC_ALPHALIMITS") *AC_cfg >> alphaclmin >> alphaclmax;
+    if (parameter == "AC_WINGAREA") {
+        *AC_cfg >> WingArea;
+        cout << "    WingArea: " << WingArea  << endl; 
+    } else if (parameter == "AC_WINGSPAN") {
+        *AC_cfg >> WingSpan;
+        cout << "    WingSpan: " << WingSpan  << endl;
+    } else if (parameter == "AC_CHORD") {
+        *AC_cfg >> cbar;
+        cout << "    Chord: " << cbar << endl;
+    } else if (parameter == "AC_IXX") {
+        *AC_cfg >> baseIxx;
+        cout << "    baseIxx: " << baseIxx << endl;
+    } else if (parameter == "AC_IYY") {
+        *AC_cfg >> baseIyy;
+        cout << "    baseIyy: " << baseIyy << endl;
+    } else if (parameter == "AC_IZZ") { 
+        *AC_cfg >> baseIzz;
+        cout << "    baseIzz: " << baseIzz << endl;
+    } else if (parameter == "AC_IXZ") { 
+        *AC_cfg >> baseIxz;
+        cout << "    baseIxz: " << baseIxz  << endl;
+    } else if (parameter == "AC_EMPTYWT") {
+        *AC_cfg >> EmptyWeight;
+        cout << "    EmptyWeight: " << EmptyWeight  << endl;
+    } else if (parameter == "AC_CGLOC") {
+        *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
+        cout << "    CG (x, y, z): " << vbaseXYZcg << endl;
+    } else if (parameter == "AC_EYEPTLOC") {
+        *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
+        cout << "    Eyepoint (x, y, z): " << vXYZep << endl;
+    } else if (parameter == "AC_AERORP") {
+        *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
+        cout << "    Ref Pt (x, y, z): " << vXYZrp << endl;
+    } else if (parameter == "AC_ALPHALIMITS") {
+        *AC_cfg >> alphaclmin >> alphaclmax;
+        cout << "    Maximum Alpha: " << alphaclmax
+             << "    Minimum Alpha: " << alphaclmin 
+             << endl;
+    }         
   }
 }
 
@@ -472,22 +539,17 @@ void FGAircraft::ReadAerodynamics(FGConfigFile* AC_cfg) {
   string token, axis;
 
   AC_cfg->GetNextConfigLine();
-
-  Coeff.push_back(*(new CoeffArray()));
-  Coeff.push_back(*(new CoeffArray()));
-  Coeff.push_back(*(new CoeffArray()));
-  Coeff.push_back(*(new CoeffArray()));
-  Coeff.push_back(*(new CoeffArray()));
-  Coeff.push_back(*(new CoeffArray()));
-
+  
   while ((token = AC_cfg->GetValue()) != "/AERODYNAMICS") {
     if (token == "AXIS") {
+      CoeffArray ca;
       axis = AC_cfg->GetValue("NAME");
       AC_cfg->GetNextConfigLine();
       while ((token = AC_cfg->GetValue()) != "/AXIS") {
-        Coeff[AxisIdx[axis]].push_back(*(new FGCoefficient(FDMExec, AC_cfg)));
-        DisplayCoeffFactors(Coeff[AxisIdx[axis]].back().Getmultipliers());
+        ca.push_back(new FGCoefficient(FDMExec, AC_cfg));
+        DisplayCoeffFactors(ca.back()->Getmultipliers());
       }
+      Coeff[AxisIdx[axis]]=ca;
       AC_cfg->GetNextConfigLine();
     }
   }
@@ -501,7 +563,7 @@ void FGAircraft::ReadUndercarriage(FGConfigFile* AC_cfg) {
   AC_cfg->GetNextConfigLine();
 
   while ((token = AC_cfg->GetValue()) != "/UNDERCARRIAGE") {
-    lGear.push_back(new FGLGear(AC_cfg, FDMExec));
+    lGear.push_back(FGLGear(AC_cfg, FDMExec));
   }
 }
 
@@ -597,39 +659,11 @@ void FGAircraft::ReadPrologue(FGConfigFile* AC_cfg) {
 
 /******************************************************************************/
 
-void FGAircraft::DisplayCoeffFactors(int multipliers) {
+void FGAircraft::DisplayCoeffFactors(vector <eParam> multipliers) {
   cout << "   Non-Dimensionalized by: ";
 
-  if (multipliers & FG_QBAR)      cout << "qbar ";
-  if (multipliers & FG_WINGAREA)  cout << "S ";
-  if (multipliers & FG_WINGSPAN)  cout << "b ";
-  if (multipliers & FG_CBAR)      cout << "c ";
-  if (multipliers & FG_ALPHA)     cout << "alpha ";
-  if (multipliers & FG_ALPHADOT)  cout << "alphadot ";
-  if (multipliers & FG_BETA)      cout << "beta ";
-  if (multipliers & FG_BETADOT)   cout << "betadot ";
-  if (multipliers & FG_PITCHRATE) cout << "q ";
-  if (multipliers & FG_ROLLRATE)  cout << "p ";
-  if (multipliers & FG_YAWRATE)   cout << "r ";
-
-  if (multipliers & FG_ELEVATOR_CMD)  cout << "De cmd ";
-  if (multipliers & FG_AILERON_CMD)   cout << "Da cmd ";
-  if (multipliers & FG_RUDDER_CMD)    cout << "Dr cmd ";
-  if (multipliers & FG_FLAPS_CMD)     cout << "Df cmd ";
-  if (multipliers & FG_SPOILERS_CMD)  cout << "Dsp cmd ";
-  if (multipliers & FG_SPDBRAKE_CMD)   cout << "Dsb cmd ";
-
-  if (multipliers & FG_ELEVATOR_POS)  cout << "De ";
-  if (multipliers & FG_AILERON_POS)   cout << "Da ";
-  if (multipliers & FG_RUDDER_POS)    cout << "Dr ";
-  if (multipliers & FG_FLAPS_POS)     cout << "Df ";
-  if (multipliers & FG_SPOILERS_POS)  cout << "Dsp ";
-  if (multipliers & FG_SPDBRAKE_POS)  cout << "Dsb ";
-
-  if (multipliers & FG_MACH)      cout << "Mach ";
-  if (multipliers & FG_ALTITUDE)  cout << "h ";
-  if (multipliers & FG_BI2VEL)    cout << "b /(2*Vt) ";
-  if (multipliers & FG_CI2VEL)    cout << "c /(2*Vt) ";
+  for (unsigned int i=0; i<multipliers.size();i++)
+    cout << State->paramdef[multipliers[i]];
 
   cout << endl;
 }
@@ -647,7 +681,7 @@ string FGAircraft::GetCoefficientStrings(void) {
       } else {
         CoeffStrings += ", ";
       }
-      CoeffStrings += Coeff[axis][sd].Getname();
+      CoeffStrings += Coeff[axis][sd]->Getname();
     }
   }
 
@@ -668,7 +702,7 @@ string FGAircraft::GetCoefficientValues(void) {
       } else {
         SDValues += ", ";
       }
-      sprintf(buffer, "%9.6f", Coeff[axis][sd].GetSD());
+      sprintf(buffer, "%9.6f", Coeff[axis][sd]->GetSD());
       SDValues += string(buffer);
     }
   }
@@ -685,10 +719,10 @@ string FGAircraft::GetGroundReactionStrings(void) {
 
   for (unsigned int i=0;i<lGear.size();i++) {
     if (!firstime) GroundReactionStrings += ", ";
-    GroundReactionStrings += (lGear[i]->GetName() + "_WOW, ");
-    GroundReactionStrings += (lGear[i]->GetName() + "_compressLength, ");
-    GroundReactionStrings += (lGear[i]->GetName() + "_compressSpeed, ");
-    GroundReactionStrings += (lGear[i]->GetName() + "_Force");
+    GroundReactionStrings += (lGear[i].GetName() + "_WOW, ");
+    GroundReactionStrings += (lGear[i].GetName() + "_compressLength, ");
+    GroundReactionStrings += (lGear[i].GetName() + "_compressSpeed, ");
+    GroundReactionStrings += (lGear[i].GetName() + "_Force");
 
     firstime = false;
   }
@@ -706,10 +740,10 @@ string FGAircraft::GetGroundReactionValues(void) {
 
   for (unsigned int i=0;i<lGear.size();i++) {
     if (!firstime) GroundReactionValues += ", ";
-    GroundReactionValues += string( lGear[i]->GetWOW()?"1":"0" ) + ", ";
-    GroundReactionValues += (string(gcvt(lGear[i]->GetCompLen(),    5, buff)) + ", ");
-    GroundReactionValues += (string(gcvt(lGear[i]->GetCompVel(),    6, buff)) + ", ");
-    GroundReactionValues += (string(gcvt(lGear[i]->GetCompForce(), 10, buff)));
+    GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", ";
+    GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(),    5, buff)) + ", ");
+    GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(),    6, buff)) + ", ");
+    GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff)));
 
     firstime = false;
   }