Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Pressure advance tuning with conditional G-code

    Scheduled Pinned Locked Moved
    Gcode meta commands
    11
    43
    3.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Schmartundefined
      Schmart
      last edited by Schmart

      I've created a conditional G-code macro that prints a model to help tune pressure advance. It's based on the model used in this post, which I happen to like very much. It's a fast and native solution, starts from your printer directly and requires no slicer or other software.

      The macro is a work-in-progress, but offers a lot of configurability already. I will probably make a number of improvements as I use it myself, but I wanted to share this with you at this stage for feedback and educational purposes (i.e. my education).

      I can't guarantee that this code will work properly on your machine. I have a simple cartesian model with XYZE axes. Also, I've tested this on my printer with a self-compiled post-beta 5 firmware 3.4.0, since I ran into some rounding issues in the output of earlier RRF firmwares, though this has been fixed by @dc42 and I've seen mentioned that this fix is part of the beta 6 release.

      I've kept the variable names as descriptive as possible. However, let me know if you need explanation on how to use this:

      ; This macro generates a test print to determine the best pressure advance factor (M572 S-parameter)
      ; It uses the test print described in this forum post:
      ; https://forum.duet3d.com/topic/6698/pressure-advance-calibration
      
      ; Author: Schmart
      
      ; WARNING: all dimensions, size units and speeds are in mm and mm/s
      
      ; Reference for conditional G-code:
      ; - https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands
      
      ; Wishes for conditional G-code:
      ; - Canceling or stopping running conditional G-code
      ; - Simulation; logging what commands would be executed/generated without actually executing them
      ; - Dumping the variables (names and values) in a macro, perhaps also treating variable in a meta-way, e.g. {#var} for count, {var[0].name} and {var['layer_height'].value}
      ; - Assigning an object or array to a variable. E.g. var axis = move.axes[0]; echo {var.axis.letter}
      ; - Custom subroutine/function definition, e.g. def print_line(var a, var b)
      ; - ceiling(), pow() and sq() functions
      
      ; TODO:
      ; - Many optimizations still remaining
      ; - Perhaps the most important variables (bed and print temperature, filament diameter, extrusion multiplier, PA stepping)
      ;   can be made into macro parameters, e.g. M98 P"0:/macros/4 - Print Tuning/Pressure Advance" B40 P204 D1.75 X0.95 S0.02 P0.002
      
      ; Starting value for pressure advance
      var pa_start = 0.0
      ; Pressure advance increment for each (whole) millimeter print height
      ; e.g. if var.height = 20, var.pa_start = 0.1 and var.pa_stepping = 0.004, then
      ; the PA test range is from 0.1 to (0.1 + 20 * 0.004) => 0.1 to 0.18.
      var pa_stepping = 0.01
      ; The extruder to apply the pressure advance factor to
      var pa_extruder = 0
      ; These values specify the center of the print bed
      ; The default bed center is at (0,0)
      var x_center = 0
      var y_center = 0
      ; Print temperatures
      var print_temperature = 205
      var standby_temperature = 120
      var bed_temperature = 40
      ; Height of the test print
      var height = 20
      var layer_height = 0.20
      ; Number of fast segments
      var fast_segments = 3
      ; Slow segments are at the beginning and the end, and in between fast segments, e.g. SLOW FAST SLOW FAST SLOW
      var slow_segment_length = 10
      var fast_segment_length = 20
      ; Definition of speeds
      var first_layer_speed = 20
      var travel_speed = 80
      var fast_segment_speed = 60
      var slow_segment_speed = 10
      ; Number of perimeters around the object as a stable base
      var skirt_loops = 6
      ; Height of the skirt in layers
      var skirt_layers = 2
      ; The tool number to print with
      var tool_number = 0
      ; Extrusion width is calculated here, but can also be set with a literal value
      ; Note that 1.05 and 1.125 are common factors that result in 0.42mm or 0.45mm width respectively
      var nozzle_bore_diameter = 0.40
      var extrusion_width = {var.nozzle_bore_diameter * 1.125}
      var filament_diameter = 1.78
      var extrusion_multiplier = 0.93
      ; Firmware retraction settings
      var retract_length = 0.5
      var retract_restart_length = 0
      var retract_speed = 40
      var deretract_speed = 40
      var retract_z_lift = 0
      
      ; Flow math
      var filament_flow = {pi * var.filament_diameter * var.filament_diameter / 4}
      var regular_flow = {(var.extrusion_width - var.layer_height) * var.layer_height + pi * var.layer_height * var.layer_height / 4}
      var bridge_flow = {pi * var.nozzle_bore_diameter * var.nozzle_bore_diameter / 4}
      var line_spacing = {var.extrusion_width - var.layer_height * (1 - pi / 4)}
      var regular_flow_ratio = { var.extrusion_multiplier * var.regular_flow / var.filament_flow}
      var purge_line_flow_ratio = { 2.0 * var.regular_flow_ratio }
      
      echo "extrusion_width: " ^ var.extrusion_width
      echo "layer_height: " ^ var.layer_height
      echo "filament_flow: " ^ var.filament_flow
      echo "bridge_flow: " ^ var.bridge_flow
      echo "regular_flow: " ^ var.regular_flow
      echo "line_spacing: " ^ var.line_spacing
      echo "regular_flow_ratio: " ^ var.regular_flow_ratio
      
      ;M37 S1 ; Enter simulation mode
      
      ; Set firmware retraction
      M207 S{var.retract_length} R{var.retract_restart_length} F{60 * var.retract_speed} T{60 * var.deretract_speed} Z{var.retract_z_lift}
      
      T{var.tool_number} ; Select tool
      M106 S0 ; Turn off part cooling fan
      M568 P{var.tool_number} S{var.print_temperature} R{var.standby_temperature} A1 ; Set tool to standby temperature
      M190 S{var.bed_temperature} ; Wait for bed temperature to reach setpoint
      M116 P{var.tool_number} ; Wait for temperatures associated with the selected tool to be reached
      
      ; Make an inventory of axes that have not yet been homed
      var axes = ""
      echo "Total number of axes: " ^ {#move.axes}
      while {iterations < #move.axes}
        if {!move.axes[iterations].homed}
          set var.axes = {var.axes ^ move.axes[iterations].letter}
      
      ; Home applicable axes
      echo "Axes to be homed: " ^ var.axes
      G28 {var.axes}
      
      ;G28 XYZ ; Home the X, Y and Z axes
      ;G28 XY ; Home the X and Y axes
      ;G28 Z ; Home the Z axis
      
      G21 ; Set units to millimeters
      M83 ; Use relative distances for extrusion
      
      ; Calculate object width
      var width = {var.fast_segments * var.fast_segment_length + (1 + var.fast_segments) * var.slow_segment_length}
      ; Calculate starting coordinates and other constant(s)
      var x_start = {var.x_center - 0.5 * var.width + var.skirt_loops * var.line_spacing}
      var y_start = {var.y_center - 0.5 * var.line_spacing + var.skirt_loops * var.line_spacing}
      var travel_feedrate = {60 * var.travel_speed}
      var first_layer_feedrate = {60 * var.first_layer_speed}
      
      ; Absolute position for purge line in X and Y space, 50 mm behind model
      G90 ; Use absolute coordinates
      G1 X{var.x_start} Y{var.y_start + 50} F{var.travel_feedrate}
      
      ; Set heater to final temperature and wait
      M568 A2
      M116 P{var.tool_number}
      
      ; Absolute position of nozzle at first layer height
      G1 Z{var.layer_height} F{var.travel_feedrate}
      
      ; Relatively print two fat purge lines
      G91 ; Switch to relative coordinates
      G1 X{var.width} E{var.width * var.purge_line_flow_ratio} F{var.first_layer_feedrate}
      G1 Y{-(2 * var.line_spacing)} F{var.travel_feedrate}
      G1 X{-var.width} E{var.width * var.purge_line_flow_ratio} F{var.first_layer_feedrate}
      
      G10 ; Retract to prevent oozing
      
      ; Move to the start of the model in X, Y and Z space
      ; The skirt code also moves to the start, but the skirt can be disabled.
      ; Also, the skirt code does not set Z, and there may be no purge line for which Z is set. Safety first.
      G90 ; Use absolute coordinates
      G1 X{var.x_start} Y{var.y_start} Z{var.layer_height} F{var.travel_feedrate}
      G91 ; Switch to relative coordinates
      
      G11 ; Advance/unretract/deretract in preparation to print
      
      ; Routine for printing the test object
      var layers = {floor(var.height / var.layer_height)}
      echo "Total number of layers: " ^ var.layers
      
      while {iterations < var.layers}
        ; Track current layer
        var layer = {iterations + 1}
        ; Current height in mm
        var z = {var.layer * var.layer_height}
        ; Calculate pressure advance factor
        var pa = {var.pa_start + floor(var.z) * var.pa_stepping}
        ; Set pressure advance
        M572 D{var.pa_extruder} S{var.pa}
      
        ; Output some statistics while printing
        echo "Layer " ^ iterations ^ " (" ^ {iterations + 1} ^ " of " ^ {var.layers} ^ " at " ^ {var.z} ^ "mm)"
        echo "Pressure advance: " ^ {var.pa}
      
        ; Pre-calculate feedrates for first layer and other layers
        var slow_segment_feedrate = {60 * (var.layer == 1 ? var.first_layer_speed : var.slow_segment_speed)}
        var fast_segment_feedrate = {60 * (var.layer == 1 ? var.first_layer_speed : var.fast_segment_speed)}
      
        ; Print skirt
        if {iterations < var.skirt_layers}
          G90 ; Use absolute coordinates
          ; Move to absolute XY start coordinates
          G1 X{var.x_start} Y{var.y_start} F{var.travel_feedrate}
          G91 ; Switch to relative coordinates
      
          ; Print all loops of the skirt
          while {iterations < var.skirt_loops}
            var skirt_loop = {var.skirt_loops - iterations}
            var x = {var.width + 2 * var.skirt_loop * var.line_spacing}
            var y = {var.line_spacing + 2 * var.skirt_loop * var.line_spacing}
            ; Print one full skirt loop
            while iterations < 2
              var direction = {iterations == 0 ? 1 : -1}
              G1 X{var.direction * var.x} E{var.x * var.regular_flow_ratio} F{var.fast_segment_feedrate}
              G1 Y{var.direction * var.y} E{var.y * var.regular_flow_ratio} F{var.fast_segment_feedrate}
            ; Travel to the start of the next skirt loop
            G1 X{var.line_spacing} Y{var.line_spacing} F{var.travel_feedrate}
      
        ; Print two perimeters back and forth of alternating slow and fast segments
        while iterations < 2
          var direction = {iterations == 0 ? 1 : -1}
          ; Slow starting segment (X)
          G1 X{var.direction * var.slow_segment_length} E{var.slow_segment_length * var.regular_flow_ratio} F{var.slow_segment_feedrate}
          ; Remaining fast and slow segments (X)
          while iterations < var.fast_segments
            G1 X{var.direction * var.fast_segment_length} E{var.fast_segment_length * var.regular_flow_ratio} F{var.fast_segment_feedrate}
            G1 X{var.direction * var.slow_segment_length} E{var.slow_segment_length * var.regular_flow_ratio} F{var.slow_segment_feedrate}
          ; Print the side perimeter (Y)
          G1 Y{var.direction * var.line_spacing} E{var.line_spacing * var.regular_flow_ratio} F{var.slow_segment_feedrate}
      
        ; Move one layer up
        G1 Z{var.layer_height} F{var.travel_feedrate}
      
      G10 ; Retract
      
      G91 ; Relative positioning
      G1 F3000 Z20 ; Move gantry up 20mm
      G90 ; Absolute positioning
      G28 X ; Home X axis
      ;M104 S0 ; Turn off nozzle heat block
      M568 P{var.tool_number} S0 R0 A2 ; Set required heater temperature off
      M140 S0 ; Turn off bed
      M106 S0 ; Turn off part cooling fan
      M18 ; Disable stepper motors
      
      ;M37 S0 ; Leave simulation mode
      

      Photo of one print in progress and one done:

      IMG_9105.jpg

      Lastly, I'm so happy with the concept and speed, that I'm now toying with the idea to make macros for:

      • Tuning bridge parameters (with flow, temperature and part cooling as variables)
      • Layer adhesion (with temperature and part cooling are variable)
      • Tuning the extrusion multiplier

      EDIT: The code didn't look right when it contains words like "doesn't" and "haven't" in comments. This results in random "{0}" inserted and illegal G-code.

      Creality CR-20 Pro with a Duet 2 Maestro, 3Dfused X+Z-axis rail kit, HIWIN-based DIY solution for the Y-axis, E3D Hemera, working ST7565 MiniPanel and various other small hardware improvements.

      T3P3Tonyundefined CNCModellerundefined 2 Replies Last reply Reply Quote 3
      • T3P3Tonyundefined
        T3P3Tony administrators @Schmart
        last edited by

        This is really very cool. Its awesome to see the concept of gcode meta commands used in this way. I have logged the wishlist items.

        @schmart said in Pressure advance tuning with conditional G-code:

        The code didn't look right when it contains words like "doesn't" and "haven't" in comments. This results in random "{0}" inserted and illegal G-code.

        I can't reproduce this in the latest build. I took a very cutdown version of your original macro posted with the ; doesn't comment and a few more lines and running that did not throw any errors.

        o_lampeundefined Schmartundefined 2 Replies Last reply Reply Quote 1
        • o_lampeundefined
          o_lampe @T3P3Tony
          last edited by

          @t3p3tony Do you both talk about the code-window of the forum? Just have to add " ```perl" in the first line

          T3P3Tonyundefined 1 Reply Last reply Reply Quote 0
          • T3P3Tonyundefined
            T3P3Tony administrators @o_lampe
            last edited by

            @o_lampe I assumed @Schmart was referring to the gcode parsed by RRF (which should throw out all the comments, no matter what they contain)

            Schmartundefined 1 Reply Last reply Reply Quote 0
            • Schmartundefined
              Schmart @T3P3Tony
              last edited by Schmart

              @t3p3tony Apologies, I was indeed referring to the markdown representation of G-code in the forum. Fortunately, the firmware itself handles comments with single quotes without any issue. @o_lampe I wasn't aware of the 'perl' option, I will try this when I'm back home!

              Creality CR-20 Pro with a Duet 2 Maestro, 3Dfused X+Z-axis rail kit, HIWIN-based DIY solution for the Y-axis, E3D Hemera, working ST7565 MiniPanel and various other small hardware improvements.

              Schmartundefined 1 Reply Last reply Reply Quote 1
              • Schmartundefined
                Schmart @Schmart
                last edited by Schmart

                @o_lampe @T3P3Tony Tried the 'perl' code block in the markdown of my original post, and changed line 100 briefly to contain "haven't" instead of "have not". But the result doesn't look better then.

                Also in the fragments below the rendering issue can be reproduced; notice the "{1}" at line 11.

                ; Make an inventory of axes that haven't yet been homed
                 var axes = ""
                 echo "Total number of axes: " ^ {#move.axes}
                 while {iterations < #move.axes}
                   if {!move.axes[iterations].homed}
                     set var.axes = {var.axes ^ move.axes[iterations].letter}
                  
                 ; Home applicable axes
                 echo "Axes to be homed: " ^ var.axes
                 G28 {var.axes}
                

                Versus the exact same perl code block with "have not":

                ; Make an inventory of axes that have not yet been homed
                 var axes = ""
                 echo "Total number of axes: " ^ {#move.axes}
                 while {iterations < #move.axes}
                   if {!move.axes[iterations].homed}
                     set var.axes = {var.axes ^ move.axes[iterations].letter}
                  
                 ; Home applicable axes
                 echo "Axes to be homed: " ^ var.axes
                 G28 {var.axes}
                

                Creality CR-20 Pro with a Duet 2 Maestro, 3Dfused X+Z-axis rail kit, HIWIN-based DIY solution for the Y-axis, E3D Hemera, working ST7565 MiniPanel and various other small hardware improvements.

                1 Reply Last reply Reply Quote 0
                • Schmartundefined
                  Schmart @T3P3Tony
                  last edited by

                  @t3p3tony said in Pressure advance tuning with conditional G-code:

                  This is really very cool. Its awesome to see the concept of gcode meta commands used in this way. I have logged the wishlist items.

                  Thank you for that, by the way! 👍❤️

                  Creality CR-20 Pro with a Duet 2 Maestro, 3Dfused X+Z-axis rail kit, HIWIN-based DIY solution for the Y-axis, E3D Hemera, working ST7565 MiniPanel and various other small hardware improvements.

                  1 Reply Last reply Reply Quote 0
                  • T3P3Tonyundefined
                    T3P3Tony administrators
                    last edited by

                    This post is deleted!
                    T3P3Tonyundefined 1 Reply Last reply Reply Quote 0
                    • T3P3Tonyundefined
                      T3P3Tony administrators @T3P3Tony
                      last edited by

                      @t3p3tony

                      ok so with perl:

                      ; Make an inventory of axes that haven't yet been homed
                       var axes = ""
                       echo "Total number of axes: " ^ {#move.axes}
                       while {iterations < #move.axes}
                         if {!move.axes[iterations].homed}
                           set var.axes = {var.axes ^ move.axes[iterations].letter}
                        
                       ; Home applicable axes
                       echo "Axes to be homed: " ^ var.axes
                       G28 {var.axes}
                      

                      without perl

                      ; Make an inventory of axes that haven't yet been homed
                       var axes = ""
                       echo "Total number of axes: " ^ {#move.axes}
                       while {iterations < #move.axes}
                         if {!move.axes[iterations].homed}
                           set var.axes = {var.axes ^ move.axes[iterations].letter}
                        
                       ; Home applicable axes
                       echo "Axes to be homed: " ^ var.axes
                       G28 {var.axes}
                      
                      T3P3Tonyundefined 1 Reply Last reply Reply Quote 0
                      • T3P3Tonyundefined
                        T3P3Tony administrators @T3P3Tony
                        last edited by

                        so i can't recreate it with that snippet is if use no specified syntax highlighting.

                        Schmartundefined 1 Reply Last reply Reply Quote 0
                        • Schmartundefined
                          Schmart @T3P3Tony
                          last edited by Schmart

                          @t3p3tony Editing on my phone is terrible because I can't get out of preview mode anymore, but I've managed to put the entire code in a code block without specifying any language, and changed line 100 to use "haven't". Then on line 106, 110, 114 and 117, I'm spotting some issues.

                          ; This macro generates a test print to determine the best pressure advance factor (M572 S-parameter)
                          ; It uses the test print described in this forum post:
                          ; https://forum.duet3d.com/topic/6698/pressure-advance-calibration
                          
                          ; Author: Schmart
                          
                          ; WARNING: all dimensions, size units and speeds are in mm and mm/s
                          
                          ; Reference for conditional G-code:
                          ; - https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands
                          
                          ; Wishes for conditional G-code:
                          ; - Canceling or stopping running conditional G-code
                          ; - Simulation; logging what commands would be executed/generated without actually executing them
                          ; - Dumping the variables (names and values) in a macro, perhaps also treating variable in a meta-way, e.g. {#var} for count, {var[0].name} and {var['layer_height'].value}
                          ; - Assigning an object or array to a variable. E.g. var axis = move.axes[0]; echo {var.axis.letter}
                          ; - Custom subroutine/function definition, e.g. def print_line(var a, var b)
                          ; - ceiling(), pow() and sq() functions
                          
                          ; TODO:
                          ; - Many optimizations still remaining
                          ; - Perhaps the most important variables (bed and print temperature, filament diameter, extrusion multiplier, PA stepping)
                          ;   can be made into macro parameters, e.g. M98 P"0:/macros/4 - Print Tuning/Pressure Advance" B40 P204 D1.75 X0.95 S0.02 P0.002
                          
                          ; Starting value for pressure advance
                          var pa_start = 0.0
                          ; Pressure advance increment for each (whole) millimeter print height
                          ; e.g. if var.height = 20, var.pa_start = 0.1 and var.pa_stepping = 0.004, then
                          ; the PA test range is from 0.1 to (0.1 + 20 * 0.004) => 0.1 to 0.18.
                          var pa_stepping = 0.01
                          ; The extruder to apply the pressure advance factor to
                          var pa_extruder = 0
                          ; These values specify the center of the print bed
                          ; The default bed center is at (0,0)
                          var x_center = 0
                          var y_center = 0
                          ; Print temperatures
                          var print_temperature = 205
                          var standby_temperature = 120
                          var bed_temperature = 40
                          ; Height of the test print
                          var height = 20
                          var layer_height = 0.20
                          ; Number of fast segments
                          var fast_segments = 3
                          ; Slow segments are at the beginning and the end, and in between fast segments, e.g. SLOW FAST SLOW FAST SLOW
                          var slow_segment_length = 10
                          var fast_segment_length = 20
                          ; Definition of speeds
                          var first_layer_speed = 20
                          var travel_speed = 80
                          var fast_segment_speed = 60
                          var slow_segment_speed = 10
                          ; Number of perimeters around the object as a stable base
                          var skirt_loops = 6
                          ; Height of the skirt in layers
                          var skirt_layers = 2
                          ; The tool number to print with
                          var tool_number = 0
                          ; Extrusion width is calculated here, but can also be set with a literal value
                          ; Note that 1.05 and 1.125 are common factors that result in 0.42mm or 0.45mm width respectively
                          var nozzle_bore_diameter = 0.40
                          var extrusion_width = {var.nozzle_bore_diameter * 1.125}
                          var filament_diameter = 1.78
                          var extrusion_multiplier = 0.93
                          ; Firmware retraction settings
                          var retract_length = 0.5
                          var retract_restart_length = 0
                          var retract_speed = 40
                          var deretract_speed = 40
                          var retract_z_lift = 0
                          
                          ; Flow math
                          var filament_flow = {pi * var.filament_diameter * var.filament_diameter / 4}
                          var regular_flow = {(var.extrusion_width - var.layer_height) * var.layer_height + pi * var.layer_height * var.layer_height / 4}
                          var bridge_flow = {pi * var.nozzle_bore_diameter * var.nozzle_bore_diameter / 4}
                          var line_spacing = {var.extrusion_width - var.layer_height * (1 - pi / 4)}
                          var regular_flow_ratio = { var.extrusion_multiplier * var.regular_flow / var.filament_flow}
                          var purge_line_flow_ratio = { 2.0 * var.regular_flow_ratio }
                          
                          echo "extrusion_width: " ^ var.extrusion_width
                          echo "layer_height: " ^ var.layer_height
                          echo "filament_flow: " ^ var.filament_flow
                          echo "bridge_flow: " ^ var.bridge_flow
                          echo "regular_flow: " ^ var.regular_flow
                          echo "line_spacing: " ^ var.line_spacing
                          echo "regular_flow_ratio: " ^ var.regular_flow_ratio
                          
                          ;M37 S1 ; Enter simulation mode
                          
                          ; Set firmware retraction
                          M207 S{var.retract_length} R{var.retract_restart_length} F{60 * var.retract_speed} T{60 * var.deretract_speed} Z{var.retract_z_lift}
                          
                          T{var.tool_number} ; Select tool
                          M106 S0 ; Turn off part cooling fan
                          M568 P{var.tool_number} S{var.print_temperature} R{var.standby_temperature} A1 ; Set tool to standby temperature
                          M190 S{var.bed_temperature} ; Wait for bed temperature to reach setpoint
                          M116 P{var.tool_number} ; Wait for temperatures associated with the selected tool to be reached
                          
                          ; Make an inventory of axes that haven't yet been homed
                          var axes = ""
                          echo "Total number of axes: " ^ {#move.axes}
                          while {iterations < #move.axes}
                            if {!move.axes[iterations].homed}
                              set var.axes = {var.axes ^ move.axes[iterations].letter}
                          
                          ; Home applicable axes
                          echo "Axes to be homed: " ^ var.axes
                          G28 {var.axes}
                          
                          ;G28 XYZ ; Home the X, Y and Z axes
                          ;G28 XY ; Home the X and Y axes
                          ;G28 Z ; Home the Z axis
                          
                          G21 ; Set units to millimeters
                          M83 ; Use relative distances for extrusion
                          
                          ; Calculate object width
                          var width = {var.fast_segments * var.fast_segment_length + (1 + var.fast_segments) * var.slow_segment_length}
                          ; Calculate starting coordinates and other constant(s)
                          var x_start = {var.x_center - 0.5 * var.width + var.skirt_loops * var.line_spacing}
                          var y_start = {var.y_center - 0.5 * var.line_spacing + var.skirt_loops * var.line_spacing}
                          var travel_feedrate = {60 * var.travel_speed}
                          var first_layer_feedrate = {60 * var.first_layer_speed}
                          
                          ; Absolute position for purge line in X and Y space, 50 mm behind model
                          G90 ; Use absolute coordinates
                          G1 X{var.x_start} Y{var.y_start + 50} F{var.travel_feedrate}
                          
                          ; Set heater to final temperature and wait
                          M568 A2
                          M116 P{var.tool_number}
                          
                          ; Absolute position of nozzle at first layer height
                          G1 Z{var.layer_height} F{var.travel_feedrate}
                          
                          ; Relatively print two fat purge lines
                          G91 ; Switch to relative coordinates
                          G1 X{var.width} E{var.width * var.purge_line_flow_ratio} F{var.first_layer_feedrate}
                          G1 Y{-(2 * var.line_spacing)} F{var.travel_feedrate}
                          G1 X{-var.width} E{var.width * var.purge_line_flow_ratio} F{var.first_layer_feedrate}
                          
                          G10 ; Retract to prevent oozing
                          
                          ; Move to the start of the model in X, Y and Z space
                          ; The skirt code also moves to the start, but the skirt can be disabled.
                          ; Also, the skirt code does not set Z, and there may be no purge line for which Z is set. Safety first.
                          G90 ; Use absolute coordinates
                          G1 X{var.x_start} Y{var.y_start} Z{var.layer_height} F{var.travel_feedrate}
                          G91 ; Switch to relative coordinates
                          
                          G11 ; Advance/unretract/deretract in preparation to print
                          
                          ; Routine for printing the test object
                          var layers = {floor(var.height / var.layer_height)}
                          echo "Total number of layers: " ^ var.layers
                          
                          while {iterations < var.layers}
                            ; Track current layer
                            var layer = {iterations + 1}
                            ; Current height in mm
                            var z = {var.layer * var.layer_height}
                            ; Calculate pressure advance factor
                            var pa = {var.pa_start + floor(var.z) * var.pa_stepping}
                            ; Set pressure advance
                            M572 D{var.pa_extruder} S{var.pa}
                          
                            ; Output some statistics while printing
                            echo "Layer " ^ iterations ^ " (" ^ {iterations + 1} ^ " of " ^ {var.layers} ^ " at " ^ {var.z} ^ "mm)"
                            echo "Pressure advance: " ^ {var.pa}
                          
                            ; Pre-calculate feedrates for first layer and other layers
                            var slow_segment_feedrate = {60 * (var.layer == 1 ? var.first_layer_speed : var.slow_segment_speed)}
                            var fast_segment_feedrate = {60 * (var.layer == 1 ? var.first_layer_speed : var.fast_segment_speed)}
                          
                            ; Print skirt
                            if {iterations < var.skirt_layers}
                              G90 ; Use absolute coordinates
                              ; Move to absolute XY start coordinates
                              G1 X{var.x_start} Y{var.y_start} F{var.travel_feedrate}
                              G91 ; Switch to relative coordinates
                          
                              ; Print all loops of the skirt
                              while {iterations < var.skirt_loops}
                                var skirt_loop = {var.skirt_loops - iterations}
                                var x = {var.width + 2 * var.skirt_loop * var.line_spacing}
                                var y = {var.line_spacing + 2 * var.skirt_loop * var.line_spacing}
                                ; Print one full skirt loop
                                while iterations < 2
                                  var direction = {iterations == 0 ? 1 : -1}
                                  G1 X{var.direction * var.x} E{var.x * var.regular_flow_ratio} F{var.fast_segment_feedrate}
                                  G1 Y{var.direction * var.y} E{var.y * var.regular_flow_ratio} F{var.fast_segment_feedrate}
                                ; Travel to the start of the next skirt loop
                                G1 X{var.line_spacing} Y{var.line_spacing} F{var.travel_feedrate}
                          
                            ; Print two perimeters back and forth of alternating slow and fast segments
                            while iterations < 2
                              var direction = {iterations == 0 ? 1 : -1}
                              ; Slow starting segment (X)
                              G1 X{var.direction * var.slow_segment_length} E{var.slow_segment_length * var.regular_flow_ratio} F{var.slow_segment_feedrate}
                              ; Remaining fast and slow segments (X)
                              while iterations < var.fast_segments
                                G1 X{var.direction * var.fast_segment_length} E{var.fast_segment_length * var.regular_flow_ratio} F{var.fast_segment_feedrate}
                                G1 X{var.direction * var.slow_segment_length} E{var.slow_segment_length * var.regular_flow_ratio} F{var.slow_segment_feedrate}
                              ; Print the side perimeter (Y)
                              G1 Y{var.direction * var.line_spacing} E{var.line_spacing * var.regular_flow_ratio} F{var.slow_segment_feedrate}
                          
                            ; Move one layer up
                            G1 Z{var.layer_height} F{var.travel_feedrate}
                          
                          G10 ; Retract
                          
                          G91 ; Relative positioning
                          G1 F3000 Z20 ; Move gantry up 20mm
                          G90 ; Absolute positioning
                          G28 X ; Home X axis
                          ;M104 S0 ; Turn off nozzle heat block
                          M568 P{var.tool_number} S0 R0 A2 ; Set required heater temperature off
                          M140 S0 ; Turn off bed
                          M106 S0 ; Turn off part cooling fan
                          M18 ; Disable stepper motors
                          
                          ;M37 S0 ; Leave simulation mode
                          

                          Creality CR-20 Pro with a Duet 2 Maestro, 3Dfused X+Z-axis rail kit, HIWIN-based DIY solution for the Y-axis, E3D Hemera, working ST7565 MiniPanel and various other small hardware improvements.

                          T3P3Tonyundefined 1 Reply Last reply Reply Quote 0
                          • T3P3Tonyundefined
                            T3P3Tony administrators @Schmart
                            last edited by

                            @schmart ok thanks. its obviously dependent on both the syntax used and the other lines.

                            OwenDundefined 1 Reply Last reply Reply Quote 1
                            • OwenDundefined
                              OwenD @T3P3Tony
                              last edited by

                              @t3p3tony
                              Nice work! @Schmart

                              The forum highlighting problem is long standing
                              https://forum.duet3d.com/post/225020
                              .
                              Sometimes you need yo try a few different language formats to get one that works.
                              Try python, bash, Java, json, pascal etc

                              1 Reply Last reply Reply Quote 1
                              • Heartleander81undefined
                                Heartleander81
                                last edited by

                                Hi. I test this today but I become with the duet3 6c Board and tool board 1lc in sbc Modus a error.

                                20211103_113705.jpg

                                What can I Do?
                                I have test it with .g and .gcode and as Macro

                                With macro I become a another error Code

                                20211103_110658.jpg

                                Schmartundefined 1 Reply Last reply Reply Quote 0
                                • izemanundefined
                                  izeman
                                  last edited by

                                  I wanted to try the code as well, and it doesn't seem to work as expected. The nozzle and bed heat up, and then the heater is turned off again as it starts printing it seems.

                                  5c5c0105-c7e0-4b80-be98-baf15001a137-image.png

                                  Schmartundefined 2 Replies Last reply Reply Quote 0
                                  • Schmartundefined
                                    Schmart @Heartleander81
                                    last edited by Schmart

                                    @heartleander81 As far as I know, the conditional G-code works in a macro only, not in a .gcode file.

                                    The second problem I suspect is a copy error. Conditional G-code is indentation sensitive; with indented text (consistently using either spaces or tabs) you essentially define the sections that run conditionally or in a loop.

                                    In other errors I spot that the word line in purge_line_flow_ratio was somehow replaced with the line numbers 139 and 141 the variable is used on, so perhaps something's going wrong in the process of copying the text from the forum post into the macro editor.

                                    I've just copied the code from the first post again in my editor (VS Code) and performed a difference/diff/compare with the code in my actual printer to verify that the code in this post is sound. There's no differences that explain what I'm seeing on your end 😞

                                    Creality CR-20 Pro with a Duet 2 Maestro, 3Dfused X+Z-axis rail kit, HIWIN-based DIY solution for the Y-axis, E3D Hemera, working ST7565 MiniPanel and various other small hardware improvements.

                                    Heartleander81undefined 1 Reply Last reply Reply Quote 0
                                    • Schmartundefined
                                      Schmart @izeman
                                      last edited by

                                      @izeman I'm missing text like 'Axes to be homed' in the console, so I'm assuming you had to modify the code for the topology of your printer.

                                      Can you verify that the code still contains the T{var.tool_number} and M568 P{var.tool_number} S{var.print_temperature} R{var.standby_temperature} A1 statements? This selects the current tool, respectively sets the active and standby temperatures and requests to go to the standby temperature.

                                      If that's still in there, according to the documentation, the M568 A2 on line 131 should use the current tool (which should be selected with T{var.tool_number}) and therefore M568 should not require the P parameter, but you can try if changing the code M568 A2 (originally on line 131) to M568 P{var.tool_number} A2 helps mitigate the error.

                                      Creality CR-20 Pro with a Duet 2 Maestro, 3Dfused X+Z-axis rail kit, HIWIN-based DIY solution for the Y-axis, E3D Hemera, working ST7565 MiniPanel and various other small hardware improvements.

                                      izemanundefined 1 Reply Last reply Reply Quote 0
                                      • Heartleander81undefined
                                        Heartleander81 @Schmart
                                        last edited by Heartleander81

                                        @schmart hi.

                                        When I write a echo for purge_line_flow_ratio become I the error on line 88 not in line 139 and line 141.
                                        I have check it on vs code to and notepad ++ ther looks All good but doun't work

                                        PCRundefined 1 Reply Last reply Reply Quote 0
                                        • PCRundefined
                                          PCR @Heartleander81
                                          last edited by

                                          @chrishamm

                                          Via privat chat @Heartleander81 and I tried to solve his problem.

                                          He is using a D3 with SBC. I am using a D3M+ standalone. I sent him my macro and he tried to simulatet it. He got this error:

                                          GetFileInfo: Cannot convert Z parameter to float (value {var.layer_height})
                                          

                                          We both are running 3.4 B5. Could this be a DSF Problem?

                                          @oozeBot i know you have some printer running D3 with SBC. Can you try to simulate it?

                                          Best

                                          Heartleander81undefined chrishammundefined 2 Replies Last reply Reply Quote 0
                                          • Heartleander81undefined
                                            Heartleander81 @PCR
                                            last edited by

                                            I have copy second time the Code from first comment.

                                            I have the error with the line 139 and 141 but the test run now.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Unless otherwise noted, all forum content is licensed under CC-BY-SA