-
Notifications
You must be signed in to change notification settings - Fork 0
/
purge_arc.cfg
94 lines (87 loc) · 5.38 KB
/
purge_arc.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
[gcode_macro PURGE_ARC]
variable_direction: 'CW' # purge clockwise or counterclockwise (either 'CW' or 'CCW')
variable_start_angle: 180.0 # angle in Degree of start point (0 is at Y_MAX)
variable_end_angle: 0.0 # angle in Degree of end point (0 is at Y_MAX)
variable_edge_offset: 5.0 # offset in mm from edge of bed defined in printer.cfg
variable_purge_speed: 25.0 # purge line printing speed in mm/s
variable_purge_line_height: 0.2 # height of purge line in mm
variable_purge_line_width: 0.6 # width of purge line in mm
variable_z_travel_height: 5.0 # z height for travel moves in mm
variable_travel_speed: 50.0 # travel speed in mm/s
variable_retract_after_purge: 0.25 # retraction in mm after purge line has been printed
variable_z_height_after_purge: 5.0 # retraction in mm after purge line has been printed
variable_retract_speed: 30.0 # retraction speed in mm/s
gcode:
{% set radius = printer.configfile.settings.printer.delta_radius - edge_offset | float %}
{% set start_angle_rads = ((start_angle * 6.283185) / 360) | float %}
{% set end_angle_rads = ((end_angle * 6.283185) / 360) | float %}
{% if start_angle < 0 or start_angle > 360 or end_angle < 0 or end_angle > 360 %}
{ action_raise_error("ERROR: Angles in [gcode_macro PURGE_ARC] must be between 0 and 360 !!!") }
{% endif %}
# calculate start coordinates
{% set sin0 = (start_angle_rads) %}
{% set sin1 = ((start_angle_rads ** 3) / 6) | float %}
{% set sin2 = ((start_angle_rads ** 5) / 120) | float %}
{% set sin3 = ((start_angle_rads ** 7) / 5040) | float %}
{% set sin4 = ((start_angle_rads ** 9) / 362880) | float %}
{% set sin5 = ((start_angle_rads ** 11) / 39916800) | float %}
{% set sin6 = ((start_angle_rads ** 13) / 6227020800) | float %}
{% set sin7 = ((start_angle_rads ** 15) / 1307674368000) | float %}
{% set sin = (-(sin0 - sin1 + sin2 - sin3 + sin4 - sin5 + sin6 - sin7)) | float %}
{% set cos0 = (1) | float %}
{% set cos1 = ((start_angle_rads ** 2) / 2) | float %}
{% set cos2 = ((start_angle_rads ** 4) / 24) | float %}
{% set cos3 = ((start_angle_rads ** 6) / 720) | float %}
{% set cos4 = ((start_angle_rads ** 8) / 40320) | float %}
{% set cos5 = ((start_angle_rads ** 10) / 3628800) | float %}
{% set cos6 = ((start_angle_rads ** 12) / 479001600) | float %}
{% set cos7 = ((start_angle_rads ** 14) / 87178291200) | float %}
{% set cos = (-(cos0 - cos1 + cos2 - cos3 + cos4 - cos5 + cos6 - cos7)) | float %}
{% set start_x = (radius * sin * -1) |round(4) | float %}
{% set start_y = (radius * cos * -1) |round(4) | float %}
# calculate end coordinates
{% set sin0 = (end_angle_rads) %}
{% set sin1 = ((end_angle_rads ** 3) / 6) | float %}
{% set sin2 = ((end_angle_rads ** 5) / 120) | float %}
{% set sin3 = ((end_angle_rads ** 7) / 5040) | float %}
{% set sin4 = ((end_angle_rads ** 9) / 362880) | float %}
{% set sin5 = ((end_angle_rads ** 11) / 39916800) | float %}
{% set sin6 = ((end_angle_rads ** 13) / 6227020800) | float %}
{% set sin7 = ((end_angle_rads ** 15) / 1307674368000) | float %}
{% set sin = (-(sin0 - sin1 + sin2 - sin3 + sin4 - sin5 + sin6 - sin7)) | float %}
{% set cos0 = (1) | float %}
{% set cos1 = ((end_angle_rads ** 2) / 2) | float %}
{% set cos2 = ((end_angle_rads ** 4) / 24) | float %}
{% set cos3 = ((end_angle_rads ** 6) / 720) | float %}
{% set cos4 = ((end_angle_rads ** 8) / 40320) | float %}
{% set cos5 = ((end_angle_rads ** 10) / 3628800) | float %}
{% set cos6 = ((end_angle_rads ** 12) / 479001600) | float %}
{% set cos7 = ((end_angle_rads ** 14) / 87178291200) | float %}
{% set cos = (-(cos0 - cos1 + cos2 - cos3 + cos4 - cos5 + cos6 - cos7)) | float %}
{% set end_x = (radius * sin * -1) |round(4) | float %}
{% set end_y = (radius * cos * -1) |round(4) | float %}
# calculate extrusion amount
{% if clockwise|upper == 'CW' %}
{% set diff_rads = start_angle_rads - end_angle_rads %}
{% else %}
{% set diff_rads = start_angle_rads - end_angle_rads %}
{% endif %}
{% if diff_rads < 0 %} {% set diff_rads = diff_rads + 6.283185 %} {% endif %}
{% if diff_rads > 6.283185 %} {% set diff_rads = diff_rads - 6.283185 %} {% endif %}
{% set purge_line_len = diff_rads * radius %}
{% set purge_line_volume = purge_line_len * purge_line_height * purge_line_width %}
{% set filament_cross_section = printer.configfile.settings.extruder.filament_diameter * printer.configfile.settings.extruder.filament_diameter / 4 %}
{% set extrude_length = purge_line_volume / 3.14 / filament_cross_section %}
# print the pruge line
G0 Z{z_travel_height} F{travel_speed * 60} # lift z to travel height
G0 X{start_x} Y{start_y} F{travel_speed * 60} # move to start of purge line
G0 Z{purge_line_height} F{travel_speed * 60} # lover Z to purge line height
G92 E0 # reset extruder
{% if clockwise|upper == 'CW' %}
G2 X{end_x} Y{end_y} I{start_x * -1} J{start_y * -1} E{extrude_length} F{purge_speed * 60} # purge
{% else %}
G3 X{end_x} Y{end_y} I{start_x * -1} J{start_y * -1} E{extrude_length} F{purge_speed * 60} # purge
{% endif %}
G92 E0 # reset extruder
G1 E{retract_after_purge * -1} F{retract_speed * 60} # retract to prevent oozing
G1 Z1 F{travel_speed * 60} # lift Z