# Generated by stepconf 1.1 at Mon Mar 14 20:22:34 2022
# If you make changes to this file, they will be
# overwritten when you run stepconf again
loadrt [KINS]KINEMATICS
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS
loadrt encoder num_chan=2 # 0 used for native speed sense, 1 used for testing new encoder
loadrt hal_parport cfg="0 out"
setp parport.0.reset-time 5000
loadrt stepgen step_type=6,6
loadrt lowpass
loadrt scale count=5  # 0 used to convert spindle speed from rps to rpm, 
                      # 1 used in cusom.hal to adjust spindle set-speed fequency
                      # 2 used in cusom.hal for mpg scale/increment selection
                      # 3 & 4 used in custom.hal for mgp joystic

addf parport.0.read base-thread
addf encoder.update-counters base-thread
addf stepgen.make-pulses base-thread
addf parport.0.write base-thread
addf parport.0.reset base-thread

addf stepgen.capture-position servo-thread
addf encoder.capture-position servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf lowpass.0         servo-thread
addf scale.0           servo-thread
addf stepgen.update-freq servo-thread

net spindle-cmd-rpm     <= spindle.0.speed-out
net spindle-cmd-rpm-abs <= spindle.0.speed-out-abs
net spindle-cmd-rps     <= spindle.0.speed-out-rps
net spindle-cmd-rps-abs <= spindle.0.speed-out-rps-abs

net xphasea => parport.0.pin-02-out
net xphaseb => parport.0.pin-03-out
net xphasec => parport.0.pin-04-out
net xphased => parport.0.pin-05-out

net zphasea => parport.0.pin-06-out
net zphaseb => parport.0.pin-07-out
net zphasec => parport.0.pin-08-out
net zphased => parport.0.pin-09-out

setp parport.0.pin-01-out-invert 1
setp parport.0.pin-01-out-reset true
setp parport.0.pin-01-out true           # 74ls374 clock pin 

# spindle encoder stuff
setp encoder.0.counter-mode true
setp encoder.0.position-scale 100
net spindle-index parport.0.pin-12-in-not
net spindle-ppr parport.0.pin-10-in-not
net spindle-ppr encoder.0.phase-A
net spindle-index encoder.0.phase-Z
net spindle-pos spindle.0.revs encoder.0.position-interpolated
net spindle-index-enable spindle.0.index-enable encoder.0.index-enable
net spindle-vel encoder.0.velocity spindle.0.speed-in 

# Filtering and scaling... moved to custom_postgui
#setp scale.0.gain 60
#setp lowpass.0.gain .07
#net spindle-vel lowpass.0.in
#net spindle-rps-filtered lowpass.0.out scale.0.in 
#net spindle-rpm-filtered scale.0.out

net estop-external <= parport.0.pin-11-in-not

setp stepgen.0.position-scale [JOINT_0]SCALE
setp stepgen.0.steplen 20000
setp stepgen.0.dirdelay 20000
setp stepgen.0.maxaccel [JOINT_0]STEPGEN_MAXACCEL
net xpos-cmd joint.0.motor-pos-cmd => stepgen.0.position-cmd
net xpos-fb stepgen.0.position-fb => joint.0.motor-pos-fb
net xphasea <= stepgen.0.phase-A
net xphaseb <= stepgen.0.phase-B
net xphasec <= stepgen.0.phase-C
net xphased <= stepgen.0.phase-D
net xenable joint.0.amp-enable-out => stepgen.0.enable

setp stepgen.1.position-scale [JOINT_1]SCALE
setp stepgen.1.steplen 20000
setp stepgen.1.dirdelay 20000
setp stepgen.1.maxaccel [JOINT_1]STEPGEN_MAXACCEL
net zpos-cmd joint.1.motor-pos-cmd => stepgen.1.position-cmd
net zpos-fb stepgen.1.position-fb => joint.1.motor-pos-fb
net zphasea <= stepgen.1.phase-A
net zphaseb <= stepgen.1.phase-B
net zphasec <= stepgen.1.phase-C
net zphased <= stepgen.1.phase-D
net zenable joint.1.amp-enable-out => stepgen.1.enable

# moved to custom.hal
#net estop-out <= iocontrol.0.user-enable-out
#net estop-ext => iocontrol.0.emc-enable-in

loadusr -W hal_manualtoolchange
net tool-change iocontrol.0.tool-change => hal_manualtoolchange.change
net tool-changed iocontrol.0.tool-changed <= hal_manualtoolchange.changed
net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number
net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared
