Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config for Klipper 00-euclid_exampleV4.cfg can't be parsed by clipper #7

Open
VTopoliuk opened this issue May 5, 2022 · 5 comments

Comments

@VTopoliuk
Copy link

Klipper version: v0.10.0-387
Error:

Error loading template 'gcode_macro DEPLOY_PROBE:gcode': TemplateSyntaxError: expected token 'end of print statement', got 'DOCK'

Happens without any modification to original file

@nionio6915
Copy link
Owner

can you provide your printer.cfg and the macro file you are using?

@nionio6915 nionio6915 reopened this Jun 5, 2022
@arikhris
Copy link

arikhris commented Jun 5, 2022

> `# array variables implementation and 
# macro setups credited to user yolodubstep
# see  https://github.com/blalor/vcore3-ratos-config 
# for updates and details
#  __________________________________________________________________________
#  |                                                                        |
#  |                                                                        |
#  |                                                                        |
#  |                                                                        |
#  |                                                                        |
#  |                                                                        |
#  |                                                                        |
#  |                                                                        |
#  |                                                                        |
#  |                                                                        |
#  |                                * Probe Ready Position                  |
#  |                                  X150 Y150                             |
#  |                                                                        |
#  |                                                                        |
#  | * Dock Re-entry staging  position                                      |
#  |   X0 Y70                                                               |
#  |                                                                        |
#  |                                                                        |
#  | * Dock Exit Position                                                   | 
#  |   X0 Y40                                                               |
#  |                                                                        |
#  |                                                                        |
#  |                                                                        |
#  |                                                                        |
#  |                                                                        |
#  |   X0 Y0    X30 Y0       X100 Y0                                        |
#  | * Dock   * Dock Side  * Dock Preflight                                 |
#  |________________________________________________________________________| 
#
# Above is example 300x300 bed to coorelate with macros and movements below.
# This example is for a fixed dock, fixed gantry/carraige and moving bed motion
# system like RailCore, Ender5, V-Core3, etc...
# Delta printes will be similar
# Moving gantry printers like Voron need a a few tweaks to ensure clearances
#  - see cpmments in the code

[gcode_macro EuclidProbe]
description: config vars for Euclid probe deploy/stow

## Replace the cordinates to suit your printer for deployment steps
variable_position_preflight: [ 100, 348 ] # positions for probe to have clear path to dock 
variable_position_side:      [  30, 348 ] # position for probe near dock to swipe on 
variable_position_dock:      [   0, 348 ] # dock position
## exit/re-entry staging
variable_position_exit:      [   0, 40 ] # exit position

## how much space to put between the bed and nozzle for homing
# RatOS
variable_bed_clearance: 15

# 300 * 60
variable_move_speeds: 18000

variable_batch_mode_enabled: False
variable_probe_state: None

gcode:
    RESPOND TYPE=command MSG="{ printer['gcode_macro EuclidProbe'] }"

# the following is a hardware probe config for the hardware configuration. 
# it can appear in the printer.cfg or in the euclid.cfg 
# USE IT IN ONE LOCATION ONLY



[homing_override]
# homing overide is machine specific. this example os for fixed gantry moving bed printer
# users need to verify application or comment out
axes: z
set_position_z: -5
gcode:
    {% set euclid_probe = printer["gcode_macro EuclidProbe"] %}

    G90

    ;; force bed to move 15mm 
    SET_KINEMATIC_POSITION Z=0
    G0 Z{ euclid_probe.bed_clearance } F500

    ;; home Y and X, Y first to avoid running into the dock
    {% if "y" not in (printer.toolhead.homed_axes | lower) %}
        G28 Y
    {% endif %}

    {% if "x" not in (printer.toolhead.homed_axes | lower) %}
        G28 X
    {% endif %}

    DEPLOY_PROBE

    ;; home Z at bed center
    G0 X{ printer.toolhead.axis_maximum.x/2 } Y{ printer.toolhead.axis_maximum.y/2 } F{ euclid_probe.move_speeds }
    G28 Z

    ;; after 'G28 Z' the probe stays in contact with the bed; move it away.
    G0 Z{ euclid_probe.bed_clearance }

    STOW_PROBE

[gcode_macro _ASSERT_PROBE_STATE]
description: ensures probe is in a known state; QUERY_PROBE must have been called before this macro!
gcode:
    ## QUERY_PROBE manually-verified results, when microswitch not depressed
    ## "TRIGGERED" -> 1 :: probe stowed
    ## "open"      -> 0 :: probe deployed
    {% set last_query_state = "stowed" if printer.probe.last_query == 1 else "deployed" %}

    {% if params.MUST_BE != last_query_state %}
        { action_raise_error("expected probe state to be {} but is {} ({})".format(params.MUST_BE, last_query_state, printer.probe.last_query)) }
    {% else %}
        ## all good; update state
        SET_GCODE_VARIABLE MACRO=EuclidProbe VARIABLE=probe_state VALUE="'{ last_query_state }'"
    {% endif %}

[gcode_macro ASSERT_PROBE_DEPLOYED]
description: error if probe not deployed
gcode:
    ; wait for moves to finish, then pause 0.25s for detection
    M400
    G4 P250

    QUERY_PROBE
    _ASSERT_PROBE_STATE MUST_BE=deployed

[gcode_macro ASSERT_PROBE_STOWED]
description: error if probe not stowed
gcode:
    ; wait for moves to finish, then pause 0.25s for detection
    M400
    G4 P250

    QUERY_PROBE
    _ASSERT_PROBE_STATE MUST_BE=stowed

[gcode_macro EUCLID_PROBE_BEGIN_BATCH]
description: begin euclid probe batch mode
gcode:
    SET_GCODE_VARIABLE MACRO=EuclidProbe VARIABLE=batch_mode_enabled VALUE=True
    RESPOND TYPE=command MSG="Probe batch mode enabled"

[gcode_macro EUCLID_PROBE_END_BATCH]
description: end euclid probe batch mode and stow probe
gcode:
    SET_GCODE_VARIABLE MACRO=EuclidProbe VARIABLE=batch_mode_enabled VALUE=False
    RESPOND TYPE=command MSG="Probe batch mode disabled"
    STOW_PROBE


[gcode_macro DEPLOY_PROBE]
description: deploy Euclid probe
gcode:
    {% set euclid_probe = printer["gcode_macro EuclidProbe"] %}

    {% if euclid_probe.batch_mode_enabled and euclid_probe.probe_state == "deployed" %}
        RESPOND TYPE=command MSG="Probe batch mode enabled: already deployed"
    {% else %}
        RESPOND TYPE=command MSG="Deploying probe"

        ; ensure the probe is currently stowed; can't deploy what isn't stowed.
        ASSERT_PROBE_STOWED

        G90

        ; set approach elevation to clear probe over bed on fixed gantry machine
        G0 Z{ euclid_probe.bed_clearance } F500

        ; move the carraige to safe position to start probe pickup
        G0 X{ euclid_probe.position_preflight[0] } Y{ euclid_probe.position_preflight[1] } F{ euclid_probe.move_speeds }

        ;  move to the side of the dock
        G0 X{ euclid_probe.position_side[0] } Y{ euclid_probe.position_side[1] } F{ euclid_probe.move_speeds }

        ; fixed bed dock and moving gantry printers need to add a move command here to lower the gantry to dock height
        ; G0 Z{INSERT DOCK HEIGHT} F500

        ; wait 1/4 second
        M400
        G4 P250

        ;  move sideways over the dock to pick up probe
        G0 X{ euclid_probe.position_dock[0] } Y{ euclid_probe.position_dock[1] } F1500

        ; confirm deploy was successful
        ASSERT_PROBE_DEPLOYED

        ; move out of the dock in a straight line
        G0 X{ euclid_probe.position_exit[0] } Y{ euclid_probe.position_exit[1] } F{ euclid_probe.move_speeds }
    {% endif %}

[gcode_macro STOW_PROBE]
description: stow Euclid probe
gcode:
    {% set euclid_probe = printer["gcode_macro EuclidProbe"] %}

    {% if euclid_probe.batch_mode_enabled %}
        RESPOND TYPE=command MSG="Probe batch mode enabled: not stowing"
    {% else %}
        RESPOND TYPE=command MSG="Stowing probe"

        ; ensure the probe is currently deployed; can't stow what isn't deployed.
        ASSERT_PROBE_DEPLOYED

        G90

        ; set approach elevation for fixed gantry system to clear probe over bed
        G0 Z{ euclid_probe.bed_clearance } F3000

        ; fixed bed dock and moving gantry printers need to add a move command here to lower the gantry to dock height
        ; G0 Z{INSERT DOCK HEIGHT} F500

        ; move to the exit/re-entry staging position
        G0 X{ euclid_probe.position_exit[0] } Y{ euclid_probe.position_exit[1] } F{ euclid_probe.move_speeds }

        ; slowly move into dock
        G0 X{ euclid_probe.position_dock[0] } Y{ euclid_probe.position_dock[1] } F3000

        ; wait for moves to finish, pause to force 90deg travel swipe
        M400
        G4 P250

        ; quick swipe off
        G0 X{ euclid_probe.position_side[0] } Y{ euclid_probe.position_side[1] } F{ euclid_probe.move_speeds }

        ; confirm stowing was successful
        ASSERT_PROBE_STOWED
    {% endif %}


; # Example macro to perform a bed mesh calibration by wrapping it in DEPLOY_PROBE/STOW_PROBE macros
[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_ORIG
gcode:
    DEPLOY_PROBE
    BED_MESH_CALIBRATE_ORIG
    STOW_PROBE

[gcode_macro START_PRINT]
# call from slicer priner gcode via
# START_PRINT EXTRUDER_TEMP=[first_layer_temperature] BED_TEMP=[first_layer_bed_temperature] FILAMENT_TYPE=[filament_type] PRINT_MIN={first_layer_print_min[0]},{first_layer_print_min[1]} PRINT_MAX={first_layer_print_max[0]},{first_layer_print_max[1]}
# 

gcode:
    {% set extruder_temp = params.EXTRUDER_TEMP | default(printer.extruder.target, true)  %}
    {% set bed_temp      = params.BED_TEMP      | default(printer.heater_bed.target, true) %}

    ## reset various states to configured or safe defaults
    CLEAR_PAUSE

    # reset velocity limits
    RESET_VELOCITY

    # reset PA to configured settings
    # comment out if you dont use PA
    SET_PRESSURE_ADVANCE ADVANCE={ printer.configfile.settings.extruder.pressure_advance } SMOOTH_TIME={ printer.configfile.settings.extruder.pressure_advance_smooth_time }

    # reset z offset
    SET_GCODE_OFFSET X=0 Y=0 Z=0

    # Reset speed and extrusion rates, in case they were manually changed
    M220 S100
    M221 S100

    # Metric values
    G21

    # Absolute positioning
    G90

    # Set extruder to absolute mode
    M82

    EUCLID_PROBE_BEGIN_BATCH

    # Home
    G28

    # Wait for bed to heat up
    M117 Heating bed...
    M190 S{ bed_temp }

    # Adjust bed tilt
    # comment out the unneeded section
    # Z_TILT_ADJUST is ratOS
    # QUAD_GANTRY_LEVEL is generic klipper

    #M117 Adjusting for tilt...
    #Z_TILT_ADJUST
    M117 Performing QUAD_GANTRY_LEVEL...
    QUAD_GANTRY_LEVEL

    # Home again as Z will have changed after tilt adjustment and bed heating.
    M117 Rehoming after tilt adjustment...
    G28 Z

    BED_MESH_CALIBRATE

    EUCLID_PROBE_END_BATCH

    # Wait for extruder to heat up
    M109 S{ extruder_temp }

    M117 Printing...

    M83
    G92 E0


[gcode_macro BED_MESH_CALIBRATE]
rename_existing: BED_MESH_CALIBRATE_ORIG

variable_buffer: 20

gcode:
    {% set start_print  = printer["gcode_macro START_PRINT"] %}
    {% set bed_mesh     = printer.configfile.settings.bed_mesh %}
    {% set probe_config = printer.configfile.settings.probe %}

    {% if start_print.first_layer_min_xy and start_print.first_layer_max_xy %}
        { action_respond_info("print_min: {}".format(start_print.first_layer_min_xy)) }
        { action_respond_info("print_max: {}".format(start_print.first_layer_max_xy)) }

        {% set print_min_x = (start_print.first_layer_min_xy[0] | float) + probe_config.x_offset %}
        {% set print_min_y = (start_print.first_layer_min_xy[1] | float) + probe_config.y_offset %}
        {% set print_max_x = (start_print.first_layer_max_xy[0] | float) + probe_config.x_offset %}
        {% set print_max_y = (start_print.first_layer_max_xy[1] | float) + probe_config.y_offset %}

        DEPLOY_PROBE

        {% if (print_min_x < print_max_x) and (print_min_y < print_max_y) %}

            {% set minimum_probe_count = 5 if bed_mesh.algorithm == "bicubic" else 3 %}

            # bed_mesh.probe_count is a tuple
            {% set probe_count = bed_mesh.probe_count %}
            {% set probe_count_x = probe_count[0] %}
            {% set probe_count_y = probe_count[1] if (probe_count | length) == 2 else probe_count_x %}

            # -1 is the effective, undocumented default
            {% set relative_reference_index = bed_mesh.relative_reference_index | default(-1, true) %}
            {% set mesh_min_x, mesh_min_y = bed_mesh.mesh_min %}
            {% set mesh_max_x, mesh_max_y = bed_mesh.mesh_max %}

            # If print area X is smaller than 50% of the bed size, use the
            # minimum probe count for X instead of the default
            {% if (print_max_x - print_min_x) < (mesh_max_x - mesh_min_x)/2 %}
                {% set probe_count_x = minimum_probe_count %}
            {% endif %}

            # If print area Y is smaller than 50% of the bed size, use the
            # minimum probe count for Y instead of the default
            {% if (print_max_y - print_min_y) < (mesh_max_y - mesh_min_y)/2 %}
                {% set probe_count_y = minimum_probe_count %}
            {% endif %}

            {% if relative_reference_index > 0 %}
                {% set relative_reference_index = ((probe_count_x * probe_count_y - 1) / 2)|int %}
            {% endif %}

            {% set mesh_min_x = [print_min_x - buffer, mesh_min_x] | max %}
            {% set mesh_min_y = [print_min_y - buffer, mesh_min_y] | max %}
            {% set mesh_max_x = [print_max_x + buffer, mesh_max_x] | min %}
            {% set mesh_max_y = [print_max_y + buffer, mesh_max_y] | min %}

            { action_respond_info("mesh_min: ({}, {})".format(mesh_min_x, mesh_min_y)) }
            { action_respond_info("mesh_max: ({}, {})".format(mesh_max_x, mesh_max_y)) }
            { action_respond_info("probe_count: ({}, {})".format(probe_count_x,probe_count_y)) }
            { action_respond_info("relative_reference_index: {}".format(relative_reference_index)) }

            BED_MESH_CALIBRATE_ORIG mesh_min={mesh_min_x},{mesh_min_y} mesh_max={mesh_max_x},{mesh_max_y} probe_count={probe_count_x},{probe_count_y} relative_reference_index={relative_reference_index}

        {% else %}
            BED_MESH_CALIBRATE_ORIG
        {% endif %}

        STOW_PROBE

    {% else %}
        DEPLOY_PROBE

        BED_MESH_CALIBRATE_ORIG

        STOW_PROBE
    {% endif %}

# BOTH OF THE FOLLOWING MACROS ARE COMMENTED OUT ON PURPOSE. UNCOMMENT THE APPROPRIATE ONE
# FOR YOUR PRINTER AND SETUP. Z-TILT IS V-CORE/RATOS,  QGL IS VORON/KLIPPER

# Macro to perform a modified z_tilt by wrapping it in DEPLOY_PROBE/STOW_PROBE macros
# [gcode_macro Z_TILT_ADJUST]
# rename_existing: Z_TILT_ADJUST_ORIG
# gcode:
#    DEPLOY_PROBE
#    Z_TILT_ADJUST_ORIG
#    STOW_PROBE

# Macro to perform a QGL by wrapping it in DEPLOY_PROBE/STOW_PROBE macros
[gcode_macro QUAD_GANTRY_LEVEL]
rename_existing: QUAD_GANTRY_LEVEL_ORIGINIAL
#klipper
# you mane need to increase the horizontal_move_z: 15
gcode:

    DEPLOY_PROBE
    QUAD_GANTRY_LEVEL_ORIGINIAL
    STOW_PROBE


[gcode_macro PROBE_CALIBRATE]
rename_existing: PROBE_CALIBRATE_ORIG
gcode:
    {% set euclid_probe = printer["gcode_macro EuclidProbe"] %}  # this is the contents of line 144
    DEPLOY_PROBE
    G90
    G0 X{ printer.toolhead.axis_maximum.x/2 } Y{ printer.toolhead.axis_maximum.y/2 } F{ euclid_probe.move_speeds }
    PROBE_CALIBRATE_ORIG
    STOW_PROBE

`

@arikhris
Copy link

arikhris commented Jun 5, 2022

same errror as op

@nionio6915
Copy link
Owner

nionio6915 commented Jun 6, 2022

  1. please upload your printer.cfg and your klipper/moonraker versions
  2. how recently did you upgrade klipper. This seems to be a jinga2 syntax error and can be related to feature changes in klipper.

@nionio6915
Copy link
Owner

nionio6915 commented Jun 7, 2022

OK, we think we have a handle on this.

Lines 189-190 are comments to provide users instructions to add a move command to clear the dock height on moves. I beleive that klipper is parsing over the comment and trying to evaluate whats inside the brackets.

; fixed bed dock and moving gantry printers need to add a move command here to lower the gantry to dock height
; G0 Z{INSERT DOCK HEIGHT} F500

Could you to try the following-

  1. After line 55 add the following comment and a variable definition
# dock clearance height for docking and stow macros
variable_dock_height: 15
  1. Revise line 190 to
; G0 Z {euclid_probe.dock_height} F500
  1. Similarly revise line ~205 in the probe stow section.

I believe that this will elimintate the error. If you use the variable or move command does not matter, its providing klipper syntax that it likes despite being behind a comment strike.

I ask that you try it because my klipper machines are not gantries and let me know that this takes care of the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants