0

I'm trying to use FB_CTRL_LIN_INTERPOLATION, which exists in Controller Toolbox in TwinCAT3 as described in this link.

Unfortunately, the examples on the Infosys site are not practical; for example, there is no data type FLOAT on twincat3 at all; it can replace with REAL or LREAL in the next revision of the site!

By the way, here is my first attempt to implement the example.

The deceleration part is:

VAR
    linInt:FB_CTRL_LIN_INTERPOLATION;
    stParams       : ST_CTRL_LIN_INTERPOLATION_PARAMS;
    fIn           : LREAL;
    fManValue     : LREAL;
    bExtrapolate  : BOOL;
    eMode         : E_CTRL_MODE;
    
    fOut                        : LREAL;
    bInIsGreaterThanMaxElement  : BOOL;
    bInIsLessThanMinElement     : BOOL;
    eState                      : E_CTRL_STATE;
    eErrorId                    : E_CTRL_ERRORCODES;
    bError                      : BOOL;
    
    Data: ARRAY[1..6, 1..2] OF INT := [10, 15, 21, 22, 30, 40, 7, 10, 9, 2, 3, 6];
END_VAR

and the body part is :

stParams.pDataTable_ADR:=ADR(Data);
stParams.tCtrlCycleTime:=T#4S;
stParams.tTaskCycleTime:=T#2S;
stParams.nDataTable_SIZEOF:=SIZEOF(Data);
stParams.nDataTable_NumberOfRows:=6;


linInt(fIn:=fIn,
    fManValue:=fManValue,
    bExtrapolate:=bExtrapolate,
    eMode:=emode,
    fOut=>fOut,
    bInIsGreaterThanMaxElement=>bInIsGreaterThanMaxElement,
    bInIsGreaterThanMaxElement=>bInIsLessThanMinElement,
    eState=>eState,
    eErrorId=>eErrorId,
    bError=>bError,
    stParams:=stParams);

I do not have any idea what is the meaning of Size of the n x 2 array for the Description of nDataTable_SIZEOF so I used SIZEOF(Data) command to assign a value to it. exactly I now wonder what the 24 is!

enter image description here

as shown in the following figure, there is an error with the table description.

any help would be appreciated if someone clears it to me what is the meaning of stparams with detail here and how I can handle this example completely.

enter image description here

asys
  • 667
  • 5
  • 20

2 Answers2

1

Your data table needs to be "ARRAY[x..y, 1..2] OF FLOAT", not INT.

The FLOAT datatype is defined as an alias inside the library as a LREAL or REAL. See: InfoSys

Hopperpop
  • 31
  • 1
  • Finally, I fixed it with `LREAL,` but according to IEC61131-3, `FLOAT` in the system manager is equal to `REAL`; alternatively, the data type `DOUBLE` in the system manager is equivalent to `LREAL` data type in IEC61131-3. For more information, see this [link](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_system/html/tcsysmgr_datatypecomparison.htm&id=) – asys Sep 18 '22 at 07:01
0

I have no experience with TwinCAT, however implementing a linear interpolator shouldn't be too difficult.

Here's an example Function Block.

Assuming you have a data array, you can interpolate using the following formulae:

// find the interval of points x falls into. let `i` be the left point of that interval.
y := (x - data[i, 1]) / (data[i + 1, 1] - data[i, 1]) * (data[i + 1, 2] - data[i, 2]) + data[i, 2];
Guiorgy
  • 1,405
  • 9
  • 26