Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support beacon_klipper version >= 2.0.0, a.k.a Beacon Contact #637

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c660870
Create beacon_contact.cfg
crkochan Aug 9, 2024
ae1bab1
Rename homing_override.cfg to homing_override.cf_
crkochan Aug 9, 2024
a3c5b27
Don't import homing_override by default.
crkochan Aug 9, 2024
9bae3f4
Rename homing_override.cf_ to homing_override.cfg
crkochan Aug 9, 2024
d1f698d
Move homing_override include into probe configs that will use it
crkochan Aug 9, 2024
98ea159
Don't include generic_probe.cfg
crkochan Aug 9, 2024
c3e567c
Add beacon_contact to printer.cfg template
crkochan Aug 9, 2024
e09bd85
Fix typo
crkochan Aug 9, 2024
f86bd2a
Re-format heatsoak message
crkochan Aug 9, 2024
e83dabc
Add beacon max probing temp variable
crkochan Aug 10, 2024
7ab1d65
Add beacon to extruder pre-heat module
crkochan Aug 10, 2024
b051cb7
Add deactivation zhop variable for Beacon
crkochan Aug 10, 2024
28f17b6
Updated beacon_contact hardware config
crkochan Aug 10, 2024
5adc523
Add Activate/Deactivate macros for beacon_contact
crkochan Aug 10, 2024
b6b2522
Add beacon homing hooks
crkochan Aug 10, 2024
b54acdc
Remove usused vars
crkochan Aug 10, 2024
7aefef5
Fix includes and file location
crkochan Aug 10, 2024
48c722f
Add missing vars
crkochan Aug 10, 2024
5fe9bca
Add variable declaration and missing vars
crkochan Aug 10, 2024
4a993aa
Set contact optimized startprint_actions
crkochan Aug 10, 2024
8e4eb2a
Move post status_leds to delay_gcode
crkochan Aug 10, 2024
01d4a90
Forgot a variable
crkochan Aug 10, 2024
9d95044
Fix incorrect command
crkochan Aug 11, 2024
a21e8c4
Add macro variable to STATUS_LEDS
crkochan Aug 11, 2024
e27a344
Present value as a string literal
crkochan Aug 11, 2024
70a1bba
Case and quotes adjustments
crkochan Aug 11, 2024
438be2f
Change quote type
crkochan Aug 11, 2024
d43765b
More quotes
crkochan Aug 11, 2024
2ade6d1
Discard use of delayed_gcode
crkochan Aug 11, 2024
3e9e35a
Add xy hooks
crkochan Aug 11, 2024
0f64405
Add activation macro
crkochan Aug 11, 2024
2ffcb63
Add contact macro
crkochan Aug 11, 2024
619794b
Case change
crkochan Aug 11, 2024
94943a2
Add recommend homing configuration
crkochan Aug 11, 2024
44e8dde
Revert status_leds
crkochan Aug 11, 2024
fb24ffc
Hook improvments and minor bug fixes (#1)
crkochan Aug 11, 2024
d3171a0
Add fast QGL/Z-Tilt macros
crkochan Aug 11, 2024
677ebb6
Chomp whitespace
crkochan Aug 11, 2024
03afdda
Merge branch 'beacon-contact' into beacon-contact-testing
crkochan Aug 11, 2024
9006c0a
Add fast QGL/Z-Tilt macros (#2)
crkochan Aug 11, 2024
4ae2c94
Merge branch 'beacon-contact' into beacon-contact-testing
crkochan Aug 11, 2024
6aba8ad
Implement hardware check
crkochan Aug 12, 2024
2236035
Merge pull request #3 from crkochan/beacon-contact-testing
crkochan Aug 12, 2024
abe4209
Probing status flag and ensure beacon calibration (#4)
crkochan Aug 21, 2024
55b34fa
Add more quick start defaults from Beacon docs
crkochan Aug 26, 2024
f3b0501
Beacon contact testing (#5)
crkochan Aug 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions config/hardware/probes/beacon_contact.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This probe type is for a Beacon probe used directly as a virtual Z endstop
# rather than with an existing physical endstop. To use this configuration,
# you will need to manually add the Beacon Klipper plugin!

## Then, you should just add the following two lines to your overrides and everything should work!
## The rest of the allowed config entries are available on this link: config/hardware/probes/inductive_virtual.cfg
# [beacon]
# serial: /dev/serial/by-id/usb-Beacon_Beacon_...


[gcode_macro _USER_VARIABLES]
# We can declare an "inductive_virtual" probe type as it's pretty close to the Beacon way of working and should just work!
variable_probe_type_enabled: "beacon_contact"
variable_startprint_actions: "extruder_preheating", "bed_soak", "chamber_soak", "tilt_calib", "bedmesh", "extruder_heating", "purge", "clean", "primeline"
gcode:

# Beacon probe definition also include the probe management macros directly from here
[include ../../../macros/base/probing/beacon_probe.cfg]
[include ../../../macros/base/probing/overrides/beacon_probe_overrides.cfg]
[include ../../../macros/base/homing/beacon_homing_hooks.cfg]

[stepper_z]
endstop_pin: probe:z_virtual_endstop
homing_retract_dist: 0

[beacon]
home_xy_position: 117.5, 117.5 # update with your safe position
home_z_hop: 5
home_z_hop_speed: 30
home_xy_move_speed: 300
home_y_before_x: false
home_method: contact
home_method_when_homed: proximity
home_autocalibrate: unhomed
home_gcode_pre_x: _HOME_PRE_AXIS AXIS=X
home_gcode_post_x: _HOME_POST_AXIS AXIS=X
home_gcode_pre_y: _HOME_PRE_AXIS AXIS=Y
home_gcode_post_y: _HOME_POST_AXIS AXIS=Y
home_gcode_pre_xy: _HOME_XY STAGE=pre
home_gcode_post_xy: _HOME_XY STAGE=post
contact_activate_gcode: _CONTACT_MACRO STAGE=activate
contact_deactivate_gcode: _CONTACT_MACRO STAGE=deactivate

[gcode_macro _beacon_contact_hardware_check]
gcode:
{% if 'mcu beacon' in printer %}
{% set version = printer['mcu beacon'].mcu_version.split(' ')|last %}
{% set major = version.split('.')|first|int %}
{% if version < '2' %}
{action_raise_error('Beacon firmware is too old. Found: %s, Expected: 2.0.0 or higher' % version)}
{% endif %}
{% else %}
{action_raise_error('Beacon MCU was not found')}
{% endif %}

[delayed_gcode _do_beacon_contact_hardware_check]
initial_duration: 5
gcode:
_beacon_contact_hardware_check
2 changes: 1 addition & 1 deletion config/machine.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ resolution: 0.1
[include ../scripts/*.cfg]

[include ../macros/base/*.cfg]
[include ../macros/base/homing/homing_*.cfg]
[include ../macros/base/homing/homing_conditional.cfg]

[include ../macros/calibration/calib*.cfg]

Expand Down
202 changes: 202 additions & 0 deletions macros/base/homing/beacon_homing_hooks.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
[gcode_macro _HOME_PRE_AXIS]
description: Perform actions prior to homing an axis
gcode:
{% set axis = params.AXIS %}
{% set kinematics = printer['configfile'].config['printer']['kinematics'] %}
{% set sensorless_homing_enabled = printer['gcode_macro _USER_VARIABLES'].sensorless_homing_enabled %}
{% set sensorless_current_factor = printer['gcode_macro _USER_VARIABLES'].sensorless_current_factor / 100 %}
{% set verbose = printer["gcode_macro _USER_VARIABLES"].verbose %}

{% set x_driver = printer["gcode_macro _USER_VARIABLES"].x_driver %}
{% set y_driver = printer["gcode_macro _USER_VARIABLES"].y_driver %}
{% set z_driver = printer["gcode_macro _USER_VARIABLES"].z_driver %}
{% set old_current_x = printer.configfile.config[x_driver ~ ' stepper_x'].run_current|float %}
{% set old_current_y = printer.configfile.config[y_driver ~ ' stepper_y'].run_current|float %}
{% set old_current_z = printer.configfile.config[z_driver ~ ' stepper_z'].run_current|float %}
{% set new_current_x = sensorless_current_factor * old_current_x %}
{% set new_current_y = sensorless_current_factor * old_current_y %}
{% set new_current_z = sensorless_current_factor * old_current_z %}

# reset parameters
{% set X, Y = False, False %}

# which axis has been requested for homing
{% if axis == 'X' %}
{% set X = True %}
{% elif axis == 'Y' %}
{% set Y = True %}
{% endif %}


{% if sensorless_homing_enabled %}
{% if kinematics == 'corexy' %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={new_current_x}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={new_current_y}
M400
{% elif kinematics == 'corexz' %}
{% if X %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={old_current_x}
SET_TMC_CURRENT STEPPER=stepper_z CURRENT={old_current_z}
{% elif Y %}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={old_current_y}
{% endif %}
M400
{% elif kinematics == 'cartesian' %}
{% if X %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={new_current_x}
{% elif Y %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={new_current_y}
{% endif %}
M400
{% endif %}
{% endif %}

{% if verbose %}
{ action_respond_info('Homing %s' % axis) }
{% endif %}


[gcode_macro _HOME_POST_AXIS]
description: Perform actions after homing an axis
gcode:
{% set axis = params.AXIS %}
{% set homing_travel_speed = printer['gcode_macro _USER_VARIABLES'].homing_travel_speed * 60 %}
{% set kinematics = printer['configfile'].config['printer']['kinematics'] %}
{% set sensorless_current_factor = printer['gcode_macro _USER_VARIABLES'].sensorless_current_factor / 100 %}
{% set sensorless_homing_enabled = printer['gcode_macro _USER_VARIABLES'].sensorless_homing_enabled %}

{% set x_homing_backoff, y_homing_backoff = printer['gcode_macro _USER_VARIABLES'].homing_backoff_distance_xy|map('float') %}

{% set x_position_endstop = printer['configfile'].config['stepper_x']['position_endstop']|float %}
{% set y_position_endstop = printer['configfile'].config['stepper_y']['position_endstop']|float %}

{% set x_driver = printer["gcode_macro _USER_VARIABLES"].x_driver %}
{% set y_driver = printer["gcode_macro _USER_VARIABLES"].y_driver %}
{% set z_driver = printer["gcode_macro _USER_VARIABLES"].z_driver %}
{% set old_current_x = printer.configfile.config[x_driver ~ ' stepper_x'].run_current|float %}
{% set old_current_y = printer.configfile.config[y_driver ~ ' stepper_y'].run_current|float %}
{% set old_current_z = printer.configfile.config[z_driver ~ ' stepper_z'].run_current|float %}

# reset parameters
{% set X, Y = False, False %}

# Which axis has been requested for homing
{% if axis == 'X' %}
{% set X = True %}
{% elif axis == 'Y' %}
{% set Y = True %}
{% endif %}

# Ensure absolute mode is set
{% if not printer['gcode_move'].absolute_coordinates %}
G90
{% endif %}

# Move away from the endstop a bit
{% if X %}
G1 X{x_position_endstop + x_homing_backoff} F{homing_travel_speed}
{% elif Y %}
G1 Y{y_position_endstop + y_homing_backoff} F{homing_travel_speed}
{% endif %}

{% if sensorless_homing_enabled %}
{% if kinematics == "corexy" %}
M400
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={old_current_x}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={old_current_y}
{% elif kinematics == "corexz" %}
{% if X %}
M400
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={old_current_x}
SET_TMC_CURRENT STEPPER=stepper_z CURRENT={old_current_z}
{% elif Y %}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={old_current_y}
{% endif %}
{% elif kinematics == "cartesian" %}
{% if X %}
SET_TMC_CURRENT STEPPER=stepper_x CURRENT={old_current_x}
{% elif Y %}
SET_TMC_CURRENT STEPPER=stepper_y CURRENT={old_current_y}
{% endif %}
{% endif %}
{% endif %}


[gcode_macro _HOME_XY]
description: Perform actions before or after homing x or y axis
variable_saved_accel: 0
gcode:
{% set stage = params.STAGE|lower %}

{% set bed_mesh_enabled = printer["gcode_macro _USER_VARIABLES"].bed_mesh_enabled %}
{% set homing_travel_accel = printer['gcode_macro _USER_VARIABLES'].homing_travel_accel %}
{% set status_leds_enabled = printer["gcode_macro _USER_VARIABLES"].status_leds_enabled %}
{% set probing_active = printer["gcode_macro ACTIVATE_PROBE"].is_active %}

# reset parameters
{% set pre, post = False, False %}

# Which axis has been requested for homing
{% if stage == 'pre' %}
{% set pre = True %}
{% elif stage == 'post' %}
{% set post = True %}
{% else %}
{ action_raise_error('Unrecognized STAGE value, valid choices: pre, post') }
{% endif %}

{% if pre %}
# Set the homing acceleration prior to any movement
SET_GCODE_VARIABLE MACRO=_HOME_XY VARIABLE=saved_accel VALUE={printer.toolhead.max_accel}
M204 S{homing_travel_accel}

{% if bed_mesh_enabled %}
BED_MESH_CLEAR
{% endif %}

G90

{% if status_leds_enabled %}
STATUS_LEDS COLOR="homing"
{% endif %}
{% elif post %}
# Reset acceleration values to what it was before
{% set saved_accel = printer["gcode_macro _HOME_XY"].saved_accel %}
SET_VELOCITY_LIMIT ACCEL={saved_accel}

{% if status_leds_enabled %}
STATUS_LEDS COLOR="ready"
{% endif %}
{% endif %}

[gcode_macro _CONTACT_MACRO]
description: Perform actions before or after contact activate/deactivate
gcode:
{% set stage = params.STAGE|lower %}

{% set status_leds_enabled = printer["gcode_macro _USER_VARIABLES"].status_leds_enabled %}
{% set probing_active = printer["gcode_macro ACTIVATE_PROBE"].is_active %}

# reset parameters
{% set activate, deactivate = False, False %}

# Which axis has been requested for homing
{% if stage == 'activate' %}
{% set activate = True %}
{% elif stage == 'deactivate' %}
{% set deactivate = True %}
{% else %}
{ action_raise_error('Unrecognized STAGE value, valid choices: activate, deactivate') }
{% endif %}

{% if not probing_active %}
{% if activate %}
{% if status_leds_enabled %}
STATUS_LEDS COLOR="homing"
{% endif %}
{% elif deactivate %}
{% if status_leds_enabled %}
STATUS_LEDS COLOR="ready"
{% endif %}
{% endif %}
{% endif %}
2 changes: 1 addition & 1 deletion macros/base/homing/homing_override.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ gcode:
{% endif %}

{% else %}
{ action_respond_error("Axis homing order not valid. Choose either X or Y first in the variables.cfg file!") }
{ action_raise_error("Axis homing order not valid. Choose either X or Y first in the variables.cfg file!") }
{% endif %}


Expand Down
62 changes: 62 additions & 0 deletions macros/base/probing/beacon_probe.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This file is used as an interface to activate/deactivate every probe type
# depending of the needs:
# - Beacon: need to be at a correct nozzle temperature to avoid burning the PEI when used

[gcode_macro ACTIVATE_PROBE]
description: Put the machine in a state being able to probe
variable_temperature: 0
variable_is_active: False
gcode:
{% set beacon_max_probing_temp = printer["gcode_macro _USER_VARIABLES"].beacon_max_probing_temp|float %}

SET_GCODE_VARIABLE MACRO=ACTIVATE_PROBE VARIABLE=is_active VALUE=True

# Check the temperature and lower it if needed
SAVE_GCODE_STATE NAME=BEFORE_BEACON_ACTION

{% set ACTUAL_TEMP = printer.extruder.temperature %}
{% set TARGET_TEMP = printer.extruder.target %}

SET_GCODE_VARIABLE MACRO=ACTIVATE_PROBE VARIABLE=temperature VALUE={TARGET_TEMP}

{% if TARGET_TEMP > beacon_max_probing_temp %}
{ action_respond_info('Extruder temperature target of %.1fC is too high for Beacon probing, lowering to %.1fC' % (TARGET_TEMP, beacon_max_probing_temp)) }
M106 S255 ; 100% the part cooling fan to help the extruder cooling
M109 S{beacon_max_probing_temp}
M106 S0 ; Stop the part cooling fan
{% else %}
# Temperature target is already low enough, but nozzle may still be too hot
{% if ACTUAL_TEMP > beacon_max_probing_temp + 3 %}
M106 S255 ; 100% the part cooling fan to help the extruder cooling
TEMPERATURE_WAIT SENSOR=extruder MAXIMUM={beacon_max_probing_temp}
M106 S0 ; Stop the part cooling fan
{% endif %}
{% endif %}

G28 Z METHOD=CONTACT CALIBRATE=1


[gcode_macro DEACTIVATE_PROBE]
description: Revert the machine to a normal state after probing
gcode:
{% set beacon_deactivation_zhop = printer["gcode_macro _USER_VARIABLES"].beacon_deactivation_zhop %}
{% set Sz = printer["gcode_macro _USER_VARIABLES"].z_drop_speed * 60 %}

G28 Z METHOD=CONTACT CALIBRATE=1

# Check and restore the nozzle temperature if needed
# Small Z hop to avoid restoring the temperature directly on the PEI
{% set z_safe = printer.toolhead.position.z + beacon_deactivation_zhop %}
{% if z_safe > printer.toolhead.axis_maximum.z %}
{% set z_safe = printer.toolhead.axis_maximum.z %}
{% endif %}
G90
G1 Z{z_safe} F{Sz}

# Then restoring the temperature
{% set old_target_temperature = printer["gcode_macro ACTIVATE_PROBE"].temperature %}
M109 S{old_target_temperature}

RESTORE_GCODE_STATE NAME=BEFORE_BEACON_ACTION

SET_GCODE_VARIABLE MACRO=ACTIVATE_PROBE VARIABLE=is_active VALUE=False
2 changes: 2 additions & 0 deletions macros/base/probing/generic_probe.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# - Dockable probe: need to be attached/docked when used
# - ... can be improved depending of new probes needs ...

[include ../homing/homing_override.cfg]

[gcode_macro ACTIVATE_PROBE]
description: Put the machine in a state being able to probe
variable_temperature: 0
Expand Down
Loading