Single Macro for filament handling?
-
@bearer Yup, that's what I was thinking
I could be totally off and blind, but I can't really see a clean way to have a macro parse a file to pull data from it, to be placed in a variable for logic functions. To save what was the last filament loaded, to be used to unload or change at a later point, this is my scribbled notes to myself...
Use M291/292 for timed user input, gives ability for user to select OK or cancel.
Based on user's selection of filament type, use M559/M560 to write/write-over loaded.g file. This file would contain the g-code to heat the hotend to the desired temp. Then that macro will be called within the main macro to perform the heating cycle for load / unload change.
Example:
M117 "Heating extruder for XXX."
M104 S210 ; PLA nozzle temp set
M104 S235 ; PETg nozzle temp set
M104 S250 ; ABS nozzle temp setFor PETg, loaded.g would contain:
M117 "Heating extruder for PETg."
;M104 S210 ; PLA nozzle temp set
M104 S235 ; PETg nozzle temp set
;M104 S250 ; ABS nozzle temp setFor PLA, loaded.g would contain:
M117 "Heating extruder for PLA."
M104 S210 ; PLA nozzle temp set
;M104 S235 ; PETg nozzle temp set
;M104 S250 ; ABS nozzle temp setBut what happens if the file doesn't exist and is looked for??
Or if somehow the user did not use the script to load the filament? If it looks for the macro 'loaded.g' and it doesn't exist how it it gracefully know/ detect the file doesn't exist? -
i think you could solve the parsing my just executing the file and use the object model to store variables.
to deal with missing files i suppose you could set a flag before calling M98 and make sure to clear said flag in each file to be executed.
I'm sure clever people will come up lots of ways to handle such things when the full support for using variables are implemented sometime in the near future.
-
@bearer It all looks like it should be very doable with everything mentioned above, I just need some time off work to start trying it out - I was also making sure that I'm not missing something, like some sort of built in feature that already does this.
I'm completely new to duet so it is all an adventure at the moment -
?!? Can state.status be used within a macro to determine if the machine is currently printing? Or will it simply return 'busy' because a macro is currently being run?
if state.status == "idle"
EDIT: It appears this should work, ref: https://forum.duet3d.com/topic/14013/triggers-within-homing-files/12
-
-
@bearer
-
I tried the following example but it will not work. When looking at the state.status from within a macro, it will always report 'busy'. Is there any other way, something I'm missing, that will let me know that a printer is not currently in printing something/ when it is idle (besides current macro)?
; If the printer hasn't been homed, home it - But first check if printer is idle if state.status = "idle"; Will never be idle when runnig within a macro?!?!? M117 Printer is idle, checking if homed. if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed G28
-
For the filament 'sub'macro, the following works. It is its own sub-macro that writes/overwrites a file called filatemp based on when the user exits the macro:
while 0=0; endless loop until canceled by user ; Set PLA temp M28 "0:/macros/filatemp" M117 "Heating extruder for PLA" T0 ; Activate Hotend M104 S200 ; set nozzle temp to 200c M109 S200 ; wait for extruder temp M29 M291 S3 R"Filament Handling" P"Filament type currently set to PLA. Press cancel to save this selection or OK to proceed to next filament type." ; Set PETg temp M28 "0:/macros/filatemp" M117 "Heating extruder for PETg" T0 ; Activate Hotend M104 S230 ; set nozzle temp to 230c M109 S230 ; wait for extruder temp M29 M291 S3 R"Filament Handling" P"Filament type currently set to PETg. Press cancel to save this selection or OK to proceed to next filament type." ; Set ABS temp M28 "0:/macros/filatemp" M117 "Heating extruder for ABS" T0 ; Activate Hotend M104 S250 ; set nozzle temp to 250c M109 S250 ; wait for extruder temp M29 M291 S3 R"Filament Handling" P"Filament type currently set to ABS. Press cancel to save this selection or OK to proceed to next filament type." ; Set PC temp M28 "0:/macros/filatemp" M117 "Heating extruder for ABS" T0 ; Activate Hotend M104 S270 ; set nozzle temp to 270c M109 S270 ; wait for extruder temp M29 M291 S3 R"Filament Handling" P"Filament type currently set to PC. Press cancel to save this selection or OK to proceed to next filament type."
Anyone have a nicer way to do this?
-
I have it working for the most part, had to make two files with third one auto-generated. These are the only files in my macro directory so that the user interface is streamlined on the paneldue 5.
The macro 'Set Filament Type' generates the 'Heat Nozzle' macro based on user input - kinda awkward but it works.
The macro 'Filament Handling' detects if filament is loaded or not, then heats up nozzle using auto-generated 'Heat Nozzle', and performs load or unload base on filament detected status.I want to add a third auto-option to 'Filament handling', based on if it is currently printing or not. If it is currently printing then it would automatically proceed to a changing of filament routine and not give load or unload as an option.
If anyone knows how to reliably do this, determine if a print is in progress at the time of macro execution, please let me know.
Any and all feedback is appreciated. Thanks!Macro (Directory):
Set Filament Type(File):
;Set Filament Type M291 P"Press OK to change filament type, else press CANCEL to exit." R"Filament Handling" S3 ; Set PLA temp M28 "0:/macros/Heat Nozzle" M117 "Heating extruder for PLA" T0 ; Activate Hotend M104 S200 ; set nozzle temp to 200c M109 S200 ; wait for extruder temp M29 M291 S3 R"Filament Handling" P"Filament type currently set to PLA. Press cancel to save this selection or OK to proceed to next filament type." ; Set PETg temp M28 "0:/macros/Heat Nozzle" M117 "Heating extruder for PETg" T0 ; Activate Hotend M104 S230 ; set nozzle temp to 230c M109 S230 ; wait for extruder temp M29 M291 S3 R"Filament Handling" P"Filament type currently set to PETg. Press cancel to save this selection or OK to proceed to next filament type." ; Set ABS temp M28 "0:/macros/Heat Nozzle" M117 "Heating extruder for ABS" T0 ; Activate Hotend M104 S250 ; set nozzle temp to 250c M109 S250 ; wait for extruder temp M29 M291 S3 R"Filament Handling" P"Filament type currently set to ABS. Press cancel to save this selection or OK to proceed to next filament type." ; Set PC temp M28 "0:/macros/Heat Nozzle" M117 "Heating extruder for ABS" T0 ; Activate Hotend M104 S270 ; set nozzle temp to 270c M109 S270 ; wait for extruder temp M29 M291 S3 R"Filament Handling" P"Filament type currently set to PC. Press cancel to save this selection or OK to proceed to next filament type."
Filament Handling(File):
;Filament Handling if sensors.filamentMonitors[0].filamentPresent = true M291 P"Press OK to begin filament UNLOADING, else press CANCEL to exit." R"Filament Handling" S3 M291 P"Please wait while the nozzle is being heated." T5 ; Display message M98 P"0:/macros/Heat Nozzle"; heat nozzle to predetermined temp M291 P"Ready for filament unloading. Gently pull filament and press OK." R"Filament Handling" S2 M291 P"Retracting filament..." T5 ; Display another message G1 E-150 F5000 ; Retract filament M400 ; Wait for the moves to finish M292 ; Hide the message M84 E0 ; Turn off extruder G10 S0 ; Turn off the heater else M291 P"Press OK to begin filament LOADING, else press CANCEL to exit." R"Filament Handling" S3 M291 P"Please wait while the nozzle is being heated." T5 ; Display message M98 P"0:/macros/Heat Nozzle"; heat nozzle to predetermined temp M291 P"Ready for filament loading. Insert filament and press OK." R"Filament Handling" S2 M291 P"Feeding filament..." T5 ; Display new message G1 E150 F600 ; Feed 150mm of filament at 600mm/min G1 E20 F100 ; Feed 20mm of filament at 100mm/min G4 P1000 ; Wait one second G1 E-1 F1800 ; Retract 10mm of filament at 1800mm/min M400 ; Wait for moves to complete M292 ; Hide the message M84 E0 ; Turn off extruder G10 S0 ; Turn off the heater
Heat Nozzle(File generated by 'Set Filament Type'):
;Heat Nozzle M117 "Heating extruder for PETg" T0 M104 S230 M109 S230
-
@Kolbi said in Single Macro for filament handling?:
I tried the following example but it will not work. When looking at the state.status from within a macro, it will always report 'busy'. Is there any other way, something I'm missing, that will let me know that a printer is not currently in printing something/ when it is idle (besides current macro)?
I suggest you look for state.status != "printing" instead. Here's how RRF determines state.status:
// Get the status index size_t RepRap::GetStatusIndex() const noexcept { return (processingConfig) ? 0 // Reading the configuration file #if HAS_LINUX_INTERFACE && SUPPORT_CAN_EXPANSION : (gCodes->IsFlashing() || expansion->IsFlashing()) ? 1 // Flashing a new firmware binary #else : (gCodes->IsFlashing()) ? 1 // Flashing a new firmware binary #endif : (IsStopped()) ? 2 // Halted #if HAS_VOLTAGE_MONITOR : (!platform->HasVinPower() && !gCodes->IsSimulating()) ? 3 // Off i.e. powered down #endif : (gCodes->IsPausing()) ? 4 // Pausing / Decelerating : (gCodes->IsResuming()) ? 5 // Resuming : (gCodes->IsPaused()) ? 6 // Paused / Stopped : (printMonitor->IsPrinting() && gCodes->IsSimulating()) ? 7 // Simulating : (printMonitor->IsPrinting()) ? 8 // Printing : (gCodes->IsDoingToolChange()) ? 9 // Changing tool : (gCodes->DoingFileMacro() || !move->NoLiveMovement() || gCodes->WaitingForAcknowledgement()) ? 10 // Busy : 11; // Idle }
-
@dc42 THANKS!
-
@dc42 said in Single Macro for filament handling?:
state.status != "printing"
So something such as following? See any pitfalls?
if state.status != "printing" ; Printer is not currently printing! if sensors.filamentMonitors[0].filamentPresent = true M291 P"Press OK to begin filament UNLOADING, else press CANCEL to exit." R"Filament Handling" S3 M291 P"Please wait while the nozzle is being heated." T5 ; Display message M98 P"0:/macros/Heat Nozzle"; heat nozzle to predetermined temp M291 P"Ready for filament unloading. Gently pull filament and press OK." R"Filament Handling" S2 M291 P"Retracting filament..." T5 ; Display another message G1 E-150 F5000 ; Retract filament M400 ; Wait for the moves to finish M292 ; Hide the message M84 E0 ; Turn off extruder G10 S0 ; Turn off the heater M291 P"Press OK to begin filament LOADING, else press CANCEL to exit." R"Filament Handling" S3 M98 P"0:/macros/Filament Handling"; run again else M291 P"Press OK to begin filament LOADING, else press CANCEL to exit." R"Filament Handling" S3 M291 P"Please wait while the nozzle is being heated." T5 ; Display message M98 P"0:/macros/Heat Nozzle"; heat nozzle to predetermined temp M291 P"Ready for filament loading. Insert filament and press OK." R"Filament Handling" S2 M291 P"Feeding filament..." T5 ; Display new message G1 E150 F600 ; Feed 150mm of filament at 600mm/min G1 E20 F100 ; Feed 20mm of filament at 100mm/min G4 P1000 ; Wait one second G1 E-1 F1800 ; Retract 10mm of filament at 1800mm/min M400 ; Wait for moves to complete M292 ; Hide the message M84 E0 ; Turn off extruder G10 S0 ; Turn off the heater else M291 P"Press OK to begin filament change, else press CANCEL to exit." R"Filament Handling" S3 M98 P"0:/sys/filament-change.g" ; call filament-change.g M98 P"0:/sys/resume.g" ; call resume.g
-
@Kolbi said in Single Macro for filament handling?:
state.status != "printing"
Didn't work when printing from SD card, had to use
if state.status != "Processing"
It needs some refinement but it meets the original goal:
If anyone wants to see all the sys and macro files, they are located here: https://github.com/rkolbi/RRF-machine-config-files/tree/master/Prusa MK3s
-
I updated the macro set abit. Now the load/unload routine sets the filament type system-wide / in DWC. This is good because then when in DWC, it shows the correct filament loaded and also that if you're using the filament config.g you're good to go.
The other change is that the 'Set Filament Type' macro will not let you change filament type if the filament is currently loaded - makes sense to me.
Since I don't use DWC when normally using the printer, the load/unload filament macros within DWC are empty - when in DWC I'll still use my macro.The three macro files are here:
https://github.com/rkolbi/RRF-machine-config-files/tree/master/Prusa MK3s/macrosI'm happy with the macro set operation and usability. If you have any thoughts on how to improve them please let me know.
Cheers,
Kolbi -
Well done.
-
@Phaedrux Thanks!
-
This is the latest version - most likely won't change until variables are enabled in the firmware.
Use the included Macros for filament handling.
To make filament loading, unloading, and changing the most straightforward and simplistic possible evolution, I have made a macro set that is readily accessible from the PanelDue. To take full advantage of the duet filament system you will need to make the system filaments PLA, PETG, ABS, and PC. This will allow you to have custom instructions for each different filament, by adding such to the filament's config.g file. !Note: Based on my current macro version, it is required that each filament's load.g and unload.g remain empty. Placing code into these files will make these macro fail.
"Set Filament Type" asks what type filament you are going to use; PLA, PETg, ABS, or PC. Based on the selection, this macro rewrites the "Heat Nozzle" macro to heat the nozzle for the selected filament type. !Note: This macro only has to be executed once for the given filament type change as it's settings are nonvolatile, regardless of reset or power off. !Note: The script will not let you change the filament type while filament is loaded.
"Filament Handling" is for any filament unloading, loading, and changing regardless of the printer's state, printing or not. This macro will load, unload, and change filament based on two conditions; whether it detects filament is currently loaded or not, and if a print is in progress or not. !Note: The logic function in the macro retrieves the current status of the filament sensor to base the perceived desired action to enact. If your printer's filament is currently empty and you intend to load filament, please do not place it into the extruder until requested to do so by the macro. Else the macro will determine that filament is loaded and that you desire to unload filament, instead of load.
"Heat Nozzle" is created by the "Set Filament Type" macro and can be selected to heat the hotend to the set temperature for the last chosen filament type. You do not need to run this to change filament, the "Filament Handling" macro automatically runs this macro to perform the heating of the hotend to carry out the filament handling, whether it be loading, unloading, or changing./macros
/macros/Filament Handling
; 0:/macros/Filament Handling ; Macro used for all filament handling evolutions if state.status != "processing" ; Printer is not currently printing! if sensors.filamentMonitors[0].filamentPresent = true ; Filament is detected, currently loaded M291 P"Press OK to begin filament UNLOADING, else press CANCEL to exit." R"Filament Handling" S3 M98 P"0:/macros/Heat Nozzle" ; Heat nozzle to predetermined temp M291 P"Ready for filament unloading. Gently pull filament and press OK." R"Filament Handling" S2 M291 P"Retracting filament..." T5 ; Display another message G1 E-150 F5000 ; Retract filament M400 ; Wait for the moves to finish T0 M702 ; Select tool 0, set filament is unloaded M104 S-273 ; Turn off hotend M140 S-273 ; Turn off heatbed M98 P"0:/macros/Filament Handling"; run again ; Now that filament is unloaded, lets ask to load filament else M291 P"Press OK to begin filament LOADING, else press CANCEL to exit." R"Filament Handling" S3 M98 P"0:/macros/Heat Nozzle" ; Heat nozzle to predetermined temp M291 P"Ready for filament loading. Insert filament and press OK." R"Filament Handling" S2 M291 P"Feeding filament..." T5 ; Display new message G1 E150 F450 ; Feed 150mm of filament at 600mm/min G1 E20 F100 ; Feed 20mm of filament at 100mm/min G4 P1000 ; Wait one second G1 E-1 F1800 ; Retract 10mm of filament at 1800mm/min M400 ; Wait for moves to complete M98 P"0:/sys/filaset" ; Set system filament type M400 ; Wait for moves to complete M104 S-273 ; Turn off hotend M140 S-273 ; Turn off heatbed else M291 P"Press OK to begin filament CHANGE, else press CANCEL to exit." R"Filament Handling" S3 M98 P"0:/sys/filament-change.g" ; Call filament-change.g M24 ; Start/resume SD print
/macros/Heat Nozzle
; 0:/macros/Heat Nozzle ; Heat nozzle to set temp M291 R"Filament Handling" P"Heating nozzle for PETg, please wait." S0 T10 T0 ; Select Tool 0 M109 S230 ; set temp to 230c and wait
/macros/Set Filament Type
; 0:/macros/Set Filament Type ; Macro used to set system's loaded filament type if sensors.filamentMonitors[0].filamentPresent = false ; if filament is loaded then reject action to change filament type M291 P{"System filament is currently set to " ^ move.extruders[0].filament ^ ". Press OK to change filament type, else press CANCEL to exit."} R"Filament Handling" S3 ; Set PLA temp M28 "0:/macros/Heat Nozzle" ; Begin writing to SD card file M291 R"Filament Handling" P"Heating nozzle for PLA, please wait." S0 T10 T0 ; Activate Hotend M109 S200 ; set temp to 200c and wait M29 ; Stop writing to SD card M28 "0:/sys/filaset" ; Begin writing to SD card file T0 M702 ; Set system filament as UNLOADED T0 M701 S"PLA" ; Set system filament as PLA M29 ; Stop writing to SD card M291 S3 R"Filament Handling" P"Filament type currently set to PLA. Press cancel to save this selection or OK to proceed to next filament type." ; Set PETg temp M28 "0:/macros/Heat Nozzle" ; Begin writing to SD card file M291 R"Filament Handling" P"Heating nozzle for PETg, please wait." S0 T10 T0 ; Activate Hotend M109 S230 ; set temp to 230c and wait M29 ; Stop writing to SD card M28 "0:/sys/filaset" ; Begin writing to SD card file T0 M702 ; Set system filament as UNLOADED T0 M701 S"PETG" ; Set system filament as PETG M29 ; Stop writing to SD card M291 S3 R"Filament Handling" P"Filament type currently set to PETg. Press cancel to save this selection or OK to proceed to next filament type." ; Set ABS temp M28 "0:/macros/Heat Nozzle" ; Begin writing to SD card file M291 R"Filament Handling" P"Heating nozzle for ABS, please wait." S0 T10 T0 ; Activate Hotend M109 S250 ; set temp to 250c and wait M29 ; Stop writing to SD card M28 "0:/sys/filaset" ; Begin writing to SD card file T0 M702 ; Set system filament as UNLOADED T0 M701 S"ABS" ; Set system filament as ABS M29 ; Stop writing to SD card M291 S3 R"Filament Handling" P"Filament type currently set to ABS. Press cancel to save this selection or OK to proceed to next filament type." ; Set PC temp M28 "0:/macros/Heat Nozzle" ; Begin writing to SD card file M291 R"Filament Handling" P"Heating nozzle for PC, please wait." S0 T10 T0 ; Activate Hotend M109 S270 ; set temp to 270c and wait M29 ; Stop writing to SD card M28 "0:/sys/filaset" ; Begin writing to SD card file T0 M702 ; Set system filament as UNLOADED T0 M701 S"PC" ; Set system filament as PC M29 ; Stop writing to SD card M291 S3 R"Filament Handling" P"Filament type currently set to PC. Press cancel to save this selection or OK to proceed to next filament type." else M291 S3 R"Filament Handling" P"Filament is currently loaded. Please unload filament before changing filament type."
-
This post is deleted! -
Is there a relatively easy way to edit these macros to work if one doesn't have a filament sensor?