FB_ALY_ScalerFitting

The Scaler Fitting module can be used to determine the parameters for feature scaling and save them in a file. These parameters can then be used in the Scaler module.

The parameters required for scaling are determined depending on the operation mode.

Normalization:

FB_ALY_ScalerFitting 1:

Standardization:

FB_ALY_ScalerFitting 2:

Syntax

Definition:

FUNCTION_BLOCK FB_ScalerFitting
VAR_OUTPUT
    ipResultMessage: Tc3_EventLogger.I_TcMessage;
    bError: BOOL;
    bNewResult: BOOL;
    bConfigured: BOOL;
    fScalingParam1: LREAL;
    fScalingParam2: LREAL;
    bBusy: BOOL;
    eState: E_TeachState;
END_VAR

FB_ALY_ScalerFitting 3: Outputs

Name

Type

Description

ipResultMessage

I_TcMessage

Contains more detailed information on the current return value. For this special interface pointer, it is ensured internally that it is always valid/assigned.

bError

BOOL

The output is TRUE if an error occurs.

bNewResult

BOOL

When a new result has been calculated, the output is TRUE.

bConfigured

BOOL

Displays TRUE when the function block is successfully configured.

fScalingParam1

LREAL

Outputs the first scaling parameter depending on the scaling mode:
Normalization: Smallest value of the input channel.
Standardization: Mean value of the input channel.

fScalingParam1

LREAL

Outputs the second scaling parameter depending on the scaling mode:
Normalization: Largest value of the input channel.
Standardization: Standard deviation of the input channel.

bBusy

BOOL

TRUE if the FB is active due to a file access.

eState

E_ALY_TeachState

Current state of the function block. See state diagram.

FB_ALY_ScalerFitting 4: Methods

Name

Definition location

Description

Call()

Local

Method for calculating the outputs for a specific configuration.

Configure()

Local

General configuration of the algorithm with its parameterized conditions.

GetBusyState()

Local

This method returns the Busy state of the function block.

Reset()

Local

Resets all internal states or the calculations performed so far.

SetChannelValue()

Local

Method for passing values to the algorithm.

SwitchState_Idle()

Local

Method for setting the function block to Idle state when the teach-in process is complete.

SwitchState_Teach()

Local

Method for putting the function block into teach-in mode.

UpdateState()

Local

State update after a state change has been initiated with one of the SwitchState methods. Is called up until the target state is reached.

State diagram

Due to the asynchronous file access in real time applications this function block needs a state machine to prepare and finish file access.

At startup the function block is in Idle state. To write the incoming data to a file it has to be switched to state Teach. Therefore the method SwitchState_Teach() has to be called once to set the function block to the PendingTeach state. After that the method UpdateState() has to be called until the function block is in state Teach. In this state one or multiple teach cycles can be proceeded. If the function block should not teach additional cycles it can be set to Idle state again. To initiate the state switch the method SwitchState_Idle() has to be called. After that the method UpdateState() has to be called until the function block is in state Idle.

State diagram for the teach procedure of the data:

FB_ALY_ScalerFitting 5:

Sample

VAR
    fbScalerFitting : FB_ALY_ScalerFitting_1Ch;
    tTimeout : TIME := T#5S;
    eScalingMode : E_ALY_ScalingMode := E_ALY_ScalingMode.Normalization;
    sFilePath : STRING := '%TC_BOOTPRJPATH%\Scaler.json';
    bConfigure : BOOL := TRUE;
    eState : E_ALY_TeachState := E_ALY_TeachState.Idle;
    bTeach : BOOL;
    fInput : LREAL;
    bFit : BOOL;
END_VAR
// Configure algorithm
IF bConfigure THEN
    bConfigure := FALSE;
    fbScalerFitting.Configure(eScalingMode, tTimeout, sFilePath);
END_IF

// Call algorithm
eState := fbScalerFitting.eState;
CASE eState OF
E_ALY_TeachState.Idle:
    IF bTeach THEN
        fbScalerFitting.SwitchState_Teach();
        fbScalerFitting.UpdateState();
    END_IF
E_ALY_TeachState.Teach:
    fbScalerFitting.SetChannelValue(fInput);
    fbScalerFitting.Call(bFit);
    IF NOT bTeach THEN
        fbScalerFitting.SwitchState_Idle();
        fbScalerFitting.UpdateState();
    END_IF
E_ALY_TeachState.Pending,
E_ALY_TeachState.PendingIdle,
E_ALY_TeachState.PendingTeach:
    fbScalerFitting.UpdateState();
    eState := fbScalerFitting.eState;
END_CASE

Requirements

Development environment

Target platform

Plc libraries to include

TwinCAT v3.1.4024.0

PC or CX (x64, x86)

Tc3_Analytics