← All exercises

Scale (Configurable)

medium

Linearly scale a raw input to engineering units between two tunable endpoints.

What it teaches

The configurable cousin of Scale. Instead of hardcoded 4-20 to 0-100, the endpoints are inputs — same straight-line idea, but the engineer can tune any sensor to any output range.

Inputs and outputs

TagTypeDefaultDescription
In_RawREALRaw input value to scale
Cfg_RawMinREALRaw value at the minimum endpoint
Cfg_RawMaxREALRaw value at the maximum endpoint
Cfg_EUMinREALEngineering unit value at the minimum endpoint
Cfg_EUMaxREALEngineering unit value at the maximum endpoint
Out_ScaledREALScaled engineering unit value

Required behavior

  • Scales the raw input proportionally from the raw range to the engineering unit range.
  • Output follows the formula: Out_Scaled = Cfg_EUMin + (In_Raw - Cfg_RawMin) * (Cfg_EUMax - Cfg_EUMin) / (Cfg_RawMax - Cfg_RawMin).
  • Inputs outside the raw range extrapolate along the same line — the output is not clamped.
  • If the raw range is zero (Cfg_RawMin equals Cfg_RawMax), the output defaults to Cfg_EUMin.