# HAL config file for vismach simulation of horizontal boring machine

# first load all the RT modules that will be needed
# kinematics
loadrt [KINS]KINEMATICS
# motion controller, get name and thread periods from ini file
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS
# load four limit3 blocks to simulate the accel and vel limits of the motors
loadrt limit3 count=4
# load window comparators for home/limit switches
loadrt wcomp count=4
loadrt not count=4

# load the vismach model
loadusr -W hbmgui

# set a visible tool
setp hbmgui.tool-length 2
setp hbmgui.tool-radius 0.5
#net tool-len motion.tooloffset.w hbmgui.tool-length

# add motion controller functions to servo thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
# add other functions
addf limit3.0 servo-thread
addf limit3.1 servo-thread
addf limit3.2 servo-thread
addf limit3.3 servo-thread
addf wcomp.0 servo-thread
addf wcomp.1 servo-thread
addf wcomp.2 servo-thread
addf wcomp.3 servo-thread
addf not.0 servo-thread
addf not.1 servo-thread
addf not.2 servo-thread
addf not.3 servo-thread

# create HAL signals for position commands from motion module
# send them to limit blocks so it will ferror if it exceeds a limit
net table-pos-cmd  joint.0.motor-pos-cmd => limit3.0.in
net head-pos-cmd   joint.1.motor-pos-cmd => limit3.1.in
net saddle-pos-cmd joint.2.motor-pos-cmd => limit3.2.in
net quill-pos-cmd  joint.3.motor-pos-cmd => limit3.3.in

# set the limit block parameters from the ini file
setp limit3.0.maxv [JOINT_0]MAX_VELOCITY
setp limit3.0.maxa [JOINT_0]MAX_ACCELERATION
setp limit3.1.maxv [JOINT_1]MAX_VELOCITY
setp limit3.1.maxa [JOINT_1]MAX_ACCELERATION
setp limit3.2.maxv [JOINT_2]MAX_VELOCITY
setp limit3.2.maxa [JOINT_2]MAX_ACCELERATION
setp limit3.3.maxv [JOINT_3]MAX_VELOCITY
setp limit3.3.maxa [JOINT_3]MAX_ACCELERATION

# loop limited position commands back to motion module feedback
# also send them to the vismach model and to the "limit switches"
net table-pos-fb  limit3.0.out => joint.0.motor-pos-fb hbmgui.table  wcomp.0.in
net head-pos-fb   limit3.1.out => joint.1.motor-pos-fb hbmgui.head   wcomp.1.in
net saddle-pos-fb limit3.2.out => joint.2.motor-pos-fb hbmgui.saddle wcomp.2.in
net quill-pos-fb  limit3.3.out => joint.3.motor-pos-fb hbmgui.quill  wcomp.3.in

# route home/limit switch signals to EMC
net table-limits-ok wcomp.0.out => not.0.in
net table-limits-tripped not.0.out => joint.0.neg-lim-sw-in joint.0.pos-lim-sw-in joint.0.home-sw-in
net head-limits-ok wcomp.1.out => not.1.in
net head-limits-tripped not.1.out => joint.1.neg-lim-sw-in joint.1.pos-lim-sw-in joint.1.home-sw-in
net saddle-limits-ok wcomp.2.out => not.2.in
net saddle-limits-tripped not.2.out => joint.2.neg-lim-sw-in joint.2.pos-lim-sw-in joint.2.home-sw-in
net quill-limits-ok wcomp.3.out => not.3.in
net quill-limits-tripped not.3.out => joint.3.neg-lim-sw-in joint.3.pos-lim-sw-in joint.3.home-sw-in

# set location of switches
# these positions are in vismach coords - they can be are offset from machine coords
# these hardware limits are set to allow 0.5in more overall travel than the soft limits
setp wcomp.0.min -50.5
setp wcomp.0.max  50.5
setp wcomp.1.min -0.5
setp wcomp.1.max  100.5
setp wcomp.2.min -25.5
setp wcomp.2.max  25.5
setp wcomp.3.min -42.5
setp wcomp.3.max  0.5

# estop loopback
net estop-loop iocontrol.0.user-enable-out iocontrol.0.emc-enable-in

# create signals for tool loading loopback
net tool-prep-loop iocontrol.0.tool-prepare iocontrol.0.tool-prepared
net tool-change-loop iocontrol.0.tool-change iocontrol.0.tool-changed

net spindle-fwd spindle.0.forward
net spindle-rev spindle.0.reverse
net spindle-speed spindle.0.speed-out

net lube iocontrol.0.lube
net flood iocontrol.0.coolant-flood
net mist iocontrol.0.coolant-mist
