[Home]SpindleOrientation

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

See also: http://wiki.linuxcnc.org/cgi-bin/wiki.pl?SpindleOrient

Here is what i use to get my spindle orientation to work with a coustom Mcode function and also work from ladder output at tool change time. see videos here

http://www.youtube.com/watch?v=UlW1s2BNixo
http://www.youtube.com/watch?v=D6dGYsXAPIU

some values and parts will need to be changed around to sute other machines etc. hope it helps someone as a starting point i have tryed to keep it neat and tidy so a copy and paste will work fine with comments to help along the way.

How it works when a tool change or spindle orientation is requested, the spindle is spun to 200rpm, when at speed the PID is enabled when the Wcomp reeds true for in position, the oriention-finish output becomes true.

known problems. can not stop spindle while in Automode so please do a M05 before using a Mcode to do a spindle orientation. maybe someone can add a proper M19 output? i also found it best to spin the spindle and then try and potion than it is to poition from zero speed if in flux mode you might find it works ok from zero speed.

must add Ladder logic, to show oriention logic steps.

 # Insert this into the ini file for quick and easy changing.

[SPINDLE_0]

 # 500ppr encoder on spindle 
 # INPUT_SCALE=500 ppr x4 (quad) = 2000 ppr
 # 2000/360=5.555* p/degree
INPUT_SCALE = -5.55555556 ORIENT_POS = 78.0
 # COMP FOR ORI POS CHECK + or - 2Deg
WCOMP_MAX = 2.0 WCOMP_MIN = -2.0
 # PID tuning values
MAX_OUTPUT = 300 DEADBAND = 0.0 P = 3 I = 1.0 D = 0.1 FF0 = 0.0 FF1 = 0.1 FF2 = 0.0 BIAS = 0.0 MAXI = 20.0 MAXD = 20.0 MAXERROR = 250.0

