Page 1 of 1

Edit Gain and Offset dynamically

Posted: Tue Mar 06, 2012 5:49 am
by ric
Hi everyone, is it possible to change dynamically gain and offset for a specific controller's tag?

Re: Edit Gain and Offset dynamically

Posted: Tue Mar 06, 2012 10:19 am
by Skylar
Hi Ric,

You could accomplish this with a global variable and a script. On the "Tags" screen, I would write a little script that scales a tag on "ValueChange" using a value that is stored in a variable, or another tag. Here is an example of what I'm talking about (I used tags for my variables):

Code: Select all

    public partial class Tags
    {
		
		void TagToScale_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
		{
			double input = Globals.Tags.TagToScale.Value;
			double gain = Globals.Tags.TagWithGain.Value;
			double offset = Globals.Tags.TagWithOffset.Value;
			
			double output = (input * gain) + offset;
			
			Globals.Tags.TagWithResult.Value = (int) output;
		}

    }

Re: Edit Gain and Offset dynamically

Posted: Fri Feb 14, 2014 12:21 am
by scott
Perhaps this might be of help.

It is a common problem with PLCs that don't support floats that we must scale our values up in order to gain resolution. When displayed on the HMI, however, we must scale it back again.

I have a tag defined as "SensorValue", and I want to change the gain on this at runtime. The number of decimal places I want I am storing in a second tag called "SensorResolution". The following code will update the gain on the SensorValue tag so that it has the number of decimal places as shown in SensorResolution.

Code: Select all

Globals.Tags.SensorValue.Gain = System.Math.Pow(10, -(double)Globals.Tags.SensorResolution.Value);
For a value of 0 in SensorResolution, the gain on SensorValue will be 1.
For a value of 1 in SensorResolution, the gain on SensorValue will be 0.1.
For a value of 2 in SensorResolution, the gain on SensorValue will be 0.01.

etc.

Don't forget to change the tag data type to float for the tag who's gain you are adjusting - the controller data type doesn't need to be changed.

Re: Edit Gain and Offset dynamically

Posted: Sat Sep 06, 2014 8:47 am
by jmkowol
Just saw this post and....wanted to say thanks.....I always was looking for the solution for the "scaling" problem.
J