static const char *IdSrc = "$Id$";
static const char *IdHdr = ID_PROPULSION;
-extern short debug_lvl;
-
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
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;
}
float PowerAvailable;
float currentThrust = 0, lastThrust=-1;
dt = State->Getdt();
+ int steady_count,j=0;
+ bool steady=false;
Forces->InitMatrix();
Moments->InitMatrix();
for (unsigned int i=0; i<numEngines; i++) {
Engines[i]->SetTrimMode(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
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-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; i<numEngines; i++) {
+ Engines[i]->SetTrimMode(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;
string enginePath = FDMExec->GetEnginePath();
float xLoc, yLoc, zLoc, Pitch, Yaw;
int Feed;
+ bool ThrottleAdded = false;
# ifndef macintosh
fullpath = enginePath + "/";
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()) {
engType = Eng_cfg.GetValue();
FCS->AddThrottle();
+ ThrottleAdded = true;
if (engType == "FG_ROCKET") {
Engines.push_back(new FGRocket(FDMExec, &Eng_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++;
} 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:
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()) {
AC_cfg->GetNextConfigLine();
}
+ if (!ThrottleAdded) FCS->AddThrottle(); // need to have at least one throttle
+
return true;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+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