Menu

FGData Merge Request #252: Fix Equipment-Instrument Settings inconsistency toward Altimeter Indicator. (merged)

Merging...

Merged

Something went wrong. Please, merge manually

Checking if merge is possible...

Something went wrong. Please, merge manually

Jimis Hol wants to merge 1 commit from /u/jimishol/flightgear-fgdata/ to next, 2021-11-23

Altimeter Indicator seems to respect even rounding. Equipment-Instrument Settings do not. Thus, many times happens that altimeter indicator setting differs steadily by 0.01 from what Equipment-Instrument shows or what user sets if he uses only 2 digits. By this we create even rounding on both places so, both places shows the same value.
(Tested on release/2020.3.11 with Cessna 172P)

Commit Date  
[cdd022] (fix_instruments_inconsistency) by jimishol jimishol

Fix Equipment-Instrument Settings inconsistency toward Altimeter Indicator.

Altimeter Indicator seems to respect even rounding. So, if on settings
appear 29.9299 it shows 29.93. Equipment-Instrument Settings do not and
shows 29.92. If user sets 29.93 then settings keep the rest previous digits
and shows 29.9399. So, altimeter indicator shows 29.94 but instrument
settings keep the difference of 0.01 and shows 29.93.
Same phenomenon happens to hpa value too.

In code with '+0.05' we create even rounding and because the coversion
of one unit to the other many times leaves decimals of values to end
to series of 9, thus Instrument Settings keeps showing 29.929999 as 29.92,
we add artificial small value 0.00001 so as to make significant digits exact.

2021-11-03 15:17:47 Tree

Discussion

  • James Turner

    James Turner - 2021-11-04

    I'd prefer to fix this by adding some helpers the Nasal/math.nas to do rounding to an explicit precision.

    Eg Math.roundToDecimals(x, 2)

    This would keep the code in the dialog.xml cleaner, and also make the intent clearer as well.

     
  • Jimis Hol

    Jimis Hol - 2021-11-10

    I can not develop a helper. The merge request can be used till some helper is involved. But, I would like to add that i am not 100% pleased by this fix that just follows the existing code. I assume that inHg in setting needs a third decimal, that can be added before a possible merge. 0.01 inHg equals to 3 hPa, so, as it is now, it can happen user not to see any change in inHg by adding 1 Hpa. With the addition of a third decimal he will see that changing.
    If you agree with the above
    setprop("/instrumentation/altimeter/setting-inhg-formatted", int(getprop("/instrumentation/altimeter/setting-inhg")1000.0+0.5)/1000.0+0.00001)
    seems to do the job.
    Still, because of the incremental feature on editing the formatted value, not allowing to set to a specific value -only giving the impression it does, till one tries to increase his just inserted new value where it becomes obvious that the old value is increased-, the third digit creates his own ambiguities to players.

     

    Last edit: Jimis Hol 2021-11-11
  • James Turner

    James Turner - 2021-11-16

    I've done some research and made some core changes: we already have:

    math.round(a,b)

    Where b is a scaling term, eg 'math.round(1239, 10.0)' will round to the nearest multiple of 10.

    What I've done is extend math.floor() to support this optional second parameter, and add math.trunc() which also supports it.

    math.floor is a true floor: always returns the integer value smaller than the argument. math.trunc always truncates towards zero, even for negative numbers.

    I hope with these additions, the Nasal code can now become very simple and readable: no need to add +0.5 anywhere if we are lucky.

     
  • Jimis Hol

    Jimis Hol - 2021-11-16

    Considering https://wiki.flightgear.org/Nasal_library complete, i missed https://wiki.flightgear.org/Nasal_library/math A link from first to second in wiki might be useful to me.
    I cannot tell where could be needed the new floor and trunc math functions, but in our case math.round function can be used. I updated the request accordingly, but i preferred to add a third digit in inHg for the reasons i wrote above.
    Alter 0.001 to 0.01 if you do not like the 3nd digit.

     
  • James Turner

    James Turner - 2021-11-19

    Actually the +0.00001 is still not ideal, in this case I /think/ we could use sprintf() which returns a string and hence avoids any further representation-as-double issues.

    Eg this might look like:

    setprop("/instrumentation/altimeter/setting-hpa-formatted", sprintf("%4d", getprop("/instrumentation/altimeter/setting-hpa"));

     
  • Jimis Hol

    Jimis Hol - 2021-11-20

    I refreshed the commits.
    Actually what needed additional decimal was hPa because 0.01 inHg is about 1/3 fraction of 1Hpa. Eventually the same logic has the HI Offset where a user might see that he set for example 2 offset at his cockpit but be aware that he actually flights with 2.9 offset, when he reads the additional decimal in instruments popup window.

     
  • James Turner

    James Turner - 2021-11-23
    • Status: open --> merged
     

Log in to post a comment.