( spindle-encoder.ngc ) ( by Lawrence Glaister VE7IT ) ( Sept 15 2007 ) ( lerman - thankyou for named variables and owords.... very cool ) ( Cut from arborite stock with 0.049" endmill. ) ( This encoder ring mounts on the lathe spindle drive pulley. ) ( Ring encoder provides A,B,Z phases using 3 H21TLB slot sensors. ) ( The H21TLB sensor use 5v and can directly drive parallel port pins. ) ( The sensor apeture is 0.035", so I used double that for the slot length ) ( to allow for some runout on mounting the ring. ) ( The main constraint is that the main track opto has to be able to physically ) ( read the inner track... reaching over the outer index track ) ( To preview what it will look like, set _endmill_dia = 0.0 below. ) ( With a high speed spindle you may be able to cut to depth in 1 pass. ) ( This example only cuts to -0.020... this can be edited and the program ) ( rerun to do 2 passes ) (======================================================================) (============================= Subroutines ============================) ( cuts a circle at request diameter around x,y to requested depth ) o100 sub (Subroutine to do a circle) ( P1=X center P2=Y center P3-diameter P4=depth P5=feedrate ) g0 z#<_safe_Z> g0 x[#1-[#3/2]] y#2 g1 F[#5/2] z#4 g2 F[#5] x[#1-[#3/2]] y#2 i[#3/2] j0 g0 z#<_safe_Z> o100 endsub (======================================================================) (=================== Define Constants/Variables =======================) #<_endmill_dia> = 0.049 ( endmill diameter ) #<_safe_Z> = 0.100 ( safe Z height ) #<_Zcut> = -0.020 ( Z depth to cut encoder elements ) #<_feedrate> = 5.0 ( cutting feedrate ) ( define characteristics of encoder and index tracks ) #<_main_track_dia> = 7.250 ( diameter of main signal track ) #<_index_track_dia> = [#<_main_track_dia> + 0.140] ( diameter of index track ) #<_inside_cutout> = 5.500 ( diameter of interior cutout == inside of pulley) #<_outside_cutout> = 7.525 ( diameter of exterior cutout ~= enough space for tracks) #<_encoder_cycles> = 90 ( number of slots to cut 180 * 4 == 1/2 degreee resolution) #<_slotlen> = 0.070 ( finished slot length for 1 encoder element ~= sensor aperture + runout ) ( define 3 params for the mounting arrangement ) #<_mount_circle> = 6.000 ( mounting bolt circle diameter ) #<_mount_holes> = 6 ( number of holes to mill for mounting bolts ) #<_mount_hdia> = 0.150 ( sloppy #6 or a #8 bolt ) #<_PI> = 3.14159 #<_endmill_rad> = [#<_endmill_dia>/2.0] ( endmill radius ) #<_encoder_theta>=[360.0/#<_encoder_cycles>] ( angular step around circle - degrees) (======================================================================) (========================= Start of Main Code =========================) G20 G90 G64 P.002 G0 z#<_safe_Z> G0 X0 Y0 m0(DEBUG,spindle_encoder.ngc: #<_encoder_cycles> cycle disk uses #<_endmill_dia> dia endmill, material top,center at 0,0,0 ... unpause[S] when ready) ( cut the main encoder slots ) ( compute angular size of cutter at cutting extremes ) # = [#<_main_track_dia> - #<_slotlen> + #<_endmill_dia>] # = [#<_main_track_dia> + #<_slotlen> - #<_endmill_dia>] # = [#<_endmill_dia>*360.0/[#*#<_PI>]] # = [#<_endmill_dia>*360.0/[#*#<_PI>]] # = [#<_encoder_theta>/2.0 ] # = #<_encoder_cycles> ( counter for cutting this many slots ) # = 360 ( starting angle to cut ) ( rough check to see if cutter dia and disk resolution are feasible ) o5 if [# GT #] (print,icutter_deg= #, slot_deg= #) (DEBUG, Unable to cut encoder because #<_endmill_dia> cutter is too large for a #<_encoder_cycles> cycle #<_main_track_dia> dia disk) m2 o5 endif ( check to see if we can machine mounting holes ) o7 if [ #<_mount_hdia> LE #<_endmill_dia> ] (print,Unable to machine mounting holes as #<_endmill_dia> endmill is too big to cut #<_mount_hdia> dia holes ) (DEBUG,Unable to machine mounting holes as #<_endmill_dia> endmill is too big to cut #<_mount_hdia> dia holes ) m2 o7 endif ( main loop to cut encoder slots around disk ) o10 do # = [#<_main_track_dia>/2.0 * cos[#]] ( x center of slot ) # = [#<_main_track_dia>/2.0 * sin[#]] ( y center of slot ) g0 z#<_safe_Z> g0 x[#] y[#] ( do a cut to the final depth at the cw inner corner of the slot ) # = [# - [#/2.0] + [#/2.0]] # = [#/2.0 * cos[#]] # = [#/2.0 * sin[#]] g1 x[#] y[#] z[#<_Zcut>] f[#<_feedrate>/2.0] ( decend to cut depth ) # = [# + [#/2.0] - [#/2.0]] # = [#/2.0 * cos[#]] # = [#/2.0 * sin[#]] # = SQRT[#*# + #*#] g3 x[#] y[#] r[#] f[#<_feedrate>] ( cut inside edge of slot ) # = [# + [#/2.0] - [#/2.0]] # = [#/2.0 * cos[#]] # = [#/2.0 * sin[#]] g1 x[#] y[#] ( cut ccw edge of slot ) # = [# - [#/2.0] + [#/2.0]] # = [#/2.0 * cos[#]] # = [#/2.0 * sin[#]] # = SQRT[#*# + #*#] g2 x[#] y[#] r[#] ( cut outer edge of slot ) # = [# - [#/2.0] + [#/2.0]] # = [#/2.0 * cos[#]] # = [#/2.0 * sin[#]] g1 x[#] y[#] ( cut back to inner cw point of slot ) g0 z#<_safe_Z> # = [# -1] # = [# - #<_encoder_theta>] o10 while [# GT 0] ( cutout index hole) ( compute angular size of cutter at cutting extremes ) # = [#<_index_track_dia> - #<_slotlen> + #<_endmill_dia>] # = [#<_index_track_dia> + #<_slotlen> - #<_endmill_dia>] # = [#<_endmill_dia>*360.0/[#*#<_PI>]] # = [#<_endmill_dia>*360.0/[#*#<_PI>]] # = [#<_encoder_theta>/2.0 ] # = 360 ( starting angle to cut ) # = [#<_index_track_dia>/2.0 * cos[#]] ( x center of slot ) # = [#<_index_track_dia>/2.0 * sin[#]] ( y center of slot ) g0 z#<_safe_Z> g0 x[#] y[#] ( do a cut to the final depth at the cw inner corner of the slot ) # = [# - [#/2.0] + [#/2.0]] # = [#/2.0 * cos[#]] # = [#/2.0 * sin[#]] g1 x[#] y[#] z[#<_Zcut>] f[#<_feedrate>/2.0] ( decend to cut depth ) # = [# + [#/2.0] - [#/2.0]] # = [#/2.0 * cos[#]] # = [#/2.0 * sin[#]] # = SQRT[#*# + #*#] g3 x[#] y[#] r[#] f[#<_feedrate>] ( cut inside edge of slot ) # = [# + [#/2.0] - [#/2.0]] # = [#/2.0 * cos[#]] # = [#/2.0 * sin[#]] g1 x[#] y[#] ( cut ccw edge of slot ) # = [# - [#/2.0] + [#/2.0]] # = [#/2.0 * cos[#]] # = [#/2.0 * sin[#]] # = SQRT[#*# + #*#] g2 x[#] y[#] r[#] ( cut outer edge of slot ) # = [# - [#/2.0] + [#/2.0]] # = [#/2.0 * cos[#]] # = [#/2.0 * sin[#]] g1 x[#] y[#] ( cut back to inner cw point of slot ) g0 z#<_safe_Z> ( mill some mounting bolt holes ) # = #<_mount_holes> # = 0 o20 do # = [#<_mount_circle>/2.0 * cos[#]] # = [#<_mount_circle>/2.0 * sin[#]] ( X ) ( Y ) ( Diameter ) ( Depth ) ( Feed ) o100 call [#] [#] [#<_mount_hdia>-#<_endmill_dia>] [#<_Zcut>] [#<_feedrate>] ( one mounting hole ) # = [# + [ 360.0/#<_mount_holes>] ] # = [# -1] o20 while [ # GT 0 ] ( cutout encoder ring ) ( X ) ( Y ) ( Diameter ) ( Depth ) ( Feed ) o100 call [0.0] [0.0] [#<_inside_cutout>-#<_endmill_dia>] [#<_Zcut>] [#<_feedrate>] ( interior cutout ) o100 call [0.0] [0.0] [#<_outside_cutout>+#<_endmill_dia>] [#<_Zcut>] [#<_feedrate>] ( exterior cutout ) M2