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

Add mixing extruder support #4566

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
d9ea256
extruder: Add mixing extruder (with example usage in a printer.cfg)
konsumverweigerer Feb 12, 2021
b1f9c01
mixingextruder: reformat code
konsumverweigerer Feb 12, 2021
1df0bb5
mixingextruder: Fix limit checks
konsumverweigerer Feb 14, 2021
a2cf769
docs: Add documentation for mixingextruder
konsumverweigerer Feb 14, 2021
987933a
mixingextruder: Add support for M165 g-code command
konsumverweigerer Feb 15, 2021
b2353fb
docs: Add documentation for the M165 g-code command
konsumverweigerer Feb 15, 2021
8617cba
mixingextruder: remove all M* g-codes and add comprehensive commands
konsumverweigerer Mar 1, 2021
b5e279a
extruder: add extruder registry and check registry at M104/M109
konsumverweigerer Mar 15, 2021
8c02e13
mixingextruder: remove enhanced G1 command and use extruder registry
konsumverweigerer Mar 15, 2021
16224e7
extruder: improve shared heater handling
konsumverweigerer Mar 16, 2021
7ac21d9
Fixed bugs preventing mixing extruders from working
matyay Jun 19, 2021
c76c3f5
Allowed chainging heater temperature of a not currently selected mixi…
matyay Jul 1, 2021
ffbac77
A crude automatic retraction handling for a mixing extruder. Works well.
matyay Jul 1, 2021
3233ea1
Added documentation for some mixing extruder nuances.
matyay Aug 7, 2021
3dda29f
Fixed too long line
matyay Aug 7, 2021
41be0f3
Removed providing a Python function object as a part of mixing extrud…
matyay Aug 10, 2021
79f8d91
Removed the unsupported "extended_g1" option from the mixing extruder…
matyay Aug 10, 2021
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
158 changes: 158 additions & 0 deletions config/printer-geeetech-301.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# This file contains common pin mappings for the GTM32 PRO board in the Geeetech 301 printer
# To use this config, the firmware should be compiled for the
# STM32F103 with "No bootloader" and with "Use USB for communication"
# disabled.

# The "make flash" command does not work on the GTM32 PRO. Instead,
# after running "make", run the following command to flash the board:
# stm32flash -w out/klipper.bin -v -i rts,-dtr,dtr /dev/ttyUSB0

# See docs/Config_Reference.md for a description of parameters.

[board_pins gtm32_pro_vb]
aliases_probes: X_MIN=PE5,X_MAX=PE4,Y_MIN=PE3,Y_MAX=PE2,Z_MIN=PE1,Z_MAX=PE0
aliases_temp: E0_TEMP=PC0,T0_PWM=PB4,E1_TEMP=PC1,T1_PWM=PB5,E2_TEMP=PC2,T2_PWM=PB0,BED_TEMP=PC3,BED_PWM=PB1
aliases_other: FAN0_PWM=PB7,FAN1_PWM=PB8,FAN2_PWM=PB9,BEEP=PB10,LED_PWM=PD12
aliases_motors: X_EN=PA8,X_DIR=PD13,X_STEP=PC6,Y_EN=PA15,Y_DIR=PA11,Y_STEP=PA12,Z_EN=PB3,Z_DIR=PD3,Z_STEP=PD6,E0_EN=PC15,E0_DIR=PC13,E0_STEP=PC14,E1_EN=PA1,E1_DIR=PB6,E1_STEP=PA0,E2_EN=PC4,E2_DIR=PB11,E2_STEP=PB2
aliases_lcd: LCD_ENC1=PE9,LCD_ENC2=PE8,LCD_PUSH=PE13,LCD_BEEP=PE12,LCD_RS=PE6,LCD_E=PE14,LCD_D4=PD8,LCD_D5=PD9,LCD_D6=PD10,LCD_D7=PE15

[multi_pin heater]
pins: T0_PWM,T1_PWM,T2_PWM

[multi_pin printhead_fans]
pins: FAN1_PWM,FAN2_PWM

[thermistor bed_thermistor]
temperature1: 24
resistance1: 104600
temperature2: 40
resistance2: 47700
temperature3: 67
resistance3: 13000

[stepper_a]
step_pin: X_STEP
dir_pin: !X_DIR
enable_pin: !X_EN
microsteps: 16
rotation_distance: 40
endstop_pin: ^X_MAX
homing_speed: 50
position_endstop: 216
arm_length: 201

[stepper_b]
step_pin: Y_STEP
dir_pin: !Y_DIR
enable_pin: !Y_EN
microsteps: 16
rotation_distance: 40
endstop_pin: ^Y_MAX

[stepper_c]
step_pin: Z_STEP
dir_pin: !Z_DIR
enable_pin: !Z_EN
microsteps: 16
rotation_distance: 40
endstop_pin: ^Z_MAX

[extruder]
step_pin: E0_STEP
dir_pin: !E0_DIR
enable_pin: !E0_EN
microsteps: 16
rotation_distance: 32
nozzle_diameter: 0.4
filament_diameter: 1.75
heater_pin: multi_pin:heater
sensor_type: EPCOS 100K B57560G104F
sensor_pin: E2_TEMP
min_extrude_temp: 160
min_temp: 0
max_temp: 250

[extruder1]
step_pin: E1_STEP
dir_pin: !E1_DIR
enable_pin: !E1_EN
microsteps: 16
rotation_distance: 32
nozzle_diameter: 0.4
filament_diameter: 1.75
shared_heater: extruder

[extruder2]
step_pin: E2_STEP
dir_pin: !E2_DIR
enable_pin: !E2_EN
microsteps: 16
rotation_distance: 32
nozzle_diameter: 0.4
filament_diameter: 1.75
shared_heater: extruder

[heater_bed]
heater_pin: BED_PWM
sensor_type: bed_thermistor
sensor_pin: BED_TEMP
min_temp: 0
max_temp: 150

[temperature_sensor board]
sensor_type: temperature_mcu
gcode_id: MCU

[temperature_sensor secondary]
sensor_pin: E1_TEMP
sensor_type: EPCOS 100K B57560G104F
gcode_id: SEC

[temperature_sensor ambient]
sensor_pin: E0_TEMP
sensor_type: EPCOS 100K B57560G104F
gcode_id: AMB

[homing_heaters]
heaters: extruder

[fan]
pin: FAN0_PWM

[heater_fan printhead]
pin: multi_pin:printhead_fans
heater: extruder
max_power: 0.6
off_below: 0.2
shutdown_speed: 0

[mixingextruder]
extruders: extruder,extruder1,extruder2

[mcu]
serial: /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AH06IBBC-if00-port0
restart_method: cheetah

[printer]
kinematics: delta
max_velocity: 300
max_accel: 3000
max_z_velocity: 150
delta_radius: 94

[output_pin beep]
pin: BEEP

[output_pin lcd_beep]
pin: LCD_BEEP

[display]
lcd_type: hd44780
rs_pin: LCD_RS
e_pin: LCD_E
d4_pin: LCD_D4
d5_pin: LCD_D5
d6_pin: LCD_D6
d7_pin: LCD_D7
encoder_pins: ^LCD_ENC1,^LCD_ENC2
click_pin: ^LCD_PUSH
60 changes: 60 additions & 0 deletions config/sample-mixing-extruder.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This file contains a configuration snippet for a printer using a
# mixing extruder (3 in - 1 out). The 3 extruder motors should be defined
# as extruder, extruder1 and extruder2

# See docs/Config_Reference.md for a description of parameters.

[mixingextruder]
extruders: extruder,extruder1,extruder2

[gcode_macro M163]
gcode:
SET_MIXING_EXTRUDER EXTRUDER=mixingextruder MIXING_MOTOR={S} SCALE={P}

[gcode_macro M164]
default_parameter_S: ACTIVE
gcode:
SAVE_MIXING_EXTRUDERS EXTRUDER=mixingextruder MIXING_EXTRUDER={S}

[gcode_macro M165]
default_parameter_A: 0.
default_parameter_B: 0.
default_parameter_C: 0.
gcode:
SET_MIXING_EXTRUDER EXTRUDER=mixingextruder MIXING_MOTOR=0 SCALE={A}
SET_MIXING_EXTRUDER EXTRUDER=mixingextruder MIXING_MOTOR=1 SCALE={B}
SET_MIXING_EXTRUDER EXTRUDER=mixingextruder MIXING_MOTOR=2 SCALE={C}
SAVE_MIXING_EXTRUDERS EXTRUDER=mixingextruder MIXING_EXTRUDER=ACTIVE

