klipper icon indicating copy to clipboard operation
klipper copied to clipboard

Read Pins Scripting

Open SergeyKrutyko opened this issue 8 years ago • 39 comments

I have a system witch one extruder & filament switching module.

Switching of the filament is realized by setting the logical state on the pins of RAMPS.

For example, 1.2 pins specify the filament number. 3 pin reports on readiness - that the filament is switched and new loaded

I fount klipper gcode command for set pin state. i dont fount command for read and condition logic.

Can I create a script that would expect this read 3 pin?

If 1, then wait. If 0 - then continue printing.

Thank you!

SergeyKrutyko avatar Sep 27 '18 08:09 SergeyKrutyko

I have a system witch one extruder & filament switching module.

I am really interested in seeing pictures of your module. Is it something similar that Prusa has?

For example, 1.2 pins specify the filament number. 3 pin reports on readiness - that the filament is switched and new loaded I fount klipper gcode command for set pin state. i dont fount command for read and condition logic. Can I create a script that would expect this read 3 pin? If 1, then wait. If 0 - then continue printing.

Klipper doesn't have such gcode scripting capabilities. If you're printing via Octoprint then you can somehow control it with action commands. http://docs.octoprint.org/en/master/features/action_commands.html# In Klipper you may create a custom menu for your functionality to manually control it. But you cannot make a gcode script in Klipper to fully automate this flow! Maybe it's doable in Octoprint.

Currently, there's no gcode to read pin state.

mcmatrix avatar Sep 27 '18 11:09 mcmatrix

mcmatrix, you right - this is analog of prusa mmu2 now it progress and i want solve this issue in advance.

In the original version of prusa it is implemented through the firmware.

How I see this solution in the klipper:

  1. There is a tool selection command T and there is a mechanism for reassigning the command. It is necessary for me that when I get the tool T0 (T1, T2 ... T4), I run a script that, depending on the value of T, should set the states of some pins, for example: ...... [tool_override] #two system variables: #OLDTOOL and NEWTOOL gcode: G1 X0 Y0 F7200 ; homing G1 E-50 F100 ; unload filament IF NEWTOOL=0 ; select tool 0 SET_PIN PIN=toolcode1 VALUE=0 SET_PIN PIN=toolcode2 VALUE=0 IF NEWTOOL=1 ; select tool 1 SET_PIN PIN=toolcode1 VALUE=1 SET_PIN PIN=toolcode2 VALUE=0 IF NEWTOOL=2 ; select tool 2 SET_PIN PIN=toolcode1 VALUE=0 SET_PIN PIN=toolcode2 VALUE=1 ;check for busy WHILE GET_PIN PIN=toolstatus VALUE=1 ....pause code.... #resume printing G1 E50 F100 ; load filament ....

SergeyKrutyko avatar Sep 27 '18 12:09 SergeyKrutyko

may be made few tool overrides: [tool0_override] [tool1_override] .... [toolx_override]

SergeyKrutyko avatar Sep 27 '18 12:09 SergeyKrutyko

main problems is: how still wait when multimaterial switch module complete work

SergeyKrutyko avatar Sep 27 '18 12:09 SergeyKrutyko

main problems is: how still wait when multimaterial switch module complete work

Somebody has to implement new gcode command for Klipper. gcode that will read and wait for pin state. for example WAIT_FOR_PIN PIN=pin STATE=1 There's internal buttons module that can be used for pin state reading.

Similar to what marlin has http://marlinfw.org/docs/gcode/M226.html

mcmatrix avatar Sep 27 '18 12:09 mcmatrix

main problems is: how still wait when multimaterial switch module complete work

Somebody has to implement new gcode command for Klipper. gcode that will read and wait for pin state. for example WAIT_FOR_PIN PIN=pin STATE=1 There's internal buttons module that can be used for pin state reading.

Similar to what marlin has http://marlinfw.org/docs/gcode/M226.html

yes as variant.... and need tool override feature or global T command override with internal variable with logic

SergeyKrutyko avatar Sep 27 '18 12:09 SergeyKrutyko

WAIT_FOR_PIN PIN=pin STATE=1 is a good idea, but need two additional parameters

  1. TIMEOUT - in seconds, to prevent the system halt
  2. ERRCMD - for abort or pause printing

ex: WAIT_FOR_PIN PIN=pin STATE=1 TIMEOUT=60 ERRCMD=@pause

SergeyKrutyko avatar Sep 27 '18 13:09 SergeyKrutyko

Tool override, could it be this?

You will define additional extruders. Because in real life you only have 1 hotend so other extruders will use shared heater.

# In a multi-extruder printer add an additional extruder section for
# each additional extruder. The additional extruder sections should be
# named "extruder1", "extruder2", "extruder3", and so on. See the
# "extruder" section in example.cfg for a description of available
# parameters.
#[extruder1]
#step_pin: ar36
#dir_pin: ar34
#...
#shared_heater:
#   If this extruder uses the same heater already defined for another
#   extruder then place the name of that extruder here.  For example,
#   should extruder3 and extruder4 share a heater then the extruder3
#   config section should define the heater and the extruder4 section
#   should specify "shared_heater: extruder3". The default is to not
#   reuse an existing heater.
#deactivate_gcode:


