#RMC Rev40 - 7i73 & new control panel
#RMC Rev32 - ATC4

loadrt [KINS]KINEMATICS
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS num_dio=20 num_aio=64 #ATC
loadrt hostmot2
loadrt hm2_eth board_ip="10.10.10.10" config="num_encoders=1 num_pwmgens=0 num_stepgens=5 sserial_port_0=10xxxx" 
setp    [HMOT](CARD0).watchdog.timeout_ns 5000000
loadrt pid                          names=pid.x,pid.y,pid.z,pid.a,pid.s,pid.o #ORIENT
loadrt abs                          count=2
loadrt lowpass                      names=lowpass.spindle
loadrt scale                        count=3                 #SPINDLE LOAD JOG-CONT
loadrt orient                       count=1                 #ORIENT
loadrt mux2                         count=6                 #ORIENT FRO SRO JOG-CONT
loadrt mux4                         names=mux4.rro          #RRO
loadrt mux16                        names=mux16.jogincr     #MPG
loadrt and2                         count=12
loadrt or2                          count=10                 #ORIENT2
loadrt not			                count=6
loadrt toggle                       count=7
loadrt toggle2nist                  count=3                 #MIST FLOOD 
loadrt dbounce                      count=4
loadrt encoder                      num_chan=1              #MAXVEL OVERRIDE
loadrt multiclick                   count=1                 #BLAST
loadrt near                         count=1
loadrt oneshot                      count=1
loadrt timedelay                    count=6
loadrt xor2                         count=1                 #ATC
loadrt carousel                     pockets=18 encoding=counts num_sense=2 dir=2   #ATC
loadrt conv_float_s32               count=2                 #ATC RRO
loadrt lincurve                     personality=6           #ORIENT
loadrt tristate_bit                 count=1                 #ORIENT2
loadrt matrix_kb                    config=4x8              #OPERATOR PANEL KEYPAD
loadrt wcomp                        count=3                 #OVERRIDES
loadrt time                         count=1                 #PROBE BASIC
loadrt blink                        count=2                 #RRO SRO LEDS
loadrt classicladder_rt numPhysInputs=15 numPhysOutputs=15 numS32in=10 numS32out=10 numFloatIn=10 numFloatOut=10 numBits=50 numWords=50

