• Tags
  • Documentation
  • Order
  • Register
  • Login
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
623
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.
  • undefined
    infiniteloop @Exerqtor
    last edited by 6 Apr 2023, 11:56

    @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.

    undefined 1 Reply Last reply 6 Apr 2023, 12:35 Reply Quote 0
    • undefined
      Exerqtor @infiniteloop
      last edited by Exerqtor 4 Jun 2023, 13:20 6 Apr 2023, 12:35

      @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
      undefined undefined undefined 3 Replies Last reply 6 Apr 2023, 16:57 Reply Quote 0
      • undefined
        infiniteloop @Exerqtor
        last edited by 6 Apr 2023, 16:57

        @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
        • undefined
          gloomyandy @Exerqtor
          last edited by 6 Apr 2023, 17:17

          @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).

          undefined 1 Reply Last reply 6 Apr 2023, 20:45 Reply Quote 2
          • undefined
            dc42 administrators @Exerqtor
            last edited by dc42 4 Jun 2023, 19:24 6 Apr 2023, 19:23

            @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
            • undefined
              Exerqtor @gloomyandy
              last edited by Exerqtor 4 Jun 2023, 21:06 6 Apr 2023, 20:45

              @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?

              undefined 1 Reply Last reply 7 Apr 2023, 09:47 Reply Quote 0
              • undefined
                Exerqtor @Exerqtor
                last edited by Exerqtor 4 Jul 2023, 09:48 7 Apr 2023, 09:47

                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
                undefined 1 Reply Last reply 7 Apr 2023, 11:51 Reply Quote 1
                • undefined
                  T3P3Tony administrators @Exerqtor
                  last edited by 7 Apr 2023, 11:51

                  @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

                  undefined 1 Reply Last reply 7 Apr 2023, 12:40 Reply Quote 1
                  • undefined
                    Exerqtor @T3P3Tony
                    last edited by Exerqtor 4 Jul 2023, 13:38 7 Apr 2023, 12:40

                    @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?

                    undefined 1 Reply Last reply 7 Apr 2023, 13:20 Reply Quote 0
                    • undefined
                      T3P3Tony administrators @Exerqtor
                      last edited by 7 Apr 2023, 13:20

                      @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
                      • undefined Exerqtor has marked this topic as solved 7 Apr 2023, 14:58
                      17 out of 17
                      • First post
                        17/17
                        Last post
                      Unless otherwise noted, all forum content is licensed under CC-BY-SA