QuanityKind and Altitudes #457
-
I've just started really looking through the documentation on mp-units and really got my curiosity piqued when I read about quantity point kinds and altitudes, since tracking the datum of an altitude tends to be a challenge. The glide computer example illustrates this well--the datum is hard-coded assumed to be MSL, but not all altitudes are MSL. Is there a way to track and ideally automatically convert between different datums? Common datums in UAV autonomy (my use-case) are MSL (Mean Sea Level), HAE (Height above WGS84 Ellipsoid), HAL (height above launch), AGL (above ground level or height above terrain). Inadvertently mixing altitudes with different datums is a fruitful source of bugs. One challenge to converting between them is the offsets to convert between them are not fixed (can't be done at compile time) and in some cases it changes depending on your geographic location (Geoid undulation which is offset between HAE and MSL varies depending on your location.) I guess at a minimum it would be at least be nice to be able to have a compile time error if you mix altitudes with two different datums. Is that possible? I believe @chiphogg was looking at a more general case of this in tracking coordinate frames that say a vector is referenced to. I'm curious what the state of that is. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 18 replies
-
mp-units library is designed to have no overhead, and that is why it requires all the conversion information at compile time. Runtime conversions (i.e. for exchanging currencies) are not supported by it. But it is not impossible. You can define two unrelated families of types (i.e. for different origins) and provide custom conversion functions that would do the work at runtime.
Sure! This should be the default ;-) Please see slide 106 from my recent presentation on the V2 framework: https://github.com/train-it-eu/conf-slides/blob/master/2023.04%20-%20ACCU%202023/mp-units%20-%20Lessons%20learned%20and%20a%20new%20library%20design.pdf. I hope that it will answer your remaining questions. If not, I would be happy to answer them here 😃 |
Beta Was this translation helpful? Give feedback.
-
Well, the short answer is that the state of it is "not done and not currently in progress". 😅 However, I do have some pretty clear ideas on the subject. The first question is to do with how we handle conversions which might change at runtime. The usual conversions in a units library are immutable, and we get spoiled with these: we can assign a temperature in Fahrenheit to a variable in Celsius, say, and the compiler takes care of giving the correct result! Naturally, we might expect the same interfaces for runtime-adjustable conversions (say, dollars to euros). If we don't notice that this is an assumption, and question it, we end up with singletons and variable global state --- in short, madness. A better solution is to have transformation objects which are templated on two frames/units/whatever. This forces you to pass them around as variables, which keeps everything clear and local. If you have a (Not that I'm suggesting units libraries should include currency in their scope --- perish the thought!) So that's the strategy, IMO: make objects that know at compile time which frames they're dealing with, but use values known at run time to do the computation. (I wrote this before reading @mpusz's response above, but I see it's entirely consistent with this strategy. A templated type would be for generic conversions, whereas the |
Beta Was this translation helpful? Give feedback.
@jasonbeach, as I mentioned, the library framework can do only as much. The conversions have to be known at compile time. However, as I stated, you can easily add runtime conversion functions to your projects. For example you can do it this way: