component ilowpass2 "Low-pass filter with integer inputs and outputs"; description """While it may find other applications, this component was written to create smoother motion while jogging with an MPG. In a machine with high acceleration, a short jog can behave almost like a step function. By putting the \\fBilowpass2\\fR component between the MPG encoder \\fBcounts\\fR output and the axis \\fRjog-counts\\fR input, this can be smoothed. If MPG output is 'signed' set 'offset' to 0. If MPG output is 'unsigned' set 'offset' (max(MPG) +1)/2. Set 'scale' to 2^31 / (max(MPG-offset) +1). Assume MPG output = 0 to 65535. Set 'offset' to 32768. Set 'scale' to 65536. If axis jog-scale in this case is set to 1/65536 (=1.5258789e-5) each jog step is a movement of 1mm. Assume MPG output = -256 to 255. Set 'offset' to 0. Set 'scale' to 8388608. """; pin in s32 in; pin out s32 out; param rw s32 offset = 32768; param rw s32 scale = 65536; param rw float gain = 0.01 """Together with the period, sets the rate at which the output changes. Useful range is between 0 and 1, with higher values causing the input value to be tracked more quickly. For instance, a setting of 0.9 causes the output value to go 90% of the way towards the input value in each period"""; variable s32 value = 0; function _ "Update the output based on the input and parameters"; license "GPL"; author "Eric Duba"; ;; FUNCTION(_) { s32 diff = ((in - offset) * scale) - value; value += (s32)(diff * gain); out = value; }