Skip to content

Commit

Permalink
First import
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamYellen committed Aug 8, 2022
1 parent 712558d commit b18c835
Show file tree
Hide file tree
Showing 16 changed files with 1,636 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.bkp
printer-*-????????_*.cfg
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "config"]
path = config
url = https://github.com/AdamYellen/RatOS-configuration
108 changes: 108 additions & 0 deletions TEST_SPEED.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Home, get position, throw around toolhead, home again.
# If MCU stepper positions (first line in GET_POSITION) are greater than a full step different (your number of microsteps), then skipping occured.
# We only measure to a full step to accomodate for endstop variance.
# Example: TEST_SPEED SPEED=300 ACCEL=5000 ITERATIONS=10

[gcode_macro TEST_SPEED]
gcode:
# Speed
{% set speed = params.SPEED|default(printer.configfile.settings.printer.max_velocity)|int %}
# Iterations
{% set iterations = params.ITERATIONS|default(5)|int %}
# Acceleration
{% set accel = params.ACCEL|default(printer.configfile.settings.printer.max_accel)|int %}
# Bounding inset for large pattern (helps prevent slamming the toolhead into the sides after small skips, and helps to account for machines with imperfectly set dimensions)
{% set bound = params.BOUND|default(20)|int %}
# Size for small pattern box
{% set smallpatternsize = SMALLPATTERNSIZE|default(20)|int %}

# Large pattern
# Max positions, inset by BOUND
{% set x_min = printer.toolhead.axis_minimum.x + bound %}
{% set x_max = printer.toolhead.axis_maximum.x - bound %}
{% set y_min = printer.toolhead.axis_minimum.y + bound %}
{% set y_max = printer.toolhead.axis_maximum.y - bound %}

# Small pattern at center
# Find X/Y center point
{% set x_center = (printer.toolhead.axis_minimum.x|float + printer.toolhead.axis_maximum.x|float ) / 2 %}
{% set y_center = (printer.toolhead.axis_minimum.y|float + printer.toolhead.axis_maximum.y|float ) / 2 %}

# Set small pattern box around center point
{% set x_center_min = x_center - (smallpatternsize/2) %}
{% set x_center_max = x_center + (smallpatternsize/2) %}
{% set y_center_min = y_center - (smallpatternsize/2) %}
{% set y_center_max = y_center + (smallpatternsize/2) %}

# Save current gcode state (absolute/relative, etc)
SAVE_GCODE_STATE NAME=TEST_SPEED

# Output parameters to g-code terminal
{ action_respond_info("TEST_SPEED: starting %d iterations at speed %d, accel %d" % (iterations, speed, accel)) }

# Absolute positioning
G90

# Set new limits
SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel} ACCEL_TO_DECEL={accel / 2}

# Home and get position for comparison later:
G28
# QGL if not already QGLd (only if QGL section exists in config)
{% if printer.configfile.settings.quad_gantry_level %}
{% if printer.quad_gantry_level.applied == False %}
QUAD_GANTRY_LEVEL
G28 Z
{% endif %}
{% endif %}
G0 X{printer.toolhead.axis_maximum.x} Y{printer.toolhead.axis_maximum.y} F{30*60}
G4 P1000
GET_POSITION

# Go to starting position
G0 X{x_min} Y{y_min} Z{bound + 10} F{speed*60}

{% for i in range(iterations) %}
# Large pattern
# Diagonals
G0 X{x_min} Y{y_min} F{speed*60}
G0 X{x_max} Y{y_max} F{speed*60}
G0 X{x_min} Y{y_min} F{speed*60}
G0 X{x_max} Y{y_min} F{speed*60}
G0 X{x_min} Y{y_max} F{speed*60}
G0 X{x_max} Y{y_min} F{speed*60}

# Box
G0 X{x_min} Y{y_min} F{speed*60}
G0 X{x_min} Y{y_max} F{speed*60}
G0 X{x_max} Y{y_max} F{speed*60}
G0 X{x_max} Y{y_min} F{speed*60}

# Small pattern
# Small diagonals
G0 X{x_center_min} Y{y_center_min} F{speed*60}
G0 X{x_center_max} Y{y_center_max} F{speed*60}
G0 X{x_center_min} Y{y_center_min} F{speed*60}
G0 X{x_center_max} Y{y_center_min} F{speed*60}
G0 X{x_center_min} Y{y_center_max} F{speed*60}
G0 X{x_center_max} Y{y_center_min} F{speed*60}

# Small box
G0 X{x_center_min} Y{y_center_min} F{speed*60}
G0 X{x_center_min} Y{y_center_max} F{speed*60}
G0 X{x_center_max} Y{y_center_max} F{speed*60}
G0 X{x_center_max} Y{y_center_min} F{speed*60}
{% endfor %}

# Restore max speed/accel/accel_to_decel to their configured values
SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel} ACCEL_TO_DECEL={printer.configfile.settings.printer.max_accel_to_decel}

# Re-home and get position again for comparison:
G28
# Go to XY home positions (in case your homing override leaves it elsewhere)
G0 X{printer.toolhead.axis_maximum.x} Y{printer.toolhead.axis_maximum.y} F{30*60}
G4 P1000
GET_POSITION

# Restore previous gcode state (absolute/relative, etc)
RESTORE_GCODE_STATE NAME=TEST_SPEED
134 changes: 134 additions & 0 deletions adaptive_bed_mesh.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#########################################
########## ADAPTIVE BED MESH ############
#########################################
# Written by Frix_x#0161 #

### What is it ? ###

# The adaptive bed mesh is simple: it's a normal bed mesh, but only "where" and "when" it's necessary.
# Sometime I print small parts, sometime I print full plates and I like to get a precise bed_mesh (like 9x9 or more). However, it take a
# lot of time and it's useless to probe all the plate for only a 5cm² part in the center. So this is where the adaptive bed mesh is helping:
# 1. It get the corners coordinates of the fisrt layer surface from the slicer
# 2. It compute a new set of points to probe on this new zone to get at least the same precision as your standard bed mesh. For example, if
# a normal bed mesh is set to 9x9 for 300mm², it will then compute 3x3 for a 100mm² surface. Also if for whatever reason your parts are in
# the corner of the build plate (like for a damaged PEI in the center), it will follow them to probe this exact area.
# 3. As the probed point computed are odd, it will also compute the new relative reference index point in the center of the zone
# 4. To go further, the macro will not do any bed_mesh if there is less than 3x3 points to probe (very small part alone) and choose/change the
# algorithm (bicubic/lagrange) depending of the size and shape of the mesh computed (like 3x3 vs 3x9)

### Installation ###
# 1. You need to change some custom settings in your slicer:
# a. SuperSlicer is easy: add in your custom g_code PRINT_START macro the SIZE argument like this:
# PRINT_START [all your shit..] SIZE={first_layer_print_min[0]}_{first_layer_print_min[1]}_{first_layer_print_max[0]}_{first_layer_print_max[1]}
# b. Cura is a bit more tricky as you need to install the post process plugin by frankbags called MeshPrintSize.py.
# In Cura menu, click Help > Show configuration folder. Copy the python script from the following link into the plugins folder: https://gist.github.com/frankbags/c85d37d9faff7bce67b6d18ec4e716ff#file-meshprintsize-py
# Then restart Cura and select in the menu: Extensions > Post processing > select Mesh Print Size
# At the end, change your custom g_code PRINT_START macro the SIZE argument like this:
# PRINT_START [all your shit..] SIZE=%MINX%_%MINY%_%MAXX%_%MAXY%
# 2. In klipper, configure a normal [bed_mesh] section in your config as you want for your machine (it will be the base to compute the new adaptive bed mesh). Keep
# in mind that you can push the precision a little bit with a mesh of 9x9 for example as not all the points will be probed.
# 3. VERY IMPORTANT CHECKS:
# a. Be sure to put the "mesh_pps" entry in the [bed_mesh] section. You can choose what you want or let it to default, but even if it's optional for Klipper, it's mandatory
# to really specify it in your config for my macro to work correctly.
# b. Also check that the mesh_min, mesh_max, probe_count and mesh_pps configs entry in your [bed_mesh] section are specified using double numbers like "probe_count: 9,9"
# as my macro is waiting for TWO numbers and will fail if there is only one specified at thoose positions.
# 4. In your PRINT_START macro definition, get the SIZE argument and pass it to the ADAPTIVE_BED_MESH to start the probing sequence like so:
# {% set FL_SIZE = params.SIZE|default("0_0_0_0")|string %}
# ADAPTIVE_BED_MESH SIZE={FL_SIZE}
# 5. Optional: my macro is using the RESPOND command for debugging purposes: add the [respond] section to your config or delete all the RESPOND lines in my macro

