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

    How to auto execute gcode under specific circumstances?

    Scheduled Pinned Locked Moved
    Gcode meta commands
    4
    8
    484
    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.
    • Psylenceoundefined
      Psylenceo
      last edited by

      Specifically, I'd like to perform a G29 or G32 at startup every time and also every # number of prints. While I have figured out how to do an auto-execute on power-up (reset, etc), I still have not been able to figure out how to execute a macro basically every x number of prints.

      The reason for this question is that at first, I thought I'd just do a G29 or G32 and be all set. But, then I realized that after each print I usually removed the glass build surface. Which got me thinking that I then needed to do the G32 or G29 for every print and thusly added it to my simplify 3D script.

      Well, now I have a wham-bam build surface so I should have to worry about my mesh changing much. But, I'd still like to make sure I have a good mesh at power-up and a validation run every nth print.

      Does anyone know how to do that or have any suggestions?

      Oh yeah, I understand the concern as well for having the machine do motions automatically hence I plan on placing an M291 S3 command at the start of both scripts to reduce the risk of issues. Which brings me to an issue while testing my auto gcode when my:

      M291 S3 R" Reset detected" P" Press ok to begin power-up routine, cancel if this was just a reset."

      When the above g-code is executed I do get a pop-up, however, there is no text and only the OK button when using the DWC.

      1 Reply Last reply Reply Quote 0
      • Danalundefined
        Danal
        last edited by

        There is no directly supported way to persist things across power cycles.

        Wild Idea 1: The closest thing today might be to use the object model to set something that you are never going to use, picking something that gets written by M500. A careful set of M500s, M501s, and object model fields that are 'harmless' to your normal operation MIGHT be able to persist a counter across power cycles.

        Wild Idea 2: Same thing, but with the names of files. Create a file named /sys/power00001.g Use conditional g-code near the end of config.g (really, probably M98 a macro from config.g) to look for that file, parse the number out of the name, change it to power00002.g, and either rename or create/delete (I do the second, more robust). Over time, you have a power cycle count.

        1 Reply Last reply Reply Quote 0
        • Psylenceoundefined
          Psylenceo
          last edited by

          Persist over power cycle isn't was I was going for sync any time I do a power cycle, an M999 command, E-stop/reset DWC button, etc I have config.g pull up a macro to do the bed leveling etc after I acknowledge it's safe to do.

          The persistent counter I want to do stems from this covid-19 ordeal where my printer is on 24/7 and once a print is done I pop it off then tell DWC to reprint. I want the software to count how many times I start a print. Then between print N and print N+1 I want to perform a bed level check then start print N+1 and reset the counter.

          This way if the controller resets or power is removed the printer will do a bed level check anyways. Hopefully, that makes more sense now.

          Danalundefined 1 Reply Last reply Reply Quote 0
          • OwenDundefined
            OwenD
            last edited by

            I don't think there's any inbuilt print counter as this information would be stored on EEPROM in order to be persistent across reboots.
            About the only thing I could think of is maybe run a macro that created some files on the SD card and checked for them etc.
            It doesn't work, because M36 returns a Json array, which I can't parse to get the error state.

            ; Unsuccessful counter kludge
            ;NOTE THIS DOESN'T WORK !!!!
            
            
            ; see if all three files are present
            M36 "0:/gcodes/003.g"
            if result != 0 ; This is where it fails because it doesn't return an error except as a json "{err:1}"
            	; if all there do bed leveling then delete them
            	;G32
            	;G29 
            	echo "has been run three times - do leveling"
            	M30 "0:/gcodes/001.g"
            	M30 "0:/gcodes.002.g"
            	M30 "0:/gcodes.003.g"
            else
            	M36 "0:/gcodes/002.g"
            		if result != 0
            			M28 "0:/gcodes/003.g" ; create file
            			echo "creating third file"
            			M29 ; close file
            		else
            			M36 "0:/gcodes/001.g"
            			if result != 0
            				M28 "0:/gcodes/002.g" ; create file
            				echo "creating second file"
            				M29 ; close file
            			else
            				M28 "0:/gcodes/001.g" ; create file
            				echo "creating first file"
            				M29 ; close file
            
            1 Reply Last reply Reply Quote 0
            • dc42undefined
              dc42 administrators
              last edited by

              What you really need is variables in conditional GCode so that you can use one as a print counter; but they won't be available until firmware 3.02. However, you can simulate them. Create a dummy tool using M563. Then you can use its XYZ tool offsets as variables. Set them using G10 and query them using the object model. Make sure that you don't accidentally select the dummy tool, for example by including an M112 command (emergency stop) in its tpre file.

              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 2
              • Danalundefined
                Danal @Psylenceo
                last edited by Danal

                @Psylenceo said in How to auto execute gcode under specific circumstances?:

                Persist over power cycle isn't was I was going for sync any time I do a power cycle, an M999 command, E-stop/reset DWC button, etc I have config.g pull up a macro to do the bed leveling etc after I acknowledge it's safe to do.

                The persistent counter I want to do stems from this covid-19 ordeal where my printer is on 24/7 and once a print is done I pop it off then tell DWC to reprint. I want the software to count how many times I start a print. Then between print N and print N+1 I want to perform a bed level check then start print N+1 and reset the counter.

                This way if the controller resets or power is removed the printer will do a bed level check anyways. Hopefully, that makes more sense now.

                Yes that makes sense:

                • All starts, no matter the cause of prior stop, all startups do bed leveling, etc, after an interactive check to see if it should be done or skipped.

                This is available right now. Write a macro that has an message for the interactive check, then does uses a little bit of conditional gcode to do, or skip, the rest of the macro. Which does whatever you want, home, level, etc. Last line of config.g calls this macro. That way it happens at every startup. That's it.

                • Maintain a print counter, so that you can do specific things, probably the same macro you use in startup above, every N prints. This does not have to count across resets, because the same thing happens at every reset.

                Again, available now, with a tiny bit of conditional g-code.

                This would require a bit of fudging, like keeping the count in a non-existent tool (like Dave said) or similar, until conditional g-code gets variables. Again, a macro... and a tiny bit of conditional g-code... this time, the macro is invoked in the "end of job" g-code field in the slicer.

                I'm sure these can be coded with conditional g-code that exists today in V3 RC8 in stand-alone mode. I am not as certain about V3 RC8 in Pi mode.

                1 Reply Last reply Reply Quote 0
                • Danalundefined
                  Danal
                  last edited by Danal

                  Define macro "StartStuff.g" or similar. Content:

                  M291 P"Run startup bed leveling and such?" S3
                  
                  G28 
                  G32
                  ...whatever...
                  

                  This will result in a dialog on the web console:

                  99d9a6c4-b46f-48ff-b57a-b4a028bae2bc-image.png

                  Pressing OK will result in the rest of the macro (G28 and so forth) running; pressing cancel will end the macro immediately.

                  Test this; when ready to have it start every time, place

                  M98 P'StartStuff.g"
                  

                  as the last line of config.g

                  p.s. No conditional gcode per se; this works right now, in all 2.recent and 3.recent versions of firmware, with or without a Pi.

                  1 Reply Last reply Reply Quote 0
                  • Danalundefined
                    Danal
                    last edited by

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