Skip to content

Commit 5e60bed

Browse files
authored
Merge pull request #32 from jtrmal/setup_macros2
Add support for KAMP being treated as moonraker extension and document the process
2 parents c365c4f + 12634ac commit 5e60bed

File tree

4 files changed

+184
-15
lines changed

4 files changed

+184
-15
lines changed

Configuration/Adaptive_Mesh.cfg

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,23 @@ variable_probe_dock_enable: False # Enables/disables the use of a dockable
3030
variable_attach_macro: 'Attach_Probe' # Here is where you define the macro that ATTACHES the probe to the printhead. E.g. 'Attach_Probe'
3131
variable_detach_macro: 'Dock_Probe' # Here is where you define the macro that DETACHES the probe from the printhead. E.g. 'Dock_Probe'
3232

33+
### This section is for those who are using Moonraker's Update Manager for KAMP, or want a more verbose macro. ###
34+
35+
variable_display_parameters: True # Display macro paramters in the console, useful for debugging the SETUP_KAMP_MESHING call, or more verbosity.
36+
3337
gcode:
38+
39+
{% if display_parameters == True %}
40+
{ action_respond_info("led_enable : %d" % (led_enable)) }
41+
{ action_respond_info("status_macro: \'%s\'" % (status_macro)) }
42+
{ action_respond_info("fuzz_enable : %d" % (fuzz_enable)) }
43+
{ action_respond_info("fuzz_min : %f" % (fuzz_min)) }
44+
{ action_respond_info("fuzz_max : %f" % (fuzz_max)) }
45+
{ action_respond_info("probe_dock_enable: %d" % (probe_dock_enable)) }
46+
{ action_respond_info("attach_macro: \'%s\'" % (attach_macro)) }
47+
{ action_respond_info("detach_macro: \'%s\'" % (detach_macro)) }
48+
{% endif %}
49+
3450
{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %}
3551
{% set bed_mesh_min = printer.configfile.settings.bed_mesh.mesh_min %}
3652
{% set bed_mesh_max = printer.configfile.settings.bed_mesh.mesh_max %}
@@ -65,15 +81,15 @@ gcode:
6581
{% set x_max = [ bed_mesh_max[0], x_max + margin_size ] | min %}
6682
{% set y_max = [ bed_mesh_max[1], y_max + margin_size ] | min %}
6783
{% endif %}
68-
84+
6985
{ action_respond_info("Object bounds, clamped to the bed_mesh: {!r}, {!r}".format(
70-
(x_min, y_min),
86+
(x_min, y_min),
7187
(x_max, y_max),
7288
)) }
73-
89+
7490
{% set points_x = (((x_max - x_min) / max_probe_point_distance_x) | round(method='ceil') | int) + 1 %}
7591
{% set points_y = (((y_max - y_min) / max_probe_point_distance_y) | round(method='ceil') | int) + 1 %}
76-
92+
7793
{% if (([points_x, points_y]|max) > 6) %}
7894
{% set algorithm = "bicubic" %}
7995
{% set min_points = 4 %}
@@ -82,14 +98,14 @@ gcode:
8298
{% set min_points = 3 %}
8399
{% endif %}
84100
{ action_respond_info( "Algorithm: {}".format(algorithm)) }
85-
101+
86102
{% set points_x = [points_x, min_points]|max %}
87103
{% set points_y = [points_y, min_points]|max %}
88104
{ action_respond_info( "Points: x: {}, y: {}".format(points_x, points_y) ) }
89105

90106
{% if printer.configfile.settings.bed_mesh.relative_reference_index is defined %}
91107
{% set ref_index = (points_x * points_y / 2) | int %}
92-
{ action_respond_info( "Reference index: {}".format(ref_index) ) }
108+
{ action_respond_info( "Reference index: {}".format(ref_index) ) }
93109
{% else %}
94110
{% set ref_index = -1 %}
95111
{% endif %}
@@ -106,4 +122,18 @@ gcode:
106122

107123
{% if probe_dock_enable == True %}
108124
{detach_macro} # Detach/stow a probe if the probe is stored somewhere outside of the print area
109-
{% endif %}
125+
{% endif %}
126+
127+
[gcode_macro SETUP_KAMP_MESHING]
128+
gcode:
129+
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=display_parameters VALUE={params.DISPLAY_PARAMETERS|default(True)|int}
130+
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=led_enable VALUE={params.LED_ENABLE|default(False)|int}
131+
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=status_macro VALUE='"{params.STATUS_MACRO|default('status_meshing')|string}"'
132+
133+
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=fuzz_enable VALUE={params.FUZZ_ENABLE|default(False)|int}
134+
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=fuzz_min VALUE={params.FUZZ_MIN|default(0)|float}
135+
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=fuzz_max VALUE={params.FUZZ_MAX|default(4)|float}
136+
137+
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=probe_dock_enable VALUE={params.PROBE_DOCK_ENABLE|default(False)|int}
138+
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=attach_macro VALUE='"{params.ATTACH_MACRO|default('Attach_Probe')|string}"'
139+
SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=detach_macro VALUE='"{params.DETACH_MACRO|default('Dock_Probe')|string}"'

Configuration/Line_Purge.cfg

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# ...
88
# max_extrude_cross_section: 5
99

10-
1110
[gcode_macro LINE_PURGE]
1211
description: A purge macro that adapts to be near your actual printed objects
1312

@@ -20,7 +19,23 @@ variable_x_default: 10 # Default X location to purge. If adaptive_e
2019
variable_y_default: 10 # Default Y location to purge. If adaptive_enable is True, this is overwritten
2120
variable_distance_to_object_y: 10 # Y distance in millimeters away from the print area for purging. Must be less than or equal to y_default if adaptive_enable is False
2221

22+
### This section is for those who are using Moonraker's Update Manager for KAMP, or want a more verbose macro. ###
23+
24+
variable_display_parameters: True # Display macro paramters in the console, useful for debugging the SETUP_LINE_PURGE call, or more verbosity.
25+
2326
gcode:
27+
28+
{% if display_parameters == True %}
29+
{ action_respond_info("adaptive_enable : %d" % (adaptive_enable)) }
30+
{ action_respond_info("z_height : %f" % (z_height)) }
31+
{ action_respond_info("purge_amount : %f" % (purge_amount)) }
32+
{ action_respond_info("line_length : %f" % (line_length)) }
33+
{ action_respond_info("flow_rate : %f" % (flow_rate)) }
34+
{ action_respond_info("x_default : %f" % (x_default)) }
35+
{ action_respond_info("y_default : %f" % (y_default)) }
36+
{ action_respond_info("distance_to_object_y : %f" % (distance_to_object_y)) }
37+
{% endif %}
38+
2439
{% if adaptive_enable == True %}
2540
{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %}
2641
{% set x_origin = (all_points | map(attribute=0) | min | default(x_default)) %}
@@ -46,4 +61,16 @@ gcode:
4661
G1 E-.5 F2100 # Retract
4762
G92 E0 # Reset extruder distance
4863
M82 # Absolute extrusion mode
49-
G0 Z{z_height * 2} F{travel_speed} # Z hop
64+
G0 Z{z_height * 2} F{travel_speed} # Z hop
65+
66+
[gcode_macro SETUP_LINE_PURGE]
67+
gcode:
68+
SET_GCODE_VARIABLE MACRO=LINE_PURGE VARIABLE=display_parameters VALUE={params.DISPLAY_PARAMETERS|default(True)|int}
69+
SET_GCODE_VARIABLE MACRO=LINE_PURGE VARIABLE=adaptive_enable VALUE={params.ADAPTIVE_ENABLE|default(True)|int}
70+
SET_GCODE_VARIABLE MACRO=LINE_PURGE VARIABLE=z_height VALUE={params.Z_HEIGHT|default(0.4)|float}
71+
SET_GCODE_VARIABLE MACRO=LINE_PURGE VARIABLE=purge_amount VALUE={params.PURGE_AMOUNT|default(40)|float}
72+
SET_GCODE_VARIABLE MACRO=LINE_PURGE VARIABLE=line_length VALUE={params.LINE_LENGTH|default(50)|float}
73+
SET_GCODE_VARIABLE MACRO=LINE_PURGE VARIABLE=flow_rate VALUE={params.FLOW_RATE|default(12)|float}
74+
SET_GCODE_VARIABLE MACRO=LINE_PURGE VARIABLE=x_default VALUE={params.X_DEFAULT|default(10)|float}
75+
SET_GCODE_VARIABLE MACRO=LINE_PURGE VARIABLE=y_default VALUE={params.Y_DEFAULT|default(10)|float}
76+
SET_GCODE_VARIABLE MACRO=LINE_PURGE VARIABLE=distance_to_object_y VALUE={params.DISTANCE_TO_OBJECT_Y|default(10)|float}

Configuration/Voron_Purge.cfg

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
# This macro will parse information from objects in your gcode to define a min and max area, creating a nearby purge with Voron flair!
44
# For successful purging, you may need to configure:
5-
#
5+
#
66
# [extruder]
77
# ...
88
# max_extrude_cross_section: 5
99

10-
1110
[gcode_macro VORON_PURGE]
1211
description: A purge macro that adapts to be near your actual printed objects
1312

@@ -22,7 +21,25 @@ variable_size: 10 # Size of the logo
2221
variable_distance_to_object_x: 10 # Distance in x to the print area
2322
variable_distance_to_object_y: 10 # Distance in y to the print area
2423

24+
### This section is for those who are using Moonraker's Update Manager for KAMP, or want a more verbose macro. ###
25+
26+
variable_display_parameters: True # Display macro paramters in the console, useful for debugging the SETUP_VORON_PURGE call, or more verbosity.
27+
2528
gcode:
29+
30+
{% if display_parameters == True %}
31+
{ action_respond_info("adaptive_enable : %d" % (adaptive_enable)) }
32+
{ action_respond_info("z_height : %f" % (z_height)) }
33+
{ action_respond_info("tip_distance : %f" % (tip_distance)) }
34+
{ action_respond_info("purge_amount : %f" % (purge_amount)) }
35+
{ action_respond_info("flow_rate : %f" % (flow_rate)) }
36+
{ action_respond_info("x_default : %f" % (x_default)) }
37+
{ action_respond_info("y_default : %f" % (y_default)) }
38+
{ action_respond_info("size : %f" % (size)) }
39+
{ action_respond_info("distance_to_object_x : %f" % (distance_to_object_x)) }
40+
{ action_respond_info("distance_to_object_y : %f" % (distance_to_object_y)) }
41+
{% endif %}
42+
2643
{% if adaptive_enable == True %}
2744
{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %}
2845
{% set x_origin = (all_points | map(attribute=0) | min | default(x_default + distance_to_object_x + size)) - distance_to_object_x - size %}
@@ -61,4 +78,18 @@ gcode:
6178
G1 E-.5 F2100 # Retract
6279
G92 E0 # Reset extruder distance
6380
M82 # Absolute extrusion mode
64-
G0 Z{z_height*2} # Z hop
81+
G0 Z{z_height*2} # Z hop
82+
83+
[gcode_macro SETUP_VORON_PURGE]
84+
gcode:
85+
SET_GCODE_VARIABLE MACRO=VORON_PURGE VARIABLE=display_parameters VALUE={params.DISPLAY_PARAMETERS|default(True)|int}
86+
SET_GCODE_VARIABLE MACRO=VORON_PURGE VARIABLE=adaptive_enable VALUE={params.ADAPTIVE_ENABLE|default(True)|int}
87+
SET_GCODE_VARIABLE MACRO=VORON_PURGE VARIABLE=z_height VALUE={params.Z_HEIGHT|default(0.4)|float}
88+
SET_GCODE_VARIABLE MACRO=VORON_PURGE VARIABLE=tip_distance VALUE={params.TIP_DISTANCE|default(10)|float}
89+
SET_GCODE_VARIABLE MACRO=VORON_PURGE VARIABLE=purge_amount VALUE={params.PURGE_AMOUNT|default(40)|float}
90+
SET_GCODE_VARIABLE MACRO=VORON_PURGE VARIABLE=flow_rate VALUE={params.FLOW_RATE|default(10)|float}
91+
SET_GCODE_VARIABLE MACRO=VORON_PURGE VARIABLE=x_default VALUE={params.X_DEFAULT|default(10)|float}
92+
SET_GCODE_VARIABLE MACRO=VORON_PURGE VARIABLE=y_default VALUE={params.Y_DEFAULT|default(10)|float}
93+
SET_GCODE_VARIABLE MACRO=VORON_PURGE VARIABLE=size VALUE={params.SIZE|default(10)|float}
94+
SET_GCODE_VARIABLE MACRO=VORON_PURGE VARIABLE=distance_to_object_x VALUE={params.DISTANCE_TO_OBJECT_X|default(10)|float}
95+
SET_GCODE_VARIABLE MACRO=VORON_PURGE VARIABLE=distance_to_object_y VALUE={params.DISTANCE_TO_OBJECT_Y|default(10)|float}

