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

load unload macro with endless loop and cancel condition

Scheduled Pinned Locked Moved
Gcode meta commands
7
44
3.0k
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.
  • undefined
    garethky
    last edited by 3 Jan 2021, 02:21

    Thanks everyone for the props and the new information. I was able to get rid of that "virtual tool" and use the object model for the filament name. I tried M703 but it doesn't work in the filament load script, so I have to execute the config file with a macro call instead.

    So now that I lost my virtual tool I needed somewhere to store the temprature and feed rate. I looked into this idea of "virtual axes" so I could store the filament settings per-tool rather than globally. This took some trial and error and I still have some warnings in the console but it work. And once I had gone that far I didn't see any reason not to do the same thing to tool changing, no reason that cant be just 3 macros either!

    I'm using the A axis to store the filament temp, B for the slow feed rate, U and V to hold the machine absolute coordinates of each tool and S to hold the nozzle diameter. then I use expressions like {tools[state.currentTool].offsets[7]} and Y{tools[state.nextTool].offsets[8]} to get the setting from the appropriate tool in the macros.

    Firmware 3.2 fixes the bug with G1 commands not accepting expressions so now the feed rate setting works as well and my flexibles wont shoot out the side of the extruder ๐Ÿ˜

    I'm not going to attempt to post all of the code here, that's what github is for: https://github.com/garethky/E3D-ToolChanger-Configuration/compare/8ee9b057f122e24b47c47b57480a3bb26d76375d..206529f2f50617df253abac9db369fd81ff42fc8

    Cheers! ๐Ÿป

    ? 1 Reply Last reply 8 Jan 2021, 09:28 Reply Quote 0
    • ?
      A Former User @garethky
      last edited by A Former User 1 Aug 2021, 12:04 8 Jan 2021, 09:28

      @garethky
      @Krohm-Koala

      I got 2 questions for giving the approach to only have 1 load.g/unload.g with in the general filaments folder a try (also that needs a workaround with a macro in each filament to point to the general file):

      1st
      for the individual load.g that is more or less only a macro-call-file for the general parametric ones you had post the example

      M98 P"/filaments/PLA/config.g" ; the filament config isn't loaded until AFTER this macro runs, but we need the variables set now

      With the new move.extruders[n].filament that could be something like

      M98 P"/filaments/move.extruders[0].filament/config.g"
      

      Or wouldnยดt just M703 be sufficient
      ?

      2nd
      How can I fetch the nozzle-temperature from the material (beside calling M703 of course), now I have:

      G10 S235 ; Set current tool temperature direct S___

      -> Would that become something like:

      G10 S{heat.heaters[1].active} ;fetch from what is in filament-config.g of selected filament

      ?

      3rd
      And for the temperature-reach-wait now

      M116 P0
      

      -> would that be something like:

      M116 P{tools[0]} ; wait for temps to be reached - for tool selected
      

      ?

      Looking at the object model that comes with RRF3.2, but I will only learn how to use it - every help appreciated ๐Ÿ˜€

      undefined 1 Reply Last reply 9 Jan 2021, 09:41 Reply Quote 0
      • undefined
        garethky
        last edited by 8 Jan 2021, 20:29

        #1 That's a good optimization! I upgraded to 3.2 firmware and now it seems that the Filament name is not set in the object model when load gets called. I haven't had a chance to investigate further. M703 didn't work there on 3.1.1. I have to go back and experiment again in 3.2

        #2 I have 2 ideas:
        First idea: If you don't have a tool selected (maybe its the beginning of the print) then this should work:

        T-1
        T2 P0 ; set the active tool but do not run the tool change macors
        M703
        ; do whatever needs doing with the filament settings
        T-1 P0

        This should also be a durable solution long term.

        Second idea: storing per-tool filament settings in the work offset system. I got started with some of the ideas over in this thread: https://forum.duet3d.com/topic/20681/virtual-axis-break-stall-detection/6?_=1610137141350

        My end goal with this is to have enough information to write a Live-Z calibration print that uses the math expressions for the extrusion lengths so they adapt to the filament diameter and nozzle diameter to print an accurate test pattern regardless of machine configuration. This doesn't require that I have access to multiple tool temperatures at the same time, so M703 will work for me.

        #3 In my tpost.g macro I have this to handle getting the tool up to temp:

        ; wait for hot end temp
        M116 P{state.currentTool}
        ? 1 Reply Last reply 9 Jan 2021, 16:45 Reply Quote 0
        • undefined
          Krohm Koala @A Former User
          last edited by 9 Jan 2021, 09:41

          @LB
          1st
          it'll be that to load the config.g of the current loaded filament

          M98 P{"0:/filaments/" ^ {move.extruders[state.currentTool].filament} ^ "/config.g"}

          2nd
          You can do as i've done, create a heat.g file in each filament, in wich you put your G10 (and maybe the bed temp also, i've separate the two and made a file that call the two macros) so you'll just have to call

          M98 P{"0:/filaments/" ^ {move.extruders[state.currentTool].filament} ^ "/heat.g"}

          3rd
          @garethky line is the way to go ๐Ÿ˜„

          ? 1 Reply Last reply 9 Jan 2021, 16:46 Reply Quote 0
          • ?
            A Former User @garethky
            last edited by 9 Jan 2021, 16:45

            @garethky

            Thanks!
            1.
            yeah now in my filament specific load/unload there is just a macro that points to the one and only load/unload for all the filaments since I get the temperatures from the filament-config.g
            2.
            have to think about it or even better: try it out ๐Ÿ™‚
            3.
            THANKS! Now it works!

            1 Reply Last reply Reply Quote 0
            • ?
              A Former User @Krohm Koala
              last edited by A Former User 1 Sept 2021, 17:18 9 Jan 2021, 16:46

              @Krohm-Koala

              Thanks!
              1.
              Thanks now it works but I had to take out the last "/" before config.g
              2.
              Yep
              We are some sort of "brothers in lazyness" I guess ๐Ÿ˜‰
              3.
              What? I do not get it...

              undefined 1 Reply Last reply 9 Jan 2021, 16:58 Reply Quote 1
              • undefined
                Krohm Koala @A Former User
                last edited by 9 Jan 2021, 16:58

                @LB the 3 was just saying that the @garethky gcode was right ๐Ÿ™‚ (sorry if it have a meaning or something that i don't understand, i haven't the greatest english x) )
                It's weird that you had to take the last "/" before config.g, it's working for me ^^

                ? 1 Reply Last reply 9 Jan 2021, 17:01 Reply Quote 0
                • ?
                  A Former User @Krohm Koala
                  last edited by A Former User 1 Sept 2021, 17:02 9 Jan 2021, 17:01

                  @Krohm-Koala said in load unload macro with endless loop and cancel condition:

                  @LB the 3 was just saying that the @garethky gcode was right ๐Ÿ™‚ (sorry if it have a meaning or something that i don't understand, i haven't the greatest english x) )
                  It's weird that you had to take the last "/" before config.g, it's working for me ^^

                  YOU are correct here -> That was an error of me, because when no filament is yet selected ("empty tool") that just threw an error SORRY -> YOU are correct here!

                  undefined 1 Reply Last reply 9 Jan 2021, 17:13 Reply Quote 0
                  • undefined
                    Krohm Koala @A Former User
                    last edited by 9 Jan 2021, 17:13

                    @LB Nice that it works now ๐Ÿ™‚

                    ? 1 Reply Last reply 9 Jan 2021, 17:28 Reply Quote 0
                    • ?
                      A Former User @Krohm Koala
                      last edited by 9 Jan 2021, 17:28

                      @Krohm-Koala said in load unload macro with endless loop and cancel condition:

                      @LB Nice that it works now ๐Ÿ™‚

                      It is not "really" working clean and cool, rather a big "workaround" to get it done somehow, but letยดs see how this all evolves the next month.

                      undefined 1 Reply Last reply 9 Jan 2021, 17:52 Reply Quote 0
                      • undefined
                        Krohm Koala @A Former User
                        last edited by 9 Jan 2021, 17:52

                        @LB How does it look now ? and what's left to do ? It's really cool to see how everyone do it their ways ๐Ÿ˜„

                        1 Reply Last reply Reply Quote 0
                        • undefined
                          garethky
                          last edited by 10 Jan 2021, 00:32

                          I have upgraded to 3.2 final and I no longer get the filament name in move.extruders[n].filament inside load.g. This now mirrors the behavior of tool changes where there is no tool selected when tpreN.g is called. I'm not against the logical consistency of this. But for tool changes we have state.nextTool which contains the tool being loaded, we don't have a similar concept for filaments. I think we should ask for a move.extruders[n].nextFilament variable in the Object Model.

                          Using this to find the filament macros directory is a neat idea. Although what we have essentially done is eliminate the need for M703 almost entirely.

                          1 Reply Last reply Reply Quote 0
                          • undefined
                            OwenD
                            last edited by 10 Jan 2021, 00:57

                            Still works for me

                            1/10/2021, 10:53:33 AM echo move.extruders[0].filament
                            ABS

                            Board: Duet 2 WiFi (2WiFi)
                            Firmware: RepRapFirmware for Duet 2 WiFi/Ethernet 3.2 (2021-01-05)
                            Duet WiFi Server Version: 1.25

                            Are you sure that there is a filament recorded in filaments.csv?
                            If there is a filament loaded in all tools the next tool is accessable using
                            echo move.extruders[state.nextTool].filament

                            1 Reply Last reply Reply Quote 0
                            • undefined
                              garethky
                              last edited by garethky 1 Oct 2021, 08:02 10 Jan 2021, 08:00

                              @OwenD

                              Maybe this is because I'm using the SBC? (Duet 3 running 3.2_final and a Pi)

                              Whenever I get into load.g (either loading or changing filaments) the filament variable is empty:

                              ; load.g
                              echo "Current Filament: '" ^ {move.extruders[state.currentTool].filament} ^ "'"

                              Current Filament: "

                              undefined 1 Reply Last reply 10 Jan 2021, 08:10 Reply Quote 0
                              • undefined
                                Krohm Koala @garethky
                                last edited by 10 Jan 2021, 08:10

                                @garethky i've just tested you echo, it works for me too, but i think it store the name after the load.g or config.g.
                                I'm loading it myself using M702 to clear filament and use M701 S"(filament)" but i don't use load/unload.g and config.g (maybe i'll be using it later but not for now) so it do nothing instead of changing the filament loaded name ^^
                                I also don't use the loading/unloading function of DWC as i have a all-in-one load/change filament macro

                                undefined 1 Reply Last reply 10 Jan 2021, 08:21 Reply Quote 0
                                • undefined
                                  garethky @Krohm Koala
                                  last edited by 10 Jan 2021, 08:21

                                  @Krohm-Koala

                                  The documentation for M701 states that it stores is after load.g exits. If you echo inside load.g, then it hasn't happened yet, so the echo will be empty.

                                  I want to use the GUI to change filament and guide the user (me ๐Ÿ˜Š ) through the process with helpful prompts.

                                  undefined undefined 2 Replies Last reply 10 Jan 2021, 09:06 Reply Quote 0
                                  • undefined
                                    OwenD @garethky
                                    last edited by 10 Jan 2021, 09:06

                                    @garethky
                                    I use a dummy fan name to store the name of the filament to be loaded.
                                    My setup is done so that I can ensure the correct filament is loaded for a sliced file, but DWC filament buttons still functions normally.
                                    Ultimately I want all the files in the filaments folders to be identical, but can't quite achieve that yet.

                                    In Prusa Slicer start G Code I have

                                    T[current_extruder] ; select tool
                                    M104 S0 R0 T[current_extruder] ; Set temps to zero to stop slicer adding them
                                    M106 P[current_extruder] S0 ;Start with fan off
                                    M950 F3 C"duex.fan3" Q0 ;create a dummy fan so we can use it's details as variables
                                    M106 P3 C"[filament_type]" S0 H-1
                                    M98 P"0:/macros/filament/check-filament-type.g"

                                    in config.g I have

                                    ; create dummy fan so we can use variables
                                    M950 F3 C"duex.fan3" Q0 ; create fan 3 on pin and set its frequency
                                    M106 P3 C"No_Filament" S0 X255 H-1
                                    ; Calibrate MCU temp
                                    M912 P0 S-4 ; Adjust MCU temp reading to match ambient
                                    ; Tools
                                    M563 P0 S"Extruder1" D0 H1 F0 ; define tool 0
                                    G10 P0 X0 Y0 Z0 ; set tool 0 axis offsets
                                    G10 P0 R0 S0 ; set initial tool 0 active and standby temperatures to 0C
                                    ; create dummy tool so we can store some variables
                                    M563 P2 S"DummyTool" ; define dummy tool 2
                                    G10 P2 X0 Y0 Z0 ; set tool 2 axis offsets
                                    G10 P2 R0 S0 ; set initial tool 2 active and standby temperatures to 0C
                                    ;Select tool zero
                                    T0 P0
                                    ; extrusion
                                    if move.extruders[state.currentTool].filament=""
                                    echo "No filament loaded. Cold extrude & retract set to defaults"
                                    M302 S190 R110 ; Allow extrusion starting from 190ยฐC and retractions already from 110ยฐC (defaults)
                                    else
                                    echo "Filament loaded. Set values per config for filament"
                                    M703 ; if a filament is loaded, set all the heats and speeds for it by loading config.g
                                    M106 P3 C{move.extruders[state.currentTool].filament} S0 H-1

                                    At present I have to do this in /filament/*/load.g.
                                    This will be easier once variables are available

                                    ;; load.g
                                    ; set the dummy fan name to the filament being loaded
                                    M950 F3 C"duex.fan3" Q0 ;create a dummy fan so we can use it's details as variables
                                    M106 P3 C"ABS" S0 H-1 ; set the fan name to ABS in case this is called from web interface
                                    M98 P"0:\macros\filament\universal_load.g"

                                    All my preheat settings and speeds etc are done in the filament/config.g
                                    These are tuned per filament naturally

                                    ; Used to set parameters for filament such as retracts, temperatures etc
                                    M302 S210 R130 ; set cold extrude and retract temperatures
                                    M291 P"loading config.g for ABS" R"Loading config" S1 T5
                                    ;M592 D0:1 A0.012 B0 ; Set non linear extrusion
                                    M572 D0 S0.09 ;Set pressure advance
                                    M207 S1.0 F2400 Z0 ; Set retraction
                                    ;M593 F25 ; cancel ringing at 25Hz

                                    filament/unload.g for all filaments just calls my universal unload.g

                                    ;; calls universal unload file.
                                    ;;
                                    M98 P"0:\macros\filament\universal_unload.g"

                                    This is the "check filament" code

                                    if move.extruders[state.currentTool].filament!= fans[3].name
                                    if job.file.fileName!=null
                                    M25
                                    M291 R"Incorrect filament loaded" P{"Incorrect filament loaded - (" ^ move.extruders[state.currentTool].filament ^ "). Print calls for (" ^ fans[3].name ^ ")." } S0 T3
                                    G4 S3
                                    M291 R"Change filament?" P"Press OK to begin filament change or CANCEL to abort job" S3
                                    M564 S0 H0; allow movement without homing
                                    M591 P1 C"e0stop" S0 D0 ; disable filament sensor for now
                                    M291 R"Incorrect Filament" P{"Move head and press OK to begin unloading " ^ move.extruders[state.currentTool].filament} S3 Z1
                                    M702 ; unload current filament
                                    M291 R"Ready to load" P{"Move head and press OK to begin loading " ^ fans[3].name} S3 Z1
                                    M701 S{fans[3].name} ; load new filament
                                    M564 S1 H1 ; do not allow movement unless homed.
                                    M591 P1 C"e0stop" S1 D0 ; enable filament sensor
                                    if job.file.fileName!=null
                                    M291 R"Filament loaded" P"Print ready to be resumed" S3

                                    This is universal load

                                    ;; universal_load.g All filament load.g files call this one.
                                    ; filament to load is stored in fans[3].name
                                    M291 R{"Loading " ^ fans[3].name} P"Loading config and heating" S1 T3
                                    G4 S3
                                    echo "attempting to load config for " ^ fans[3].name
                                    M98 P{"0:\filaments\" ^ fans[3].name ^ "\config.g"} ; load config to get extrude temps etc
                                    if result==0
                                    echo "config loaded"
                                    else
                                    echo "error loading config"
                                    echo "check tool"
                                    ;check if no tool selected or if heater is off
                                    if state.currentTool=-1
                                    T0 P0
                                    if heat.heaters[state.currentTool].state="off"
                                    T0 P0
                                    G10 P{state.currentTool} R0 S0
                                    echo "waiting for temp"
                                    M291 R{"Loading " ^ fans[3].name} P"Waiting for nozzle loading temperature..." S1 T0
                                    M98 P"0:/macros/heating/preheat_current_filament.g" ; preheat to the temps set in filament config.g
                                    M116 ; Wait for temperature
                                    ;check if the requested filament is already loaded
                                    if move.extruders[state.currentTool].filament=fans[3].name
                                    echo "filament already loaded"
                                    M291 R"Cancel loading" P"Filament already loaded. Skipping load moves" S3
                                    G4 S3
                                    M99;
                                    ; opt out option as print in running
                                    if job.file.fileName!=null && state.status!="paused"
                                    echo "Print job is running - confirmation required"
                                    M291 R"Confirm?" P"A print job is in progress. Press OK to continue or CANCEL to abort" S3
                                    ;we know the requested filament isn't loaded, but if something else is, we need to unload it first
                                    if move.extruders[state.currentTool].filament!=""
                                    echo "unload required"
                                    if move.extruders[state.currentTool].filament!=fans[3].name
                                    M702 S{"{move.extruders[state.currentTool].filament}"}
                                    M291 R"Unload finished" P"Press OK when ready to load new filament" S3
                                    echo "another filament loaded, so load new one"
                                    M701 S{fans[3].name}
                                    ; we check filament loaded again in case this is a second loop from an unload.
                                    if move.extruders[state.currentTool].filament!=fans[3].name
                                    echo "loading filament"
                                    M291 R{"Loading " ^ fans[3].name} P"Feeding and priming..." S0 T3
                                    M98 P"0:/macros/filament/do_moves_for_load.g"
                                    echo "loading complete"
                                    G92 E0 ; set extruder position to zero
                                    M291 R{"Loading " ^ fans[3].name} P"Filament loaded....." S1 T5
                                    M98 P"0:/macros/songs/simpsons.g"
                                    echo "exiting universal_load.g"
                                    G4 S3

                                    This is universal unload

                                    ;; Universal unload.g - direct all other filament unoad.g instances to this file
                                    ;;
                                    if state.currentTool==-1
                                    M291 R"Error" P"No tool selected. Unload aborted" S2
                                    M99
                                    echo "waiting for unload temp"
                                    if move.extruders[state.currentTool].filament == ""
                                    M291 R"Error" P"No filament loaded. Unload aborted" S2 T2
                                    M99
                                    M703 ; ensure correct filament settings are loaded.
                                    M291 R{"Unloading " ^ move.extruders[state.currentTool].filament} P"Waiting for nozzle unloading temperature..." S0 T10
                                    G4 S2
                                    G10 S{heat.coldRetractTemperature+5} R{heat.coldRetractTemperature} ; Heat current tool just enough to cold pull
                                    G4 S1
                                    M292 ; close popup
                                    ;show progress of heating from lower temp
                                    while (heat.heaters[tools[state.currentTool].heaters[state.currentTool]].current) < (heat.coldRetractTemperature + 5 - 2)
                                    M291 R"Preheating.. Please wait" P{"Current temp = " ^ heat.heaters[tools[state.currentTool].heaters[state.currentTool]].current ^ " : target = " ^ (heat.coldRetractTemperature+5)} S0 T1
                                    G4 P500
                                    ;show progress of cooling from hotter temp
                                    while (heat.heaters[tools[state.currentTool].heaters[state.currentTool]].current) > (heat.coldRetractTemperature + 5 + 2)
                                    M291 R"Preheating.. Please wait" P{"Current temp = " ^ heat.heaters[tools[state.currentTool].heaters[state.currentTool]].current ^ " : target = " ^ (heat.coldRetractTemperature+5)} S0 T1
                                    G4 P500
                                    M116 S0.5 ; Wait for temperature to be within 0.5 degrees of target
                                    echo "waiting for filament to settle"
                                    M291 R{"Unloading " ^ move.extruders[state.currentTool].filament} P"Waiting for filament to soften (or firm)..." S0 T10
                                    G4 T10; Wait for additional delay for filament to cool or soften
                                    echo "unloading"
                                    M291 R{"Unloading " ^ move.extruders[state.currentTool].filament} P"Retracting..." S0 T5
                                    M98 P"0:/macros/filament/do_moves_for_unload.g"
                                    G92 E0 ; set extruder position to zero
                                    echo "unloading complete"
                                    1 Reply Last reply Reply Quote 0
                                    • undefined
                                      Krohm Koala @garethky
                                      last edited by 10 Jan 2021, 09:23

                                      @garethky I use a macro, it show at the first page btw ๐Ÿ˜„ it's universal in one file (i just had to separate the purge loop to be able to cancel it) and i also like to be guide, i've done everything to be as simple and explicit as possible for the ease of use ๐Ÿ˜„ but i admit that it can be nice to use the built-in solution ๐Ÿ™‚
                                      also it detects if there's a filament, if not it skip the unload
                                      @OwenD wow it's a nice approach ! A bit too complicated for me but man, it's nice work ๐Ÿ™‚

                                      1 Reply Last reply Reply Quote 1
                                      • undefined
                                        garethky
                                        last edited by 11 Jan 2021, 00:48

                                        Also, if you put this in your load.g

                                        echo "In PETG.load, calling M703"
                                        M703
                                        echo "In PETG.load, M703 returned"
                                        echo {move.extruders[state.currentTool].filament}

                                        and this in your config.g

                                        echo "PETG Config Loaded"
                                        

                                        Then click the load filament button in the UI, You will get this in the console:

                                        M701 S"PETG" M703
                                        In PETG.load, calling M703
                                        In PETG.load, M703 returned
                                        PETG Config Loaded

                                        If you drop the same code into the unload macro you get different output:

                                        M702
                                        In PETG.unload, calling M703
                                        PETG Config Loaded
                                        In PETG.unload, M703 returned
                                        PETG

                                        So calls to M703 inside load.g don't appear to work. This is similar to how homing calls inside a homing file are illegal, so I'm not surprised. M703 inside of unload work just fine. So I love all of the optimizations above but I cant get any of them to work. I'm just going to ignore the blank string in load.g until variables show up.

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