#   A list of G-Code commands (one per line; subsequent lines
#   indented) to execute on a G-Code tool change command (eg, "T1")
#   that deactivates this extruder and activates some other
#   extruder. It only makes sense to define this section on
#   multi-extruder printers. The default is to not run any special
#   G-Code commands on deactivation.
#activate_gcode:
#   A list of G-Code commands (one per line; subsequent lines
#   indented) to execute on a G-Code tool change command (eg, "T0")
#   that activates this extruder. It only makes sense to define this
#   section on multi-extruder printers. The default is to not run any
#   special G-Code commands on activation.

During toolchange T<index> activate and deactive gcode is executed from extruder.

mcmatrix avatar Sep 27 '18 13:09 mcmatrix

This is possible? I have only one physical heater / extruder in the system

SergeyKrutyko avatar Sep 27 '18 13:09 SergeyKrutyko

Sorry i see description for: #shared_heater

SergeyKrutyko avatar Sep 27 '18 13:09 SergeyKrutyko

mcmatrix, thanks for ideas. if you must realise command WAIT_FOR_PIN - then complete resolve my project for mmu2 bassed module!

SergeyKrutyko avatar Sep 27 '18 13:09 SergeyKrutyko

Btw if your filament switching module is open source project then maybe you could share it with the community. I'm really interested to see this mmu2 based module working. Maybe I even try to build it for myself if you share the project.

mcmatrix avatar Sep 27 '18 13:09 mcmatrix

Btw if your filament switching module is open source project then maybe you could share it with community. I'm really interested to see this mmu2 based module working. Maybe I even try to build it for myself.

offcoz! now i get all stl files of original prusa mmu2 and print it. also i waiting for all necesuary parts from aliexpress. original project based on prusa board. my project on ramps + nema17. total budget of my version mmu2 (original prusa stl details + ramps) is 80$ - it realy low price for this feature :)

i write own firmware for ramps. now i still wait for parts delivery and after complete and tests i place it to github if it interested :)

SergeyKrutyko avatar Sep 27 '18 14:09 SergeyKrutyko

I therefore wrote it here. I hoped that if this is possible and the necessary functionality in the klipper will appear, I will be able to finish the project faster

SergeyKrutyko avatar Sep 27 '18 14:09 SergeyKrutyko

Here is original prusa solidworks project of mmu2 https://www.thingiverse.com/thing:3080920

SergeyKrutyko avatar Sep 27 '18 14:09 SergeyKrutyko

IF NEWTOOL=0 ; select tool 0 SET_PIN PIN=toolcode1 VALUE=0

I would caution against "programming in g-code". Instead, I'd recommend creating a Klipper "extras" module (see: https://github.com/KevinOConnor/klipper/blob/master/docs/Code_Overview.md#adding-a-host-module ) that performs the required actions and error handling.

original project based on prusa board. my project on ramps + nema17.

If your filament switcher has its own micro-controller you might want to consider running Klipper on that micro-controller and using Klipper's multi-mcu capability.

-Kevin

KevinOConnor avatar Sep 27 '18 14:09 KevinOConnor

If your filament switcher has its own micro-controller you might want to consider running Klipper on that micro-controller and using Klipper's multi-mcu capability.

Own microcontroller will essentially perform a primitive task - engine management (material supply, slot switching and tube movement). There will also be several buttons for manual control.

Communicate with the main board of the printer, everything will be 3-4 wires, according to which the simplest combination will be applied to replace the filament.

To connect the entire system to the klipper seems to me too difficult and not justified

SergeyKrutyko avatar Sep 27 '18 14:09 SergeyKrutyko

I would caution against "programming in g-code". Instead, I'd recommend creating a Klipper "extras" module (see: https://github.com/KevinOConnor/klipper/blob/master/docs/Code_Overview.md#adding-a-host-module ) that performs the required actions and error handling.

Kevin, i dont know python.... or know it too bad ((( also hardware + arduino and c++ is my featured technologies.

I agree that it may make sense to make the system as klipper module - but for now it seems to me faster and easier to do everything with a separate card controlled via wires through pins

SergeyKrutyko avatar Sep 27 '18 14:09 SergeyKrutyko

For tool change scripting you can use slicer options. For example, Simplify3D has tool change script options and probably others have it too.

...
{IF NEWTOOL=1}G1 F12000 Z2
{IF NEWTOOL=1}G90
{IF NEWTOOL=0} Do WHATEVER
...

mcmatrix avatar Sep 27 '18 14:09 mcmatrix

For toolchange scripting you can use slicer options. For example Simplify3D has toolchange script options and probably others have it too.

{IF NEWTOOL=1}G1 F12000 Z2
{IF NEWTOOL=1}G90
{IF NEWTOOL=0} Do WHATEVER

I thought about it! But:

  1. A system with several clipper extruders solves this task more beautifully.
  2. I would not like to be tied to a simplify only

SergeyKrutyko avatar Sep 27 '18 14:09 SergeyKrutyko