protoloft / klipper_z_calibration

Klipper plugin for self-calibrating z-offset
GNU General Public License v3.0
1.05k stars 151 forks source link

Relative Reference Index Deprecated #104

Closed AustinTylerDean closed 1 year ago

AustinTylerDean commented 1 year ago

Is the deprecation going to interfere with this plugin/config?

todstelzer commented 1 year ago

It is broken...

todstelzer commented 1 year ago

Got it working. z_calibration.zip

But Variable Bed mesh macro isnt working so far. Not sure how to fix this.

todstelzer commented 1 year ago

Seems to work as well now. Praise chatGPT for it...

[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_zero_reference_position : True gcode: ATTACH_PROBE {% 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 zero_reference_position %}
            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} zero_reference_position={area_max_x},{area_max_y}
        {% 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 %}
DOCK_PROBE

I cant comment is as code. Don´t know how it should work but with `` it´s not working correctly.

AustinTylerDean commented 1 year ago

Did you use ChatGPT to fix this? If so, I would LOVE the transcript!

Secondly, I hope it helped Protoloft, if it indeed fixed the problem.

todstelzer commented 1 year ago

Its in German. I had to poke him multiple times to get what i wanted :)

For the z_calibration.py it was trial and error till i found out that i have to use printer.zero_reference_position to get the new zero_reference_position value into the *.py file. No chatGPT here.

For the variable bed mesh macro i used ChatGPT. I didnt know how to pares x and y to a single parameter and he helped me there. zero_reference_position={area_max_x},{area_max_y}

I Just printed a test part and it seems to work ^.^

AustinTylerDean commented 1 year ago

Awesome! Thank you very much! I hope this is all helpful to the author, as future releases will definitely cause people to come here asking the same question. Appreciated, Todstelzer!

todstelzer commented 1 year ago

Ok i´m not sure whats going on but it stopped working.... I tested it and did print a small part but when i tried second part nothing worked again.

todstelzer commented 1 year ago

Ok have to go to sleep now but i figured it out so i can use the printer at least. I can´t get the new value zero_reference_position applied to self.bed_site inside z_calibration. I set it now to 175,175 (line 158 in the picture). Its the middle of my bed and should work on smaller beds as well.

The new bed mesh dont use a index value. Instead, as far i can tell, it probes the zero_reference_position as the last point in the mesh. So the probe point is now fixed and not tied to the bed mesh anymore.

Screenshot 2023-06-22 023023

z_calibration.zip ets/67606371/53755b4e-644a-4f9e-8a30-041eaa5906b5)

todstelzer commented 1 year ago

You can add bed_xy_position: xxx, yyy to z_calibration.cfg and set the zero_reference_position there. It must be the same value as in printer.cfg [bed_mesh] zero_reference_position value

yanfoo commented 1 year ago

You can add bed_xy_position: xxx, yyy to z_calibration.cfg and set the zero_reference_position there. It must be the same value as in printer.cfg [bed_mesh] zero_reference_position value

Thanks, Your py file with bed_xy_position and zero_reference_position value fixed it for me.

TitusLabs commented 1 year ago

Sorry, I was just prevented for quite a while. I will fix this tomorrow...

VORONENTHUSIAST commented 1 year ago

Hey, I'm having the same issue - I'm not quite sure on how to get this new .py file working on my printer (I can build them fine, software I suck at a little!) I've tried copying the file over by downloading the new one linked in this thread and winSCP but I'm still getting the out of range message when performing the cailbration - strange thing is, if I take the auto-z macro out of everything, my variable bed mesh is working as I updated it according to the bed_mesh help file for klipper to include my zero reference position. I've added that into bed_xy_position due to relative reference index being depreciated - what am I doing wrong?

todstelzer commented 1 year ago

You can add bed_xy_position: xxx, yyy to z_calibration.cfg and set the zero_reference_position there. It must be the same value as in printer.cfg [bed_mesh] zero_reference_position value

It should work adding bed_xy_position: xxx, yyy to z_calibration or using the modded py file. There the value is hardcoded to 175, 175 Wich you have to set the ref_zero in printer.cfg - bed_mesh too.

yanfoo commented 1 year ago

This is exactly what I did and used winscp to do it. The out of range is something else, it should say what the measured range is and compare to what you set you may need to increase the range.