HAL File parts

 #Compoents needed.
 #scale0 = Spindle RPM Scale
 #scale1 = Spindle ABS
 #scale6 = Spindle Deg to Rev
 #scale7 spindle load
 addf scale.0 servo-thread
 addf scale.6 servo-thread
 addf scale.7 servo-thread
 addf scale.1 servo-thread 

 setp scale.1.gain 0.16667
 #spindle speed gain
 #pwm/speed=1/6000=0.0001667
 #6k
 setp scale.0.gain 0.000166667

 #load abs comp make spindle pos
 loadrt abs count=3
 addf abs.0 servo-thread
 addf abs.1 gui-thread
 addf abs.2 servo-thread

 #convert spindle speed to s32
 loadrt conv_float_s32 count=1
 addf conv-float-s32.0 servo-thread
 #covert spindle s32 to float
 loadrt conv_s32_float count=1
 addf conv-s32-float.0 servo-thread 

 #comp for sp ori
 loadrt wcomp count=1
 addf wcomp.0 servo-thread 

 loadrt mux2 count=1
 addf mux2.0 servo-thread
 loadrt mux4 count=1
 addf mux4.0 servo-thread

 loadrt tristate_bit count=1
 addf tristate-bit.0 servo-thread

 #Spindle Section 

 #set scale and pwm
 setp hm2_5i20.0.encoder.03.scale [SPINDLE_0]INPUT_SCALE
 setp hm2_[HOSTMOT2](BOARD).0.pwmgen.03.output-type 3
 setp hm2_[HOSTMOT2](BOARD).0.gpio.020.invert_output true

 #set spindle encoder type
 setp hm2_[HOSTMOT2](BOARD).0.encoder.03.counter-mode 0
 setp hm2_[HOSTMOT2](BOARD).0.encoder.03.filter 1
 setp hm2_[HOSTMOT2](BOARD).0.encoder.03.index-invert 0
 setp hm2_[HOSTMOT2](BOARD).0.encoder.03.index-mask 0
 setp hm2_[HOSTMOT2](BOARD).0.encoder.03.index-mask-invert 0 

 setp pid.4.Pgain [SPINDLE_0]P
 setp pid.4.Igain [SPINDLE_0]I
 setp pid.4.Dgain [SPINDLE_0]D
 setp pid.4.bias [SPINDLE_0]BIAS
 setp pid.4.FF0 [SPINDLE_0]FF0
 setp pid.4.FF1 [SPINDLE_0]FF1
 setp pid.4.FF2 [SPINDLE_0]FF2
 setp pid.4.deadband [SPINDLE_0]DEADBAND
 #limit spindle speed 
 setp pid.4.maxoutput [SPINDLE_0]MAX_OUTPUT
 #set ori postion
 setp pid.4.command [SPINDLE_0]ORIENT_POS 

 # prevent integrator windup at the beginning of an orient
 # after running the spindle for a long time.  The error is
 # very high before the first index happens.
 setp pid.4.maxerrorI [SPINDLE_0]MAXI
 setp pid.4.maxerrorD [SPINDLE_0]MAXD
 setp pid.4.maxerror [SPINDLE_0]MAXERROR

 #spindle sync

 net ori-index <= classicladder.0.out-17 

 #spindle sync
 newsig tristate.index bit
 sets tristate.index true
 net tristate.index => tristate-bit.0.in 
 net spindle-index <= tristate-bit.0.out
 net ori-index => tristate-bit.0.enable
 net spindle-index <= motion.spindle-index-enable
 net spindle-index <=> hm2_[HOSTMOT2](BOARD).0.encoder.03.index-enable 

 net spindle-velocity motion.spindle-speed-in <= hm2_[HOSTMOT2](BOARD).0.encoder.03.velocity
 net spindle-deg <= hm2_[HOSTMOT2](BOARD).0.encoder.03.position 

 #convert degrees to revs for spindle sync moves
 #1/360=0.002777778
 #deg*0.002777778=revs
 setp scale.6.gain 0.002777778
 net spindle-deg <= scale.6.in
 net spinde-revs scale.6.out => motion.spindle-revs

 #ori
 net spindle-deg => pid.4.feedback 

 # check position error with window comparator
 # set a +/- 2 degree window
 setp wcomp.0.min [SPINDLE_0]WCOMP_MIN
 setp wcomp.0.max  [SPINDLE_0]WCOMP_MAX
 net sp-orient-pos-err wcomp.0.in <= pid.4.error
 net ori-finish classicladder.0.in-17 <= wcomp.0.out 

 #spindle enable
 net spindle-enable-out classicladder.0.out-04 => hm2_[HOSTMOT2](BOARD).0.pwmgen.03.enable
 net spindle-enable-in motion.spindle-on => classicladder.0.in-16  

 #for pyvcp
 net spindle-velocity => abs.1.in
 net spindle-s-abs abs.1.out => scale.1.in
 net spindle-s-abs-out <= scale.1.out 

 #spindle enable 
 net spindle-enable-out => hm2_[HOSTMOT2](BOARD).0.gpio.046.out
 net Satspeed classicladder.0.in-20 <= hm2_[HOSTMOT2](BOARD).0.gpio.036.in_not
 net Satspeed2 motion.spindle-at-speed <= classicladder.0.out-15
 net spindle-ok classicladder.0.in-34 <= hm2_[HOSTMOT2](BOARD).0.gpio.032.in_not

 net spindle-float conv-float-s32.0.in <= motion.spindle-speed-out
 net spindle-s32 classicladder.0.s32in-03 <= conv-float-s32.0.out
 net spindle-s32-out conv-s32-float.0.in <= classicladder.0.s32out-03
 net spindle-rpm-in <= conv-s32-float.0.out

 net ori-enable pid.4.enable <= classicladder.0.out-14
 #output
 net sp-orient-rpm-cmd pid.4.output

 # select between normal speed and orient speed
 # based on ori-enable (M119) command
 net sp-orient-rpm-cmd => mux2.0.in1
 net spindle-rpm-in => mux2.0.in0
 net ori-enable => mux2.0.sel
 # output of mux is desired spindle RPM
 net spindle-rpm-out mux2.0.out => scale.0.in
 net spindle-speed-DAC scale.0.out => hm2_[HOSTMOT2](BOARD).0.pwmgen.03.value

 Change Mods:
 please note any updates or changed made here to the above.

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited August 4, 2017 3:28 pm by Andypugh (diff)
Search:
Published under a Creative Commons License