Author Topic: help  (Read 1627 times)

horus61

  • Newbie
  • *
  • Posts: 4
    • View Profile
help
« on: January 15, 2021, 05:28:54 AM »
Good morning. I need help. I would like to match the level of a dam to a volume fixed in a table. I state that I have a volume level table in csv format. I have micrologix 1400 and the level value corresponds to n7: 10. Thank you.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: help
« Reply #1 on: January 15, 2021, 06:05:25 AM »
Maybe PID where the level value would be Process Variable (PV), your highest fixed volume would be Set Point, Control Variable could be attached to N7:20.

If you manage to determine the range that Control Variable would go through, see below, then keep reading N7:20 and compare its value to your fixed values to determine when there is a match, you might need to do it in code and use Select Case in VB or Switch in C#, with cases corresponding to your fixed values from the csv.


Mapping one numeric range onto another:

If you have number x in the range [a,b] and you want to transform it to number y in the range [c,d], you need to do this:

y = (x − a) * ((d − c) / (b − a)) + c


It might also be as simple as just mapping N7:10 range to your fixed values range and only reading N7:10 and comparing it. For comparison of <= or >= you would probably have to use If statements instead of Select Case / Switch.

Not that I've tried any of these but if you find anything useful then go for it.
« Last Edit: January 15, 2021, 06:35:41 AM by Godra »

horus61

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: help
« Reply #2 on: January 15, 2021, 06:37:47 AM »
Thank you for your help. I am a novice and recently I have ventured into the development of small applications in advancedhmi. You could make an example of the code that you would implement in a calculated variable that is the Volume to be represented in a form together with the dam level. Thank you for your cooperation and I greet you cordially from Italy.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: help
« Reply #3 on: January 15, 2021, 07:36:55 AM »
Since you are a novice, you need to spend some time familiarizing yourself with Visual Studio and AdvancedHMI.

This forum probably has all the info you would need in order to learn (not to mention using Google for any additional information).
Maybe start with "Additional Components" category since you can see the code in all the controls posted there.

Since I don't have any understanding of your level of knowledge, my guess would be that even if I post some code then I would need to explain to you what it does.

If you don't understand how to map your ranges then take a look at this post that has several explanations:

   https://stackoverflow.com/questions/5731863/mapping-a-numeric-range-onto-another


horus61

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: help
« Reply #4 on: January 15, 2021, 01:51:31 PM »
Thank you for your helpful advice and wish you a good day.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: help
« Reply #5 on: January 16, 2021, 12:47:47 AM »
Just to try help you understand mapping one range to another, here is the gauge example which has the range of input values [0, 240] mapped to the arc which spans 270 degrees, which is the range [0, 270] (see the attached picture).

The java code that draws the needle in the correct place is like this:

Code: [Select]
        if (mGaugeCurrentValue > mGaugeMaxValue)
            canvas.rotate((270 / (mGaugeMaxValue - mGaugeMinValue)) * (Math.min(mGaugeMaxValue, mGaugeCurrentValue) - mGaugeMinValue) - 45);
        else
            canvas.rotate((270 / (mGaugeMaxValue - mGaugeMinValue)) * (Math.max(mGaugeMinValue, mGaugeCurrentValue) - mGaugeMinValue) - 45);

The code calculates the number of degrees that the needle needs to be rotated from its initial position.
Since the needle is initially drawn in the green rectangle then the calculation has to be offset for -45 to virtually bring it to zero position.
If somebody was to bother drawing the needle initially in the zero position then the offset would not be used.
Math.min and Math.max are making sure that needle doesn't go out of the arc.

From the attached picture, these would be the corresponding values:

mGaugeCurrentValue = 155
mGaugeMaxValue = 240
mGaugeMinValue = 0

In this particular example mGaugeMinValue = 0 but it could have any other value, like for example the range [-80, 80] would have mGaugeMinValue = -80.
« Last Edit: January 16, 2021, 12:59:53 AM by Godra »