Conditional code to purge after a period of time.
-
With multi-input, single output hot ends, all filaments are held at print temperature even though one or more might not be moving forward as the print progresses. Over time, those unused filaments can hydrolise (become more runny) and eventually contaminate the filament that is in use. Also, it is necessary to retract all filaments concurrently which means the same section of the "unused" filaments undergoes multiple retraction cycles which can eventually lead to problems.
So I'm wondering if there is a way to run a purge cycle during a print after a period of "n" hours or minutes has elapsed. The necessary commands to move the print head over a chute, extrude and wipe the nozzle could be wrapped in a macro. But ideally I'd want to run that macro at layer change. So the condition to trigger the macro would be the first layer change (G1 Zn) after "n" minutes or hours from when the print started. Ideally, I'd like two conditions. The first being time, the second being retraction cycles. So the macro would be triggered on the first layer change after either "n" minutes or "n" retraction cycles - whichever happens first.
I could write a little python script to post process the gcode file, count retraction cycles and insert the macro on the next layer change but that won't deal with the time aspect and I do enough post processing as it is, so I'd rather avoid that route if possible.
Thoughts?
-
@deckingman could you not always call the macro at every layer change but only actually run the contents if a variable is set to true?
And then use daemon.g to set that variable to true after the time has elapsed? -
@deckingman
About the only way I can think of with the retraction check would be to post process your file and convert all G10 to G10.1
The time based check is easy enough
You can just create a global variable in start.g or your slicer startglobal numHours = 2 ; or whatever global purgeTime = state.time + (global.numHours * 60 * 60) ; converted to seconds global retractCount = 0 global maxRetracts = 100
In your slicer layer change call a macro that compares
if (state.Time > global.purgeTime) || (global.retractCount >= global.maxRetracts) ; do your purging set global.purgeTime = state.time + (global.numHours * 60 * 60) ; reset timer set global.retractCount = 0
Edit
Forgot to say your G10.1 macro needs to increment the retraction count
set global.retractCount = global.retractCount + 1
Edit 2:
corretion. It'sstate.time
notstate.Time
-
@deckingman I would use the procedure as jay_s_uk suggested with daemon.g and evaluating variables, and detect the layer change by using the procedure of slam in
https://forum.duet3d.com/topic/23248/job-layer-not-working-anymore-with-3-3rc2/4?_=1624263146134
by analyzing the layer number comment lines.A more exotic idea which you will probably not like is stall detection of Z and put the code into the .g file which is executed after the pause.
-
@deckingman
Thinking about the G10 to G10.1 thing, it may be that the time taken to run the macro may affect print quality.
You'd have to test it to see how much.Maybe better to do a search and replace on G10 and just stick
set global.retractCount = global.retractCount + 1
in front of it. -
Thanks for the ideas guys - keep 'em coming.
@OwenD ..........or how about declare the globals in the slicer start code as you describe. But then add " set global.retractCount = global.retractCount + 1" to the front of the slicer layer change script you posted? That way the retractCount would get implemented without the need to do any search and replace or other post gcode processing.
Edit 2:
corretion. It's state.time not state.TimeCorrection to your "corretion" which should be correction. - (sorry, my warped sense of humour wouldn't let that one go).
-
@deckingman said in Conditional code to purge after a period of time.:
or how about declare the globals in the slicer start code as you describe. But then add " set global.retractCount = global.retractCount + 1" to the front of the slicer layer change script you posted?
That would only count layer changes, not retractions.
Correction to your "corretion" which should be correction. - (sorry, my warped sense of humour wouldn't let that one go).
I'm afraid my brain and my fingers aren't always on speaking terms these days
-
@deckingman
Also you'd need to check for the pre-existance of those globals to account for running multiple prints in succession.var TimeTillPurge = 2 ; so you only have to change one value if exists(global.numHours) set global.numHours = var.TimeTillPurge else global numHours = var.TimeTillPurge etc etc
-
@OwenD said in Conditional code to purge after a period of time.:
..................That would only count layer changes, not retractions.
Of course it would - whatever was I thinking?
I'm afraid my brain and my fingers aren't always on speaking terms these days
My brain just doesn't work...........