|
|
@ -5,30 +5,32 @@ import bezier, math
|
|
|
|
|
|
|
|
|
|
|
|
def triangulate_lengths(settings, dest_xy):
|
|
|
|
def triangulate_lengths(settings, dest_xy):
|
|
|
|
|
|
|
|
|
|
|
|
# get the desired length of the left pulley wire
|
|
|
|
left_pulley_position = (settings.left_pulley_x_offset, -settings.pulley_y_droop)
|
|
|
|
b = (settings.left_pulley_x_offset + (settings.pulley_diameter/2) + dest_xy[0])
|
|
|
|
right_pulley_position = (settings.right_pulley_x_offset + settings.canvas_x, -settings.pulley_y_droop)
|
|
|
|
a = dest_xy[1] + settings.pulley_y_droop
|
|
|
|
|
|
|
|
desired_left_line_length = math.sqrt(pow(a, 2) + pow(b, 2))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# get the desired length of the right pulley wire
|
|
|
|
right_squared_x = pow(right_pulley_position[0] - dest_xy[0], 2)
|
|
|
|
b = (settings.right_pulley_x_offset - (settings.pulley_diameter/2) + dest_xy[0])
|
|
|
|
right_squared_y = pow(right_pulley_position[1] - dest_xy[1], 2)
|
|
|
|
a = dest_xy[1] + settings.pulley_y_droop
|
|
|
|
|
|
|
|
desired_right_line_length = math.sqrt(pow(a, 2) + pow(b, 2))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return desired_left_line_length, desired_right_line_length
|
|
|
|
left_squared_x = pow(left_pulley_position[0] - dest_xy[0], 2)
|
|
|
|
|
|
|
|
left_squared_y = pow(left_pulley_position[1] - dest_xy[1], 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
right_pulley_length = math.sqrt(right_squared_x + right_squared_y)
|
|
|
|
|
|
|
|
left_pulley_length = math.sqrt(left_squared_x + left_squared_y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return left_pulley_length, right_pulley_length
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def untriangulate_lengths(settings, x, y):
|
|
|
|
def untriangulate_lengths(settings, x, y):
|
|
|
|
result = [0, 0]
|
|
|
|
result = [0, 0]
|
|
|
|
|
|
|
|
|
|
|
|
if x > 0:
|
|
|
|
r0 = x
|
|
|
|
result[0] = (settings.distance_between_centers * settings.distance_between_centers - y * y + x * x) / (2 * x)
|
|
|
|
r1 = y
|
|
|
|
try:
|
|
|
|
r2 = settings.distance_between_centers
|
|
|
|
result[1] = math.sqrt(settings.distance_between_centers * settings.distance_between_centers - result[0] * result[0])
|
|
|
|
|
|
|
|
except:
|
|
|
|
a = (pow(r0, 2) - pow(r1, 2) + pow(r2, 2)) / (2 * r2)
|
|
|
|
result[1] = 10
|
|
|
|
h = math.sqrt(pow(r0, 2) - pow(a, 2))
|
|
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
return a, h
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Svg2GcodeConverter:
|
|
|
|
class Svg2GcodeConverter:
|
|
|
@ -40,14 +42,16 @@ class Svg2GcodeConverter:
|
|
|
|
# First cycle base case flag
|
|
|
|
# First cycle base case flag
|
|
|
|
self.started = False
|
|
|
|
self.started = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
starting_xy = triangulate_lengths(self.settings, (self.settings.canvas_x/2, 0))
|
|
|
|
|
|
|
|
|
|
|
|
self.gcode_preamble = '''
|
|
|
|
self.gcode_preamble = '''
|
|
|
|
G91 ; Set to relative mode for the initial pen lift
|
|
|
|
G91 ; Set to relative mode for the initial pen lift
|
|
|
|
G1 Z1 ; Lift head by 1
|
|
|
|
G1 Z1 ; Lift head by 1
|
|
|
|
G0 F{1} ; Set the feed rate
|
|
|
|
G0 F{1} ; Set the feed rate
|
|
|
|
G1 Z{0} ; Move the pen to just above the paper
|
|
|
|
G1 Z{0} ; Move the pen to just above the paper
|
|
|
|
G90
|
|
|
|
G90
|
|
|
|
G92 X337.87 Y372.36
|
|
|
|
G92 X{2} Y{3}
|
|
|
|
'''.format(1, self.settings.speed)
|
|
|
|
'''.format(1, self.settings.speed, starting_xy[0], starting_xy[1])
|
|
|
|
|
|
|
|
|
|
|
|
self.gcode_end = '''
|
|
|
|
self.gcode_end = '''
|
|
|
|
G1 Z{0} F7000 ; Raise the pen
|
|
|
|
G1 Z{0} F7000 ; Raise the pen
|
|
|
@ -155,6 +159,7 @@ class Svg2GcodeConverter:
|
|
|
|
#gcode += "G1 X{:.3f} Y{:.3f}\n".format(start_x, start_y)
|
|
|
|
#gcode += "G1 X{:.3f} Y{:.3f}\n".format(start_x, start_y)
|
|
|
|
|
|
|
|
|
|
|
|
lengths = triangulate_lengths(self.settings, (start_x, start_y))
|
|
|
|
lengths = triangulate_lengths(self.settings, (start_x, start_y))
|
|
|
|
|
|
|
|
gcode += "; Setting down tip at beginning of line ({}, {})\n".format(start_x, start_y)
|
|
|
|
gcode += "G1 X{:.3f} Y{:.3f}\n".format(lengths[0], lengths[1])
|
|
|
|
gcode += "G1 X{:.3f} Y{:.3f}\n".format(lengths[0], lengths[1])
|
|
|
|
gcode += "G1 Z{:.3f} \n".format(0)
|
|
|
|
gcode += "G1 Z{:.3f} \n".format(0)
|
|
|
|
|
|
|
|
|
|
|
@ -162,13 +167,17 @@ class Svg2GcodeConverter:
|
|
|
|
x = i[0][0]
|
|
|
|
x = i[0][0]
|
|
|
|
y = i[1][0]
|
|
|
|
y = i[1][0]
|
|
|
|
tmp_len = triangulate_lengths(self.settings, (x * scale, y * scale))
|
|
|
|
tmp_len = triangulate_lengths(self.settings, (x * scale, y * scale))
|
|
|
|
|
|
|
|
gcode += "; Continuing the line ({}, {})\n".format(x * scale, y * scale)
|
|
|
|
gcode += "G1 X{:.3f} Y{:.3f}\n".format(tmp_len[0], tmp_len[1])
|
|
|
|
gcode += "G1 X{:.3f} Y{:.3f}\n".format(tmp_len[0], tmp_len[1])
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(part, Line):
|
|
|
|
if isinstance(part, Line):
|
|
|
|
start_len = triangulate_lengths(self.settings, (start_x, start_y))
|
|
|
|
start_len = triangulate_lengths(self.settings, (start_x, start_y))
|
|
|
|
end_len = triangulate_lengths(self.settings, (end_x, end_y))
|
|
|
|
end_len = triangulate_lengths(self.settings, (end_x, end_y))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gcode += "; Setting down tip at beginning of line ({}, {})\n".format(start_x, start_y)
|
|
|
|
gcode += "G1 X{:.3f} Y{:.3f}\n".format(start_len[0], start_len[1])
|
|
|
|
gcode += "G1 X{:.3f} Y{:.3f}\n".format(start_len[0], start_len[1])
|
|
|
|
gcode += "G1 Z{:.3f} \n".format(0)
|
|
|
|
gcode += "G1 Z{:.3f} \n".format(0)
|
|
|
|
|
|
|
|
gcode += "; Moving tip to the end of the line ({}, {})\n".format(end_x, end_y)
|
|
|
|
gcode += "G1 X{:.3f} Y{:.3f}\n".format(end_len[0], end_len[1])
|
|
|
|
gcode += "G1 X{:.3f} Y{:.3f}\n".format(end_len[0], end_len[1])
|
|
|
|
|
|
|
|
|
|
|
|
gcode += self.gcode_end
|
|
|
|
gcode += self.gcode_end
|
|
|
|