Power failure and resurrection on a CNC machine
-
@nightowl999 said in Power failure and resurrection on a CNC machine:
This is the file:
That's what I've expected. The only thing I miss is my beloved ";EOF" at the end of RestoreSpindleSpeed.g
Now the big question: does this setup what you want or do you need additional functions to be restored after a power off? With the same technique, we could generate a complete replacement or a better suited version of resurrect.g.
-
That's awesome, thank you
Because this is following a power failure, and from a safety perspective, there are some procedures I will need to initiate from starting up after the power failure (it's never my intention to be away from the machine while it's running, by the way).
I understand the machine must be homed, so it knows where it is, return to its last known XY location, remember what file it was running, remember where in that file it had got to, then wait for me to say OK for it to carry on. At the 'carry on' it should start the spindle and plunge slowly down to it's last known Z height then continue the project.
Simples!
I think the parameters for most of that will be in the resume.g file?
I've added the EOF line!
-
@nightowl999 said in Power failure and resurrection on a CNC machine:
I think the parameters for most of that will be in the resume.g file?
That depends. Currently, your resume.g is mainly meant to be called after a pause - I doubt you want this to permanently call for permission to continue. Also, at that stage of resurrect.g, i.e. when resurrect.g calls resume.g, the spindle is already running. Nothing to dream of - you want to be asked before.
A better place to ask might be your resurrect-prologue.g. From there, you can cancel further execution of resurrect.g.
I understand the machine must be homed, so it knows where it is, return to its last known XY location, remember what file it was running, remember where in that file it had got to, then wait for me to say OK for it to carry on. At the 'carry on' it should start the spindle and plunge slowly down to it's last known Z height then continue the project.
The question here is: does resurrect.g what you want? As I said, we can insert a dialog in the prologue which then asks for permission to continue … but are you fine with the part of resurrect.g which follows on the call of the prologue?
-
@infiniteloop
So it's about the event timing (I'm not sure I actually meant the resume.g file!)...On power fail, the M911 string initiates the SaveSpindleSpeed.g file which writes the RestoreSpindleSpeed.g file, taking (some) information from the active job file and elsewhere, and the default resurrect.g file is also written.
On power resume, the resurrect.g file calls the resurrect-prologue.g file, which calls the RestoreSpindleSpeed.g file to set the variables and other information ready for the specific file to continue.
It might be worth homing the machine on power resume and for it to wait there until I allow it to continue (if everything is OK, or Cancel if I need to stop the project.
Cancel will be the same as Cancel Job on the DWC.
On OK, the spindle should move to the last known XY, turn on at the saved Spindle speed, thendrop down to the last known Z height and continue on it's way.
So, in answer to your question, I think the resurrect.g file does do what I want, except for the homing sequence, which I think is necessary. I could be wrong, if all the necessary information is held in the resurrect.g file and precludes the need to home. That's what I'm not sure about.
Thank you!
-
@nightowl999 said in Power failure and resurrection on a CNC machine:
On power fail, the M911 string initiates the SaveSpindleSpeed.g file which writes the RestoreSpindleSpeed.g file, taking (some) information from the active job file and elsewhere, and the default resurrect.g file is also written.
Correct.
@nightowl999 said in Power failure and resurrection on a CNC machine:
On power resume, the resurrect.g file calls the resurrect-prologue.g file, which calls the RestoreSpindleSpeed.g file …
Up to here: correct.
… to set the variables and other information ready for the specific file to continue.
No, the file RestoreSpindleSpeed.g just restores the previously saved spindle speed - that's it. After that, it returns control back to resurrect-prologue.g (which, at this point, has no more instructions available), and, after finishing execution of the prologue, control returns to resurrect.g which then executes all lines following the call of resurrect-prologue.g.
I think the resurrect.g file does do what I want, except for the homing sequence, which I think is necessary.
That's the main job of resurrect-prologue.g - allow me to cite the documentation:
At the very least, your sys/resurrect-prologue.g file must do the following:
Home the printer, without crashing the head into the print. On a delta, or on a Cartesian or CoreXY printer with a Z max homing switch, you can home all axes. On other types of printers you may have to skip homing Z and use a G92 command to tell the printer the current Z coordinate. If you choose not to home an axis, then even if the print head hasn't moved since power down, the motor positions will change by up to 4 full steps compared to their position at power down. Note: recent firmware versions write a G92 command containing the coordinates at the time of failure into resurrect.g, just before the call to resurrect-prologue.g. So you may get away without homing axes. But it is still best to home any axes that you can (typically X and Y on a cartesian or CoreXY printer). -
I’m definitely going to try and help others with this in the future, as payback for all your help!
Although I feel like I’m wading through treacle, I’m learning as I go!
-
@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?
-
-
@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…
-
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
-
@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
-
@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...
-
@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!
-
@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.
-
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
-
@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.
-
@infiniteloop No, sorry. I get exactly the same error
-
@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. -
@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)}
-
@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?
-
@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?