README.md

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ Relative Reference Index is a method used in the Klipper firmware to calculate m
194194
</details>
195195
<br>
196196
197+
<!-- Moonraker Setup -->
198+
197199
### I prefer using Moonraker's update manager:
198200
199201
@@ -206,7 +208,88 @@ Relative Reference Index is a method used in the Klipper firmware to calculate m
206208
<p>
207209
</p>
208210
209-
Oops! This is still a work in progress. Check back soon!
211+
# Moonraker Update Manager Setup
212+
213+
The purpose of this setup is to enable updating KAMP by using Moonraker's plugin manager.
214+
This comes at cost of higher complexity of setup, **and** the need to edit an already existing `PRINT_START` Macro.
215+
216+
To begin, `ssh` into your device running klipper and use the following commands:
217+
218+
```bash
219+
cd
220+
git clone https://github.com/kyleisah/Klipper-Adaptive-Meshing-Purging.git
221+
ln -s ~/Klipper-Adaptive-Meshing-Purging/Configuration printer_data/config/KAMP
222+
```
223+
224+
Then, add the following snippet into your `printer.cfg` file: [^1]
225+
```jinja
226+
[include KAMP/*cfg]
227+
```
228+
Alternatively, you can choose which files you wish to include (useful for those who **only** want adaptive purging) by using the following: [^1]
229+
```jinja
230+
[include KAMP/Adaptive_Mesh.cfg]
231+
[include KAMP/Voron_Purge.cfg]
232+
[include KAMP/Line_Purge.cfg]
233+
```
234+
235+
Lastly, add the following snippet to your `moonraker.conf` file: [^1]
236+
237+
```jinja
238+
[update_manager Klipper-Adaptive-Meshing-Purging]
239+
type: git_repo
240+
channel: dev
241+
path: ~/Klipper-Adaptive-Meshing-Purging
242+
origin: https://github.com/kyleisah/Klipper-Adaptive-Meshing-Purging.git
243+
managed_services: klipper
244+
primary_branch: main
245+
```
246+
247+
This should be all that needs to be done for enabling updates via Moonraker's Update Manager! Be sure to restart your firmware and moonraker instance, or reboot your Pi for all changes to take effect. [^1]
248+
249+
⚠️ Please pay special attention to the following, as this is a critical step:
250+
251+
Before using any macros from KAMP when using the moonraker managed method, you have to **SET** the parameters for the macros before they are called, or they will only use the default parameters. You should only have to change your `PRINT_START` once or twice until you have the parameters set how you like them, then you can leave them alone. There is an example provided at the bottom of this section to show you how you can do this.
252+
253+
> For setting up adaptive meshing, you need to call the macro:
254+
>> ```jinja
255+
>> SETUP_KAMP_MESHING [parameters]
256+
>> ```
257+
> For adaptive purging (Voron-logo):
258+
>> ```jinja
259+
>> SETUP_VORON_PURGE [parameters]
260+
>> ```
261+
> For an adaptive purging in a form of a simple line:
262+
>> ```jinja
263+
>> SETUP_LINE_PURGE [parameters]
264+
>> ```
265+
266+
Be sure the calls for `BED_MESH_CALIBRATE` and/or `VORON_PURGE`/`LINE_PURGE` are also included in your `PRINT_START` and are called **AFTER** calling these setup macros.
267+
268+
As for the parameters, you can inspect the individual config files and the macros. You can also add the parameter `DISPLAY_PARAMETERS=1` to either of the SETUP calls and it will print current values (useful for debugging) when calling the actual macros.
269+
After modifying the `PRINT_START` macro, do not forget to restart klipper again. [^1]
270+
271+
Example `PRINT_START`:
272+
```
273+
[gcode_macro PRINT_START]
274+
gcode:
275+
.
276+
.
277+
SETUP_KAMP_MESHING DISPLAY_PARAMETERS=1 LED_ENABLE=1 FUZZ_ENABLE=1
278+
SETUP_VORON_PURGE DISPLAY_PARAMETERS=1 ADAPTIVE_ENABLE=1
279+
.
280+
.
281+
BED_MESH_CLEAR
282+
BED_MESH_CALIBRATE
283+
.
284+
.
285+
VORON_PURGE
286+
```
287+
288+
As you can see, `SETUP_KAMP_MESHING` is setting `LED_ENABLE` and `FUZZ_ENABLE` *before* `BED_MESH_CALIBRATE` is called. The same has also been done using `SETUP_VORON_PURGE`.
289+
290+
<br>
291+
292+
**It is important that the `SETUP` macros are being called *before* the actual macro, otherwise default values are used.**
210293
211294
</details>
212295
<br>
@@ -245,8 +328,6 @@ Solution:
245328
246329
# Adaptive Purging
247330
248-
<br>
249-
250331
## Introduction
251332
Adaptive Purging takes the same secret sauce of Adaptive Meshing, and uses it for a pre-print prime line or purge. So instead of the purge line always being in the same spot of your print bed, the purge will actually be near your print! Some folks find this useful as they can lower the count of lines in their print skirt, or remove it altogether!
252333
<br>

0 commit comments

Comments
 (0)