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

    Max number of parameters?

    Scheduled Pinned Locked Moved Solved
    Gcode meta commands
    rrf 3.5.0-b2 duet 3 mini 5+ standalone
    6
    17
    690
    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.
    • dc42undefined
      dc42 administrators @Exerqtor
      last edited by dc42

      @Exerqtor are you invoking the macro using M98, or in some other way?

      Are you running standalone or in SBC mode?

      Make sure you have a space between E or F and whatever precedes it, for example use D1 E2 not D1E2 (which would be interpreted as just a D parameter with value 1e2 i.e. 100).

      Duet WiFi hardware designer and firmware engineer
      Please do not ask me for Duet support via PM or email, use the forum
      http://www.escher3d.com, https://miscsolutions.wordpress.com

      Exerqtorundefined 1 Reply Last reply Reply Quote 0
      • Exerqtorundefined
        Exerqtor @dc42
        last edited by Exerqtor

        @dc42 said in Max number of parameters?:

        @Exerqtor are you invoking the macro using M98, or in some other way?

        By M98 yeah,

        Are you running standalone or in SBC mode?

        Standalone.

        Make sure you have a space between E or F and whatever precedes it, for example use D1 E2 not D1E2 (which would be interpreted as just a D parameter with value 1e2 i.e. 100).

        There are spaces allready so that shouldn't be the case, this is the two macro's in question:

        ; /sys/print/a_mesh.g  v2.1
        ; Called by print_probe.g before a print starts
        ; Used to probe a new bed mesh at the start of a print
        
        ; ====================---------------------------------------------------------
        ; Settings section
        ; ====================
        
        ; Minimum deviation from default mesh
        var minDev              = 20                                                   ; The minimum deviation between the default mesh points before an adaptive mesh is generated.
        
        ; Probing points for adaptive mesh
        var minMeshPoints       = 3                                                    ; The minimum amount of probing points for both X & Y.
        var maxMeshPoints       = 10                                                   ; The maximum amount of probing points for both X & Y
        
        ; Don't touch anyting beyond this point(unless you know what you're doing)!!
        ; ====================---------------------------------------------------------
        ; Prep phase
        ; ====================
        
        ; Grab default probing grid
        var m557MinX = move.compensation.probeGrid.mins[0]                             ; Grabs your default x min
        var m557MaxX = move.compensation.probeGrid.maxs[0]                             ; Grabs your default x max
        var m557MinY = move.compensation.probeGrid.mins[1]                             ; Grabs your default y min
        var m557MaxY = move.compensation.probeGrid.maxs[1]                             ; Grabs your default y max
        ; Grab the default mesh spacing
        var meshSpacing_X = {move.compensation.probeGrid.spacings[0]}                  ; Grabbing the X spacing of the current M557 settings
        var meshSpacing_Y = {move.compensation.probeGrid.spacings[1]}                  ; Grabbing the Y spacing of the current M557 settings
        
        ; ====================---------------------------------------------------------
        ; Setup print area
        ; ====================
        
        ; Define a variable to represent the min/max mesh coordinates
        var pamMinX = {global.paMinX}                                                  ; The min X position of the print job
        var pamMaxX = {global.paMaxX}                                                  ; The max X position of the print job
        var pamMinY = {global.paMinY}                                                  ; The min Y position of the print job
        var pamMaxY = {global.paMaxY}                                                  ; The max Y position of the print job
        
        ; ====================---------------------------------------------------------
        ; Check if adaptive mesh is needed
        ; ====================
        
        var enabled = "PLACEHOLDER"
        var msg = "PLACEHOLDER"
        
        if (var.m557MinX + var.minDev) >= var.pamMinX                                  ; Check if the difference between default min X and the print area min X is smaller than the set deviation
          set var.pamMinX = {var.m557MinX}                                             ; The difference is smaller than min deviation so set pamMinX to m557MinX
        
        if (var.m557MaxX - var.minDev) <= var.pamMaxX                                  ; Check if the difference between default max X and the print area max X is smaller than the set deviation
          set var.pamMaxX = {var.m557MaxX}                                             ; The difference is smaller than min deviation so set pamMaxX to m557MaxX
        
        if (var.m557MinY + var.minDev) >= var.pamMinY                                  ; Check if the difference between default min Y and the print area min Y is smaller than the set deviation
          set var.pamMinY = {var.m557MinY}                                             ; The difference is smaller than min deviation so set pamMinY to m557MinY
        
        if (var.m557MaxY - var.minDev) <= var.pamMaxY                                  ; Check if the difference between default max X and the print area max Y is smaller than the set deviation
          set var.pamMaxY = {var.m557MaxY}                                             ; The difference is smaller than min deviation so set pamMaxY to m557MaxY
        
        if var.m557MinX = var.pamMinX && var.m557MaxX = var.pamMaxX && var.m557MinY = var.pamMinY  && var.m557MaxY = var.pamMaxY
          set var.enabled = false
          set var.msg = "Print area bellow min deviation, using default mesh!"         ; Set the message
        else
          set var.enabled = true
          ; Get the number of probes for X taking minMeshPoints and maxMeshPoints into account
          var meshX = floor(min(var.maxMeshPoints - 1, (max(var.minMeshPoints - 1, (var.pamMaxX - var.pamMinX) / var.meshSpacing_X) + 1)))
          ; Get the number of probes for Y taking minMeshPoints and maxMeshPoints into account
          var meshY = floor(min(var.maxMeshPoints - 1, (max(var.minMeshPoints - 1, (var.pamMaxY - var.pamMinY) / var.meshSpacing_Y) + 1)))
          ; Set message about the Adaptive mesh that's been created
          set var.msg = "Adaptive mesh, X-min: " ^ var.pamMinX ^ "; X-max: " ^ var.pamMaxX ^ "; Y-min: " ^ var.pamMinY ^ "; Y-max: " ^ var.pamMaxY ^ "; Probes, X: " ^ var.meshX ^ "; Y: " ^ var.meshY
        
        ; Info message
        M291 P{var.msg} T6                                                             ; Display message about what's going to happen
        
        ; *--DEBUGGING--*
        echo {var.msg}
        
        ; If a adaptive grid is to be used
        if var.enabled
          ; ====================---------------------------------------------------------
          ; Transfere grid
          ; ====================
        
          ; Transfere print area probing grid to mesh.g
          M98 P"mesh.g" A{var.pamMinX} B{var.pamMaxX} C{var.pamMinY} D{var.pamMaxY} E{var.meshX} F{var.meshY}
        
        ; /sys/mesh.g  v2.2
        ; Called as response to G29 or a_mesh.g
        ; Used to probe a new bed mesh
        
        ;---/
        ; -/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--
        ; THIS MACRO ONLY WORKS WITH RRF 3.5.0b1 AND LATER!!
        ;--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--
        ;-/
        
        ; ====================
        ; Prep phase
        ; ====================
        
        if exists(param.A)
          ; Grab default probing grid
          var m557MinX = move.compensation.probeGrid.mins[0]                           ; Grabs your default x min
          var m557MaxX = move.compensation.probeGrid.maxs[0]                           ; Grabs your default x max
          var m557MinY = move.compensation.probeGrid.mins[1]                           ; Grabs your default y min
          var m557MaxY = move.compensation.probeGrid.maxs[1]                           ; Grabs your default y max
          ; Grab the default mesh spacing
          var m577meshX = {move.compensation.probeGrid.spacings[0]}                    ; Grabbing the X spacing of the current M557 settings
          var m577meshY = {move.compensation.probeGrid.spacings[1]}                    ; Grabbing the Y spacing of the current M557 settings
        
          ; Parse the print area probing grid
          var pamMinX = {param.A}                                                      ; min X position of the print area mesh
          var pamMaxX = {param.B}                                                      ; max X position of the print area mesh
          var pamMinY = {param.C}                                                      ; min Y position of the print area mesh
          var pamMaxY = {param.D}                                                      ; max Y position of the print area mesh
          
          ; Parse the print area mesh spacing
          var meshX = {param.E}                                                        ; Number of points to probe in the X axis
          var meshY = {param.F}                                                        ; Number of points to probe in the Y axis
            
          ; LED status
          if exists(global.sb_leds)
            set global.sb_leds = "meshing"                                             ; StealthBurner LED status
        
          ; *--DEBUGGING--*
          var msg = "PLACHOLDER"
          set var.msg = "Adaptive mesh, X-min: " ^ var.pamMinX ^ "; X-max: " ^ var.pamMaxX ^ "; Y-min: " ^ var.pamMinY ^ "; Y-max: " ^ var.pamMaxY ^ "; Probes, X: " ^ var.meshX ^ "; Y: " ^ var.meshY
          echo {var.msg}
        
          ; Set the probing mesh
          M557 X{var.pamMinX}:{var.pamMaxX} Y{var.pamMinY}:{var.pamMaxY} P{var.meshX}:{var.meshY}
        
          ; Move to the center of the print area
          G0 X{var.pamMinX + ((var.pamMaxX - var.pamMinX)/2) - sensors.probes[0].offsets[0]} Y{var.pamMinY + ((var.pamMaxY - var.pamMinY)/2) - sensors.probes[0].offsets[1]}
        
        else
          G28                                                                          ; Home all axis
        
          ; Level the bed
          set global.bed_trammed = false                                               ; Set trammed state to false to make it re-level before mesh probing
          if fileexists("/sys/lib/print/print_tram.g")
            M98 P"/sys/lib/print/print_tram.g"                                         ; Level the bed
          else
            echo "print_tram.g missing, aborting!"
            abort
        
          ; LED status
          if exists(global.sb_leds)
            set global.sb_leds = "meshing"                                             ; StealthBurner LED status
        
        ; Lower currents
        if fileexists("/sys/lib/current/xy_current_low.g")
          M98 P"/sys/lib/current/xy_current_low.g" C60                                 ; Set low XY currents
        else
          M913 X60 Y60                                                                 ; Set X Y motors to 60% of their max current
        if fileexists("/sys/lib/current/z_current_low.g")
          M98 P"/sys/lib/current/z_current_low.g"                                      ; Set low Z currents
        else
          M913 Z60                                                                     ; Set Z motors to 60% of their max current
        
        ; Get the reference Z offset
        G30 K0 S-3                                                                     ; Probe the bed and set the Z probe trigger height to the height it stopped at
        G91                                                                            ; Relative positioning
        G1 Z2 F1500                                                                    ; Lower bed 2mm relative to when the probe just triggered
        G90                                                                            ; Absolute positioning
        M400                                                                           ; Wait for moves to finish
        
        ; ====================
        ; Probing code
        ; ====================
        
        ; Probe a new bed mesh!
        M291 R"Mesh Probing" P"Probing now! Please wait..." T10                        ; Probing new mesh bed message
        
        if exists(param.A)
          ; Probe the new adaptive mesh
          G29 S0                                                                       ; Probe the bed, save height map to heightmap.csv and enable compensation
          G29 S3 P"adaptive_heightmap.csv"                                             ; Save the current height map to file "adaptive_heightmap.csv"
          G29 S1 P"adaptive_heightmap.csv"                                             ; Load height map file "adaptive_heightmap.csv" and enable mesh bed compensation
          M400                                                                         ; Wait for moves to finish
        else
          ; Probe the new default mesh
          G29 S0                                                                       ; Probe the bed, save height map to heightmap.csv and enable compensation
          G29 S3 P"default_heightmap.csv"                                              ; Save the current height map to file "default_heightmap.csv"
          G29 S1 P"default_heightmap.csv"                                              ; Load height map file "default_heightmap.csv" and enable mesh bed compensation
          M400                                                                         ; Wait for moves to finish
        
        ; ====================
        ; Finish up
        ; ====================
        
        if exists(param.A)
          ; Restore the default probing mesh
          M557 X{var.m557MinX}:{var.m557MaxX} Y{var.m557MinY}:{var.m557MaxY} P{var.m577meshX}:{var.m577meshY}
        
        ; Full currents
        if fileexists("/sys/lib/current/xy_current_high.g")
          M98 P"/sys/lib/current/xy_current_high.g"                                    ; Set high XY currents
        else
          M913 X100 Y100                                                               ; Set X Y motors to var.100% of their max current
        if fileexists("/sys/lib/current/z_current_high.g")
          M98 P"/sys/lib/current/z_current_high.g"                                     ; Set high Z currents
        else
          M913 Z100                                                                    ; Set Z motors to var.100% of their max current
        
        ; Uncomment the following lines to lower Z(bed) after probing
        G90                                                                            ; Absolute positioning
        G1 Z{global.Nozzle_CL} F2400                                                   ; Move to Z global.Nozzle_CL
        
        M291 R"Mesh Probing" P"Done" T4                                                ; Mesh probing done
        
        ; If using Voron TAP, report that probing is completed
        if exists(global.TAPPING)
          set global.TAPPING = false
          M402 P0                                                                      ; Return the hotend to the temperature it had before probing
        
        ; LED status
        if exists(global.sb_leds)
          set global.sb_leds = "ready"                                                 ; StealthBurner LED status
        

        This is how it looks in console if I run it:

        Adaptive mesh, X-min: 53.594; X-max: 128.131; Y-min: 65.0065; Y-max: 104.985; Probes, X: 3; Y: 3
        Adaptive mesh, X-min: 53.594; X-max: 128.131; Y-min: 65.0065; Y-max: 104.985; Probes, X: null; Y: nu
        Error: in file macro line 45: M557: Wrong number of values in array, expected 2
        
        dc42undefined 1 Reply Last reply Reply Quote 0
        • dc42undefined
          dc42 administrators @Exerqtor
          last edited by dc42

          @Exerqtor said in Max number of parameters?:

          M98 P"mesh.g" A{var.pamMinX} B{var.pamMaxX} C{var.pamMinY} D{var.pamMaxY} E{var.meshX} F{var.meshY}

          Does it work if you invoke it with constant parameters instead of variables?

          I checked the code and found a problem if you use lowercase parameter letters (which will be fixed in 3.5beta3), but found no other limits or bugs.

          Duet WiFi hardware designer and firmware engineer
          Please do not ask me for Duet support via PM or email, use the forum
          http://www.escher3d.com, https://miscsolutions.wordpress.com

          dc42undefined Exerqtorundefined 2 Replies Last reply Reply Quote 0
          • dc42undefined
            dc42 administrators @dc42
            last edited by

            PS:

            var pamMinX = {param.A} 
            

            You don't need the { } there, you can just use:

            var pamMinX = param.A
            

            The { } are needed when you use an expression as a parameter value in a regular GCode command.

            Duet WiFi hardware designer and firmware engineer
            Please do not ask me for Duet support via PM or email, use the forum
            http://www.escher3d.com, https://miscsolutions.wordpress.com

            1 Reply Last reply Reply Quote 1
            • Exerqtorundefined
              Exerqtor @dc42
              last edited by Exerqtor

              @dc42 said in Max number of parameters?:

              @Exerqtor said in Max number of parameters?:

              M98 P"mesh.g" A{var.pamMinX} B{var.pamMaxX} C{var.pamMinY} D{var.pamMaxY} E{var.meshX} F{var.meshY}

              Does it work if you invoke it with constant parameters instead of variables?

              I checked the code and found a problem if you use lowercase parameter letters (which will be fixed in 3.5beta3), but found no other limits or bugs.

              I'll give that a go in soon. But just for sanity's sake it SHOULD work the way i have it writen now too right?

              @dc42 said in Max number of parameters?:

              PS:

              var pamMinX = {param.A} 
              

              You don't need the { } there, you can just use:

              var pamMinX = param.A
              

              The { } are needed when you use an expression as a parameter value in a regular GCode command.

              Oh cool, i'll change that right away. Still not know all those "rules" one may say.


              Edit: Edit2:
              I just tried manually setting the E & F too 3 when i send M98 P"mesh.g" rather than using variables, same issue.

              I then tried manually setting var.meshX & var.meshY too 3 in mesh.g, same issue.

              Then I manually set M557 P3: while still trying to use variables to set X & Y, same issue.
              I still got:

              Error: in file macro line 45: M557: Wrong number of values in array, expected 2
              

              Ok, so the issue apparently ain't just in parameter E & F.... I manually input the coordinates to the M557 to see what happened(m557 X154.491:191.633 Y58.4547:85.9547 P3:3).
              And sure AF it went past that point now. BUT it threw another error farther down when it was supposed to restore the default mesh. Console readout bellow:

              6.4.2023, 13:14:46	9 points probed, min error -0.027, max error 0.046, mean 0.010, deviation 0.019
                                      Height map saved to file 0:/sys/heightmap.csv
                                      Height map saved to file 0:/sys/adaptive_heightmap.csv
                                      Error: in file macro line 114 column 22: M557: unknown variable 'm557MinX'
              6.4.2023, 13:14:21	Z probe trigger height set to -0.639 mm
              6.4.2023, 13:14:18	Adaptive mesh min-max: X:154.491-191.633; Y:58.4547-85.9547; Probe points, X:3; Y:3
                                      Adaptive mesh min-max: X:154.491-191.633; Y:58.4547-85.9547; Probe points, X:3; Y:3
                                      Inserting Adaptive M557
                                      Adaptive M557 insterted
              

              It's like RRF "forgets" the variables once they've been used once inside the same program.

              The current state of mesh.g for referance:

              ; /sys/mesh.g  v2.2
              ; Called as response to G29 or a_mesh.g
              ; Used to probe a new bed mesh
              
              ;---/
              ; -/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--
              ; THIS MACRO ONLY WORKS WITH RRF 3.5.0b1 AND LATER!!
              ;--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--
              ;-/
              
              ; ====================
              ; Prep phase
              ; ====================
              
              if exists(param.A)
                ; Grab default probing grid
                var m557MinX = move.compensation.probeGrid.mins[0]                           ; Grabs your default x min
                var m557MaxX = move.compensation.probeGrid.maxs[0]                           ; Grabs your default x max
                var m557MinY = move.compensation.probeGrid.mins[1]                           ; Grabs your default y min
                var m557MaxY = move.compensation.probeGrid.maxs[1]                           ; Grabs your default y max
                ; Grab the default mesh spacing
                var m577meshX = move.compensation.probeGrid.spacings[0]                      ; Grabbing the X spacing of the current M557 settings
                var m577meshY = move.compensation.probeGrid.spacings[1]                      ; Grabbing the Y spacing of the current M557 settings
              
                ; Parse the print area probing grid
                var pamMinX = param.A                                                        ; min X position of the print area mesh
                var pamMaxX = param.B                                                        ; max X position of the print area mesh
                var pamMinY = param.C                                                        ; min Y position of the print area mesh
                var pamMaxY = param.D                                                        ; max Y position of the print area mesh
                
                ; Parse the print area mesh spacing
                ;var meshX = param.E                                                          ; Number of points to probe in the X axis
                ;var meshY = param.F                                                          ; Number of points to probe in the Y axis
                var meshX = 3                                                          ; Number of points to probe in the X axis
                var meshY = 3                                                         ; Number of points to probe in the Y axis
                
                ; LED status
                if exists(global.sb_leds)
                  set global.sb_leds = "meshing"                                             ; StealthBurner LED status
              
                ; *--DEBUGGING--*
                var msg = "PLACHOLDER"
                ;set var.msg = "Adaptive mesh, X-min: " ^ var.pamMinX ^ "; X-max: " ^ var.pamMaxX ^ "; Y-min: " ^ var.pamMinY ^ "; Y-max: " ^ var.pamMaxY ^ "; Probes, X: " ^ var.meshX ^ "; Y: " ^ var.meshY
                set var.msg = "Adaptive mesh min-max: X:" ^ var.pamMinX ^ "-" ^ var.pamMaxX ^ "; Y:" ^ var.pamMinY ^ "-" ^ var.pamMaxY ^ "; Probe points, X:" ^ var.meshX ^ "; Y:" ^ var.meshY
                echo {var.msg}
              
                ; Set the probing mesh
                echo "Inserting Adaptive M557"
                ;M557 X{var.pamMinX}:{var.pamMaxX} Y{var.pamMinY}:{var.pamMaxY} P{var.meshX}:{var.meshY}
                M557 X154.491:191.633 Y58.4547:85.9547 P3:3
                echo "Adaptive M557 insterted"
              
                ; Move to the center of the print area
                G0 X{var.pamMinX + ((var.pamMaxX - var.pamMinX)/2) - sensors.probes[0].offsets[0]} Y{var.pamMinY + ((var.pamMaxY - var.pamMinY)/2) - sensors.probes[0].offsets[1]}
              
              else
                G28                                                                          ; Home all axis
              
                ; Level the bed
                set global.bed_trammed = false                                               ; Set trammed state to false to make it re-level before mesh probing
                if fileexists("/sys/lib/print/print_tram.g")
                  M98 P"/sys/lib/print/print_tram.g"                                         ; Level the bed
                else
                  echo "print_tram.g missing, aborting!"
                  abort
              
                ; LED status
                if exists(global.sb_leds)
                  set global.sb_leds = "meshing"                                             ; StealthBurner LED status
              
              ; Lower currents
              if fileexists("/sys/lib/current/xy_current_low.g")
                M98 P"/sys/lib/current/xy_current_low.g" C60                                 ; Set low XY currents
              else
                M913 X60 Y60                                                                 ; Set X Y motors to 60% of their max current
              if fileexists("/sys/lib/current/z_current_low.g")
                M98 P"/sys/lib/current/z_current_low.g"                                      ; Set low Z currents
              else
                M913 Z60                                                                     ; Set Z motors to 60% of their max current
              
              ; Get the reference Z offset
              G30 K0 S-3                                                                     ; Probe the bed and set the Z probe trigger height to the height it stopped at
              G91                                                                            ; Relative positioning
              G1 Z2 F1500                                                                    ; Lower bed 2mm relative to when the probe just triggered
              G90                                                                            ; Absolute positioning
              M400                                                                           ; Wait for moves to finish
              
              ; ====================
              ; Probing code
              ; ====================
              
              ; Probe a new bed mesh!
              M291 R"Mesh Probing" P"Probing now! Please wait..." T10                        ; Probing new mesh bed message
              
              if exists(param.A)
                ; Probe the new adaptive mesh
                G29 S0                                                                       ; Probe the bed, save height map to heightmap.csv and enable compensation
                G29 S3 P"adaptive_heightmap.csv"                                             ; Save the current height map to file "adaptive_heightmap.csv"
                G29 S1 P"adaptive_heightmap.csv"                                             ; Load height map file "adaptive_heightmap.csv" and enable mesh bed compensation
                M400                                                                         ; Wait for moves to finish
              else
                ; Probe the new default mesh
                G29 S0                                                                       ; Probe the bed, save height map to heightmap.csv and enable compensation
                G29 S3 P"default_heightmap.csv"                                              ; Save the current height map to file "default_heightmap.csv"
                G29 S1 P"default_heightmap.csv"                                              ; Load height map file "default_heightmap.csv" and enable mesh bed compensation
                M400                                                                         ; Wait for moves to finish
              
              ; ====================
              ; Finish up
              ; ====================
              
              if exists(param.A)
                ; Restore the default probing mesh
                M557 X{var.m557MinX}:{var.m557MaxX} Y{var.m557MinY}:{var.m557MaxY} P{var.m577meshX}:{var.m577meshY}
              
              ; Full currents
              if fileexists("/sys/lib/current/xy_current_high.g")
                M98 P"/sys/lib/current/xy_current_high.g"                                    ; Set high XY currents
              else
                M913 X100 Y100                                                               ; Set X Y motors to var.100% of their max current
              if fileexists("/sys/lib/current/z_current_high.g")
                M98 P"/sys/lib/current/z_current_high.g"                                     ; Set high Z currents
              else
                M913 Z100                                                                    ; Set Z motors to var.100% of their max current
              
              ; Uncomment the following lines to lower Z(bed) after probing
              G90                                                                            ; Absolute positioning
              G1 Z{global.Nozzle_CL} F2400                                                   ; Move to Z global.Nozzle_CL
              
              M291 R"Mesh Probing" P"Done" T4                                                ; Mesh probing done
              
              ; If using Voron TAP, report that probing is completed
              if exists(global.TAPPING)
                set global.TAPPING = false
                M402 P0                                                                      ; Return the hotend to the temperature it had before probing
              
              ; LED status
              if exists(global.sb_leds)
                set global.sb_leds = "ready"                                                 ; StealthBurner LED status
              
              infiniteloopundefined 1 Reply Last reply Reply Quote 0
              • infiniteloopundefined
                infiniteloop @Exerqtor
                last edited by

                @Exerqtor

                It's like RRF "forgets" the variables once they've been used once inside the same program.

                For reference, see here.

                Every call of a macro "resets" the local variables, in other words, their scope is limited to the macro they are declared in. To inspect the actual contents of a var at a certain place in your code, insert echo commands.

                Exerqtorundefined 1 Reply Last reply Reply Quote 0
                • Exerqtorundefined
                  Exerqtor @infiniteloop
                  last edited by Exerqtor

                  @infiniteloop

                  Yeah that I know, but i thought they should persist inside the macro they were created (intil it finish). For instance if you look at mesh.g. The variables I declare between line 17-35 at the start of the macro should still exisist at the end(or in this case in line 114 where i try to restore the default grid)?

                  Or will they be forgotten after tramming (line 56-69) or current adjustement's (line 71-79)?

                  I was onder the imopression they were to persist at least, if not that would certainly explain alot.


                  EDIT:

                  Well i just restructured the macro so that no "sub macros" get called after the variables get declared, and it still shits the bed in the exact same fashion.

                  The "new" mesh.g:

                  ; /sys/mesh.g  v2.2
                  ; Called as response to G29 or a_mesh.g
                  ; Used to probe a new bed mesh
                  
                  ;---/
                  ; -/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--
                  ; THIS MACRO ONLY WORKS WITH RRF 3.5.0b1 AND LATER!!
                  ;--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--
                  ;-/
                  
                  ; ====================
                  ; Prep phase
                  ; ====================
                  
                  if !exists(param.A)                                                            ; If this isn't part of a print job with adaptive mesh, tram the bed
                    G28                                                                          ; Home all axis
                  
                    ; Level the bed
                    set global.bed_trammed = false                                               ; Set trammed state to false to make it re-level before mesh probing
                    if fileexists("/sys/lib/print/print_tram.g")
                      M98 P"/sys/lib/print/print_tram.g"                                         ; Level the bed
                    else
                      echo "print_tram.g missing, aborting!"
                      abort
                  
                  ; LED status
                  if exists(global.sb_leds)
                  set global.sb_leds = "meshing"                                                 ; StealthBurner LED status
                  
                  ; Lower currents
                  if fileexists("/sys/lib/current/xy_current_low.g")
                    M98 P"/sys/lib/current/xy_current_low.g" C60                                 ; Set low XY currents
                  else
                    M913 X60 Y60                                                                 ; Set X Y motors to 60% of their max current
                  if fileexists("/sys/lib/current/z_current_low.g")
                    M98 P"/sys/lib/current/z_current_low.g"                                      ; Set low Z currents
                  else
                    M913 Z60                                                                     ; Set Z motors to 60% of their max current
                  
                  if exists(param.A)                                                             ; This is part of a print job with adaptive mesh, bed has allready been trammed
                    ; Grab default probing grid
                    var m557MinX = move.compensation.probeGrid.mins[0]                           ; Grabs your default x min
                    var m557MaxX = move.compensation.probeGrid.maxs[0]                           ; Grabs your default x max
                    var m557MinY = move.compensation.probeGrid.mins[1]                           ; Grabs your default y min
                    var m557MaxY = move.compensation.probeGrid.maxs[1]                           ; Grabs your default y max
                    ; Grab the default mesh spacing
                    var m577meshX = move.compensation.probeGrid.spacings[0]                      ; Grabbing the X spacing of the current M557 settings
                    var m577meshY = move.compensation.probeGrid.spacings[1]                      ; Grabbing the Y spacing of the current M557 settings
                  
                    ; Parse the print area probing grid
                    var pamMinX = param.A                                                        ; min X position of the print area mesh
                    var pamMaxX = param.B                                                        ; max X position of the print area mesh
                    var pamMinY = param.C                                                        ; min Y position of the print area mesh
                    var pamMaxY = param.D                                                        ; max Y position of the print area mesh
                    
                    ; Parse the print area mesh spacing
                    var meshX = param.E                                                          ; Number of points to probe in the X axis
                    var meshY = param.F                                                          ; Number of points to probe in the Y axis
                    ;var meshX = 3                                                                ; Number of points to probe in the X axis
                    ;var meshY = 3                                                                ; Number of points to probe in the Y axis
                    
                    ; LED status
                    if exists(global.sb_leds)
                      set global.sb_leds = "meshing"                                             ; StealthBurner LED status
                  
                    ; *--DEBUGGING--*
                    var msg = "PLACHOLDER"
                    set var.msg = "Adaptive mesh min-max: X:" ^ var.pamMinX ^ "-" ^ var.pamMaxX ^ "; Y:" ^ var.pamMinY ^ "-" ^ var.pamMaxY ^ "; Probe points, X:" ^ var.meshX ^ "; Y:" ^ var.meshY
                    echo {var.msg}
                  
                    ; Set the probing mesh
                    echo "Inserting Adaptive M557"
                    M557 X{var.pamMinX}:{var.pamMaxX} Y{var.pamMinY}:{var.pamMaxY} P{var.meshX}:{var.meshY}
                    ;M557 X154.491:191.633 Y58.4547:85.9547 P3:3
                    echo "Adaptive M557 insterted"
                  
                    ; Move to the center of the print area
                    G0 X{var.pamMinX + ((var.pamMaxX - var.pamMinX)/2) - sensors.probes[0].offsets[0]} Y{var.pamMinY + ((var.pamMaxY - var.pamMinY)/2) - sensors.probes[0].offsets[1]}
                  
                  ; Get the reference Z offset
                  G30 K0 S-3                                                                     ; Probe the bed and set the Z probe trigger height to the height it stopped at
                  G91                                                                            ; Relative positioning
                  G1 Z2 F1500                                                                    ; Lower bed 2mm relative to when the probe just triggered
                  G90                                                                            ; Absolute positioning
                  M400                                                                           ; Wait for moves to finish
                  
                  ; ====================
                  ; Probing code
                  ; ====================
                  
                  ; Probe a new bed mesh!
                  M291 R"Mesh Probing" P"Probing now! Please wait..." T10                        ; Probing new mesh bed message
                  
                  if exists(param.A)
                    ; Probe the new adaptive mesh
                    G29 S0                                                                       ; Probe the bed, save height map to heightmap.csv and enable compensation
                    G29 S3 P"adaptive_heightmap.csv"                                             ; Save the current height map to file "adaptive_heightmap.csv"
                    G29 S1 P"adaptive_heightmap.csv"                                             ; Load height map file "adaptive_heightmap.csv" and enable mesh bed compensation
                    M400                                                                         ; Wait for moves to finish
                  else
                    ; Probe the new default mesh
                    G29 S0                                                                       ; Probe the bed, save height map to heightmap.csv and enable compensation
                    G29 S3 P"default_heightmap.csv"                                              ; Save the current height map to file "default_heightmap.csv"
                    G29 S1 P"default_heightmap.csv"                                              ; Load height map file "default_heightmap.csv" and enable mesh bed compensation
                    M400                                                                         ; Wait for moves to finish
                  
                  ; ====================
                  ; Finish up
                  ; ====================
                  
                  if exists(param.A)
                    ; Restore the default probing mesh
                    M557 X{var.m557MinX}:{var.m557MaxX} Y{var.m557MinY}:{var.m557MaxY} P{var.m577meshX}:{var.m577meshY}
                  
                  ; Full currents
                  if fileexists("/sys/lib/current/xy_current_high.g")
                    M98 P"/sys/lib/current/xy_current_high.g"                                    ; Set high XY currents
                  else
                    M913 X100 Y100                                                               ; Set X Y motors to var.100% of their max current
                  if fileexists("/sys/lib/current/z_current_high.g")
                    M98 P"/sys/lib/current/z_current_high.g"                                     ; Set high Z currents
                  else
                    M913 Z100                                                                    ; Set Z motors to var.100% of their max current
                  
                  ; Uncomment the following lines to lower Z(bed) after probing
                  G90                                                                            ; Absolute positioning
                  G1 Z{global.Nozzle_CL} F2400                                                   ; Move to Z global.Nozzle_CL
                  
                  M291 R"Mesh Probing" P"Done" T4                                                ; Mesh probing done
                  
                  ; If using Voron TAP, report that probing is completed
                  if exists(global.TAPPING)
                    set global.TAPPING = false
                    M402 P0                                                                      ; Return the hotend to the temperature it had before probing
                  
                  ; LED status
                  if exists(global.sb_leds)
                    set global.sb_leds = "ready"                                                 ; StealthBurner LED status
                  
                  infiniteloopundefined gloomyandyundefined dc42undefined 3 Replies Last reply Reply Quote 0
                  • infiniteloopundefined
                    infiniteloop @Exerqtor
                    last edited by

                    @Exerqtor

                    The variables I declare between line 17-35 at the start of the macro should still exisist at the end(or in this case in line 114…

                    And, do they? Use echo to monitor their values.

                    1 Reply Last reply Reply Quote 0
                    • gloomyandyundefined
                      gloomyandy @Exerqtor
                      last edited by

                      @Exerqtor Hmm the variables you created are inside the body of an if statement. In most programming language variables like this would be considered to be local to that block and so would cease to exist at the end of the block. I'm not 100% if that is also the case with the language used here, but I would not be surprised. You might want to move them so that they are created outside the scope of the if statement (and give them a default value), then update that default value (if it makes sense in the body of the if).

                      Exerqtorundefined 1 Reply Last reply Reply Quote 2
                      • dc42undefined
                        dc42 administrators @Exerqtor
                        last edited by dc42

                        @Exerqtor said in Max number of parameters?:

                        The variables I declare between line 17-35 at the start of the macro should still exisist at the end(or in this case in line 114 where i try to restore the default grid)?

                        No! Lines 17-25 are within the if-block that starts at line 15. Any variables declared within this if-block cease to exist when the if-block ends at line 50. This is completely standard behaviour in block-structured languages.

                        Duet WiFi hardware designer and firmware engineer
                        Please do not ask me for Duet support via PM or email, use the forum
                        http://www.escher3d.com, https://miscsolutions.wordpress.com

                        1 Reply Last reply Reply Quote 1
                        • Exerqtorundefined
                          Exerqtor @gloomyandy
                          last edited by Exerqtor

                          @gloomyandy @dc42

                          Aha! Then it all makes sense, i had no idea that was how it worked (or that it's the standard in block structured languages). I've never worked with variables, conditional statements etc. before it got implemented in RRF so i'm learning as i go 😮‍💨.

                          But with that knowledge i'm sure I will figure it out 😅

                          So if i create the local variable within the main body of the macro, but assign it a new value within a if-block it will cary along outside the if block right?

                          Exerqtorundefined 1 Reply Last reply Reply Quote 0
                          • Exerqtorundefined
                            Exerqtor @Exerqtor
                            last edited by Exerqtor

                            That sure did the trick (for the most part), who would think playing by the rules would help 🤣

                            I've got all but one "function" of the script to work at this point: restoring the default mesh (line 117).

                            mesh.g

                            ; /sys/mesh.g  v2.5
                            ; Called as response to G29 or a_mesh.g
                            ; Used to probe a new bed mesh
                            
                            ;---/
                            ; -/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--
                            ; THIS MACRO ONLY WORKS WITH RRF 3.5.0b1 AND LATER!!
                            ;--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--/--
                            ;-/
                            
                            ; ====================
                            ; Prep phase
                            ; ====================
                            
                            if !exists(param.A)                                                            ; If this isn't part of a print job with adaptive mesh, tram the bed
                              G28                                                                          ; Home all axis
                            
                              ; Level the bed
                              set global.bed_trammed = false                                               ; Set trammed state to false to make it re-level before mesh probing
                              if fileexists("/sys/lib/print/print_tram.g")
                                M98 P"/sys/lib/print/print_tram.g"                                         ; Level the bed
                              else
                                echo "print_tram.g missing, aborting!"
                                abort
                            
                            ; LED status
                            if exists(global.sb_leds)
                              set global.sb_leds = "meshing"                                               ; StealthBurner LED status
                            
                            ; Lower currents
                            if fileexists("/sys/lib/current/xy_current_low.g")
                              M98 P"/sys/lib/current/xy_current_low.g" C60                                 ; Set low XY currents
                            else
                              M913 X60 Y60                                                                 ; Set X Y motors to 60% of their max current
                            if fileexists("/sys/lib/current/z_current_low.g")
                              M98 P"/sys/lib/current/z_current_low.g"                                      ; Set low Z currents
                            else
                              M913 Z60                                                                     ; Set Z motors to 60% of their max current
                            
                            ; Grab default probing grid
                            var m557MinX = move.compensation.probeGrid.mins[0]                             ; Grabs your default x min
                            var m557MaxX = move.compensation.probeGrid.maxs[0]                             ; Grabs your default x max
                            var m557MinY = move.compensation.probeGrid.mins[1]                             ; Grabs your default y min
                            var m557MaxY = move.compensation.probeGrid.maxs[1]                             ; Grabs your default y max
                            ; Grab the default mesh spacing
                            var m577meshX = move.compensation.probeGrid.spacings[0]                        ; Grabbing the X spacing of the current M557 settings
                            var m577meshY = move.compensation.probeGrid.spacings[1]                        ; Grabbing the Y spacing of the current M557 settings
                            
                            ; Variable placeholders
                            var pamMinX = "PLACEHOLDER"                                                    ; min X position of the print area mesh
                            var pamMaxX = "PLACEHOLDER"                                                    ; max X position of the print area mesh
                            var pamMinY = "PLACEHOLDER"                                                    ; min Y position of the print area mesh
                            var pamMaxY = "PLACEHOLDER"                                                    ; max Y position of the print area mesh
                            var meshX = "PLACEHOLDER"                                                      ; Number of points to probe in the X axis
                            var meshY = "PLACEHOLDER"                                                      ; Number of points to probe in the Y axis
                            
                            if exists(param.A)                                                             ; This is part of a print job with adaptive mesh, bed has allready been trammed
                              ; Parse the print area probing grid
                              set var.pamMinX = param.A                                                    ; min X position of the print area mesh
                              set var.pamMaxX = param.B                                                    ; max X position of the print area mesh
                              set var.pamMinY = param.C                                                    ; min Y position of the print area mesh
                              set var.pamMaxY = param.D                                                    ; max Y position of the print area mesh  
                              ; Parse the print area mesh spacing
                              set var.meshX = param.E                                                      ; Number of points to probe in the X axis
                              set var.meshY = param.F                                                      ; Number of points to probe in the Y axis
                                
                              ; *--DEBUGGING--*
                              var msg = "PLACHOLDER"
                              set var.msg = "Adaptive mesh min:max: X:" ^ var.pamMinX ^ ":" ^ var.pamMaxX ^ "; Y:" ^ var.pamMinY ^ ":" ^ var.pamMaxY ^ "; Probe points, X:" ^ var.meshX ^ " Y:" ^ var.meshY
                              echo {var.msg}
                            
                              ; Set the probing mesh
                              echo "Inserting Adaptive M557"
                              M557 X{var.pamMinX, var.pamMaxX} Y{var.pamMinY, var.pamMaxY} P{var.meshX, var.meshY}
                              echo "Adaptive M557 insterted"
                            
                              ; Move to the center of the print area
                              G0 X{var.pamMinX + ((var.pamMaxX - var.pamMinX)/2) - sensors.probes[0].offsets[0]} Y{var.pamMinY + ((var.pamMaxY - var.pamMinY)/2) - sensors.probes[0].offsets[1]}
                            
                            ; Get the reference Z offset
                            G30 K0 S-3                                                                     ; Probe the bed and set the Z probe trigger height to the height it stopped at
                            G91                                                                            ; Relative positioning
                            G1 Z2 F1500                                                                    ; Lower bed 2mm relative to when the probe just triggered
                            G90                                                                            ; Absolute positioning
                            M400                                                                           ; Wait for moves to finish
                            
                            ; ====================
                            ; Probing code
                            ; ====================
                            
                            ; Probe a new bed mesh!
                            M291 R"Mesh Probing" P"Probing now! Please wait..." T10                        ; Probing new mesh bed message
                            
                            if exists(param.A)
                              ; Probe the new adaptive mesh
                              G29 S0                                                                       ; Probe the bed, save height map to heightmap.csv and enable compensation
                              G29 S3 P"adaptive_heightmap.csv"                                             ; Save the current height map to file "adaptive_heightmap.csv"
                              G29 S1 P"adaptive_heightmap.csv"                                             ; Load height map file "adaptive_heightmap.csv" and enable mesh bed compensation
                              M400                                                                         ; Wait for moves to finish
                            else
                              ; Probe the new default mesh
                              G29 S0                                                                       ; Probe the bed, save height map to heightmap.csv and enable compensation
                              G29 S3 P"default_heightmap.csv"                                              ; Save the current height map to file "default_heightmap.csv"
                              G29 S1 P"default_heightmap.csv"                                              ; Load height map file "default_heightmap.csv" and enable mesh bed compensation
                              M400                                                                         ; Wait for moves to finish
                            
                            ; ====================
                            ; Finish up
                            ; ====================
                            
                            ; *--DEBUGGING--*
                            var msg1 = "PLACHOLDER"
                            set var.msg1 = "Default mesh min:max: X:" ^ var.m557MinX ^ ":" ^ var.m557MaxX ^ "; Y:" ^ var.m557MinY ^ ":" ^ var.m557MaxY ^ "; Probe points, X:" ^ var.m577meshX ^ " Y:" ^ var.m577meshY
                            echo {var.msg1}
                            
                            ;Restore the default probing mesh
                            M557 X{var.m557MinX, var.m557MaxX} Y{var.m557MinY, var.m557MaxY} P{var.m577meshX, var.m577meshY}
                            
                            ; Full currents
                            if fileexists("/sys/lib/current/xy_current_high.g")
                              M98 P"/sys/lib/current/xy_current_high.g"                                    ; Set high XY currents
                            else
                              M913 X100 Y100                                                               ; Set X Y motors to var.100% of their max current
                            if fileexists("/sys/lib/current/z_current_high.g")
                              M98 P"/sys/lib/current/z_current_high.g"                                     ; Set high Z currents
                            else
                              M913 Z100                                                                    ; Set Z motors to var.100% of their max current
                            
                            ; Uncomment the following lines to lower Z(bed) after probing
                            G90                                                                            ; Absolute positioning
                            G1 Z{global.Nozzle_CL} F2400                                                   ; Move to Z global.Nozzle_CL
                            
                            M291 R"Mesh Probing" P"Done" T4                                                ; Mesh probing done
                            
                            ; If using Voron TAP, report that probing is completed
                            if exists(global.TAPPING)
                              set global.TAPPING = false
                              M402 P0                                                                      ; Return the hotend to the temperature it had before probing
                            
                            ; LED status
                            if exists(global.sb_leds)
                              set global.sb_leds = "ready"                                                 ; StealthBurner LED status
                            

                            This is what console outputs, and given the echo i can't for the life of me understand what might be causing it to act up:

                            7.4.2023, 11:30:17	9 points probed, min error -0.014, max error 0.066, mean 0.016, deviation 0.026
                                                    Height map saved to file 0:/sys/heightmap.csv
                                                    Height map saved to file 0:/sys/adaptive_heightmap.csv
                                                    Default mesh min:max: X:10.0:340.0; Y:10.0:340.0; Probe points, X:30.0 Y:30.0
                                                    Error: in file macro line 117 column 81: M557: expected non-negative integer value
                            7.4.2023, 11:29:57	Z probe trigger height set to -0.629 mm
                            7.4.2023, 11:29:53	Adaptive mesh min:max: X:248.186:287.586; Y:141.312:209.3; Probe points, X:3 Y:3
                                                    Inserting Adaptive M557
                                                    Adaptive M557 insterted
                            
                            T3P3Tonyundefined 1 Reply Last reply Reply Quote 1
                            • T3P3Tonyundefined
                              T3P3Tony administrators @Exerqtor
                              last edited by

                              @Exerqtor said in Max number of parameters?:

                              Error: in file macro line 117 column 81: M557: expected non-negative integer value

                              ;Restore the default probing mesh
                              M557 X{var.m557MinX, var.m557MaxX} Y{var.m557MinY, var.m557MaxY} P{var.m577meshX, var.m577meshY}
                              

                              so translating from the values you echoed you are sending:

                              M557 X{10.0,340.0} Y{10.0,340.0} P{30.0,30.0}
                              

                              Which is invalid because you cannot have non integer number of probe points (its also invalid because you can't have 900 probe points 30x30 = 900)

                              the P values need to be integers not floats. so you can use the "floor" command to round down those floats to integers:

                              M557 X{10.0,340.0} Y{10.0,340.0} P{floor(10.0),floor(10.0)}
                              

                              so

                              ;Restore the default probing mesh
                              M557 X{var.m557MinX, var.m557MaxX} Y{var.m557MinY, var.m557MaxY} P{floor(var.m577meshX), floor(var.m577meshY)}
                              

                              you still need to change your logic so you cannot exceed the maximum number of points. one option would be to use the "spacing" rather the number of points option, alternatively add a check and set to a maximum if the earlier calculations come up with too many points.

                              www.duet3d.com

                              Exerqtorundefined 1 Reply Last reply Reply Quote 1
                              • Exerqtorundefined
                                Exerqtor @T3P3Tony
                                last edited by Exerqtor

                                @T3P3Tony

                                Aaah that's what I've been doing wrong the whole time! When i originally started writing this i wanted it to fetch the NUMBER of probe points not the spacing between them.

                                This sould do the trick shouldn't it?:

                                ; Grab default probing grid
                                var m557MinX = move.compensation.probeGrid.mins[0]                             ; Grabs your default x min
                                var m557MaxX = move.compensation.probeGrid.maxs[0]                             ; Grabs your default x max
                                var m557MinY = move.compensation.probeGrid.mins[1]                             ; Grabs your default y min
                                var m557MaxY = move.compensation.probeGrid.maxs[1]                             ; Grabs your default y max
                                ; Calculate the default numbber of probe points
                                var m577meshX = floor((var.m557MaxX - var.m557MinX / move.compensation.probeGrid.spacings[0]) + 1)))
                                var m577meshY = floor((var.m557MaxY - var.m557MinY / move.compensation.probeGrid.spacings[1]) + 1)))
                                

                                Maybe I'm asking for too much, but wouldn't a node for number of probe points pr. axis be handy?

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

                                  @Exerqtor that looks about right - although you need to test to make sure.

                                  you can just use the spacing setting, rather than the number of points, in you M557 command, since those values come from the spacings reported in the OM.

                                  www.duet3d.com

                                  1 Reply Last reply Reply Quote 0
                                  • Exerqtorundefined Exerqtor has marked this topic as solved
                                  • First post
                                    Last post
                                  Unless otherwise noted, all forum content is licensed under CC-BY-SA