# LGF_NonLinearInterpolation (FB / 3.0.1)

Overview

Author: Siemens Digital Industries

## Short description

This function implements a characteristic curve. The characteristic curve is defined via an interpolation point table with linear interpolation between the interpolation points. A prescribed input value generates an output value in each cycle based on the characteristic curve from the interpolation point table.

### Block Interface

| LGF_NonLinearInterpolation (FB) |
--- | --- | ---
LReal |  |  | value |  | outputValue |  |  | LReal
LReal |  |  | defaultOutValue |  |  |  |  |
Bool |  |  | enDefaultOutValue |  |  |  |  |
Bool |  |  | track |  |  |  |  |
Bool |  |  | reset |  |  |  |  |
Array[*] of LGF_typeNonLinSetpoints |  |  | setpoints |  |  | Array[*] of LGF_typeNonLinSetpoints

### Input parameter

Identifier | Data type | Default value | Description
--- | --- | --- | ---
value | LReal | 0.0 | Input value for calculating the output value over the defined characteristic curve.
defaultOutValue | LReal | 0.0 | Value for pre-assignment of the output variable (`outputValue` = `defaultOutValue`)
enDefaultOutValue | Bool | FALSE | Assign default output value (`outputValue` = `defaultOutValue`)
track | Bool | FALSE | The value of the output `outputValue` follows the value of the input `value` without using the characteristic curve as long as this input is set. (`outputValue` = `value`)
reset | Bool | FALSE | If the interpolation point table is changed in running operation, the input `reset` must be activated afterwards. Otherwise, the block cannot guarantee correct execution. (`outputValue` = 0.0)

### Output parameter

Identifier | Data type | Description
--- | --- | ---
outputValue | LReal | The output value that has been calculated from the input value over the defined characteristic curve.

### In/Out parameter

Identifier | Data type | Description
--- | --- | ---
setpoints | Array[*] of LGF_typeNonLinSetpoints | Setpoint point table for defining the characteristic curve (polynomial)

## User defined datatype(s)

### LGF_typeNonLinSetpoints (UDT / V3.0.1)

Data type to setup a setpoint table for the function `LGF_NonLinearInterpolation`

Identifier | Data type | Default value | Description
--- | --- | --- | ---
inputValue | LReal | 0.0 | Input value to be interpolated
outputValue | LReal | 0.0 | Corresponding interpolated value

## Functional description

The value of the output `outputValue` based on the following priority:

1. As long as the input `enDefaultOutValue` is set, the value defined via the parameter `defaultOutValue` will be output as output value.
2. As long as the input `reset` is set, the block is reset and the output value is `0.0`.
3. If the input `track` is set, the output value will be output directly as input value, without consideration of the characteristic curve.
4. Based on the input value, a characteristic curve value is calculated via the linearly interpolated, interpolation point table and output as an output value.

- If the input value is between two interpolation points within the interpolation point table, the output value is calculated as the intersection with the connecting line between the preceding and following interpolation points (see Figure below).
- If the input value is before the first interpolation point (lowest value defined in the interpolation point table), the output value will be calculated as the intersection of the line formed by the first two interpolation points of the interpolation point table.
- If the input value is after the last interpolation point (highest value defined in the interpolation point table), the output value will be calculated as the intersection of the line formed by the last two interpolation points of the interpolation point table.

### Interpolation point table

The interpolation point table is implemented through a variable of the data type Array. The type of the array corresponds to the PLC data type `LGF_typeNonLinSetpoints`.

You can create the interpolation point table in any global data block. The size of the array depends on the number of interpolation points.

Figure: Sample path of the output signal

NOTICE
  To keep the computing time of the block as short as possible, there is no check of the parameterization or the data of the interpolation point table.

  When entering the interpolation points in the interpolation point table, the following particularities must be considered. If these particularities are not taken into account, it can lead to a malfunction of the block.

  - At least two interpolation points must be entered in the interpolation point table.
  - The interpolation points in the interpolation point table must be entered in the Table in ascending order of the input values.

### Example

Figure: Sample data block

## Change log

Version & Date | Change description
--- | ---
| 1.0.0 | Siemens Industry Online Support
| 04.01.2017 | First released version
| 1.0.1 | Siemens Industry Online Support
| 17.08.2018 | Upgrade: TIA V15 Update 2
| 1.0.2 | Siemens Industry Online Support
| 23.11.2018 | Upgrade: TIA V15.1
| 1.0.6 | Simatic Systems Support
| 15.11.2019 | Regions, comments and constants are added
| 3.0.0 | Simatic Systems Support
| 23.04.2020 | Set version to V3.0.0, harmonize the version of the whole library
| 3.0.1 | Simatic Systems Support
| 22.03.2021 | Insert documentation