addf [HMOT](CARD0).read         servo-thread
addf motion-command-handler     servo-thread
addf motion-controller          servo-thread
addf orient.0           		servo-thread    #ORIENT
addf mux2.0			            servo-thread    #ORIENT
addf mux2.1			            servo-thread    #FRO
addf mux2.2			            servo-thread    #FRO
addf mux2.3			            servo-thread    #SRO
addf mux2.4			            servo-thread    #SRO
addf mux2.5			            servo-thread    #JOG-CONT
addf mux4.rro   	            servo-thread    #RRO
addf mux16.jogincr              servo-thread    #MPG
addf pid.x.do-pid-calcs         servo-thread
addf pid.y.do-pid-calcs         servo-thread
addf pid.z.do-pid-calcs         servo-thread
addf pid.a.do-pid-calcs         servo-thread
addf pid.s.do-pid-calcs         servo-thread
addf pid.o.do-pid-calcs         servo-thread    #ORIENT
addf lowpass.spindle            servo-thread
addf near.0                     servo-thread
addf abs.0                      servo-thread
addf abs.1                      servo-thread    #ORIENT
addf classicladder.0.refresh    servo-thread
addf oneshot.0                  servo-thread    #ESTOP RELAY
addf timedelay.0                servo-thread    #MACHINE ON
addf timedelay.1                servo-thread    
addf timedelay.2                servo-thread    
addf timedelay.3                servo-thread    #SPINDLE FAN
addf timedelay.4                servo-thread    #BLAST
addf timedelay.5                servo-thread    #FEEDHOLD LED
addf and2.0                     servo-thread    #AIR PRESSURE
addf and2.1                     servo-thread    #PDB ENABLE
addf and2.2						servo-thread    
addf and2.3						servo-thread    #BLAST
addf and2.4                     servo-thread    #FEEDHOLD LED
addf and2.5                     servo-thread    #YELOW LED
addf and2.6						servo-thread    #ORIENT
addf and2.7						servo-thread    #BLINK FRO
addf and2.8						servo-thread    #BLINK SRO
addf and2.9						servo-thread    #MODE MANUAL
addf and2.10					servo-thread    #MODE MDI
addf and2.11					servo-thread    #MODE AUTO
addf or2.0                      servo-thread    #PDB
addf or2.1                      servo-thread    #AUTO MODE FROM LADDER OR BTN
addf or2.2                      servo-thread    #FRO BLINK
addf or2.3                      servo-thread    #FRO BLINK
addf or2.4                      servo-thread    #ORIENT
addf or2.5                      servo-thread    #ORIENT
addf or2.6                      servo-thread    #ORIENT2
addf or2.7                      servo-thread    #SRO BLINK
addf or2.8                      servo-thread    #SRO BLINK
addf or2.9                      servo-thread    #RRO
addf not.0						servo-thread    #PDB ENABLE
addf not.1                      servo-thread    #OPTSTOP
addf not.2                      servo-thread    #BLKDEL
addf not.3                      servo-thread    #FRO
addf not.4                      servo-thread    #PROBE BASIC POSTGUI
addf not.5                      servo-thread    #spare
addf toggle.0                   servo-thread    #OPTSTOP
addf toggle.1                   servo-thread    #BLKDEL
addf toggle.2                   servo-thread    #postgui MIST
addf toggle.3                   servo-thread    #postgui FLOOD
addf toggle.4                   servo-thread    #BLAST
addf toggle.5                   servo-thread    #SGLBLK
addf toggle.6                   servo-thread    #LIGHTS
addf toggle2nist.0              servo-thread    #MIST
addf toggle2nist.1              servo-thread    #FLOOD
addf toggle2nist.2              servo-thread    #SPARE
addf dbounce.0                  servo-thread    #OPTSTOP
addf dbounce.1                  servo-thread    #BLKDEL
addf dbounce.2                  servo-thread    #postgui MIST
addf dbounce.3                  servo-thread    #postgui FLOOD
addf encoder.update-counters    servo-thread
addf encoder.capture-position   servo-thread
addf scale.0                    servo-thread    #SPINDLE LOAD
addf scale.1                    servo-thread    #JOG-CONT
addf scale.2                    servo-thread    #BLAST
addf multiclick.0               servo-thread    #BLAST
addf xor2.0                     servo-thread    #PDB
addf carousel.0                 servo-thread    #ATC
addf conv-float-s32.0           servo-thread    #ATC (G-code analogue outputs are s32 floats)
addf conv-float-s32.1           servo-thread    #RRO
addf lincurve.0                 servo-thread    #ORIENT
addf tristate-bit.0             servo-thread    #ORIENT2
addf matrix_kb.0                servo-thread    #OPERATOR PANEL KEYPAD
addf wcomp.0                    servo-thread    #FRO
addf wcomp.1                    servo-thread    #SRO
addf wcomp.2                    servo-thread    #RRO
addf blink.0                    servo-thread    #RRO
addf blink.1                    servo-thread    #SRO
addf time.0                     servo-thread    #PROBE BASIC POSTGUI
addf [HMOT](CARD0).write        servo-thread
setp dbounce.0.delay            5               #OPTSTOP
setp dbounce.1.delay            5               #BLKDEL
setp dbounce.2.delay            5               #postgui MIST
setp dbounce.3.delay            5               #postgui FLOOD
setp [HMOT](CARD0).dpll.01.timer-us -50
setp [HMOT](CARD0).stepgen.timer-number 1


#external input signals
#net VFD_ANALOG_IN               <=  [HMOT](CARD0).7i76.0.0.input-00
net VFD_ANALOG_IN               <=  [HMOT](CARD0).7i76.0.0.analogin0
net TOOL_SETTER_OVERTRAVEL      <=  [HMOT](CARD0).7i76.0.0.input-01

#LIMIT SWITCHES (invert pins for all NC proxys)
net home-a                      <=  [HMOT](CARD0).7i76.0.0.input-10-not
net min-y                       <=  [HMOT](CARD0).7i76.0.0.input-11-not
net max-home-y                  <=  [HMOT](CARD0).7i76.0.0.input-12-not
net min-x                       <=  [HMOT](CARD0).7i76.0.0.input-14-not
net max-home-x                  <=  [HMOT](CARD0).7i76.0.0.input-13-not
net max-home-z                  <=  [HMOT](CARD0).7i76.0.0.input-15-not

#AIR SAFETY - comment out to bypass air safety
#net AIR_PRESSURE_OK             <=  [HMOT](CARD0).7i76.0.0.input-24
net ESTOP-RELAY                 <=	[HMOT](CARD0).7i76.0.0.input-20
net AIR_PRESSURE_OK             =>  and2.0.in0
net ESTOP-RELAY                 =>  and2.0.in1
net ESTOP-CLEAR                 <=  and2.0.out
#net ESTOP-CLEAR                 =>  iocontrol.0.emc-enable-in
net ESTOP-RELAY                 =>  iocontrol.0.emc-enable-in
net ESTOP-OUT			        <=	iocontrol.0.user-enable-out

#MACHINE-ON WITH ESTOP CLEAR
setp oneshot.0.width            2
setp timedelay.0.off-delay      0.1
net ESTOP-RELAY 	            =>	oneshot.0.in
net MACHINE_ON_DELAY            <=  oneshot.0.out
net MACHINE_ON_DELAY            =>  timedelay.0.in
net MACHINE_ON                  <=  timedelay.0.out
net MACHINE_ON                  =>  halui.machine.on
net MACHINE-IS-ON               <=  halui.machine.is-on

#SPINDLE FAN
setp timedelay.3.on-delay       5
setp timedelay.3.off-delay      30
net spindle-enable              =>  timedelay.3.in
net SPINDLE_FAN                 <=  timedelay.3.out
net SPINDLE_FAN                 =>  [HMOT](CARD0).7i76.0.0.output-05

#ENABLE SIGNAL TO STEPPER DRIVES
net machine-is-enabled          <=  motion.motion-enabled
net machine-is-enabled          =>  [HMOT](CARD0).7i76.0.0.output-09    

#*******************
#  AXIS X JOINT 0
#*******************
setp   pid.x.Pgain     [JOINT_0]P
setp   pid.x.Igain     [JOINT_0]I
setp   pid.x.Dgain     [JOINT_0]D
setp   pid.x.bias      [JOINT_0]BIAS
setp   pid.x.FF0       [JOINT_0]FF0
setp   pid.x.FF1       [JOINT_0]FF1
setp   pid.x.FF2       [JOINT_0]FF2
setp   pid.x.deadband  [JOINT_0]DEADBAND
setp   pid.x.maxoutput [JOINT_0]MAX_OUTPUT
setp   pid.x.error-previous-target true
setp   pid.x.maxerror 0.000500 # This setting is to limit bogus stepgen velocity corrections caused by position feedback sample time jitter.
net x-index-enable  <=> pid.x.index-enable
net x-enable        =>  pid.x.enable
net x-pos-cmd       =>  pid.x.command
net x-pos-fb        =>  pid.x.feedback
net x-output        <=  pid.x.output

# Step Gen signals/setup
setp   [HMOT](CARD0).stepgen.00.dirsetup        [JOINT_0]DIRSETUP
setp   [HMOT](CARD0).stepgen.00.dirhold         [JOINT_0]DIRHOLD
setp   [HMOT](CARD0).stepgen.00.steplen         [JOINT_0]STEPLEN
setp   [HMOT](CARD0).stepgen.00.stepspace       [JOINT_0]STEPSPACE
setp   [HMOT](CARD0).stepgen.00.position-scale  [JOINT_0]STEP_SCALE
setp   [HMOT](CARD0).stepgen.00.step_type        0
setp   [HMOT](CARD0).stepgen.00.control-type     1
setp   [HMOT](CARD0).stepgen.00.maxaccel         [JOINT_0]STEPGEN_MAXACCEL
setp   [HMOT](CARD0).stepgen.00.maxvel           [JOINT_0]STEPGEN_MAXVEL

# ---closedloop stepper signals---
net x-pos-cmd    <= joint.0.motor-pos-cmd
net x-vel-cmd    <= joint.0.vel-cmd
net x-output     <= [HMOT](CARD0).stepgen.00.velocity-cmd
net x-pos-fb     <= [HMOT](CARD0).stepgen.00.position-fb
net x-pos-fb     => joint.0.motor-pos-fb
net x-enable     <= joint.0.amp-enable-out
net x-enable     => [HMOT](CARD0).stepgen.00.enable
net ALARM_X      <=  [HMOT](CARD0).7i76.0.0.input-31
net ALARM_X      =>  joint.0.amp-fault-in

# ---setup home / limit switch signals---
net max-home-x      =>  joint.0.home-sw-in
net min-x           =>  joint.0.neg-lim-sw-in
net max-home-x      =>  joint.0.pos-lim-sw-in