Sent from Outlook for Androidhttps://aka.ms/AAb9ysg


From: Uwe Söll @.> Sent: Tuesday, June 27, 2023 9:53:17 AM To: protoloft/klipper_z_calibration @.> Cc: yanfoo @.>; Comment @.> Subject: Re: [protoloft/klipper_z_calibration] Relative Reference Index Deprecated (Issue #104)

You can add bed_xy_position: xxx, yyy to z_calibration.cfg and set the zero_reference_position there. It must be the same value as in printer.cfg [bed_mesh] zero_reference_position value

It should work adding bed_xy_position: xxx, yyy to z_calibration or using the modded py file.

— Reply to this email directly, view it on GitHubhttps://github.com/protoloft/klipper_z_calibration/issues/104#issuecomment-1609557172, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMZW5MEWH6GPTKTWLIDVGM3XNLQU3ANCNFSM6AAAAAAZPED6CY. You are receiving this because you commented.Message ID: @.***>

VORONENTHUSIAST commented 1 year ago

This is exactly what I did and used winscp to do it. The out of range is something else, it should say what the measured range is and compare to what you set you may need to increase the range. Sent from Outlook for Androidhttps://aka.ms/AAb9ysg ____ From: Uwe Söll @.> Sent: Tuesday, June 27, 2023 9:53:17 AM To: protoloft/klipper_z_calibration @.> Cc: yanfoo @.>; Comment @.> Subject: Re: [protoloft/klipper_z_calibration] Relative Reference Index Deprecated (Issue #104) You can add bed_xy_position: xxx, yyy to z_calibration.cfg and set the zero_reference_position there. It must be the same value as in printer.cfg [bed_mesh] zero_reference_position value It should work adding bed_xy_position: xxx, yyy to z_calibration or using the modded py file. — Reply to this email directly, view it on GitHub<#104 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMZW5MEWH6GPTKTWLIDVGM3XNLQU3ANCNFSM6AAAAAAZPED6CY. You are receiving this because you commented.Message ID: @.***>

Yeah, it's really strange, it's putting X to 360 something, and y to around 680?! I'm on a 310x310 bed so tried 155 x and 155 y as well as 162.5 for the bed_xy_position (came from my old klippy log when using the relative_reference_index before updating) yet both produced this result, I have given up for now, as removing the z_calibrate from my start macro has gotten me printing with an adaptive mesh, but it would be nice to have again!

Sorry, should have added - it's only done this since I can no longer use the relative_reference_index, this is why I'm so confused

todstelzer commented 1 year ago

Can you post/link your printer.cfg [bed_mesh] section and calibrate_z.cfg? Maybe its a typo somewhere.

nozzle_xy_position: 227,353

Maybe you used a . instead of a , ?

VORONENTHUSIAST commented 1 year ago

Can you post/link your printer.cfg [bed_mesh] section and calibrate_z.cfg? Maybe its a typo somewhere.

nozzle_xy_position: 227,353

Maybe you used a . instead of a , ?

Thank you for being so willing to take a look for me :)

This is my bed_mesh section:

[bed_mesh] speed: 175 horizontal_move_z: 10

--------------------------------------------------------------------

Uncomment below for 250mm build

mesh_min: 40, 40

mesh_max: 210, 210

Uncomment for 300mm build

mesh_min: 40, 40

mesh_max: 275, 275

Uncomment for 350mm build

mesh_min: 40, 40

mesh_max: 310, 310

Uncomment for Custom build plate Size

mesh_min: 40, 40 mesh_max: 285, 285

--------------------------------------------------------------------

zero_reference_position: 155, 155 probe_count: 7,9 # Values should be odd, so one point is directly at bed center mesh_pps: 2, 3 fade_start: 1 fade_end: 10 algorithm: bicubic bicubic_tension: 0.2

Here is my calibrate_z:

[z_calibration] nozzle_xy_position: 196.5, 310 switch_xy_offsets: 5.5, -19.43 bed_xy_position: 155, 155 wiggle_xy_offsets: 185, 310 switch_offset: 3.44 safe_z_height: 5

position_min: 0.625 (Hashed out as reading directly from printer.cfg after using SAVE_CONFIG command)

start_gcode: Attach_Probe

before_switch_gcode:

