Skip to content

Instantly share code, notes, and snippets.

@ChipCE
Last active April 11, 2024 11:44
Show Gist options
  • Save ChipCE/95fdbd3c2f3a064397f9610f915f7d02 to your computer and use it in GitHub Desktop.
Save ChipCE/95fdbd3c2f3a064397f9610f915f7d02 to your computer and use it in GitHub Desktop.
Klipper bed mesh on print area only macro install guide

READ THIS FIRST

Adaptive bed mesh is merged into klipper master branch. You can use this feature without this custom macro. Official klipper adaptive bed mesh

Klipper mesh on print area only install guide

What this macro do

  • This macro will dynamically changing the bed mesh area based on the size of the parts will be printed. The fw will only probe on the area that the part will be printed (plus mesh_area_offset value)

Setup guide

  • (1) Add the following macro to your printer config, this will replace the default BED_MESH_CALIBRATE command.
[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_BASE
; gcode parameters
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
; the clearance between print area and probe area 
variable_mesh_area_offset : 5.0
; number of sample per probe point
variable_probe_samples : 2
; minimum probe count
variable_min_probe_count : 4
; scale up the probe count, should be 1.0 ~ < variable_max_probe_count/variable_min_probe_count
variable_probe_count_scale_factor : 1.0
; enable preference index
variable_enable_reference_index : False
gcode:
    {% if params.AREA_START and params.AREA_END %}
        {% set bedMeshConfig = printer["configfile"].config["bed_mesh"] %}
        {% set safe_min_x = bedMeshConfig.mesh_min.split(",")[0]|float %}
        {% set safe_min_y = bedMeshConfig.mesh_min.split(",")[1]|float %}
        {% set safe_max_x = bedMeshConfig.mesh_max.split(",")[0]|float %}
        {% set safe_max_y = bedMeshConfig.mesh_max.split(",")[1]|float %}

        {% set area_min_x = params.AREA_START.split(",")[0]|float %}
	{% set area_min_y = params.AREA_START.split(",")[1]|float %}
	{% set area_max_x = params.AREA_END.split(",")[0]|float %}
	{% set area_max_y = params.AREA_END.split(",")[1]|float %}

	{% if bedMeshConfig.probe_count.split(",")|length == 2 %}
            {% set meshPointX = bedMeshConfig.probe_count.split(",")[0]|int %}
            {% set meshPointY = bedMeshConfig.probe_count.split(",")[1]|int %}
        {% else %}
            {% set meshPointX = bedMeshConfig.probe_count.split(",")[0]|int %}
            {% set meshPointY = bedMeshConfig.probe_count.split(",")[0]|int %}
        {% endif %}

	{% set meshMaxPointX = meshPointX %}
	{% set meshMaxPointY = meshPointY %}


        {% if (area_min_x < area_max_x) and (area_min_y < area_max_y) %}
            {% if area_min_x - mesh_area_offset >=  safe_min_x %}
                {% set area_min_x = area_min_x - mesh_area_offset %}
            {% else %}
                {% set area_min_x = safe_min_x %}
            {% endif %}

            {% if area_min_y - mesh_area_offset >=  safe_min_y %}
                {% set area_min_y = area_min_y - mesh_area_offset %}
            {% else %}
                {% set area_min_y = safe_min_y %}
            {% endif %}

            {% if area_max_x + mesh_area_offset <=  safe_max_x %}
                {% set area_max_x = area_max_x + mesh_area_offset %}
            {% else %}
                {% set area_max_x = safe_max_x %}
            {% endif %}

            {% if area_max_y + mesh_area_offset <=  safe_max_y %}
                {% set area_max_y = area_max_y + mesh_area_offset %}
            {% else %}
                {% set area_max_y = safe_max_y %}
            {% endif %}

            {% set meshPointX = (meshPointX * (area_max_x - area_min_x) / (safe_max_x - safe_min_x) * probe_count_scale_factor)|round(0)|int %}
            {% if meshPointX < min_probe_count %}
                {% set meshPointX = min_probe_count %}
            {% endif %}
	    {% if meshPointX > meshMaxPointX %}
                {% set meshPointX = meshMaxPointX %}
            {% endif %}

            {% set meshPointY = (meshPointY * (area_max_y -area_min_y ) / (safe_max_y - safe_min_y) * probe_count_scale_factor )|round(0)|int %}
            {% if meshPointY < min_probe_count %}
                {% set meshPointY = min_probe_count %}
            {% endif %}
	    {% if meshPointY > meshMaxPointY %}
                {% set meshPointY = meshMaxPointY %}
            {% endif %}

            {% set algorithm = "bicubic" %}
	    {% if "algorithm" in bedMeshConfig %}
	        {% set algorithm = bedMeshConfig.algorithm %}
            {% endif %}
            {% if meshPointX >=7 or meshPointY >=7 %}
                {% set algorithm = "bicubic" %}
            {% endif %}

            {% if enable_reference_index %}
                {% set referenceIndex = (meshPointX * meshPointY / 2 - 1 )|round(0)|int %}
                BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} samples={probe_samples|int} algorithm={algorithm} relative_reference_index={referenceIndex}
            {% else %}
                BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} samples={probe_samples|int} algorithm={algorithm}
            {% endif %}
        {% else %}
            BED_MESH_CALIBRATE_BASE
        {% endif %}
    {% else %}
        BED_MESH_CALIBRATE_BASE
    {% endif %}
  • (2) Go to slicer setting and replace the old bed mesh gcode the following command.

Prusa Slicer
BED_MESH_CALIBRATE AREA_START={first_layer_print_min[0]},{first_layer_print_min[1]} AREA_END={first_layer_print_max[0]},{first_layer_print_max[1]}

Ideal maker
BED_MESH_CALIBRATE AREA_START={print_pos_min_x},{print_pos_min_y} AREA_END={print_pos_max_x},{print_pos_max_y}

Cura slicer
BED_MESH_CALIBRATE AREA_START=%MINX%,%MINY% AREA_END=%MAXX%,%MAXY%