#*******************
#  AXIS Y JOINT 1
#*******************
setp   pid.y.Pgain     [JOINT_1]P
setp   pid.y.Igain     [JOINT_1]I
setp   pid.y.Dgain     [JOINT_1]D
setp   pid.y.bias      [JOINT_1]BIAS
setp   pid.y.FF0       [JOINT_1]FF0
setp   pid.y.FF1       [JOINT_1]FF1
setp   pid.y.FF2       [JOINT_1]FF2
setp   pid.y.deadband  [JOINT_1]DEADBAND
setp   pid.y.maxoutput [JOINT_1]MAX_OUTPUT
setp   pid.y.error-previous-target true
setp   pid.y.maxerror 0.000500 # This setting is to limit bogus stepgen velocity corrections caused by position feedback sample time jitter.
net y-index-enable  <=> pid.y.index-enable
net y-enable        =>  pid.y.enable
net y-pos-cmd       =>  pid.y.command
net y-pos-fb        =>  pid.y.feedback
net y-output        <=  pid.y.output

# Step Gen signals/setup
setp   [HMOT](CARD0).stepgen.01.dirsetup        [JOINT_1]DIRSETUP
setp   [HMOT](CARD0).stepgen.01.dirhold         [JOINT_1]DIRHOLD
setp   [HMOT](CARD0).stepgen.01.steplen         [JOINT_1]STEPLEN
setp   [HMOT](CARD0).stepgen.01.stepspace       [JOINT_1]STEPSPACE
setp   [HMOT](CARD0).stepgen.01.position-scale  [JOINT_1]STEP_SCALE
setp   [HMOT](CARD0).stepgen.01.step_type        0
setp   [HMOT](CARD0).stepgen.01.control-type     1
setp   [HMOT](CARD0).stepgen.01.maxaccel         [JOINT_1]STEPGEN_MAXACCEL
setp   [HMOT](CARD0).stepgen.01.maxvel           [JOINT_1]STEPGEN_MAXVEL

# ---closedloop stepper signals---
net y-pos-cmd    <= joint.1.motor-pos-cmd
net y-vel-cmd    <= joint.1.vel-cmd
net y-output     <= [HMOT](CARD0).stepgen.01.velocity-cmd
net y-pos-fb     <= [HMOT](CARD0).stepgen.01.position-fb
net y-pos-fb     => joint.1.motor-pos-fb
net y-enable     <= joint.1.amp-enable-out
net y-enable     => [HMOT](CARD0).stepgen.01.enable
net ALARM_Y      <=  [HMOT](CARD0).7i76.0.0.input-30
net ALARM_Y      =>  joint.1.amp-fault-in

# ---setup home / limit switch signals---
net max-home-y     =>  joint.1.home-sw-in
net min-y     =>  joint.1.neg-lim-sw-in
net max-home-y     =>  joint.1.pos-lim-sw-in

#*******************
#  AXIS Z JOINT 2
#*******************
setp   pid.z.Pgain     [JOINT_2]P
setp   pid.z.Igain     [JOINT_2]I
setp   pid.z.Dgain     [JOINT_2]D
setp   pid.z.bias      [JOINT_2]BIAS
setp   pid.z.FF0       [JOINT_2]FF0
setp   pid.z.FF1       [JOINT_2]FF1
setp   pid.z.FF2       [JOINT_2]FF2
setp   pid.z.deadband  [JOINT_2]DEADBAND
setp   pid.z.maxoutput [JOINT_2]MAX_OUTPUT
setp   pid.z.error-previous-target true
setp   pid.z.maxerror 0.000500 # This setting is to limit bogus stepgen velocity corrections caused by position feedback sample time jitter.
net z-index-enable  <=> pid.z.index-enable
net z-enable        =>  pid.z.enable
net z-pos-cmd       =>  pid.z.command
net z-pos-fb        =>  pid.z.feedback
net z-output        <=  pid.z.output

# Step Gen signals/setup
setp   [HMOT](CARD0).stepgen.02.dirsetup        [JOINT_2]DIRSETUP
setp   [HMOT](CARD0).stepgen.02.dirhold         [JOINT_2]DIRHOLD
setp   [HMOT](CARD0).stepgen.02.steplen         [JOINT_2]STEPLEN
setp   [HMOT](CARD0).stepgen.02.stepspace       [JOINT_2]STEPSPACE
setp   [HMOT](CARD0).stepgen.02.position-scale  [JOINT_2]STEP_SCALE
setp   [HMOT](CARD0).stepgen.02.step_type        0
setp   [HMOT](CARD0).stepgen.02.control-type     1
setp   [HMOT](CARD0).stepgen.02.maxaccel         [JOINT_2]STEPGEN_MAXACCEL
setp   [HMOT](CARD0).stepgen.02.maxvel           [JOINT_2]STEPGEN_MAXVEL

# ---closedloop stepper signals---
net z-pos-cmd    <= joint.2.motor-pos-cmd
net z-vel-cmd    <= joint.2.vel-cmd
net z-output     <= [HMOT](CARD0).stepgen.02.velocity-cmd
net z-pos-fb     <= [HMOT](CARD0).stepgen.02.position-fb
net z-pos-fb     => joint.2.motor-pos-fb
net z-enable     <= joint.2.amp-enable-out
net z-enable     => [HMOT](CARD0).stepgen.02.enable
net ALARM_Z      <=  [HMOT](CARD0).7i76.0.0.input-29
net ALARM_Z      =>  joint.2.amp-fault-in

# ---setup home / limit switch signals---
net max-home-z     =>  joint.2.home-sw-in
net z-neg-limit     =>  joint.2.neg-lim-sw-in
net max-home-z     =>  joint.2.pos-lim-sw-in


#RMC Rev26 - 4th axis disabled and probe & tool setter
#*******************
#  AXIS A JOINT 3
#*******************

#setp   pid.a.Pgain     [JOINT_3]P
#setp   pid.a.Igain     [JOINT_3]I
#setp   pid.a.Dgain     [JOINT_3]D
#setp   pid.a.bias      [JOINT_3]BIAS
#setp   pid.a.FF0       [JOINT_3]FF0
#setp   pid.a.FF1       [JOINT_3]FF1
#setp   pid.a.FF2       [JOINT_3]FF2
#setp   pid.a.deadband  [JOINT_3]DEADBAND
#setp   pid.a.maxoutput [JOINT_3]MAX_OUTPUT
#setp   pid.a.error-previous-target true
#setp   pid.a.maxerror 0.000500 # This setting is to limit bogus stepgen velocity corrections caused by position feedback sample time jitter.
#net a-index-enable  <=> pid.a.index-enable
#net a-enable        =>  pid.a.enable
#net a-pos-cmd       =>  pid.a.command
#net a-pos-fb        =>  pid.a.feedback
#net a-output        <=  pid.a.output

## Step Gen signals/setup
#setp   [HMOT](CARD0).stepgen.03.dirsetup        [JOINT_3]DIRSETUP
#setp   [HMOT](CARD0).stepgen.03.dirhold         [JOINT_3]DIRHOLD
#setp   [HMOT](CARD0).stepgen.03.steplen         [JOINT_3]STEPLEN
#setp   [HMOT](CARD0).stepgen.03.stepspace       [JOINT_3]STEPSPACE
#setp   [HMOT](CARD0).stepgen.03.position-scale  [JOINT_3]STEP_SCALE
#setp   [HMOT](CARD0).stepgen.03.step_type        0
#setp   [HMOT](CARD0).stepgen.03.control-type     1
#setp   [HMOT](CARD0).stepgen.03.maxaccel         [JOINT_3]STEPGEN_MAXACCEL
#setp   [HMOT](CARD0).stepgen.03.maxvel           [JOINT_3]STEPGEN_MAXVEL

# ---closedloop stepper signals---
#net a-pos-cmd    <= joint.3.motor-pos-cmd
#net a-vel-cmd    <= joint.3.vel-cmd
#net a-output     <= [HMOT](CARD0).stepgen.03.velocity-cmd
#net a-pos-fb     <= [HMOT](CARD0).stepgen.03.position-fb
#net a-pos-fb     => joint.3.motor-pos-fb
#net a-enable     <= joint.3.amp-enable-out
#net a-enable     => [HMOT](CARD0).stepgen.03.enable
#net ALARM_A      <= [HMOT](CARD0).7i76.0.0.input-28
#net ALARM_A      => joint.3.amp-fault-in

## ---setup home / limit switch signals---
#net home-a     =>  joint.3.home-sw-in
#net a-neg-limit     =>  joint.3.neg-lim-sw-in
#net a-pos-limit     =>  joint.3.pos-lim-sw-in