Klipper: Yet another MMU support. some questions about gcode_macro

Created on 16 Nov 2019  路  12Comments  路  Source: KevinOConnor/klipper

I have build a custom MMU2 witha skr-mini board (https://www.thingiverse.com/thing:3910546). I currently use it with Marlin and a custom firmware.
I try to use it with klipper, and so i started to define a config file for it.
Actually I can home it, load/unload filament ... but in order to improve my config, I have some questions (I added the definition of my stepper in the post) :

_1) How could I get the status of an endstop from a gcode_macro.
For example, I need to unload the filament if the PINDA on the MMU is TRIGGERED, so I need to test the status from the endstop of [manual_stepper drive_stepper]
I have also a IR sensor on the extruder that detect that the filament is inserted, and need to get its status in order to pause the print if the filament is not correctly inserted in the extruder._
=> OK I write a little patch for a get_status() of the manual_stepper that return the state of the endstop

_2) I need to define two endstop for the [manual_stepper drive_stepper], the PINDA that detect the insert of the filament, and an IR on the extruder that detect that the filament is correctly inserted.
but how to define two endstop (maybe min and max) in the config ?_
=> OK i use the endstop pin of idler stepper, so i can ask it state with {%if ...%}

3) the loading process need to move two stepper at the same time (the gear on the mmu and the extruder) in order to insert the filament (and stop when the IR is triggered). but how to move two stepper at the same time ?

_4) in order to work with slic3r ... without modification, I need T0 T1 ... T4 gcode. It's possible to define a macro T that use the second character as an parameter ?_
=> OK just redefine T0 .. T4 as gcode_macro

5) how to PAUSE a macro, because PAUSE pause octoprint, but the macro is interpreted to the end of the gcode_macro

`

based on https://github.com/mwr666/klipper/blob/sunbeam2.0c_multi_mcu_mmu2/config/printer-protodev-corexy-multi-mcu-mmu2.cfg

[manual_stepper drive_stepper]
step_pin: mmboard:PC5
dir_pin: mmboard:PB0
enable_pin: !mmboard:PC4
step_distance: .0065788
velocity: 20
accel: 10
endstop_pin: ^mmboard:PC2

[manual_stepper idler_stepper]
step_pin: mmboard:PB13
dir_pin: mmboard:PB14
enable_pin: !mmboard:PB12
step_distance: .040000
velocity: 100
accel: 80

endstop_pin: ^mmboard:P1.27

[manual_stepper selector_stepper]
step_pin: mmboard:PC6
dir_pin: mmboard:PC7
enable_pin: !mmboard:PB15
step_distance: .0025
velocity: 35
accel: 100
endstop_pin: !mmboard:PC0
`

klippy.log

Most helpful comment

I posted a pull request with the two function i needed and an example of configuration for the mmu.

All is working without issue now

B57E078A-9100-4142-8D8E-B235E8A5693B
7C2DDD9C-D3E7-48B6-AA6E-48DA123295A9

All 12 comments

I write a quick patch for manual_stepper.py for 1)

    def get_status(self, eventtime):
         endstops = self.stepper.get_endstops()
         print_time = self.printer.lookup_object('toolhead').get_last_move_time()
         return {'endstop': ["open", "TRIGGERED"][not not endstops[0][0].query_endstop(print_time)]}

so i can test the status in macro

{% if printer["manual_stepper drive_stepper"].endstop == "TRIGGERED" %}

If someone is interested, my current config (with a lot of macro en {% if ...%} is here https://github.com/kakou-fr/klipper/blob/master/config/printer-mmu-remix.cfg

@kakou-fr

You can query state of a gcode_button

[gcode_button danger_zone]
pin: helper1:ar22
press_gcode:
   M118 DangerZone off
release_gcode:
   M118 DangerZone ON

and in G-code macro

  {% if printer["output_pin dangerous"].value == 0 %}
  M118 Homing - skipping backing off due to not dangerous
  {% else %}

and use this to force reading the value when printer starts up

[delayed_gcode welcome]
initial_duration: 1
gcode:
  M118 Hello and welcome!
 QUERY_BUTTON button=danger_zone

Hope this helps

for (2) you can use a relay to connect to a single pin two endstops by wiring the endstop output through the relays - I recommand pair of solid state relays - https://images-na.ssl-images-amazon.com/images/I/613fIzTrA2L._SX425_.jpg

for (3) i used a relay to connect step pin on two step sticks between 2 relays.

(4) T0... Tx map to extruders. You can define extruder, extruder1, ... extruder5 and each T0-T5 will have activate_gcode and deactivate_gcode that can be run. You can fake multiple extruders by wiring the step/dir pins together on the step stick to the other step or you can remove check in klipper code that makes sure a pin is not reused.

Finally i put the IR pin to an stepper without endstop, so i can ask it state.

the last issues I have is :

  • how to PAUSE a macro, because PAUSE pause octoprint, but the macro is interpreted to the end of the gcode_macro
  • how to run two motor at the same time

thks for help

Macros are interpreted at start of macro run. Pausing a macro will make no difference if you change stuff. Maybe run chained delayed_gcode at each step and check if a gcode variable has some special value and abort or just don't chain next delayed gcode?

something like PAUSE_NOW that PAUSE octoprint but also pause klipper (and so don't immediately interpret the end of the MACRO)

FWIW, this is something that I suspect adding a python module (eg, klippy/extras/mmu2.py) would be appropriate. I suspect trying to implement the mmu semantics in macros will be difficult and fragile.

-Kevin

I already write the behavior as a set of MACRO. the only blocking point is the behavior of PAUSE that pause octoprint and not klipper, so it continue to execute some gcode after PAUSE.

I suspect trying to implement the mmu semantics in macros will be difficult and fragile.

Writing the macro was not so hard, the behaviour of the MMU is really simple. But why did you say that It will be fragile ?

I posted a pull request with the two function i needed and an example of configuration for the mmu.

All is working without issue now

B57E078A-9100-4142-8D8E-B235E8A5693B
7C2DDD9C-D3E7-48B6-AA6E-48DA123295A9

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smokez89 picture smokez89  路  4Comments

LazaroFilm picture LazaroFilm  路  6Comments

amaximchuk picture amaximchuk  路  6Comments

krpepe picture krpepe  路  5Comments

talfari picture talfari  路  5Comments