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:

Standardization:

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
Outputs
Name | Type | Description |
---|---|---|
ipResultMessage | 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 |
bNewResult | BOOL | When a new result has been calculated, the output is |
bConfigured | BOOL | Displays |
fScalingParam1 | LREAL | Outputs the first scaling parameter depending on the scaling mode: |
fScalingParam1 | LREAL | Outputs the second scaling parameter depending on the scaling mode: |
bBusy | BOOL |
|
eState | Current state of the function block. See state diagram. |
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:

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 |