end_gcode: Dock_Probe

Sorry for not attaching a link for them, not 100% sure how to do it (I know, I'm sounding really stupid right now!)

VORONENTHUSIAST commented 1 year ago

Oh, if needed, here is my bed_mesh_calibrate macro - I have gone for KAMP:

[gcode_macro SETUP_KAMP_MESHING] gcode: SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=display_parameters VALUE={params.DISPLAY_PARAMETERS|default(True)|int} SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=led_enable VALUE={params.LED_ENABLE|default(False)|int} SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=status_macro VALUE='"{params.STATUS_MACRO|default('status_meshing')|string}"'

SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=fuzz_enable VALUE={params.FUZZ_ENABLE|default(False)|int} SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=fuzz_min VALUE={params.FUZZ_MIN|default(0)|float} SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=fuzz_max VALUE={params.FUZZ_MAX|default(4)|float}

SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=probe_dock_enable VALUE={params.PROBE_DOCK_ENABLE|default(False)|int} SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=attach_macro VALUE='"{params.ATTACH_MACRO|default('Attach_Probe')|string}"' SET_GCODE_VARIABLE MACRO=BED_MESH_CALIBRATE VARIABLE=detach_macro VALUE='"{params.DETACH_MACRO|default('Dock_Probe')|string}"'

[gcode_macro BED_MESH_CALIBRATE] rename_existing: _BED_MESH_CALIBRATE

This section configures mesh point fuzzing, which allows probe points to be varied slightly if printing multiples of the same G-code file.

variable_fuzz_enable: False # Enables/disables the use of mesh point fuzzing to slightly randomize probing points to spread out wear on a build surface, default is False. variable_fuzz_min: 2 # If enabled, the minimum amount in mm a probe point can be randomized, default is 0. variable_fuzz_max: 7 # If enabled, the maximum amount in mm a probe point can be randomized, default is 4.

This section is for configuring a mesh margin, which allows the probed mesh to be expanded outwards from the print area.

variable_margin_enable: False # Enables/disables adding a margin to the meshed area to pad a mesh out for specific needs, default is False. variable_margin_size: 5 # Size in millimeters to expand the mesh outwards from the print area in all directions.

This section is for those using a dockable probe that is stored outside of the print area.

variable_probe_dock_enable: False # Enables/disables the use of a dockable probe that is stored outside of the print area, default is False. variable_attach_macro: 'Attach_Probe' # Here is where you define the macro that ATTACHES the probe to the printhead. E.g. 'Attach_Probe' variable_detach_macro: 'Dock_Probe' # Here is where you define the macro that DETACHES the probe from the printhead. E.g. 'Dock_Probe'

This section is for those who are using Moonraker's Update Manager for KAMP, or want a more verbose macro.

variable_display_parameters: True # Display macro paramters in the console, useful for debugging the SETUP_KAMP_MESHING call, or more verbosity.

gcode:

{% if display_parameters == True %}
  { action_respond_info("status_macro: \'%s\'" % (status_macro))  }
  { action_respond_info("fuzz_enable : %d" % (fuzz_enable))  }
  { action_respond_info("fuzz_min    : %f" % (fuzz_min))  }
  { action_respond_info("fuzz_max    : %f" % (fuzz_max))  }
  { action_respond_info("probe_dock_enable: %d" % (probe_dock_enable))  }
  { action_respond_info("attach_macro: \'%s\'" % (attach_macro))  }
  { action_respond_info("detach_macro: \'%s\'" % (detach_macro))  }
{% endif %}

{% set all_points = printer.exclude_object.objects | map(attribute='polygon') | sum(start=[]) %}
{% set bed_mesh_min = printer.configfile.settings.bed_mesh.mesh_min %}
{% set bed_mesh_max = printer.configfile.settings.bed_mesh.mesh_max %}
{% set probe_count = printer.configfile.settings.bed_mesh.probe_count %}
{% set probe_count = probe_count if probe_count|length > 1 else probe_count * 2  %}
{% set max_probe_point_distance_x = ( bed_mesh_max[0] - bed_mesh_min[0] ) / (probe_count[0] - 1)  %}
{% set max_probe_point_distance_y = ( bed_mesh_max[1] - bed_mesh_min[1] ) / (probe_count[1] - 1)  %}
{% set x_min = all_points | map(attribute=0) | min | default(bed_mesh_min[0]) %}
{% set y_min = all_points | map(attribute=1) | min | default(bed_mesh_min[1]) %}
{% set x_max = all_points | map(attribute=0) | max | default(bed_mesh_max[0]) %}
{% set y_max = all_points | map(attribute=1) | max | default(bed_mesh_max[1]) %}

{% if margin_enable == False %}
    {% set margin_size = 0 %}
{% endif %}

{ action_respond_info("{} object points, clamping to bed mesh [{!r} {!r}]".format(
    all_points | count,
    bed_mesh_min,
    bed_mesh_max,
)) }

{% if fuzz_enable == True %}
    {% set fuzz_range = range((fuzz_min * 100) | int, (fuzz_max * 100) | int + 1) %}
    {% set x_min = (bed_mesh_min[0] + fuzz_max - margin_size, x_min) | max - (fuzz_range | random / 100.0) %}
    {% set y_min = (bed_mesh_min[1] + fuzz_max - margin_size, y_min) | max - (fuzz_range | random / 100.0) %}
    {% set x_max = (bed_mesh_max[0] - fuzz_max + margin_size, x_max) | min + (fuzz_range | random / 100.0) %}
    {% set y_max = (bed_mesh_max[1] - fuzz_max + margin_size, y_max) | min + (fuzz_range | random / 100.0) %}
{% else %}
    {% set x_min = [ bed_mesh_min[0], x_min - margin_size ] | max %}
    {% set y_min = [ bed_mesh_min[1], y_min - margin_size ] | max %}
    {% set x_max = [ bed_mesh_max[0], x_max + margin_size ] | min %}
    {% set y_max = [ bed_mesh_max[1], y_max + margin_size ] | min %}
{% endif %}

{ action_respond_info("Object bounds, clamped to the bed_mesh: {!r}, {!r}".format(
    (x_min, y_min),
    (x_max, y_max),
)) }

{% set points_x = (((x_max - x_min) / max_probe_point_distance_x) | round(method='ceil') | int) + 1 %}
{% set points_y = (((y_max - y_min) / max_probe_point_distance_y) | round(method='ceil') | int) + 1 %}

{% if (([points_x, points_y]|max) > 6) %}
    {% set algorithm = "bicubic" %}
    {% set min_points = 4 %}
{% else %}
    {% set algorithm = "lagrange" %}
    {% set min_points = 3 %}
{% endif %}
{ action_respond_info( "Algorithm: {}".format(algorithm)) }

{% set points_x = [points_x, min_points]|max  %}
{% set points_y = [points_y, min_points]|max  %}
{ action_respond_info( "Points: x: {}, y: {}".format(points_x, points_y) ) }

{% if printer.configfile.settings.bed_mesh.relative_reference_index is defined %}
    {% set ref_index = (points_x * points_y / 2) | int %}
    { action_respond_info( "Reference index: {}".format(ref_index) ) }
{% else %}
    {% set ref_index = -1 %}
{% endif %}

{% if probe_dock_enable == True %}
    {attach_macro}              # Attach/deploy a probe if the probe is stored somewhere outside of the print area
{% endif %}

{% if led_enable == True %}
    {status_macro}              # Set status LEDs
{% endif %}

_BED_MESH_CALIBRATE mesh_min={x_min},{y_min} mesh_max={x_max},{y_max} ALGORITHM={algorithm} PROBE_COUNT={points_x},{points_y} RELATIVE_REFERENCE_INDEX={ref_index}

{% if probe_dock_enable == True %}
    {detach_macro}              # Detach/stow a probe if the probe is stored somewhere outside of the print area
{% endif %}
todstelzer commented 1 year ago

Hmm looks good. Did you try and switch on/off the printer already? And what happens when you use my .py with commented out bed_xy_position: 155, 155? In the .py the position is 175,175 if there is no bed_xy_position defined.

If thats not fix it you have to wait for @TitusLabs to change the code.

VORONENTHUSIAST commented 1 year ago

I did the switch off and on, sadly no dice, I will have a look back through the .py file and report back in a bit - just finishing a print and about to have some evening time with the family :)

