Klipper3d / klipper

Klipper is a 3d-printer firmware
GNU General Public License v3.0
9.49k stars 5.32k forks source link

Menu PSU Control #643

Closed SergeyKrutyko closed 6 years ago

SergeyKrutyko commented 6 years ago

I have a klipper with menu features. I make menu items for PSU Control Plugin:

.... [menu control_pon] type: command name: Power ON gcode: M80

[menu control_poff] type: command name: Power OFF gcode: M81 ....

If i select this command from menu then get: Recv: // Unknown command:"M81" Recv: // Unknown command:"M80"

If i write it from terminal then all ok:

Send: M80 PSUControl: ok

and it worked ok....

Please help me!

mcmatrix commented 6 years ago

The Klipper itself doesn't support M81, M80. Therefore Klipper reports that it's Unknown command. Where is your PSU on/off pin connected to (Raspberry or printer controller)? If it's connected to printer board then you can emulate M81, M80 via gcode macro. You can try these. It will create M80, M81 g-code macros for you.

# Lets assume that it's Arduino pin 12
[output_pin psupower]
pin: ar12
# power on
[gcode_macro M80]
gcode: SET_PIN PIN=psupower VALUE=1

# power off
[gcode_macro M81]
gcode: SET_PIN PIN=psupower VALUE=0

or you can just use SET_PIN directly in your scripts.

SergeyKrutyko commented 6 years ago

i am sorry, but my systems have a control of ATX power via pin of Orange PI......

There is no other solution?

ViperWorx commented 6 years ago

If you are using the PSU Control plugin, which it looks like you are, it may be possible to hook into that. However, it would probably need digging around in the code for that plugin. @mcmatrix will be able to confirm if this is possible or not.

mcmatrix commented 6 years ago

@SergeyKrutyko Could you post screenshot of your PSU Control settings.

ViperWorx commented 6 years ago

Two switching methods: GCode Command and System Command.

screenshot 2018-09-13 10 02 09 screenshot 2018-09-13 10 02 42

SergeyKrutyko commented 6 years ago

qip shot - screen 746

SergeyKrutyko commented 6 years ago

@AxMod3DPrint the problem is that when using the GCODE in PSU Plugin works from the terminal, but does not work from the menu

mcmatrix commented 6 years ago

@SergeyKrutyko Maybe you could additionally try Action Commands plugin to catch firmware responses. https://plugins.octoprint.org/plugins/actioncommands/

In Octoprint Action Commands plugin you have to define 2 additional actions poweroff type:system gpio mode 7 output & gpio write 7 0 poweron type:system gpio mode 7 output & gpio write 7 1

And from the menu you have to send an action to Octoprint

[menu control_pon]
type: command
name: Power ON
action: respond action:poweron
gcode:

[menu control_poff]
type: command
name: Power OFF
action: respond action:poweroff
gcode:
ViperWorx commented 6 years ago

@SergeyKrutyko realise that. Settings screens were there as an example.

SergeyKrutyko commented 6 years ago

@mcmatrix NOT WORK VIA ACTION..... log file nothing too..... (((

CHILLYSMOKES commented 6 years ago

@mcmatrix Can you just make another menu 'element' that will execute system commands? You have already called os. in your header. This will remove the need to interface Octoprint. Lemme know if I'm close. 8)

mcmatrix commented 6 years ago

@SergeyKrutyko What didn't work? To help you I need more info. This is how I understand the PSU plugin is working. Correct me if I'm wrong. You have defined 2 On System commands to turn gpio on/off. Octoprint is monitoring gcodes that are feed thru it and will catch M80, M81. When seeing M80 it will execute ON command, when M81 then OFF command.

The Klipper won't see these because Octoprint will catch these gcodes and these will not pass. Klipper doesn't support such gcodes.

To make it work you have to use additional plugin Action Commands.

Did you define two actions poweroff, poweron in that Octoprint plugin and made changes in menu items? When you execute menu item what you'll see in Octoprint console?

For example when executing Power ON from the menu it should send //action:poweron to the host (octoprint). Octoprint plugin is monitoring these and will execute whatever command you have attached to these actions.

mcmatrix commented 6 years ago

@mcmatrix Can you just make another menu 'element' that will execute system commands? You have already called os. in your header. This will remove the need to interface Octoprint. Lemme know if I'm close. 8)

@KevinOConnor What do you think about this? I can add additional function to action:. Let's say call <whatever you want to call from shell>. Is there a safe way to execute shell commands from Klipper (sync or async?) without breaking Klipper workflow?

KevinOConnor commented 6 years ago

@KevinOConnor What do you think about this? I can add additional function to action:. Let's say call . Is there a safe way to execute shell commands from Klipper (sync or async?) without breaking Klipper workflow?

I'd prefer to avoid that. (Running shell commands can lead to flow control problems and security concerns.) I think the long term solution would be to enhance the Klipper Linux MCU code to support toggling gpio pins on the Raspberry Pi. Then flipping the power pin would be just like flipping any other pin in Klipper.

-Kevin

galosre commented 4 years ago

@mcmatrix Sorry to reopen this. But i am anxious to get it working with PSU Control when switching Method is "Gpio pin#" what should be the fields in action commands? Janar Sööt image

ld3300 commented 4 years ago

Hi @galosre ,

This is how I have implemented it: I actually use the gcode response method, but it should work either way (as long as you have respond declared in your config file

[respond]
default_type: echo
[menu __klipper __shutdownnow]
type: command
name: Shutdown Now
enable: true
gcode: RESPOND TYPE=command MSG=action:M81

Then in the Action Commands Octoprint plugin (not action commands prompt) setup something like this (the first line is what you would want): action commands

Then in PSU control set this up: psu control

and for good measure in Serial Connection under Firmware and Protocol I block those commands from being sent to the printer (just so it doesn't complain at me): serial connection

galosre commented 4 years ago

I got it working for a while with M81 but I wanted to try your other suggestion from the other thread: remove the "action:" from the last line and try it. gcode: RESPOND TYPE=command MSG=poweroff but this definitely was not working action:poweroff Unknown command:"GCODE:" but now with M81 got just 19:17:16 action:M81 This is very strange! [menu __command_power_off] type: command name: Power off enable: true gcode: RESPOND TYPE=command MSG=action:M81

And about the same topic how can I trigger this Gcode macro? [gcode_macro M80] gcode: RESPOND TYPE=command MSG=action:poweron G4 P1500 FIRMWARE_RESTART gcode: RESPOND TYPE=command MSG=poweron does not bring me any joy! image

ld3300 commented 4 years ago

my bad, the action:M81 is supposed to be there. I was looking at the wrong thing.

Assuming your host processor isn't powered from your psu then startup would be the same, but you would need another action command for the firmware restart. If your host is powered from the PSU (as mine is), then you cannot send an action command to turn it on. You have to configure the power on with the top bar button, or by one of the other means PSU control documents.

you can't put gcode macros in action commands like that (gcode: RESPOND TYPE=command MSG=poweron), they only exist in klipper.

I essentially wrote the tutorial for you a couple of posts ago and you got it working. You just need to keep applying the same principles to execute other Action Commands. The principles are you send a RESPOND TYPE=command MSG=action:(whatever) Put the (whatever) in the action field put the gcode or name of a klipper gcode_macro you want to spit out in the last field (ie M80, START_PRINT, firmware_restart, whatever), and when the action command is received the value will be sent.

Spend some time looking through the klipper supported gcodes file and the gcode macros section of the example-extras.cfg file to learn what can be implemented.

galosre commented 4 years ago

Finally the menu [menu __command_power_off] is working again I think the plugin got confused with the other actions No, my PI is always on I just want to send firmware _restart, When I click connect in klipper's plugin but this does not appear to be picked up. image

ld3300 commented 4 years ago

That probably won't work with action commands, but did you try putting it in the octoprint gcode settings screen where it says "after connection to printer is established"

galosre commented 4 years ago

Thank you so much this is working perfectly image One last question not related at the end of a print" I got Too many consecutive timeouts, printer still connected and alive?" and this happened before Psu control Trigger Off.

ld3300 commented 4 years ago

Do you have any Kipper macros running at the end of the print that have long wait times?

galosre commented 4 years ago

Maybe G4 ; Wait in cura Custom End G-code Anyway not a big deal.

galosre commented 4 years ago

I just realized just adding M80 and M81 in those fields I can start and end (if necessary ) the printer just by clicking connect /disconnect in octoklipper without ever using the green lightning icon from psu control so in this case Action Command is just useful for the menu poweroff Again Thank you image

whoim2 commented 4 years ago

Я только что понял, что просто добавив M80 и M81 в эти поля, я могу запускать и завершать (при необходимости) принтер, просто нажимая кнопку «Подключить / отключить» в octoklipper, даже не используя зеленый значок молнии из элемента управления psu, поэтому в этом случае команда Action просто полезна для Poweroff меню снова Спасибо образ

Hello! I need delay between board power on and 'firmware_restart', no work as you wrote. Work if type mannualy in terminal..