/api/printer/command is asynchronous


#1

Is there a trick/way to wait for G-Code command completion in octoprint rest API?

I'm trying to command the printer (via /api/printer/command) to go to a certain position, then read the position using an external instrument (a DRO - Digital Readout). Trouble is the octoprint command returns before completion and the DRO read happens somewhere in the middle of the move. I could of course wait (a lot! esp for Z) but that would kind of defeat the purpose of the project: to quickly test for any positioning errors.

Here is a log with sequence of commanded position / actual position when that command returned


x:\node octotest 0
{Printer:0.0, DRO:-0.007}

x:\node octotest 0
{Printer:0.0, DRO:-0.007}

x:\node octotest 10
{Printer:10.0, DRO:3.079}

x:\node octotest 10
{Printer:10.0, DRO:9.990}

x:\node octotest 0
{Printer:0.0, DRO:4.834}

x:\node octotest 0
{Printer:0.0, DRO:-0.007}

x:\node octotest 10
{Printer:10.0, DRO:9.150}

x:\node octotest 20
{Printer:20.0, DRO:12.829}

x:\node octotest 20
{Printer:20.0, DRO:19.953}

x:\node octotest 0
{Printer:0.0, DRO:16.424}

x:\node octotest 0
{Printer:0.0, DRO:-0.007}


#2

I fear you'll need to write a custom plugin for that, have it issue your positioning command, wait for movements to finish via M400 and then send an M114 or some other kind of information query with on_sent filled so that it calls your measurement routine.

That's similar to how @FormerLurker does ensure Octolapse waits for all moves to finish before triggering an image capture as far as I know.

The API - due to its and the printer's firmware asynchronous nature - is ill suited for the task as you observed yourself.


#3

@mgx3d, let me know if you decide to create a plugin for this and I will point you in the right direction. It turns out it is pretty tricky to implement the functionality you want, but it IS possible with most printers.