FB_CMA_WatchUpperThresholds

Configurable threshold value monitoring of multi-channel data

Similar to the function block FB_CMA_DiscreteClassification, this function block allocates the individual channels of a multi-channel signal to a number of configurable discrete categories, based on configurable threshold values. After the configuration the function block calculates a one-dimensional array with precisely two values for each input vector. The type of both elements is a signed 32-bit Integer number. The first value of the result identifies the number of highest determined category, the second value the channel number with the highest category. In both cases numbering starts with zero. If no input value of a channel matches the respective threshold value for the lowest category, the resulting value is -1. If an input value equals the threshold value of a category, it is counted under this category. If several channels are allocated the highest category, the channel number with the lower number is returned.

Configuration

The function block can be configured at runtime by specifying the threshold value for each channel and each threshold value category.

Memory properties

Depending on the function block configuration with bMemorize, the number of the highest threshold value category and the number of the triggering channel are saved until the method ResetData() is called, or the values are recalculated after each step.

NaN occurrence

If the input value is NaN, the result of the classification is -2. No NaN values are expected at the output.

Behavior when processing multi-channel input data

When processing several channels (nChannels > 1), there is a possibility of each channel having different return values. In this case, return values can be queried separately on the function block. If the results from one or more channels are impermissible, but not all channels, the value on the function block corresponds to eCM_InfRTime_AmbiguousChannelResults. If the results of all channels are impermissible, then the value on the function block corresponds to eCM_ErrRTime_ErrornousChannelResults.

A list of return values of all channels can be queried using the method GetChannelErrors().

When processing several subchannels (nSubChannels > 0), particular attention must be paid to the formatting of the input and output data. If the input data consist of a multi-channel result of an upstream function block, the value of nChannels must be adopted; further configuration takes place in this case via the parameter nSubChannels.

Sample: In the statistical consideration (e.g. by FB_CMA_Quantiles) of the frequency channels of a multi-channel spectrum (e.g. FB_CMA_MagnitudeSpectrum), the value of nChannels must be identical to the number of input signals; the number of subchannels nSubChannels corresponds to the length of the spectrum.

Inputs and outputs

The input and output buffers correspond to one of the following definitions (input / output shape). The variable parameters are part of the function block input stInitPars.

Versions

Input buffer (MultiArray input stream)
Element type, number of dimensions, dimension sizes

Output buffer (MultiArray output stream)
Element type, number of dimensions, dimension sizes

Standard version
(nSubChannels = 0)

LREAL, 1,
nChannels

DINT (32bit), 1,
2

Multi-channel version
(nSubChannels > 0)

LREAL, 2,
nChannels x nSubChannels

DINT (32bit), 2,
nChannels x 2

VAR_INPUT
    stInitPars      : ST_CM_WatchUpperThresholds_InitPars;  // init parameter
    nOwnID          : UDINT;                                // ID for this FB instance
    aDestIDs        : ARRAY[1..cCMA_MaxDest] OF UDINT;      // IDs of destinations for output
    nResultBuffers  : UDINT := 4;                           // number of MultiArrays which should be initialized for results (0 for no initialization)
    tTransferTimeout: LTIME := LTIME#500US;                 // timeout checking off during access to inter-task FIFOs
END_VAR

Input parameters

The input parameters of this function block represent initialization parameters and must already be assigned in the declaration of the FB instance! (Alternatively: Init() method). They may only be assigned once. A change at runtime is not possible.

Output parameters

VAR_OUTPUT
    bError         : BOOL;                           // TRUE if an error occurs. Reset by next method call.
    hrErrorCode    : HRESULT;                        // '< 0' = error; '> 0' = info; '0' = no error/info
    ipErrorMessage : I_TcMessage := fbErrorMessage;  // Shows detailed information about occurred errors, warnings and more.
    nCntResults    : ULINT;                          // Counts outgoing results (MultiArrays were calculated and sent to transfer tray).
END_VAR
  • bError: The output is TRUE if an error occurs.
  • hrErrorCode: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
  • ipErrorMessage: Contains more detailed information on the current return value. Refer here to the section Error description and information. This special interface pointer is internally secured so that it is always valid/assigned.

Methods

Call():

The method is called each cycle in order to apply the algorithm to the current input data. The function block waits for input data if the method indicates neither new results nor an error. This is a regular behavior in the process of the analysis chain.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
METHOD Call : HRESULT
VAR_OUTPUT
    bNewResult   : BOOL;       // TRUE every time when outgoing MultiArray was calculated and sent to transfer tray.
    bError       : BOOL;       // TRUE if an error occurs.
    hrErrorCode  : HRESULT;    // '< 0' = error; '> 0' = info; '0' = no error/info
END_VAR
  • bError: The output is TRUE if an error occurs.
  • hrErrorCode: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes. This output is identical to the return value of the method.
FB_CMA_WatchUpperThresholds 1:

If a timeout occurs or no MultiArray buffer is available for the result, then neither the input data nor the result data are lost. They are forwarded on the next call.

Init():

This method is not usually necessary in a Condition Monitoring application. It offers an alternative to the function block initialization. The Init() method may only be called during the initialization phase of the PLC. It cannot be used at runtime. You are referred to the use of an FB_init method or the attribute 'call_after_init' (see TwinCAT PLC reference). In addition, this facilitates the function block encapsulation.

The input parameters of the function block instance may not be assigned in the declaration if the initialization is to take place using the Init() method.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.

Configure():

The classification arguments must be configured at the beginning with the call of this method. The corresponding PLC array must be defined as follows. The Configure() method can also be used for a new configuration with a different set of arguments.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
METHOD Configure : HRESULT
VAR_INPUT
    pArg     : POINTER TO LREAL; // pointer to array (LREAL) of arguments
    nArgSize : UDINT;            // size of arguments buffer in bytes 
END_VAR

The input buffers correspond to one of the following definitions (input shape). The variable parameters are part of the function block input stInitPars.

Versions

Input buffer (MultiArray input stream)
Element type, number of dimensions, dimension sizes

Identical configuration of all channels and subchannels

LREAL, 1,
nMaxClasses

Channel-specific configuration
(nSubChannels = 0)

LREAL, 2,
nChannels x nMaxClasses

Subchannel-specific configuration
(nSubChannels > 0)

LREAL, 2,
nSubChannels x nMaxClasses

Channel and subchannel-specific configuration
(nSubChannels > 0)

LREAL, 3,
nChannels x nSubChannels x nMaxClasses

ResetData():

The method deletes all data records that have already been added, see Memory property of the function block. If the Call() method is called again after a ResetData(), the internal memory must be replenished in order to calculate a valid result.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
METHOD ResetData : HRESULT
VAR_INPUT
END_VAR

Alternatively bMemorize=FALSE can be set in the initialization structure for an automatic reset.

PassInputs():

As long as an FB_CMA_Source instance is called and signal data are thus transferred to a target block, all further function blocks of the analysis chain have to be called cyclically as explained in the API PLC Reference.
Sometimes it is useful not to execute an algorithm for a certain time. For example, some algorithms should be executed only after prior training or configuration. The function block must be called cyclically, but it is sufficient for the data arriving at the function block to be forwarded in the communication ring. This is done using the PassInputs() method in place of the Call() method. The algorithm itself is not called here, and accordingly no result is calculated and no output buffer generated.

  • Return value: If an error occurs, a corresponding error code of the type HRESULT is output. Possible values are described in the List of error codes.
METHOD PassInputs : HRESULT
VAR_INPUT
END_VAR

GetChannelErrors():

The method enables the querying of a list of the channel-specific return values when processing several channels (nChannels > 1). A call is useful in the case that the return value of the function block corresponds to one of the values eCM_InfRTime_AmbiguousChannelResults or eCM_ErrRTime_ErrornousChannelResults.

  • Return value: Information on the reading process of the list of error codes. The value is set to TRUE if the query was successful, otherwise to FALSE.

    METHOD GetChannelErrors : BOOL
VAR_IN_OUT
    aChannelErrors : ARRAY[*] OF HRESULT;
END_VAR
  • aChannelErrors: Error list of the type HRESULT of the length nChannels.

Similar function blocks

The FB_CMA_DiscreteClassification function block classifies multi-channel input data.

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4022.25

PC or CX (x86, x64)

Tc3_CM, Tc3_CM_Base

FB_CMA_WatchUpperThresholds 2:

Limited functional scope already available with CM 3.1. See section Compatibility.