Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Single Macro for filament handling?

    Scheduled Pinned Locked Moved Solved
    Gcode meta commands
    6
    21
    3.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Kolbiundefined
      Kolbi
      last edited by Kolbi

      ?!? 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

      A Former User? 1 Reply Last reply Reply Quote 0
      • A Former User?
        A Former User @Kolbi
        last edited by

        @Kolbi https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands

        Kolbiundefined 1 Reply Last reply Reply Quote 0
        • Kolbiundefined
          Kolbi @A Former User
          last edited by

          @bearer 👍

          1 Reply Last reply Reply Quote 0
          • Kolbiundefined
            Kolbi
            last edited by

            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
            
            dc42undefined 1 Reply Last reply Reply Quote 0
            • Kolbiundefined
              Kolbi
              last edited by Kolbi

              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?

              1 Reply Last reply Reply Quote 0
              • Kolbiundefined
                Kolbi
                last edited by Kolbi

                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
                
                1 Reply Last reply Reply Quote 0
                • dc42undefined
                  dc42 administrators @Kolbi
                  last edited by dc42

                  @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
                  
                  }
                  

                  Duet WiFi hardware designer and firmware engineer
                  Please do not ask me for Duet support via PM or email, use the forum
                  http://www.escher3d.com, https://miscsolutions.wordpress.com

                  Kolbiundefined 1 Reply Last reply Reply Quote 0
                  • Kolbiundefined
                    Kolbi @dc42
                    last edited by

                    @dc42 THANKS!

                    1 Reply Last reply Reply Quote 0
                    • Kolbiundefined
                      Kolbi
                      last edited by Kolbi

                      @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
                         
                         
                      
                      1 Reply Last reply Reply Quote 0
                      • Kolbiundefined
                        Kolbi
                        last edited by Kolbi

                        @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:
                        Picture1.png

                        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

                        1 Reply Last reply Reply Quote 1
                        • Kolbiundefined
                          Kolbi
                          last edited by

                          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/macros

                          I'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

                          1 Reply Last reply Reply Quote 0
                          • Phaedruxundefined
                            Phaedrux Moderator
                            last edited by

                            Well done.

                            Z-Bot CoreXY Build | Thingiverse Profile

                            Kolbiundefined 1 Reply Last reply Reply Quote 0
                            • Kolbiundefined
                              Kolbi @Phaedrux
                              last edited by

                              @Phaedrux Thanks!

                              1 Reply Last reply Reply Quote 0
                              • Kolbiundefined
                                Kolbi
                                last edited by Kolbi

                                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."
                                
                                
                                

                                filament.pdf

                                1 Reply Last reply Reply Quote 2
                                • mitchundefined
                                  mitch
                                  last edited by mitch

                                  This post is deleted!
                                  1 Reply Last reply Reply Quote 0
                                  • VirtualBrownundefined
                                    VirtualBrown
                                    last edited by

                                    Is there a relatively easy way to edit these macros to work if one doesn't have a filament sensor?

                                    1 Reply Last reply Reply Quote 0
                                    • First post
                                      Last post
                                    Unless otherwise noted, all forum content is licensed under CC-BY-SA