Skip to content

Instantly share code, notes, and snippets.

@noahliketheark
Forked from ChipCE/readme.md
Last active February 6, 2023 14:00
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save noahliketheark/4acd58d5604f2fb4b387caec1e0ee9a3 to your computer and use it in GitHub Desktop.
Save noahliketheark/4acd58d5604f2fb4b387caec1e0ee9a3 to your computer and use it in GitHub Desktop.
Klipper probe print area only

Klipper probe print area only install guide

What this macro do

  • This macro will dymanic change the bed_mesh area, number of probe points, and relative reference based on the size of the printed part.

Setup guide

  • (1) Confiugre [bed_mesh]. This is mine for example:
[bed_mesh]
speed: 100
horizontal_move_z: 5
mesh_min: 10,10
mesh_max: 265,230
algorithm: bicubic
bicubic_tension: 0.1
probe_count: 7,7
mesh_pps: 2,2
relative_reference_index: 24   # (5,3)=7 (3,3)=4 (5,5)=12 (7,7)=24 (7,5)=17 (9,9)=40
move_check_distance: 5.0
split_delta_z: .025
fade_start: 0.6
fade_end: 10
fade_target: 0
  • (2) This macro will replace the default BED_MESH_CALIBRATE command.
 
[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_BASE
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
variable_mesh_area_offset : 5              ## the clearance between print area and probe area
gcode=
	{% 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 invlaid for bicubic
			{% set meshPointY = 5 %}  # set 7x5 mesh
			{% endif %}
			{% endif %}
		{% if meshPointY > 5 %}
			{% if meshPointX == 3 %}  # 3x7 mesh invlaid 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 %}
  • (4) Configure START_PRINT macro. This is mine for example:
[gcode_macro START_PRINT]
variable_parameter_EXTRUDER_TEMP: 210
variable_parameter_BED_TEMP: 60
gcode:
	M140 S{params.BED_TEMP|default(60)|float}        # set bed temp
	M104 S{params.EXTRUDER_TEMP|default(200)|float}  # set extruder temp
	M117 Homing...
	SMART_HOME                               # home macro
	M117 Bed Mesh...
	BED_MESH_CALIBRATE AREA_START={params.AREA_START|default("0,0")} AREA_END={params.AREA_END|default("0,0")}
	G1 X5 Y5 z50 F2000                  # Move head xy
	M117 Waiting for bed temp
	M190 S{params.BED_TEMP|default(60)|float}        # wait for bed temp
	M117 Waiting for extruder temp
	M109 S{params.EXTRUDER_TEMP|default(200)|float}  # wait for extruder temp
	_PRIME
	M117 Printing....

[gcode_macro SMART_HOME]
gcode:
	M117 Homing...
	{% set toHome = [] %}
	{% if 'x' not in printer.toolhead.homed_axes %}
		{ toHome.append('x') or "" }
		{% endif %}
	{% if 'y' not in printer.toolhead.homed_axes %}
		{ toHome.append('y') or "" }
		{% endif %}
	{% if 'z' not in printer.toolhead.homed_axes %}
		{ toHome.append('z') or "" }
		{% endif %}
	{% if toHome|length == 0 %}
		{ action_respond_info('All axes homed!') }
		{% else %}
		G28 { toHome|join(' ') }
		{% endif %}
	M117 Homed.
	
[gcode_macro _PRIME]
gcode:
	M117 Loading Filament...
	M83                               # Uses Relative Extrusion
	G90                               # Uses Absolute Coordinates
	G1 Z50 F1000                       # Move head z
	G1 X2 Y2 F3000                    # Move head xy
	G1 Z4 F1000                       # Move head z
	G92 E0                            # Reset extruder
	G1 E80 F800                      # Load 80 mm Filament
	G92 E0                            # Reset extruder
	M117 Priming...
	G1 X10 Y2 F5000.0 ;Move to start position
	G1 X10 Y2 Z0.3 F5000.0 ;Move to start position
	G1 X160 Y2 Z0.3 F1800.0 E20 ;Draw line
	G4 P500
	G1 X180 Y2 Z3 F1800.0 ;Move to side a little
	G4 P500
	M117 Primed
  • (5) Add the following to Super Slicer start gcode: 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]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment