CNC Pause and Resume config files
-
I've had a lot of success, thanks to several people on this forum, tweaking the standard 3D printer pause and resume config files to be more suitable for CNC use, but I've come across a bit a glitch.
The pause.g file appears to function correctly, but I get this error when I resume from the pause, the end result being the spindle speed isn't 'saved':
Error: in file macro line 2 column 4: meta command: unknown value 'currentTool'
These are the files:
;pause.g G1 Z{max(move.axes[2].userPosition+5,move.axes[2].max-5)} if currentTool >= 0 & tools[state.currentTool].spindle >= 0 set global.savedSpindleSpeed = tools[state.currentTool].spindleRpm ; save current spindle speed G1 X273.5 Y560 ; go to a safe place M5 ; turn the spindle off echo "Spindle speed saved at " ^ { global.savedSpindleSpeed } ^ " RPM"
; resume.g if currentTool >= 0 & tools[state.currentTool].spindle >= 0 M3 S{global.savedSpindleSpeed} ; resume saved spindle speed G4 S1 ; pause to allow the spindle to reach saved speed G1 R1 X0 Y0 F2400 ; go to above the paused XY position, keeping current Z
I'm guessing the savedSpindleSpeed hasn't actually been saved because the system either doesn't recognise 'currentTool', I've got a typo somewhere or the tool configuration is wrong.
Are there reference pages I could look at to try my own troubleshooting, please - unless someone sees something I haven't?
Thank you.
-
@nightowl999 in both files you gave used both "currentTool" (which is wrong) and "state.currentTool" (which is correct).
-
-
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
-
@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?
-
@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
-
@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 onWhen 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 savedThank you
-
@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 speedThis won't resolve to true because you have a couple of errors
Tryif {state.currentTool >= 0} & {tools[state.currentTool].spindleRpm >= 0} M3 S{global.savedSpindleSpeed} ; resume saved spindle speed
-
@owend Whoops, sorry. I kinda progressed this in the other thread you've responded to
Thank you, anyway
-
@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"
-
@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
-
@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 -
@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!
-
@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
-
@owend Doing that now, but I REMd out the other lines, so that's why there's a line 20.
Not any more, though!
-
@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
-
@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.
-
@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. -
@owend I'll try it, but I'm aware you're tired (as am I!)
-
@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.