stuartofmt / DuetLapse3

Create time lapse videos from Duet3D based 3D Printers
20 stars 3 forks source link

Run custom command and end of print. #5

Closed adammhaile closed 2 years ago

adammhaile commented 2 years ago

Maybe I'm just missing something but I'm wondering if it's possible to have run custom handling at the end of the print? Specifically what I'm trying to do is switch from taking an image every layer to triggering a video to be captured. My printer will park both tools (it's IDEX) and then lift the bed and the print all the way up out the top of the machine. I thought it would be need to do the normal timelapse but then capture this last part at the end of the print.

Maybe this is something I could add? I'd love to have the ability to trigger actions based on specific gcode - a comment even. I'm quite comfortable with Python, just unsure of where might be best to add such a feature in the duetlapse code.

stuartofmt commented 2 years ago

Let me have a think about that. Could it be something as simple as switching to a timed Timelapse for a specific length of time after the print is complete ? I’m not sure gcodes will help because they are done once the print job is finished but it may be possible to intercept - something to ponder.

adammhaile commented 2 years ago

Well, I guess more what I'd be after is the ability to do something like insert ; DO VIDEO (or really anything) and have DuetLapse see that and trigger a different mode - such as simply capturing a video. And, I'll admit, my setup is even weirder because I'm kind of abusing how it all works... I have a Lumix camera that can be controlled over wifi. I can trigger it to take an image with a simple http call - so I'm using the weburl1 parameter and just giving it that HTTP path - it causes the camera to capture an image to it's SD card, but does not actually return the image. So DuetLapse fails to create a timelapse at the end (all the "images" it receives are just text responses from the HTTP call). And what I was hoping to do was then make a final HTTP call that will tell it to start capturing video at a pre-determined time (based on inserted GCode).

I think that there's a duet plugin or something that let's you fire arbitrary code based on GCode calls... I may just have to use that.

stuartofmt commented 2 years ago

Let me have a little think about this. It can be done and I have the code to detect certain gcode (specifically M117 through the message output) in one of my other apps. Its a matter of how to do it in a simple and flexible way. I have some ideas.

Initial thoughts are to embed a M117 message (with special format) that contains the name of a bash script or program to execute. In your case - the script would have the http call you want to make (for example using wget).

As well -- your request had my think about how the -extratime option was implemented. I've not been happy with it because of vagaries with ffmpeg, so I think I have different and better way to implement that functionality.

With a bit of luck I may have a prototype for you to try in a couple of days.

stuartofmt commented 2 years ago

@adammhaile

Here is what I came up with. Please test it out and let me know.

It will monitor messages created by M117 gcode (either in the print file or from the DWC console).

There is a new switch -execkey that specifies a string patter to indicate that the message contains a command. (e.g. -execkey :do: ). It just has to be something that would not normally appear at the start of a message. When DuetLapse3 sees a message with the execkey at the start, it takes the rest of the message and tries to execute the remainder of the message string.

Lets say there is a bash script (or python or ...) -- test.sh `

!/bin/bash

echo "-----------"

echo "$1 $2"

echo "----------"

`

Send M117 :do: ./test.sh 'hello !' world NOTE: there are no quotes around the full M117 string This will cause DuetLapse3 to execute ./test.sh 'hello !' world in the local OS. Note: In this example you will only see the output if you are running DuetLapse3 in a console.

You will need to rename the file to DuetLapse3.py EDIT: Let me repost this file later today. I'd accidentally cut/paste some stuff should not have been in that file :-(

stuartofmt commented 2 years ago

@adammhaile

Please try this. Edit: Deleted [DuetLapse3.py.txt]

stuartofmt commented 2 years ago

Latest ..... fixed a self induced error ...

[DuetLapse3.py.txt]

adammhaile commented 2 years ago

Hey, Thanks @stuartofmt ! I promise I will try this out real soon... I started a 5 day print right before you posted the first one... it's still going.

stuartofmt commented 2 years ago

@adammhaile

You might want to try this. Its the next release candidate. I added the following, fairly significant addition. It may also be useful in your context.

Appreciate any feedback.

Using M117 Duetlapse3.[x] to control DuetLapse3

gcode file can now include M117 (message) to control DuetLapse3. This provides more finite control by allowing (for example) capture of images to start and stop at a specific point in the print. This feature supports all the explicit control commands in the web interface, specifically

'start','standby','pause','continue', 'snapshot', 'restart', 'terminate'

Note that the M117 commands can be sent from DWC or the printer gcode file, although the most useful for will be from the gcode file.

Valid command are in the form M117 Duetlapse3.[x] where [x] is one of the control commands given above.

For Example

M117 DuetLapse3.start    # Causes DuetLapse3 to start (assuming it was in standby)
G4 S10

NOTE especially the use of G4 (dwell) immediately after the EACH M117 code. THIS IS MANDATORY FOR CORRECT OPERATION.
M117 messages over write previous messages and DuetLapse3 needs to "see" the command. If a newer M117 was sent before DuetLapse3 "saw" the command, the command would be missed.

DuetLapse3 polls (default every 5 seconds). The recommended dwell is 2 times the poll interval (10 seconds if using the default).

One way to use this feature would be (but is not limited to) starting DuetLapse3 with the option:
-standby

Then include M117 DuetLapse3.start in the gcode print file where you want image capture to start. Then include M117 DuetLapse3.terminate where you want image capture to stop.

An example test gcode is here:

Run DuetLapse3 with the following suggested options:

-verbose -standby -extratime 5 -execkey :do: -keepfiles -dontwait -seconds 30 

It does not print but does move the print head around. It includes M117 DuetLapse3.start, M117 DuetLapse3.snapshot and M117 DuetLapse3.terminate. It also includes M117 :do: commands that invoke test.sh here:

#!/bin/bash

echo "-----------"

echo "$1 $2"

echo "----------"
stuartofmt commented 2 years ago

This capability was rolled into Version 4.0.0