component fakeencoder; pin in float velocity; pin out float position; pin io bit index-enable; function _; license "GPL"; ;; #include FUNCTION(_) { double old_position = position; double new_position = old_position + velocity * fperiod; if(index_enable) { if(floor(new_position) != floor(old_position)) { index_enable = false; if(velocity > 0) // turning forward, position after reset should be positive new_position = new_position - floor(new_position); else // turning backward, position after reset should be negative new_position = new_position - ceil(new_position); index_enable = 0; } } position = new_position; }