cp2004 / OctoPrint-GCodeMacros

Configure custom gcode macros you can use anywhere!
https://plugins.octoprint.org/plugins/gcode_macro
GNU Affero General Public License v3.0
7 stars 2 forks source link

[Feature Request] Wait for and use response #13

Closed dajomas closed 2 years ago

dajomas commented 2 years ago

Hi,

would it be possible to build in functionality to wait for a response and use the contents of that response.

For instance, when I send G28 X0 Y0 my Creality3D Ender 5 Plus responds with Recv: X:360.00 Y:360.00 Z:40.20 E:813.64 Count X:28800 Y:28800 Z:32160

Now, I would like to extract the first X and Y values and be able to halve them so I can center my nozzle on the plate

for example, do something like this:

G28 X0 Y0
{% wait_for "Recv:" | extract_key_value %}

This could then result in something like:

Recv: {
  'X1': 360.00,
  'Y1': 360.00,
  'Z1': 40.20,
  'E1': 813.64,
  'X2': 28800,
  'Y2': 28800,
  'Z2': 32160
}

Then I could use this to center the nozzle:

G0 X{% Recv.X1/-2 %} Y{% Recv.Y1/-2 %}
cp2004 commented 2 years ago

Unfortunately this would not be possible to do from this plugin. The Jinja2 templates are evaluated & rendered once, as soon as the macro @ command is used, they are not rendered live as the script progresses.

Getting a consistent reply back to commands from the printer would be very difficult to make work universally. There's no standard format to the reply from a command, any parsing would have to be done with a custom regex created by the user, as well as the issue that sometimes the received lines back from the printer could be interrupted by stuff like temperature reporting.

For very advanced stuff like this I would recommend to create your own plugin or fork an existing one, so you can create the custom code to try and do this yourself - I can't provide it to an end user effectively.