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

Klippain compatibility with HH v2.5 #517

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 34 additions & 4 deletions docs/mmu.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,45 @@ Finally, enable Klippain's MMU feature by uncommenting the corresponding line in

HappyHare is a software with a lot of features and you should first have a look at how it works and its concepts [here](https://github.com/moggieuk/Happy-Hare?tab=readme-ov-file#---readme-table-of-contents) and its documentation section [here](https://github.com/moggieuk/Happy-Hare/tree/main/doc). On top of this, Klippain define a couple of things a bit differently to allow more flexibility and a better integration with it.

### Happy_Hare v2.5 and higher

HappyHare v2.5 and higher can natively manage all the initialisation and finalization of the MMU. Here are some recommendations for a good experience with klippain:

#### Changes recommended in Happy_Hare configuration variables
1. You can set `variable_user_pre_initialize_extension` like this:
```yml
# in [gcode_macro _MMU_SOFTWARE_VARS]
variable_user_pre_initialize_extension: "_CG28" ; Executed at start of _MMU_INITIALIZE. Commonly G28 to home
```
2. Check the `variable_park_z_hop` you want to use with MMU macros:
```yml
# in [gcode_macro _MMU_SEQUENCE_VARS]
variable_park_z_hop : 1.0 ; Additional Z_hop (mm) when toolchanging (works in and out of print)
```
3. Some MMU variables are overridden by klippain on startup to use the more global ones defined in klippain. So be aware that the following variables will have no effect if you have those defined in Klippain `variables.cfg`.
```yml
# in [gcode_macro _MMU_SEQUENCE_VARS]
variable_park_xy : 50, 50 ; Coordinates of park position for toolchange
variable_travel_speed : 200 ; XY travel speed in mm/s
variable_lift_speed : 15 ; Z travel speed in mm/s
```

#### Custom start print gcode in your slicer
Add the `MMU_START_SETUP` and `MMU_START_CHECK` as below, before your original `START_PRINT` call:
```
MMU_START_SETUP INITIAL_TOOL={initial_tool} REFERENCED_TOOLS=!referenced_tools! TOOL_COLORS=!colors! TOOL_TEMPS=!temperatures! TOOL_MATERIALS=!materials! PURGE_VOLUMES=!purge_volumes!
MMU_START_CHECK
# And followed by your standard START_PRINT call
START_PRINT EXTRUDER_TEMP={first_layer_temperature[initial_extruder] + extruder_temperature_offset[initial_extruder]} BED_TEMP=[first_layer_bed_temperature] MATERIAL=[filament_type] SIZE={first_layer_print_min[0]}_{first_layer_print_min[1]}_{first_layer_print_max[0]}_{first_layer_print_max[1]}
```

### Check gates on START_PRINT

If you want to check the gates at the start of a print to avoid an error when using a gate that was previously marked as empty, it is recommended to set `variable_mmu_check_gates_on_start_print: True` in your Klippain `variables.cfg`.

> **Note**:
>
> Be sure to also include `TOOLS_USED=!referenced_tools!` in your slicer custom start print gcode in order to allow the [HappyHare Moonraker gcode preprocessor](https://github.com/moggieuk/Happy-Hare/blob/main/doc/gcode_preprocessing.md) to work correctly and and to ensure that all tools are checked.
> Be sure to also include `TOOLS_USED=!referenced_tools!` in your slicer custom start print gcode in order to allow the [HappyHare Moonraker gcode preprocessor](https://github.com/moggieuk/Happy-Hare/blob/main/doc/gcode_preprocessing.md) to work correctly and to ensure that all tools are checked.

### Early check errors during START_PRINT

Expand Down Expand Up @@ -84,9 +116,7 @@ You can also use the `MMU_GATE_MAP GATE=n SPOOLID=id` macro at runtime to change

### Variable check error

```
MMU support is enabled in Klippain, but some variables are missing from your variables.cfg. Please update your template or refer to the corresponding documentation: https://github.com/Frix-x/klippain/blob/main/docs/mmu.md
```
> MMU support is enabled in Klippain, but some variables are missing from your variables.cfg. Please update your template or refer to the corresponding documentation: https://github.com/Frix-x/klippain/blob/main/docs/mmu.md

If you have the previous message in the console when Klippain is starting, you will want to update your Klippain `variables.cfg` template file or check that the MMU variables are set correctly in it:
- `variable_mmu_force_homing_in_start_print`: True or False
Expand Down
20 changes: 16 additions & 4 deletions macros/base/cancel_print.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ gcode:

PARK

{% if klippain_mmu_enabled and mmu_unload_on_cancel_print %}
{% if printer.mmu.enabled and printer.mmu.tool|int != -2 %}
{% if klippain_mmu_enabled %}
{% if printer.mmu.enabled and printer.configfile.settings.mmu.happy_hare_version >= 2.5 %}
_MMU_CLEAR_POSITION
{% elif printer.mmu.enabled and mmu_unload_on_cancel_print and printer.mmu.tool|int != -2 %}
# Unload filament and park the MMU
MMU_EJECT
{% elif printer.extruder.can_extrude %}
# Pull back the filament a little bit
G92 E0
G1 E-10 F2100
{% endif %}
{% elif printer.extruder.can_extrude %}
# Pull back the filament a little bit
Expand Down Expand Up @@ -67,7 +73,11 @@ gcode:
{% endif %}

{% if klippain_mmu_enabled %}
{% if printer.mmu.enabled and printer.mmu.print_start_detection|int == 0 %}
{% if printer.mmu.enabled and printer.configfile.settings.mmu.happy_hare_version >= 2.5 %} # reset mmu vars
{% set vars = printer['gcode_macro _MMU_CLIENT_VARS'] %}
{vars.user_cancel_extension|default("")}
_MMU_RUN_MARKERS
{% elif printer.mmu.enabled and printer.mmu.print_start_detection|int == 0 %}
_MMU_PRINT_END STATE=cancelled
{% endif %}
{% endif %}
Expand All @@ -76,5 +86,7 @@ gcode:
{% if filament_sensor_enabled %}
SET_FILAMENT_SENSOR SENSOR="runout_sensor" ENABLE=1
{% endif %}

BASE_CANCEL_PRINT

RESPOND MSG="Print cancelled!"
13 changes: 11 additions & 2 deletions macros/base/end_print.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ gcode:
PARK

{% if klippain_mmu_enabled %}
{% if printer.mmu.enabled and mmu_unload %}
{% if printer.mmu.enabled and printer.configfile.settings.mmu.happy_hare_version >= 2.5 %}
{% if printer['gcode_macro _MMU_RUN_MARKERS'].mmu_end_run == 1 %}
RESPOND MSG="MMU end already done"
{% elif mmu_unload %}
MMU_END EJECT=true
{% else %}
MMU_END
{% endif %}
_MMU_RUN_MARKERS
{% elif printer.mmu.enabled and mmu_unload %}
# unload filament and park into MMU. Or just unload filament out of extruder if using bypass.
MMU_EJECT
{% endif %}
Expand Down Expand Up @@ -68,7 +77,7 @@ gcode:
{% endif %}

{% if klippain_mmu_enabled %}
{% if printer.mmu.enabled and printer.mmu.print_start_detection|int == 0 %}
{% if printer.mmu.enabled and printer.configfile.settings.mmu.happy_hare_version < 2.5 and printer.mmu.print_start_detection|int == 0 %}
_MMU_PRINT_END
{% endif %}
{% endif %}
Expand Down
29 changes: 25 additions & 4 deletions macros/base/pause_resume.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@ description: Pause the print and park
gcode:
{% set light_enabled = printer["gcode_macro _USER_VARIABLES"].light_enabled %}
{% set light_intensity_start_print = printer["gcode_macro _USER_VARIABLES"].light_intensity_start_print %}
{% set klippain_mmu_enabled = printer["gcode_macro _USER_VARIABLES"].klippain_mmu_enabled %}

{% if printer.pause_resume.is_paused %}
RESPOND MSG="Print is already paused"
{% else %}
SAVE_GCODE_STATE NAME=PAUSE_state
{% if light_enabled %}
LIGHT_ON S={light_intensity_start_print}
{% endif %}
BASE_PAUSE
PARK
{% if klippain_mmu_enabled %}
{% if printer.mmu.enabled and printer.configfile.settings.mmu.happy_hare_version >= 2.5 %}
{% set vars = printer['gcode_macro _MMU_CLIENT_VARS'] %}
_RETRACT
_MMU_SAVE_POSITION
BASE_PAUSE
_MMU_PARK
{vars.user_pause_extension|default("")}
{% else %}
SAVE_GCODE_STATE NAME=PAUSE_state
BASE_PAUSE
PARK
{% endif %}
{% else %}
SAVE_GCODE_STATE NAME=PAUSE_state
BASE_PAUSE
PARK
{% endif %}
{% endif %}


Expand All @@ -30,7 +46,12 @@ gcode:
RESPOND MSG="Print is not paused. Resume ignored"
{% else %}
{% if klippain_mmu_enabled %}
{% if printer.mmu.enabled and printer.mmu.is_locked %}
{% if printer.mmu.enabled and printer.configfile.settings.mmu.happy_hare_version >= 2.5 %}
{% set vars = printer['gcode_macro _MMU_CLIENT_VARS'] %}
_MMU_RESTORE_POSITION
{vars.user_resume_extension|default("")}
_RETRACT
{% elif printer.mmu.enabled and printer.mmu.is_locked %}
RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=0
{% else %}
RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1 MOVE_SPEED={St}
Expand Down
23 changes: 14 additions & 9 deletions macros/base/start_print.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ variable_chamber_maxtime: 0
variable_initial_tool: 0
variable_check_gates: 0
variable_tools_used: ""
variable_referenced_tools: "!referenced_tools!"
variable_sync_mmu_extruder: 0
variable_material: "XXX"
variable_fl_size: "0_0_0_0"
Expand All @@ -23,30 +24,34 @@ gcode:
{% set SOAK = params.SOAK|default(printer["gcode_macro _USER_VARIABLES"].print_default_soak)|int %} # Heatsoak time of the bed in minutes
{% set CHAMBER_TEMP = params.CHAMBER|default(printer["gcode_macro _USER_VARIABLES"].print_default_chamber_temp)|int %} # Chamber temperature setpoint
{% set CHAMBER_MAXTIME = params.CHAMBER_MAXTIME|default(printer["gcode_macro _USER_VARIABLES"].print_default_chamber_max_heating_time)|int %} # Chamber heatsoak timeout in minutes
{% set INITIAL_TOOL = params.INITIAL_TOOL|default(0)|int %} # Initial tool (for the MMU/ERCF initialization)
{% set MATERIAL = params.MATERIAL|default(printer["gcode_macro _USER_VARIABLES"].print_default_material)|string %} # Material type set in the slicer
{% set FL_SIZE = params.SIZE|default("0_0_0_0")|string %} # Get bounding box of the first layer for the adaptive bed mesh
{% set BED_MESH_PROFILE = params.MESH|default("")|string %} # Bed mesh profile to load
{% set ADAPTIVE_PRIMELINE = params.ADAPTIVE_PRIMELINE|default(1)|int %} # Weither to do or not an adaptive prime line near the real print zone

# Get all the specific MMU parameters passed from the slicer
{% set INITIAL_TOOL = params.INITIAL_TOOL|default(0)|int %} # Initial tool (for the MMU/ERCF initialization)
{% set CHECK_GATES = params.CHECK_GATES|default(printer['gcode_macro _USER_VARIABLES'].mmu_check_gates_on_start_print)|default(0)|int %} # Check if MMU gates are availables
{% set TOOLS_USED = params.TOOLS_USED|default("")|string %} # Check if MMU gates (used in gcode file) are availables
{% set REFERENCED_TOOLS = params.REFERENCED_TOOLS|default("!referenced_tools!")|string %} # same as TOOLS_USED for compatibility with HH macros
{% set SYNC_MMU_EXTRUDER = params.SYNC_MMU_EXTRUDER|default(0)|int %} # set MMU gear motor and extruder synchronization during print TODO
{% set BED_MESH_PROFILE = params.MESH|default("")|string %} # Bed mesh profile to load
{% set ADAPTIVE_PRIMELINE = params.ADAPTIVE_PRIMELINE|default(1)|int %} # Weither to do or not an adaptive prime line near the real print zone

# Set the variables to be used in all the modules based on the slicer parameters
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=bed_temp VALUE={BED_TEMP}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=extruder_temp VALUE={EXTRUDER_TEMP}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=soak VALUE={SOAK}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=chamber_temp VALUE={CHAMBER_TEMP}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=chamber_maxtime VALUE={CHAMBER_MAXTIME}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=initial_tool VALUE={INITIAL_TOOL}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=check_gates VALUE={CHECK_GATES}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=tools_used VALUE='"{TOOLS_USED}"'
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=sync_mmu_extruder VALUE={SYNC_MMU_EXTRUDER}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=material VALUE='"{MATERIAL}"'
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=fl_size VALUE='"{FL_SIZE}"'
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=bed_mesh_profile VALUE='"{BED_MESH_PROFILE}"'
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=adaptive_primeline VALUE={ADAPTIVE_PRIMELINE}

SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=initial_tool VALUE={INITIAL_TOOL}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=check_gates VALUE={CHECK_GATES}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=tools_used VALUE='"{TOOLS_USED}"'
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=referenced_tools VALUE='"{REFERENCED_TOOLS}"'
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=sync_mmu_extruder VALUE={SYNC_MMU_EXTRUDER}

{% if params.TOTAL_LAYER %} # total layers count (if provided by the slicer)
SET_PRINT_STATS_INFO TOTAL_LAYER={params.TOTAL_LAYER|int}
SET_GCODE_VARIABLE MACRO=START_PRINT VARIABLE=total_layer VALUE={params.TOTAL_LAYER|int}
Expand Down Expand Up @@ -209,7 +214,7 @@ gcode:
{% endif %}

{% if klippain_mmu_enabled %}
{% if printer.mmu.enabled and printer.mmu.print_start_detection|int == 0 %}
{% if printer.mmu.enabled and printer.configfile.settings.mmu.happy_hare_version < 2.5 and printer.mmu.print_start_detection|int == 0 %}
_MMU_PRINT_START
{% endif %}
{% endif %}
Expand Down
Loading