FB_MllPrediction

FB_MllPrediction 1:

Syntax

Definition:

FUNCTION_BLOCK FB_MllPrediction
VAR_INPUT
    stPredictionParameter : ST_MllPredictionParameters;
    eTraceLevel           : TcEventSeverity;
END_VAR
VAR_OUTPUT
    bBusy                 : BOOL;
    bError                : BOOL;
    ipResultMessage       : I_TcMessage;
    hrErrorCode           : HRESULT;
END_VAR

FB_MllPrediction 2: Inputs

Name

Type

Description

stPredictionParameter

ST_MllPredictionParameters

General Prediction parameters

eTraceLevel

TcEventSeverity

Eventlogger trace level. Default = Critical. Must be set before Configure method is called

FB_MllPrediction 3: Outputs

Name

Type

Description

bBusy

BOOL

True if a asynchronous action is taking place

bError

BOOL

Indicates error in method

ipResultMessage

I_TcMessage

Contains the last invoked error

hrErrorCode

HRESULT

Unique error code

FB_MllPrediction 4: Methods

Name

Description

CheckPreferredIODataTypes

Checks if the supplied I/O data types are preferred by the currently loaded model.

CheckSupportedIODataTypes

Checks if the supplied I/O data types are supported by the currently loaded model.

Configure

Configures the FB with the given parameters. It returns true if the configuration or reconfiguration is done | Please call this method only from one task context at the time.

GetCustomAttribute_array

Retrieves a custom array attribute (int8/16/32/64 or fp32/64) from the machine learning model, which can be of any data type (requires casting after retrieval) and can be an array.

GetCustomAttribute_fp64

Retrieves a custom floating-point attribute (converted to 64-bit floating point) from the machine learning model.

GetCustomAttribute_int64

Retrieves a custom integer attribute (converted to 64-bit signed int) from the machine learning model.

GetCustomAttribute_str

Retrieves a custom string attribute from the machine learning model.

GetEngineIdFromRef

Retrieves the numeric engine id from its (optional) reference name.

GetInputDim

Retrieve the size of the input dimension from the currently loaded model.

GetMaxConcurrency

Retrieves the maximum number of threads that can concurrently use the loaded model via individual EngineIds.

GetModelName

Retrieves the name of the loaded model.

GetOutputDim

Retrieves the size of the output dimension from the currently loaded model.

Predict

Performs a prediction using the currently loaded model, expecting that the input data has been already written to the input buffer prior to call and output data will be retrieved from the output buffer after prediction.

PredictRef

Performs a prediction using the currently loaded model, expecting that the input data has been already written to the input buffer prior to call and output data will be retrieved from the output buffer after prediction.

Reset

Resets an error

SetActiveEngineOptions

Allows to set special engine options to the currently active engine.

General information

The FB_MllPrediction is a central Function Block for the usage of TC3 Machine Learning in the PLC. The Function Block offers a variety of Methods as described above. Basically, the FB_MllPrediction offers the functionality to load and to execute ML models. Hence, it is an interface to the TwinCAT 3 integrated inference engine (ML Runtime).

Error handling

Note that all methods of FB_MllPrediction return a BOOL which indicates if the execution on the method caused any error, e.g.

bFailed := fbprediction.GetInputDim(nInputDim);

The evaluation of the return value of the methods is equivalent to the evaluation of the Output bError of FB_MllPrediction.

Further, FB_MllPrediction references the TwinCAT 3 EventLogger and thus ensures that information (events) is provided via the standardized interface I_TcMessage. The trace level can be adjusted using TcEventSeverity.

Sample Code

Sample code for the usage of the Function Block is available here.

System Requirements