delta

nkrkv/pid/delta

Outputs a difference between the current `IN` value and its value at the moment of the last node update.
delta
@/delta
Outputs a difference between the current `IN` value and its value at the moment of the last node update.
INnumber
Input value
UPDpulse
Triggers a new update
RSTpulse
Resets the output difference to 0
delta
OUT
IN
UPD
RST
OUTnumber
Difference between the current `IN` value and the value it has when the previous `UPD` was send. Can be positive or negative. Always equals to 0 on the first update.
To use the node in your project you should have the nkrkv/pid 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 output_OUT

struct State {
    Number prevValue = NAN;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    auto state = getState(ctx);
    auto inValue = getValue<input_IN>(ctx);
    
    // Emit 0 in case of reset or the very first update
    auto outValue =
        (isInputDirty<input_RST>(ctx) || isnan(state->prevValue))
        ? 0
        : inValue - state->prevValue;
    
    emitValue<output_OUT>(ctx, outValue);
    state->prevValue = inValue;
}