Dynamic calculation of CG and inertias.
This commit is contained in:
parent
96b4460ac4
commit
6eaf06957d
4 changed files with 77 additions and 13 deletions
|
@ -190,24 +190,24 @@ bool FGAircraft::LoadAircraft(string aircraft_path, string engine_path, string f
|
||||||
aircraftfile >> cbar;
|
aircraftfile >> cbar;
|
||||||
cout << "Aircraft Chord: " << cbar << endl;
|
cout << "Aircraft Chord: " << cbar << endl;
|
||||||
} else if (holding_string == "AC_IXX") {
|
} else if (holding_string == "AC_IXX") {
|
||||||
aircraftfile >> Ixx;
|
aircraftfile >> baseIxx;
|
||||||
cout << "Aircraft Ixx: " << Ixx << endl;
|
cout << "Aircraft Base Ixx: " << baseIxx << endl;
|
||||||
} else if (holding_string == "AC_IYY") {
|
} else if (holding_string == "AC_IYY") {
|
||||||
aircraftfile >> Iyy;
|
aircraftfile >> baseIyy;
|
||||||
cout << "Aircraft Iyy: " << Iyy << endl;
|
cout << "Aircraft Base Iyy: " << baseIyy << endl;
|
||||||
} else if (holding_string == "AC_IZZ") {
|
} else if (holding_string == "AC_IZZ") {
|
||||||
aircraftfile >> Izz;
|
aircraftfile >> baseIzz;
|
||||||
cout << "Aircraft Izz: " << Izz << endl;
|
cout << "Aircraft Base Izz: " << baseIzz << endl;
|
||||||
} else if (holding_string == "AC_IXZ") {
|
} else if (holding_string == "AC_IXZ") {
|
||||||
aircraftfile >> Ixz;
|
aircraftfile >> baseIxz;
|
||||||
cout << "Aircraft Ixz: " << Ixz << endl;
|
cout << "Aircraft Base Ixz: " << baseIxz << endl;
|
||||||
} else if (holding_string == "AC_EMPTYWT") {
|
} else if (holding_string == "AC_EMPTYWT") {
|
||||||
aircraftfile >> EmptyWeight;
|
aircraftfile >> EmptyWeight;
|
||||||
EmptyMass = EmptyWeight / GRAVITY;
|
EmptyMass = EmptyWeight / GRAVITY;
|
||||||
cout << "Aircraft Empty Weight: " << EmptyWeight << endl;
|
cout << "Aircraft Empty Weight: " << EmptyWeight << endl;
|
||||||
} else if (holding_string == "AC_CGLOC") {
|
} else if (holding_string == "AC_CGLOC") {
|
||||||
aircraftfile >> Xcg >> Ycg >> Zcg;
|
aircraftfile >> baseXcg >> baseYcg >> baseZcg;
|
||||||
cout << "Aircraft C.G.: " << Xcg << " " << Ycg << " " << Zcg << endl;
|
cout << "Aircraft Base C.G.: " << baseXcg << " " << baseYcg << " " << baseZcg << endl;
|
||||||
} else if (holding_string == "AC_EYEPTLOC") {
|
} else if (holding_string == "AC_EYEPTLOC") {
|
||||||
aircraftfile >> Xep >> Yep >> Zep;
|
aircraftfile >> Xep >> Yep >> Zep;
|
||||||
cout << "Pilot Eyepoint: " << Xep << " " << Yep << " " << Zep << endl;
|
cout << "Pilot Eyepoint: " << Xep << " " << Yep << " " << Zep << endl;
|
||||||
|
@ -319,6 +319,9 @@ bool FGAircraft::Run(void)
|
||||||
|
|
||||||
void FGAircraft::MassChange()
|
void FGAircraft::MassChange()
|
||||||
{
|
{
|
||||||
|
float Xt, Xw, Yt, Yw, Zt, Zw, Tw;
|
||||||
|
float IXXt, IYYt, IZZt, IXZt;
|
||||||
|
|
||||||
// UPDATE TANK CONTENTS
|
// UPDATE TANK CONTENTS
|
||||||
//
|
//
|
||||||
// For each engine, cycle through the tanks and draw an equal amount of
|
// For each engine, cycle through the tanks and draw an equal amount of
|
||||||
|
@ -372,6 +375,38 @@ void FGAircraft::MassChange()
|
||||||
Weight += Tank[t]->GetContents();
|
Weight += Tank[t]->GetContents();
|
||||||
|
|
||||||
Mass = Weight / GRAVITY;
|
Mass = Weight / GRAVITY;
|
||||||
|
|
||||||
|
// Calculate new CG here.
|
||||||
|
|
||||||
|
Xt = Yt = Zt = 0;
|
||||||
|
Xw = Yw = Zw = 0;
|
||||||
|
for (int t=0; t<numTanks; t++) {
|
||||||
|
Xt += Tank[t]->GetX()*Tank[t]->GetContents();
|
||||||
|
Yt += Tank[t]->GetY()*Tank[t]->GetContents();
|
||||||
|
Zt += Tank[t]->GetZ()*Tank[t]->GetContents();
|
||||||
|
|
||||||
|
Tw += Tank[t]->GetContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
Xcg = (Xt + EmptyWeight*baseXcg) / (Tw + EmptyWeight);
|
||||||
|
Ycg = (Yt + EmptyWeight*baseYcg) / (Tw + EmptyWeight);
|
||||||
|
Zcg = (Zt + EmptyWeight*baseZcg) / (Tw + EmptyWeight);
|
||||||
|
|
||||||
|
// Calculate new moments of inertia here
|
||||||
|
|
||||||
|
IXXt = IYYt = IZZt = IXZt = 0.0;
|
||||||
|
for (int t=0; t<numTanks; t++) {
|
||||||
|
IXXt += ((Tank[t]->GetX()-Xcg)/12.0)*((Tank[t]->GetX() - Xcg)/12.0)*Tank[t]->GetContents()/GRAVITY;
|
||||||
|
IYYt += ((Tank[t]->GetY()-Ycg)/12.0)*((Tank[t]->GetY() - Ycg)/12.0)*Tank[t]->GetContents()/GRAVITY;
|
||||||
|
IZZt += ((Tank[t]->GetZ()-Zcg)/12.0)*((Tank[t]->GetZ() - Zcg)/12.0)*Tank[t]->GetContents()/GRAVITY;
|
||||||
|
IXZt += ((Tank[t]->GetX()-Xcg)/12.0)*((Tank[t]->GetZ() - Zcg)/12.0)*Tank[t]->GetContents()/GRAVITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ixx = baseIxx + IXXt;
|
||||||
|
Iyy = baseIyy + IYYt;
|
||||||
|
Izz = baseIzz + IZZt;
|
||||||
|
Ixz = baseIxz + IXZt;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,9 @@ private:
|
||||||
float Moments[3];
|
float Moments[3];
|
||||||
float Forces[3];
|
float Forces[3];
|
||||||
string AircraftName;
|
string AircraftName;
|
||||||
float Ixx, Iyy, Izz, Ixz, EmptyMass, Mass;
|
float baseIxx, baseIyy, baseIzz, baseIxz, EmptyMass, Mass;
|
||||||
|
float Ixx, Iyy, Izz, Ixz;
|
||||||
|
float baseXcg, baseYcg, baseZcg;
|
||||||
float Xcg, Ycg, Zcg;
|
float Xcg, Ycg, Zcg;
|
||||||
float Xep, Yep, Zep;
|
float Xep, Yep, Zep;
|
||||||
float rho, qbar, Vt;
|
float rho, qbar, Vt;
|
||||||
|
|
|
@ -95,6 +95,12 @@ void FGOutput::DelimitedOutput(void)
|
||||||
cout << "Udot,";
|
cout << "Udot,";
|
||||||
cout << "Vdot,";
|
cout << "Vdot,";
|
||||||
cout << "Wdot,";
|
cout << "Wdot,";
|
||||||
|
cout << "P,";
|
||||||
|
cout << "Q,";
|
||||||
|
cout << "R,";
|
||||||
|
cout << "PDot,";
|
||||||
|
cout << "QDot,";
|
||||||
|
cout << "RDot,";
|
||||||
cout << "Fx,";
|
cout << "Fx,";
|
||||||
cout << "Fy,";
|
cout << "Fy,";
|
||||||
cout << "Fz,";
|
cout << "Fz,";
|
||||||
|
@ -114,7 +120,7 @@ void FGOutput::DelimitedOutput(void)
|
||||||
cout << Rotation->Getphi() << ",";
|
cout << Rotation->Getphi() << ",";
|
||||||
cout << Rotation->Gettht() << ",";
|
cout << Rotation->Gettht() << ",";
|
||||||
cout << Rotation->Getpsi() << ",";
|
cout << Rotation->Getpsi() << ",";
|
||||||
cout << Atmosphere->Getrho() << ",";
|
cout << Atmosphere->GetDensity() << ",";
|
||||||
cout << State->GetVt() << ",";
|
cout << State->GetVt() << ",";
|
||||||
cout << Translation->GetU() << ",";
|
cout << Translation->GetU() << ",";
|
||||||
cout << Translation->GetV() << ",";
|
cout << Translation->GetV() << ",";
|
||||||
|
@ -125,6 +131,12 @@ void FGOutput::DelimitedOutput(void)
|
||||||
cout << Translation->GetUdot() << ",";
|
cout << Translation->GetUdot() << ",";
|
||||||
cout << Translation->GetVdot() << ",";
|
cout << Translation->GetVdot() << ",";
|
||||||
cout << Translation->GetWdot() << ",";
|
cout << Translation->GetWdot() << ",";
|
||||||
|
cout << Rotation->GetP() << ",";
|
||||||
|
cout << Rotation->GetQ() << ",";
|
||||||
|
cout << Rotation->GetR() << ",";
|
||||||
|
cout << Rotation->GetPdot() << ",";
|
||||||
|
cout << Rotation->GetQdot() << ",";
|
||||||
|
cout << Rotation->GetRdot() << ",";
|
||||||
cout << Aircraft->GetFx() << ",";
|
cout << Aircraft->GetFx() << ",";
|
||||||
cout << Aircraft->GetFy() << ",";
|
cout << Aircraft->GetFy() << ",";
|
||||||
cout << Aircraft->GetFz() << ",";
|
cout << Aircraft->GetFz() << ",";
|
||||||
|
@ -160,6 +172,12 @@ void FGOutput::DelimitedOutput(string fname)
|
||||||
datafile << "Udot,";
|
datafile << "Udot,";
|
||||||
datafile << "Vdot,";
|
datafile << "Vdot,";
|
||||||
datafile << "Wdot,";
|
datafile << "Wdot,";
|
||||||
|
datafile << "P,";
|
||||||
|
datafile << "Q,";
|
||||||
|
datafile << "R,";
|
||||||
|
datafile << "PDot,";
|
||||||
|
datafile << "QDot,";
|
||||||
|
datafile << "RDot,";
|
||||||
datafile << "Fx,";
|
datafile << "Fx,";
|
||||||
datafile << "Fy,";
|
datafile << "Fy,";
|
||||||
datafile << "Fz,";
|
datafile << "Fz,";
|
||||||
|
@ -179,7 +197,7 @@ void FGOutput::DelimitedOutput(string fname)
|
||||||
datafile << Rotation->Getphi() << ",";
|
datafile << Rotation->Getphi() << ",";
|
||||||
datafile << Rotation->Gettht() << ",";
|
datafile << Rotation->Gettht() << ",";
|
||||||
datafile << Rotation->Getpsi() << ",";
|
datafile << Rotation->Getpsi() << ",";
|
||||||
datafile << Atmosphere->Getrho() << ",";
|
datafile << Atmosphere->GetDensity() << ",";
|
||||||
datafile << State->GetVt() << ",";
|
datafile << State->GetVt() << ",";
|
||||||
datafile << Translation->GetU() << ",";
|
datafile << Translation->GetU() << ",";
|
||||||
datafile << Translation->GetV() << ",";
|
datafile << Translation->GetV() << ",";
|
||||||
|
@ -190,6 +208,12 @@ void FGOutput::DelimitedOutput(string fname)
|
||||||
datafile << Translation->GetUdot() << ",";
|
datafile << Translation->GetUdot() << ",";
|
||||||
datafile << Translation->GetVdot() << ",";
|
datafile << Translation->GetVdot() << ",";
|
||||||
datafile << Translation->GetWdot() << ",";
|
datafile << Translation->GetWdot() << ",";
|
||||||
|
datafile << Rotation->GetP() << ",";
|
||||||
|
datafile << Rotation->GetQ() << ",";
|
||||||
|
datafile << Rotation->GetR() << ",";
|
||||||
|
datafile << Rotation->GetPdot() << ",";
|
||||||
|
datafile << Rotation->GetQdot() << ",";
|
||||||
|
datafile << Rotation->GetRdot() << ",";
|
||||||
datafile << Aircraft->GetFx() << ",";
|
datafile << Aircraft->GetFx() << ",";
|
||||||
datafile << Aircraft->GetFy() << ",";
|
datafile << Aircraft->GetFy() << ",";
|
||||||
datafile << Aircraft->GetFz() << ",";
|
datafile << Aircraft->GetFz() << ",";
|
||||||
|
|
|
@ -78,6 +78,9 @@ public:
|
||||||
bool GetSelected(void) {return Selected;}
|
bool GetSelected(void) {return Selected;}
|
||||||
float GetPctFull(void) {return PctFull;}
|
float GetPctFull(void) {return PctFull;}
|
||||||
float GetContents(void) {return Contents;}
|
float GetContents(void) {return Contents;}
|
||||||
|
float inline GetX(void) {return X;}
|
||||||
|
float inline GetY(void) {return Y;}
|
||||||
|
float inline GetZ(void) {return Z;}
|
||||||
|
|
||||||
enum TankType {ttUNKNOWN, ttFUEL, ttOXIDIZER};
|
enum TankType {ttUNKNOWN, ttFUEL, ttOXIDIZER};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue