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

    Automating Sequenced Prints and Repetitions

    Scheduled Pinned Locked Moved
    Gcode meta commands
    2
    2
    732
    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.
    • SpoonUnitundefined
      SpoonUnit
      last edited by SpoonUnit

      With the incidence of RRF 3.3beta2, specifically the introduction of macro commands and variables, I can finally update my earlier hacky solutions for print automation. I'm not sure whether any one else will be interested really, but I can't see anything else quite like this here, so I thought I'd try to get it all down and at the very least I've documented it here for myself for later.

      What have I achieved?

      I've automated print removal and next-job start.

      How does it affect slicing?

      From a slicing perspective, it boils down to simply changing my end gcode from this:

      M98 P"/macros/end.g"
      

      to this

      M98 P"0:/macros/nextjob.gcode"
      

      How are models removed from the bed?

      In my case, I have a PEI-coated Alu bed from which prints in ABS, PLA, and PETG are all freely movable once the temperature gets down to about 38 degrees C. At this point, I use a tool to push the printed models from the bed into a waiting cardboard box below. Even without a specific tool for this, some models could easily be pushed by some part of the hotend carriage, assuming it's also cooled sufficiently.

      OK. So let's get into the nitty gritty.

      First, this solution supports sequences of jobs named seq1.gcode, seq2.gcode, .... seqN.gcode, or the repetition of any job named *.gcode.

      The first change is in config.g, where I define some global variables:

      ; define variables
      global repeatingJob = false
      global sequenceJob = false
      global currentSeq = 1
      global seqLimit = 1
      global remainingRepCount = 0
      global repeatingJobName = "repeat"
      

      I then have two macros for initiating a sequence job or a repeating job.

      StartSequenceJob.g

      set global.sequenceJob = true
      set global.repeatingJob = false
      set global.currentSeq = param.A
      set global.seqLimit = param.B
      M32 {"0:/gcodes/seq" ^ global.currentSeq ^ ".gcode"}
      

      StartRepeatingJob.g

      set global.sequenceJob = false
      set global.repeatingJob = true
      set global.remainingRepCount = param.A - 1
      set global.repeatingJobName = param.B
      M32 {"0:/gcodes/" ^ global.repeatingJobName ^ ".gcode"}
      

      As previously mentioned, the last line of every job uses the following end g-code:

      M98 P"0:/macros/nextjob.g"
      

      So here's nextjob.g

      if global.repeatingJob || global.sequenceJob
        G91					; relative coords
        G1 Z2 F1000			; Move Z+2
        G90					; absolute coords
        T2					; switch to seep tool 2, position 3
      
        ; check sweep height
      
        G0 Z5 F1000			; Move to sweep height
      
        ; un-comment printing tools for job
      
        ;G10 P0 S120 R120	; Set tool 0 to active and standby temp of 120
        ;G10 P1 S120 R120	; Set tool 1 to active and standby temp of 120
        ;G10 P2 S120 R120	; Set tool 2 to active and standby temp of 120
        G10 P3 S120 R120	; Set tool 3 to active and standby temp of 120
      
        ; comment following 4 lines during testing
      
        M140 S25			; Set bed temp to 25
        M191 P0 R41		; Await bed temp to cool and report 41
        M141 P0 S0		; Set bed temp to 0 (in case no more jobs)
        G4 S300			; Pause 300 seconds (5 minutes) to allow to cool to 38 or lower
      
        G1 Y-35 F2000		; Move current tool to front, sweeping objects
        T-1				; drop off tool
      
      M98 P"/macros/CallTrigger4.g" ; CallRepeatingTrigger
      

      The last line is the solution of how to kick off the next job from a job. I create and call a trigger.

      CallTrigger4.g

      ; Set up trigger4.g automation
      M950 J2 C"duex.e3stop"	; Define Input J2 for pin duex.e3stop
      M581 P2 S1 T4 R0		; Connect Input J2 (P1) to trigger 4 (T4) always (R0) for inactive to active (S1 - also default)
      ; Execute trigger4.g
      M582 T4
      

      And finally we have trigger4.g

      ; This is triggered using M98 P"/macros/CallTrigger4.g" as the last line of the macro nextjob.gcode
      
      ; Switch off trigger4.g
      M581 P-1 T4 ; remove trigger
      ; Pause here to allow the previous job to complete and be flushed.
      M400
      G4 S5
      
      ; RRF 3.3b2 implementation
      ; Can now use globals and macro params
      
      ; Three possible repeat scenarios; sequenced jobs, repetitions, standard jobs
      if global.repeatingJob
      	if global.remainingRepCount > 0
      		set global.remainingRepCount = global.remainingRepCount - 1
      		M32 "0:/gcodes/repeat.gcode"
      	else
      		M98 P"/macros/end.g"
      elif global.sequenceJob
      	if global.currentSeq < global.seqLimit
      		set global.currentSeq = global.currentSeq + 1
      		M32 {"0:/gcodes/seq" ^ global.currentSeq ^ ".gcode"}
      	else
      		M98 P"/macros/end.g"
      else
      	M98 P"/macros/end.g"
      

      Finally, at the end of my end.gcode file, I have this:

      ; reset globals
      set global.repeatingJob = false
      set global.sequenceJob = false
      

      And that's it for the setup. With this all in place, creating a sequence of prints requires the following console command:

      M98 P"0:/macros/StartSequenceJob.g" A1 B13
      

      This will print seq1 to seq13. Should you wish to increase the job list, simply upload more jobs and execute the following at the command line:

      set global.seqLimit=14
      

      You can easily reduce the count the same ways. To cancel all jobs after the current one, you could also do this:

      set global.sequenceJob=true
      

      To setup a repeating job, use this console command:

      M98 P"0:/macros/Repeat Iterations/StartRepeatingJob.g" A4 B"cone"
      

      This will result in cone.gcode being printed 4 times.

      If a job (e.g. cone.gcode) is in progress, and you want repeat that job a further 3 times, you can set the globals appropriately:

      set global.repeatingJob=true
      set global.repeatingJobName = "cone"
      set global.remainingRepCount = 3
      

      Before RRF3.3beta2 I had to use a dummy heater to store my variable values and could only use numbers. I could have probably gone further and used dummy tool names to store strings, but it was all very hacky. Having variables and globals makes this whole solution feel a lot more solid and dependable, and a little bit less complex to explain.

      Hopefully there's something here someone can use.

      timcurtis67undefined 1 Reply Last reply Reply Quote 6
      • timcurtis67undefined
        timcurtis67 @SpoonUnit
        last edited by

        @spoonunit
        Nice work. I'm looking forward to trying some of this out.

        I run some fairly large production runs on my printers.

        Thank you for sharing this.

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