Gcode streaming ahead/Camera shutter release question


#1

So, I had the idea of using the octopi to control a camera shutter. So I setup the plugin that allows g-code to run a script. Then I setup a script that will toggle a GPIO pin of then on, which is connected to a relay.
When I then pass "OCTO1" in the gcode it does toggle the relay on and off. So far so good.
Then I setup a post processing script to, on every layer change, add a move to the corner of my printer (G0 X400 Y400 F12000), and the OCTO1.

In testing this with a simple gcode file that will move 100mm one way, trigger, move back, trigger, repeat...
I find that it just toggles off and on the relay over and over, and then is still moving back and forth long after it has finished toggling off and on.

I think this is because it's reading in, and sending the gcode several moves ahead of where the printer is actually interpreting them. Is there a way to get around this. I want the printer to move to X400 Y400, stop, take a picture, then move back. This way it will just look like the object is growing out of the build plate of its own volition, in the final time lapse.

Any ideas.


#2

This is happening because of the gcode buffer on the printer's side. OctoPrint is acting on the command as it is being sent to the printer rather than when the printer actually runs that part of the code. I know Make Anything had done a similar set-up as you but he was using a physical remote trigger for his camera and the actual move of the extruder to the "400, 400" position physically pressed the button on the remote.


#3

I figured it out.... I just add a small dwell before OCTO1.
even G4 P50, makes it wait till it's moved into place before triggering the relay, without messing with the firmware buffer.