# counting the spindle encoder in software loadrt encoder num_chan=1 # simulate the encoder loadrt sim_encoder num_chan=1 loadrt limit2 count=1 addf limit2.0 servo-thread ####################################################### # Beginning of threading related stuff ####################################################### # spindle speed control net spindle-speed-cmd motion.spindle-speed-out => limit2.0.in net spindle-speed-limited limit2.0.out => sim-encoder.0.speed # simulate spindle mass setp limit2.0.maxv 500.0 # rpm/second # spindle encoder # connect encoder signals to encoder counter net spindle-phase-A sim-encoder.0.phase-A => encoder.0.phase-A net spindle-phase-B sim-encoder.0.phase-B => encoder.0.phase-B net spindle-phase-Z sim-encoder.0.phase-Z => encoder.0.phase-Z # assume 120 ppr = 480 counts/rev for the spindle setp sim-encoder.0.ppr 120 # iocontrol output is in rpm, but sim-encoder speed is rps setp sim-encoder.0.scale 60 # scale encoder output to read in revolutions # (that way thread pitches can be straightforward, # a 20 tpi thread would multiply the encoder output # by 1/20, etc) setp encoder.0.position-scale 480 # encoder reset control # hook up motion controller's sync output net spindle-index-enable motion.spindle-index-enable <=> encoder.0.index-enable # report our revolution count to the motion controller net spindle-pos encoder.0.position => motion.spindle-revs # for spindle velocity estimate loadrt lowpass count=1 loadrt scale count=1 net spindle-rps-raw encoder.0.velocity lowpass.0.in net spindle-rps-filtered lowpass.0.out scale.0.in motion.spindle-speed-in net spindle-rpm-filtered scale.0.out setp scale.0.gain 60 setp lowpass.0.gain .07 addf lowpass.0 servo-thread addf scale.0 servo-thread net spindle-fwd <= motion.spindle-forward addf encoder.capture-position servo-thread addf sim-encoder.update-speed servo-thread addf sim-encoder.make-pulses base-thread addf encoder.update-counters base-thread