From 0786793f42f288d792c15e0206d3abb0db0df67c Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 30 May 2000 16:48:52 +0000 Subject: [PATCH] 05/30/2000 updates from Jon Berdnt. Landing gear code now is beginning to work. --- src/FDM/JSBSim.cxx | 30 ++++++++++++++++++++---------- src/FDM/JSBSim/FGAircraft.cpp | 1 + src/FDM/JSBSim/FGConfigFile.cpp | 4 +++- src/FDM/JSBSim/FGConfigFile.h | 2 ++ src/FDM/JSBSim/FGControls.cpp | 5 +++-- src/FDM/JSBSim/FGControls.h | 5 +++-- src/FDM/JSBSim/FGLGear.cpp | 29 +++++++++++++++-------------- src/FDM/JSBSim/FGPosition.h | 6 +++--- src/FDM/JSBSim/FGTranslation.cpp | 8 ++++---- src/FDM/JSBSim/FGTrimLong.cpp | 18 ++++-------------- 10 files changed, 58 insertions(+), 50 deletions(-) diff --git a/src/FDM/JSBSim.cxx b/src/FDM/JSBSim.cxx index 0714817c7..25a47a69d 100644 --- a/src/FDM/JSBSim.cxx +++ b/src/FDM/JSBSim.cxx @@ -62,7 +62,7 @@ int FGJSBsim::init( double dt ) { - + bool result; FG_LOG( FG_FLIGHT, FG_INFO, "Starting and initializing JSBsim" ); FG_LOG( FG_FLIGHT, FG_INFO, " created FDMExec" ); @@ -75,12 +75,17 @@ int FGJSBsim::init( double dt ) { FDMExec.GetState()->Setdt( dt ); - FDMExec.GetAircraft()->LoadAircraft( aircraft_path.str(), + result = FDMExec.GetAircraft()->LoadAircraft( aircraft_path.str(), engine_path.str(), current_options.get_aircraft() ); - FG_LOG( FG_FLIGHT, FG_INFO, " loaded aircraft" << - current_options.get_aircraft() ); + if (result) { + FG_LOG( FG_FLIGHT, FG_INFO, " loaded aircraft" << current_options.get_aircraft() ); + } else { + FG_LOG( FG_FLIGHT, FG_INFO, " aircraft" << current_options.get_aircraft() + << " does not exist"); + return 0; + } FDMExec.GetAtmosphere()->UseInternal(); @@ -109,10 +114,12 @@ int FGJSBsim::init( double dt ) { fgic->SetRollAngleRadIC(get_Phi()); fgic->SetPitchAngleRadIC(get_Theta()); fgic->SetHeadingRadIC(get_Psi()); - fgic->SetLatitudeRadIC(get_Latitude()); +// fgic->SetLatitudeRadIC(get_Latitude()); + fgic->SetLatitudeRadIC(get_Lat_geocentric()); fgic->SetLongitudeRadIC(get_Longitude()); - FDMExec.GetPosition()->SetRunwayRadius(scenery.cur_radius); + FDMExec.GetPosition()->SetRunwayRadius(scenery.cur_radius*METER_TO_FEET); + FDMExec.GetPosition()->SetSeaLevelRadius(get_Sea_level_radius()); FG_LOG( FG_FLIGHT, FG_INFO, " phi: " << get_Phi()); FG_LOG( FG_FLIGHT, FG_INFO, " theta: " << get_Theta() ); @@ -120,9 +127,9 @@ int FGJSBsim::init( double dt ) { FG_LOG( FG_FLIGHT, FG_INFO, " lat: " << get_Latitude() ); FG_LOG( FG_FLIGHT, FG_INFO, " lon: " << get_Longitude() ); FG_LOG( FG_FLIGHT, FG_INFO, " alt: " << get_Altitude() ); - + //must check > 0, != 0 will give bad result if --notrim set - if(current_options.get_trim_mode() == true) { + if(current_options.get_trim_mode() > 0) { FG_LOG( FG_FLIGHT, FG_INFO, " Starting trim..." ); FGTrimLong *fgtrim=new FGTrimLong(&FDMExec,fgic); fgtrim->DoTrim(); @@ -130,8 +137,10 @@ int FGJSBsim::init( double dt ) { fgtrim->TrimStats(); fgtrim->ReportState(); - controls.set_elevator_trim(FDMExec.GetFCS()->GetPitchTrimCmd()); + controls.set_elevator_trim(FDMExec.GetFCS()->GetDeCmd()); controls.set_throttle(FGControls::ALL_ENGINES,FDMExec.GetFCS()->GetThrottleCmd(0)/100); + //the trimming routine only knows how to get 1 value for throttle + delete fgtrim; FG_LOG( FG_FLIGHT, FG_INFO, " Trim complete." ); @@ -185,7 +194,8 @@ int FGJSBsim::update( int multiloop ) { // Inform JSBsim of the local terrain altitude; uncommented 5/3/00 // FDMExec.GetPosition()->SetRunwayElevation(get_Runway_altitude()); // seems to work - FDMExec.GetPosition()->SetRunwayRadius(scenery.cur_radius); + FDMExec.GetPosition()->SetRunwayRadius(scenery.cur_radius*METER_TO_FEET); + FDMExec.GetPosition()->SetSeaLevelRadius(get_Sea_level_radius()); FDMExec.GetAtmosphere()->SetExTemperature(get_Static_temperature()); FDMExec.GetAtmosphere()->SetExPressure(get_Static_pressure()); diff --git a/src/FDM/JSBSim/FGAircraft.cpp b/src/FDM/JSBSim/FGAircraft.cpp index cb8855631..316356337 100644 --- a/src/FDM/JSBSim/FGAircraft.cpp +++ b/src/FDM/JSBSim/FGAircraft.cpp @@ -176,6 +176,7 @@ bool FGAircraft::LoadAircraft(string aircraft_path, string engine_path, string f aircraftCfgFileName = AircraftPath + "/" + fname + "/" + fname + ".cfg"; FGConfigFile AC_cfg(aircraftCfgFileName); + if (!AC_cfg.IsOpen()) return false; ReadPrologue(&AC_cfg); diff --git a/src/FDM/JSBSim/FGConfigFile.cpp b/src/FDM/JSBSim/FGConfigFile.cpp index 8016df771..ae020ec21 100644 --- a/src/FDM/JSBSim/FGConfigFile.cpp +++ b/src/FDM/JSBSim/FGConfigFile.cpp @@ -30,7 +30,9 @@ FGConfigFile::FGConfigFile(string cfgFileName) cfgfile.open(cfgFileName.c_str()); CommentsOn = false; CurrentIndex = 0; - GetNextConfigLine(); + Opened = true; + if (cfgfile.is_open()) GetNextConfigLine(); + else Opened = false; } diff --git a/src/FDM/JSBSim/FGConfigFile.h b/src/FDM/JSBSim/FGConfigFile.h index a5c065d03..e5d1ab32f 100644 --- a/src/FDM/JSBSim/FGConfigFile.h +++ b/src/FDM/JSBSim/FGConfigFile.h @@ -75,6 +75,7 @@ public: string GetValue(string); string GetValue(void); bool IsCommentLine(void); + bool IsOpen(void) {return Opened;} FGConfigFile& operator>>(double&); FGConfigFile& operator>>(float&); FGConfigFile& operator>>(int&); @@ -87,6 +88,7 @@ private: ifstream cfgfile; string CurrentLine; bool CommentsOn; + bool Opened; unsigned int CurrentIndex; }; diff --git a/src/FDM/JSBSim/FGControls.cpp b/src/FDM/JSBSim/FGControls.cpp index 4ce14792e..277db5c52 100644 --- a/src/FDM/JSBSim/FGControls.cpp +++ b/src/FDM/JSBSim/FGControls.cpp @@ -51,8 +51,9 @@ FGControls::~FGControls() { // $Log$ -// Revision 1.11 2000/05/27 03:48:15 curt -// 5/26/2000 updated from Jon and Tony. +// Revision 1.12 2000/05/30 14:48:53 curt +// 05/30/2000 updates from Jon Berdnt. Landing gear code now is beginning to +// work. // // Revision 1.3 2000/04/26 10:55:57 jsb // Made changes as required by Curt to install JSBSim into FGFS diff --git a/src/FDM/JSBSim/FGControls.h b/src/FDM/JSBSim/FGControls.h index 3b16b8cf5..a85c4ccb7 100644 --- a/src/FDM/JSBSim/FGControls.h +++ b/src/FDM/JSBSim/FGControls.h @@ -175,8 +175,9 @@ extern FGControls controls; // $Log$ -// Revision 1.10 2000/05/27 03:48:15 curt -// 5/26/2000 updated from Jon and Tony. +// Revision 1.11 2000/05/30 14:48:53 curt +// 05/30/2000 updates from Jon Berdnt. Landing gear code now is beginning to +// work. // // Revision 1.5 2000/05/12 22:45:35 jsb // Removed extraneous namespace identifiers and header files diff --git a/src/FDM/JSBSim/FGLGear.cpp b/src/FDM/JSBSim/FGLGear.cpp index 865fbe6bf..ca7235ca7 100644 --- a/src/FDM/JSBSim/FGLGear.cpp +++ b/src/FDM/JSBSim/FGLGear.cpp @@ -55,7 +55,7 @@ FGLGear::FGLGear(FGConfigFile* AC_cfg, FGFDMExec* fdmex) : vXYZ(3), Aircraft = Exec->GetAircraft(); Position = Exec->GetPosition(); Rotation = Exec->GetRotation(); - + WOW = false; } @@ -72,14 +72,13 @@ FGColumnVector FGLGear::Force(void) { static FGColumnVector vForce(3); static FGColumnVector vLocalForce(3); - static FGColumnVector vLocalGear(3); - static FGColumnVector vWhlBodyVec(3); - static FGColumnVector vWhlVelVec(3); + static FGColumnVector vLocalGear(3); // Vector: CG to this wheel (Local) + static FGColumnVector vWhlBodyVec(3); // Vector: CG to this wheel (Body) + static FGColumnVector vWhlVelVec(3); // Velocity of this wheel (Local) - vWhlBodyVec = vXYZ - Aircraft->GetXYZcg(); + vWhlBodyVec = (vXYZ - Aircraft->GetXYZcg()) / 12.0; vWhlBodyVec(eX) = -vWhlBodyVec(eX); vWhlBodyVec(eZ) = -vWhlBodyVec(eZ); - vWhlBodyVec = vWhlBodyVec/12.0; vLocalGear = State->GetTb2l() * vWhlBodyVec; @@ -89,17 +88,19 @@ FGColumnVector FGLGear::Force(void) WOW = true; - vWhlVelVec = State->GetTb2l() * (Rotation->GetPQR() * vWhlBodyVec); - compressSpeed = vWhlVelVec(eZ) + Position->GetVd(); + vWhlVelVec = State->GetTb2l() * (Rotation->GetPQR() * vWhlBodyVec); + vWhlVelVec += Position->GetVel(); + compressSpeed = vWhlVelVec(eZ); - vLocalForce(eZ) = min(-compressLength * kSpring - compressSpeed * bDamp, (float)0.0); + vWhlVelVec = -1.0 * vWhlVelVec.Normalize(); + vWhlVelVec(eZ) = 0.00; - vForce = State->GetTl2b() * vLocalForce ; + vLocalForce(eZ) = min(-compressLength * kSpring - compressSpeed * bDamp, (float)0.0); + vLocalForce(eX) = fabs(vLocalForce(eZ) * statFCoeff) * vWhlVelVec(eX); + vLocalForce(eY) = fabs(vLocalForce(eZ) * statFCoeff) * vWhlVelVec(eY); - // currently only aircraft body axis Z-force modeled - vMoment(eX) = vForce(eZ) * vWhlBodyVec(eY); - vMoment(eY) = -vForce(eZ) * vWhlBodyVec(eX); - vMoment(eZ) = 0.0; + vForce = State->GetTl2b() * vLocalForce ; + vMoment = vWhlBodyVec * vForce; } else { diff --git a/src/FDM/JSBSim/FGPosition.h b/src/FDM/JSBSim/FGPosition.h index a03d859ec..97c4a7d66 100644 --- a/src/FDM/JSBSim/FGPosition.h +++ b/src/FDM/JSBSim/FGPosition.h @@ -74,9 +74,9 @@ public: inline FGColumnVector GetVel(void) { return vVel; } inline FGColumnVector GetUVW(void) { return vUVW; } - inline double GetVn(void) { return vVel(1); } - inline double GetVe(void) { return vVel(2); } - inline double GetVd(void) { return vVel(3); } + inline double GetVn(void) { return vVel(eX); } + inline double GetVe(void) { return vVel(eY); } + inline double GetVd(void) { return vVel(eZ); } inline double Geth(void) { return h; } inline double Gethdot(void) { return RadiusDot; } inline double GetLatitude(void) { return Latitude; } diff --git a/src/FDM/JSBSim/FGTranslation.cpp b/src/FDM/JSBSim/FGTranslation.cpp index b7e9e90b8..82eff48ed 100644 --- a/src/FDM/JSBSim/FGTranslation.cpp +++ b/src/FDM/JSBSim/FGTranslation.cpp @@ -115,18 +115,18 @@ bool FGTranslation::Run(void) { mVel(3,3) = 0.0; vUVWdot = mVel*vPQR + vForces/Mass; - - vNcg = vUVWdot * INVGRAVITY; + + vNcg=vUVWdot*INVGRAVITY; vUVW += 0.5*dt*rate*(vlastUVWdot + vUVWdot) + vWindUVW; - + Vt = vUVW.Magnitude(); if (vUVW(eW) != 0.0) alpha = vUVW(eU)*vUVW(eU) > 0.0 ? atan2(vUVW(eW), vUVW(eU)) : 0.0; if (vUVW(eV) != 0.0) beta = vUVW(eU)*vUVW(eU)+vUVW(eW)*vUVW(eW) > 0.0 ? atan2(vUVW(eV), - (fabs(vUVW(eU))/vUVW(eU))*sqrt(vUVW(eU)*vUVW(eU) + vUVW(eW)*vUVW(eW))) : 0.0; + sqrt(vUVW(eU)*vUVW(eU) + vUVW(eW)*vUVW(eW))) : 0.0; qbar = 0.5*rho*Vt*Vt; diff --git a/src/FDM/JSBSim/FGTrimLong.cpp b/src/FDM/JSBSim/FGTrimLong.cpp index 846a264d3..91f0a29f1 100644 --- a/src/FDM/JSBSim/FGTrimLong.cpp +++ b/src/FDM/JSBSim/FGTrimLong.cpp @@ -334,9 +334,9 @@ float FGTrimLong::qdot_func(float x) { /******************************************************************************/ bool FGTrimLong::DoTrim(void) { - int k=0,j=0,sum=0,trim_failed=0,jmax=Naxis; + int k=0; int its; - float step,temp,min,max; + if(fgic->GetVtrueKtsIC() < 1) { cout << "Trim failed, on-ground trimming not yet implemented." << endl; @@ -345,7 +345,6 @@ bool FGTrimLong::DoTrim(void) { return false; } - trimfp fp; fgic -> SetAlphaDegIC((alphaMin+alphaMax)/2); fdmex -> GetFCS() -> SetDeCmd(0); @@ -402,10 +401,7 @@ bool FGTrimLong::DoTrim(void) { total_its=k; k=Ncycles; //force the trim to fail } - - - - } + } if( udot > Tolerance ) { if(checkLimits(udotf,dth,0,1) == false) { cout << " Sorry, udot doesn't appear to be trimmable" << endl; @@ -414,10 +410,7 @@ bool FGTrimLong::DoTrim(void) { total_its=k; k=Ncycles; //force the trim to fail } - - - - } + } if(qdot > A_Tolerance) { if(checkLimits(qdotf,fdmex->GetFCS()->GetPitchTrimCmd(),-1,1) == false) { @@ -425,9 +418,6 @@ bool FGTrimLong::DoTrim(void) { total_its=k; k=Ncycles; //force the trim to fail } - - - } } k++;