mariusl wrote:As the material is pulled through, the encoder on the other side will start to count when the section starts to exit the machine. When the end of the section is in the middle of the machine, the first encoder is not counting but the second one is
This was recently discussed on the mailing list in a slightly different scenario. (a sectional linear motor).
In that scenario there was a risk of cumulative errors on the switch-over, but assuming that with your machine the part only travels once through the machine, this is not a problem for you.
You can probably switch to the exit encoder as soon as the X-position > the distance between the encoders.
One way (not the neatest, but good enough) would be to use encoder1 while X < critical_length and encoder2 + critical_length for X > critical_length.
It is very important to reset both encoders before loading a new workpiece with this approach. You also need to zero encoder 2 on switchover.
Use "comp"
www.linuxcnc.org/docs/html/man/man9/comp.9.html to set a flag based on length
use "mux2"
www.linuxcnc.org/docs/html/man/man9/mux2.9.html controlled by that flag to switch between the encoder positions
use "sum2"
www.linuxcnc.org/docs/html/man/man9/sum2.9.html to add the fixed offset to the second encoder position.
use "edge"
www.linuxcnc.org/docs/html/man/man9/edge.9.html to generate a reset pulse for encoder 2 on changeover.
Is this enough. or do you need a sample HAL file?
I think this is the simplest solution, though it would be better to work in encoder counts, latching values and summing deltas.
A custom HAL component might be worth considering.