# 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

return d / (180.0 / math.pi)

angle = (angle + fudge_angle) % 360
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')

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,b_xy,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,b_xy,0.0,0.0,feed))
of.write('G02 X%1.4f Y%1.4f R%1.4f F%d \n' % (b_xy,b_xy,slot_id,feed))

#
of.write('G01  X%1.4f Y%1.4f F%d\n' % (c_xy,c_xy, feed))

# cut outside arc
#
of.write('G03 X%1.4f Y%1.4f R%1.4f  F%d \n' % (d_xy,d_xy,slot_od,feed))

# cut back to the beginning
#
of.write('G01  X%1.4f Y%1.4f F%d\n' % (a_xy,a_xy, 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')

# 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,-fan_xy,fan_radius,feed))
of.write('G02 X%1.4f Y%1.4f R%1.4f F%d \n' % (fan_xy,fan_xy,fan_radius,feed))

home()

of.write('m2\n%\n')
of.close```