Machining Mars Etek Backplate with Python

      No Comments on Machining Mars Etek Backplate with Python

To get the slots and the screws just right I used a Sherline tabletop CNC milling machine to cut the screw slots and openings. Only a little rework and it came out pretty good.

Being new to machine a g-codes and also being a programmer I cobbled up some python to calculate the angles and emit the g-code used by the linuxcnc program. The code is below:

 

import math
 
# G20 is inch units
 
preamble = """
%
N10
G17
G20
"""
 
toolsize = 0.200
depth = 0.200
plunge_rate = 2
feed = 3
 
# angle offset to rotate motor from normal
#
fudge_angle = 0
 
def deg_to_rad(d) :
return d / (180.0 / math.pi)
 
def vector(angle, radius) :
angle = (angle + fudge_angle) % 360
angle = deg_to_rad(angle)
y = math.cos(angle) * radius
x = math.sin(angle) * radius
return (x,y)
 
def transition(xy) :
of.write('G0 X%1.4f Y%1.4f Z0\n' % xy)
 
def plunge() :
of.write('G01 Z-%1.4f F%d\n'(depth, plunge_rate))
 
def home() :
"lift the tool and transition home"
 
of.write('G00 Z%1.4f\n' % depth)
of.write('G00 X0.0 Y0.0\n\n')
 
shroud_radius = 3.5
screw_arc = 4
def screw_slot(angle) :
"cut slot for the screw"
 
a_xy = vector(angle - screw_arc, shroud_radius)
b_xy = vector(angle + screw_arc, shroud_radius)
 
transition(a_xy)
plunge()
 
# Cut the circle
#
 
of.write('G02 X%1.4f Y%1.4f R%1.4f F%d \n'(b_xy[0],b_xy[1],shroud_radius,feed))
home()
 
of = open("backplate.nc","w")
of.write(preamble)
 
# Cut the electrical slot
#
of.write('(Electrical slot)\n')
 
slot_id = 2.2 + toolsize
slot_od = 3.75 - toolsize
start_angle = 116.0
end_angle = 156.0
 
a_xy = vector(start_angle, slot_id)
b_xy = vector(end_angle, slot_id)
c_xy = vector(end_angle, slot_od)
d_xy = vector(start_angle, slot_od)
 
# transition to the start
#
transition(a_xy)
plunge()
 
# cut inside arc
#
##of.write('G02 X%1.4f Y%1.4f I%1.4f J%1.4f F%d \n' % (b_xy[0],b_xy[1],0.0,0.0,feed))
of.write('G02 X%1.4f Y%1.4f R%1.4f F%d \n'(b_xy[0],b_xy[1],slot_id,feed))
 
# cut to outside radius
#
of.write('G01  X%1.4f Y%1.4f F%d\n'(c_xy[0],c_xy[1], feed))
 
# cut outside arc
#
of.write('G03 X%1.4f Y%1.4f R%1.4f  F%d \n'(d_xy[0],d_xy[1],slot_od,feed))
 
# cut back to the beginning
#
of.write('G01  X%1.4f Y%1.4f F%d\n'(a_xy[0],a_xy[1], feed))
 
home()
 
of.write('(Slot 2)\n')
screw_slot(97)
of.write('(Slot 3)\n')
screw_slot(236)
 
# Case bolt
#
of.write('(Case bolt hole)\n')
 
bolt_xy = vector(45, 4.0)
transition(bolt_xy)
plunge()
home()
 
of.write('(Slot 1)\n')
screw_slot(-15)
 
home()
 
# Cut the fan circle
#
of.write('(Cut fan circle)\n')
 
fan_radius = 2.0 - toolsize
fan_xy = vector(0, fan_radius)
 
# transition to the start
#
transition(fan_xy)
 
# Cut the circle
#
plunge()
of.write('G02 X%1.4f Y%1.4f R%1.4f F%d \n'(fan_xy[0],-fan_xy[1],fan_radius,feed))
of.write('G02 X%1.4f Y%1.4f R%1.4f F%d \n'(fan_xy[0],fan_xy[1],fan_radius,feed))
 
home()
 
of.write('m2\n%\n')
of.close