Stores a number which gets incremented on each `INC` pulse.
AVG=SUM/IDX
When RST pulse, SUM reset to zero.
If STEP is neagtive then Decrease.
Dont Set outputs differ from zero.
counter(avg)
@/counter(avg)
Stores a number which gets incremented on each `INC` pulse.
AVG=SUM/IDX
When RST pulse, SUM reset to zero.
If STEP is neagtive then Decrease.
Dont Set outputs differ from zero.
STEPnumber
Value to add on each increment. Use a negative value (e.g. -1) to make decrements.
INCpulse
Triggers a single step.
RSTpulse
Resets the counting value to start.
AVGnumber
The average value.
IDXnumber
The counting index value.
SUMnumber
To use the node in your project you should have the koadrobot/logic 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
struct State {
};
{{ GENERATED_CODE }}
void evaluate(Context ctx)
{
Number sum = getValue<output_SUM>(ctx);
Number idx = getValue<output_IDX>(ctx);
Number avg = getValue<output_AVG>(ctx);
if (isInputDirty<input_RST>(ctx))
{
sum = 0;
idx = 0;
avg = 0;
}
else if (isInputDirty<input_INC>(ctx))
{
sum += getValue<input_STEP>(ctx);
idx++;
if (idx==0)
avg=0;
else
avg= sum / idx;
}
emitValue<output_SUM>(ctx, sum);
emitValue<output_IDX>(ctx, idx);
emitValue<output_AVG>(ctx, avg);
}