-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoonraker_obico_macros.cfg
146 lines (129 loc) · 8.23 KB
/
moonraker_obico_macros.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
## !!! This file is read-only. Maybe the used editor indicates
[pause_resume]
## Usage: _OBICO_LAYER_CHANGE [CURRENT_LAYER=<layer#>] [MINX=<x min object>] [MAXX=<x max object>] [MINY=<y min object>] [MAXY=<y max object>]
[gcode_macro _OBICO_LAYER_CHANGE]
description:Run a scan across the current print area
variable_first_layer_scan_retract_length: 6 # retract length [mm], used at scan start
variable_first_layer_scan_retract_speed: 30 # retract speed [mm/sec], used at scan start
variable_first_layer_scan_cooldown_temp: 170 # The temperature to cool down to before scanning
variable_first_layer_scan_resume_speed: 300 # resume move speed [mm/sec]
variable_first_layer_scan_enabled: True # enables the scan process [True/False]
variable_first_layer_scan_stepover: 10 # scan step [mm] for the Y direction
variable_first_layer_scan_speed: 10 # scan move speed [mm/sec]
variable_first_layer_scan_zhop: 4 # zhop [mm] during scan
variable_first_layer_scan_zhop_speed: 15 # zhop move speed [mm/sec]
variable_verbose: False # Enable debug prints [True/False]
## do not change these
variable_current_layer: -1
variable_first_layer_scanning: False
variable_wait: {'resume': "RESUME", 'absolute_coordinates': True, 'absolute_extrude': True, 'e': 0.0, 'previous_temp': 0}
gcode:
##### detect if a custom user PAUSE or RESUME macro is defined #####
{% set pause_macro = "PAUSE" if printer.configfile.settings['gcode_macro pause'] is not defined
else printer.configfile.settings['gcode_macro pause'].rename_existing %}
{% set resume_macro = "RESUME" if printer.configfile.settings['gcode_macro resume'] is not defined
else printer.configfile.settings['gcode_macro resume'].rename_existing %}
##### evaluate input parameter CURRENT_LAYER #####
{% set current_layer_default = printer.print_stats.info.current_layer if printer.print_stats.info.current_layer is not none else -1 %}
{% set current_layer = params.CURRENT_LAYER|default(current_layer_default)|int %}
##### evaluate input parameter MINX, MINY, MAXX, MAXY #####
{% set polygon_points = printer.exclude_object.objects|map(attribute='polygon')|sum(start=[]) if printer.exclude_object is defined else [] %}
{% set min_x = params.MINX|default(polygon_points|map(attribute=0)|min|default(printer.toolhead.axis_minimum.x))|float %}
{% set min_y = params.MINY|default(polygon_points|map(attribute=1)|min|default(printer.toolhead.axis_minimum.y))|float %}
{% set max_x = params.MAXX|default(polygon_points|map(attribute=0)|max|default(printer.toolhead.axis_maximum.x))|float %}
{% set max_y = params.MAXY|default(polygon_points|map(attribute=1)|max|default(printer.toolhead.axis_maximum.y))|float %}
##### calc needed Y steps #####
{% set stepoverCount = ((max_y - min_y) / first_layer_scan_stepover|float)|round(method='ceil')|int %}
##### end of definitions #####
{% if verbose %} RESPOND PREFIX='OBICO DEBUG:' MSG='{"Layer %d" % (current_layer)}' {% endif %}
SET_GCODE_VARIABLE MACRO=_OBICO_LAYER_CHANGE VARIABLE=current_layer VALUE={current_layer}
{% if first_layer_scan_enabled and current_layer == 2 %}
SET_GCODE_VARIABLE MACRO=_OBICO_LAYER_CHANGE VARIABLE=first_layer_scanning VALUE=True
## store information for restore
{% set wait_dic = {'resume' : resume_macro,
'absolute_coordinates': printer.gcode_move.absolute_coordinates,
'absolute_extrude' : printer.gcode_move.absolute_extrude,
'e' : printer.gcode_move.gcode_position.e,
'previous_temp' : printer.extruder.target} %}
SET_GCODE_VARIABLE MACRO=_OBICO_LAYER_CHANGE VARIABLE=wait VALUE="{wait_dic}"
## retract and move up
{% if verbose %} RESPOND PREFIX='OBICO DEBUG:' MSG="Prepare scanning" {% endif %}
{% if verbose %} RESPOND PREFIX='OBICO DEBUG:' MSG='{"Scan Coordinates: Min:[%.3f:%.3f] Max:[%.3f:%.3f]" % (min_x,min_y,max_x,max_y)}' {% endif %}
{% if printer[printer.toolhead.extruder].can_extrude %}
{% if verbose %} RESPOND PREFIX='OBICO DEBUG:' MSG='{"Retract %.1fmm filament" % first_layer_scan_retract_length|abs}' {% endif %}
M83 ; insure relative extrusion
G0 E-{first_layer_scan_retract_length|abs} F{first_layer_scan_retract_speed|float * 60}
{% endif %}
G91
G0 Z{first_layer_scan_zhop|abs} F{first_layer_scan_zhop_speed|float * 60}
## Turn on the fan and lower temperature before scanning
M106 S255
{% if verbose %} RESPOND PREFIX='OBICO DEBUG:' MSG='{"Fan on and lowering temperature to %.1f" % first_layer_scan_cooldown_temp}' {% endif %}
M104 S{first_layer_scan_cooldown_temp}
M109 S{first_layer_scan_cooldown_temp} ; Wait for temperature to reach 170
{pause_macro} ; call the basic klipper PAUSE gcode
## scan the bed
{% if verbose %} RESPOND PREFIX='OBICO DEBUG:' MSG="Start scanning" {% endif %}
## call the delay macro to get a message and resume after scanning
UPDATE_DELAYED_GCODE ID=_WAIT_OBICO_LAYER_CHANGE DURATION=1.0
G90
G0 X{min_x} Y{min_y} F{first_layer_scan_resume_speed|float * 60}
{% for ystep in range(stepoverCount) %}
G0 Y{min_y + first_layer_scan_stepover|float * ystep} F{first_layer_scan_speed|float * 60}
G0 X{max_x if ystep % 2 == 0 else min_x} F{first_layer_scan_speed|float * 60}
{% endfor %}
{% if verbose %} RESPOND PREFIX='OBICO DEBUG:' MSG="Finish scanning" {% endif %}
SET_GCODE_VARIABLE MACRO=_OBICO_LAYER_CHANGE VARIABLE=first_layer_scanning VALUE=False
{% endif %}
[delayed_gcode _WAIT_OBICO_LAYER_CHANGE]
gcode:
{% set lc_macro = printer['gcode_macro _OBICO_LAYER_CHANGE'] %}
{% if lc_macro.first_layer_scanning %}
## still waiting
{% if lc_macro.verbose %} RESPOND PREFIX='OBICO DEBUG:' MSG="Waiting for first layer scan..." {% endif %}
UPDATE_DELAYED_GCODE ID=_WAIT_OBICO_LAYER_CHANGE DURATION=1.0
{% else %}
## Turn off the fan and resume and unretract
M107
{% if lc_macro.verbose %} RESPOND PREFIX='OBICO DEBUG:' MSG="Fan off and resume print" {% endif %}
{% if lc_macro.verbose %} RESPOND PREFIX='OBICO DEBUG:' MSG='{"Call %s VELOCITY=%.1f" % (lc_macro.wait.resume, lc_macro.first_layer_scan_resume_speed)}' {% endif %}
{lc_macro.wait.resume} VELOCITY={lc_macro.first_layer_scan_resume_speed} ; call the basic klipper RESUME gcode
G91
G0 Z-{lc_macro.first_layer_scan_zhop|abs} F{lc_macro.first_layer_scan_zhop_speed|float * 60}
{% if printer[printer.toolhead.extruder].can_extrude %}
{% set first_layer_scan_unretract_length = lc_macro.first_layer_scan_retract_length + 0.5 %} ; unretract a bit more
{% if lc_macro.verbose %} RESPOND PREFIX='OBICO DEBUG:' MSG='{"Extrude %.1fmm filament" % first_layer_scan_unretract_length|abs}' {% endif %}
M83
G0 E{first_layer_scan_unretract_length|abs} F{lc_macro.first_layer_scan_retract_speed|float * 60}
{% endif %}
## Restore temperature after scanning
M104 S{lc_macro.wait.previous_temp}
M109 S{lc_macro.wait.previous_temp} ; Wait for the previous temperature to be reached
{% if lc_macro.verbose %} RESPOND PREFIX='OBICO DEBUG:' MSG='{"Heating back up to previous temperature"}' {% endif %}
## restore movement and extruder system
{% if lc_macro.wait.absolute_coordinates %} G90 {% endif %}
{% if lc_macro.wait.absolute_extrude %}
M82
G92 E{lc_macro.wait.e} ; restore the e value in absolute mode
{% endif %}
{% endif %}
[gcode_macro OBICO_LINK_STATUS]
description:Link to Obico server
variable_one_time_passcode: ''
variable_one_time_passlink: ''
variable_is_linked: False
gcode:
{action_respond_info('Obico one_time_passcode: {}'.format(one_time_passcode))}
{action_respond_info('Obico one_time_passlink: {}'.format(one_time_passlink))}
{action_respond_info('Obico is_linked: {}'.format(is_linked))}
{% if not is_linked and one_time_passcode != '' %}
M117 Code: {one_time_passcode}
{% else %}
M117 Obico linked
{% endif %}
[gcode_macro _OBICO_RELINK]
description:Re-link to Obico server
gcode:
{action_respond_info('WARNING: Re-link to Obico server')}
{action_call_remote_method("obico_remote_event", event_name='relink_obico', message='')}
{action_respond_info('WARNING: relink_obico requested')}