state.status and filament runout?



  • Is it possible to determine if a macro is being run during a print versus being executed directly by the user?

    Background:

    User commanded filament loading/unloaded:
    I have a macro for unloading and loading filament. The filament files themselves are pretty simple which makes it easier to create new filaments. Each will call a common file so that I don't have to reproduce that code or fix it in more places than one.

    PETG Example:

    ; 0:/filaments/PETG/load.g
    ; Macro used to load PETG, Called by the M701 S”PETG” command
    
    ; Custom temp for PETG here
    M80				; Turn on PSU
    T0				; Activate Hotend
    M702			; Unload previous material
    M291 R"Filament Handling" P"Heating nozzle for PETG, please wait." S0
    M109 S250			; set temp to 250c and wait
    
    ; Finish Common Steps
    M98 P/macros/general/filament/Load_Common
    
    ; 0:/filaments/PETG/unload.g
    ; Macro used to unload PETG, Called by the M702 command
    
    ; Custom temp for PETG here
    M80				; Turn on PSU
    T0				; Activate Hotend
    M291 R"Filament Handling" P"Heating nozzle for PETG, please wait." S0
    M109 S250		; set temp to 250c and wait
    
    ; Finish Common Steps
    M98 P/macros/general/filament/UnLoad_Common
    

    The common files:

    ; 0:/macros/general/filament/Load_Common
    ; Common Macro used to load filament, Called by the M701 S”???” command
    ; Each filament in /filaments/XXX/load.g will set the custom extruder temp then call this common macro
    
    ; Determine if we need to Home first or not
    if state.status != "processing"	;If a print is NOT in progress
    	if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed
    		G28		; Home all axes
    
    ; Filament is currently loaded
    if sensors.filamentMonitors[0].filamentPresent = true		
        M291 P"Retracting filament..." R"Unloading Filament" T5 ; Display another message
        G1 E-50 F3000 		; Retract 50mm of filament at 3000mm/min
    
    M400				; Wait for all moves to finish
    	
    ; Position the bed
    G90            		; absolute positioning
    G1 X0 Y0 Z50 F6000 	; go to X=0 Y=0 Z=50
    
    M98 P/macros/Tunes/Attention.g
    M291 P"Insert filament and then click OK to start feeding" R"Proceed?" S3
    M291 P"Feeding filament..." R"Loading Filament" T5 ; Display new message
    G1 E60 F600 ; Feed 60mm of filament at 600mm/min
    
    M98 P/macros/Tunes/Attention.g
    M291 P"Wipe off filament then click OK to complete feeding" R"Proceed?" S3
    
    M291 P"Retracting 2mm of filament..." R" Filament" T5 ; Display another message
    G1 E-2 F300 		; Retract 2mm of filament at 300mm/min
    M400				; Wait for all moves to finish
    
    ;If a print is NOT in progress
    if state.status != "processing"	
    	G10 S0 ; Turn off the heaters
    
    M98 P/macros/Tunes/LuckyTune.g
    M291 R"Filament Handling" P"Loading Complete." T5
    
    ; 0:/macros/general/filament/Unload_Common
    ; Common Macro used to load filament, Called by the M702 command
    ; Each filament in /filaments/XXX/unload.g will set the custom extruder temp then call this common macro
    
    ; Determine if we need to Home first or not
    if state.status != "processing"	;If a print is NOT in progress
    	if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed
    		G28		; Home all axes
    	
    M291 P"Retracting filament..." R"Unloading Filament" T5 ; Display another message
    G1 E-50 F3000 		; Retract 50mm of filament at 3000mm/min
    M400				; Wait for all moves to finish
    
    ; Filament is currently loaded
    if sensors.filamentMonitors[0].filamentPresent = true
        M291 P"Ready for filament unloading. Gently pull filament out and press OK." R"Filament Handling" S2
    
    ;If a print is NOT in progress
    if state.status != "processing"	
    	G10 S0 ; Turn off the heaters
    
    M98 P/macros/Tunes/LuckyTune.g
    M291 R"Filament Handling" P"Unloading Complete." T5
    

    Now for the issue:
    I am testing the filament run-out use case. My filament monitor also has the micro-switch enabled. In the event that a run-out occurs it looks like the pause.g is being called correctly, which in turn calls the filament-change.g correctly. The issue is that when this occurs because of a run-out I DO NOT want the heaters turned off. I attempted to use state.status and I expected the call to return processing when printing and busy when executing a macro. I am obviously incorrect with that assumption because my heaters were disabled when this was run in a filament-out condition.

    ; pause.g
    ; called when a print from SD card is paused or filament out is detected
    ;
    ; generated by RepRapFirmware Configuration Tool v2.1.8 on Sun Feb 09 2020 08:41:29 GMT-0600 (Central Standard Time)
    M83            ; relative extruder moves
    G1 E-4 F3600   ; retract 4mm of filament
    G91            ; relative positioning
    G1 Z5 F360     ; lift Z by 5mm
    G90            ; absolute positioning
    G1 X0 Y0 F6000 ; go to X=0 Y=0
    
    if sensors.filamentMonitors[0].filamentPresent = false          ; Filament is absent, we must have run out
         M291 S1 R"No filament detected." P"Filament Handling." T10
         M98 P"0:/sys/filament-change.g"                            ; Call filament-change.g
         G1 R1 X0 Y0 Z5 F6000                                       ; go to 5mm above position of the last print move
         G1 R1 X0 Y0                                                ; go back to the last print move
         M83                                                        ; relative extruder moves
         G1 E4 F3600                                                ; extrude 4mm of filament
         M24				                                        ; Resume Print 
    
    ; 0:/sys/filament-change.g
    ; Macro used to change filament during prints
    
    M291 P"Filament change in progress." R"Filament Change" T5 ; Display message
    
    ; Move extruder to loading position
    G1 Z5 F360		; lift Z by 5mm
    G90				; absolute positioning
    G1 X0 Y0 F6000 ; go to X=0 Y=0
    
    ; if a filament was loaded but we just ran out, load some more
    if move.extruders[0].filament != "" then
         M98 P{"0:/filaments/" ^ move.extruders[0].filament ^ "/load.g"}  ; Reload the same type of filament
         ;G1 R1 X0 Y0 Z5 F6000 ; go to 5mm above position of the last print move
         ;M83                  ; relative extruder moves to resume printing
    
    else
         M291 P"Use macros to load the desired filament." R"Filament Handling" S3
    
    ; resume.g
    ; called before a print from SD card is resumed
    ;
    ; generated by RepRapFirmware Configuration Tool v2.1.8 on Sun Feb 09 2020 08:41:29 GMT-0600 (Central Standard Time)
    G1 R1 X0 Y0 Z5 F6000 ; go to 5mm above position of the last print move
    G1 R1 X0 Y0          ; go back to the last print move
    M83                  ; relative extruder moves
    G1 E4 F3600          ; extrude 4mm of filament
    
    

    Is it possible to determine if a macro is being run during a print versus being executed directly by the user?



  • @mitch
    state.status will return "busy" when you run a macro.
    However in your case it's possible for it to return "printing" or maybe "processing" depending on where it is during a print. It might also return "busy" during a print.
    I'm not sure on the last.

    Maybe you should check whether a file is loaded

    if job.file.fileName == null
    	echo "No file selected"
           ;Turn off heaters etc
    else
    	echo "Printing " ^ job.file.fileName
            ; Do whatever you want here
    


  • @mitch
    state.status will return "busy" when you run a macro.
    However in your case it's possible for it to return "printing" or maybe "processing" depending on where it is during a print. It might also return "busy" during a print.
    I'm not sure on the last.

    Maybe you should check whether a file is loaded

    if job.file.fileName == null
    	echo "No file selected"
           ;Turn off heaters etc
    else
    	echo "Printing " ^ job.file.fileName
            ; Do whatever you want here
    


  • @OwenD great suggestion. Exactly what I was looking for.



  • @OwenD That's a great way to solve it! Checking if a file is currently loaded didn't occur to me as a way to solve the question.

    @mitch I went slightly off the deep-end and was thinking of using variables(or closest to it) to solve it as such:

    Load_Common:
    Lines: 33-35 Turn off heaters if not in Processing state.

    Unload_Common:
    Lines: 18-20 Turn off heaters in not in Processing state.

    filament-change.g calls load or unload

    In config.g (to set up existence and initial state):
    M950 F5 C"duex.fan5"
    M106 P5 C"Variable1-A"

    Logic example for pause.g:
    M106 P5 C"Variable1-B" Added before line 13

    if sensors.filamentMonitors[0].filamentPresent = false          ; Filament is absent, we must have run out
         M106 P5 C"Variable1-B"
         M291 S1 R"No filament detected." P"Filament Handling." T10
    

    Logic example for Load_Common.g:

    ;If a print is NOT in progress
    If fans[5].name = "Variable1-A" then
    	G10 S0 ; Turn off the heaters
    Else
            M106 P5 C"Variable1-A"
    


  • @Kolbi That is why I like this forum so much. Lots of quick responses and several ways to skin the cat. I think I am going to go with the file loaded as it seems to be the easiest way to solve this one.

    Although, this is really all your fault because the macros you have on your github sparked the inspiration to dig into some of this.

    BLtouch assisted bed leveling macro:
    The next idea I had was to look at a way to make a BLtouch bed leveling assistant macro. The idea would be to have the bltouch probe go to each leveling point so the user just adjusts the bed level slowly until the BL touch activates. I figure doing this in 3 or 4 passes to include the center point should make it a much shorter process that the trial and error of leveling and re-running the entire G29 to figure out where you want to tweak and re-run.

    Thanks for the help.



  • @mitch Yup, I'd go with the file check route also.

    Glad to hear I sparked inspiration! The craftbot using something like what you're talking about with assisted bed leveling - I just saw that here: https://www.youtube.com/watch?v=eItOpffE3ts



  • @Kolbi yes, at around 1:00:00 in that video is exactly what I was thinking. Should be some kind of guided level assistance with the BL touch. I searched around the forum and I haven't see anything like that yet for the Duet but I would be shocked if someone hasn't played with yet before. If I have time tomorrow I might give it a start. Will create a new thread if I can make some headway on it and maybe collaboratively we can come up with something.

    Here it is in more detail:
    https://youtu.be/YOVBBA4vJHE



  • Seems like it should be possible but the biggest hurdle would be that variables are not available for use. But... Could do something like this:

    Execute this to probe and save Z position information:

    G30 S-1
    G60 S0 ; Save to slot 0 (S0,1,2,3,4,5)
    G1 Z5
    

    Recall the z info with:

    ; Read Z position (coords[2]) from slot 0 (restorePoints[0], restorePoints[1],....)
    echo "Saved Z position for slot 0: " ^ state.restorePoints[0].coords[2] ^ "."
    

    Previously I've used this method for slots 0,1,2,3,4,5 with no issues. I myself don't have an adjustable bed but of course, I'd give what assistance I can.


  • administrators

    @mitch said in state.status and filament runout?:

    The next idea I had was to look at a way to make a BLtouch bed leveling assistant macro. The idea would be to have the bltouch probe go to each leveling point so the user just adjusts the bed level slowly until the BL touch activates. I figure doing this in 3 or 4 passes to include the center point should make it a much shorter process that the trial and error of leveling and re-running the entire G29 to figure out where you want to tweak and re-run.

    See https://duet3d.dozuki.com/Wiki/Using_the_manual_bed_levelling_assistant.



  • @dc42 thank you. This is very helpful. I will give it a try. It seems the assistant you have asks the user to adjust per a given thread pitch. I do like the craftbot method of just continuously probing and letting the use make micro adjustments to see how close they are getting to the desired positions.

    Perhaps once we have SBC capability on the Duet2 we can make more elaborate wizards and guided assistants.