I want to use the value, you get when using the PROBE command in a macro. how do I have to do that?
something like this? Feature request: Run a gcode command and store output in a macro variable or some internal location ¡ Issue #2573 ¡ Klipper3d/klipper ¡ GitHub
personally it can just be grepâd out of the klippy.log
this one greps the last 100lines of klippy.log
tail -n 100 klippy.log | grep âResultâ
outputs:
Result is z=-0.017969
for example, but what you do with it?? you can pipe it into another file and read it maybeâŚ
I asked a similar question recently, you can find the z_offset by using
{printer.gcode_move.homing_origin.z}
Note that you canât query that variable in the same macro as you do a G28 or other probe commands, so you have to put the query inside another macro, and call that macro to do the query. Something like this:
[gcode_macro QUERY_ZOFFSET]
gcode:
MESSAGE MSG="Final Z Offset value: {printer.gcode_move.homing_origin.z}"
Note 2: That variable only includes the changes made to z_offset at runtime, and does not include the value specified in the config file. You can retrieve that value by using something like
{printer.config_file.probe.z_offset} (double check the syntax, I'm going by memory)
Hope this helps
So I tried your solution but it shows 0.0 on the LCD (probably my fault). In Addition I
need the value in the original macro any Idea?
[gcode_macro QUERY_ZOFFSET]
gcode:
m117 {printer.gcode_move.homing_origin.z}
[gcode_macro ScrewAdjust]
gcode:
G28
G1 X{43.71} Y{67.96} F6000
Probe
QUERY_ZOFFSET
I want to write a custom screw tilt adjust. The printer takes one screw as a baseline and then continuously probes on the next point while you turn the screw until the height is near the one of the baseline. You get feedback how much and in which direction you have to turn.
Iâm not familiar with the probe command, just I just looked it up in the documentation, and it makes no mention of it changing the z_offset. If you just want the z position, rather than the z_offset, you could try using the MANUAL_PROBE command, and then use {printer.manual_probe.z_position} to find the current Z position
As for getting the value in the original macro, you might be able to use a gcode_macro for a global variable, and storing the value there. I have no idea if it would work or not, but if you give me a little while, I will test it
Actually, you can also find the position by using {printer.gcode_move.position.z}
Thanks i got the time. Iâm really surprised how active this page is. Thanks a lot! for your help.
I actually donât want to use the MANUAL_PROBE command. Wouldnât it be possible to use the value u get as a result when using the PROBE command?
Thatâs the Z position, not the offset. You should be able to read the value with {printer.gcode_move.position.z}, but again, in a separate macro. Iâm just trying now to see how you might get the value back in the original macro
I wasnât able to get the return value, I had my doubts. Hopefully someone who actually knows what they are talking about will chime in with the correct answer
Ok thx
Iâm new to this so please donât cry if i write complete shit. Is it possible to create a macro that returns a value?
Itâs all good. We all started from scratch and one point or another. To answer your question, not that I am aware of. Thatâs why I was trying to store the return value in a global variable, but that didnât work either. I will keep thinking about it, as I would really like to find a way to do it too.
So I found this :
and then wrote this:
[gcode_macro SetBaseLine]
BaseLine: 0
gcode:
{% set BaseLine = printer.gcode_move.position.z%}
[gcode_macro TestPoint]
InTolerance: False
gcode:
{% if printer.gcode_move.position.z>[âgcode_macro SetBaseLineâ].BaseLine-([âgcode_macro ScrewAdjustâ].Tolerance)/2 and printer.gcode_move.position.z<[âgcode_macro SetBaseLineâ].BaseLine+([âgcode_macro ScrewAdjustâ].Tolerance)/2%}
{action_respond_info(âPerfectâ)}
{% set InTolerance = True %}
{% endif %}
{% if printer.gcode_move.position.z>[âgcode_macro SetBaseLineâ].BaseLine %}
{action_respond_info(âLowerâ)}
{% endif %}
{% if printer.gcode_move.position.z<[âgcode_macro SetBaseLineâ].BaseLine %}
{action_respond_info(âHigherâ)}
{% endif %}
[gcode_macro ScrewAdjust]
Tolerance: 0.01
ScrewPitch: 0.5
gcode:
G28
G1 X{43.71} Y{67.96} F6000
PROBE
SetBaseLine
G1 X{279.91} Y{67.96} F6000
{% for [âgcode_macro TestPointâ].InTolerance != True %}
PROBE
TestPoint
{% endfor %}
G1 X{43.71} Y{310} F6000
G1 X{279.91} Y{310} F6000
but Iâm getting this Error. Any Ideas?
Error loading template âgcode_macro ScrewAdjust:gcodeâ: TemplateSyntaxError: canât assign to âlistâ
So I found this:
and wrote this:
[gcode_macro SetBaseLine]
BaseLine: 0
gcode:
{% set BaseLine = printer.gcode_move.position.z%}
[gcode_macro TestPoint]
InTolerance: False
gcode:
{% if printer.gcode_move.position.z>[âgcode_macro SetBaseLineâ].BaseLine-([âgcode_macro ScrewAdjustâ].Tolerance)/2 and printer.gcode_move.position.z<[âgcode_macro SetBaseLineâ].BaseLine+([âgcode_macro ScrewAdjustâ].Tolerance)/2%}
{action_respond_info(âPerfectâ)}
{% set InTolerance = True %}
{% endif %}
{% if printer.gcode_move.position.z>[âgcode_macro SetBaseLineâ].BaseLine %}
{action_respond_info(âLowerâ)}
{% endif %}
{% if printer.gcode_move.position.z<[âgcode_macro SetBaseLineâ].BaseLine %}
{action_respond_info(âHigherâ)}
{% endif %}
[gcode_macro ScrewAdjust]
Tolerance: 0.01
ScrewPitch: 0.5
gcode:
G28
G1 X{43.71} Y{67.96} F6000
PROBE
SetBaseLine
G1 X{279.91} Y{67.96} F6000
{% for [âgcode_macro TestPointâ].InTolerance != True %}
PROBE
TestPoint
{% endfor %}
G1 X{43.71} Y{310} F6000
G1 X{279.91} Y{310} F6000
Getting this error:
Error loading template âgcode_macro ScrewAdjust:gcodeâ: TemplateSyntaxError: canât assign to âlistâ
First off, I know very little about Python or Jinja, but I think that you need to prefix the expression with âprinterâ
So this:
{% for [âgcode_macro TestPointâ].InTolerance != True %}
Should be this:
{% for printer[âgcode_macro TestPointâ].InTolerance != True %}
Thatâs how I use it, and how it is referenced in the image you posted above. Without that prefix, I think Jinja interprets the items within the square brackets to be a list
[gcode_macro SetBaseLine]
BaseLine: 0
gcode:
{% set BaseLine = printer.gcode_move.position.z%}
[gcode_macro TestPoint]
InTolerance: False
gcode:
{% if printer.gcode_move.position.z>printer[âgcode_macro SetBaseLineâ].BaseLine-(printer[âgcode_macro ScrewAdjustâ].Tolerance)/2 and printer.gcode_move.position.z<printer[âgcode_macro SetBaseLineâ].BaseLine+(printer[âgcode_macro ScrewAdjustâ].Tolerance)/2%}
{action_respond_info(âPerfectâ)}
{% set InTolerance = True %}
{% endif %}
{% if printer.gcode_move.position.z>printer[âgcode_macro SetBaseLineâ].BaseLine %}
{action_respond_info(âLowerâ)}
{% endif %}
{% if printer.gcode_move.position.z<printer[âgcode_macro SetBaseLineâ].BaseLine %}
{action_respond_info(âHigherâ)}
{% endif %}
[gcode_macro ScrewAdjust]
Tolerance: 0.01
ScrewPitch: 0.5
gcode:
G28
G1 X{43.71} Y{67.96} F6000
PROBE
SetBaseLine
G1 X{279.91} Y{67.96} F6000
{% for printer[âgcode_macro TestPointâ].InTolerance != True %}
PROBE
TestPoint
{% endfor %}
G1 X{43.71} Y{310} F6000
G1 X{279.91} Y{310} F6000
now i got this error:
Error loading template âgcode_macro ScrewAdjust:gcodeâ: TemplateSyntaxError: expected token âinâ, got â[â
Yes, the syntax for the for loop is wrong, in fact the logic for that section of code is wrong. I can tell you why it is wrong, but I donât know Python so I donât know how to fix it.
The problem is that the for loop is expecting a list of values to cycle through, so something like
for a in [1 2 3 4 5]
(I donât know if that syntax is correct in Python, but thatâs sort of how I would do it in Perl) But you have given the for command a scalar value (printer[âgcode_macro TestPointâ].InTolerance) rather than a list., and that is why you are getting that error. I have to go out for a few hours, but I will take a look later and see if I can find the correct syntax for you, but hopefully someone who knows Python / Jinja will reply before then.
Also, as I said, the logic is wrong. Are you trying to store a list of points to be probed somewhere? If so, you need a list or an array, but currently you have a single scalar value. Assuming that you are trying to probe a list of points, you need to change the code to something like this.
{% for point_to_scan in [1 2 3 4] %}
{% if printer[âgcode_macro TestPointâ].InTolerance(point_to_scan) != True %}
PROBE
TestPoint
{% endif %}
{% endfor %}
Again, syntax will be wrong, but hopefully you will get what I mean
Is there something like a while loop in JINJA2? I havenât got a list so far. I just have these four movement commands to move to the points.