[gcode_macro M166]
default_parameter_T: ACTIVE
default_parameter_S: RESET
default_parameter_A: -1
default_parameter_Z: -1
default_parameter_I: -1
default_parameter_J: -1
gcode:
# Assume there is only one mixing extruder and it is named "mixingextruder"
{% set extruder = 'mixingextruder' %}
{% if extruder >= 0 %}
{% if params.A|float >= 0 and params.Z|float >= 0 and params.I|int >= 0 and params.J|int >= 0 %}
ADD_MIXING_GRADIENT EXTRUDER={extruder} START_HEIGHT={A} END_HEIGHT={Z} START={I} END={J}
SET_MIXING_GRADIENT EXTRUDER={extruder} ENABLE={S}
{% elif S != "RESET" %}
SET_MIXING_GRADIENT EXTRUDER={extruder} ENABLE={S}
{% else %}
RESET_MIXING_GRADIENT EXTRUDER={extruder}
{% endif %}
{% else %}
{action_raise_error("Could not find mixingextruder")}
{% endif %}

[gcode_macro M567]
default_parameter_P: ACTIVE
default_parameter_E: 1:0:0
gcode:
{% set weights = (E+":0:0").split(":") %}
SET_MIXING_EXTRUDER EXTRUDER=mixingextruder MIXING_MOTOR=0 SCALE={weights[0]}
SET_MIXING_EXTRUDER EXTRUDER=mixingextruder MIXING_MOTOR=1 SCALE={weights[1]}
SET_MIXING_EXTRUDER EXTRUDER=mixingextruder MIXING_MOTOR=2 SCALE={weights[2]}
SAVE_MIXING_EXTRUDERS EXTRUDER=mixingextruder MIXING_EXTRUDER={P}
19 changes: 19 additions & 0 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,25 @@ more information.
# parameters.
```

### [mixingextruder]

A mixing printhead which has <n>in-1out mixing nozzle. When specified
16 virtual mixingextruders are created ("mixingextruder",
"mixingextruder1", ... "mixingextruder15"). They can be activated like
the standard extruders with "ACTIVATE_EXTRUDER EXTRUDER=mixingextruder" and
"MIXING_STATUS EXTRUDER=mixingextruder" provides some statistics.
When activated additional g-code are available. See
[G-Codes](G-Codes.md#mixing-commands) for
a detailed description of the additional commands.

```
[mixingextruder]
#extruders:
# Which extruders feed into the hotend/nozzle. provide a comma
# separated list, eg. "extruder,extruder1,extruder2".
# This configuration is required.
```

### [manual_stepper]

Manual steppers (one may define any number of sections with a
Expand Down
38 changes: 38 additions & 0 deletions docs/G-Codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,44 @@ enabled:
future G-Code movement commands may run in parallel with the stepper
movement.

### Mixingextruder Commands

The following commands are available when a
[mixingextruder config section](Config_Reference.md#mixingextruder) is
enabled:
- `ACTIVATE_EXTRUDER EXTRUDER=<mixingextruder>`: This command activates
the specified mixing extruder. Subsequent G1 commands use the mixing
defined for that mixing extruder.
- `SET_MIXING_EXTRUDER MIXING_MOTOR=<extruder>
SCALE=<scale>`: Set a scale for a given extruder.
- `SAVE_MIXING_EXTRUDERS [MIXING_EXTRUDER=<target>]`: Saves the previous set scales to a given
target mixing extruder. If the target is is not given, save it at the
currently active mixing extruder. For example with a 2in-iout extruder to set
the mix for "mixingextruder3" to 75%/25% one would use:
`SET_MIXING_EXTRUDER MIXING_MOTOR=0 SCALE=75`
`SET_MIXING_EXTRUDER MIXING_MOTOR=1 SCALE=25`
`SAVE_MIXING_EXTRUDERS MIXING_EXTRUDER=3`
- `ADD_MIXING_GRADIENT EXTRUDER=<mixingextruder> START=<start_source>
END=<end_source> START_HEIGHT=<start> END_HEIGHT=<end>`: Configures
(adds) a gradient for the given mixing extruder. The sources are
references to (other) mixing extruders. For example if with a 2in-1out
extruder "mixingextruder2" is set mix 100%/0% and "mixingextruder3"
is set to 0%/100%
`ADD_MIXING_GRADIENT EXTRUDER=mixingextruder START=2 END=3
START_HEIGHT=10 END_HEIGHT=20`
`ADD_MIXING_GRADIENT EXTRUDER=mixingextruder START=3 END=2
START_HEIGHT=20 END_HEIGHT=30`
would setup a gradient for "mixingextruder" which is constant 100%/0%
between heights 0mm and 10mm, then linearly interpolates to 0%/100% at
height 20mm and back to 100%/0% at height 30mm and stays that for all
heights above.
- `RESET_MIXING_GRADIENT EXTRUDER=<mixingextruder>`: Reset/remove all
gradients for the given mixing extruder.
- `SET_MIXING_GRADIENT EXTRUDER=<mixingextruder> [ENABLE=<enable>] [METHOD=<method>]`:
Enable/disable the gradient at the given mixing extruder and set the gradient method.
- `MIXING_STATUS EXTRUDER=<mixingextruder>`: Returns the configuration
and status of the given mixing extruder.

### Extruder stepper Commands

The following command is available when an
Expand Down
95 changes: 95 additions & 0 deletions docs/Mixing_Extruder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Mixing extruder

This document describes how to configure and use a filament mixing extruder.
Please also refer to the [config reference](Config_Reference.md) and supported
[G-Codes](G-Codes.md).

## Configuring a mixing extruder.

A mixing extruder has N-filament inputs and a single nozzle. This requires
N independent filament drives. They have to be defined in the config as regular
extruders.

Since they all drive filament to the same hotend they must have the
`shared_heater` property set to point to one of them. For this reason all
heater-related parameters should be set only for that one.

Following individual filament drivers definitions there should be the
`[mixingextruder]` section which groups all of them to tell Klipper that
they in fact drive the same mixing hotend.

Here is an example of configuration snippet for 3-to-1 mixing extruder:
```
# "Alpha" stepper
[extruder]
step_pin: PC7
dir_pin: !PC8
enable_pin: !PA18
microsteps: 16
rotation_distance: 7.15
nozzle_diameter: 0.400
filament_diameter: 1.75
heater_pin: PC22
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PA6
control: pid
pid_kp: 37.919
pid_ki: 0.950
pid_kd: 378.241
min_temp: 0
max_temp: 275
pressure_advance: 0.1
min_extrude_temp: 0

# "Beta" stepper
[extruder1]
step_pin: PB3
dir_pin: !PC10
enable_pin: !PB4
microsteps: 16
rotation_distance: 7.15
nozzle_diameter: 0.400
filament_diameter: 1.75
pressure_advance: 0.1
shared_heater: extruder

# "Gamma" stepper
[extruder2]
step_pin: PB1
dir_pin: !PB0
enable_pin: !PB2
microsteps: 16
rotation_distance: 7.15
nozzle_diameter: 0.400
filament_diameter: 1.75
pressure_advance: 0.1
shared_heater: extruder

[mixingextruder]
extruders: extruder,extruder1,extruder2
```

Stepper parameters may vary among all the drivers but in most systems they are
identical.

## Retractions

For correct operation of a mixing extruder all N input filaments should be
retracted by the same amount regardless of the mixing ratio used. Most
3D printer firmware implement that via firmware retractions.

The current implementation of retractions in Klipper is different and is based
on automatic tracking of extrusion moves. When Klipper detects a retraction
(which is backward extrusion move) it sets internally the mixing ratio for
each filament driver to 1/N ensuring that all filaments are moved by the same
distance. The retracted distance is accumulated and used to detect the end
of subsequent unretraction move. When that happens the mixing ratio is restored.

Because retractions happen with mixing ratio of 1/N for each stepper the amount
the filament actually moves and the move speed is also divided by N. This
currently has to be accounted for in a slicer firmware. For example whe one
wants to retract by 3mm with the speed of 50mm/s a 3-to-1 mixing extruder then
the values in the slicer need to be 3 * 3mm = 9mm and 3 * 50mm/s = 150mm/s.

A mixing extruder should be thought of as if it was driving a "virtual filament"
at the point where it enters the nozzle.
1 change: 1 addition & 0 deletions docs/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ communication with the Klipper developers.
using adxl345 accelerometer hardware to measure resonance.
- [Pressure advance](Pressure_Advance.md): Calibrate extruder
pressure.
- [Mixing extruder](Mixing_Extruder.md): Information about setting-up and using filament mixing extruders.
- [Slicers](Slicers.md): Configure "slicer" software for Klipper.
- [Command Templates](Command_Templates.md): G-Code macros and
conditional evaluation.
Expand Down
Loading