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

    Power failure and resurrection on a CNC machine

    Scheduled Pinned Locked Moved
    CNC
    4
    108
    7.1k
    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.
    • infiniteloopundefined
      infiniteloop @Nightowl
      last edited by

      @nightowl999 said in Power failure and resurrection on a CNC machine:

      Although I feel like I’m wading through treacle, I’m learning as I go!

      Don't worry, it's easy. Just take your commented resurrect.g and follow the lines. Near the beginning, you will come up with the line

      M98 P"resurrect-prologue.g"
      

      At that point, the control flow is handed over to the macro (which in turn can call other macros). After the macro (or chain of macros) is done, control goes back to the next line in resurrect.g. That's all - just one command after the other. Well, and some of the commands (the macros) contain their own list of commands … so what?

      1 Reply Last reply Reply Quote 0
      • Nightowlundefined Nightowl referenced this topic
      • infiniteloopundefined
        infiniteloop @Nightowl
        last edited by

        @nightowl999 OK, I've done some homework myself, here's an updated version of the macro SaveSpindleSpeed.g (it has become a bit more complex, but you can just copy it):

        ; SaveSpindleSpeed.g
        ; Macro to store the actual spindle speed (RPM) at the time this is called
        ; To restore the saved datum, call the macro "RestoreSpindleSpeed.g".
        ; Before it activates the spindle, RestoreSpindleSpeed.g asks whether to continue with the print or not.
        ; If not, the process can be stopped with these two lines in resurrect-prologue.g:
        ;
        ;	if {global.abort_process == true}
        ;		abort									;;; please not that this line must be indented
        ;
        ; Requires RRF 3.4 and a CNC configuration with valid spindles[0] entry in the object model
        
        
        var fName = "RestoreSpindleSpeed.g"
        
        echo >{var.fName} "; "^var.fName
        echo >>{var.fName} "; Spindle speed saved from running """^{job.file.fileName}^""" CNC file"
        echo >>{var.fName} ""
        echo >>{var.fName} "; set up the global variable abort_process so we can abort further execution of resurrect.g:"
        echo >>{var.fName} "if {!exists(global.abort_process)}"
        echo >>{var.fName} "    global abort_process = true"
        echo >>{var.fName} "else"
        echo >>{var.fName} "    set global.abort_process = true"
        echo >>{var.fName} ""
        echo >>{var.fName} "; now comes the dialog:"
        echo >>{var.fName} "M291 S3 R""Resurrect:"" P""Continue with <"^{job.file.fileName}^">?"""
        echo >>{var.fName} ""
        echo >>{var.fName} "; we will only arrive here if the dialog was closed with OK:"
        echo >>{var.fName} "global abort_process = false"
        echo >>{var.fName} "M3 S"^{spindles[0].active}
        echo >>{var.fName} ""
        echo >>{var.fName} ";EOF"
        

        This will generate the macro RestoreSpindleSpeed.g as before, but I've added a dialog to it which asks whether you want to continue (of course, before the spindle is turned on).

        In order for all this to work, you will have to modify your resurrect-prologue.g like this:

        ; resurrect-prologue.g
        
        M98 P"RestoreSpindleSpeed.g"
        if {global.abort_process == true}
        		abort
        ; abort terminates this and all other macros in the call chain, so 'rien ne va plus'
        
        ; Continuation has been approved, so here we go:"
        ;
        ; Here, please home your axes
        ;
        ; at the end of this, control goes back to resurrect.g
        

        As long as you didn't modify your resurrect-prologue.g in the meantime, you can simply replace its contents with a copy from the black box above.

        Then, you should add your homing commands - I've commented where to put them.

        Hope this helps… 😊

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

          This is brilliant, thank you @infiniteloop

          I'll check it out tomorrow morning (it's a bit too late here to wake the neighbours!) and let you know how I get on.

          I really can't tell you how much I appreciate your help.

          Thanks again, my friend 👍

          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

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

            @nightowl999

            This is brilliant

            No, it’s attentive reading. The technique for the dialog is tricky, so it helped that I remembered the thread "Echo commands…", where @mikeabuilder explained the technique in detail - BTW, it was your thread, and he addressed his "trick" to you. So you could have written the code as well. At least, you were told how to do it…

            In fact, a good programmer spends at least 95% of his time on reading, 100% on meditation and the remaining 5% on coding, tests and debugging - at most… 😎

            [Edit] Oh, I forgot: When we finally fall asleep (which is rare), we dream of an algorithm to calculate a 'something' of which we only know the result: 42 😊

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

              @infiniteloop said in Power failure and resurrection on a CNC machine:

              No, it’s attentive reading.

              I beg to differ. What you have done for me is brilliant, even if it's simple to you!

              Anyway, on with the experiment...

              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 @infiniteloop
                last edited by

                @infiniteloop
                There seems to be an error in the resurrect-prologue.g file, because when I use M916 in the MDI, I get the following:

                Error: in file macro line 3 column 26: meta command: unknown variable 'abort_process'
                

                I've indented the line below, as instructed, so perhaps there's a typo. I'll investigate.

                I'm also getting:

                Warning: Macro file 0:/sys/workzero.g not found
                

                ...but I'm not sure what caused that!

                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

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

                  @Nightowl999 Who the hell is "MDI"?

                  The complaint about a missing abort_process indicates that RestoreSpindleSpeed.g is either not run before - it should be called from line 3 of resurrect-prologue.g, please compare your prologue with the sample I posted yesterday…

                  … or, if RestoreSpindleSpeed.g has been called before, that macro does not reflect my recent modification of SaveSpindleSpeed.g: my latest version (refer to the yesterday post) generates a RestoreSpindleSpeed.g that initialises the global variable abort_process.

                  The warning "Macro file 0:/sys/workzero.g not found" is unrelated - I have no knowledge of a macro carrying that name, so I can't help you with that.

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

                    @infiniteloop

                    Yes, it's called from that file:

                    ; resurrect-prologue.g
                    M98 P"RestoreSpindleSpeed.g"
                    if global.abort_process == true
                    	abort
                    ; abort terminates this and all other macros in the cal chain, so 'rien ne va plus'
                    ; Continuation has been approved, so here we go:"
                    M98 P"homeall.g"	; homes all axes before restarting the job
                    {1}
                    

                    And all I did with the updated RestoreSpindleSpeed.g was copy and paste...

                    A thought: Should the variable be declared in config.g, or is it a system variable?

                    PS I tried without the curly brackets, but it made no difference, so I put them back 🙂

                    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

                    infiniteloopundefined 1 Reply Last reply Reply Quote 0
                    • infiniteloopundefined
                      infiniteloop
                      last edited by

                      @nightowl999 said in Power failure and resurrection on a CNC machine:

                      Yes, it's called from that file

                      Fine. Then please replace the contents of SaveSpindleSpeed.g with this here, as I've found an (unrelated) bug.

                      ; SaveSpindleSpeed.g
                      ; Macro to store the actual spindle speed (RPM) at the time this is called
                      ; To restore the saved datum, call the macro "RestoreSpindleSpeed.g".
                      ; Before it activates the spindle, RestoreSpindleSpeed.g asks whether to continue with the print or not.
                      ; If not, the process can be stopped with these two lines in resurrect-prologue.g:
                      ;
                      ;	if {global.abort_process == true}
                      ;		abort									;;; please not that this line must be indented
                      ;
                      ; Requires RRF 3.4 and a CNC configuration with valid spindles[0] entry in the object model
                      
                      
                      var fName = "RestoreSpindleSpeed.g"
                      
                      echo >{var.fName} "; "^var.fName
                      echo >>{var.fName} "; Spindle speed saved from running """^{job.file.fileName}^""" CNC file"
                      echo >>{var.fName} ""
                      echo >>{var.fName} "; set up the global variable abort_process so we can abort further execution of resurrect.g:"
                      echo >>{var.fName} "if {!exists(global.abort_process)}"
                      echo >>{var.fName} "    global abort_process = true"
                      echo >>{var.fName} "else"
                      echo >>{var.fName} "    set global.abort_process = true"
                      echo >>{var.fName} ""
                      echo >>{var.fName} "; now comes the dialog:"
                      echo >>{var.fName} "M291 S3 R""Resurrect:"" P""Continue with <"^{job.file.fileName}^">?"""
                      echo >>{var.fName} ""
                      echo >>{var.fName} "; we will only arrive here if the dialog was closed with OK:"
                      echo >>{var.fName} "set global.abort_process = false"
                      echo >>{var.fName} "M3 S"^{spindles[0].active}
                      echo >>{var.fName} ""
                      echo >>{var.fName} ";EOF"
                      

                      Then, please simulate a power outage - this step is needed to generate the proper RestoreSpindleSpeed.g macro.

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

                        @infiniteloop No, sorry. I get exactly the same error 😞

                        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

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

                          @nightowl999 said in Power failure and resurrection on a CNC machine:

                          No, sorry. I get exactly the same error

                          OK, let's see … Could you please compare your RestoreSpindleSpeed.g with this here:

                          ; RestoreSpindleSpeed.g
                          ; Spindle speed saved from running "null" CNC file
                          
                          ; set up the global variable abort_process so we can abort further execution of resurrect.g:
                          if {!exists(global.abort_process)}
                              global abort_process = true
                          else
                              set global.abort_process = true
                          
                          ; now comes the dialog:
                          M291 S3 R"Resurrect:" P"Continue with <null>?"
                          
                          ; we will only arrive here if the dialog was closed with OK:
                          set global.abort_process = false
                          M3 S0
                          
                          ;EOF
                          

                          I generated this without a job running, that's why the CNC file name is "null", and without a spindle, M3 will always be told a speed of 0 RPM.

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

                            @infiniteloop Erm, my file looks like this...

                            ; RestoreSpindleSpeed.g
                            ; Spindle speed saved from running "0:/gcodes/Calibration Toolpath.gcode" CNC file
                            
                            ; set up the global variable abort_process so we can abort further execution of resurrect.g:
                            if {!exists(global.abort_process)}
                            

                            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

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

                              @nightowl999 said in Power failure and resurrection on a CNC machine:

                              I just noted a difference between your resurrect-prologue.g and the template I sent you - here's my version:

                              if {global.abort_process == true}
                              

                              and here's your corresponding line:

                              if global.abort_process == true
                              

                              You see the difference? 😌

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

                                @infiniteloop I do, yes. I tried it at that, but changed it back to using the squiggly brackets, as it made no difference.

                                They're currently in place, as per your version.

                                ; resurrect-prologue.g
                                M98 P"RestoreSpindleSpeed.g"
                                if {global.abort_process == true}
                                	abort
                                ; abort terminates this and all other macros in the call chain, so 'rien ne va plus'
                                ; Continuation has been approved, so here we go:"
                                M98 P"homeall.g"	; homes all axes before restarting the job
                                {1}
                                

                                I don't know why there are two {1} showing at the end of the file, though. There's only 1 in the actual file!

                                Where is the global.abort_process declared, or is it a ssytem variable?

                                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

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

                                  @nightowl999 said in Power failure and resurrection on a CNC machine:

                                  Erm, my file looks like this...

                                  That's a radically abbreviated version… 🤔

                                  Either, your SaveSpindleSpeed.g has been truncated so that it just generates 4 lines of output, or we see the result of too little power left after pulling the plug.

                                  [Edit] First, please check your copy of SaveSpindleSpeed.g carefully against the posted version. If both are equal, call SaveSpindleSpeed.g from the console:

                                  • throws it an error?
                                  • looks the resulting RestoreSpindleSpeed.g like the one I posted above?
                                  1 Reply Last reply Reply Quote 0
                                  • infiniteloopundefined
                                    infiniteloop @Nightowl
                                    last edited by

                                    @nightowl999 said in Power failure and resurrection on a CNC machine:

                                    I don't know why there are two {1} showing at the end of the file

                                    I'm not quite sure, either, but I think they indicate empty lines.

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

                                      @infiniteloop said in Power failure and resurrection on a CNC machine:

                                      but I think they indicate empty lines.

                                      Maybe you're right about the powerloss, then, or (sorry for asking again) the global.abort_process variable hasn't been declared?

                                      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

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

                                        @nightowl999 I've added some hints to my post above. Please try them …

                                        Nightowlundefined 3 Replies Last reply Reply Quote 1
                                        • Nightowlundefined
                                          Nightowl @infiniteloop
                                          last edited by Nightowl

                                          @infiniteloop It says the file's not found, but it's deffo there in my \sys folder!

                                          Error: in file macro line 28 column 26: meta command: control character in string
                                          

                                          OK, there was a " missing on the last line...

                                          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 @infiniteloop
                                            last edited by Nightowl

                                            @infiniteloop Now the file looks like this:

                                            ; RestoreSpindleSpeed.g
                                            ; Spindle speed saved from running "null" CNC file
                                            
                                            ; set up the global variable abort_process so we can abort further execution of resurrect.g:
                                            if {!exists(global.abort_process)}
                                                global abort_process = true
                                            else
                                                set global.abort_process = true
                                            
                                            ; now comes the dialog:
                                            M291 S3 R"Resurrect:" P"Continue with <null>?"
                                            
                                            ; we will only arrive here if the dialog was closed with OK:
                                            set global.abort_process = false
                                            M3 S0
                                            
                                            ;EOF
                                            

                                            I'll have another go at the power fail test...

                                            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

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