CurveLinPLCopen motion icon

FunctionClosed A function calculates a result according to the current value of its inputs. A function has no internal data and is not linked to declared instances. block- Linear interpolation on a curve.

Inputs

X : REAL     X coordinate of the point to be interpolated.

XAxis : REAL[]     X coordinates of the known points of the X axis.

YVal : REAL[]     Y coordinate of the points defined on the X axis.

Outputs

Y : REAL      Interpolated Y value corresponding to the X input

OK : BOOL      TRUE if successful.

ERR : DINT      Error code if failed - 0 if OK.

Remarks

This function performs linear interpolation in between a list of points defined in the XAxis single dimension array. The output Y value is an interpolation of the Y values of the two rounding points defined in the X axis. Y values of defined points are passed in the YVal single dimension array.

Values in XAxis must be sorted from the smallest to the biggest. There must be at least two points defined in the X axis. YVal and XAxis input arrays must have the same dimension.

In case the X input is less than the smallest defined X point, the Y output takes the first value defined in YVal and an error is reported. In case the X input is greater than the biggest defined X point, the Y output takes the last value defined in YVal and an error is reported.

The ERR output gives the cause of the error if the function fails:

Error Code Meaning

0

OK

1

Invalid dimension of input arrays

2

Invalid points for the X axis

4

X is out of the defined X axis