From 226b8a897195ae2cf672e189a49a75f3374ea522 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 30 Dec 1999 18:01:59 +0000 Subject: [PATCH] Here is a wrap-up of the latest changes to JSBSim. It still is flaky, but much less so due to returning the aero reference point stuff to the config files. Don't know what happened there ... Additionally, I have added a new field to the config file: CFG_VERSION. A version number, currently 1.1, is assigned to the config file and a matching definition is found in FGDefs.h. The two need to match. Tony has also added code into FGAircraft.cpp to handle if aero reference point is not specified. --- src/FDM/JSBSim/FGAircraft.cpp | 59 +++++++++++++++++++------------- src/FDM/JSBSim/FGCoefficient.cpp | 11 ++++-- src/FDM/JSBSim/FGCoefficient.h | 4 +++ src/FDM/JSBSim/FGControls.cpp | 22 ++++++++---- src/FDM/JSBSim/FGFDMExec.cpp | 2 +- 5 files changed, 64 insertions(+), 34 deletions(-) diff --git a/src/FDM/JSBSim/FGAircraft.cpp b/src/FDM/JSBSim/FGAircraft.cpp index f49e9dd98..b45efcbbe 100644 --- a/src/FDM/JSBSim/FGAircraft.cpp +++ b/src/FDM/JSBSim/FGAircraft.cpp @@ -159,6 +159,7 @@ bool FGAircraft::LoadAircraft(string aircraft_path, string engine_path, string f streampos gpos; int axis; string axis_descript; + bool readAeroRp=false; axis = -1; aircraftDef = aircraft_path + "/" + fname + "/" + fname + ".cfg"; @@ -169,6 +170,8 @@ bool FGAircraft::LoadAircraft(string aircraft_path, string engine_path, string f numTanks = numEngines = 0; numSelectedOxiTanks = numSelectedFuelTanks = 0; + Xcg=Ycg=Zcg=0; //protection for no cg specified in file + while (!aircraftfile.fail()) { holding_string.erase(); aircraftfile >> holding_string; @@ -218,6 +221,7 @@ bool FGAircraft::LoadAircraft(string aircraft_path, string engine_path, string f cout << "Aircraft Empty Weight: " << EmptyWeight << endl; } else if (holding_string == "AC_AERORP") { aircraftfile >> Xrp >> Yrp >> Zrp; + readAeroRp=true; cout << "Aerodynamic Reference Point: " << Xrp << " " << Yrp << " " << Zrp << endl; } else if (holding_string == "AC_CGLOC") { aircraftfile >> baseXcg >> baseYcg >> baseZcg; @@ -310,8 +314,15 @@ bool FGAircraft::LoadAircraft(string aircraft_path, string engine_path, string f aircraftfile.getline(scratch, 127); } } - cout << "End of Configuration File Parsing." << endl; + + if(!readAeroRp) { + Xrp = Xcg; + Yrp = Ycg; + Zrp = Zcg; + cout << "Aerodynamic reference point not found, set to empty weight cg location" << endl; + } + cout << "End of Configuration File Parsing." << endl; return true; } @@ -431,32 +442,31 @@ void FGAircraft::MassChange() void FGAircraft::FMAero(void) { float F[3]; - float Fxaero,Fyaero,Fzaero; float dxcg,dycg,dzcg; + float ca, cb, sa, sb; int axis_ctr,ctr; F[0] = F[1] = F[2] = 0.0; - for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) - for (ctr=0; ctr < coeff_ctr[axis_ctr]; ctr++) + for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) { + for (ctr=0; ctr < coeff_ctr[axis_ctr]; ctr++) { F[axis_ctr] += Coeff[axis_ctr][ctr]->TotalValue(); + Coeff[axis_ctr][ctr]->DumpSD(); + } + } + + ca = cos(alpha); + sa = sin(alpha); + cb = cos(beta); + sb = sin(beta); - Fxaero = - F[DragCoeff]*cos(alpha)*cos(beta) - - F[SideCoeff]*cos(alpha)*sin(beta) - + F[LiftCoeff]*sin(alpha); - Fyaero = F[DragCoeff]*sin(beta) - + F[SideCoeff]*cos(beta); - Fzaero = - F[DragCoeff]*sin(alpha)*cos(beta) - - F[SideCoeff]*sin(alpha)*sin(beta) - - F[LiftCoeff]*cos(alpha); - - Forces[0] += - F[DragCoeff]*cos(alpha)*cos(beta) - - F[SideCoeff]*cos(alpha)*sin(beta) - + F[LiftCoeff]*sin(alpha); - Forces[1] += F[DragCoeff]*sin(beta) - + F[SideCoeff]*cos(beta); - Forces[2] += - F[DragCoeff]*sin(alpha)*cos(beta) - - F[SideCoeff]*sin(alpha)*sin(beta) - - F[LiftCoeff]*cos(alpha); + Forces[0] += - F[DragCoeff]*ca*cb + - F[SideCoeff]*ca*sb + + F[LiftCoeff]*sa; + Forces[1] += F[DragCoeff]*sb + + F[SideCoeff]*cb; + Forces[2] += - F[DragCoeff]*sa*cb + - F[SideCoeff]*sa*sb + - F[LiftCoeff]*ca; // 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 @@ -468,13 +478,14 @@ void FGAircraft::FMAero(void) dycg = (Yrp - Ycg)/12; dzcg = -(Zrp - Zcg)/12; - Moments[0] += Fzaero*dycg - Fyaero*dzcg; //rolling moment - Moments[1] += Fxaero*dzcg - Fzaero*dxcg; //pitching moment - Moments[2] += -Fxaero*dycg + Fyaero*dxcg; //yawing moment + Moments[0] += Forces[2]*dycg - Forces[1]*dzcg; //rolling moment + Moments[1] += Forces[0]*dzcg - Forces[2]*dxcg; //pitching moment + Moments[2] += -Forces[0]*dycg + Forces[1]*dxcg; //yawing moment for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) { for (ctr = 0; ctr < coeff_ctr[axis_ctr+3]; ctr++) { Moments[axis_ctr] += Coeff[axis_ctr+3][ctr]->TotalValue(); + Coeff[axis_ctr+3][ctr]->DumpSD(); } } } diff --git a/src/FDM/JSBSim/FGCoefficient.cpp b/src/FDM/JSBSim/FGCoefficient.cpp index 0e69bcb75..2ed2d69ef 100644 --- a/src/FDM/JSBSim/FGCoefficient.cpp +++ b/src/FDM/JSBSim/FGCoefficient.cpp @@ -352,7 +352,7 @@ float FGCoefficient::Value(float rVal, float cVal) col1temp = rFactor*(Table3D[r][c-1] - Table3D[r-1][c-1]) + Table3D[r-1][c-1]; col2temp = rFactor*(Table3D[r][c] - Table3D[r-1][c]) + Table3D[r-1][c]; - Value = col1temp + cFactor*(col2temp - col1temp); + SD = Value = col1temp + cFactor*(col2temp - col1temp); for (midx=0;midx