X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FJSBSim%2FFGPropulsion.cpp;h=16be1ffdf21f79b940bb1acadd321671e6fefb29;hb=5fe0f047022bd168c7685169a8a3cedc8e93430e;hp=555887df1b0167ac4f5accfcfc4247b34b576c74;hpb=a2049b110f44e28cba48b5d3d0adccd6df39a8ed;p=flightgear.git diff --git a/src/FDM/JSBSim/FGPropulsion.cpp b/src/FDM/JSBSim/FGPropulsion.cpp index 555887df1..16be1ffdf 100644 --- a/src/FDM/JSBSim/FGPropulsion.cpp +++ b/src/FDM/JSBSim/FGPropulsion.cpp @@ -57,8 +57,6 @@ INCLUDES static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_PROPULSION; -extern short debug_lvl; - /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -70,8 +68,8 @@ FGPropulsion::FGPropulsion(FGFDMExec* exec) : FGModel(exec) numSelectedFuelTanks = numSelectedOxiTanks = 0; numTanks = numEngines = numThrusters = 0; numOxiTanks = numFuelTanks = 0; - Forces = new FGColumnVector(3); - Moments = new FGColumnVector(3); + Forces = new FGColumnVector3(3); + Moments = new FGColumnVector3(3); if (debug_lvl & 2) cout << "Instantiated: " << Name << endl; } @@ -117,6 +115,8 @@ bool FGPropulsion::GetSteadyState(void) { float PowerAvailable; float currentThrust = 0, lastThrust=-1; dt = State->Getdt(); + int steady_count,j=0; + bool steady=false; Forces->InitMatrix(); Moments->InitMatrix(); @@ -125,10 +125,18 @@ bool FGPropulsion::GetSteadyState(void) { for (unsigned int i=0; iSetTrimMode(true); Thrusters[i]->SetdeltaT(dt*rate); - while (pow(currentThrust - lastThrust, 2.0) > currentThrust*0.00010) { + steady=false; + while (!steady && j < 6000) { PowerAvailable = Engines[i]->Calculate(Thrusters[i]->GetPowerRequired()); lastThrust = currentThrust; currentThrust = Thrusters[i]->Calculate(PowerAvailable); + if(fabs(lastThrust-currentThrust) < 0.0001) { + steady_count++; + if(steady_count > 120) { steady=true; } + } else { + steady_count=0; + } + j++; } *Forces += Thrusters[i]->GetBodyForces(); // sum body frame forces *Moments += Thrusters[i]->GetMoments(); // sum body frame moments @@ -143,7 +151,34 @@ bool FGPropulsion::GetSteadyState(void) { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -bool FGPropulsion::LoadPropulsion(FGConfigFile* AC_cfg) + +bool FGPropulsion::ICEngineStart(void) { + float PowerAvailable; + int j; + dt = State->Getdt(); + + Forces->InitMatrix(); + Moments->InitMatrix(); + + for (unsigned int i=0; iSetTrimMode(true); + Thrusters[i]->SetdeltaT(dt*rate); + j=0; + while (!Engines[i]->GetRunning() && j < 2000) { + PowerAvailable = Engines[i]->Calculate(Thrusters[i]->GetPowerRequired()); + Thrusters[i]->Calculate(PowerAvailable); + j++; + } + *Forces += Thrusters[i]->GetBodyForces(); // sum body frame forces + *Moments += Thrusters[i]->GetMoments(); // sum body frame moments + Engines[i]->SetTrimMode(false); + } + return true; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +bool FGPropulsion::Load(FGConfigFile* AC_cfg) { string token, fullpath; string engineFileName, engType; @@ -152,6 +187,7 @@ bool FGPropulsion::LoadPropulsion(FGConfigFile* AC_cfg) string enginePath = FDMExec->GetEnginePath(); float xLoc, yLoc, zLoc, Pitch, Yaw; int Feed; + bool ThrottleAdded = false; # ifndef macintosh fullpath = enginePath + "/"; @@ -167,8 +203,8 @@ bool FGPropulsion::LoadPropulsion(FGConfigFile* AC_cfg) engineFileName = AC_cfg->GetValue("FILE"); - cout << "\n Reading engine from file: " << fullpath - + engineFileName + ".xml"<< endl; + if (debug_lvl > 0) cout << "\n Reading engine from file: " << fullpath + + engineFileName + ".xml"<< endl; FGConfigFile Eng_cfg(fullpath + engineFileName + ".xml"); if (Eng_cfg.IsOpen()) { @@ -176,6 +212,7 @@ bool FGPropulsion::LoadPropulsion(FGConfigFile* AC_cfg) engType = Eng_cfg.GetValue(); FCS->AddThrottle(); + ThrottleAdded = true; if (engType == "FG_ROCKET") { Engines.push_back(new FGRocket(FDMExec, &Eng_cfg)); @@ -194,19 +231,27 @@ bool FGPropulsion::LoadPropulsion(FGConfigFile* AC_cfg) AC_cfg->GetNextConfigLine(); while ((token = AC_cfg->GetValue()) != "/AC_ENGINE") { *AC_cfg >> token; - if (token == "XLOC") { *AC_cfg >> xLoc; cout << " X = " << xLoc << endl;} - else if (token == "YLOC") { *AC_cfg >> yLoc; cout << " Y = " << yLoc << endl;} - else if (token == "ZLOC") { *AC_cfg >> zLoc; cout << " Z = " << zLoc << endl;} - else if (token == "PITCH") { *AC_cfg >> Pitch; cout << " Pitch = " << Pitch << endl;} - else if (token == "YAW") { *AC_cfg >> Yaw; cout << " Yaw = " << Yaw << endl;} - else if (token == "FEED") { + if (token == "XLOC") { *AC_cfg >> xLoc; } + else if (token == "YLOC") { *AC_cfg >> yLoc; } + else if (token == "ZLOC") { *AC_cfg >> zLoc; } + else if (token == "PITCH") { *AC_cfg >> Pitch;} + else if (token == "YAW") { *AC_cfg >> Yaw;} + else if (token == "FEED") { *AC_cfg >> Feed; Engines[numEngines]->AddFeedTank(Feed); - cout << " Feed tank: " << Feed << endl; + if (debug_lvl > 0) cout << " Feed tank: " << Feed << endl; } else cerr << "Unknown identifier: " << token << " in engine file: " << engineFileName << endl; } + if (debug_lvl > 0) { + cout << " X = " << xLoc << endl; + cout << " Y = " << yLoc << endl; + cout << " Z = " << zLoc << endl; + cout << " Pitch = " << Pitch << endl; + cout << " Yaw = " << Yaw << endl; + } + Engines[numEngines]->SetPlacement(xLoc, yLoc, zLoc, Pitch, Yaw); numEngines++; @@ -219,7 +264,7 @@ bool FGPropulsion::LoadPropulsion(FGConfigFile* AC_cfg) } else if (token == "AC_TANK") { // ============== READING TANKS - cout << "\n Reading tank definition" << endl; + if (debug_lvl > 0) cout << "\n Reading tank definition" << endl; Tanks.push_back(new FGTank(AC_cfg)); switch(Tanks[numTanks]->GetType()) { case FGTank::ttFUEL: @@ -238,8 +283,8 @@ bool FGPropulsion::LoadPropulsion(FGConfigFile* AC_cfg) thrusterFileName = AC_cfg->GetValue("FILE"); - cout << "\n Reading thruster from file: " << - fullpath + thrusterFileName + ".xml" << endl; + if (debug_lvl > 0) cout << "\n Reading thruster from file: " << + fullpath + thrusterFileName + ".xml" << endl; FGConfigFile Thruster_cfg(fullpath + thrusterFileName + ".xml"); if (Thruster_cfg.IsOpen()) { @@ -280,6 +325,8 @@ bool FGPropulsion::LoadPropulsion(FGConfigFile* AC_cfg) AC_cfg->GetNextConfigLine(); } + if (!ThrottleAdded) FCS->AddThrottle(); // need to have at least one throttle + return true; } @@ -382,6 +429,100 @@ string FGPropulsion::GetPropulsionValues(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +FGColumnVector3& FGPropulsion::GetTanksCG(void) +{ + iTank = Tanks.begin(); + vXYZtank.InitMatrix(); + while (iTank < Tanks.end()) { + vXYZtank(eX) += (*iTank)->GetX()*(*iTank)->GetContents(); + vXYZtank(eY) += (*iTank)->GetY()*(*iTank)->GetContents(); + vXYZtank(eZ) += (*iTank)->GetZ()*(*iTank)->GetContents(); + iTank++; + } + return vXYZtank; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +float FGPropulsion::GetTanksWeight(void) +{ + float Tw = 0.0; + + iTank = Tanks.begin(); + while (iTank < Tanks.end()) { + Tw += (*iTank)->GetContents(); + iTank++; + } + return Tw; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +float FGPropulsion::GetTanksIxx(const FGColumnVector3& vXYZcg) +{ + float I = 0.0; + iTank = Tanks.begin(); + while (iTank < Tanks.end()) { + I += ((*iTank)->GetX() - vXYZcg(eX))*((*iTank)->GetX() - vXYZcg(eX)) * (*iTank)->GetContents()/(144.0*GRAVITY); + iTank++; + } + return I; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +float FGPropulsion::GetTanksIyy(const FGColumnVector3& vXYZcg) +{ + float I = 0.0; + iTank = Tanks.begin(); + while (iTank < Tanks.end()) { + I += ((*iTank)->GetY() - vXYZcg(eY))*((*iTank)->GetY() - vXYZcg(eY)) * (*iTank)->GetContents()/(144.0*GRAVITY); + iTank++; + } + return I; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +float FGPropulsion::GetTanksIzz(const FGColumnVector3& vXYZcg) +{ + float I = 0.0; + iTank = Tanks.begin(); + while (iTank < Tanks.end()) { + I += ((*iTank)->GetZ() - vXYZcg(eZ))*((*iTank)->GetZ() - vXYZcg(eZ)) * (*iTank)->GetContents()/(144.0*GRAVITY); + iTank++; + } + return I; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +float FGPropulsion::GetTanksIxz(const FGColumnVector3& vXYZcg) +{ + float I = 0.0; + iTank = Tanks.begin(); + while (iTank < Tanks.end()) { + I += ((*iTank)->GetX() - vXYZcg(eX))*((*iTank)->GetZ() - vXYZcg(eZ)) * (*iTank)->GetContents()/(144.0*GRAVITY); + iTank++; + } + return I; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +float FGPropulsion::GetTanksIxy(const FGColumnVector3& vXYZcg) +{ + float I = 0.0; + iTank = Tanks.begin(); + while (iTank != Tanks.end()) { + I += ((*iTank)->GetX() - vXYZcg(eX))*((*iTank)->GetY() - vXYZcg(eY)) * (*iTank)->GetContents()/(144.0*GRAVITY); + iTank++; + } + return I; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + void FGPropulsion::Debug(void) { //TODO: Add your source code here