it would be nice to try and figure this out before the fix is implemented, but knowing my knowledge limits, I might be better off waiting hahaha! :D

todstelzer commented 1 year ago

Its line 151 to 153 in the py for bed_xy_position parameter. And line 158 in my py its set to a fixed value of 175,175. But with bed_xy_position it should work with the original py.

https://github.com/protoloft/klipper_z_calibration/issues/104#issuecomment-1601855604

VORONENTHUSIAST commented 1 year ago

Yeah, this is where my lack of knowledge is evident - I'm looking at lines 151 through 170 of your .py file and can't understand how it's hard coded to 175, 175? calibration py

VORONENTHUSIAST commented 1 year ago

Okay, I'm really confused now - I have downloaded the included .zip from your comment, have looked at the file and then relooked at your screengrab from above - they are vastly different - I will change the file I have here to what your screen grab looks like (obviously switching out 175, 175 to my parameters) and let you know what happens!

todstelzer commented 1 year ago

That isnt my py file. I redownloaded it and it has the chances in it.

grafik

VORONENTHUSIAST commented 1 year ago

yeah, would help if I kept up with the avatars next to comments!!

Actually downloaded yours this time! made the change to the section where you put your bed parameters, lets see what happens!!

Thanks for your patience with me! :D

todstelzer commented 1 year ago

Ah you download the first py file. You have to use the py file attached to the picture below it

VORONENTHUSIAST commented 1 year ago

Well, I would test it again, but now for some reason when I unhash my include line for the auto_z_calibrate and the parts inside the print start macro, save the config and reboot, it is ignoring the change and leaving them hashed. I really don't think this is a question for here, as you've done enough for me - so I will get this sorted and then report back if it's working or not. I'm assuming that it will now I have the correct py file!! ;)

VORONENTHUSIAST commented 1 year ago

Right, everything has saved properly - opened winSCP again to look at the .py, it's the correct one - did the CALIBRATE_Z function - still giving me an out of range error - "!! Move out of range: 381.500 620.000 3.685 [0.000]"

This is super perplexing!!

@TitusLabs please comment on here when you have implemented the updates and merged this, or whatever it is you will be doing, looks like I need the professional touch over my hack and slash attempt! :D

todstelzer commented 1 year ago

Maybe it´s a missing G90. Try G90 in console and than CALIBRATE_Z

VORONENTHUSIAST commented 1 year ago

Maybe it´s a missing G90. Try G90 in console and than CALIBRATE_Z

Can confirm this hasn't worked either :/ something just isn't playing right

todstelzer commented 1 year ago

Try out my z_calib macro:

[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 : 3 ; scale up the probe count, should be 1.0 ~ < variable_max_probe_count/variable_min_probe_count variable_probe_count_scale_factor : 0.7 ; enable preference index variable_enable_reference_index : True gcode: _CheckProbe action=query Attach_Probe {% 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 meshPointX >=4 or meshPointY >=4 %}
            {% set algorithm = "bicubic" %}
        {% endif %}

        {% if enable_reference_index %}
            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}
        {% 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 %}
Dock_Probe
VORONENTHUSIAST commented 1 year ago

Thanks, can I put this in below the KAMP section of my macro, replacing my BED_MESH_CALIBRATE section, or shall I just use this config as a file in its own right, replacing my one completely for the minute?

todstelzer commented 1 year ago

Copy your own macro in printer cfg to a text file to save it and paste my macro in and test it.

VORONENTHUSIAST commented 1 year ago

Added it in, restarted, and got the following error:

File contains parsing errors: /home/mks/klipper_config/Macros/Bed_Mesh_Calibrate.cfg

[line 19]: '{% if params.AREA_START and params.AREA_END %}\n' [line 97]: '{% else %}\n' [line 99]: '{% endif %}\n'

Once the underlying issue is corrected, use the "RESTART" command to reload the config and restart the host software. Printer is halted

Damn I feel like the dog begging for a bone now, I'm so sorry I'm taking up your time!!

todstelzer commented 1 year ago

Thats my printer.cfg right now. printer.zip

VORONENTHUSIAST commented 1 year ago

Thanks, copying it from there worked.

I've just rebooted the printer again by turning it off at the wall and it's still producing the same error, very peculiar.

At this point I'm just going to leave it alone and wait to see what happens. Thanks so much for all your help though!

todstelzer commented 1 year ago

You can try and ask in the Voron discord Klipper section for help. I hope you will find the problem. Good luck! https://discord.gg/voron

VORONENTHUSIAST commented 1 year ago

They will undoubtedly (and rightly so) berate me for pressing the update button with no good reason... when will I learn, if it ain't broke don't fix it! :')

Luckily I haven't updated the firmware on my other 2.4, so that one will still play ball! :D

Honestly I can't thank you enough for your help, I'm sure I will have it working again on this machine when the main repo gets updated with the changes!

Something I do want to point out about my issue - it does take the print head back to the endstop and drop to it, then rise once before this error message appears, don't know if that makes any difference to anyone? For now I'm back to printing without this fancy plugin

TitusLabs commented 1 year ago

So, first of all, thank you for pointing that out. I had not noticed it yet.

Furthermore, you can still use the relative reference index. No printer has to stand still here :smile:

I have just uploaded a fix in the development branch that should work with both an older Klipper version and with a current Klipper version with relative reference index or zero reference_position configured.

Feel free to give me feedback

VORONENTHUSIAST commented 1 year ago

Hi, Titus, thanks so much for the response, sadly the relative reference index has now thrown the printer into halting and has to be removed from the config file :/

I will look to update to the fix in the development branch once I've worked out how to do that (I'm really not very good at this side of things) and let you know how it goes :)

TitusLabs commented 1 year ago

No, the relative reference index is only marked as deprecated. My printer worked just fine after updating Klipper to the current version. The plugin breaks if you replace the relative reference index with the newer zero reference position (and there is no bed position configured). You don't have to to that right now...

VORONENTHUSIAST commented 1 year ago

That's so strange, mine just wouldn't work?! I'm gonna have to go back and re-look at that, as I didn't have any problems before trying to use this zero reference position!

VORONENTHUSIAST commented 1 year ago

No, the relative reference index is only marked as deprecated. My printer worked just fine after updating Klipper to the current version. The plugin breaks if you replace the relative reference index with the newer zero reference position (and there is no bed position configured). You don't have to to that right now...

Annnnd now I'm back in another loop I'd forgotten about earlier - since adding the relative reference index back in and removing the zero reference position, I'm being told my z_calibration is not a valid config section - I'm starting to loose the will over this as I can print without it just fine, hahaha

but, to confirm, yes, my printer itself is working with the relative reference index placed back in!

TitusLabs commented 1 year ago

Ok, may be too many changes at once. Try the new one from the development branch. That should work in any case now. But I don't give any guarantee for any fancy macros here :zany_face:

VORONENTHUSIAST commented 1 year ago

yeah, it's my hack and slash that's causing the problem - after placing the new file in using winSCP, it keeps loading blank when I turn on the machine - I need to learn more about linux, SSH, etc. and do this properly I think, I have a feeling it's using 3 or 4 different interfaces to make all of my changes!

I LOVE this macro, it makes my machine feel more 'professional' if you like, having a full calibration before each print starts is really cool to look at too!! :D

VORONENTHUSIAST commented 1 year ago

IT'S WORKING!!!!!!!

SO!! instead of replacing the file again, I opened the current one on my machine using winSCP, pasted the information from your development branch file (my file was blank, no deleting needed) I then saved this and reloaded it.

After this, I then SSH'd into my Pi using Putty (I say Pi, I'm actually using the MKS SKIPR board so have their equivalent on board the PCB) and used the sudo reboot command. This then rebooted my machine and it all loaded - I just ran the Z_CALIBRATE command on my console and low and behold, it worked!!! :D

I am so happy to have this back up and running again, at least for the minute - I will now need to ponder as to why it's not working with the zero_reference_position ready for when they get rid of relative reference completely!

TitusLabs commented 1 year ago

Great :+1:

You always need to reload Klipper when you change a python file!

Now, you should be able to use the zero_reference_position too...

VORONENTHUSIAST commented 1 year ago

I'll create a separate file using that, upload it and let you know how it goes!!

VORONENTHUSIAST commented 1 year ago

I have a slight bit of tweaking to do on my switch offset -this is a little higher than I'd like, but the grin on my face definitely isn't!! Thanks so much @TitusLabs and @todstelzer for your help, it's super appreciated!!

Auto_Z_Calibrate

TitusLabs commented 1 year ago

It's released :+1: