From: Bertrand <bco...@us...> - 2016-07-03 17:20:58
|
Update of /cvsroot/jsbsim/JSBSim/src/initialization In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv9720/src/initialization Modified Files: FGInitialCondition.h FGInitialCondition.cpp Log Message: Fixed the altitude setter such that it does not modify the specified geodetic latitude. Index: FGInitialCondition.h =================================================================== RCS file: /cvsroot/jsbsim/JSBSim/src/initialization/FGInitialCondition.h,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -r1.45 -r1.46 *** FGInitialCondition.h 26 Jun 2016 20:33:04 -0000 1.45 --- FGInitialCondition.h 3 Jul 2016 17:20:55 -0000 1.46 *************** *** 72,76 **** typedef enum { setvt, setvc, setve, setmach, setuvw, setned, setvg } speedset; ! typedef enum { setasl, setagl} altitudeset; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --- 72,77 ---- typedef enum { setvt, setvc, setve, setmach, setuvw, setned, setvg } speedset; ! typedef enum { setasl, setagl } altitudeset; ! typedef enum { setgeoc, setgeod } latitudeset; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *************** *** 682,685 **** --- 683,687 ---- speedset lastSpeedSet; altitudeset lastAltitudeSet; + latitudeset lastLatitudeSet; unsigned int enginesRunning; int needTrim; *************** *** 701,704 **** --- 703,707 ---- void calcAeroAngles(const FGColumnVector3& _vt_BODY); void calcThetaBeta(double alfa, const FGColumnVector3& _vt_NED); + double ComputeGeodAltitude(double geodLatitude); bool LoadLatitude(Element* position_el); void Debug(int from); Index: FGInitialCondition.cpp =================================================================== RCS file: /cvsroot/jsbsim/JSBSim/src/initialization/FGInitialCondition.cpp,v retrieving revision 1.110 retrieving revision 1.111 diff -C2 -r1.110 -r1.111 *** FGInitialCondition.cpp 3 Jul 2016 14:27:48 -0000 1.110 --- FGInitialCondition.cpp 3 Jul 2016 17:20:55 -0000 1.111 *************** *** 105,108 **** --- 105,110 ---- position.SetLatitude(latRad0); position.SetAltitudeAGL(altAGLFt0); + lastLatitudeSet = setgeoc; + lastAltitudeSet = setagl; orientation = FGQuaternion(phi0, theta0, psi0); *************** *** 148,151 **** --- 150,154 ---- lastSpeedSet = setvt; lastAltitudeSet = setasl; + lastLatitudeSet = setgeoc; enginesRunning = 0; needTrim = 0; *************** *** 703,709 **** --- 706,718 ---- double PitotAngle = Aircraft->GetPitotAngle(); + double geodLatitude = position.GetGeodLatitudeRad(); altitudeASL=alt; position.SetAltitudeASL(alt); + if (lastLatitudeSet == setgeod) { + double h = ComputeGeodAltitude(geodLatitude); + position.SetPositionGeodetic(position.GetLongitude(), geodLatitude, h); + } + soundSpeed = Atmosphere->GetSoundSpeed(altitudeASL); rho = Atmosphere->GetDensity(altitudeASL); *************** *** 735,738 **** --- 744,749 ---- double altitude; + lastLatitudeSet = setgeoc; + switch(lastAltitudeSet) { case setagl: *************** *** 742,748 **** break; default: - altitude = position.GetAltitudeASL(); position.SetLatitude(lat); ! position.SetAltitudeASL(altitude); } } --- 753,758 ---- break; default: position.SetLatitude(lat); ! break; } } *************** *** 911,919 **** //****************************************************************************** ! // Load the latitude from the XML file. The computations below assume that the ! // terrain is a sphere and that the elevation is uniform all over the Earth. ! // Would that assumption fail, the computation below would need to be adapted ! // since the position radius would depend on the terrain elevation which depends ! // itself on the latitude. // // This is an acceptable trade off because this routine is only used by --- 921,930 ---- //****************************************************************************** ! // Given an altitude above the sea level (or a position radius which is the ! // same) and a geodetic latitude, compute the geodetic altitude. It is assumed ! // that the terrain is a sphere and that the elevation is uniform all over the ! // Earth. Would that assumption fail, the computation below would need to be ! // adapted since the position radius would depend on the terrain elevation which ! // depends itself on the latitude. // // This is an acceptable trade off because this routine is only used by *************** *** 921,924 **** --- 932,947 ---- // Earth is a sphere. + double FGInitialCondition::ComputeGeodAltitude(double geodLatitude) + { + double R = position.GetRadius(); + double slat = sin(geodLatitude); + double RN = a / sqrt(1.0 - e2*slat*slat); + double p1 = e2*RN*slat*slat; + double p2 = e2*e2*RN*RN*slat*slat-R*R; + return p1 + sqrt(p1*p1-p2) - RN; + } + + //****************************************************************************** + bool FGInitialCondition::LoadLatitude(Element* position_el) { *************** *** 946,959 **** if (lat_type == "geod" || lat_type == "geodetic") { ! double R = position.GetRadius(); ! double slat = sin(latitude); ! double RN = a / sqrt(1.0 - e2*slat*slat); ! double p1 = e2*RN*slat*slat; ! double p2 = e2*e2*RN*RN*slat*slat-R*R; ! double h = p1 + sqrt(p1*p1-p2) - RN; position.SetPositionGeodetic(position.GetLongitude(), latitude, h); } ! else position.SetLatitude(latitude); } --- 969,980 ---- if (lat_type == "geod" || lat_type == "geodetic") { ! double h = ComputeGeodAltitude(latitude); position.SetPositionGeodetic(position.GetLongitude(), latitude, h); + lastLatitudeSet = setgeod; } ! else { position.SetLatitude(latitude); + lastLatitudeSet = setgeoc; + } } |