Macro for cleaning and purging nozzle
-
I've been trying to adapt a klipper macro for purging and cleaning the nozzle to work with RRF 3.x, and this is what i've got as of now.
Would love some inputs and how to fix any problems i'm sure i've made lol
; nozzle_scrub.g ; Called when "M98 P"sys/lib/brush/nozzle_scrub.g"" is sent ; Used to clean the nozzle ; ;-------------------------------------------------------------------------------------------------------------------------------------- ; Sample macro config to be used in conjunction with a Purge Bucket & Nozzle Scrubber combo. ; The goal of this macro is to provide a nozzle scrubbing and purging routine that is easily copied/referenced into your printer. ; Users can simply change parameters and enable/disable options in the first half. Descriptions are plentiful, making this macro ; look huge but informative and are laid out in sequence to be read first describing the line below; PLEASE READ CAREFULLY. ; This sample config assumes the following: The user has implemented a purge bucket & nozzle scrubber to their printer ; It can be tweaked for customized purge bucket geometries and brushes. ; Features in this macro: purge routine that can be enabled/disabled. ; By default, bucket is located at rear right of bed and purge routine is enabled. The purge and scrubbing routine is randomized ; in either left or right bucket to ensure as even as possible distribution of filament gunk. ; Default parameters are set for safe speeds and movements. Where necessary, tweak the parameters for the nozzle scrub procedure ; to fit your printer. ;-------------------------------------------------------------------------------------------------------------------------------------- ; If you want the purging routine in your bucket enabled, set to True (and False vice versa). var enable_purge = True ; These parameters define your filament purging. The retract variable is used to retract right after purging to prevent unnecessary ; oozing. Some filament are particularly oozy and may continue to ooze out of the nozzle for a second or two after retracting. The ; ooze dwell variable makes allowance for this. Update as necessary. If you decided to not enable purge, you can ignore this section. var purge_len = 10 ; Amount of filament, in mm, to purge. var purge_spd = 150 ; Speed, in mm/min, of the purge. var purge_temp_min = 240 ; Minimum nozzle temperature to permit a purge. Otherwise, purge will not occur. var purge_ret = 2 ; Retract length, in mm, after purging to prevent slight oozing. Adjust as necessary. var ooze_dwell = 2 ; Dwell/wait time, in seconds, after purging and retracting. ; Adjust this so that your nozzle scrubs within the brush. Currently defaulted to be a lot higher for safety. Be careful not to go too low! var brush_top = 5.4 ; These parameters define your scrubbing, travel speeds, safe z clearance and how many times you want to wipe. Update as necessary. Wipe ; direction is randomized based off whether the left or right bucket is randomly selected in the purge & scrubbing routine. var clearance_z = 5 ; When traveling, but not cleaning, the clearance along the z-axis between nozzle and brush. var wipe_qty = 3 ; Number of complete (A complete wipe: left, right, left OR right, left, right) wipes. var prep_spd_xy = 3000 ; Travel (not cleaning) speed along x and y-axis in mm/min. var prep_spd_z = 1500 ; Travel (not cleaning) speed along z axis in mm/min. var wipe_spd_xy = 5000 ; Nozzle wipe speed in mm/min. ; These parameters define the size of the brush. Update as necessary. A visual reference is provided below. Note that orientation of ; parameters remain the same whether bucket is at rear or front. ; ; ← brush_width → ; _________________ ↑ ; | | ↑ If you chose location_bucket_rear = True, Y position is acquired ; brush_start (x) | | brush_depth from your stepper_y position_max. Adjust your brush physically in ; |_________________| ↓ Y so that the nozzle scrubs within the brush. ; (y) ↓ ; brush_front ; __________________________________________________________ ; PRINTER FRONT ; ; ; Input where your brush start is on the x axis var brush_start = 225 ; This value is defaulted from brush location in CAD (rear left). Change if your brush width is different. var brush_width = 37 ; These are only used if location_bucket_rear is False. You specify a custom location in y axis for your brush - see diagram above. ;; var brush_front = 354 var brush_depth = 5 ; These parameters define the size of your purge bucket. Update as necessary. If you decided to not enable purge, you can ignore ; this section. A visual reference is provided below. Note that orientation of parameters remain the same whether bucket is at rear ; or front. ; ; bucket_gap ; ← ---- → ; __________________________________________ ; | | | | ; | | | | ; bucket_start (x) | |______| | ; | | | | ; | | | | ; |_________________|. . . |_________________| ; ← ------------- → ← ------------- → ; bucket_left_width bucket_right_width ; _______________________________________________________________________________________ ; PRINTER FRONT ; Input your left bucket width var bucket_left_width = 92 ; Input your gap width var bucket_gap = 22 ; Input your left bucket width var bucket_right_width = 40 ; Input where your bucket start is on the x axis var bucket_start = 205 ;-------------------------------------------------------------------------------------------------------------------------------------- ; From here on, unless you know what you're doing, it's recommended not to change anything. Feel free to peruse the code and reach out to me ; on Discord (Exerqtor#3178) or the duet forum (Exerqtor) if you spot any problems, or have any sugestions for improvements! ;-------------------------------------------------------------------------------------------------------------------------------------- ; Placeholder. The variable will later be set to contain, at random, a number representing the left(0) or right(1) bucket. var bucket_pos = 1 ; First, check if the axes are homed. if move.axes[0].homed || move.axes[1].homed || move.axes[2].homed ; if axes are homed ; Report what's going on M291 R"Cleaning nozzle" P"Please wait..." T0 ; cleaning nozzle message ; Set to absolute positioning. G90 ; Check if user enabled purge option or not. if var.enable_purge = True echo "Purging" ; Randomly select left or right bin for purge. 0 = left, 1 = right set var.bucket_pos = random(2) ; Raise Z for travel. G1 Z{var.brush_top + var.clearance_z} F{var.prep_spd_z} ; Move in to the brush. G1 Y{var.brush_front + (var.brush_depth / 2)} F{var.prep_spd_xy} ; Position for purge. Randomly selects middle of left or right bucket. It references from the middle of the left bucket. G1 X{var.bucket_start + (var.bucket_left_width / (2 - var.bucket_pos)) + (var.bucket_pos * var.bucket_gap) + (var.bucket_pos * (var.bucket_right_width / 2))} ; Perform purge if the temp is up to min temp. If not, it will skip and continue executing rest of macro. Small retract after ; purging to minimize any persistent oozing at 5x purge_spd. G4 dwell is in milliseconds, hence * 1000 in formula. if heat.heaters[1].current > var.purge_temp_min M83 ; relative mode G1 E{var.purge_len} F{var.purge_spd} G1 E-{var.purge_ret} F{var.purge_spd * 5} G4 P{var.ooze_dwell * 1000} G92 E0 ; reset extruder ; Position for wipe. Either left or right of brush based off bucket_pos to avoid unnecessary travel. G1 Z{var.brush_top + var.clearance_z} F{var.prep_spd_z} G1 X{var.brush_start + (var.brush_width * var.bucket_pos)} F{var.prep_spd_xy} ; Move in to the brush. G1 Y{var.brush_front + (var.brush_depth / 2)} ; Move nozzle down into brush. G1 Z{var.brush_top} F{var.prep_spd_z} ; Perform wipe. Wipe direction based off bucket_pos for cool random scrubby routine. while true G1 X{var.brush_start + (var.brush_width * (1 - var.bucket_pos))} F{var.wipe_spd_xy} G1 X{var.brush_start + (var.brush_width * var.bucket_pos)} F{var.wipe_spd_xy} if iterations = {var.wipe_qty + 1} break ; Clear from area. M117 Cleaned! G1 Z{var.brush_top + var.clearance_z} F{var.prep_spd_z} ; If the axes aren't homed running the macro will be automatically cancelled. else !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed ; if axes aren't homed abort M291 R"Axes not homed" P"Please home all axes first!" T0 ; cleaning nozzle message
For reference: https://forum.duet3d.com/topic/28762/creating-a-random-number-in-a-macro/9
-
-
If you want to check that all of the axes listed are homed you needed to use && (and) instead of || (or).
-
When you have an if statement every line of following code that should be performed if the if is true should be indented 2 spaces from the if. A mixture of tabs and spaces will generate a complaint. And using the same number of spaces will keep things visually lined up and easier to read. If may even be required.
-
RRF Gcode is case sensitive. For example you have if var.enable_purge = True. That will generate an error as the constant is true not True.
-
You have an else followed by things to check. You cannot follow an else with things to check. The if above performs a check. If the check is false then the code under the else that is indented will be executed.
So clean that up and be sure you indenting is correct. Right now it's hard to read. Post it again and I will look closer.
Frederick
-
-
Thx for the lession The "||" between axes in my homing check is something i've copied from one lf my other macro's that i've been using almost two years now so it's actually working. But i'll change lt to "&&", didn't know the difference between the two tbh.
Reguarding the indentations i think it's getting messed up when i copy/paste the code into here tbh. I'm using tab is indentation by preference and in the file everything after the if is indented with 1tab.
I'll post the whole file once i've gotten to my computer and fixed the other stuffEDIT:
Got a minute to clean it up and switched to using spaces for indentations, so here's the file: nozzle_scrub.g -
@exerqtor said in Macro for cleaning and purging nozzle:
The "||" between axes in my homing check is something i've copied from one lf my other macro's that i've been using almost two years now so it's actually working.
If the goal is to be sure that all three axes are homed it cannot be working with || unless you have uncovered a bug in the firmware.
Got a minute to clean it up and switched to using spaces for indentations, so here's the file: nozzle_scrub.g
The problem with tabs is that different editors with different settings are going to format the text differently. With spaces it's always going to look the same on all editors, aside from font differences and things like that.
I am look at the file now.
Frederick
-
Here is my first edit. I added some "section headers" where I think they belong but please check to see if I have understood what you are doing.
There were a couple of indentation errors and an if near the end that I changed to an else since it is a bit simpler and works the same overall.
Let me know if I have made mistakes.
Thanks.
Frederick
-
I perhaps should mention that so far all I have done is try to insure the syntax and the logic is correct.
I haven't looked at the code to see how well it will do the job or anything of that nature.
Frederick
-
@fcwilt said in Macro for cleaning and purging nozzle:
@exerqtor said in Macro for cleaning and purging nozzle:
The "||" between axes in my homing check is something i've copied from one lf my other macro's that i've been using almost two years now so it's actually working.
If the goal is to be sure that all three axes are homed it cannot be working with || unless you have uncovered a bug in the firmware.
It's worked as far as i can understand at least, so in that case it must be a bug. Or maybe i've only been lucky with my usecase since i've been using it to like this for instance:
; Make sure all axes are Homed if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed ; if axes aren't homed G28 ; home all axes
(also, why does that {1} show up here in the forum all of a sudden?)
Got a minute to clean it up and switched to using spaces for indentations, so here's the file: nozzle_scrub.g
The problem with tabs is that different editors with different settings are going to format the text differently. With spaces it's always going to look the same on all editors, aside from font differences and things like that.
Aha i see, you learn something every day haha.
Here is my first edit. I added some "section headers" where I think they belong but please check to see if I have understood what you are doing.
There were a couple of indentation errors and an if near the end that I changed to an else since it is a bit simpler and works the same overall.
Let me know if I have made mistakes.
Yeah you get where i'm getting at for sure!
What editor are you using btw? I find working with spaces as supposed to tabs is somewhat difficult in notepad++ (to see where you're at if that makes sense).I perhaps should mention that so far all I have done is try to insure the syntax and the logic is correct.
I haven't looked at the code to see how well it will do the job or anything of that nature.
Well if the construct of the calculations etc. is done right now i'll drop it in the printer and see what happens, see what it outputs!
Just give me a few! -
The reason || works is you are checking for not homed via the exclamation point character proceeding the move.axes[#].homed value.
You only need to find one not homed axis to have it be true, thus || works as desired.
But when trying to determine if all axes are homed you need to check them all, thus the need for the &&.
As to my editor:
The editor I am using is one I have used for years - EditPad Pro.
It is somewhat quirky. Example, when something goes wrong, say a file cannot be accessed, the error message may end with "Bummer!".
But it is very powerful and once learned you can do just about anything.
The Duet boards support FTP which stands for File Transport Protocol. This means you can upload/download files using any FTP client.
This editor supports FTP.
It also has the concept of a Project - which is basically a group of files that you assign to a Project which you have created and named.
When you open a Project it opens all the assigned files. When you close the Project it closes all the files.
Things like find or replace can work across all the files in the Project.
But the great thing for me is the the editor supports Projects using an FTP connection.
So when I setup a Project correctly and associate it with the correct FTP connection, then when the Project is opened all the files are downloaded from the Duet and are available for editing.
When a file is changed and saved it is automatically uploaded back to the Duet.
That's a very brief overview.
Frederick
-
@fcwilt said in Macro for cleaning and purging nozzle:
The reason || works is you are checking for not homed via the exclamation point character proceeding the move.axes[#].homed value.
You only need to find one not homed axis to have it be true, thus || works as desired.
But when trying to determine if all axes are homed you need to check them all, thus the need for the &&.
That makes sense!
As to my editor:
The editor I am using is one I have used for years - EditPad Pro.
It is somewhat quirky. Example, when something goes wrong, say a file cannot be accessed, the error message may end with "Bummer!".
But it is very powerful and once learned you can do just about anything.
The Duet boards support FTP which stands for File Transport Protocol. This means you can upload/download files using any FTP client.
This editor supports FTP.
It also has the concept of a Project - which is basically a group of files that you assign to a Project which you have created and named.
When you open a Project it opens all the assigned files. When you close the Project it closes all the files.
Things like find or replace can work across all the files in the Project.
But the great thing for me is the the editor supports Projects using an FTP connection.
So when I setup a Project correctly and associate it with the correct FTP connection, then when the Project is opened all the files are downloaded from the Duet and are available for editing.
When a file is changed and saved it is automatically uploaded back to the Duet.
That's a very brief overview.
Okok, i'll check it out if i find working with spaces etc. in notepad to be to annoying. I'm using WinSCP to FTP into the duet if i need to work on the files in the printer allready but ther project functions sounds sweet though!
Other than that i've made some small minute changes to the macro, but i think(?) the math is setup wrong with the parenthesis and stuff in some places.
And the "loop" part for where it's supposed to actually wipe on the brush for the amout of times defined by var.wipe_qty don't seem to work. (Don't know if i'm just to dense or the fact that my programming skills is way bellow what it should be while working with conditional stuff. But i really miss some more examples of how to "make" the different functions etc. in the docs).
-
@exerqtor said in Macro for cleaning and purging nozzle:
Okok, i'll check it out if i find working with spaces etc. in notepad to be to annoying. I'm using WinSCP to FTP into the duet if i need to work on the files in the printer allready but ther project finctions sounds sweet though!
There are likely other good editors that have similar features. I know one called UltraEdit that has been around for ages.
Other than that i've made some small minute changes to the macro, but i think(?) the math is setup wrong with the parenthesis and stuff in some places.
Be glad to look at it.
And the "loop" part for where it's supposed to actually wipe on the brush for the amout of times defined by var.wipe_qty don't seem to work. (Don't know if i'm just to dense or the fact that my programming skills is way bellow what it should be while working with conditional stuff. But i really miss some more examples of how to "make" the different functions etc. in the docs).
Be glad to create some examples for you.
Just let me know.
Frederick
-
@fcwilt said in Macro for cleaning and purging nozzle:
@exerqtor said in Macro for cleaning and purging nozzle:
Okok, i'll check it out if i find working with spaces etc. in notepad to be to annoying. I'm using WinSCP to FTP into the duet if i need to work on the files in the printer allready but ther project finctions sounds sweet though!
There are likely other good editors that have similar features. I know one called UltraEdit that has been around for ages.
I'll have a look at both once i've got some spare time to "waste"
Other than that i've made some small minute changes to the macro, but i think(?) the math is setup wrong with the parenthesis and stuff in some places.
Be glad to look at it.
And the "loop" part for where it's supposed to actually wipe on the brush for the amout of times defined by var.wipe_qty don't seem to work. (Don't know if i'm just to dense or the fact that my programming skills is way bellow what it should be while working with conditional stuff. But i really miss some more examples of how to "make" the different functions etc. in the docs).
Be glad to create some examples for you.
Just let me know.
Sure, if you want to take a look at it you can use this(it's pretty much the same exactly the same as your V1), don't mind the stuff i've uncommented it's something i'm working on in parallell:
nozzle_scrub_v1.1.g -
Ok so now i've messed around some more with the macro and everything should be working EXCEPT the brush "loop".
Wanna have a look @fcwilt ?
nozzle_scrub_v1.2.g -
@exerqtor said in Macro for cleaning and purging nozzle:
Ok so now i've messed around some more with the macro and everything should be working EXCEPT the brush "loop".
Wanna have a look @fcwilt ?
nozzle_scrub_v1.2.gSure. Downloading it now.
What is the problem with the "loop"?
Frederick
-
Aren't you seeing warnings about mixed indentation (tabs and spaces)?
I am seeing a lot of tab characters.
Frederick
-
@fcwilt said in Macro for cleaning and purging nozzle:
@exerqtor said in Macro for cleaning and purging nozzle:
Ok so now i've messed around some more with the macro and everything should be working EXCEPT the brush "loop".
Wanna have a look @fcwilt ?
nozzle_scrub_v1.2.gSure. Downloading it now.
What is the problem with the "loop"?
Well it just don't loop i guess? it just does one brush motion and stops.
@fcwilt said in Macro for cleaning and purging nozzle:
Aren't you seeing warnings about mixed indentation (tabs and spaces)?
I am seeing a lot of tab characters.
Haven't tried running it yet, but it shouldn't be many tabs? ( I forgot using spaces on those few lines i added after the last time you looked at it).
This should be purged for any tabs (i think lol):
nozzle_scrub_v1.3.g -
@exerqtor said in Macro for cleaning and purging nozzle:
Haven't tried running it yet, but it should be many tabs? ( I forgot using spaces on those few lines i added after the last time you looked at it).
This should be purged for any tabs (i think lol):I would be glad to buy you a proper editor - it would make my "proof reading" easier as I wouldn't have to try to work out what the indentation was supposed to be.
Frederick
-
@fcwilt said in Macro for cleaning and purging nozzle:
@exerqtor said in Macro for cleaning and purging nozzle:
Haven't tried running it yet, but it should be many tabs? ( I forgot using spaces on those few lines i added after the last time you looked at it).
This should be purged for any tabs (i think lol):I would be glad to buy you a proper editor - it would make my "proof reading" easier as I wouldn't have to try to work out what the indentation was supposed to be.
Haha i THINK all the indentations should be spaces now, it was some left in the clear lines i didn't know about. Sorry for making it harder than it should
-
@exerqtor said in Macro for cleaning and purging nozzle:
@fcwilt said in Macro for cleaning and purging nozzle:
@exerqtor said in Macro for cleaning and purging nozzle:
Haven't tried running it yet, but it should be many tabs? ( I forgot using spaces on those few lines i added after the last time you looked at it).
This should be purged for any tabs (i think lol):I would be glad to buy you a proper editor - it would make my "proof reading" easier as I wouldn't have to try to work out what the indentation was supposed to be.
Haha i THINK all the indentations should be spaces now, it was some left in the clear lines i didn't know about. Sorry for making it harder than it should
I can buy a copy of EditPad online and license it to you. Then you can download it and start to use it today.
Frederick
-
I made a change to first test for non-homed axes. It eliminates that else all the way at the end of the file. It tests and if it fails it warns you and aborts.
And I added a missing S parameter to a M118. Given the other times you used echo what was the reason for the M118?
Frederick
-
@fcwilt said in Macro for cleaning and purging nozzle:
@exerqtor said in Macro for cleaning and purging nozzle:
@fcwilt said in Macro for cleaning and purging nozzle:
@exerqtor said in Macro for cleaning and purging nozzle:
Haven't tried running it yet, but it should be many tabs? ( I forgot using spaces on those few lines i added after the last time you looked at it).
This should be purged for any tabs (i think lol):I would be glad to buy you a proper editor - it would make my "proof reading" easier as I wouldn't have to try to work out what the indentation was supposed to be.
Haha i THINK all the indentations should be spaces now, it was some left in the clear lines i didn't know about. Sorry for making it harder than it should
I can buy a copy of EditPad online and license it to you. Then you can download it and start to use it today.
I really appreciate the offer, but i think it's to much to ask of you to buy me a license. It's EditPad Pro you were vouching for right? I'll actually sit my ass down and take a good look at it now.
@fcwilt said in Macro for cleaning and purging nozzle:
I made a change to first test for non-homed axes. It eliminates that else all the way at the end of the file. It tests and if it fails it warns you and aborts.
And I added a missing S parameter to a M118. Given the other times you used echo what was the reason for the M118?
Ah cool, much better way of doing it for sure!
To be honest the M118's was just some "garbage" i put in there while i started to retrofit the macro from Klipper to RRF, and since it wasn't mission critical i didn't care to do anything about it until i had other stuff fixed.For reference the klipper macro i worked off is this one:
https://github.com/VoronDesign/VoronUsers/blob/master/abandoned_mods/printer_mods/edwardyeeks/Decontaminator_Purge_Bucket_%26_Nozzle_Scrubber/Macros/nozzle_scrub.cfgI did one little itteration where i removed some of the uncommented code and fixed a bug where i had called for "var.brush_gap" instead of "var.bucket_gap" in line 151.
So now it works, loops and all. BUT i get
Error: in file macro line 169 column 209: G1: expected ')'
and i can't really understand what part of the equation it's refering to when i look at the code.
nozzle_scrub_v1.4.g