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

execute G-Code after render finish #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pappicio
Copy link

add some python code and timelapse.cfg gmacro to time shutdown printer after collected mp4 from jpgs

@@ -342,3 +346,21 @@ gcode:
RESUME_BASE
{% endif %}

[gcode_macro _done_shutdown]
gcode:
UPDATE_DELAYED_GCODE ID=_done_shutdown_timer DURATION=0
Copy link
Author

@pappicio pappicio Oct 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPDATE_DELAYED_GCODE ID=_done_shutdown_timer DURATION=0
my own code to delete delayed gcode on printeing finish on printer.cfg

{% else %}
m117 spengo.....
m118 spengo.....
spegni_tutto
Copy link
Author

@pappicio pappicio Oct 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spegni_tutto
my own gcode to power off a tasmota switch to shutdown printer and raspberry

@FrYakaTKoP
Copy link
Member

@pappicio Thanks for your suggestion but i don't think it's a good idea to have a "shutdown command" built in to the render method.

We already have a working solution for all that like to shutdown there printers after a finished render. I still need to properly test and document it but that's what the render macro is for:

Disable Autorender and add following to you print end gcode after heater are off etc.

TIMELAPSE_RENDER
; here your shutdown gcode

@pappicio
Copy link
Author

pappicio commented Oct 30, 2021

@pappicio Thanks for your suggestion but i don't think it's a good idea to have a "shutdown command" built in to the render method.

We already have a working solution for all that like to shutdown there printers after a finished render. I still need to properly test and document it but that's what the render macro is for:

Disable Autorender and add following to you print end gcode after heater are off etc.

TIMELAPSE_RENDER
; here your shutdown gcode

Ok. Thanks a lot for that. I'll try to use your solution, I'll be able to shutdown all, also Raspberry, only when render Is finish3d and MP4 created.

@FrYakaTKoP
Copy link
Member

Ok. Thanks a lot for that. I'll try to use your solution, I'll be able to shutdown all, also Raspberry, only when render Is finish3d and MP4 created.

yes that what was the idea behind the render macro. Please give feedback when it works for you.

@pappicio
Copy link
Author

pappicio commented Oct 31, 2021

it doesn't works like expected:
I thinked:
end print/start render/render finish/create .mp4/start delayed count down to shutdown printer
but...

08:24:32
echo: Fatto!!!
08:24:33
// Timelapse: Rendering started
08:24:33
echo: Countdown spegnimento...
08:24:34
echo: ciclo2...
08:24:35
echo: ciclo2...
08:24:37
echo: ciclo2...
08:24:37
echo: ciclo2...
08:24:38
echo: ciclo2...
.....
08:25:09
echo: ciclo2...
08:25:11
echo: ciclo2...
08:25:12
echo: ciclo2...
08:25:12
// Timelapse: Rendering finished
08:25:12
Done printing file

it starts countdown while render video, it could appen that the timer to shutdown is shorter to render all works, and printer could be turned off before I have the timelapse ready,
like:
08:24:32
echo: Fatto!!!
08:24:33
// Timelapse: Rendering started
// Timelapse: Rendering finished
echo: Countdown spegnimento...
08:24:34
echo: ciclo2...
08:24:35
echo: ciclo2...
08:24:37
echo: ciclo2...
08:24:37
echo: ciclo2...
08:24:38
echo: ciclo2...
08:25:09
echo: ciclo2...
08:25:11
echo: ciclo2...
08:25:12
echo: ciclo2...
08:25:12
08:25:12
Done printing file

@pappicio
Copy link
Author

and.... is it possible to add a variable: pause_while_render, cos pause_base gcode on rendering enable my alexa to advice that printer is in pause, maybe for filament change (I use also change filament color during print!), and false advices appens in this way, while if I can choice to pause or not, all could be works well,
I noted also that extruder to cold down around 50 degrees, thake a while, maybe in that time, all renders can be possible to finish...

@FrYakaTKoP
Copy link
Member

FrYakaTKoP commented Oct 31, 2021

@pappicio

and.... is it possible to add a variable: pause_while_render.

Sorry the Pause is needed to block further execution of the gcode. There is no other way i can achieve a "render and wait" in gcode other than the pause. We introduced the pause because before people would have to a very long G4 Dwell after starting the render to make sure the render is finished. I may consider to add a user configurable gcode execution after render is finished in future but i got other priorities at the moment.

I noted also that extruder to cold down around 50 degrees, thake a while, maybe in that time, all renders can be possible to finish...
the cooldown shouldn't be a blocking gcode so i don't understand what you mean. Could you explain this further?

edit
also if you need a render macro without a pause, just make your own and add it to your printer.cfg

[gcode_macro TIMELAPSE_RENDER_NOPAUSE]
gcode:
  {action_call_remote_method("timelapse_render")}

but be warned this will not block further gcode exectution and you will need to dwell enough time before shutting down your raspberry

@pappicio
Copy link
Author

pappicio commented Oct 31, 2021

maybe some code is better than 1000 words:

[gcode_macro END_PRINT]
...
...
TIMELAPSE_RENDER
UPDATE_DELAYED_GCODE ID=_done_shutdown_timer DURATION=1
M117 countdown spegnimento...
M118 Countdown spegnimento...

[delayed_gcode _done_shutdown_timer]
initial_duration: 0
gcode:
{% if printer.extruder.temperature > 50 %}
UPDATE_DELAYED_GCODE ID=_done_shutdown_timer DURATION=1
m117 ciclo2...
m118 ciclo2...
{% else %}
m117 spengo...
m118 spengo...

#macro to shutdown tasmota switch on printer

spegni_tutto

{% endif %}

[gcode_macro spegni_tutto]
gcode:
{action_call_remote_method("set_device_power",
device="spegni_tutto",
state="off")}

when print finish, I wait for extruder cools down at < 50 degree, then shutdown printer... and it take a while... maybe some minutes that are sufficient to save timelapse.

@pappicio
Copy link
Author

in order to the pause command, it dowsn't block gcode execution, In my end_print gcode, stop all, shutdown termistor, and execute:
TIMELAPSE_RENDER

while render is executed, also starts my colddown timer, not after, so, start render, execute other parts of my gcode, includinf printer shutdown and after stop timelapse_render, as you can see in belowe console output...
I'd like to have:
TIMELAPSE_RENDER
wait (while lock other gcode execution)
wait
wait
TIMELAPSE_RENDER END
continue to execute my gcode
shutsown printer.
and the only way to do that (in gcode), I've found is only by loop command like that...


[gcode_macro START_PRINT]
...
...
M117 Riscaldo Piatto e estrusore...
M118 Riscaldo Piatto e estrusore...
M140 S{B} ; heat Bed senza attendere
M104 S{H}
check_temp
...
...
*end start_print

[gcode_macro check_temp]
gcode:
{% set count = 1200 %} ###10 wait max 10 minues while extruder heads...
{% for c in range(count) %}
templedcolor_timer
{% endfor %}

[gcode_macro templedcolor_timer]
gcode:
{% if printer.extruder.target|int > 0 %}
{% if printer.extruder.temperature < printer.extruder.target %}
#M117 ciclico...
#M118 ciclico...
{% set rosso = (printer.extruder.temperature / printer.extruder.target)|round(2) %}
{% set blu = (1-(printer.extruder.temperature / printer.extruder.target))|round(2) %}
#M117 rosso={rosso} blu={blu }
#M118 rosso={rosso} blu ={blu }
SET_LED LED=neopixel RED={rosso} GREEN=0 BLUE={blu}
G4 P500
#{% else %}
#M117 Fine ciclo...
#M118 Fine ciclo...
{% endif %}
{% else %}
m118 extrusore spento...
{% endif %}


only in this case, with a for cycle, I can wait looping into a gcode block and execute other macro to change led strip color according extruder temp, but main gmacro (STERT_PRINT), wait.... and continue only after for loop ends
somrthing similiar into render code, could appen, wait its execution until finished, and then continue the macro that called command:
TIMELAPSE_RENDER

@FrYakaTKoP
Copy link
Member

FrYakaTKoP commented Oct 31, 2021

@pappicio sorry but i don't see to add a non pause variable to the macro to master. What i understand you need a timelapse render which is not blocking further gcode execution and like to make your own wait loop. If so, just overwrite the predefined macro with your own either make a copy of timelapse.cfg with a different name and include this instead ot just add your custom macro after [include timelapse.cfg] which will overwrite the existing one, but also doesn't change the macro file in the repo. So you still can update via updatemanager but can use your custom macro. But adding a "nopause" variable to master will confuse most people don't understand the concept around it, so i don't think it's smart to do so.

Also from your PR i understand you need to run a custom gcode macro after the render is finished. As said that is something i can see as a feature in the master without adding confusion to most people. So when my other priorities are done i will add the possibility to run a gcode macro after render is finished.

Would that satisfy your needs?

@pappicio
Copy link
Author

pappicio commented Oct 31, 2021

Would that satisfy your needs?

yes, shurely, and thanks for your great work about, I'll use my shutdown timer joined
to the TIMELAPSE_RENDER command into [END_PRINT] gcode
is ok for me! (waiting a custom gcode to execute only after render finished!!!)
thanks a lot, for me this pull request can be close!

@FrYakaTKoP
Copy link
Member

@pappicio i will close it when i added gcode execution after finished render ;)

@FrYakaTKoP FrYakaTKoP self-assigned this Nov 14, 2021
@FrYakaTKoP FrYakaTKoP added the enhancement New feature or request label Nov 20, 2021
@FrYakaTKoP FrYakaTKoP changed the title Add files via upload execute G-Code after render finish Dec 5, 2021
@QGB
Copy link

QGB commented Mar 7, 2023

moonraker How to post gcode wait to finish blocking call?

@FrYakaTKoP
Copy link
Member

FrYakaTKoP commented Apr 11, 2023

moonraker How to post gcode wait to finish blocking call?

that's the problem, klipper doesn't allow blocking gcode calls. That's the reason we use the pause macro to hold back further gcode execution. On the other hand if you use the upstream version of the code TIMELAPSE_RENDER should pause klipper and therefore stop further execution of later gcode until finished.

Are you using pappicio's fork or the upstream code? If the first please try changing to upstream it should be fixed there. If later please make a new issue with the title "render doesn't block further gcode execution" and add attach a moonraker.log with a failed print/timelapse in it, so i can investigate further

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants