SpinControl Rounding "Error"

Wiljan
2019-07-12
2019-07-26
  • Wiljan

    Wiljan - 2019-07-12

    Hi

    The user need to adjust a var Test (REAL)in 0.1 step in range 0..2 so I have added in a SpinControl in the visualization and I set that to a variable Test REAL, added in a interval of 0.1 and a limit of 0 and 2.

    Thant works somehow fine ....but you would expect it step like 0.0, 0.1, 0.2, 0.3 etc to 2.0 in both directions, but what happens are
    0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.700000048, 0.8000001, 0.9000001, 1.00000012 etc..
    and if you spin negative then the value are getting even more off some kind of rounding error

    So what does happens here it it a conversion to/from some other number base ?
    Sure I can start to change it to integer and the do some math forth and back divide etc but is that really intended?

    Any nice trick?

    Codesys V3.5 SP12 Patch 6pbF

     
  • josepmariarams

    josepmariarams - 2019-07-13

    Use s long integer instead.

    T:lint
    Timeon: lreal

    T:=t+10

    Timeon:=to_lreal(t)/10.0

    Sent from my Moto G (5S) Plus using Tapatalk

     
  • Wiljan

    Wiljan - 2019-07-13

    Yeah, so just tried with integer in the SpinControl and interval of 1 the calc a real

    Test3_Value:=(int_to_real (spin2_value)/10);
    

    and put it in a textbox instead of the build in textbox in the the SpinControl

    I does work but a bit odd in codesys ...
    I tried the the spincontrol in C# just for a test with a interval of 0.1 and there it works as expected

    Anyway I have another question:
    In Webvisualition I need a symbol as a "Tank" of liquid and to show the level of the liquid
    I do not see any "Tank" in the webvisui, are there a place to get more symbols than what's standard in codesys?

     
  • aliazzz

    aliazzz - 2019-07-13

    option 1
    Build the element yourself using the readily provided primitives (99.9 percent of the time this will suffice!)
    There is a readymade bargraph element, but you can design your own bargraph (tip: use a rectangle or so).
    When designing it yourself you will learn new cool stuff about the visualisation as a bonus.

    option 2
    Try google?

    option 3
    obtain the "visu-toolkit" which is a professional CODESYS add-on which you have to pay for.
    As far as I know it comes with a mandatory training at CODESYS or on site.
    For further details on it you should contact sales (or search this forum as there are some topics on it)

     
  • Wiljan

    Wiljan - 2019-07-14

    Aliazzz hat geschrieben:
    option 1
    Build the element yourself using the readily provided primitives (99.9 percent of the time this will suffice!)
    There is a readymade bargraph element, but you can design your own bargraph (tip: use a rectangle or so).
    When designing it yourself you will learn new cool stuff about the visualisation as a bonus.

    I'm already doing that, but was wondering if there were some free open add-on somewhere or a description how to build your own eg if they are save in a xml style or so.
    Since I work with Festo and they do have a HMI libray where you use studio designer where you have a lot of ready very nice symbols available, (whic for sure only work with Festo HMI scereens) and thereby are "Paid" it makes sense.

    It might be the same if you could add in a library with symbols for web visu on certain models of PLC

    Aliazzz hat geschrieben:
    option 2
    Try google?

    Yeah I know Google.... but I really did not find what I had in mind

    Aliazzz hat geschrieben:
    option 3
    obtain the "visu-toolkit" which is a professional CODESYS add-on which you have to pay for.
    As far as I know it comes with a mandatory training at CODESYS or on site.
    For further details on it you should contact sales (or search this forum as there are some topics on it)

    That might be a route, need to loo into symbols and pricing

    Thank You

     
  • ndzied1

    ndzied1 - 2019-07-26

    Wiljan hat geschrieben:
    Hi
    The user need to adjust a var Test (REAL)in 0.1 step in range 0..2 so I have added in a SpinControl in the visualization and I set that to a variable Test REAL, added in a interval of 0.1 and a limit of 0 and 2.
    Thant works somehow fine ....but you would expect it step like 0.0, 0.1, 0.2, 0.3 etc to 2.0 in both directions, but what happens are
    0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.700000048, 0.8000001, 0.9000001, 1.00000012 etc..
    and if you spin negative then the value are getting even more off some kind of rounding error
    So what does happens here it it a conversion to/from some other number base ?
    Sure I can start to change it to integer and the do some math forth and back divide etc but is that really intended?
    Any nice trick?
    Codesys V3.5 SP12 Patch 6pbF

    The reason this happens is because 0.1 cannot be exactly represented in a REAL which follows the IEEE-754 Floating point number convention.

    Your 0.1 value is actually 0.100000001490116119384765625 inside the computer. After adding a few time, those extra bits start to show up in your summed number.

    You can check out this site (and several others) to see how floats/REAL are stored in the computer.
    https://www.h-schmidt.net/FloatConverter/IEEE754.html m

     

Log in to post a comment.