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

    CNC Pause and Resume config files

    Scheduled Pinned Locked Moved
    Gcode meta commands
    3
    44
    1.7k
    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.
    • Nightowlundefined
      Nightowl @dc42
      last edited by

      @dc42 Aha!

      So "currentTool" should be replaced with "state.currentTool"?

      Thank you!

      Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
      I'm still on my learning curve, so take everything I say with caution!

      RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

      Nightowlundefined 1 Reply Last reply Reply Quote 0
      • Nightowlundefined
        Nightowl @Nightowl
        last edited by Nightowl

        So I've made the changes you suggested, @dc42, but the spindle speed is not saved correctly. The first notification I get is the spindle speed is saved at 0RPM

        The second thing is that, on resume, the spindle doesn't start up again. This may be related, of course.

        These are my files now...

        ; pause.g
        G1 Z{max(move.axes[2].userPosition+5,move.axes[2].max-5)}				; move the Z axis to a safe height
        if state.currentTool >= 0 & tools[state.currentTool].spindle >= 0
        	set global.savedSpindleSpeed = tools[state.currentTool].spindleRpm	; save current spindle speed
        G1 X273.5 Y560 F2400													; move XY to a safe place
        M5																		; turn the spindle off
        echo "Spindle speed saved at " ^ { global.savedSpindleSpeed } ^ "RPM"
        
        ; resume.g
        if state.currentTool >= 0 & tools[state.currentTool].spindle >= 0
        	M3 S{global.savedSpindleSpeed}	; resume saved spindle speed
        G4 S1								; wait 1 second to allow the spindle to spin up
        echo "Spindle speed resumed at " ^ { global.savedSpindleSpeed } ^ "RPM"
        G1 R1 X0 Y0 F2400					; go above the paused XY position
        

        Could you also tell me how to post these in the black boxes with pretty coloured text, too? I feel I'm demonstrating my ignorance every time I post code this way! 😊

        PS I'm going to change the echo lines shortly 👍

        Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
        I'm still on my learning curve, so take everything I say with caution!

        RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

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

          @nightowl999 have you declared the savedSpindleSpeed variable in config.g, like this?

          global savedSpindleSpeed = 0

          Also, if you temporarily remove the M5 command from pause.g does the spindle continue to run?

          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

          Nightowlundefined 2 Replies Last reply Reply Quote 0
          • Nightowlundefined
            Nightowl @dc42
            last edited by

            @dc42 said in CNC Pause and Resume config files:

            global savedSpindleSpeed = 0

            Exactly like that, yes, and way down the file, as you suggested.

            @dc42 said in CNC Pause and Resume config files:

            Also, if you temporarily remove the M5 command from pause.g does the spindle continue to run?

            I'll check that tomorrow and let you know.

            Thank you

            Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
            I'm still on my learning curve, so take everything I say with caution!

            RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

            1 Reply Last reply Reply Quote 0
            • Nightowlundefined
              Nightowl @dc42
              last edited by Nightowl

              @dc42 A bit of an update...

              With the M5 command disabled, the spindle continues to run.

              In the DWC, the Current RPM is shown as 10,000rpm but the Set RPM is 18,000rpm.

              The first lines of code within the gcode file are...

              1 ; VECTRIC POST REVISION
              2 ; A long string of random letters and numbers
              3 T1
              4 G17
              5 G21
              6 G90
              7 G0Z5.090
              8 G0X0.000Y0.000
              9 M3P0S18000
              ... and so on

              When I click Pause, I get this in the Console:

              26/05/2022, 12:20:07 Printing paused at X155.3 Y188.6 Z66.0
              26/05/2022, 12:19:56 Spindle speed saved at 0 RPM
              26/05/2022, 12:19:54 M25
              Resume state saved

              Thank you

              Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
              I'm still on my learning curve, so take everything I say with caution!

              RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

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

                @nightowl999 said in CNC Pause and Resume config files:

                ; resume.g
                if state.currentTool >= 0 & tools[state.currentTool].spindle >= 0
                M3 S{global.savedSpindleSpeed} ; resume saved spindle speed

                This won't resolve to true because you have a couple of errors
                Try

                 if {state.currentTool >= 0} & {tools[state.currentTool].spindleRpm >= 0}
                   M3 S{global.savedSpindleSpeed}	; resume saved spindle speed
                
                Nightowlundefined 1 Reply Last reply Reply Quote 1
                • Nightowlundefined
                  Nightowl @OwenD
                  last edited by

                  @owend Whoops, sorry. I kinda progressed this in the other thread you've responded to 😊

                  Thank you, anyway 👍

                  Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                  I'm still on my learning curve, so take everything I say with caution!

                  RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

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

                    @nightowl999
                    Probably better to keep this here as it's more specific than the other thread as it's become messy.

                    I'm not really familiar with all requirements of CNC mode but it may be prudent to do some more checks in your macro.
                    Also I note that there are some other spindle related object model values.
                    These might help trace what's going on

                    ; first ensure we have an active tool
                    if state.currentTool =-1
                           echo "No tool active.  Selecting tool zero"
                           T0 ; select tool zero
                    if state.currentTool >= 0
                          echo "Spindle state on tool " , state.currentTool , " is " ,   spindles[state.currentTool].active
                    
                    if {state.currentTool >= 0} & {tools[state.currentTool].spindleRpm >= 0}
                           M3 S{global.savedSpindleSpeed}	; resume saved spindle speed
                           G4 S1					; wait 1 second to allow the spindle to spin up
                           echo "Spindle speed resumed at ", spindles[state.currentTool].active, "RPM" ; this should show that the setting was successful
                           G1 R1 X0 Y0 F2400	
                    
                    else
                    
                           echo "condition not met.  Spindle speed remains at " , tools[state.currentTool].spindleRpm ,  "RPM"
                    

                    EDIT
                    I noticed an error here. Code amended above
                    echo "Spindle speed resumed at ", spindles[].active, "RPM"

                    Nightowlundefined 1 Reply Last reply Reply Quote 0
                    • Nightowlundefined
                      Nightowl @OwenD
                      last edited by

                      @owend This is the text from the console after changing the resume.g file...

                      27/05/2022, 20:02:40 	M0
                      Printing paused at X125.6 Y125.8 Z65.0
                      Cancelled printing file 0:/gcodes/Calibration Toolpath.gcode, print time was 0h 0m
                      27/05/2022, 20:02:27 	Spindle speed saved at 0 RPM
                      27/05/2022, 20:02:24 	M25
                      Resume state saved
                      27/05/2022, 20:02:22 	Printing resumed
                      27/05/2022, 20:02:09 	Spindle speed resumed at  0 RPM
                      27/05/2022, 20:02:09 	M24
                      No tool active.  Selecting tool zero
                      Spindle state on tool  0  is  5000
                      27/05/2022, 20:02:00 	Printing paused at X128.8 Y122.6 Z66.0
                      27/05/2022, 20:01:47 	Spindle speed saved at 0 RPM
                      27/05/2022, 20:01:46 	M25
                      Resume state saved
                      27/05/2022, 20:01:29 	M32 "0:/gcodes/Calibration Toolpath.gcode"
                      File 0:/gcodes/Calibration Toolpath.gcode selected for printing
                      

                      Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                      I'm still on my learning curve, so take everything I say with caution!

                      RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

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

                        @nightowl999

                        OK,
                        We are getting close.
                        It seems there is no tool selected after the pause.
                        If you have multiple tools then it may be necessary to record which was selected.
                        I made a small error on one part that didn't give me the value I wanted in one of tehechos.

                        Please change both files

                        ; pause.g
                        G1 Z{max(move.axes[2].userPosition+5,move.axes[2].max-5)} ; move the Z axis to a safe height
                        if {state.currentTool >= 0} & {tools[state.currentTool].spindleRpm >= 0}
                        	set global.savedSpindleSpeed = tools[state.currentTool].spindleRpm ; save current spindle speed
                        	G1 X273.5 Y560 F2400 ; move XY to a safe place
                        	M5 ; turn the spindle off
                        	echo "Spindle speed saved at " ^ { global.savedSpindleSpeed } ^ "RPM"
                        else
                        	echo "condition not met - Tool is ", state.currentTool, " Spindle RPM is ", tools[state.currentTool].spindleRpm
                        

                        and

                        resume.g
                        
                        ; first ensure we have an active tool
                        if state.currentTool =-1
                        	echo "No tool active.  Selecting tool zero"
                        	T0 ; select tool zero
                        if state.currentTool >= 0
                        	echo "Spindle state on tool " , state.currentTool , " is " ,   spindles[state.currentTool].state
                        if {state.currentTool >= 0} & {tools[state.currentTool].spindleRpm >= 0}
                        	M3 S{global.savedSpindleSpeed}	; resume saved spindle speed
                        	G4 S1					; wait 1 second to allow the spindle to spin up
                        	echo "Spindle speed resumed at ", spindles[state.currentTool].active, "RPM" ; this should show that the setting was successful
                        	G1 R1 X0 Y0 F2400	
                        else
                        	echo "condition not met.  Spindle speed remains at " , tools[state.currentTool].spindleRpm ,  "RPM"
                        

                        EDIT:
                        Apologies.
                        I got the indenting on pause.g all wrong. (lack of sleep). Corrected above

                        Nightowlundefined 1 Reply Last reply Reply Quote 0
                        • Nightowlundefined
                          Nightowl @OwenD
                          last edited by Nightowl

                          @owend I'm happy to leave this for now, if you need to get some beauty sleep!

                          Here's the console text:

                          27/05/2022, 20:25:40 	M0
                          Cancelled printing file 0:/gcodes/Calibration Toolpath.gcode, print time was 0h 0m
                          27/05/2022, 20:25:27 	Printing paused at X128.8 Y122.6 Z66.0
                          27/05/2022, 20:25:26 	Error: in file macro line 20 column 81: meta command: array index out of bounds
                          27/05/2022, 20:25:24 	M25
                          Resume state saved
                          27/05/2022, 20:25:19 	M32 "0:/gcodes/Calibration Toolpath.gcode"
                          File 0:/gcodes/Calibration Toolpath.gcode selected for printing
                          

                          PS You have nothing to apologise for!

                          Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                          I'm still on my learning curve, so take everything I say with caution!

                          RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

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

                            @nightowl999
                            All good.

                            Can you try this pause.g
                            I can't understand the index out of bounds if there's a tool selected.
                            There is no line 20, but you're probably getting extra carriage returns when copy/pasting

                            ; pause.g
                            if state.currentTool = -1
                            	echo "No tool selected"
                            G1 Z{max(move.axes[2].userPosition+5,move.axes[2].max-5)} ; move the Z axis to a safe height
                            {if state.currentTool >= 0} & {tools[state.currentTool].spindleRpm >= 0}
                            	set global.savedSpindleSpeed = tools[state.currentTool].spindleRpm ; save current spindle speed
                            	G1 X273.5 Y560 F2400 ; move XY to a safe place
                            	M5 ; turn the spindle off
                            	echo "Spindle speed saved at " ^ { global.savedSpindleSpeed } ^ "RPM"
                            else
                            	echo "condition not met - Tool is ", state.currentTool, " Spindle RPM is ", tools[state.currentTool].spindleRpm
                            
                            Nightowlundefined 3 Replies Last reply Reply Quote 0
                            • Nightowlundefined
                              Nightowl @OwenD
                              last edited by

                              @owend Doing that now, but I REMd out the other lines, so that's why there's a line 20.

                              Not any more, though!

                              Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                              I'm still on my learning curve, so take everything I say with caution!

                              RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

                              1 Reply Last reply Reply Quote 0
                              • Nightowlundefined
                                Nightowl @OwenD
                                last edited by

                                @owend Here you go...

                                27/05/2022, 20:38:47 	M0
                                Cancelled printing file 0:/gcodes/Calibration Toolpath.gcode, print time was 0h 0m
                                27/05/2022, 20:38:33 	Printing paused at X128.8 Y122.6 Z66.0
                                27/05/2022, 20:38:32 	No tool selected
                                Error: Bad command: {if state.currentTool >= 0} & {tools[state.currentTool].spindleRpm >= 0}
                                Error: in file macro line 6 column 36: meta command: array index out of bounds
                                27/05/2022, 20:38:30 	M25
                                Resume state saved
                                27/05/2022, 20:38:24 	M32 "0:/gcodes/Calibration Toolpath.gcode"
                                File 0:/gcodes/Calibration Toolpath.gcode selected for printing
                                

                                Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                                I'm still on my learning curve, so take everything I say with caution!

                                RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

                                1 Reply Last reply Reply Quote 0
                                • Nightowlundefined
                                  Nightowl @OwenD
                                  last edited by Nightowl

                                  @owend Should the wriggly brackets be after the second "if"?

                                  I changed it anyway, and now get this in the Console:

                                  27/05/2022, 20:46:49 	M0
                                  Cancelled printing file 0:/gcodes/Calibration Toolpath.gcode, print time was 0h 0m
                                  27/05/2022, 20:46:44 	Printing paused at X125.6 Y125.8 Z66.0
                                  27/05/2022, 20:46:43 	No tool selected
                                  Error: in file macro line 11 column 81: meta command: array index out of bounds
                                  27/05/2022, 20:46:40 	M25
                                  Resume state saved
                                  27/05/2022, 20:46:35 	M32 "0:/gcodes/Calibration Toolpath.gcode"
                                  File 0:/gcodes/Calibration Toolpath.gcode selected for printing
                                  

                                  BTW, when I click pause, the spinde keeps running and the XY stays where it is, not returning to the safe XY.

                                  Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                                  I'm still on my learning curve, so take everything I say with caution!

                                  RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

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

                                    @nightowl999 said in CNC Pause and Resume config files:

                                    Should the wriggly brackets be after the second "if"?

                                    Yes, I thought I corrected that.

                                    But now it's clear there's no tool selected when you are pausing.
                                    Therefore none of the subsequent code can work as it relies on a tool being selected.
                                    Is this a real job, or a dummy one?

                                    I'm willing to bet this would work (if I haven't mage any syntax errors LOL)

                                    ; pause.g
                                    if state.currentTool = -1
                                    	echo "No tool selected - selecting tool zero"
                                    	T0
                                    G1 Z{max(move.axes[2].userPosition+5,move.axes[2].max-5)} ; move the Z axis to a safe height
                                    if {state.currentTool >= 0} & {tools[state.currentTool].spindleRpm >= 0}
                                    	set global.savedSpindleSpeed = tools[state.currentTool].spindleRpm ; save current spindle speed
                                    	G1 X273.5 Y560 F2400 ; move XY to a safe place
                                    	M5 ; turn the spindle off
                                    	echo "Spindle speed saved at " ^ { global.savedSpindleSpeed } ^ "RPM"
                                    else
                                    	echo "condition not met - Tool is ", state.currentTool, " Spindle RPM is ", tools[state.currentTool].spindleRpm
                                    

                                    EDIT
                                    If this works then we need to know how many tools you have.

                                    Nightowlundefined 1 Reply Last reply Reply Quote 1
                                    • Nightowlundefined
                                      Nightowl @OwenD
                                      last edited by

                                      @owend I'll try it, but I'm aware you're tired (as am I!)

                                      Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                                      I'm still on my learning curve, so take everything I say with caution!

                                      RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

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

                                        @nightowl999 said in CNC Pause and Resume config files:

                                        but I'm aware you're tired (as am I!)

                                        It's 5:51 AM here. I'm tired because I woke at 3am and couldn't get back to sleep 😧
                                        Try it when you can and report back.

                                        Nightowlundefined 2 Replies Last reply Reply Quote 1
                                        • Nightowlundefined
                                          Nightowl
                                          last edited by

                                          It works! And the spindle turns off with pause and on with resume!

                                          Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                                          I'm still on my learning curve, so take everything I say with caution!

                                          RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

                                          OwenDundefined 1 Reply Last reply Reply Quote 0
                                          • Nightowlundefined
                                            Nightowl @OwenD
                                            last edited by

                                            @owend It's only 9pm here, but I've been trying to sort this all day!

                                            Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                                            I'm still on my learning curve, so take everything I say with caution!

                                            RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

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