scale(to-duty)

koadrobot/aritmatics/scale(to-duty)

Scale input value to duty (0..1) by Start..Stop (map) with ensure (Start<Stop ).
scale(to-duty)
@/scale(to-duty)
Scale input value to duty (0..1) by Start..Stop (map) with ensure (Start<Stop ).
Xnumber
Value to map
STARTnumber
Source range lower bound
STOPnumber
Source range upper bound
scale(to-duty)
X
START
STOP
DUTY
DUTYnumber
To use the node in your project you should have the koadrobot/aritmatics library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD dirtieness disable

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    Number x = getValue<input_X>(ctx);
    Number start = getValue<input_START>(ctx);
    Number stop = getValue<input_STOP>(ctx);
    Number out = (x-start) / (stop-start);
    emitValue<output_DUTY>(ctx, out);
}