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

    Random number generation with Meta Commands?

    Scheduled Pinned Locked Moved
    Gcode meta commands
    4
    11
    589
    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.
    • Kolbiundefined
      Kolbi
      last edited by

      Hi all,

      I was trying to make a simple random number generator - single digit, -9 to 9 numeric swing and came up with this:

      echo floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))
      

      Is there a better way to do this?

      Cheers,
      Kolbi

      1 Reply Last reply Reply Quote 0
      • dc42undefined
        dc42 administrators
        last edited by

        What's the use case? We could add a random number function if it would be generally useful.

        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

        Kolbiundefined engikeneerundefined 2 Replies Last reply Reply Quote 1
        • Kolbiundefined
          Kolbi
          last edited by

          @dc42 As of now I'm using it to offset prime line and working on making it used to offset prints starting location on the build plate.

          1 Reply Last reply Reply Quote 0
          • Kolbiundefined
            Kolbi @dc42
            last edited by

            Sorry @dc42, use case posted here: https://forum.duet3d.com/topic/17872/automatic-bed-leveling-with-conditional-gcode-iterations/62

            Cheers,
            Kolbi

            1 Reply Last reply Reply Quote 0
            • Kolbiundefined
              Kolbi
              last edited by Kolbi

              Or to make a R2D2 impression...

              while iterations <= 4                            ; perform 5 passes
                 M300 S{3000+(200*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))} P{200+(10*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))}
                 M300 S{3000+(200*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))} P{100+(10*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))}
                 G4 P200
              
              1 Reply Last reply Reply Quote 0
              • engikeneerundefined
                engikeneer @dc42
                last edited by

                @dc42 jumping on this one, I would find it quite useful if I could slightly randomise my z home position. I use a piezo nozzle contact to home Z and I have a ziflex magnetic build surface. I find that over time my Z-offset is drifting because repeated probing of the same point is putting an indent in the surface and damaging it.
                I'm thinking if I could randomise the probing point within a given area (say a 10mm square) it would give me much less wear on the ziflex and shouldn't impact my z homing accuracy too much (by being in nearly the same place)

                E3D TC with D3Mini and Toolboards.
                Home-built CoreXY, Duet Wifi, Chimera direct drive, 2x BMG, 300x300x300 build volume
                i3 clone with a bunch of mods

                1 Reply Last reply Reply Quote 1
                • mrehorstdmdundefined
                  mrehorstdmd
                  last edited by

                  I would find it useful for randomly selecting pattern files to run on my sand table.

                  https://drmrehorst.blogspot.com/

                  1 Reply Last reply Reply Quote 1
                  • Kolbiundefined
                    Kolbi
                    last edited by

                    @dc42, here's the primeline macro - use case:

                    ; 0:/sys/primeline.g
                    ; Print prime-line at a 'randomized' Y positon from -1.1 to -2.9
                    
                    G1 X0 Z0.6 Y{-2+(0.1*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))} F3000.0;
                    G92 E0.0                                                   ; set E position to 0
                    G1 Z0.2 X100.0 E30.0 F1000.0                               ; prime line
                    G92 E0.0                                                   ; set E position to 0
                    M400                                                       ; finish all current moves / clear the buffer
                    

                    Cheers,
                    Kolbi

                    1 Reply Last reply Reply Quote 0
                    • dc42undefined
                      dc42 administrators
                      last edited by dc42

                      I've added a random(nnn) function to the expression evaluator, where n must be a positive integer. It returns a random integer in the range 0 to nnn-1. It will be in the 3.02beta releases.

                      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

                      Kolbiundefined 1 Reply Last reply Reply Quote 0
                      • Kolbiundefined
                        Kolbi @dc42
                        last edited by

                        @dc42 said in Random number generation with Meta Commands?:

                        It will be in the 3.02beta releases.

                        Nice! Is there a list of new expected features?

                        dc42undefined 1 Reply Last reply Reply Quote 0
                        • dc42undefined
                          dc42 administrators @Kolbi
                          last edited by

                          @Kolbi said in Random number generation with Meta Commands?:

                          @dc42 said in Random number generation with Meta Commands?:

                          It will be in the 3.02beta releases.

                          Nice! Is there a list of new expected features?

                          You can see what is already implemented or partly implemented at https://github.com/Duet3D/RepRapFirmware/blob/v3-dev/WHATS_NEW_RRF3.md.

                          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
                          • First post
                            Last post
                          Unless otherwise noted, all forum content is licensed under CC-BY-SA