Take image via GCode-Command

In my plugin PrintJobHistory I implemented a feature to take a snapshot after a specific M117 command was executed.
It looks like that this feature did not work, see M117 Snap Not Taking a Snapshot · Issue #123 · OllisGit/OctoPrint-PrintJobHistory · GitHub

It does not take the picture until the bed and gantry have moved to the final position.

I use the "octoprint.comm.protocol.gcode.sent" hook and it listen for a specific M117 command:
See https://github.com/OllisGit/OctoPrint-PrintJobHistory/blob/1bb95f30ddf91eb61795ee51593a91d0e812236b/octoprint_PrintJobHistory/init.py#L768-L781

If the command reached, I started a new thread to take a picture...the picture is taken succesful, but too late.

I know that are a couple of caches/buffers involved and also the thread of the camera could also be an issue. But what do you think, is is possible to implement such feature?

Btw. in the next Plugin-Release I will change the hook to: octoprint.comm.protocol.gcode.sending ...maybe it makes a difference.

Taking pictures in-sync with gcode is a very hard problem to solve - look at what the OctoLapse plugin has to try and do. One of the key things it uses is the M400 (finish moves) command, and then uses the G4 (dwell) command (I think it's that one) to pause the printer while it takes the picture.

The delay is configurable because every setup is different. Some cameras are slower, some are fast. Lower resolutions are a lot quicker to download and save a snapshot to the disk, and different Pi's will process in different amounts of time. It's impossible to get one setup for everyone.

If the people using this feature adjusted their gcode to include a G4 delay after the 'take snapshot' command, they may have more success.

1 Like

Might also be able to make use of M118 before G4 so you know exactly when the machine is pausing.

@Charlie_Powell , @kantlivelong, thanks a lot for your answers.

I will try to implement the M118 approach. The gcode looks like this:

M400 ;finish moves
M300 S440 P100 ; playing a beep
G4 P1000 ;Wait for no vibrations

M118 //action:pjhTakeSnapshot

G4 P60000 ;Camera take the picture 

Lets see..maybe it works :wink:

Actually even better you might be able to hold the queue after sending M118 eliminating the need for the snapshot pause at all. Once you receive pjhTakeSnapshot you know you're good to snap so once the snap is done you can resume the job.

Definitely follow up on this though.