*(Cura slicer plugin) To make the macro to work in Cura slicer, you need to install the post process plugin click here to download (based on frankbags's script)
- In cura menu Help -> Show configuration folder.
- Copy the python script from the above link in to scripts folder.
- Restart Cura
- In cura menu Extensions -> Post processing -> Modify G-Code and select Klipper print area mesh

For user using single command START_PRINT

  • (*) If you use single command start gcode like START_PRINT BED_TEMP={material_bed_temperature_layer_0} EXTRUDER_TEMP={material_print_temperature_layer_0} .You might need to add parameter parsing to BED_MESH_CALIBRATE inside START_PRINT. This is an example, also check my macro sample
[gcode_macro START_PRINT]
variable_parameter_EXTRUDER_TEMP: 190
variable_parameter_BED_TEMP: 60
; gcode parameters for area bed mesh
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
gcode:
    # preheat, homing, etc
    BED_MESH_CALIBRATE AREA_START={params.AREA_START|default("0,0")} AREA_END={params.AREA_END|default("0,0")}
    # the rest of your start macro here

And you will need to change Slicer start gcode to this

  • Cura: START_PRINT EXTRUDER_TEMP={material_print_temperature_layer_0} BED_TEMP={material_bed_temperature_layer_0} AREA_START=%MINX%,%MINY% AREA_END=%MAXX%,%MAXY%
  • Prusa slicer: START_PRINT EXTRUDER_TEMP=[first_layer_temperature] BED_TEMP=[first_layer_bed_temperature] AREA_START={first_layer_print_min[0]},{first_layer_print_min[1]} AREA_END={first_layer_print_max[0]},{first_layer_print_max[1]}

change logs

  • 2022/07/21
    • Added force lagrange algorithm for mesh with lower than 3 points
    • Added enable_reference_index config flag

The code does not work?

  • I will try to help if possible, you will have to post ALL of your configs, your slicer start gcode and your sliced gcode.
  • If I'm cannot or too slow to respose, our discord members might help you. Check our discord here
@kubark42
Copy link

kubark42 commented Sep 20, 2022

@panik988 @Lecso11, et al:
There are two things I had to do to get this to work with Klicky.

  1. Place the below into a file called bed_mesh_print_area.cfg.
[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_BASE
; gcode parameters
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
; the clearance between print area and probe area 
variable_mesh_area_offset : 5.0
; number of sample per probe point
variable_probe_samples : 2
; minimum probe count
variable_min_probe_count : 3
; scale up the probe count, should be 1.0 ~ < variable_max_probe_count/variable_min_probe_count
variable_probe_count_scale_factor : 1.0
; enable preference index
variable_enable_reference_index : False

variable_mesh_delta : 25                   ## distance between points
variable_x_mesh_max : 7                    ## max points on x-axis
variable_y_mesh_max : 7                    ## max points on y-axis

gcode:

    _CheckProbe action=query
	G90
    Attach_Probe

	{% if params.AREA_START and params.AREA_END %}
	## get [bed_mesh] config parameters
		{% set bedMeshConfig = printer["configfile"].config["bed_mesh"] %}
		{% set safe_min_x = bedMeshConfig.mesh_min.split(",")[0]|float %}
		{% set safe_min_y = bedMeshConfig.mesh_min.split(",")[1]|float %}
		{% set safe_max_x = bedMeshConfig.mesh_max.split(",")[0]|float %}
		{% set safe_max_y = bedMeshConfig.mesh_max.split(",")[1]|float %}
	## get print area min/max from slicer gcode
		{% set area_min_x = params.AREA_START.split(",")[0]|float %}
		{% set area_min_y = params.AREA_START.split(",")[1]|float %}
		{% set area_max_x = params.AREA_END.split(",")[0]|float %}
		{% set area_max_y = params.AREA_END.split(",")[1]|float %}
	## set probing area
		{% if area_min_x - mesh_area_offset >=  safe_min_x %}
			{% set area_min_x = area_min_x - mesh_area_offset %}
			{% else %}
			{% set area_min_x = safe_min_x %}
		{% endif %}
		{% if area_min_y - mesh_area_offset >=  safe_min_y %}
			{% set area_min_y = area_min_y - mesh_area_offset %}
			{% else %}
			{% set area_min_y = safe_min_y %}
		{% endif %}
		{% if area_max_x + mesh_area_offset <=  safe_max_x %}
			{% set area_max_x = area_max_x + mesh_area_offset %}
			{% else %}
			{% set area_max_x = safe_max_x %}
		{% endif %}
		{% if area_max_y + mesh_area_offset <=  safe_max_y %}
			{% set area_max_y = area_max_y + mesh_area_offset %}
			{% else %}
			{% set area_max_y = safe_max_y %}
		{% endif %}
	## set probe counts
		{% set meshPointX = ((area_max_x - area_min_x) / mesh_delta + 1)|round(0)|int %}
		{% if meshPointX < 3 %}
			{% set meshPointX = 3 %}
			{% elif meshPointX > x_mesh_max %}
			{% set meshPointX = x_mesh_max %}
		{% endif %}
		{% set meshPointY = ((area_max_y - area_min_y) / mesh_delta + 1)|round(0)|int %}
		{% if meshPointY < 3 %}
			{% set meshPointY = 3 %}
			{% elif meshPointY > y_mesh_max %}
			{% set meshPointY = y_mesh_max %}
		{% endif %}
	## check for invalid mesh
		{% if meshPointX > 5 %}
			{% if meshPointY == 3 %}  # 7x3 mesh invalid for bicubic
			{% set meshPointY = 5 %}  # set 7x5 mesh
			{% endif %}
		{% endif %}
		{% if meshPointY > 5 %}
			{% if meshPointX == 3 %}  # 3x7 mesh invalid for bicubic
			{% set meshPointX = 5 %}  # set 5x7 mesh
			{% endif %}
		{% endif %}
	## set new reference index point
		{% set referenceIndex = (meshPointX * meshPointY / 2 - 1 )|round(0)|int %}
	## send bed mesh parameters
		M117 probe_count={meshPointX},{meshPointY}
		BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} relative_reference_index={referenceIndex} 
	{% else %}
	BED_MESH_CALIBRATE_BASE
	{% endif %}

    Dock_Probe
  1. Place the below into klicky-probe.cfg.
[include ./bed_mesh_print_area.cfg]             # Bounding box for mesh https://gist.github.com/ChipCE/95fdbd3c2f3a064397f9610f915f7d02?permalink_comment_id=4119897#gistcomment-4119897

You can test with, e.g., BED_MESH_CALIBRATE AREA_START=100,100 AREA_END=200,200

@chainbreaker2012
Copy link

Quick question reguarding the relative_reference_index would thee be a way to do a macro for taking mesh lowest point and using that as the relative reference index? Or is that already taken care of in this?

@locki-cz
Copy link

Is possible do it without changes in slicer?

@kubark42
Copy link

kubark42 commented Sep 21, 2022

@locki-cz you can test manually with BED_MESH_CALIBRATE AREA_START=50,50 AREA_END=100,100. This will do a mesh across a square bounded by (50,50) and (100,100) You'll have to set the bounding box yourself, though, since it's not coming from the slicer.

@locki-cz
Copy link

locki-cz commented Oct 5, 2022

I followed this manual but i am not able figureou what is wrong :(

21:02:24 Klipper state: Disconnect
21:02:24 FIRMWARE_RESTART
21:02:08 Internal error on command:"PRINT_START"
21:02:08 Internal error on command:"BED_MESH_CALIBRATE"
21:02:08 Internal error on command:"BED_MESH_CALIBRATE_BASE"

image

@dnahas
Copy link

dnahas commented Oct 11, 2022

To enforce an odd number of probe points, I added the following, BEFORE the {% set algorithm = "lagrange" %} line. **This (lazy) placement can increase an even max points variable.

{% if meshPointX is divisibleby 2 %}
     {% set meshPointX = meshPointX + 1 %}
{% endif %}
{% if meshPointY is divisibleby 2 %}
     {% set meshPointY = meshPointY + 1 %}
{% endif %}

@ChipCE Thank you for you effort!!

@datapaganism
Copy link

Is there any possible way to increase the object area and add a purge line?

@ChipCE
Copy link
Author

ChipCE commented Oct 21, 2022

@datapaganism Yes, its possible but

  • this macro is a override of the original command and it should do just that
  • Each machine have it's purge line position, length and direction. It's hard to make one to work for all.

A simple hack that cam make it work on your machine: save area_min_x, area_min_y, area_max_x, area_max_y to some where(with saved variable or set gcode variable value) and use that as preference for your purge line gcode/macro

@ChipCE
Copy link
Author

ChipCE commented Oct 21, 2022

@dnahas Thank you!
My small machine actually have max possible probe count 6x6 so i might want to keep the even probe count. I have ideal to fix all the algorithm and probe count problem. I will try to move my lazy ass and fix that in the next few days.

@dnahas
Copy link

dnahas commented Oct 22, 2022

Is there any possible way to increase the object area and add a purge line? @datapaganism

For RatRig RatOS I changed the following PRIME_LINE macro lines (I didnt see the need to save it).

From:

  G1 X{printer.toolhead.axis_minimum.x + 5} Y{printer.toolhead.axis_minimum.y + 10} F{speed}
  G1 Y{printer.toolhead.axis_minimum.y + 80} E16 F1200
  G1 Y{printer.toolhead.axis_minimum.y + 100} F{speed}

To:

  G1 X{printer.bed_mesh.mesh_min[0]|float} Y{printer.bed_mesh.mesh_min[1]|float} F{speed}
  G1 Y{printer.bed_mesh.mesh_min[1]|float + 80} E16 F1200
  G1 Y{printer.bed_mesh.mesh_min[1]|float + 100} F{speed}

*This is my lazy code that does not provide any check for out side of safe area.

Also see
printer.bed_mesh.profiles.XXXXXX.mesh_params.min_y
printer.configfile.save_config_pending_items['XXXXXX'].min_y

@pjaxed
Copy link

pjaxed commented Oct 29, 2022

Thank you @ChipCE and all contributors. I now have this working with my Klicky probe setup. One issue left for me to work though is the Z Offset which is now off. Any pointers where to look?

@5P4P
Copy link

5P4P commented Oct 29, 2022

Thank you @ChipCE and all contributors. I now have this working with my Klicky probe setup. One issue left for me to work though is the Z Offset which is now off. Any pointers where to look?

This works great on my Voron 2.4r2 https://github.com/protoloft/klipper_z_calibration

@pjaxed
Copy link

pjaxed commented Oct 29, 2022 via email

@xdased14x
Copy link

xdased14x commented Nov 1, 2022

@panik988 @Lecso11, et al: There are two things I had to do to get this to work with Klicky.

  1. Place the below into a file called bed_mesh_print_area.cfg.
[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_BASE
; gcode parameters
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
; the clearance between print area and probe area 
variable_mesh_area_offset : 5.0
; number of sample per probe point
variable_probe_samples : 2
; minimum probe count
variable_min_probe_count : 3
; scale up the probe count, should be 1.0 ~ < variable_max_probe_count/variable_min_probe_count
variable_probe_count_scale_factor : 1.0
; enable preference index
variable_enable_reference_index : False

variable_mesh_delta : 25                   ## distance between points
variable_x_mesh_max : 7                    ## max points on x-axis
variable_y_mesh_max : 7                    ## max points on y-axis

gcode:

    _CheckProbe action=query
	G90
    Attach_Probe

	{% if params.AREA_START and params.AREA_END %}
	## get [bed_mesh] config parameters
		{% set bedMeshConfig = printer["configfile"].config["bed_mesh"] %}
		{% set safe_min_x = bedMeshConfig.mesh_min.split(",")[0]|float %}
		{% set safe_min_y = bedMeshConfig.mesh_min.split(",")[1]|float %}
		{% set safe_max_x = bedMeshConfig.mesh_max.split(",")[0]|float %}
		{% set safe_max_y = bedMeshConfig.mesh_max.split(",")[1]|float %}
	## get print area min/max from slicer gcode
		{% set area_min_x = params.AREA_START.split(",")[0]|float %}
		{% set area_min_y = params.AREA_START.split(",")[1]|float %}
		{% set area_max_x = params.AREA_END.split(",")[0]|float %}
		{% set area_max_y = params.AREA_END.split(",")[1]|float %}
	## set probing area
		{% if area_min_x - mesh_area_offset >=  safe_min_x %}
			{% set area_min_x = area_min_x - mesh_area_offset %}
			{% else %}
			{% set area_min_x = safe_min_x %}
		{% endif %}
		{% if area_min_y - mesh_area_offset >=  safe_min_y %}
			{% set area_min_y = area_min_y - mesh_area_offset %}
			{% else %}
			{% set area_min_y = safe_min_y %}
		{% endif %}
		{% if area_max_x + mesh_area_offset <=  safe_max_x %}
			{% set area_max_x = area_max_x + mesh_area_offset %}
			{% else %}
			{% set area_max_x = safe_max_x %}
		{% endif %}
		{% if area_max_y + mesh_area_offset <=  safe_max_y %}
			{% set area_max_y = area_max_y + mesh_area_offset %}
			{% else %}
			{% set area_max_y = safe_max_y %}
		{% endif %}
	## set probe counts
		{% set meshPointX = ((area_max_x - area_min_x) / mesh_delta + 1)|round(0)|int %}
		{% if meshPointX < 3 %}
			{% set meshPointX = 3 %}
			{% elif meshPointX > x_mesh_max %}
			{% set meshPointX = x_mesh_max %}
		{% endif %}
		{% set meshPointY = ((area_max_y - area_min_y) / mesh_delta + 1)|round(0)|int %}
		{% if meshPointY < 3 %}
			{% set meshPointY = 3 %}
			{% elif meshPointY > y_mesh_max %}
			{% set meshPointY = y_mesh_max %}
		{% endif %}
	## check for invalid mesh
		{% if meshPointX > 5 %}
			{% if meshPointY == 3 %}  # 7x3 mesh invalid for bicubic
			{% set meshPointY = 5 %}  # set 7x5 mesh
			{% endif %}
		{% endif %}
		{% if meshPointY > 5 %}
			{% if meshPointX == 3 %}  # 3x7 mesh invalid for bicubic
			{% set meshPointX = 5 %}  # set 5x7 mesh
			{% endif %}
		{% endif %}
	## set new reference index point
		{% set referenceIndex = (meshPointX * meshPointY / 2 - 1 )|round(0)|int %}
	## send bed mesh parameters
		M117 probe_count={meshPointX},{meshPointY}
		BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} relative_reference_index={referenceIndex} 
	{% else %}
	BED_MESH_CALIBRATE_BASE
	{% endif %}

    Dock_Probe
  1. Place the below into klicky-probe.cfg.
[include ./bed_mesh_print_area.cfg]             # Bounding box for mesh https://gist.github.com/ChipCE/95fdbd3c2f3a064397f9610f915f7d02?permalink_comment_id=4119897#gistcomment-4119897

You can test with, e.g., BED_MESH_CALIBRATE AREA_START=100,100 AREA_END=200,200

tried this and i get a full bed mesh every time i run a test print. the part i'm using is small and i move it around the bed
i committed out the the klicky bed mesh cfg,not sure what i'm doing wrong

@pjaxed
Copy link

pjaxed commented Nov 3, 2022

Thank you for feedback. Issue was with the code generated by my slicer. All is working as it should.

@C0NN0R92
Copy link

C0NN0R92 commented Nov 5, 2022

i keep getting Error evaluating 'gcode_macro BED_MESH_CALIBRATE:gcode': jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'bed_mesh' can anyone help me

@ChipCE
Copy link
Author

ChipCE commented Nov 5, 2022

i keep getting Error evaluating 'gcode_macro BED_MESH_CALIBRATE:gcode': jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'bed_mesh' can anyone help me

seem like "bed_mesh" is missing in your original config

@ga-rr-is-on
Copy link

ga-rr-is-on commented Nov 17, 2022

To get this to work on IdeaMaker using single Start_Print
(including temp parameters to help those that are new to using Klipper macros and parameters within the Slicer G-Code). If you can copy and paste, you don't need to modify anything.
Copy and paste the BED_MESH_CALIBRATE macro as per instructions above to your printer.cfg file.
If you have a START_PRINT macro already in you printer.cfg file, comment out that section and paste the code below above the code you just commented out. If not, just paste this under the BED_MESH_CALIBRATE macro. Indentation is important.

[gcode_macro START_PRINT]
gcode:
    {% set BED_TEMP = params.BED_TEMP|default(60)|float %} # Setup bed temp parameter and give it a default value of 60
    {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(210)|float %} # Setup extruder temp parameter and give it a default value of 210
    {% set AREA_START = params.AREA_START|default("75,75") %} # Setup start coordinates for the mesh and give it a default of 75,75
    {% set AREA_END = params.AREA_END|default("125,125") %} # Setup end coordinates for the mesh and give it a default of 125,125
    #The original default values for the Start and End coordinates were both 0,0, which either takes the measured value at 0,0 and uses that value everywhere, or does nothing, i forget
    #75,75 and 125,125 will at least probe a small area close to the middle depending on your size bed. Adjust however you want. 
    M140 S{BED_TEMP} # Start bed heating using the declared or default value
    G28 # Home the printer while we wait on the bed to heat up
    M190 S{BED_TEMP} # Wait for bed to reach temperature
    BED_MESH_CALIBRATE AREA_START={params.AREA_START} AREA_END={params.AREA_END} # Create the mesh
    G90 # Use absolute coordinates
    G1 X1 Y1 F5000; Move to the front left corner
    SET_GCODE_OFFSET Z=0.0 # Reset the G-Code Z offset (adjust Z offset if needed)
    G1 Z5 F3000 # Move the nozzle near the bed    
    G1 Z0.15 F300 # Move the nozzle very close to the bed
    M109 S{EXTRUDER_TEMP} # Set and wait for nozzle to reach temperature

Uncomment any additional lines that you commented out of the existing START_PRINT macro that you want to include and each line is commented so you understand exactly what it is doing.

Leave anything commented out that you do not know what it is doing until you can add your own comments. Additional commands are useful, but not necessary.

Add this to your Start GCode setting in IdeaMaker:

START_PRINT EXTRUDER_TEMP={temperature_extruder1} BED_TEMP={temperature_heatbed} AREA_START={print_pos_min_x},{print_pos_min_y} AREA_END={print_pos_max_x},{print_pos_max_y}

@olivierD-FR
Copy link

Hello, anyone know how I can fix this problem. I receive this error not on every gcode file?

image

@olivierD-FR
Copy link

Hello, anyone know how I can fix this problem. I receive this error not on every gcode file?

image

SOLVED: I was not passing the zone to test in the slicer (forgot to update all my printers config in Prusa Slicer

@tohax
Copy link

tohax commented Dec 1, 2022

Simplify3d?

@Skennd
Copy link

Skennd commented Dec 16, 2022

Unfortunately I wasn't isolating variables but I was just able to get past there errors. The last bits of tinkering I did was moving the BMC macro above START_PRINT and commenting out split_delta_z and a faulty region in the [bed_mesh] config section.

Internal error on command:"START_PRINT"
Internal error on command:"BED_MESH_CALIBRATE"
Internal error on command:"BED_MESH_CALIBRATE_BASE"

@voronbuildstart
Copy link

im having the same problem as Skennd and locki-cz has anyone solved this been at it for a bit now

@Skennd
Copy link

Skennd commented Dec 20, 2022

im having the same problem as Skennd and locki-cz has anyone solved this been at it for a bit now

Like I'd said I was able to get past it. I did them all at once tho. I'm guessing based on nothing at all that putting the bed mesh macro before [start_print]. I also commented out the faulty region and split delta z I had set in my [bed_mesh] config section

@locki-cz
Copy link

locki-cz commented Dec 20, 2022

there are some bugs in macro, i used diferent one, much better ... but still have problem with first layer ... then just turned it of because floating z endstop with bed mesh when it is not complete.... no time to install TAP ... try this one:

https://github.com/Frix-x/klipper-voron-V2/blob/main/macros/calibration/adaptive_bed_mesh.cfg

and i will use this with tap and it have random purge ...

https://github.com/kyleisah/Klipper-Adaptive-Meshing-Purging

@Skennd
Copy link

Skennd commented Dec 21, 2022

I'll have to check that out once I get a coreXY set up. I'm on an ender 3 so I've been avoiding the nice voron and ratOS resources. I feel like it would take more work to adapt than this was.
If you don't mind be asking, what's buggy about this one?

@MrLowe72
Copy link

MrLowe72 commented Jan 1, 2023

Hi I think I know the answer but could do with this being confirmed, after installing the macro and the bed mesh being calibrated for the print i now get this when the probe is completed

Move out of range: 203.175 361.000 7.600 [14.000]

This is an Ender 3 S1 Pro with a bed of 220 x 220, why is it calculating a 203 x 361.

thanks

@ChipCE
Copy link
Author

ChipCE commented Jan 2, 2023

If the bed mesh is completed then the error showup, the problem is more likely from your start gcode. Just my random guess, maybe the G0 or G1 is called when the printer in relative mode. You can try to add G90 line right after bed meah command called.

@rstudner
Copy link

rstudner commented Jan 7, 2023

Question - so I have this working (I think). But wanted a bit of clarity.

If I go into Fluidd/Mainsail "Tune" to view the Mesh, it shows it near a corner and not "in the center of the bed" though I of course watched it probe perfectly in the center of my bed around the "bound" of the print as desired
Screenshot 2023-01-07 at 8 36 38 AM

@frankbags
Copy link

are the X and Y coordinates correct? that's all that matters, the visual representation will be cut off after the furthest probe points.

@rstudner
Copy link

rstudner commented Jan 9, 2023

Anyone know in superslicer what the custom G code would be? I can't seem to find the right variable:

START_PRINT BED_TEMP=[first_layer_bed_temperature] EXTRUDER_TEMP=[first_layer_temperature] AREA_START=[first_layer_print_min[0]],[first_layer_print_min[1]] AREA_END=[first_layer_print_max[0]],[first_layer_print_max[1]]

doesn't like first_layer_print_min[0] etc.

@ChipCE
Copy link
Author

ChipCE commented Jan 10, 2023

@rstudner The web UI only draw the area you probed. Does the web UI display the exact mesh position?

what slicer are you using?

@petitxef
Copy link

@rstudner I have this code on start g-code on superslicer:

START_PRINT AREA_START_X={first_layer_print_min[0]} AREA_START_Y={first_layer_print_min[1]} AREA_END_X={first_layer_print_max[0]} AREA_END_Y={first_layer_print_max[1]}

@0RedSky0
Copy link

0RedSky0 commented Jan 17, 2023

I have a Shutdown at the start, can someone help me:

12:45
Internal error on command:"BED_MESH_CALIBRATE"
12:45
Internal error on command:"BED_MESH_CALIBRATE_BASE"
12:45
Klipper state: Shutdown

Log:
Generating new points...
bed_mesh: generated points
Index | Tool Adjusted | Probe
0 | (89.0, 138.2) | (67.0, 128.7)
1 | (105.8, 138.2) | (83.8, 128.7)
2 | (122.7, 138.2) | (100.7, 128.7)
3 | (139.6, 138.2) | (117.6, 128.7)
4 | (156.5, 138.2) | (134.5, 128.7)
5 | (156.5, 155.1) | (134.5, 145.6)
6 | (139.6, 155.1) | (117.6, 145.6)
7 | (122.7, 155.1) | (100.7, 145.6)
8 | (105.8, 155.1) | (83.8, 145.6)
9 | (89.0, 155.1) | (67.0, 145.6)
10 | (89.0, 172.0) | (67.0, 162.5)
11 | (105.8, 172.0) | (83.8, 162.5)
12 | (122.7, 172.0) | (100.7, 162.5)
13 | (139.6, 172.0) | (117.6, 162.5)
14 | (156.5, 172.0) | (134.5, 162.5)
15 | (156.5, 188.9) | (134.5, 179.4)
16 | (139.6, 188.9) | (117.6, 179.4)
17 | (122.7, 188.9) | (100.7, 179.4)
18 | (105.8, 188.9) | (83.8, 179.4)
19 | (89.0, 188.9) | (67.0, 179.4)
20 | (89.0, 205.7) | (67.0, 196.2)
21 | (105.8, 205.7) | (83.8, 196.2)
22 | (122.7, 205.7) | (100.7, 196.2)
23 | (139.6, 205.7) | (117.6, 196.2)
24 | (156.5, 205.7) | (134.5, 196.2)
Internal error on command:"BED_MESH_CALIBRATE_BASE"
Traceback (most recent call last):
File "/home/pi/klipper/klippy/gcode.py", line 198, in _process_commands
handler(gcmd)
File "/home/pi/klipper/klippy/gcode.py", line 135, in
func = lambda params: origfunc(self._get_extended_params(params))
File "/home/pi/klipper/klippy/gcode.py", line 135, in
func = lambda params: origfunc(self._get_extended_params(params))
File "/home/pi/klipper/klippy/extras/bed_mesh.py", line 607, in cmd_BED_MESH_CALIBRATE
self.update_config(gcmd)
File "/home/pi/klipper/klippy/extras/bed_mesh.py", line 576, in update_config
self.print_generated_points(gcmd.respond_info)
File "/home/pi/klipper/klippy/extras/bed_mesh.py", line 406, in print_generated_points
% (rri, self.points[rri][0], self.points[rri][1]))
IndexError: list index out of range
Transition to shutdown state: Internal error on command:"BED_MESH_CALIBRATE_BASE"

@ChipCE
Copy link
Author

ChipCE commented Jan 17, 2023

@0RedSky0 I will need ALL of you config and the sliced gcode to debug. Can you post it here plz?

@0RedSky0
Copy link

[include mainsail.cfg]

VzBoT############

#######################

[printer]
kinematics: corexy
max_velocity: 800
max_accel: 6000
max_accel_to_decel: 6000
max_z_velocity: 35
max_z_accel: 120
square_corner_velocity: 12

[mcu]
serial:/dev/serial/by-id/usb-Klipper_stm32h743xx_300039000951303339323537-if00

[mcu rpi]
serial: /tmp/klipper_host_mcu

[adxl345]
cs_pin: rpi:None

[resonance_tester]
accel_chip: adxl345
probe_points:
165, 165, 20 # an example

########################################

EXP1 / EXP2 (display) pins

########################################

[board_pins]
aliases:
# EXP1 header
EXP1_1=PC5, EXP1_3=PB1, EXP1_5=PE9, EXP1_7=PE11, EXP1_9=,
EXP1_2=PB0, EXP1_4=PE8, EXP1_6=PE10, EXP1_8=PE12, EXP1_10=<5V>,
# EXP2 header
EXP2_1=PA6, EXP2_3=PE7, EXP2_5=PB2, EXP2_7=PC4, EXP2_9=,
EXP2_2=PA5, EXP2_4=PA4, EXP2_6=PA7, EXP2_8=, EXP2_10=

See the sample-lcd.cfg file for definitions of common LCD displays.

########################
########################

[stepper_x]
step_pin: PA15
dir_pin: PA8
enable_pin: !PD1
microsteps: 16
rotation_distance: 40
endstop_pin: ^PC1
position_endstop: 0
position_min: 0
position_max: 328
homing_speed: 100
full_steps_per_rotation: 200
homing_retract_dist: 0
homing_positive_dir: false
step_pulse_duration: 0.000001

[tmc5160 stepper_x]
cs_pin: PD0
spi_software_miso_pin: PE15
spi_software_mosi_pin: PE13
spi_software_sclk_pin: PE14
run_current: 1.100
#hold_current: 1.200
diag1_pin: PC3
sense_resistor: 0.075

########################

[stepper_y]
step_pin: PD4
dir_pin: PD3
enable_pin: !PD6
microsteps: 16
rotation_distance: 40
endstop_pin: ^PC3
position_endstop: 0
position_min: 0
position_max: 325
homing_speed: 100
full_steps_per_rotation: 200
homing_retract_dist: 0
homing_positive_dir: false
step_pulse_duration: 0.000001

[tmc5160 stepper_y]
cs_pin: PD5
spi_software_miso_pin: PE15
spi_software_mosi_pin: PE13
spi_software_sclk_pin: PE14
run_current: 1.100
#hold_current: 1.000
diag1_pin: PC1
sense_resistor: 0.075

########################

[stepper_z]
step_pin: PE2
dir_pin: PE3
enable_pin: !PE0
microsteps: 16
rotation_distance: 3.985
endstop_pin: probe:z_virtual_endstop
position_min: -3
position_max: 320
full_steps_per_rotation: 200
homing_retract_dist: 5.0
homing_positive_dir: false
homing_speed: 5.0
second_homing_speed: 2.5
step_pulse_duration: 0.000001

[tmc5160 stepper_z]
cs_pin: PE1
spi_software_miso_pin: PE15
spi_software_mosi_pin: PE13
spi_software_sclk_pin: PE14
run_current: 1.5
#hold_current: 0.600
diag1_pin: PC0
sense_resistor: 0.075

[stepper_z1]
step_pin: PD11
dir_pin: PD10
enable_pin: !PD13
microsteps: 16
rotation_distance: 3.985
full_steps_per_rotation: 200
step_pulse_duration: 0.000001

[tmc5160 stepper_z1]
cs_pin: PD12
spi_software_miso_pin: PE15
spi_software_mosi_pin: PE13
spi_software_sclk_pin: PE14
run_current: 1.5
#hold_current: 0.600
diag1_pin: PA0
sense_resistor: 0.075

########################

[extruder]

Vz-HextrudORT

step_pin: PD15
dir_pin: PD14
enable_pin: !PC7
microsteps: 16
rotation_distance: 5.586
nozzle_diameter: 0.600
#nozzle_diameter: 0.400
filament_diameter: 1.750
full_steps_per_rotation: 200
heater_pin: PB3
sensor_type: ATC Semitec 104NT-4-R025H42G
sensor_pin: PA2
control: pid
pid_kp = 24.525
pid_ki = 2.555
pid_kd = 58.860
min_temp: 0
max_temp: 305
max_extrude_only_distance: 500.0
max_extrude_cross_section: 300
min_extrude_temp: 0
#pressure_advance: 0.02
#pressure_advance_smooth_time: 0.03
step_pulse_duration: 0.000001

[tmc5160 extruder]
cs_pin: PC6
spi_software_miso_pin: PE15
spi_software_mosi_pin: PE13
spi_software_sclk_pin: PE14
run_current: 0.6
#hold_current:0.300
diag1_pin: PC1
sense_resistor: 0.075

########################
########################

[heater_bed]
heater_pin: PD7
sensor_type: Generic 3950
sensor_pin: PA1
min_temp: 0
max_temp: 130
control: pid
pid_kp = 60.859
pid_ki = 3.145
pid_kd = 294.406

########################

FANS

########################

[fan]
##Print Cooling Fan - FAN1 Connector
pin: PB6
max_power: 1
kick_start_time: 0.5
off_below: 0.10

[heater_fan hotend_fan]
##Hotend Fan - FAN0 Connector
pin: PB7
max_power: 1.0
kick_start_time: 0.5
heater: extruder
heater_temp: 50.0

[fan_generic Exhaust_fan]

exhaust fan - FAN2

pin: PB5
max_power: 1
shutdown_speed: 0
kick_start_time: 0.1
off_below: 0.10

########################

PAUSE_RESUME

########################

[pause_resume]
recover_velocity: 350

########################

SCREWSADJUST

########################

[screws_tilt_adjust]
screw1: 40, 35
screw1_name: front left screw
screw2: 328, 35
screw2_name: front right screw
screw3: 328, 318
screw3_name: rear right screw
screw4: 40, 318
screw4_name: rear left screw
horizontal_move_z: 12
speed: 350
screw_thread: CW-M3

########################

PROBE

########################

[bltouch]
sensor_pin: ^PC13
control_pin: PE5
x_offset: -22
y_offset: -9.5
#z_offset: 3.350

#[safe_z_home]
#home_xy_position: 187, 175
#speed: 400
#z_hop: 7
#z_hop_speed: 30

[homing_override]
set_position_z: 0
#set_position_x: 0
#set_position_y: 0
axes: xyz
gcode:
G90
G0 Z5 F600
G28 X0 Y0
G0 X187 Y175 F9000
G28 Z0
G0 Z5 F500
Z_TILT_ADJUST
G0 X187 Y175 F9000
G28 Z0
G0 Z5 F500

########################

MeshBed

########################

[z_tilt]
z_positions: 383, 160
-50, 160
points: 328, 170
35, 170
speed: 400
horizontal_move_z: 7
retries: 20
retry_tolerance: 0.0020

########################

MeshBed

########################

[bed_mesh]
speed: 400
horizontal_move_z: 7
mesh_min: 22, 10
mesh_max: 300, 310
probe_count: 21, 21
algorithm: bicubic
relative_reference_index: 220

[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_BASE
; gcode parameters
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
; the clearance between print area and probe area
variable_mesh_area_offset : 10.0
; number of sample per probe point
variable_probe_samples : 2
; minimum probe count
variable_min_probe_count : 3
; scale up the probe count, should be 1.0 ~ < variable_max_probe_count/variable_min_probe_count
variable_probe_count_scale_factor : 1.0
; enable preference index
variable_enable_reference_index : False
gcode:
{% if params.AREA_START and params.AREA_END %}
{% set bedMeshConfig = printer["configfile"].config["bed_mesh"] %}
{% set safe_min_x = bedMeshConfig.mesh_min.split(",")[0]|float %}
{% set safe_min_y = bedMeshConfig.mesh_min.split(",")[1]|float %}
{% set safe_max_x = bedMeshConfig.mesh_max.split(",")[0]|float %}
{% set safe_max_y = bedMeshConfig.mesh_max.split(",")[1]|float %}

    {% set area_min_x = params.AREA_START.split(",")[0]|float %}
{% set area_min_y = params.AREA_START.split(",")[1]|float %}
{% set area_max_x = params.AREA_END.split(",")[0]|float %}
{% set area_max_y = params.AREA_END.split(",")[1]|float %}

{% if bedMeshConfig.probe_count.split(",")|length == 2 %}
        {% set meshPointX = bedMeshConfig.probe_count.split(",")[0]|int %}
        {% set meshPointY = bedMeshConfig.probe_count.split(",")[1]|int %}
    {% else %}
        {% set meshPointX = bedMeshConfig.probe_count.split(",")[0]|int %}
        {% set meshPointY = bedMeshConfig.probe_count.split(",")[0]|int %}
    {% endif %}

{% set meshMaxPointX = meshPointX %}
{% set meshMaxPointY = meshPointY %}


    {% if (area_min_x < area_max_x) and (area_min_y < area_max_y) %}
        {% if area_min_x - mesh_area_offset >=  safe_min_x %}
            {% set area_min_x = area_min_x - mesh_area_offset %}
        {% else %}
            {% set area_min_x = safe_min_x %}
        {% endif %}

        {% if area_min_y - mesh_area_offset >=  safe_min_y %}
            {% set area_min_y = area_min_y - mesh_area_offset %}
        {% else %}
            {% set area_min_y = safe_min_y %}
        {% endif %}

        {% if area_max_x + mesh_area_offset <=  safe_max_x %}
            {% set area_max_x = area_max_x + mesh_area_offset %}
        {% else %}
            {% set area_max_x = safe_max_x %}
        {% endif %}

        {% if area_max_y + mesh_area_offset <=  safe_max_y %}
            {% set area_max_y = area_max_y + mesh_area_offset %}
        {% else %}
            {% set area_max_y = safe_max_y %}
        {% endif %}

        {% set meshPointX = (meshPointX * (area_max_x - area_min_x) / (safe_max_x - safe_min_x) * probe_count_scale_factor)|round(0)|int %}
        {% if meshPointX < min_probe_count %}
            {% set meshPointX = min_probe_count %}
        {% endif %}
    {% if meshPointX > meshMaxPointX %}
            {% set meshPointX = meshMaxPointX %}
        {% endif %}

        {% set meshPointY = (meshPointY * (area_max_y -area_min_y ) / (safe_max_y - safe_min_y) * probe_count_scale_factor )|round(0)|int %}
        {% if meshPointY < min_probe_count %}
            {% set meshPointY = min_probe_count %}
        {% endif %}
    {% if meshPointY > meshMaxPointY %}
            {% set meshPointY = meshMaxPointY %}
        {% endif %}

        {% set algorithm = "lagrange" %}
        {% if "algorithm" in bedMeshConfig and meshPointX >=4 and meshPointY >=4 %}
            {% set algorithm = bedMeshConfig.algorithm %}
        {% endif %}

        {% if enable_reference_index %}
            {% set referenceIndex = (meshPointX * meshPointY / 2 - 1 )|round(0)|int %}
            BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} samples={probe_samples|int} algorithm={algorithm} relative_reference_index={referenceIndex}
        {% else %}
            BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} samples={probe_samples|int} algorithm={algorithm}
        {% endif %}
    {% else %}
        BED_MESH_CALIBRATE_BASE
    {% endif %}
{% else %}
    BED_MESH_CALIBRATE_BASE
{% endif %}

########################
######## MACROS ########
########################

########################

Z TILT ADJUST

########################

[gcode_macro Z_TILT]
gcode:
Z_TILT_ADJUST

########################

START_PRINT

########################

[gcode_macro START_PRINT]
gcode:

Use Mesh Profile

#BED_MESH_PROFILE LOAD="achtzig"
#BED_MESH_PROFILE LOAD="neunzig"
#BED_MESH_PROFILE LOAD="neunzigrau"
#####Princore PA12 CF#####
#SET_PRESSURE_ADVANCE ADVANCE=0.03
#SET_PRESSURE_ADVANCE EXTRUDER=extruder SMOOTH_TIME=0.03

########################

END_PRINT

########################

[gcode_macro END_PRINT]
variable_machine_depth: 300
variable_machine_width: 300
gcode:
# Turn off bed, extruder, and fan
M140 S0
M104 S0
M106 S0
# Relative positionning
G91
# Retract and raise Z
G1 Z0.2 E-2 F2400
# Wipe out
G1 X5 Y5 F3000
# Raise Z more
G1 Z10
# Absolute positionning
G90
# Present print
G1 X{machine_width} Y{machine_depth}
# Disable steppers
M84
BED_MESH_CLEAR
# Print message on LCD
M117 Druck beendet!

## <---------------------- SAVE_CONFIG ---------------------->
#
# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
##
#
# [bltouch]
#*# z_offset = 3.55

@0RedSky0
Copy link

0RedSky0 commented Jan 17, 2023

;FLAVOR:Marlin
;TIME:383
;Filament used: 1.28256m
;Layer height: 0.2
;MINX:148.375
;MINY:148.375
;MINZ:0.2
;MAXX:176.625
;MAXY:176.625
;MAXZ:10.4
;POSTPROCESSED
;Generated with Cura_SteamEngine 5.2.1
M140 S90
M105
M190 S90
M104 S265
M105
M109 S265
M82 ;absolute extrusion mode
SET_GCODE_OFFSET Z=0.0
G28
BED_MESH_CALIBRATE AREA_START=148.375,148.375 AREA_END=176.625,176.625
;Purge Line
G1 X3.1 Y20 F14000.0
G1 Z5 F3000
G1 Z0.15 F300
G92 E0
G1 Z0.25 F2000.0
G1 X3.1 Y200.0 Z0.25 F1500.0 E15
G1 X3.5 Y200.0 Z0.25 F5000.0
G92 E0
G92 E0
G92 E0
G1 F3000 E-1
;LAYER_COUNT:53
;LAYER:0
M107
G0 F21000 X149.736 Y149.494 Z0.2

@ChipCE
Copy link
Author

ChipCE commented Jan 17, 2023

Hi,
Because you have reference_index, try to change the variable_enable_reference_index : False to variable_enable_reference_index : True

@0RedSky0
Copy link

Thank you for your quick help. It works perfectly now!

@rstudner
Copy link

@rstudner I have this code on start g-code on superslicer:

START_PRINT AREA_START_X={first_layer_print_min[0]} AREA_START_Y={first_layer_print_min[1]} AREA_END_X={first_layer_print_max[0]} AREA_END_Y={first_layer_print_max[1]}

Thanks!

I ended up with this m'self:

START_PRINT BED_TEMP=[first_layer_bed_temperature] EXTRUDER_TEMP=[first_layer_temperature]
AREA_START={first_layer_print_min[0]},{first_layer_print_min[1]} AREA_START={first_layer_print_max[0]},{first_layer_print_max[1]}

@Lekkz
Copy link

Lekkz commented Jan 27, 2023

please help, I sometimes get an error and I haven't figured out the reason why? the frustrating thing is that it only happens sometimes. although I do understand what the error is saying I don't understand why is happening.
2023-01-27 11_14_26
2023-01-27 11_13_28
``[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_BASE
; gcode parameters
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
; the clearance between print area and probe area
variable_mesh_area_offset : 2.0
; number of sample per probe point
variable_probe_samples : 1
; minimum probe count
variable_min_probe_count : 3
; scale up the probe count, should be 1.0 ~ < variable_max_probe_count/variable_min_probe_count
variable_probe_count_scale_factor : 1.0
; enable preference index
variable_enable_reference_index : False
gcode:
{% if params.AREA_START and params.AREA_END %}
{% set bedMeshConfig = printer["configfile"].config["bed_mesh"] %}
{% set safe_min_x = bedMeshConfig.mesh_min.split(",")[0]|float %}
{% set safe_min_y = bedMeshConfig.mesh_min.split(",")[1]|float %}
{% set safe_max_x = bedMeshConfig.mesh_max.split(",")[0]|float %}
{% set safe_max_y = bedMeshConfig.mesh_max.split(",")[1]|float %}

    {% set area_min_x = params.AREA_START.split(",")[0]|float %}
{% set area_min_y = params.AREA_START.split(",")[1]|float %}
{% set area_max_x = params.AREA_END.split(",")[0]|float %}
{% set area_max_y = params.AREA_END.split(",")[1]|float %}

{% if bedMeshConfig.probe_count.split(",")|length == 2 %}
        {% set meshPointX = bedMeshConfig.probe_count.split(",")[0]|int %}
        {% set meshPointY = bedMeshConfig.probe_count.split(",")[1]|int %}
    {% else %}
        {% set meshPointX = bedMeshConfig.probe_count.split(",")[0]|int %}
        {% set meshPointY = bedMeshConfig.probe_count.split(",")[0]|int %}
    {% endif %}

{% set meshMaxPointX = meshPointX %}
{% set meshMaxPointY = meshPointY %}


    {% if (area_min_x < area_max_x) and (area_min_y < area_max_y) %}
        {% if area_min_x - mesh_area_offset >=  safe_min_x %}
            {% set area_min_x = area_min_x - mesh_area_offset %}
        {% else %}
            {% set area_min_x = safe_min_x %}
        {% endif %}

        {% if area_min_y - mesh_area_offset >=  safe_min_y %}
            {% set area_min_y = area_min_y - mesh_area_offset %}
        {% else %}
            {% set area_min_y = safe_min_y %}
        {% endif %}

        {% if area_max_x + mesh_area_offset <=  safe_max_x %}
            {% set area_max_x = area_max_x + mesh_area_offset %}
        {% else %}
            {% set area_max_x = safe_max_x %}
        {% endif %}

        {% if area_max_y + mesh_area_offset <=  safe_max_y %}
            {% set area_max_y = area_max_y + mesh_area_offset %}
        {% else %}
            {% set area_max_y = safe_max_y %}
        {% endif %}

        {% set meshPointX = (meshPointX * (area_max_x - area_min_x) / (safe_max_x - safe_min_x) * probe_count_scale_factor)|round(0)|int %}
        {% if meshPointX < min_probe_count %}
            {% set meshPointX = min_probe_count %}
        {% endif %}
    {% if meshPointX > meshMaxPointX %}
            {% set meshPointX = meshMaxPointX %}
        {% endif %}

        {% set meshPointY = (meshPointY * (area_max_y -area_min_y ) / (safe_max_y - safe_min_y) * probe_count_scale_factor )|round(0)|int %}
        {% if meshPointY < min_probe_count %}
            {% set meshPointY = min_probe_count %}
        {% endif %}
    {% if meshPointY > meshMaxPointY %}
            {% set meshPointY = meshMaxPointY %}
        {% endif %}

        {% set algorithm = "lagrange" %}
        {% if "algorithm" in bedMeshConfig and meshPointX >=4 and meshPointY >=4 %}
            {% set algorithm = bedMeshConfig.algorithm %}
        {% endif %}

        {% if enable_reference_index %}
            {% set referenceIndex = (meshPointX * meshPointY / 2 - 1 )|round(0)|int %}
            BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} samples={probe_samples|int} algorithm={algorithm} relative_reference_index={referenceIndex}
        {% else %}
            BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} samples={probe_samples|int} algorithm={algorithm}
        {% endif %}
    {% else %}
        BED_MESH_CALIBRATE_BASE
    {% endif %}
{% else %}
    BED_MESH_CALIBRATE_BASE
{% endif %}

``[gcode_macro START_PRINT]
variable_parameter_EXTRUDER_TEMP: 235
variable_parameter_BED_TEMP: 50
; gcode parameters for area bed mesh
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
gcode:
{% set BED_TEMP = params.BED_TEMP|default(50)|float %}
{% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(235)|float %}
M104 S{EXTRUDER_TEMP} T0
M140 S{BED_TEMP}
G28
# preheat, homing, etc
BED_MESH_CALIBRATE AREA_START={params.AREA_START|default("0,0")} AREA_END={params.AREA_END|default("0,0")}
# the rest of your start macro here
M117 Waiting for temperature
# Start bed heating and continue
#M140 S{BED_TEMP}
{% if printer.heater_bed.temperature < params.BED_TEMP|float0.95 %}
M190 S{params.BED_TEMP|float
0.95} # wait till 0.85 of bed temp is reached, then continue
{% endif %}
#M140 S{EXTRUDER_TEMP}
#M190 S{BED_TEMP}
#M109 S{EXTRUDER_TEMP}
M190 S{BED_TEMP}
M109 S{EXTRUDER_TEMP} T0
PRIME_LINE
M117 Printing...

[gcode_macro END_PRINT]
gcode:
M117 Done printing :)
# move z down
G91
G1 Z10 F3000
G1 E-5
G28 X Y
#disable hotend and heated bed
M104 S0
M140 S0
# disable steppers
M84
BED_MESH_CLEAR

@ChipCE
Copy link
Author

ChipCE commented Jan 27, 2023

@Lekkz the mesh is completed so your macro setting is good.
Here is the problem: Unlike full size bed mesh witch the last probe position always in the bed corner, bed mesh area more likely end at center of the bed where the printed part are. You have to modify your PRIME_LINE, move the toolhead to the prime line start position before calling the extrude gcodes.

@Lekkz
Copy link

Lekkz commented Jan 28, 2023

@ChipCE thanks for the response, this is what I have for my PRIME_LINE [gcode_macro PRIME_LINE] gcode: M117 Prime Line G92 E0 ;Reset Extruder # move z axis G1 Z2.0 F3000 ;Move Z Axis up # move to prime position G1 X10 Y30 Z0.28 F5000.0 ;Move to start position G1 X10 Y200.0 Z0.28 F1500.0 E15 ;Draw the first line G1 X15 Y200.0 Z0.28 F5000.0 ;Move to side a little G1 X15 Y50 Z0.28 F1500.0 E30 ;Draw the second line G92 E0 ;Reset Extruder G1 Z2.0 F3000 ;Move Z Axis up

@ChipCE
Copy link
Author

ChipCE commented Jan 29, 2023

@Lekkz I think add G90 command at the start of your prime line will fix that

@sgoph
Copy link

sgoph commented Feb 7, 2023

Can someone please explain what this section does:

{% set algorithm = "lagrange" %}
{% if "algorithm" in bedMeshConfig and meshPointX >=4 and meshPointY >=4 %}
{% set algorithm = bedMeshConfig.algorithm %}
{% endif %}

Is it setting the algorithm to lagrange if the mesh points are 4 or greater? Or.. Is it setting the algorithm to whatever is set in printer.cfg if the points are >=4?

If I wanted to increase the number of probe points calculated for any given print area, would I just increase the scale factor (ie 1.25, 1.5, 1.75)?

Thanks!

@ChipCE
Copy link
Author

ChipCE commented Feb 7, 2023

@sgoph It's not that well writen, but similar to this.

{% set algorithm = bedMeshConfig.algorithm %} {% if meshPointX <4 and meshPointY <4 %} {% set algorithm = "lagrange" %} {% endif %} Bicubic need 4 points or more so we will need to force change to lagrange if the meshPoints are under 4.

Yes. Increase the scale factor will do it.

@whi-tw
Copy link

whi-tw commented Feb 9, 2023

I'm working on a macro which enables per-object meshes if:

  1. 'Label Objects' is turned on in the slicer
  2. moonraker is set up with:
    [file_manager]
    enable_object_processing: True
    
  3. klipper is configured with [exclude_object]

This will make a single small mesh for every item on the bed and load it dynamically when the object starts printing:

https://github.com/whi-tw/klipper-adaptive-mesh/releases/tag/v0.0.2 (adaptive_bed_mesh.cfg in the Assets section)

This has the benefit of the meshes being very detailed, as they are only made on the area of each object - no wasted space.

If anyone wants to give it a go, please leave feedback on the repo with any issues.

@rstudner
Copy link

Minor help request from y'all experts... for some reason I can't seem to get this right.

My Ender bed isn't very flat (hah!)

So if I have it calculate a mesh for a smaller object in the center of the bed, when it moves fromt he post-purge line to the center, it'll scratch/drag my nozzle on the way over.

Trying to get it to move up 1mm, navigate to 'skirt/brim/whatever' start ,then lower back down 1mm

@ChipCE
Copy link
Author

ChipCE commented Feb 14, 2023

@rstudner This macro cannot be changed to fix your problem. But modify your start gcode can fix that. Post your start gcode here and i will try to look at it.

@andrewt27
Copy link

andrewt27 commented Feb 19, 2023

@ChipCE Hi, I have a fairly large distance between the nozzle and the sensor (57mm). With large print I get errors like this
!! Move out of range: -27.016 86.484 5.000 [0.000]
How to compensate it?

Edit:
[SOLVED] I have changed x min in config:
[bed_mesh]
...
mesh_min: 57, 10
...

@kllxdababy
Copy link

22:13
Internal error on command:"PRINT_START"
22:13
Internal error on command:"BED_MESH_CALIBRATE"
22:13
Internal error on command:"BED_MESH_CALIBRATE_BASE"

Getting this error after my voron does QGL and homes.

Here is my print start macro:
[gcode_macro PRINT_START]
variable_parameter_EXTRUDER_TEMP: 190
variable_parameter_BED_TEMP: 30

gcode parameters for area bed mesh

variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
gcode:
G32 ; home all axes
G90 ; absolute positioning
G1 Z20 F3000 ; move nozzle away from bed
BED_MESH_CALIBRATE AREA_START={params.AREA_START|default("0,0")} AREA_END={params.AREA_END|default("0,0")}

@Zephyrus67
Copy link

Where exactly did you get %MINX% etc. from in Cura slicer? in my Cura that does not pass anything but the %MINX% and similar.

I am already using the "START_PRINT BED_TEMP=110 EXTRUDER_TEMP=255" part but the definition of area does not seem to work

@Zephyrus67
Copy link

Sorry. I didnt see the part where the plugin is mentioned...got it working now.

@Zephyrus67
Copy link

Zephyrus67 commented Mar 3, 2023

But will you not need a "BED_MESH_PROFILE Load=default" in your printer.cfg to actually load the saved mesh? With normal BED_MESH_CALIBRATE you need to.

@1yrik
Copy link

1yrik commented Mar 10, 2023

The script works great, mostly. I have one issue (more of a minor inconvenience) where the Klipper gives a "Must home axis first: 0.000 0.000 5.000 [0.000]" on 3 consecutive lines. I just have to manually home the printer and then it works great, it's still just an inconvenience. My though is just that a G28 (I have a G28 macro) needs to be thrown in somewhere, I'm just not sure where exactly...
Thanks in advance for any help!
8% Printing - ETA_ 21_12 - handletest gcode - Google Chrome 2023-03-09 8_36_18 PM

@ChipCE
Copy link
Author

ChipCE commented Mar 10, 2023

@1yrik I think you need to edit your start gcode. This override macro is the same as the original BED_MESH_CALIBRATE, it can be called without homed axis.

@1yrik
Copy link

1yrik commented Mar 10, 2023

@ChipCE I know I have to add in a "G28" somewhere, I'm just not sure where. I'll take another look and see if anything obvious needs changing.

@Matei-alt
Copy link

When I boot up my printer after doing said changes I get this error. How can I fix this?
image

@ChipCE
Copy link
Author

ChipCE commented Mar 14, 2023

@Matei-alt seem like you dont have [bed_mesh] enabled in your config.

@Matei-alt
Copy link

@ChipCE Oh, I tought "this will replace the default BED_MESH_CALIBRATE command." meant to just replace that whole thing. Sorry for bothering you.

@mattfox27
Copy link

I have a question when probing begins the probe almost drags across the bed, like it does not go up it stays on the bed moves to the left then goes up a little and back down, is that correct?

@frankbags
Copy link

frankbags commented Mar 25, 2023

That's normal behavior if you have the option under [bltouch] stow_on_each_sample: false

https://www.klipper3d.org/BLTouch.html#multi-probing-without-stowing

if you have no clearance issues then it shouldn't be a problem, it does save a lot of time when building a mesh

@mattfox27
Copy link

Ya the probe was actually touching the bed as it moved to the next point which was causing false readings. I have to add a line in mesh section like horizontal_Z_probe: 8. This wasn't the exact line but something similar

@screech24
Copy link

Anyone using Bambu Studio or Orcaslicer ? I cant seem to get this to work using either of those slicers.. using the prusaslicer settings ... "START_PRINT EXTRUDER_TEMP=[first_layer_temperature] BED_TEMP=[first_layer_bed_temperature] AREA_START={first_layer_print_min[0]},{first_layer_print_min[1]} AREA_END={first_layer_print_max[0]},{first_layer_print_max[1]}"

@FraLem89
Copy link

M190 S[bed_temperature_initial_layer_single]
M109 S[nozzle_temperature_initial_layer]
M117
PRINT_START EXTRUDER=[nozzle_temperature_initial_layer] BED=[bed_temperature_initial_layer_single] PRINT_MIN={first_layer_print_min[0]},{first_layer_print_min[1]} PRINT_MAX={first_layer_print_max[0]},{first_layer_print_max[1]}

@DaKlassiker
Copy link

DaKlassiker commented Apr 17, 2023

Unknown command:"AREA_START=158.387,158.396"

it does the full bed then. Any ideas? i´m using klicky probe

Superslicer:
PRINT_START BED=[first_layer_bed_temperature] EXTRUDER={first_layer_temperature[initial_extruder]+extruder_temperature_offset[initial_extruder]} CHAMBER=[chamber_temperature]
AREA_START={first_layer_print_min[0]},{first_layer_print_min[1]} AREA_END={first_layer_print_max[0]},{first_layer_print_max[1]}

[gcode_macro PRINT_START]
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0

gcode:
{% set FILAMENT = params.FILAMENT|default('Default')|string %}
{% set MIN_TEMP = params.EXTRUDER|int * 0.9 %}
{% set BED_TEMP = params.BED|default(0)|int %}
{% set EXTRUDER_TEMP = params.EXTRUDER|default(0)|float %}
{% set chamber = params.CHAMBER|default(0)|int %}

SET_GCODE_VARIABLE MACRO=PRINT_START VARIABLE=chambertemp VALUE={chamber}

{% if params.FILAMENT == 'ABS' %}
	{% set nevermore_fan_speed = 0.70 %}
  
{% elif params.FILAMENT == 'ASA' %}
    {% set nevermore_fan_speed = 0.70 %}

{% elif params.FILAMENT == 'PETG' %}
	{% set nevermore_fan_speed = 0.40 %}
	
{% elif params.FILAMENT == 'PLA' %}
	{% set nevermore_fan_speed = 0 %}

{% elif params.FILAMENT == 'WOOD' %}
	{% set nevermore_fan_speed = 0 %}
	
{% else %} 
	{% set nevermore_fan_speed = 0 %}
{% endif %}

SET_FAN_SPEED FAN=Nevermore SPEED={nevermore_fan_speed}
#SET_FILAMENT_SENSOR SENSOR=filament_sensor ENABLE=1
M107
M117 {params.FILAMENT}
M190 S{BED_TEMP} #M140
G28
G90
 {% if printer["temperature_sensor chamber"].temperature < chamber %}              
    HEATSOAK T={BED_TEMP} MOVE=1                                                         
    M190 S{BED_TEMP}                                                                    
    TEMPERATURE_WAIT SENSOR="temperature_sensor chamber" MINIMUM={chamber}          
{% else %}                                                                         
    {% if printer.heater_bed.temperature < (BED_TEMP-2) %}                               
        HEATSOAK T={BED_TEMP} MOVE=1                                                     
        M190 S{BED_TEMP}                                                                 
    {% else %}                                                                      
        HEATSOAK T={BED_TEMP} MOVE=0                                                   
    {% endif %}
{% endif %} 
M106 S0                                                                              
LEDWHITE 
ATTACH_PROBE_LOCK                                                              
QUAD_GANTRY_LEVEL                                                                  
G28 Z                                                                           
G90                                                                               
G0 Z20                                                                              
G0 X{printer.toolhead.axis_maximum.x/2} Y{printer.toolhead.axis_maximum.y/2} F19500 
BED_MESH_CALIBRATE AREA_START={params.AREA_START|default("0,0")} AREA_END={params.AREA_END|default("0,0")}
DOCK_PROBE_UNLOCK                                                                   
M109 S{EXTRUDER_TEMP}
SETACTUAL_ETMP
G1 E-1 F300
CALIBRATE_Z                                                                       
G92 E0                                                                             
PRIME_NOZZLE

@ChipCE
Copy link
Author

ChipCE commented Apr 18, 2023

@DaKlassiker your Prusa start gcode is splitted into 2 lines. They must be in the same line.

@HelioSG
Copy link

HelioSG commented May 3, 2023

@ChipCE
Dear, I'm trying to use the macro Klipper mesh on print area only, but I'm getting an error message:
"Internal error on command:"BED_MESH_CALIBRATE_BASE"
Once the underlying issue is corrected, use the
"FIRMWARE_RESTART" command to reset the firmware, reload the
config, and restart the host software." Could you help me

@gtollini
Copy link

gtollini commented May 6, 2023

@ChipCE
Klipper has a minimum probe distance which isn't addressed by the current script. This can easily be solved by adding:

{% if (area_max_x - area_min_x) / meshMaxPointX < 1 %}
  {% set meshPointX = (area_max_x - area_min_x)|int %}
{% endif %}

And

{% if (area_max_y - area_min_y) / meshMaxPointY < 1 %}
  {% set meshPointY = (area_max_y - area_min_y)|int %}
{% endif %}

After the checks at lines 69-71 and 77-79.

@ChipCE
Copy link
Author

ChipCE commented May 7, 2023

@gtollini Thank for point out the bug!

I have some question about your fix code

{% if (area_max_x - area_min_x) / meshMaxPointX < 1 %}
  {% set meshPointX = (area_max_x - area_min_x)|int %}
{% endif %}
  • in the first line, we check if the probe distance is smaller than 1 or not, {% if (area_max_x - area_min_x) / meshMaxPointX < 1 %} should be {% if (area_max_x - area_min_x) / meshPointX < 1 %}
  • Why set {% set meshPointX = (area_max_x - area_min_x)|int %}? We set the mesh to 1mm distance with this?

@DocKuro
Copy link

DocKuro commented May 8, 2023

Hello, I'm trying to get this script to work, I added the macro and modified the START_PRINT line on superslicer; now the generated GCODE for my sample print looks like this:

START_PRINT EXTRUDER_TEMP=195 BED_TEMP=60 AREA_START=118.669,78.6702 AREA_END=231.35,191.33

The macro generate the points, but then fails calling the BED_MESH_CALIBRATE_BASE, so I made some try and generated a command that should cover my area, like this:

BED_MESH_CALIBRATE_BASE mesh_min=118.669,78.6702 mesh_max=231.35,191.33 probe_count=4,5 samples=5 algorithm=bicubic

The macro returns this output:

// Generating new points...
// bed_mesh: generated points
// Index | Tool Adjusted | Probe
// 0 | (129.3, 34.1) | (118.7, 78.7)
// 1 | (166.8, 34.1) | (156.2, 78.7)
// 2 | (204.4, 34.1) | (193.8, 78.7)
// 3 | (241.9, 34.1) | (231.3, 78.7)
// 4 | (241.9, 62.2) | (231.3, 106.8)
// 5 | (204.4, 62.2) | (193.8, 106.8)
// 6 | (166.8, 62.2) | (156.2, 106.8)
// 7 | (129.3, 62.2) | (118.7, 106.8)
// 8 | (129.3, 90.4) | (118.7, 135.0)
// 9 | (166.8, 90.4) | (156.2, 135.0)
// 10 | (204.4, 90.4) | (193.8, 135.0)
// 11 | (241.9, 90.4) | (231.3, 135.0)
// 12 | (241.9, 118.6) | (231.3, 163.2)
// 13 | (204.4, 118.6) | (193.8, 163.2)
// 14 | (166.8, 118.6) | (156.2, 163.2)
// 15 | (129.3, 118.6) | (118.7, 163.2)
// 16 | (129.3, 146.7) | (118.7, 191.3)
// 17 | (166.8, 146.7) | (156.2, 191.3)
// 18 | (204.4, 146.7) | (193.8, 191.3)
// 19 | (241.9, 146.7) | (231.3, 191.3)
// Klipper state: Shutdown
!! Internal error on command:"BED_MESH_CALIBRATE_BASE"

and the Fluidd UI error message says list index out of range
The points look all valid to me (print area is 350x310), could you point me to something else to look at?

@DocKuro
Copy link

DocKuro commented May 8, 2023

Well, it was easier than expected, I just had to enable the reference_index calculation in your macro
variable_enable_reference_index : True

@HelioSG check if this helps you too since your error looked very similar to mine.
Basically if you set a relative_reference_index in your [bed_mesh] configuration section, you have to enable its dynamic calculation, otherwise the index will not be relevant and its index could be outside the number of points generated, giving the aforementioned error.

@louispires
Copy link

Got it working good on my 400³ V-Core 3 - However 1 thing I noticed was the default BED MESH is saved as RATOS, this now saves it under DEFAULT, which during each layer change, causes these two log entries:
image

Not a BIG deal but if I could save this as RATOS, then it shouldn't load the BED mesh multiple times...

@ChipCE
Copy link
Author

ChipCE commented May 11, 2023

@louispires you can add BED_MESH_PROFILE LOAD= SAVE= REMOVE= to set the profile name you want to save to or load from.

@borolo222
Copy link

borolo222 commented Jun 27, 2023

I get no error messages, however it uses the normal calibration procedure for the print.

Cura settings:
START_PRINT T_BED={material_bed_temperature_layer_0} T_EXTRUDER={material_print_temperature_layer_0}
AREA_START=%MINX%,%MINY% AREA_END=%MAXX%,%MAXY%

In the gcode, the variables are sent:
AREA_START=96.5,96.5 AREA_END=138.5,138.5

printer.cfg:
[bed_mesh]
speed: 120
mesh_min: 10, 10
mesh_max: 200, 219
probe_count: 7,7
algorithm: bicubic
mesh_pps: 2,2
fade_start: 1
fade_end: 10
fade_target: 0

Macros:
calibrate same as example

`Start print:
[gcode_macro START_PRINT]

; gcode parameters for area bed mesh
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0

gcode:
M117 Starting
# Get params
{% set T_BED = params.T_BED|default(50) %}
{% set T_EXTRUDER = params.T_EXTRUDER|default(205) %}
M117 Homing
# Use absolute coordinates
# G92

M117 Waiting for temperature
# Start bed heating and continue
M140 S{T_BED}
{% if printer.heater_bed.temperature > params.T_BED|float*0.85 %}
    M140 S{T_BED}
    M109 S{T_EXTRUDER} 
    M190 S{T_BED}
{% else %}
    M190 S{params.T_BED|float*0.85} # wait till 0.85 of bed temp is reached, then continue
    M140 S{T_BED} 
    M109 S{T_EXTRUDER}
    M190 S{T_BED}
{% endif %}

#BUILD MESH
M117 Homing
G28 ; Home all axes

;BED_MESH_CALIBRATE
BED_MESH_CALIBRATE AREA_START={params.AREA_START|default("0,0")} AREA_END={params.AREA_END|default("0,0")}
M117 Bed mesh

#Load Mesh
# M117 Loading Mesh
# BED_MESH_PROFILE LOAD="bed1b"

# Prime line
M117 Priming
PRIME_LINE

# Load Skew Profile
SKEW_PROFILE LOAD=my_skew_profile

M117 Printing...`

+++++

thanks for your help

@pradeep1080
Copy link

Hey,

Will it work in Delta printers? I made the changes as instructed in this page but I get the following error:
Error evaluating 'gcode_macro BED_MESH_CALIBRATE:gcode': jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'mesh_min'

@SlattyMatty
Copy link

You don't really need to be probing your bed before every print with a delta since it's static. Any variation between meshes you create will most likely be negligible.

@rwaspe
Copy link

rwaspe commented Aug 25, 2023

Has anyone figured out how to do this on Simplify3d or can't it be done?

@riva03
Copy link

riva03 commented Aug 30, 2023

Hello!

I'm getting this error:

!! Error evaluating 'gcode_macro BED_MESH_CALIBRATE:gcode': jinja2.exceptions.UndefinedError: 'extras.gcode_macro.GetStatusWrapper object' has no attribute 'gcode_macro _KAMP_Settings'

Thanks in advance

@jf2615
Copy link

jf2615 commented Aug 30, 2023

I keep getting the following error.
gcode command BED_MESH_CALIBRATE already registered Once the underlying issue is corrected, use the "RESTART" command to reload the config and restart the host software. Printer is halted

I have the BED_MESH_CALIBRATE renamed to BED_MESH_CALIBRATE_BASE in printer.cfg
I am calling a marcros.cfg where I have this script placed as a separate macro.

@frankbags
Copy link

are you including the macros.cfg twice by chance?
and are you renaming the original macro like this or simply rename the actual macro?

[gcode_macro BED_MESH_CALIBRATE] rename_existing: BED_MESH_CALIBRATE_BASE

@Nathan22211
Copy link

ok so I just copy pasted that macro into my config on my 350 siboor trident. It seems this macro doesn't work with Klicky. it didn't go and pick up my probe. I might modify the macro to fix that.

@Shaneweston
Copy link

I know I have done something stupid, but my brain has decided to take a holiday without me so i can't work out where I am wrong.

Two issues. The auto bed mesh seems to do the whole bed not just the print area. Also it leaves blobs of filament that slowly reduce in size as it probes the bed.


CURA START CODE
G21 ;metric values
G90 ;absolute positioning
M82 ;set extruder to absolute mode
M107 ;start with the fan off
G28 X0 Y0 ;move X/Y to min endstops
M300 S1318 P266
G28 Z0 ;move Z to min endstops
G0 Z0.2
G92 E0 ;zero the extruded length
G1 X40 E25 F400 ; Extrude 25mm of filament in a 4cm line. Reduce speed (F) if you have a nozzle smaller than 0.4mm!
G92 E0 ;zero the extruded length again
G1 E-1 F500 ; Retract a little
G1 X80 F4000 ; Quickly wipe away from the filament line
BED_MESH_CALIBRATE AREA_START=%MINX%,%MINY% AREA_END=%MAXX%,%MAXY%
M117 ; Printing…
G5


POST PLUGIN SCRIPT
C:\Users\shane\AppData\Roaming\cura\5.4\plugins\PostProcessingPlugin\Scripts\MeshPrintSize.py
import re #To perform the search and replace.

from ..Script import Script

class MeshPrintSize(Script):

def getSettingDataString(self):
    return """{
        "name": "Mesh Print Size",
        "key": "MeshPrintSize",
        "metadata": {},
        "version": 2,
        "settings":{}
    }"""

def execute(self, data):
        minMaxXY = {'MAXY':0,'MAXX':0, 'MINY':0,'MINX':0}
        lineData = ''

        for layer_number, layer in enumerate(data):
            for k,v in minMaxXY.items():
                result = re.search(str(k)+":(\d*\.?\d*)",layer)
                if result is not None:
                    minMaxXY[k] = result.group(1)

            if re.search('START_PRINT.*', layer) is not None:
                lineData = layer
                for k, v in minMaxXY.items():
                    pattern = re.compile('START_PRINT ')
                    replace = 'START_PRINT {variable}={value} '.format(variable = k, value = v)
                    lineData = re.sub(pattern, replace, lineData)

                data[layer_number] = lineData

        return data

******************************************************************8
BED_MESH_CALIBRATE.CFG
[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_BASE
; gcode parameters
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
; the clearance between print area and probe area
variable_mesh_area_offset : 5.0
; number of sample per probe point
variable_probe_samples : 2
; minimum probe count
variable_min_probe_count : 8
; scale up the probe count, should be 1.0 ~ < variable_max_probe_count/variable_min_probe_count
variable_probe_count_scale_factor : 1.0
; enable preference index
variable_enable_reference_index : False
gcode:
{% if params.AREA_START and params.AREA_END %}
{% set bedMeshConfig = printer["configfile"].config["bed_mesh"] %}
{% set safe_min_x = bedMeshConfig.mesh_min.split(",")[0]|float %}
{% set safe_min_y = bedMeshConfig.mesh_min.split(",")[1]|float %}
{% set safe_max_x = bedMeshConfig.mesh_max.split(",")[0]|float %}
{% set safe_max_y = bedMeshConfig.mesh_max.split(",")[1]|float %}

    {% set area_min_x = params.AREA_START.split(",")[0]|float %}
{% set area_min_y = params.AREA_START.split(",")[1]|float %}
{% set area_max_x = params.AREA_END.split(",")[0]|float %}
{% set area_max_y = params.AREA_END.split(",")[1]|float %}

{% if bedMeshConfig.probe_count.split(",")|length == 2 %}
        {% set meshPointX = bedMeshConfig.probe_count.split(",")[0]|int %}
        {% set meshPointY = bedMeshConfig.probe_count.split(",")[1]|int %}
    {% else %}
        {% set meshPointX = bedMeshConfig.probe_count.split(",")[0]|int %}
        {% set meshPointY = bedMeshConfig.probe_count.split(",")[0]|int %}
    {% endif %}

{% set meshMaxPointX = meshPointX %}
{% set meshMaxPointY = meshPointY %}


    {% if (area_min_x < area_max_x) and (area_min_y < area_max_y) %}
        {% if area_min_x - mesh_area_offset >=  safe_min_x %}
            {% set area_min_x = area_min_x - mesh_area_offset %}
        {% else %}
            {% set area_min_x = safe_min_x %}
        {% endif %}

        {% if area_min_y - mesh_area_offset >=  safe_min_y %}
            {% set area_min_y = area_min_y - mesh_area_offset %}
        {% else %}
            {% set area_min_y = safe_min_y %}
        {% endif %}

        {% if area_max_x + mesh_area_offset <=  safe_max_x %}
            {% set area_max_x = area_max_x + mesh_area_offset %}
        {% else %}
            {% set area_max_x = safe_max_x %}
        {% endif %}

        {% if area_max_y + mesh_area_offset <=  safe_max_y %}
            {% set area_max_y = area_max_y + mesh_area_offset %}
        {% else %}
            {% set area_max_y = safe_max_y %}
        {% endif %}

        {% set meshPointX = (meshPointX * (area_max_x - area_min_x) / (safe_max_x - safe_min_x) * probe_count_scale_factor)|round(0)|int %}
        {% if meshPointX < min_probe_count %}
            {% set meshPointX = min_probe_count %}
        {% endif %}
    {% if meshPointX > meshMaxPointX %}
            {% set meshPointX = meshMaxPointX %}
        {% endif %}

        {% set meshPointY = (meshPointY * (area_max_y -area_min_y ) / (safe_max_y - safe_min_y) * probe_count_scale_factor )|round(0)|int %}
        {% if meshPointY < min_probe_count %}
            {% set meshPointY = min_probe_count %}
        {% endif %}
    {% if meshPointY > meshMaxPointY %}
            {% set meshPointY = meshMaxPointY %}
        {% endif %}

        {% set algorithm = "bicubic" %}
    {% if "algorithm" in bedMeshConfig %}
        {% set algorithm = bedMeshConfig.algorithm %}
        {% endif %}
        {% if meshPointX >=7 or meshPointY >=7 %}
            {% set algorithm = "bicubic" %}
        {% endif %}

        {% if enable_reference_index %}
            {% set referenceIndex = (meshPointX * meshPointY / 2 - 1 )|round(0)|int %}
            BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} samples={probe_samples|int} algorithm={algorithm} relative_reference_index={referenceIndex}
        {% else %}
            BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} samples={probe_samples|int} algorithm={algorithm}
        {% endif %}
    {% else %}
        BED_MESH_CALIBRATE_BASE
    {% endif %}
{% else %}
    BED_MESH_CALIBRATE_BASE
{% endif %}

PRINTER.CFG
###Anycubic Vyper Klipper Config###

[include mainsail.cfg]
[include BED_MESH_CALIBRATE.cfg]

[stepper_x]
step_pin: PC2
dir_pin: PB9
enable_pin: !PC3
microsteps: 16
rotation_distance: 40
endstop_pin: !PA7
position_min: -3
position_endstop: -3
position_max: 245
homing_speed: 30.0

[stepper_y]
step_pin: PB8
dir_pin: PB7
enable_pin: !PC13
microsteps: 16
rotation_distance: 32
endstop_pin: !PC5
position_min: -17
position_endstop: -17
position_max: 245
homing_speed: 30.0

[stepper_z]
step_pin: PB6
dir_pin: !PB5
enable_pin: !PC14
microsteps: 16
rotation_distance: 8
endstop_pin: PB2
#position_endstop: 0.0
position_max: 260
position_min: -5
homing_speed: 5.0

[stepper_z1]
step_pin: PC0
dir_pin: !PC1
enable_pin: !PC15
microsteps: 16
rotation_distance: 8
#endstop_pin: PC6

[extruder]
step_pin: PB4
dir_pin: !PB3
enable_pin: !PA15
microsteps: 16
rotation_distance: 22.185
gear_ratio: 50:17
full_steps_per_rotation: 200
nozzle_diameter: 0.400
filament_diameter: 1.750
max_extrude_cross_section: 5.0
heater_pin: PA1
sensor_type: ATC Semitec 104GT-2
sensor_pin: PC4
#control: pid
#pid_kp = 28.937
#pid_ki = 1.295
#pid_kd = 161.688
min_temp: 0
max_temp: 260
pressure_advance = 0.34

[heater_fan extruder_fan]
pin: PB1

[heater_bed]
heater_pin: PA4
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PB0
#control: pid
#pid_kp = 67.648
#pid_ki = 1.044
#pid_kd = 1095.893
min_temp: 0
max_temp: 110

[fan]
pin: PA0

[probe]
pin: !PB12
#z_offset: 0
activate_gcode:
probe_reset

[output_pin LED]
pin: mcu:PA13
pwm: False
value: 0

[output_pin probe_reset_pin]
pin: PB13

[filament_switch_sensor runout]
pause_on_runout: True
switch_pin: PA5

[mcu]
serial: /dev/ttyUSB0
restart_method: command

[temperature_sensor Raspberry Pi]
sensor_type: temperature_host
min_temp: 0
max_temp: 100

[safe_z_home]
home_xy_position: -3,-17
z_hop: 10

[input_shaper]

#shaper_freq_x: 62.2

#shaper_type_x: ei

#shaper_freq_y: 36.8

#shaper_type_y: mzv

[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 4000
max_accel_to_decel: 3000
max_z_velocity: 5
max_z_accel: 100

[bed_mesh]
mesh_min: 15,15
mesh_max: 230, 230
probe_count: 6,6
mesh_pps: 2,3
algorithm: bicubic
speed: 5400
horizontal_move_z: 5

[gcode_macro probe_reset]
gcode:
SET_PIN PIN=probe_reset_pin VALUE=0
G4 P300
SET_PIN PIN=probe_reset_pin VALUE=1
G4 P100

[display_status]

[pause_resume]

[gcode_macro PAUSE]
description: Pause the actual running print
rename_existing: PAUSE_BASE
gcode:
##### set defaults #####
{% set x = params.X|default(230) %} #edit to your park position
{% set y = params.Y|default(230) %} #edit to your park position
{% set z = params.Z|default(10)|float %} #edit to your park position
{% set e = params.E|default(1) %} #edit to your retract length
##### calculate save lift position #####
{% set max_z = printer.toolhead.axis_maximum.z|float %}
{% set act_z = printer.toolhead.position.z|float %}
{% set lift_z = z|abs %}
{% if act_z < (max_z - lift_z) %}
{% set z_safe = lift_z %}
{% else %}
{% set z_safe = max_z - act_z %}
{% endif %}
##### end of definitions #####
PAUSE_BASE
G91
{% if printer.extruder.can_extrude|lower == 'true' %}
G1 E-{e} F2100
{% else %}
{action_respond_info("Extruder not hot enough")}
{% endif %}
{% if "xyz" in printer.toolhead.homed_axes %}
G1 Z{z_safe}
G90
G1 X{x} Y{y} F6000
{% else %}
{action_respond_info("Printer not homed")}
{% endif %}

[gcode_macro RESUME]
description: Resume the actual running print
rename_existing: RESUME_BASE
gcode:
##### set defaults #####
{% set e = params.E|default(1) %} #edit to your retract length
#### get VELOCITY parameter if specified ####
{% if 'VELOCITY' in params|upper %}
{% set get_params = ('VELOCITY=' + params.VELOCITY) %}
{%else %}
{% set get_params = "" %}
{% endif %}
##### end of definitions #####
G91
{% if printer.extruder.can_extrude|lower == 'true' %}
G1 E{e} F2100
{% else %}
{action_respond_info("Extruder not hot enough")}
{% endif %}
RESUME_BASE {get_params}

[gcode_macro CANCEL_PRINT]
description: Cancel the actual running print
rename_existing: CANCEL_PRINT_BASE
gcode:
TURN_OFF_HEATERS
CANCEL_PRINT_BASE

## <---------------------- SAVE_CONFIG ---------------------->
#
# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
##
#
# [input_shaper]
## shaper_type_x = ei
#
# shaper_freq_x = 61.0
## shaper_type_y = mzv
#
# shaper_freq_y = 58.0
##
#
# [bed_mesh default]
## version = 1
#
# points =
## -0.235000, -0.242500, -0.200000, -0.037500, 0.005000, -0.080000, 0.000000, 0.080000, 0.210000, 0.280000, 0.175000, 0.172500, 0.172500, 0.332500, 0.327500
#
# -0.232500, -0.227500, -0.190000, -0.067500, 0.087500, -0.330000, 0.027500, 0.085000, 0.235000, 0.357500, 0.245000, 0.225000, 0.260000, 0.330000, 0.122500
## -0.145000, -0.275000, -0.185000, -0.037500, -0.125000, 0.032500, -0.052500, 0.005000, 0.240000, 0.340000, 0.327500, 0.255000, 0.242500, 0.362500, 0.370000
#
# -0.155000, -0.247500, -0.200000, -0.015000, 0.122500, 0.090000, 0.005000, 0.077500, 0.215000, 0.147500, 0.287500, 0.197500, 0.240000, 0.295000, 0.327500
## -0.202500, -0.275000, -0.147500, -0.035000, 0.045000, 0.045000, -0.047500, 0.042500, 0.267500, 0.367500, 0.222500, 0.022500, 0.275000, 0.260000, 0.322500
#
# -0.065000, -0.352500, -0.230000, -0.077500, 0.005000, 0.090000, 0.037500, 0.047500, 0.160000, 0.370000, 0.325000, 0.200000, 0.297500, 0.370000, 0.370000
## -0.240000, -0.220000, -0.160000, -0.025000, 0.122500, 0.045000, 0.082500, -0.090000, 0.250000, 0.322500, 0.317500, 0.240000, 0.280000, 0.340000, 0.402500
#
# -0.052500, -0.200000, -0.130000, 0.005000, 0.005000, -0.485000, -0.040000, -0.050000, 0.247500, 0.362500, 0.182500, 0.242500, 0.297500, 0.400000, 0.432500
## -0.035000, -0.325000, -0.152500, -0.037500, 0.120000, -0.015000, 0.032500, 0.087500, 0.125000, 0.210000, 0.280000, 0.120000, 0.082500, 0.330000, 0.295000
#
# -0.065000, -0.315000, -0.155000, -0.055000, -0.202500, -0.035000, 0.090000, 0.125000, 0.260000, 0.245000, 0.160000, 0.167500, 0.240000, 0.012500, 0.327500
## -0.112500, -0.122500, -0.120000, 0.012500, 0.120000, 0.172500, 0.137500, 0.135000, 0.282500, 0.287500, 0.242500, 0.247500, 0.295000, 0.405000, 0.345000
#
# -0.112500, -0.307500, -0.127500, -0.035000, 0.127500, 0.187500, 0.115000, 0.080000, 0.160000, 0.407500, 0.342500, 0.250000, 0.317500, 0.120000, 0.395000
## -0.147500, -0.152500, -0.107500, -0.037500, 0.120000, 0.052500, 0.125000, 0.207500, 0.335000, 0.325000, 0.372500, 0.112500, 0.295000, 0.365000, 0.357500
#
# -0.112500, -0.357500, -0.077500, 0.005000, -0.045000, 0.147500, 0.127500, 0.037500, 0.330000, 0.450000, 0.267500, 0.227500, 0.302500, 0.365000, 0.407500
## -0.142500, -0.150000, -0.147500, 0.005000, 0.165000, 0.167500, 0.160000, 0.195000, 0.367500, -0.245000, 0.140000, 0.330000, 0.182500, 0.355000, 0.407500
#
# x_count = 15
## y_count = 15
#
# mesh_x_pps = 2
## mesh_y_pps = 2
#
# algo = bicubic
## tension = 0.2
#
# min_x = 15.0
## max_x = 229.9
#
# min_y = 15.0
## max_y = 229.9
#
#
## [probe]
#
# z_offset = -0.170
##
#
# [stepper_z]
## position_endstop = 2.760
#
#
## [extruder]
#
# control = pid
## pid_kp = 32.303
#
# pid_ki = 1.976
## pid_kd = 132.037
#
#
## [heater_bed]
#
# control = pid
## pid_kp = 68.901
#
# pid_ki = 1.215
## pid_kd = 976.672
#
#
## [bed_mesh 15x15]
#
# version = 1
## points =
#
# -0.777500, -0.850000, -0.895000, -0.792500, -0.632500, -0.932500, -0.637500, -0.665000, -0.592500, -0.460000, -0.537500, -0.682500, -0.715000, -0.640000, -1.017500
## -1.085000, -1.102500, -0.887500, -0.755000, -0.582500, -0.615000, -0.662500, -0.777500, -0.562500, -0.485000, -0.512500, -0.717500, -0.755000, -0.647500, -0.665000
#
# -0.795000, -0.805000, -0.827500, -0.730000, -0.632500, -0.565000, -0.645000, -0.687500, -0.650000, -0.477500, -0.517500, -0.632500, -0.672500, -0.572500, -0.982500
## -0.890000, -0.807500, -0.935000, -0.687500, -0.677500, -0.522500, -0.762500, -0.677500, -0.677500, -0.422500, -0.487500, -0.682500, -0.715000, -0.627500, -0.902500
#
# -0.802500, -0.722500, -0.825000, -0.735000, -0.555000, -0.545000, -1.007500, -0.645000, -0.557500, -0.430000, -0.485000, -0.625000, -0.650000, -0.542500, -0.950000
## -0.647500, -0.647500, -0.732500, -0.665000, -0.490000, -0.467500, -0.542500, -0.605000, -0.545000, -0.392500, -0.602500, -0.652500, -0.710000, -0.632500, -0.905000
#
# -0.685000, -0.835000, -0.747500, -0.750000, -0.547500, -0.472500, -0.592500, -0.617500, -0.437500, -0.352500, -0.427500, -0.595000, -0.662500, -0.515000, -0.867500
## -0.642500, -0.655000, -0.765000, -0.655000, -0.447500, -0.520000, -0.547500, -0.637500, -0.480000, -0.362500, -0.422500, -0.625000, -0.642500, -0.550000, -0.725000
#
# -0.565000, -0.680000, -0.912500, -0.667500, -0.472500, -0.477500, -0.552500, -0.552500, -0.440000, -0.287500, -0.362500, -0.500000, -0.550000, -0.437500, -0.850000
## -0.487500, -0.625000, -0.680000, -0.575000, -0.417500, -0.390000, -0.690000, -0.527500, -0.392500, -0.285000, -0.382500, -0.510000, -0.580000, -0.475000, -0.505000
#
# -0.512500, -0.595000, -0.642500, -0.565000, -0.400000, -0.357500, -0.435000, -0.490000, -0.340000, -0.250000, -0.360000, -0.635000, -0.540000, -0.550000, -0.782500
## -0.477500, -0.517500, -0.777500, -0.542500, -0.330000, -0.295000, -0.410000, -0.432500, -0.320000, -0.265000, -0.320000, -0.490000, -0.630000, -0.420000, -0.757500
#
# -0.762500, -0.962500, -0.797500, -0.680000, -0.377500, -0.305000, -0.595000, -0.470000, -0.280000, -0.192500, -0.197500, -0.545000, -0.517500, -0.517500, -0.675000
## -1.185000, -0.660000, -0.600000, -0.435000, -0.280000, -0.320000, -0.345000, -0.525000, -0.227500, -0.157500, -0.227500, -0.435000, -0.562500, -0.667500, -0.805000
#
# -0.605000, -0.525000, -0.607500, -0.475000, -0.320000, -0.252500, -0.357500, -0.427500, -0.230000, -0.112500, -0.215000, -0.440000, -0.600000, -0.405000, -0.510000
## x_count = 15
#
# y_count = 15
## mesh_x_pps = 2
#
# mesh_y_pps = 2
## algo = bicubic
#
# tension = 0.2
## min_x = 15.0
#
# max_x = 229.9
## min_y = 15.0
#
# max_y = 229.9
##
#
# [bed_mesh 15 hot]
## version = 1
#
# points =
## -0.452500, -0.550000, -0.380000, -0.170000, -0.135000, -0.372500, -0.127500, 0.037500, 0.150000, 0.125000, 0.015000, 0.030000, 0.225000, 0.160000, 0.012500
#
# -0.487500, -0.505000, -0.300000, -0.127500, -0.142500, -0.160000, -0.170000, 0.102500, 0.172500, 0.110000, 0.020000, 0.130000, 0.157500, 0.095000, 0.012500
## -0.460000, -0.525000, -0.297500, -0.082500, -0.092500, -0.125000, -0.065000, 0.012500, 0.222500, 0.177500, 0.055000, 0.147500, 0.265000, 0.212500, 0.012500
#
# -0.502500, -0.537500, -0.292500, -0.090000, -0.070000, -0.120000, -0.292500, 0.137500, 0.230000, 0.140000, 0.137500, 0.195000, 0.312500, 0.260000, 0.092500
## -0.497500, -0.540000, -0.547500, -0.100000, -0.055000, -0.117500, -0.047500, 0.195000, 0.250000, 0.262500, 0.115000, 0.227500, 0.330000, 0.310000, 0.105000
#
# -0.452500, -0.412500, -0.225000, -0.067500, -0.032500, -0.077500, 0.002500, 0.202500, 0.262500, 0.255000, 0.055000, 0.245000, 0.337500, 0.310000, 0.105000
## -0.417500, -0.562500, -0.365000, -0.047500, 0.000000, -0.062500, -0.025000, 0.192500, 0.317500, 0.270000, 0.172500, 0.237500, 0.355000, 0.327500, 0.167500
#
# -0.400000, -0.420000, -0.227500, -0.010000, 0.020000, -0.037500, 0.022500, 0.260000, 0.337500, 0.295000, 0.227500, 0.295000, 0.380000, 0.257500, 0.217500
## -0.412500, -0.415000, -0.227500, -0.012500, 0.015000, -0.040000, 0.037500, 0.260000, 0.375000, 0.322500, 0.275000, 0.332500, 0.442500, 0.200000, 0.222500
#
# -0.380000, -0.382500, -0.180000, 0.017500, 0.050000, -0.017500, 0.090000, 0.287500, 0.415000, 0.360000, 0.257500, 0.360000, 0.460000, 0.385000, 0.257500
## -0.377500, -0.367500, -0.137500, 0.040000, 0.092500, 0.030000, 0.117500, 0.300000, 0.425000, 0.375000, 0.285000, 0.332500, 0.455000, 0.327500, 0.252500
#
# -0.397500, -0.390000, -0.145000, 0.057500, 0.105000, -0.117500, 0.157500, 0.377500, 0.432500, 0.417500, 0.337500, 0.410000, 0.500000, 0.467500, 0.292500
## -0.462500, -0.362500, -0.177500, 0.032500, -0.067500, 0.065000, 0.150000, 0.375000, 0.502500, 0.420000, 0.357500, 0.177500, 0.550000, 0.475000, 0.307500
#
# -0.417500, -0.377500, -0.147500, 0.062500, 0.105000, 0.097500, 0.175000, 0.377500, 0.507500, 0.460000, 0.385000, 0.257500, 0.557500, 0.537500, 0.385000
## -0.425000, -0.375000, -0.217500, 0.085000, 0.152500, 0.105000, 0.220000, 0.295000, 0.502500, 0.435000, 0.365000, 0.425000, 0.540000, 0.462500, 0.312500
#
# x_count = 15
## y_count = 15
#
# mesh_x_pps = 2
## mesh_y_pps = 2
#
# algo = bicubic
## tension = 0.2
#
# min_x = 15.0
## max_x = 229.9
#
# min_y = 15.0
## max_y = 229.9
#
#
## [bed_mesh 25 hot]
#
# version = 1
## points =
#
# -0.722500, -0.252500, -0.117500, -0.047500, -0.055000, 0.010000, 0.020000, 0.050000, 0.177500, 0.360000, 0.435000, 0.490000, 0.492500, 0.495000, 0.445000, 0.560000, 0.607500, 0.732500, 0.732500, 0.762500, 0.737500, 0.602500, 0.587500, 0.592500, 0.582500
## -0.325000, -0.200000, -0.070000, 0.017500, 0.030000, 0.030000, 0.052500, 0.100000, 0.200000, 0.242500, 0.432500, 0.487500, 0.497500, 0.470000, 0.455000, 0.490000, 0.637500, 0.720000, 0.765000, 0.725000, 0.750000, 0.645000, 0.582500, 0.607500, 0.680000
#
# -0.365000, -0.150000, -0.005000, 0.010000, 0.050000, 0.052500, -0.017500, 0.115000, 0.225000, 0.352500, 0.425000, 0.315000, 0.525000, 0.507500, 0.480000, 0.517500, 0.527500, 0.750000, 0.755000, 0.770000, 0.442500, 0.622500, 0.600000, 0.650000, 0.585000
## -0.385000, -0.282500, -0.022500, 0.017500, 0.075000, -0.155000, 0.112500, 0.125000, 0.240000, 0.355000, 0.480000, 0.550000, 0.507500, 0.482500, 0.515000, 0.505000, 0.647500, 0.620000, 0.792500, 0.707500, 0.742500, 0.657500, 0.600000, 0.255000, 0.642500
#
# -0.362500, -0.190000, -0.097500, 0.025000, 0.060000, -0.190000, 0.082500, 0.110000, 0.270000, 0.397500, 0.477500, 0.505000, 0.552500, 0.520000, 0.507500, 0.587500, 0.682500, 0.617500, 0.820000, 0.822500, 0.802500, 0.712500, 0.395000, 0.497500, 0.692500
## -0.510000, -0.402500, -0.095000, -0.047500, -0.132500, -0.092500, 0.097500, 0.142500, 0.255000, 0.405000, 0.437500, 0.512500, 0.522500, 0.542500, 0.550000, 0.577500, 0.682500, 0.785000, 0.745000, 0.790000, 0.765000, 0.710000, 0.657500, 0.662500, 0.722500
#
# -0.495000, -0.167500, -0.142500, 0.002500, -0.040000, 0.007500, 0.082500, 0.105000, 0.212500, 0.395000, 0.472500, 0.567500, 0.530000, 0.472500, 0.562500, 0.627500, 0.727500, 0.830000, 0.725000, 0.875000, 0.785000, 0.750000, 0.757500, 0.755000, 0.802500
## -0.287500, -0.142500, -0.002500, 0.072500, 0.080000, 0.085000, 0.107500, 0.102500, 0.257500, 0.390000, 0.520000, 0.592500, 0.610000, 0.560000, 0.580000, 0.620000, 0.750000, 0.852500, 0.885000, 0.812500, 0.837500, 0.762500, 0.747500, 0.755000, 0.805000
#
# -0.485000, -0.155000, -0.005000, 0.050000, 0.087500, 0.087500, 0.080000, -0.027500, 0.277500, 0.157500, 0.520000, 0.560000, 0.595000, 0.540000, 0.555000, 0.735000, 0.757500, 0.842500, 0.872500, 0.547500, 0.820000, 0.777500, 0.700000, 0.457500, 0.817500
## -0.232500, -0.070000, -0.107500, 0.080000, 0.115000, 0.080000, 0.120000, 0.000000, 0.287500, 0.427500, 0.555000, 0.612500, 0.615000, 0.565000, 0.605000, 0.630000, 0.727500, 0.820000, 0.910000, 0.877500, 0.852500, 0.647500, 0.677500, 0.767500, 0.817500
#
# -0.397500, -0.167500, -0.237500, 0.092500, 0.092500, 0.107500, 0.110000, 0.182500, 0.315000, 0.457500, 0.600000, 0.577500, 0.600000, 0.587500, 0.610000, 0.657500, 0.755000, 0.867500, 0.900000, 0.872500, 0.867500, 0.795000, 0.470000, 0.755000, 0.802500
## -0.235000, -0.080000, 0.012500, 0.112500, 0.125000, 0.122500, -0.345000, 0.235000, 0.335000, 0.482500, 0.562500, 0.625000, 0.615000, 0.572500, 0.612500, 0.400000, 0.602500, 0.877500, 0.905000, 0.915000, 0.842500, 0.455000, 0.780000, 0.787500, 0.825000
#
# -0.245000, -0.085000, -0.177500, 0.027500, 0.097500, -0.010000, 0.170000, 0.230000, 0.265000, 0.472500, 0.530000, 0.610000, 0.620000, 0.580000, 0.470000, 0.697500, 0.787500, 0.900000, 0.907500, 0.932500, 0.890000, 0.822500, 0.802500, 0.855000, 0.885000
## -0.212500, -0.117500, 0.042500, 0.135000, 0.170000, 0.127500, 0.162500, 0.237500, 0.362500, 0.485000, 0.597500, 0.610000, 0.665000, 0.617500, 0.642500, 0.707500, 0.837500, 0.912500, 0.957500, 0.910000, 0.910000, 0.867500, 0.830000, 0.840000, 0.877500
#
# -0.215000, -0.075000, 0.045000, 0.115000, 0.157500, 0.145000, 0.105000, 0.197500, 0.242500, 0.507500, 0.607500, 0.585000, 0.672500, 0.640000, 0.640000, 0.705000, 0.697500, 0.920000, 0.965000, 0.975000, 0.897500, 0.885000, 0.810000, 0.865000, 0.947500
## -0.160000, -0.165000, -0.272500, 0.100000, 0.132500, 0.172500, 0.192500, 0.255000, 0.395000, 0.545000, 0.627500, 0.667500, 0.685000, 0.667500, 0.682500, 0.750000, 0.567500, 0.957500, 0.995000, 1.000000, 0.937500, 0.842500, 0.837500, 0.655000, 0.920000
#
# -0.187500, -0.055000, 0.087500, 0.162500, 0.145000, -0.072500, 0.202500, 0.277500, 0.402500, 0.557500, 0.647500, 0.717500, 0.652500, 0.647500, 0.652500, 0.735000, 0.837500, 0.965000, 0.962500, 0.995000, 0.920000, 0.885000, 0.865000, 0.875000, 0.762500
## -0.130000, -0.032500, 0.080000, 0.037500, 0.207500, 0.210000, 0.187500, 0.292500, 0.407500, 0.515000, 0.670000, 0.717500, 0.722500, 0.667500, 0.677500, 0.740000, 0.637500, 0.925000, 1.007500, 1.007500, 0.952500, 0.872500, 0.865000, 0.910000, 0.952500
#
# -0.285000, -0.412500, 0.030000, 0.067500, 0.232500, 0.192500, 0.162500, 0.192500, 0.430000, 0.592500, 0.667500, 0.725000, 0.732500, 0.515000, 0.722500, 0.797500, 0.910000, 0.792500, 1.007500, 1.027500, 0.947500, 0.907500, 0.880000, 0.885000, 0.955000
## -0.207500, -0.035000, 0.020000, 0.165000, 0.040000, 0.227500, 0.227500, 0.317500, 0.482500, 0.567500, 0.710000, 0.727500, 0.630000, 0.735000, 0.740000, 0.760000, 0.902500, 0.830000, 1.017500, 1.037500, 0.985000, 0.920000, 0.907500, 0.897500, 0.970000
#
# -0.227500, -0.077500, 0.075000, 0.197500, 0.170000, 0.197500, 0.245000, 0.325000, 0.445000, 0.610000, 0.482500, 0.760000, 0.752500, 0.745000, 0.732500, 0.822500, 0.895000, 1.030000, 1.065000, 1.082500, 1.000000, 0.957500, 0.940000, 0.595000, 0.930000
## -0.210000, -0.032500, 0.045000, 0.120000, 0.110000, 0.202500, 0.255000, 0.330000, 0.435000, 0.600000, 0.702500, 0.770000, 0.750000, 0.732500, 0.747500, 0.832500, 0.930000, 0.905000, 1.040000, 1.057500, 1.015000, 0.870000, 0.915000, 0.957500, 1.007500
#
# -0.242500, -0.032500, -0.377500, -0.077500, 0.000000, 0.200000, 0.265000, 0.350000, 0.482500, 0.605000, 0.725000, 0.777500, 0.767500, 0.722500, 0.760000, 0.735000, 0.960000, 0.875000, 1.075000, 1.072500, 1.002500, 0.952500, 0.790000, 0.950000, 1.022500
## -0.200000, -0.042500, 0.082500, 0.027500, 0.235000, 0.227500, 0.272500, 0.352500, 0.485000, 0.640000, 0.715000, 0.757500, 0.777500, 0.750000, 0.740000, 0.465000, 0.962500, 1.050000, 1.047500, 0.787500, 0.997500, 0.535000, 0.945000, 0.945000, 1.032500
#
# -0.240000, -0.050000, 0.055000, 0.100000, 0.272500, 0.200000, 0.082500, 0.362500, 0.502500, 0.637500, 0.715000, 0.795000, 0.787500, 0.762500, 0.787500, 0.870000, 0.542500, 1.137500, 1.067500, 1.065000, 1.000000, 0.945000, 0.527500, 0.625000, 0.960000
## x_count = 25
#
# y_count = 25
## mesh_x_pps = 2
#
# mesh_y_pps = 2
## algo = bicubic
#
# tension = 0.2
## min_x = 15.0
#
# max_x = 229.8
## min_y = 15.0
#
# max_y = 229.8
##
#
# [bed_mesh new]
## version = 1
#
# points =
## -0.342500, -0.135000, -0.162500, -0.137500, -0.345000, 0.042500, 0.235000, 0.050000, 0.130000, 0.280000, 0.192500, 0.317500, 0.395000, 0.400000, 0.560000, 0.530000, 0.565000, 0.585000, 0.512500, 0.467500, 0.477500, -0.377500, 0.475000, 0.617500, 0.572500
#
# -0.132500, -0.042500, -0.167500, -0.175000, -0.067500, 0.072500, 0.200000, 0.290000, 0.155000, 0.275000, 0.240000, 0.242500, 0.262500, 0.397500, 0.422500, 0.552500, 0.582500, 0.520000, 0.372500, 0.427500, 0.390000, -0.302500, 0.587500, 0.565000, 0.592500
## -0.090000, -0.090000, -0.037500, -0.255000, -0.002500, 0.072500, 0.205000, 0.270000, 0.287500, 0.322500, 0.257500, 0.242500, 0.277500, 0.400000, 0.480000, 0.552500, 0.550000, 0.562500, 0.397500, 0.425000, 0.437500, 0.485000, 0.572500, 0.547500, 0.572500
#
# -0.127500, -0.085000, -0.122500, -0.145000, -0.020000, 0.000000, 0.157500, 0.292500, 0.310000, 0.310000, 0.192500, 0.245000, 0.312500, 0.360000, 0.482500, 0.567500, 0.590000, 0.527500, 0.527500, 0.460000, 0.437500, 0.490000, 0.582500, 0.490000, 0.442500
## -0.040000, -0.085000, -0.165000, -0.040000, -0.035000, 0.082500, 0.230000, 0.305000, 0.287500, 0.270000, 0.207500, 0.240000, 0.280000, 0.362500, 0.485000, 0.192500, 0.592500, 0.442500, 0.442500, 0.480000, 0.395000, 0.452500, 0.562500, 0.602500, 0.532500
#
# -0.077500, -0.100000, -0.137500, -0.205000, 0.000000, 0.060000, 0.167500, 0.215000, 0.315000, 0.310000, 0.192500, 0.280000, 0.277500, 0.415000, 0.480000, 0.542500, 0.602500, 0.545000, 0.432500, 0.447500, 0.495000, 0.550000, 0.515000, 0.550000, 0.562500
## -0.110000, -0.167500, -0.092500, -0.037500, -0.047500, 0.037500, 0.195000, 0.200000, 0.265000, 0.277500, 0.272500, 0.277500, 0.282500, 0.375000, 0.475000, 0.600000, 0.555000, 0.555000, 0.500000, 0.457500, 0.475000, 0.547500, 0.530000, 0.455000, 0.622500
#
# -0.075000, -0.130000, -0.070000, -0.090000, -0.087500, 0.112500, 0.115000, 0.267500, 0.347500, 0.325000, 0.285000, 0.277500, 0.067500, 0.440000, 0.520000, 0.537500, 0.557500, 0.552500, 0.472500, 0.480000, 0.442500, 0.527500, 0.615000, 0.632500, 0.620000
## -0.030000, -0.040000, -0.160000, -0.075000, -0.045000, -0.040000, 0.202500, 0.247500, 0.300000, 0.282500, 0.245000, 0.232500, 0.282500, 0.430000, 0.450000, 0.600000, 0.497500, 0.582500, 0.460000, 0.495000, 0.475000, 0.522500, 0.562500, 0.550000, 0.562500
#
# -0.070000, -0.077500, -0.147500, -0.082500, -0.085000, 0.082500, 0.225000, 0.307500, 0.327500, 0.250000, 0.260000, 0.275000, 0.310000, 0.455000, 0.497500, 0.550000, 0.577500, 0.555000, 0.437500, 0.482500, 0.440000, 0.527500, 0.555000, 0.635000, 0.557500
## -0.080000, -0.075000, -0.130000, -0.127500, -0.032500, -0.142500, 0.200000, 0.312500, 0.325000, 0.315000, 0.285000, 0.232500, 0.310000, 0.405000, 0.537500, 0.522500, 0.610000, 0.557500, 0.472500, 0.445000, 0.472500, 0.555000, 0.607500, 0.622500, 0.550000
#
# -0.032500, -0.040000, -0.122500, -0.082500, 0.000000, 0.122500, 0.237500, 0.312500, 0.112500, 0.285000, 0.230000, 0.247500, 0.290000, 0.425000, 0.547500, 0.607500, 0.582500, 0.577500, 0.517500, 0.497500, 0.487500, 0.545000, 0.617500, 0.430000, 0.605000
## -0.095000, -0.012500, -0.022500, -0.005000, -0.012500, 0.122500, 0.205000, 0.320000, 0.350000, 0.305000, 0.200000, 0.295000, 0.280000, 0.315000, 0.557500, 0.595000, 0.562500, 0.547500, 0.462500, 0.422500, 0.467500, 0.442500, 0.620000, 0.547500, 0.630000
#
# -0.042500, -0.087500, -0.210000, -0.067500, 0.032500, 0.130000, 0.242500, 0.315000, 0.320000, 0.310000, 0.312500, 0.160000, 0.320000, 0.422500, 0.515000, 0.600000, 0.632500, 0.477500, 0.555000, 0.430000, 0.480000, 0.537500, 0.617500, 0.645000, 0.530000
## -0.010000, -0.037500, -0.065000, -0.127500, 0.000000, 0.120000, 0.245000, 0.315000, 0.360000, 0.332500, 0.322500, 0.252500, 0.325000, 0.445000, 0.560000, 0.275000, 0.637500, 0.570000, 0.517500, 0.427500, 0.522500, 0.627500, 0.685000, 0.642500, 0.545000
#
# 0.005000, -0.082500, -0.040000, -0.370000, 0.035000, 0.167500, 0.227500, 0.275000, 0.232500, 0.355000, 0.315000, 0.265000, 0.385000, 0.480000, -0.070000, 0.590000, 0.655000, 0.610000, 0.470000, 0.470000, 0.552500, 0.597500, 0.670000, 0.660000, 0.667500
## -0.077500, -0.140000, -0.077500, -0.077500, -0.042500, 0.157500, 0.282500, 0.267500, 0.385000, 0.377500, 0.237500, 0.355000, 0.385000, 0.487500, 0.592500, 0.672500, 0.550000, 0.535000, 0.520000, 0.485000, 0.517500, 0.552500, 0.582500, 0.565000, 0.625000
#
# -0.085000, -0.182500, -0.122500, -0.085000, 0.075000, 0.190000, 0.272500, 0.375000, 0.307500, 0.400000, 0.225000, 0.262500, 0.407500, 0.517500, 0.472500, 0.677500, 0.647500, 0.557500, 0.560000, 0.497500, 0.550000, 0.595000, 0.632500, 0.707500, 0.680000
## -0.085000, -0.172500, -0.072500, -0.087500, 0.082500, 0.167500, 0.330000, 0.355000, 0.437500, 0.390000, 0.392500, 0.325000, 0.437500, 0.530000, 0.517500, 0.722500, 0.692500, 0.500000, 0.565000, 0.550000, 0.562500, 0.590000, 0.685000, 0.722500, 0.532500
#
# -0.005000, -0.402500, -0.020000, 0.030000, 0.042500, 0.195000, 0.285000, 0.387500, 0.432500, 0.417500, 0.407500, 0.397500, 0.392500, 0.272500, 0.567500, 0.685000, 0.725000, 0.622500, 0.562500, 0.572500, 0.605000, 0.705000, 0.682500, 0.585000, 0.640000
## 0.035000, 0.002500, -0.002500, -0.047500, 0.080000, 0.127500, 0.325000, 0.440000, 0.470000, 0.407500, 0.392500, 0.432500, 0.472500, 0.555000, 0.680000, 0.720000, 0.717500, 0.670000, 0.650000, 0.590000, 0.607500, 0.670000, 0.715000, 0.757500, 0.687500
#
# -0.005000, -0.035000, 0.002500, -0.002500, -0.005000, 0.220000, 0.325000, 0.432500, 0.480000, 0.440000, 0.440000, 0.380000, 0.480000, 0.582500, 0.567500, 0.727500, 0.755000, 0.695000, 0.675000, 0.547500, 0.582500, 0.627500, 0.727500, 0.775000, 0.765000
## -0.047500, -0.042500, -0.040000, 0.035000, 0.037500, 0.215000, 0.292500, 0.435000, 0.477500, 0.455000, 0.380000, 0.357500, 0.440000, 0.562500, 0.700000, 0.712500, 0.727500, 0.637500, 0.602500, 0.550000, 0.602500, 0.672500, 0.597500, 0.757500, 0.710000
#
# -0.005000, 0.007500, -0.080000, -0.165000, 0.120000, 0.245000, 0.342500, 0.432500, 0.485000, 0.475000, 0.397500, 0.400000, 0.477500, 0.605000, 0.687500, 0.705000, 0.705000, 0.557500, 0.667500, 0.637500, 0.627500, 0.637500, 0.722500, 0.755000, 0.722500
## -1.887500, 0.032500, -0.027500, 0.002500, 0.037500, 0.157500, 0.290000, 0.395000, 0.397500, 0.400000, 0.440000, 0.475000, 0.440000, 0.597500, 0.672500, 0.702500, 0.715000, 0.717500, 0.625000, 0.637500, 0.590000, 0.710000, 0.630000, 0.755000, 0.795000
#
# x_count = 25
## y_count = 25
#
# mesh_x_pps = 2
## mesh_y_pps = 2
#
# algo = bicubic
## tension = 0.2
#
# min_x = 15.0
## max_x = 229.8
#
# min_y = 15.0
#*# max_y = 229.8

@ChipCE
Copy link
Author

ChipCE commented Oct 21, 2023

@Shaneweston seem like you use the wrong version of the post processcing script.

use this https://raw.githubusercontent.com/ChipCE/Slicer-profile/master/cura-slicer/scripts/KlipperPrintArea.py

@tc60045
Copy link

tc60045 commented Oct 30, 2023

I am with @Shaneweston -- some probs with Cura (v5.5 in my case). Fix below

Error shows up in cura log:
2023-10-30 14:00:06,919 - ERROR - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [227]: Exception: Exception occurred while loading post processing plugin: module 'PostProcessingPlugin.PostProcessingPlugin.MeshPrintSize' has no attribute 'MeshPrintSize'

Note that this is when copying in the "frankbags" python script referenced.

The trick is to (a) clean up unnecceary line breaks that demonstrate Frank Bags needs to read PEP8, as who puts a double line break under a def?! (Guido and I curse your name from our high horses), then (b) name the file KlipperPrintArea.py.

Cura will then load the KlipperPrintArea.py script when it restarts, and you can add the script to post processing in the menu.

@frankbags
Copy link

@tc60045

First, this isn't my version of the script. My version ( https://gist.github.com/frankbags/c85d37d9faff7bce67b6d18ec4e716ff ) , while not optimal doesn't have a double line break after the def. Only the version @ChipCE has modified and linked to.

Second, screw Python and the horse it rode in on.

@tc60045
Copy link

tc60045 commented Oct 30, 2023

Ha! @frankbags -- touche!

@ChipCE
Copy link
Author

ChipCE commented Oct 30, 2023

@tc60045 It's my fault, not frankbags's. Thanks for point out the problem!

@frankbags Thanks for the script. It works wonderfully. I don't remember and understand why I have to make my copy of it in the first place.

@gitvisual
Copy link

gitvisual commented Jan 1, 2024

Hi!

Im having some weird issue. I know the bed is perfectly leveled from the printheads POV since i used one of those micrometer gauge attached on printhead.
When i print a first-layer-level-test without bed mesh enabled it gets really good. But when i enable it it drags the nozzle on the bed on some areas
image

It's almost as it's misreading the probes and tries to compensate down when it's not needed.

What am i doing wrong?
Can i add something to make it run better?

(I'm running Klipper on a Creality Sonic Pad, printing on a Ender 3 S1 Pro)

Below are my printer.cfg and macro.cfg (or rather the parts from those files with relevant information)

Printer.cfg:

[bltouch]
sensor_pin: ^PC14       #signal check port ^stand for pull up
control_pin: PC13       #singal control prot
x_offset: -30.0
y_offset: -40.0
#z_offset: 0          #z off_set configuration
speed: 20
stow_on_each_sample = false #high speed for bltoch,
samples: 1
samples_result: median
#probe_with_touch_mode = true

[bed_mesh]
probe_count = 6,6
algorithm = lagrange
# probe_count = 6,6
# algorithm = lagrange
# # probe_count = 20,20
# # algorithm = bicubic
# # # probe_count = 20,20
# # # algorithm = bicubic
speed: 150
mesh_min: 15,30         #need to handle head distance with bl_touch
mesh_max: 210,190       #max probe range
# # # # probe_count: 5,5
fade_start: 1
fade_end: 10
fade_target: 0
# # # # algorithm: bicubic

[bed_screws]
screw1: 25, 33
screw2: 202, 33
screw3: 202, 202
screw4: 25, 202

[gcode_macro G29]				#界面中增加G29指令
gcode:
  G28
  bed_mesh_calibrate
  G1 X0 Y0 Z10 F4200
  # save_config

[gcode_arcs]
#resolution: 1.0

#*# <---------------------- SAVE_CONFIG ---------------------->
#*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
#*#
#*# [bltouch]
#*# z_offset = 2.325
#*#
#*# [input_shaper]
#*# shaper_type_x = mzv
#*# shaper_freq_x = 53.4
#*# shaper_type_y = mzv
#*# shaper_freq_y = 40.8
#*#
#*# [bed_mesh default]
#*# version = 1
#*# points =
#*# 	  -0.170000, -0.157500, -0.107500, -0.121250
#*# 	  -0.097500, -0.120000, -0.092500, -0.063750
#*# 	  -0.086250, -0.061250, -0.022500, -0.055000
#*# 	  -0.036250, -0.072500, -0.056250, -0.042500
#*# x_count = 4
#*# y_count = 4
#*# mesh_x_pps = 2
#*# mesh_y_pps = 2
#*# algo = lagrange
#*# tension = 0.2
#*# min_x = 68.6
#*# max_x = 181.4
#*# min_y = 48.599999999999994
#*# max_y = 161.4

Macro.cfg:

# Cura start G-Code:
# START_PRINT EXTRUDER_TEMP={material_print_temperature_layer_0} BED_TEMP={material_bed_temperature_layer_0} AREA_START=%MINX%,%MINY% AREA_END=%MAXX%,%MAXY%
[gcode_macro START_PRINT]
variable_parameter_EXTRUDER_TEMP: 200
variable_parameter_BED_TEMP: 60
; gcode parameters for area bed mesh
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
gcode:
  G92 E0 ; Reset Extruder
  {% set BED_TEMP = params.BED_TEMP|default(60)|float %}
  {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(190)|float %}

  
  M104 S{EXTRUDER_TEMP} ; Start heating extruder
  M140 S{BED_TEMP} ; Start heating bed
  G28 ; Home all axes
  M190 S{BED_TEMP} ; Wait for bed to reach temp before proceeding
  
  
  BED_MESH_CALIBRATE AREA_START={params.AREA_START|default("0,0")} AREA_END={params.AREA_END|default("0,0")} ; Auto bed leveling
  G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
  G1 X0.1 Y20 Z0.3 F5000.0 ; Move to start position
  M109 S{EXTRUDER_TEMP} ; Wait for extruder to reach temp before proceeding
  G1 X0.1 Y200.0 Z0.3 F1500.0 E15 ; Draw the first line
  G1 X0.4 Y200.0 Z0.3 F5000.0 ; Move to side a little
  G1 X0.4 Y20 Z0.3 F1500.0 E30 ; Draw the second line
  G92 E0 ; Reset Extruder
  G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
  G1 X5 Y20 Z0.3 F5000.0 ; Move over to prevent blob squish

[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_BASE
; gcode parameters
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
; the clearance between print area and probe area 
variable_mesh_area_offset : 5.0
; number of sample per probe point
variable_probe_samples : 3
; minimum probe count
variable_min_probe_count : 4
; scale up the probe count, should be 1.0 ~ < variable_max_probe_count/variable_min_probe_count
variable_probe_count_scale_factor : 1.0
; enable preference index
variable_enable_reference_index : False
gcode:
    {% if params.AREA_START and params.AREA_END %}
        {% set bedMeshConfig = printer["configfile"].config["bed_mesh"] %}
        {% set safe_min_x = bedMeshConfig.mesh_min.split(",")[0]|float %}
        {% set safe_min_y = bedMeshConfig.mesh_min.split(",")[1]|float %}
        {% set safe_max_x = bedMeshConfig.mesh_max.split(",")[0]|float %}
        {% set safe_max_y = bedMeshConfig.mesh_max.split(",")[1]|float %}

        {% set area_min_x = params.AREA_START.split(",")[0]|float %}
	{% set area_min_y = params.AREA_START.split(",")[1]|float %}
	{% set area_max_x = params.AREA_END.split(",")[0]|float %}
	{% set area_max_y = params.AREA_END.split(",")[1]|float %}

	{% if bedMeshConfig.probe_count.split(",")|length == 2 %}
            {% set meshPointX = bedMeshConfig.probe_count.split(",")[0]|int %}
            {% set meshPointY = bedMeshConfig.probe_count.split(",")[1]|int %}
        {% else %}
            {% set meshPointX = bedMeshConfig.probe_count.split(",")[0]|int %}
            {% set meshPointY = bedMeshConfig.probe_count.split(",")[0]|int %}
        {% endif %}

	{% set meshMaxPointX = meshPointX %}
	{% set meshMaxPointY = meshPointY %}


        {% if (area_min_x < area_max_x) and (area_min_y < area_max_y) %}
            {% if area_min_x - mesh_area_offset >=  safe_min_x %}
                {% set area_min_x = area_min_x - mesh_area_offset %}
            {% else %}
                {% set area_min_x = safe_min_x %}
            {% endif %}

            {% if area_min_y - mesh_area_offset >=  safe_min_y %}
                {% set area_min_y = area_min_y - mesh_area_offset %}
            {% else %}
                {% set area_min_y = safe_min_y %}
            {% endif %}

            {% if area_max_x + mesh_area_offset <=  safe_max_x %}
                {% set area_max_x = area_max_x + mesh_area_offset %}
            {% else %}
                {% set area_max_x = safe_max_x %}
            {% endif %}

            {% if area_max_y + mesh_area_offset <=  safe_max_y %}
                {% set area_max_y = area_max_y + mesh_area_offset %}
            {% else %}
                {% set area_max_y = safe_max_y %}
            {% endif %}

            {% set meshPointX = (meshPointX * (area_max_x - area_min_x) / (safe_max_x - safe_min_x) * probe_count_scale_factor)|round(0)|int %}
            {% if meshPointX < min_probe_count %}
                {% set meshPointX = min_probe_count %}
            {% endif %}
	    {% if meshPointX > meshMaxPointX %}
                {% set meshPointX = meshMaxPointX %}
            {% endif %}

            {% set meshPointY = (meshPointY * (area_max_y -area_min_y ) / (safe_max_y - safe_min_y) * probe_count_scale_factor )|round(0)|int %}
            {% if meshPointY < min_probe_count %}
                {% set meshPointY = min_probe_count %}
            {% endif %}
	    {% if meshPointY > meshMaxPointY %}
                {% set meshPointY = meshMaxPointY %}
            {% endif %}

            {% set algorithm = "bicubic" %}
	    {% if "algorithm" in bedMeshConfig %}
	        {% set algorithm = bedMeshConfig.algorithm %}
            {% endif %}
            {% if meshPointX >=7 or meshPointY >=7 %}
                {% set algorithm = "bicubic" %}
            {% endif %}

            {% if enable_reference_index %}
                {% set referenceIndex = (meshPointX * meshPointY / 2 - 1 )|round(0)|int %}
                BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} samples={probe_samples|int} algorithm={algorithm} relative_reference_index={referenceIndex}
            {% else %}
                BED_MESH_CALIBRATE_BASE mesh_min={area_min_x},{area_min_y} mesh_max={area_max_x},{area_max_y} probe_count={meshPointX},{meshPointY} samples={probe_samples|int} algorithm={algorithm}
            {% endif %}
        {% else %}
            BED_MESH_CALIBRATE_BASE
        {% endif %}
    {% else %}
        BED_MESH_CALIBRATE_BASE
    {% endif %}

@frankbags
Copy link

Can you run PROBE_ACCURACY and see if it's giving constant readings, your probe could be broken. If it's consistent can you run the PROBE_CALIBRATE command again and make sure that your x/y offsets are correct, the bl touch should move to where the nozzle was after it homes.

@gitvisual
Copy link

It is very consistent and the offsets are spot on 👌🏻.
Todat I thought I found the issue, the gantry was somewhat tilted. I fixed that and hopes for the best, but no. If the bed itself is warped the auto-bed-leveling should compensate for that, right? I can feel the z-axis compensating, but everyone the nozzle goes over one of those areas (where the heightmap says its higher), the nozzle drags on the bed. Is it not compensating enough?

@numanair
Copy link

numanair commented Jan 2, 2024

@gitvisual That sounds like you have some twist to your motion. The closer/more aligned the probe is (XY) with the nozzle the better for dealing with twist.

@gitvisual
Copy link

@numanair I'm sorry but I don't really understand, can you explain that for me?

@numanair
Copy link

numanair commented Jan 4, 2024

@gitvisual Let's say your x axis rail/extrusion has a twist to it and you have a probe which is offset from the nozzle on the x-direction. This twist causes the carriage to rotate as it moves left-right, which causes the nozzle to move in the z-direction a little. Since the probe is offset, the carriage is at a different location when probing as it is when printing at the same probed point. Hence there is a difference in what the probe and the nozzle "see".

@gitvisual
Copy link

gitvisual commented Jan 4, 2024

@numanair Thank you for the explanation. I read about klippers new function (from 0.12.0) "Axis_twist_compensation". Unfortunately I run klippy on a sonic pad that only has klipper 0.11.0.
I tried ssh into the pad and wget the axis_twist_compensation.py - file (along with probe.py) directly from klipper3d GitHub page.
This made it possible to use the function from my sonic pad but I'm not sure it actually uses the calibration or not since it doesn't make the prints any better (or worse).

@dagno-IT
Copy link

Hi, thank you for your amazing work!!!
Works perfectly for mine with cura, but it probes the wrong area, it doesn't use the bltouch y_offset parameter so it probes the area "in front" of the print area.

Thank you in advance for your help

############ printer.cfg ###############
[bltouch] # enable for BLTouch
control_pin: PA8
sensor_pin: ^PA11
#control_pin: PA4
#sensor_pin: ^PC4
#pin_up_touch_mode_reports_triggered: False
Probe_with_touch_mode: True
stow_on_each_sample: False
y_offset: 27.5
samples: 3
samples_result: median
sample_retract_dist: 5.0
samples_tolerance: 0.01
samples_tolerance_retries: 3

[safe_z_home]
home_xy_position: 112, 157 # Change coordinates to the center of your print bed
speed: 50
z_hop: 10 # Move up 10mm
z_hop_speed: 5

[bed_mesh]
speed: 120
horizontal_move_z: 5
mesh_min: 12, 80
mesh_max: 212, 225
probe_count: 5, 5
mesh_pps: 2, 3
algorithm: bicubic
bicubic_tension: 0.2

######### Cura start gcode ##########
G21 ; metric values
G90 ; absolute positioning
M82 ; set extruder to absolute mode
M107 ; start with the fan off
G92 E0 ; Reset Extruder
M104 S140 ; extruder pretemp
M190 S{material_bed_temperature_layer_0} ; wait for bed temp
G28 ; Home all axes
BED_MESH_CALIBRATE AREA_START=%MINX%,%MINY% AREA_END=%MAXX%,%MAXY%
G1 Z1 F3000 ;
G1 X1 Y20 F3000 ;
G1 Z0.4 F300 ; Move Z Axis DOWN little
M109 S{material_print_temperature_layer_0} ; wait for extruder temp
G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
G1 X0.1 Y25 Z0.3 F5000.0 ; Move to start position
G1 X0.1 Y200.0 Z0.3 F1500.0 E15 ; Draw the first line
G1 X0.4 Y200.0 Z0.3 F5000.0 ; Move to side a little
G1 X0.4 Y25 Z0.3 F1500.0 E30 ; Draw the second line
G92 E0 ; Reset Extruder
G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
G1 X5 Y25 Z0.3 F5000.0 ; Move over to prevent blob squish

@mohalsa
Copy link

mohalsa commented Jan 25, 2024

I am using a single line Gcode in Orca slicer and a macro in my klipper, I can't seem to get it to work with ORCA Slicer, What would be the start and end Gcode in Orca slicer in order to make it parse the correct data and act upon it.

This is my current Machine Code in Orca slicer:

START_PRINT EXTRUDER_TEMP=[nozzle_temperature_initial_layer] BED_TEMP=[bed_temperature_initial_layer]

This is my klipper START_PRINT macro:

[gcode_macro START_PRINT]
variable_parameter_EXTRUDER_TEMP: 220
variable_parameter_BED_TEMP: 65
variable_parameter_AREA_START : 0,0
variable_parameter_AREA_END : 0,0
gcode:
  {% set BED_TEMP = params.BED_TEMP|default(60)|float %}
  {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(200)|float %}
  M190 S{BED_TEMP}
  ;Set and wait for nozzle to reach temperature
  M109 S{EXTRUDER_TEMP}
  G28
  ;Enable the below line to allow auto bed mesh generation for the object being printed.
  BED_MESH_CALIBRATE AREA_START={params.AREA_START|default("0,0")} AREA_END={params.AREA_END|default("0,0")}
  G92 E0 #Reset Extruder
  G1 Z2.0 F300 #Move Z Axis up
  G1 X10.1 Y20 Z0.28 F5000.0 #Move to start position
  G1 X10.1 Y200.0 Z0.28 F1500.0 E15 #Draw the first line
  G1 X10.4 Y200.0 Z0.28 F5000.0 #Move to side a little
  G1 X10.4 Y20 Z0.28 F1500.0 E30 #Draw the second line
  G92 E0 #Reset Extruder
  G1 Z2.0 F3000 #Move Z Axis up

@DDen87
Copy link

DDen87 commented Jan 27, 2024

@ChipCE do you have some advice on getting this working with the Orca Slicer? I believe it has something to do with the START G-code. This is how mine look like:
START_PRINT EXTRUDER_TEMP=[nozzle_temperature_initial_layer]
BED_TEMP=[bed_temperature_initial_layer_single] MATERIAL=[filament_type]
AREA_START=%MINX%,%MINY% AREA_END=%MAXX%,%MAXY%

@frankbags
Copy link

@ChipCE do you have some advice on getting this working with the Orca Slicer? I believe it has something to do with the START G-code. This is how mine look like: START_PRINT EXTRUDER_TEMP=[nozzle_temperature_initial_layer] BED_TEMP=[bed_temperature_initial_layer_single] MATERIAL=[filament_type] AREA_START=%MINX%,%MINY% AREA_END=%MAXX%,%MAXY%

This is the wrong start g-code for PrusaSlicer flavors. You are using the Cura one.

@DDen87
Copy link

DDen87 commented Jan 28, 2024

@frankbags thanks for the help! It worked!

@wwian
Copy link

wwian commented Feb 27, 2024

Hello @ChipCE!

I saw on the KLIPPER Configuration Changes (20230619) that RELATIVE_REFERENCE_INDEX is no longer available as a parameter for the BED_MESH_CALIBRATE gcode command.

Would you please update the Klipper bed mesh on print area only macro readme.md sample code to reflect this deprecation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment