Macro for K-Factor (Pressure Advance) Calibration
-
I got fed up of constantly tweaking the K-Factor calibration for Marlin that you can download, so I wrote a little Macro that can be run from the Duet.
This is also by far the most reliable method for me for determining pressure advance.
https://gist.github.com/bernhardberger/555c4913d492a5213b49b2efa4f0b24e
This should work for Delta printers with the origin (0,0) at center and also cartesian printes with origin at the edge of the bed.
There are no sanity checks (yet), so be careful.
Any suggestions welcome.
Please use the code from the Gist, somehow the forum feature breaks the pasted code (adds {1} instead of newlines..?)
; adjust values to your needs var temp_nozzle = 195 var temp_bed = 55 var nozzle_diameter = 0.6 var layer_height = 0.1618 var line_width = 0.6 var pa_start = 0 var pa_end = 0.05 var pa_step_size = 0.002 var print_speed_slow_mms = 30 var print_speed_fast_mms = 200 var travel_speed_mms = 300 var travel_speed_z_mms = 300 var line_spacing = 5 var origin_x = 0 var origin_y = 0 var bed_center = true var line_length_slow = 40 var line_length_fast = 100 var fan_speed = 0.0 ; range 0.0...1.0 var dwell_time_milliseconds = 2000 var prime_nozzle = false var prime_nozzle_macro = "0:/macros/_Printing/prime_nozzle.g" ;set to "" (empty string) if you don't want to prime the nozzle, otherwise enter the macro location M291 R"Pressure Advance Calibration" P{"Start Factor: " ^ {var.pa_start} ^ ", End Factor: " ^ {var.pa_end} ^ ", Steps: " ^ {var.pa_step_size}} ; [!!!!!] DO NOT CHANGE VALUES AFTER THIS LINE [!!!!!!] ;------------------------------------------------------ ; calculated values start var print_speed_slow = {var.print_speed_slow_mms * 60} var print_speed_fast = {var.print_speed_fast_mms * 60} var travel_speed = {var.travel_speed_mms * 60} var travel_speed_z = {var.travel_speed_z_mms * 60} ; extrusion calculation taken from slic3r docs (https://manual.slic3r.org/advanced/flow-math) ; A = rectangle + circle = (line_width - layer_height)*layer_height + pi(layer_height/2) * pi(layer_height/2) var e_per_mm = {(var.line_width - var.layer_height) * var.layer_height + (pi * ((var.layer_height/2) * (var.layer_height/2)))} ; calculated values end G21 ; Millimeter units G90 ; Absolute XYZ M83 ; Relative E T0 ; Switch to tool 0 M104 S{var.temp_nozzle} M190 S{var.temp_bed} G1 Z5 F{var.travel_speed_z} ; move nozzle down M109 S{var.temp_nozzle} ; Wait for nozzle temp ;M204 S5000 P5000; Acceleration G92 E0 ; Reset extruder distance M106 S{var.fan_speed} ;turn off fan G1 X0 Y0 F{var.travel_speed} ; move nozzle to center G1 Z{var.layer_height} F{var.travel_speed_z} ; Move to layer height M572 D0 S0 ;reset pressure advance ; ==== PRIME NOZZLE START ==== if var.prime_nozzle == true if var.prime_nozzle_macro != "" M98 P{var.prime_nozzle_macro} ; ==== PRIME NOZZLE END ==== var line_length_total = {2 * var.line_length_slow + var.line_length_fast} var pos_x_start = 0 var pos_y_start = 0 if var.bed_center == true set var.pos_x_start = {-1 * (var.line_length_total / 2)} set var.pos_y_start = {-1 * var.line_spacing * ((var.pa_end - var.pa_start) / var.pa_step_size) / 2} var pos_x_end = {var.pos_x_start + var.line_length_total} var pos_y_end = {var.pos_y_start + var.line_spacing * ((var.pa_end - var.pa_start) / var.pa_step_size)} var anchor_y_start = {var.pos_y_start - var.line_spacing} var anchor_y_end = {var.pos_y_end + var.line_spacing} var anchor_y_length = {sqrt(0 + (var.anchor_y_end - var.anchor_y_start) * (var.anchor_y_end - var.anchor_y_start))} ; we only move in the y plance ; ==== ANCHOR FRAME START ==== G1 X{var.pos_x_start} Y{var.anchor_y_start} F{var.travel_speed} ; move to start G11 ; un-retract G1 X{var.pos_x_start} Y{var.anchor_y_end} E{var.e_per_mm * var.anchor_y_length} F{var.print_speed_slow} ; print line G1 X{var.pos_x_start + var.line_width} Y{var.anchor_y_end} F{var.travel_speed} ; move to start G1 X{var.pos_x_start + var.line_width} Y{var.anchor_y_start} E{var.e_per_mm * var.anchor_y_length} F{var.print_speed_slow} ; print line G10 ; retract G1 X{var.pos_x_end} Y{var.anchor_y_start} F{var.travel_speed} ; move to start G11 ; un-retract G1 X{var.pos_x_end} Y{var.anchor_y_end} E{var.e_per_mm * var.anchor_y_length} F{var.print_speed_slow} ; print line G1 X{var.pos_x_end - var.line_width} Y{var.anchor_y_end} F{var.travel_speed} ; move to start G1 X{var.pos_x_end - var.line_width} Y{var.anchor_y_start} E{var.e_per_mm * var.anchor_y_length} F{var.print_speed_slow} ; print line G10 ; retract ; ==== ANCHOR FRAME END ==== G4 P{var.dwell_time_milliseconds} ; Pause (dwell) for specified milliseconds ; ==== TEST PATTERN START (loop) ==== var pa_current = {var.pa_start} var pos_y_current = {var.pos_y_start} while {var.pa_current <= var.pa_end} G1 X{var.pos_x_start} Y{var.pos_y_current} F{var.travel_speed} ; move to start M118 S"M572 D0 S " ^ {var.pa_current} L1 M572 D0 S{var.pa_current} ; set PA factor G11 ; un-retract G1 X{var.pos_x_start + var.line_length_slow} Y{var.pos_y_current} E{var.e_per_mm * var.line_length_slow} F{var.print_speed_slow} ; print slow line G1 X{var.pos_x_start + var.line_length_slow + var.line_length_fast} Y{var.pos_y_current} E{var.e_per_mm * var.line_length_fast} F{var.print_speed_fast} ; print fast line G1 X{var.pos_x_end} Y{var.pos_y_current} E{var.e_per_mm * var.line_length_slow} F{var.print_speed_slow} ; print slow line G10 ; retract set var.pa_current = {var.pa_current + var.pa_step_size} set var.pos_y_current = {var.pos_y_current + var.line_spacing} ; ==== TEST PATTERN END ==== M0 ;finish
-
@bberger said in Macro for K-Factor (Pressure Advance) Calibration:
Please use the code from the Gist, somehow the forum feature breaks the pasted code (adds {1} instead of newlines..?)
I changed the code type to JSON (Gcode is not recognised and Highlight.js tags it a SQL for some reason) and that removes the spurious {1}s I hope this will be fixed in a future version of the markdown plugin.
-
@t3p3tony thank you!
Couldn't you use the same gcode highlighter that @chrishamm is using in DWC?
On another note:
- Is there a better way to calculate extrusion amount in RRF? (respectively a better formula than that from a multi-year old slic3r wiki?).
I already know that I need to adjust the line gap for the anchor frame (they currently overlap, didn't bother to use a formula for that).
-
can I query filament diameter and nozzle diameter from the object model? I remember that there is a gcode implemented in RRF that allows you to define nozzle diameter and filament width for the print monitor. Could be an improvement to make this work for various nozzle sozes and filament diameters without the need to edit the macro too much.
-
This could also be a nice idea for a DWC plugin some day.. pretty sure that it could be better handled as plugin in python than a gcode macro.
-
-
@bberger said in Macro for K-Factor (Pressure Advance) Calibration:
Couldn't you use the same gcode highlighter that @chrishamm is using in DWC?
Not without modifying the markdown plugin that this forum software uses.
-
@bberger said in Macro for K-Factor (Pressure Advance) Calibration:
On another note:
- Is there a better way to calculate extrusion amount in RRF? (respectively a better formula than that from a multi-year old slic3r wiki?).
I already know that I need to adjust the line gap for the anchor frame (they currently overlap, didn't bother to use a formula for that).
-
can I query filament diameter and nozzle diameter from the object model? I remember that there is a gcode implemented in RRF that allows you to define nozzle diameter and filament width for the print monitor. Could be an improvement to make this work for various nozzle sozes and filament diameters without the need to edit the macro too much.
-
This could also be a nice idea for a DWC plugin some day.. pretty sure that it could be better handled as plugin in python than a gcode macro.
For 1. that is the classic shape of an extruded line (stadium cross section). I don't think its a issue to do it that way. as long as its consistent because PA is a factor not an absolute. Slicers may use different formulas for setting the extrusion amount (and thus get different line widths) but i don't think that matters.
For 2. There is M404 https://docs.duet3d.com/User_manual/Reference/Gcodes#m404-filament-width however most people wont be using it so not a good idea to rely on.
For 3. Yes potentially a "tuning" plugin for DWC/DSF or both would be useful.