# Feel free to ping me on Discord (Frix_x#0161) if you need help or have any comments to improve it :)


[gcode_macro ADAPTIVE_BED_MESH]
description: Perform a bed mesh, but only where and when it's needed
gcode:
# 1 ----- GET ORIGINAL BEDMESH PARAMS FROM CONFIG ----------------------
{% set xMinConf, yMinConf = printer["configfile"].config["bed_mesh"]["mesh_min"].split(',')|map('trim')|map('int') %}
{% set xMaxConf, yMaxConf = printer["configfile"].config["bed_mesh"]["mesh_max"].split(',')|map('trim')|map('int') %}
{% set xProbeCntConf, yProbeCntConf = printer["configfile"].config["bed_mesh"]["probe_count"].split(',')|map('trim')|map('int') %}
{% set algo = printer["configfile"].config["bed_mesh"]["algorithm"] %}
{% set xMeshPPS, yMeshPPS = printer["configfile"].config["bed_mesh"]["mesh_pps"].split(',')|map('trim')|map('int') %}
# If the SIZE parameter is defined and set not a dummy placeholder, we do the adaptive
# bed mesh logic. If it's ommited, we still do the original BED_MESH_CALIBRATE function
{% if params.SIZE is defined and params.SIZE != "0_0_0_0" %}

# 2 ----- GET MESH SIZE AND MARGIN FROM MACRO CALL --------------------
{% set xMinSpec, yMinSpec, xMaxSpec, yMaxSpec = params.SIZE.split('_')|map('trim')|map('int') %}
{% set margin = params.MARGIN|default(5)|int %}

# 3 ----- APPLY MARGINS ----------------------------------------------
# We use min/max function as we want it to be constrained by the original
# bedmesh size. This will avoid going outside the machine limits
{% set xMin = [xMinConf, (xMinSpec - margin)]|max %}
{% set xMax = [xMaxConf, (xMaxSpec + margin)]|min %}
{% set yMin = [yMinConf, (yMinSpec - margin)]|max %}
{% set yMax = [yMaxConf, (yMaxSpec + margin)]|min %}

# 4 ----- COMPUTE A NEW PROBE COUNT ----------------------------------
# The goal is to have at least the same precision as from the config. So we compute an equivalent number
# of probe points on each X/Y dimensions (distance between two points should be the same as in the config)
{% set xProbeCnt = ((xMax - xMin) * xProbeCntConf / (xMaxConf - xMinConf))|round(0, 'ceil')|int %}
{% set yProbeCnt = ((yMax - yMin) * yProbeCntConf / (yMaxConf - yMinConf))|round(0, 'ceil')|int %}

# Then, three possibilities :
# a) Both dimensions have less than 3 probe points : the bed_mesh is not needed as it's a small print.
# b) If one of the dimension is less than 3 and the other is greater. The print looks to be elongated and
# need the adaptive bed_mesh : we add probe points to the small direction to reach 3 and be able to do it.
# c) If both direction are greater than 3, we need the adaptive bed_mesh and it's ok.
# At the end we control (according to Klipper bed_mesh method: "_verify_algorithm") that the computed probe_count is
# valid according to the choosen algorithm or change it if needed.
{% if xProbeCnt < 3 and yProbeCnt < 3 %}
RESPOND MSG="Adaptive bed mesh: mesh not needed"

{% else %}
{% set xProbeCnt = [3, xProbeCnt]|max %}
{% set yProbeCnt = [3, yProbeCnt]|max %}

# We verify that the number of probe points on each axis is odd or add
# one to it. This is to have a relative_reference_index point at the center of the mesh
{% if xProbeCnt % 2 == 0 %}
{% set xProbeCnt = xProbeCnt + 1 %}
{% endif %}
{% if yProbeCnt % 2 == 0 %}
{% set yProbeCnt = yProbeCnt + 1 %}
{% endif %}

# Check of the probe points and interpolation algorithms according to Klipper code
{% if xMeshPPS != 0 or yMeshPPS != 0 %}
{% set probeCntMin = [xProbeCnt, yProbeCnt]|min %}
{% set probeCntMax = [xProbeCnt, yProbeCnt]|max %}
{% if algo == "lagrange" and probeCntMax > 6 %}
# Lagrange interpolation tends to oscillate when using more than 6 samples: swith to bicubic
{% set algo = "bicubic" %}
{% endif %}
{% if algo == "bicubic" and probeCntMin < 4 %}
{% if probeCntMax > 6 %}
# Impossible case: need to add probe point on the small axis to be >= 4 (we want 5 to keep it odd)
{% if xProbeCnt > yProbeCnt %}
{% set yProbeCnt = 5 %}
{% else %}
{% set xProbeCnt = 5 %}
{% endif %}
{% else %}
# In this case bicubic is not adapted (less than 4 points): switch to lagrange
{% set algo = "lagrange" %}
{% endif %}
{% endif %}
{% endif %}

# 5 ----- COMPUTE THE RELATIVE_REFERENCE_INDEX POINT --------------------
{% set rRefIndex = (((xProbeCnt * yProbeCnt) - 1) / 2)|int %}

# 6 ----- FORMAT THE PARAMETERS TO CALL BED_MESH_CALIBRATE --------------
{% set mesh_min = "%d,%d"|format(xMin, yMin) %}
{% set mesh_max = "%d,%d"|format(xMax, yMax) %}
{% set probe_count = "%d,%d"|format(xProbeCnt, yProbeCnt) %}
RESPOND MSG="Adaptive bed mesh: MESH_MIN={mesh_min} MESH_MAX={mesh_max} PROBE_COUNT={probe_count} RELATIVE_REFERENCE_INDEX={rRefIndex} ALGORITHM={algo}"
BED_MESH_CALIBRATE MESH_MIN={mesh_min} MESH_MAX={mesh_max} PROBE_COUNT={probe_count} RELATIVE_REFERENCE_INDEX={rRefIndex} ALGORITHM={algo}
{% endif %}
{% else %}
RESPOND MSG="Adaptive bed mesh: nominal bed mesh"
BED_MESH_CALIBRATE
{% endif %}
1 change: 1 addition & 0 deletions config
Submodule config added at 235095
52 changes: 52 additions & 0 deletions custom-velocities.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# ; External perimeter
# {if extrusion_role=~/ExternalPerimeter/};[extrusion_role]
# SET_VELOCITY_LIMIT ACCEL=1000 ACCEL_TO_DECEL=500 SQUARE_CORNER_VELOCITY=5

# ; Perimeter
# {elsif extrusion_role=~/Perimeter/};[extrusion_role]
# SET_VELOCITY_LIMIT ACCEL=2000 ACCEL_TO_DECEL=1000 SQUARE_CORNER_VELOCITY=5

# ; Overhang perimeter
# {elsif extrusion_role=~/OverhangPerimeter/};[extrusion_role]
# SET_VELOCITY_LIMIT ACCEL=2000 ACCEL_TO_DECEL=1000 SQUARE_CORNER_VELOCITY=5

