LinearFunction
This simulation component outputs the result of the linear function Output(Input) = Slope * Input + Offset
.
When to use
Use this simulation component if you want to change the offset and slope of an input signal. You can for example convert unit-less signals into signals which have a defined unit or vice versa.
How to use
Add this simulation component from the simulation component library and define the parameters Offset
and Slope
.
Parameters
Offset
A value indicating an offset which is added to the input signal.
Slope
A value indicating a factor with which the input signal is multiplied.
Inputs
Input
The input to the LinearFunction
block.
Outputs
Output
Outputs a value which is calculated by the formula Slope * Input + Offset
.
Example
In this example, the distance output of a DistanceSensor simulation component is connected to the LinearFunction
block. The distance is scaled between a lower and upper sensor limit, e.g. from 0 m ... 0.5 m, to an analog value, e.g. from 0 ... 27648.
To calculate the Slope
we can use the following formula:
Slope = (adc_upper - adc_lower) / (upperLimitSensor - lowerLimitSensor)
Slope = (27648 - 0) / (0.5 - 0)
Slope = 55296
The offset is calculated as follows:
Offset = adc_lower - (slope * lowerLimitSensor)
Offset = 0 - (55296 * 0)
Offset = 0
For a DistanceSensor output of 0.25 m the LinearFunction block outputs an analog value of 13824.