beautypg.com

General purpose functions – MTS Series 793 User Manual

Page 378

background image

With this function, the preceding four-point running average can be written as:

real old[4];
shift(old, “My Signal”);

//just discard oldest value.

“My Average Signal” = avg (old, 4);

The shift function does not really have to move all the values. It is as efficient on large arrays as it is on small
ones.

The other useful function is size (array). It returns the allocated size of a real array (isize(array) works with
integer arrays). This is useful when writing loops, which is the next topic. Here is a more general implementation
of the running average expression:

real oldValues[50];

//keeps the last 50 values.

real currentSum;

//assume all values start out 0.

real discardedValue;

//temporary

discardedValue = shift(oldValues, “My Signal”);
current Sum = currentSum + “My Signal” – discardedValue;
“My Average Signal” = currentSum/size(oldValues);

Indexing outside the bounds of an array is an error. The signal will be set to invalid.

Note:

Using large arrays can significantly deplete the available heap memory in the controller. Even if the
calculation succeeds in allocating the memory it needs, this can cause other parts of the Controller to
subsequently run out of memory. Extreme care should be taken when allocating large arrays.

General Purpose Functions

mod(x,y)

Returns the floating point remainder of x/y.

If y is zero, a NaN is generated. If used as a signal, it is marked “Invalid”, which may cause an interlock if
used for compensation, feedback, command, or other critical use.

clip(x, clipMin, clipMax)

Clips the value by the specified minimum and maximum values.

iclip(x, iclipMin, iclipMax)

Works the same as clip, but uses integer arguments.

interlock(b)

Asserts the specified interlock on the station and writes a message to the station log which identifies the
calculation signal that caused the interlock.

programInterlock(b)

Works the same as interlock(b), but acts on the program interlock chain.

error(errorId)

Aborts the calculation, which invalidates the output signal of the calculation (which will also trip the interlock
if used as a critical system signal, such as a control feedback).

Once this command is performed:

378 MTS Series 793 Control Software

Calculated Signals