All pastes #1490017 Raw Edit

motion.hal

public text v1 · immutable
#1490017 ·published 2009-07-09 20:23 UTC
rendered paste body
# ########################################
# Firmware files are in /lib/firmware/hm2/7i43/
# Must symlink the hostmot2 firmware directory of sanbox to
# /lib/firmware before running EMC2...
# sudo ln -s $HOME/emc2-sandbox/src/hal/drivers/mesa-hostmot2/firmware /lib/firmware/hm2
#
# See also:
# <http://www.linuxcnc.org/docs/devel/html/man/man9/hostmot2.9.html#config%20modparam>
# and http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?HostMot2
#
# #####################################################################


# ###################################
# Core EMC/HAL Loads
# ###################################



setp hm2_[HOSTMOT2](BOARD).0.pwmgen.pwm_frequency 40000

setp hm2_[HOSTMOT2](BOARD).0.watchdog.timeout_ns 10000000


# ################################################
# THREADS
# ################################################


       

# ######################################################
# Axis-of-motion Specific Configs (not the GUI)
# ######################################################


# ################
# X [0] Axis
# ################

# axis enable chain
newsig emcmot.00.enable bit
sets emcmot.00.enable FALSE
net emcmot.00.enable => pid.0.enable
net emcmot.00.enable => hm2_[HOSTMOT2](BOARD).0.pwmgen.05.enable
net emcmot.00.enable <= axis.0.amp-enable-out 

# encoder feedback
setp hm2_[HOSTMOT2](BOARD).0.encoder.05.counter-mode 0
setp hm2_[HOSTMOT2](BOARD).0.encoder.05.filter 1
setp hm2_[HOSTMOT2](BOARD).0.encoder.05.index-invert 1
setp hm2_[HOSTMOT2](BOARD).0.encoder.05.index-mask 0
setp hm2_[HOSTMOT2](BOARD).0.encoder.05.index-mask-invert 0

net xinex-en axis.0.index-enable hm2_[HOSTMOT2](BOARD).0.encoder.05.index-enable
net xhome axis.0.home-sw-in

setp  hm2_[HOSTMOT2](BOARD).0.encoder.05.scale  819.2
net motor.00.pos-fb hm2_[HOSTMOT2](BOARD).0.encoder.05.position => pid.0.feedback
net motor.00.pos-fb => axis.0.motor-pos-fb #push copy back to Axis GUI

# set PID loop gains from inifile
setp pid.0.Pgain [AXIS_0]P
setp pid.0.Igain [AXIS_0]I
setp pid.0.Dgain [AXIS_0]D
setp pid.0.bias [AXIS_0]BIAS
setp pid.0.FF0 [AXIS_0]FF0
setp pid.0.FF1 [AXIS_0]FF1
setp pid.0.FF2 [AXIS_0]FF2
setp pid.0.deadband [AXIS_0]DEADBAND
setp pid.0.maxoutput [AXIS_0]MAX_VELOCITY

# position command signals
setp hm2_[HOSTMOT2](BOARD).0.pwmgen.05.output-type 1 #pwm on pin1, dir on pin2
setp hm2_[HOSTMOT2](BOARD).0.pwmgen.05.scale  -120.0

net emcmot.00.pos-cmd axis.0.motor-pos-cmd => pid.0.command
net motor.00.command  pid.0.output  =>  hm2_[HOSTMOT2](BOARD).0.pwmgen.05.value


# ################
# Z [2] Axis
# ################

# axis enable chain
newsig emcmot.04.enable bit
sets emcmot.04.enable FALSE
net emcmot.04.enable => pid.2.enable
net emcmot.04.enable => hm2_[HOSTMOT2](BOARD).0.pwmgen.04.enable
net emcmot.04.enable <= axis.2.amp-enable-out 

#homing
net zinex-en axis.2.index-enable hm2_[HOSTMOT2](BOARD).0.encoder.04.index-enable


# encoder feedback
setp hm2_[HOSTMOT2](BOARD).0.encoder.04.counter-mode 0
setp hm2_[HOSTMOT2](BOARD).0.encoder.04.filter 1
setp hm2_[HOSTMOT2](BOARD).0.encoder.04.index-invert 0
setp hm2_[HOSTMOT2](BOARD).0.encoder.04.index-mask 0
setp hm2_[HOSTMOT2](BOARD).0.encoder.04.index-mask-invert 0

setp  hm2_[HOSTMOT2](BOARD).0.encoder.04.scale  200
net motor.04.pos-fb hm2_[HOSTMOT2](BOARD).0.encoder.04.position => pid.2.feedback
net motor.04.pos-fb => axis.2.motor-pos-fb #push copy back to Axis GUI

