-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Approximating mean sea level / geoid radius with WGS-84 spheroid/ellipsoid #184
Comments
After some further digging into the code, I realized that the spherical earth (or spherical mean sea level) assumption is quite deeply baked into the current implementation (e.g. with concepts such as a "geocentric terrain level radius" which is useful only under this assumption). I played around a bit to get a deeper understanding of what would have to be done to have both altitude and terrain level defined as a height above an ellipsoid instead of a radius of a sphere. I am currently stuck on getting the trim routine to work with my changes. |
Hi @simfinite
Contributions are welcome and if you want to address this topic then be prepared to fight a beast 😉 because there is interdependence between these computations and the rest of the code. But it can be a very interesting subject nonetheless. In the short term, the default version |
Modeling the Earth as a sphere is certainly something that should be kept in JSBSim (as least as an option) since most flight dynamics textbooks are either assuming that the Earth is flat (which we are not modeling) or that the Earth is a sphere because the maths are still manageable which is not the case if you assume that the Earth is an ellipsoid or even worse a general geoid. Having said that, nothing prevents us from adding an option where the Earth ground would be modeled as the WGS84 ellipsoid.
FlightGear is using a specially designed derived class of However even when JSBSim is used within FlightGear, the sea level altitude is computed with the mean sea level radius that you mentioned above. I am not aware of anyone complaining that the location is inconsistent with GPS coordinates however (but this does not mean that the current code is correct, just that nobody noticed it before you did). |
I dug into my personal archive and found much food for thoughts:
I told you this is a beast to fight but this does not mean we cannot bring it down 😃 |
Thank's for the feedback and digging up all these links. It's good to know that I seem to have hit a spot and not just failed to setup my simulation correctly. I agree it looks like a beast, but why not poke it a little bit to see what happens ;) Before getting any deeper into the code and details of the issue, I would like to provide a user-side perspective of what I personally would like to have in JSBSim. As mentioned above, I use JSBSim in combination with the ArduPlane autopilot for simulating fixed-wing drones in the context of research projects. Sometimes, I need to export and work with the simulated trajectories in other tools/environments which is when the coordinate reference systems, earth models and altitude references really matter. A simple example would be to export the trajectory to KML in order to visualize it in Google Earth. As explained above, if I would use current JSBSim's ECEF cartesian coordinates for this, the altitude would seemingly change with latitude due to the spherical earth in JSBSim and ellipsoidal earth in Google Earth. If I use lat/lon/alt coordinates from the spherical earth and project them on an ellipsoid it probably looks ok at first sight, but without figuring out the math of that projection and its implications, I don't really know what I'm doing anymore. Here are the types of earth models I would like JSBSim to support along with the corresponding use cases:
From my current understanding we should distinguish between the two problems:
I would like to focus on the 2nd problem. Do you agree that this has not been solved for FlightGear yet? My current understanding is that FlightGear provides ground level ASL/MSL to JSBSim, which then maps this ground level onto its spherical mean sea level. If this is true, then the distance travelled in flights along a north/south axis on the spherical JSBSim earth should be slightly greater than expected for an ellipsoidal earth. Also, as mentioned above, the ECEF coordinates along this trajectory are not useful when applied in the context of an ellipsoidal earth model. |
There is already a similar feature in JSBSim. At the moment, it can only be generated via a script but it can certainly be moved to the input/output features of JSBSim. jsbsim/src/input_output/FGScript.cpp Lines 482 to 517 in 511869e
I mentioned that off the top of my head but what I am sure of is that JSBSim does not depend by any means on FlightGear to perform its lat/lon/altitude computations. The FlightGear class
Well, somehow the FlightGear project has solved this problem and much beyond since it uses a complete and accurate model of the Earth geography based on "open source" cartography. However, even if JSBSim has tight links with FlightGear, it is an independent project meaning that we can have our own model of the Earth shape.
Honestly I do not know the details of the scenery implementation in FlightGear. What I know is that they use a completely separate project named TerraGear to produce and manage the data. I also know that TerraGear needs an insanely high amount of CPU/memory/disk space to run, up to the point that it has its own team devoted to the maintenance/development of the project. And since this is such a highly specialized and complex topic, I would certainly not want to duplicate their work.
Well, the distance traveled only depends on the trajectory of the aircraft and not on the Earth shape. Having said that, the GNC (Guidance, Navigation and Control) that is generally implemented in JSBSim is indeed assuming that the Earth is a sphere meaning that the navigation results in a trajectory that might be slightly wrong as you mentioned. However JSBSim is so versatile that some people might have developed their own GNC that would account for the WGS84 ellipsoid (the Space Shuttle model comes to my mind as I know that its authors have come a long way towards fidelity).
Indeed, the Space Shuttle model is the exception rather than the rule. Most users are using the standard features and I am convinced they would appreciate if JSBSim could save them the coding of the WGS84 computation in their model. |
Ok, thanks. I just wanted to make sure that I understand what has and what hasn't been solved in JSBSim and FlightGear.
Of course. But the trajectory of the aircraft is restricted to the atmosphere which again is bound to the surface (or actually the mean sea level) of the planet - spherical or ellipsoidal. You mention implementation of GNC functions that rely on the spherical earth assumption. That probably includes the Haversine distance formula in |
There is now only one place where the gravity parameters are defined and where all the related calculations take place. This ensures that all classes use the same value of g. This commit is related to the discussion from the issue #184.
@simfinite Sorry I lost track of this discussion but I have not forgotten that there is work to be done on this topic 😄
You are correct this is what I was thinking about.
Not off the top of my head but there must certainly exist some other examples. BTW the work on this topic is also related to issue #201 since the crash described there is related to how JSBSim interacts with |
See discussion in issue #184. The accuracy of some tests had to be slightly relaxed since calculations for the WGS84 ellipsoid are solved numerically: they are slightly less accurate than the closed form equations that were used for the perfect sphere.
Resuming my work on this topic: it seems that we made a bad design decision years ago when making the distinction between geodetic and geocentric coordinates. Indeed there are 2 scenarios:
In both cases the distinction is useless: a better decision would have been to use geodetic coordinates only and drop geocentric. Now we have to manage the situation where a user specifies a mix of geocentric latitude with geodetic altitude. The maths behind that scenario are not trivial and I am struggling to see the point of spending time implementing that (except for backward compatibility ?). |
Refreshing my knowledge on the difference between geodetic altitude and geocentric altitude, from - https://en.wikipedia.org/wiki/Geodetic_datum
So something like this? GD-Alt (geodetic altitude) and GC-Alt (geocentric altitude) are my annotations. |
Some further thoughts: according to the definition of the geocentric altitude and knowing that it's only used for orbital mechanics, geocentric altitude only makes sense for a measurement above the sea level, doesn't it ? On the figure below, I added a green mountain so that it clearly illustrates that AGL might vary greatly depending on the definition that is picked for the geocentric AGL (pink dots below). In addition, I guess AGL is only meaningful for aircraft and irrelevant for orbital mechanics ? So if I am correct, geocentric coordinates are measured above the sea level only, while geodetic coordinates can be measured either above ground level or above sea level. |
Just noticed that the latitude values shown in the Wikipedia diagram that I annotated are swapped around. Alpha which is geodetic latitude should be 60 degrees and beta - geocentric latitude should be 66 degrees. After sketching the annotations I wondered whether we should support (other than for backwards compatibility) the mixing of (lon, lat) coordinates in one datum with an (altitude) in a different datum as you mentioned in one of your examples. In other words if we do support both geodetic and geocentric then maybe require that the altitude component needs to be in the same datum? In terms of your question regarding geocentric AGL (pink dots) I would imagine the pink dot closer to the vehicle, i.e. on the P-Vehicle dashed line represents the ground level in the geocentric datum. So the geocentric AGL would be the difference between the vehicle's geocentric altitude and the pink dot. The other pink dot, i.e. the one on the plumb bob line is a ground altitude in the local/vehicle NED datum. |
More compliance with the WGS84 standard. Geodetic altitude is incorrectly implemented however since as @seanmcleod mentioned in issue #184, it has a different definition than geodetic altitude when the Earth is modeled as an ellipsoid.
Hmm... The diagram from Wikipedia seems correct to me. The length CF1 being shorter than AF1, alpha is therefore higher than beta.
I tend to agree with you: mixing geocentric and geodetic coordinates should be rejected by JSBSim. Unfortunately we have accumulated some history where the 2 datums have been mixed: this is the case in the example scripts for instance. I have committed some code (16ac672) which allows to specify geocentric latitude with geodetic altitude.
Drat ! I was expecting an answer like "Sure ! Who cares about geocentric AGL ?" 😄. And unfortunately you picked the dot that requires the more complex calculations but your choice makes sense.
Right, its definition is quite involved but its computation is simpler to implement than the other dot 😄 I am still challenging the relevance of the geocentric AGL however since this altitude is used by orbital mechanics and AFAIK satellites do not require to measure the AGL but rather the ASL. |
You're right, I wasn't think straight! 😉
I'm not saying we really have to care about or support the calculation of geocentric AGL, at this point I'm just mentioning what I think the definition of geocentric AGL is. Now a couple of questions regarding geocentric AGL. Is the aim, if we do decide it's useful, to be able to report geocentric AGL since we support geocentric coordinates in general? So if we support the reporting of geodetic AGL then we should also support the reporting of geocentric AGL? I haven't looked at the code in detail yet, but it looks like the AGL value for the aircraft is retrieved via the And the So assuming the following: If a JSBSim user wanted access to the geocentric AGL without a terrain model, i.e. assuming a spherical earth or ellipsoid, e.g. WGS84 then the ECEF XYZ coordinates would be used to project to a geocentric datum and return the geocentric altitude. If they wanted access to the geocentric AGL with a terrain model then their |
Glad to see this discussion is alive again. Unfortunately, I am currently not in the position time-wise to contribute much to the solution, but I do want to point out my opinion on GC-AGL vs. GD-AGL: I think the only time a GC-AGL would be useful in JSBSim (and not considering orbital mechanics), is when assuming a spherical earth. In that case, however, GC-AGL and GD-AGL are identical, right? Thus, the distinction is not required as GC-AGL can be considered a "special case GD-AGL" for a spherical earth. |
Definition: geocentric altitude is defined as the height above the ellipsoid surface along a line to the center of the ellipsoid (the radius).
These are good questions. I already mentioned that I don't think this quantity is relevant but you made a point about the potential inconsistency in JSBSim if we do not support geocentric AGL. I guess that we need a plausible use case to bring that discussion from theoretical highness down to the ground (pun intended 😉) and make a decision. The question is whether there exists a use case for which a missing geocentric AGL computation would make the user's life notably more complicated ? For example, the case of the geocentric ASL has been settled (as far as I am concerned) when you mentioned orbital mechanics. Indeed the only reference that makes sense for orbital vehicles is the center of the planet since the gravity originates from there.
Correct. Terrain is described in terms of geodetic coordinates: the terrain height is the geodetic height of the terrain with respect to the WGS84 ellipsoid measured at the geodetic latitude and longitude passed via the
If the terrain definition is missing then the geocentric AGL is trivially equal to the geocentric ASL since the terrain height is zero by default.
Correct. This definition corresponds to the pink dot along the plumb line in my figure above. Its computation is not very expensive because the coordinates of GC-P can be computed quite easily from the equation I derived above. An
The problem with the pink dot that intercepts the terrain along the geocentric radius (see the figure you posted above) is that it is not exactly above GC-P in the geodetic datum. Instead it is slightly offset. The only option (as far as I can see) would be an iterative process that would start from the "plumb line dot" and progress to the seeked intersection. Unfortunately there is no reason the terrain height varies monotonically between the "plumb line dot" and the seeked dot and I guess that will result in some very difficult convergence of the algorithm for a lot of pathological cases. |
Yes, glad to see it sparks interest even after more than one year idling.
No problem. We all have some real life constraints. You are welcome to bring your point of view to the discussion even if you don't have time to dedicate to coding.
My guts feelings are that your statement is correct. However we are still missing a strong argument to settle the case. Can someone need the geocentric AGL for their specific application ? |
More food for thoughts: JSBSim is currently using geocentric ASL to compute the atmospheric properties (pressure, temperature, density, humidity rate, etc.). But I think that it should theoretically use geodetic height instead of geocentric ASL because the "J2" gravity varies along the geodetic height. The difference between the 2 altitude definitions is negligible when flying close to the ground but can become measurable beyond stratosphere. Am I over-engineering the case ? |
FYI, I have asked the Outerra team if they have some usage of the geocentric height and it seems that they are not making any distinction between geodetic and geocentric coordinates. So as far as they are concerned the distinction between geocentric and WGS84 AGL is irrelevant. I will ask the same question on the FlightGear mailing list and see if we get a different feedback. |
In the process of updating WGS84 conformance, I have added (commit ecb7952) the ability to modify the planet characteristics with a new XML element <planet>
<semimajor_axis unit="M"> 6378137.0 </semimajor_axis>
<semiminor_axis unit="M"> 6356752.3142 </semiminor_axis>
<rotation_rate unit="RAD/SEC"> 7292115.8553E-11 </rotation_rate>
<GM unit="M3/SEC2"> 3986000.9E+8 </GM>
<J2> 0.00108263 </J2>
</planet> The idea is to allow JSBSim to simulate flight/orbit/descent on any planet such as the Moon, Mars, etc. This is an idea that has been considered for a long time by the developers as can be seen from the following comments in jsbsim/src/models/FGInertial.cpp Lines 67 to 77 in b6e65d4
and the existence of the files FGMars.h and FGMars.cpp to model the atmosphere of Mars almost from day one. |
I had been meaning to ask how a JSBSim user currently selects between a spherical earth model and the WGS84 ellipsoid model. Taking a look at the code in jsbsim/src/models/FGInertial.cpp Line 73 in ecb7952
Then if a planet XML element is specified with different values for the semi-major and semi-minor axes then the ground callback is updated to use these in jsbsim/src/models/FGInertial.cpp Line 106 in ecb7952
So if I'm following the code correctly and haven't missed some other piece it looks like the ground callback defaults to the WGS84 ellipsoid model and if a user wanted to use a spherical earth model they would need to provide a planet XML element with the semi-major and semi-minor axes set to the earth's radius? |
The short story: it was not possible so far.
Correct. Even after the commit ecb7952 has been pushed, the default remains the same: Earth is modeled as an oblate spheroid with dimensions from WGS84.
Yes.
Yes but there is more than the ground callback involved since jsbsim/src/models/FGPropagate.cpp Lines 122 to 123 in ecb7952
and FGInitialConditions also interrogates FGInertial to get the semi-major and semi-minor axes.jsbsim/src/initialization/FGInitialCondition.cpp Lines 126 to 129 in ecb7952
Previously, FGInertial::GetSemimajor() and FGInertial::GetSemiminor() were still reporting the same values whatever the ground callback was set to. So FGFDMExec::LoadPlanetConstants() has to be called after the planet characteristics have been modified:Lines 721 to 731 in ecb7952
|
More progress with the support of WGS84 in JSBSim: I have recently pushed 2 commits (94fef95 and 679bda6) to address a problem that has been reported a long time ago (SF bug #80 dating from March 17, 2010). At the moment, the code from these 2 commits is dead code and JSBSim still computes the local frame orientation as it always did. But before proceeding with some further changes, I would like some feedback from the community. The problemIn JSBSim, the local frame (also known as the NED frame a.k.a. North-East-Down frame - see the definition in the docs) is always oriented so that the down axis points towards the Earth center since the transformation matrix is computed with the geocentric latitude: jsbsim/src/math/FGLocation.cpp Lines 301 to 309 in 679bda6
jsbsim/src/math/FGLocation.cpp Lines 322 to 336 in 679bda6
Problem: when the WGS84 gravity is used (which is the default), the down axis as computed by the code above is not parallel to the gravity. This is because the WGS84 gravity does not point towards the Earth center. In Stevens & Lewis "Aircraft Control and Simulation - 3rd edition", it is specified that the NED frame transformation matrix should be computed with the geodetic latitude so that the down axis be parallel to the spheroid normal (p. 27 for the principles and p. 31 for the formula 1.6-22 of the transformation matrix). They also explain that the gravity computed with the J2 formula (and taking into account the centripetal acceleration) is parallel to the spheroid normal within a few micro-g's (p.33). This is confirmed by the 2 commits I pushed earlier this week: jsbsim/src/models/FGInertial.cpp Lines 141 to 167 in 679bda6
jsbsim/tests/unit_tests/FGInertialTest.h Lines 42 to 67 in 679bda6
So what's wrong will you ask me ? The code confirms the statements from Stevens & Lewis and the NED transformation matrices should use the geodetic latitude instead of the geocentric latitude. By the way, that is exactly what has been requested in the SourceForge bug report. Yes but noIf we just replace the geocentric latitude by the geodetic latitude in
For those 2 reasons, I would like to replace the computation of the NED transformation matrices made by What do you think ? Any comments or better ideas ? In other words, the question is should the NED frame be simply tangent to the spheroid ? Or should the definition of the down axis be such that the gravity vector coordinates are always |
So it seems that the proposed changes would lead to support for both topocentric and topodetic frames? That would be a good thing. Maybe tedious to code, but it would be good.
Jon
|
So in picture form from Stevens & Lewis, the difference between the normal to the spheroid versus the normal to the geoid?
Now Stevens & Lewis defines NED as:
In terms of the definitions for the NED frame in the JSBSim docs the following 3 statements are only all true for a spherical earth model with no geoid model right?
If we go with a NED frame simply tangent to the spheroid what code would be affected? If a user wanted to compare say some hand-calculated flat-earth calculations (assuming for their hand calculations that they assume the 3 items listed above for the NED frame in the JSBSim documentation currently) then they could achieve that by setting up the following in JSBSim right?
|
I don't currently have a good idea of what JSBSim code currently makes use of the NED frame. Came across the following comment while starting to look. jsbsim/src/models/FGAccelerations.h Lines 78 to 83 in 2c44e8d
|
Yes, the question is indeed whether we use the local vertical (plumb-bob direction) or the spheroid normal.
Right. These 3 statements can only be simultaneously met for a spherical Earth. The problem with the WGS84 model is that we can meet only one and the question is which one ?
We would only need to modify the code below so that jsbsim/src/math/FGLocation.cpp Lines 322 to 336 in 679bda6
There a number of tests that fail when making that modification however and that needs further investigations.
If the user wants to runs simulations around a spherical Earth then yes, the set up would be the one you described above. Alternatively the user could set However, flat-Earth cannot be modeled stricto sensu by JSBSim. |
There are two main usages:
Yes I wrote this comment some time ago because the computation of accelerations and propagation had accumulated a number of frame transformations over the years which affected the precision of the calculations. I have submitted a number of patches at the time to reduce the frame transformations to the bare minimum and improve precision. |
The idea is rather to drop topocentric NED frames and have topodetic NED frames instead. In the event, one would want to use pure topocentric frames, the best option would be to specify a spherical planet with the new |
So we should expect to see differences in the pitch angle on that order between a NED frame which has it's down component normal to the spheroid versus one that is normal to the geoid then?
Yep. So French, English and Latin at a minimum I see 😉 I had to take Latin as a 3rd language for the 1st two years of high-school. |
Yes, right. Following this discussion, the more I think about it, the more I am convinced that I am over-engineering the problem. I guess we will stick with Stevens & Lewis definition of the NED frame (i.e. tangent to the spheroid) and users that mix standard gravity with an oblate planet will have to live with a gravity vector that has a weird direction with respect to the NED frame. Unless someone has an objection ?
Well, that's one of the few Latin expressions I know and since I could not figure out the equivalent English expression I went for that one 😄 Latin expressions are sometimes used in French such as alter ego, I guess it is because the language originates itself from Latin. |
Guess we could print a warning if the planet isn't spherical and the user selects standard gravity? In terms of weird direction in this case are we talking about the difference being the deviation of the normal? |
I don't know. We already have an issue #140 opened about having too much warnings.
That's correct. 11.5 arc-min is not much so how low the deviation |
I wasn't thinking of having the warning printed based on a particular deviation value, rather a general warning that the user is using a non-standard setup in terms of standard gravity combined with a non-spherical planet. I was also thinking in terms of a warning message on startup. If you were to look at the deviation of the normal and only display a message based on some cut-off value then there may be no warning on startup but only later on as the aircraft flies north/south right? In terms of the too many warnings I guess we could look at having some warning levels that the user can suppress, or disable specific warnings? |
Well, what would be the criterion to decide if the planet is non-spherical ? As soon as the semi-major axis
Since we know that the maximum deviation occurs at a latitude of 45 degrees, this can be evaluated as soon as My personal preference would be the 2nd option. What do you think ?
Yes, I think we should migrate to FlightGear/SimGear's log system |
My thinking is not to try and determine a threshold related to accuracy and to warn the user then. Rather only to warn the user for some specific combinations that may indicate they've made a mistake in the combination they've chosen, i.e. Standard gravity and non-spherical planet (a != b) - thought they were using a spherical model and standard gravity. EGM96 J2 gravity and spherical planet (a == b) - thought they were using WGS84 spheroid model EGM96 J2 gravity. If they did mean to use the specific combination then some option to suppress the warning. In taking a look at some of the recent code for the jsbsim/src/models/FGInertial.cpp Line 58 in ecb7952
In other words should we display an error if a |
As per the discussion in issue #184, the down axis is now normal to the spheroid (it was pointing towards the planet center previously). Also fixes bug SF80.
@seanmcleod |
As per the discussion in issue #184 and suggestions from @seanmcleod.
Waypoints are used to compute distance and heading from one point to another. They were computed using Haversine formula which are only applicable to spherical planets. In the context of issue #184, the present commit converts waypoint computations to WGS84 thanks to Charles F. F. Karney's library GeographicLib which is licensed under the MIT/X11 license.
For the record, I just pushed the commit 70a327f which converts the waypoint calculations to WGS84.
Previously, these 2 methods were using the Haversine formulas which are only valid for a spherical planet. Unfortunately the computation of the geodesic distance and azimuth on an ellipsoid is quite complex so, rather than developing our own code from scratch, I have used Charles F. F. Karney's library GeographicLib. GeographicLib is licensed under the MIT/X11 license so I have included the source code from GeographicLib that is relevant to the computation of geodesic distances and headings. That way, JSBSim still has no external dependencies. The author of GeographicLib has conducted quite thorough investigations on the topic as can be seen from the very impressive bibliography that he has collected. He is also maintaining his library for several years now so I am quite confident that we can rely on his library and save ourselves the trouble of maintaining such a piece of complex and very specialized software. This also updates the In case some users have the GeographicLib library already installed on their computer, I plan to update our CMake build process to be able to link with an external GeographicLib library when there is one, otherwise our copy of the GeographicLib source code will be compiled. As far as I can tell this was the last bit of JSBSim that was not conformant with WGS84 so, unless someone objects, I plan to close this issue which is now more than 2 years old. |
Thanks a lot for working on this. I think the WGS84 support will really push JSBSim's applicability for real-world scenarios where aeronautical navigation is required. |
@simfinite You're welcome ! So I am closing this issue. Would any of you find an error, a bug or a feature that still needs to be converted to WGS84, please open a new issue. |
Hey all,
I am using JSBSim together with the ArduPlane framework to simulate fixed-wing drones. Looking at JSBSim CSV logs, I noticed that the ECEF position coordinates were way off from what I expected. The aircraft was initialized at ~9000m height above the WGS-84 ellipsoid (GPS altitude) when initialized with altitude AGL set to '0'.
Looking around the code, I found out that this is because the default mean sea level radius (in FGDefaultGroundCallback) is initialized to the major semi-axis (equatorial earth radius). This constant value is used as the default reference for altitude AGL and terrain elevation everywhere.. the earth's a sphere again.
Now, I realize that there may be other implementations of FGGroundCallback, possibly with complex geoid and terrain models. However, for my use-case, all I really want is to be able to place the aircraft on an airfield, take-off and produce some reasonable log files. The WGS-84 spheroid is a good reference for that, especially since GPS altitude values can be found everywhere.
Does anyone agree that the WGS-84 spheroid/ellipsoid would be a much better approximation of the geoid than a simple sphere? Any reasons against it? Anything I may have missed/misunderstood?
I would be happy to implement this, if we can agree that it would make sense and wouldn't break anything...
The text was updated successfully, but these errors were encountered: