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

    2 different brushes for 4 printheads

    Scheduled Pinned Locked Moved Solved
    Tuning and tweaking
    6
    19
    578
    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.
    • dc42undefined
      dc42 administrators @Mike 1
      last edited by dc42

      @MIke-1 the reason that doesn't work is that you need to put "active" in double quotes. But an easier way is to use state.currentTool as @OwenD suggests.

      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

      Mike 1undefined 1 Reply Last reply Reply Quote 0
      • Mike 1undefined
        Mike 1 @OwenD
        last edited by

        @OwenD
        Oh, I can't use this version because my tools are alternating.

        OwenDundefined 1 Reply Last reply Reply Quote 0
        • Mike 1undefined
          Mike 1 @dc42
          last edited by

          @dc42
          Oh thanks! Now it is working fine!

          You are all awsome!

          1 Reply Last reply Reply Quote 0
          • OwenDundefined
            OwenD @Mike 1
            last edited by

            @MIke-1 said in 2 different brushes for 4 printheads:

            @OwenD
            Oh, I can't use this version because my tools are alternating.

            Apologies
            I missed that

            Mike 1undefined 1 Reply Last reply Reply Quote 0
            • Mike 1undefined
              Mike 1 @OwenD
              last edited by

              @OwenD
              Thanks anyway!

              OwenDundefined 1 Reply Last reply Reply Quote 0
              • OwenDundefined
                OwenD @Mike 1
                last edited by OwenD

                @MIke-1
                My clumsy effort was mainly to prompt you to try to condense your code if possible.
                Whilst manually creating an if / elif for every tool works, it's often more efficient in code and easier to read if you look for a pattern that will work regardless of the number of tools (or heaters or whatever).
                In your case, one pattern is whether the tool selected is an odd or even number.
                We can check that using mod()
                What I should have posted was something like this.

                if state.currentTool != -1 ; check if a tool selected 
                  if mod(state.currentTool,2) = 0 ; tool must be even number or zero
                    M98 P"brush_right.g"
                  else
                    M98 P"brush_left.g" ; must be odd numbered tool
                else
                  echo "no tool selected"
                

                You do however have to ensure that there is indeed a tool selected, otherwise state.currentTool is -1 and it would resolve to false and run the brush left macro
                mod(-1,2)=0 is false
                Whereas in your code, you don't have a condition for -1, so that wouldn't occur.

                If the code works, it's not wrong and it terms of lines of code there's not much difference in this case, so there's no reason for you to change what you have now.

                Mike 1undefined 2 Replies Last reply Reply Quote 1
                • Mike 1undefined
                  Mike 1 @OwenD
                  last edited by

                  @OwenD

                  Sorry for the late reply, I did not expect an answer.

                  But your code hepled me to better understand how the coding here works 🙂

                  I used the first line to make homing more save, as I can only do homing without a tool attached to the printheard.

                  I will keep my code because it ist more simpple to read and allows me to select a 3rd or 4th macro with different bush settings. It might get interesting, if I will use a vulacono hotened in the future.

                  Thanx!

                  1 Reply Last reply Reply Quote 0
                  • Mike 1undefined
                    Mike 1 @OwenD
                    last edited by

                    @OwenD said in 2 different brushes for 4 printheads:

                    if state.currentTool != -1 ; check if a tool selected
                    if mod(state.currentTool,2) = 0 ; tool must be even number or zero
                    M98 P"brush_right.g"
                    else
                    M98 P"brush_left.g" ; must be odd numbered tool
                    else
                    echo "no tool selected"

                    Can I use 2 commands after an if? How do I know when the if ends? I am missing () or endif to understand when something ends 🙂

                    gloomyandyundefined 1 Reply Last reply Reply Quote 0
                    • gloomyandyundefined
                      gloomyandy @Mike 1
                      last edited by

                      @MIke-1 The meta commands in RRF use indentation to indicate which statements are part of the body for conditional statements so for instance

                      if state.currentTool != -1
                          G28 X
                          G28 Y
                      

                      Makes both home commands conditional but in

                      if state.currentTool != -1
                          G28 X
                      G28 Y
                      

                      only the G28 X is conditional

                      See: https://docs.duet3d.com/User_manual/Reference/Gcode_meta_commands#conditional-construct

                      Mike 1undefined 1 Reply Last reply Reply Quote 0
                      • Mike 1undefined
                        Mike 1 @gloomyandy
                        last edited by

                        @gloomyandy
                        Thanx!

                        Topic can be closed 🙂

                        1 Reply Last reply Reply Quote 0
                        • Phaedruxundefined Phaedrux marked this topic as a question
                        • Phaedruxundefined Phaedrux has marked this topic as solved
                        • First post
                          Last post
                        Unless otherwise noted, all forum content is licensed under CC-BY-SA