# set PID loop gains from inifile
setp pid.2.Pgain [AXIS_2]P
setp pid.2.Igain [AXIS_2]I
setp pid.2.Dgain [AXIS_2]D
setp pid.2.bias [AXIS_2]BIAS
setp pid.2.FF0 [AXIS_2]FF0
setp pid.2.FF1 [AXIS_2]FF1
setp pid.2.FF2 [AXIS_2]FF2
setp pid.2.deadband [AXIS_2]DEADBAND
setp pid.2.maxoutput [AXIS_2]MAX_VELOCITY

# position command signals
setp hm2_[HOSTMOT2](BOARD).0.pwmgen.04.output-type 1 #pwm on pin1, dir on pin2
setp hm2_[HOSTMOT2](BOARD).0.pwmgen.04.scale  -80.0

net emcmot.04.pos-cmd axis.2.motor-pos-cmd => pid.2.command
net motor.04.command  pid.2.output  =>  hm2_[HOSTMOT2](BOARD).0.pwmgen.04.value

# ################
# Spindle
# ################


setp hm2_[HOSTMOT2](BOARD).0.pwmgen.02.output-type 1 #pwm on pin1, dir on pin2
setp hm2_[HOSTMOT2](BOARD).0.pwmgen.02.scale  -1

net spin-enable <= motion.spindle-on => hm2_[HOSTMOT2](BOARD).0.pwmgen.02.enable

#read spindle speed
setp hm2_[HOSTMOT2](BOARD).0.encoder.02.counter-mode 0
setp hm2_[HOSTMOT2](BOARD).0.encoder.02.filter 1
setp hm2_[HOSTMOT2](BOARD).0.encoder.02.index-invert 0
setp hm2_[HOSTMOT2](BOARD).0.encoder.02.index-mask 0
setp hm2_[HOSTMOT2](BOARD).0.encoder.02.index-mask-invert 0
setp hm2_[HOSTMOT2](BOARD).0.encoder.02.scale  4000

net spindle-position motion.spindle-revs hm2_[HOSTMOT2](BOARD).0.encoder.02.position
net spin_idx motion.spindle-index-enable hm2_[HOSTMOT2](BOARD).0.encoder.02.index-enable

net spindle-actual rps2rpm.in0 motion.spindle-speed-in hm2_[HOSTMOT2](BOARD).0.encoder.02.velocity
setp rps2rpm.in1 60   #convert rps to rpm
net spin-actual-rpm abs.1.in rps2rpm.out

net spindle-scaled-abs spin-lpf.in abs.1.out
setp spin-lpf.gain 0.01 #smooth spindle display
net spindle_display spin-lpf.out

#at speed and spindle stationary
setp spin-near0.difference 35 #within 35rpm
setp spin-near0.in1 0
net spin-actual-rpm spin-near0.in2
net spin-stationary spin-near0.out

setp spin-nearspeed.difference 20 #should really be scaled per gear
net spin-actual-rpm spin-nearspeed.in1
net spin-cmd spin-nearspeed.in2
net spin-atspeed spin-nearspeed.out
net spin-safetomove motion.spindle-at-speed

#limit acceleration
#if acceleration is too high the inverter faults
#do this before scaling because chuck inertia is the
#main problem

setp spin-alimit.maxv 200 #rpm/sec
net spin-cmd spin-alimit.in motion.spindle-speed-out
net spin-cmd-alimited spin-alimit.out

#limit speeds in each gear
net spin-cmd-alimited abs.0.in
net spin-abs abs.0.out
net spin-cw abs.0.sign

setp spin-limit1.min 14 #14rpm
setp spin-limit1.max 275 #275rpm
setp spin-limit2.min 40 #40rpm
setp spin-limit2.max 795  #795rpm
setp spin-limit3.min 125 #125rpm
setp spin-limit3.max 2500  #2500rpm

net spin-abs spin-limit1.in spin-limit2.in spin-limit3.in


net spin_limited1 spinmux2.in1 spin-limit1.out #gear 1
net spin_limited2 spinmux2.in2 spin-limit2.out #gear 2
net spin_limited3 spinmux2.in3 spin-limit3.out #gear 3

net spin-mux0 spinmux2.sel0
net spin-mux1 spinmux2.sel1

net spin-limited spinmux2.out

#scale commanded spindle speed for each gear
setp spinmux1.in1 0.0034743 #gear 1
setp spinmux1.in2 0.0012 #gear 2
setp spinmux1.in3 0.0003844 #gear 3
net spin-mux0 spinmux1.sel0
net spin-mux1 spinmux1.sel1

net spin-scale spingain.in1 spinmux1.out
net spin-limited spingain.in0
net spin-scaled spingain.out hm2_[HOSTMOT2](BOARD).0.pwmgen.02.value