# ; Internal infill
# {elsif extrusion_role=~/InternalInfill/};[extrusion_role]
# SET_VELOCITY_LIMIT ACCEL=5000 ACCEL_TO_DECEL=2500 SQUARE_CORNER_VELOCITY=5

# ; Top solid infill
# {elsif extrusion_role=~/TopSolidInfill/};[extrusion_role]
# SET_VELOCITY_LIMIT ACCEL=2000 ACCEL_TO_DECEL=1000 SQUARE_CORNER_VELOCITY=5

# ; Solid infill
# {elsif extrusion_role=~/SolidInfill/};[extrusion_role]
# SET_VELOCITY_LIMIT ACCEL=4000 ACCEL_TO_DECEL=2000 SQUARE_CORNER_VELOCITY=5

# ; Bridge infill
# {elsif extrusion_role=~/BridgeInfill/};[extrusion_role]
# SET_VELOCITY_LIMIT ACCEL=5000 ACCEL_TO_DECEL=2500 SQUARE_CORNER_VELOCITY=5

# ; Gap fill
# {elsif extrusion_role=~/GapFill/};[extrusion_role]
# SET_VELOCITY_LIMIT ACCEL=2000 ACCEL_TO_DECEL=1000 SQUARE_CORNER_VELOCITY=5

# ; Skirt
# {elsif extrusion_role=~/Skirt/};[extrusion_role]
# SET_VELOCITY_LIMIT ACCEL=5000 ACCEL_TO_DECEL= 2500 SQUARE_CORNER_VELOCITY=5

# ; Support material
# {elsif extrusion_role=~/SupportMaterial/};[extrusion_role]
# SET_VELOCITY_LIMIT ACCEL=5000 ACCEL_TO_DECEL= 2500 SQUARE_CORNER_VELOCITY=5

# ; Support material interface
# {elsif extrusion_role=~/SupportMaterialInterface/};[extrusion_role]
# SET_VELOCITY_LIMIT ACCEL=5000 ACCEL_TO_DECEL= 2500 SQUARE_CORNER_VELOCITY=5

# ; Thin walls
# {elsif extrusion_role=~/ThinWall/};[extrusion_role]
# SET_VELOCITY_LIMIT ACCEL=2000 ACCEL_TO_DECEL=1000 SQUARE_CORNER_VELOCITY=5

# ; Other
# {else};[extrusion_role]
# SET_VELOCITY_LIMIT ACCEL=4444 ACCEL_TO_DECEL=2222 SQUARE_CORNER_VELOCITY=5
# {endif}
1 change: 1 addition & 0 deletions input_shaper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.png
32 changes: 32 additions & 0 deletions klicky/klicky-bed-mesh-calibrate.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This macro was provided by discord user Garrettwp to whom i give my thanks for sharing it with me.
# I have tweaked it a lot.
# They are based on the great Annex magprobe dockable probe macros "#Originally developed by Mental,
# modified for better use on K-series printers by RyanG and Trails", kudos to them.
# That macro as since evolved into a klipper plugin that currently is pending inclusion in klipper,
# more information here, https://github.com/Annex-Engineering/Quickdraw_Probe/tree/main/Klipper_Macros
# User richardjm revised the macro variables and added some functions, thanks a lot
# by standing on the shoulders of giants, lets see if we can see further
#
# the current home for this version is https://github.com/jlas1/Klicky-Probe

###################
# Bed mesh calibrate
[gcode_macro BED_MESH_CALIBRATE]
rename_existing: _BED_MESH_CALIBRATE
description: Perform Mesh Bed Leveling with klicky automount
gcode:

{% set V = printer["gcode_macro _User_Variables"].verbose %}
{% if V %}
{ action_respond_info("Bed Mesh Calibrate") }
{% endif %}

_CheckProbe action=query
G90
Attach_Probe

_BED_MESH_CALIBRATE {% for p in params
%}{'%s=%s ' % (p, params[p])}{%
endfor %}

Dock_Probe
Loading

0 comments on commit b18c835

Please sign in to comment.