# core HAL config file for simulation - 4 axis

# load RT modules
loadrt [KINS]KINEMATICS
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS
loadrt ddt count=8

# add motion controller functions to servo thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf ddt.0 servo-thread
addf ddt.1 servo-thread
addf ddt.2 servo-thread
addf ddt.3 servo-thread
addf ddt.4 servo-thread
addf ddt.5 servo-thread
addf ddt.6 servo-thread
addf ddt.7 servo-thread

# create HAL signals for position commands from motion module
net J0pos <= joint.0.motor-pos-cmd
net J1pos <= joint.1.motor-pos-cmd
net J2pos <= joint.2.motor-pos-cmd
net J3pos <= joint.3.motor-pos-cmd


# loop position commands back to motion module feedback
net J0pos => joint.0.motor-pos-fb
net J1pos => joint.1.motor-pos-fb
net J2pos => joint.2.motor-pos-fb
net J3pos => joint.3.motor-pos-fb

# send the position commands thru differentiators to
# generate velocity and accel signals
# define the signals, and hook them up
net J0pos => ddt.0.in
net J0vel <= ddt.0.out
net J0vel => ddt.1.in
net J0acc <= ddt.1.out

net J1pos => ddt.2.in
net J1vel <= ddt.2.out
net J1vel => ddt.3.in
net J1acc <= ddt.3.out

net J2pos => ddt.4.in
net J2vel <= ddt.4.out
net J2vel => ddt.5.in
net J2acc <= ddt.5.out

net J3pos => ddt.6.in
net J3vel <= ddt.6.out
net J3vel => ddt.7.in
net J3acc <= ddt.7.out

# 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

# amp control
net xena joint.0.amp-enable-out
net yena joint.1.amp-enable-out
net zena joint.2.amp-enable-out
net aena joint.3.amp-enable-out

net xflt joint.0.amp-fault-in
net yflt joint.1.amp-fault-in
net zflt joint.2.amp-fault-in
net aflt joint.3.amp-fault-in

loadusr -W scaragui

net j0 joint.0.pos-fb scaragui.joint0
net j1 joint.1.pos-fb scaragui.joint1
net j2 joint.2.pos-fb scaragui.joint2
net j3 joint.3.pos-fb scaragui.joint3
