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

    Invitation to share your conditional GCode scripts

    Scheduled Pinned Locked Moved
    Gcode meta commands
    14
    23
    4.7k
    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.
    • OwenDundefined
      OwenD @PaulHew
      last edited by

      @PaulHew said in Invitation to share your conditional GCode scripts:

      @OwenD Please can I make a suggestion, at the beginning, issue a

      M290 R0 S0
      

      to reset baby stepping before you try to start performing jogging Z and trigger heights.

      Just this minute made that mistake!

      Paul

      Good idea!
      So let it be written...

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

        Code to check if all axes are homed and optionally home them, or cancel macro.
        It iterates across ALL axes making it more portable code (for those with >3 axis)
        This saves manually listing them in an if || (or) statement such as

        if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed
        

        I imagine this would be useful for tool changing printers where you might be doing something that may or may not require homing.
        For the rest of us, I'd just run G28 if any are not homed.

        ;first check if any axes are not homed and optionally home them 
        while iterations < #move.axes
        	if !move.axes[iterations].homed ; check if each axis is homed
        		M291 P{"Axis " ^ move.axes[iterations].letter ^ " is not homed.  Home now?"} R"Axis un-homed" S3 ; continue or abort?
        		M98 P{"0:/sys/home" ^ (move.axes[iterations].letter) ^ ".g"} ; home axis if answer is OK - G28 doesn't accept object variable so run macro
        		
        ; rest of code here
        
        1 Reply Last reply Reply Quote 2
        • fškundefined
          fšk
          last edited by

          Here is what I use to choose machine type at startup depending on what tool is connected.
          I include a resistor connected to the sensor pin inside the tool connector. This gives a fixed temperature reading and lets the machine choose its type depending on what is connected at startup.

          M308 S23 P"e2temp" Y"thermistor" T100000 B3950 A"ModeSelector"   ;setup a thermistor input as config selection sensor 
          
          
          ;wait for the sensor to start returning meaningful values (don't know if there is a better approach for this) 
          while sensors.analog[23].lastReading==0||sensors.analog[23].lastReading==2000
            echo
          
          ;print the value detected (useful when adding a new mode)
          ;M117 ModeSelector value:{sensors.analog[23].lastReading}
          
          ;depending on sensor reading choose a system folder
          if sensors.analog[23].lastReading==-273.1
            M117 No Attachment Detected.
          elif sensors.analog[23].lastReading<155
            M117 Going to be a CNC.
            M505 P"CNC"
          else 
            M117 Going to be a 3D printer.
            M505 P"Printer"
          
          ;load config.g from the chosen system folder
          M98 P"config.g"
          
          1 Reply Last reply Reply Quote 3
          • mwwhitedundefined
            mwwhited
            last edited by

            That’s pretty cool. I’m considering my using a serial line with some tiny85 chips that I have laying around to do the same thing. For now I write out a script that I try to call from config.g that just sets up the last executed tool script.

            Setup 3 to 1

            M28 "0:/sys/lasttool.g"
            M98 P"0:/macros/Config Scripts/Setup 3 to 1 Hotend"
            M29
            

            I have a script that uses conditional code to clear out tools, fans, and heaters as well as de-energizing my relays (stepper bank switch).

            Change Toolhead

            ;echo "check temperature"
            while iterations < #sensors.analog
            	if sensors.analog[iterations] != null && sensors.analog[iterations].lastReading > 32 && sensors.analog[iterations].name != "PS"
            		if sensors.analog[iterations].name != "Bed"
            			abort "Must wait for tool head to cool down!!!"
            
            ;echo "set relays"
            M18 E ; Turn off Steppers for extruders
            G4 P100
            M42 P0 S0 ; Ensure relay 0 is off
            M42 P1 S0 ; Ensure relay 1 is off
            M42 P2 S0 ; Ensure relay 2 is off
            G4 P100
            
            ;echo "remove all tools"
            while iterations < #tools
            	;echo "Removing Tool ", tools[iterations].name, "T", iterations
            	M563 P{iterations} D-1 H-1
            
            ;echo "disable heaters"
            while iterations < #heat.heaters
            	if heat.bedHeaters[0] != iterations
            		;echo "Removing Temp Sensor and heater", sensors.analog[heat.heaters[iterations].sensor].name, "T", heat.heaters[iterations].sensor, "H", iterations
            		M308 S{heat.heaters[iterations].sensor} P"nil" Y"nil"
            		M950 H{iterations} C"nil"
            
            ;echo "remove fans"
            while iterations < #fans
            	if fans[iterations] != null && fans[iterations ].name != "Power Supply"
            		;echo "Removing Fan", fans[iterations].name, "F", iterations
            		M950 F{iterations} C"nil"
            
            M30 "0:/sys/lasttool.g"
            
            1 Reply Last reply Reply Quote 1
            • fmaundefined
              fma
              last edited by

              Once reading I²C bus is implemented (it is maybe already done in current release, I didn't check yet), using a I²C EEPROM can be a way to identify a device; this is often used in consumer products (Gopro does or did that for their accessories).

              Frédéric

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

                @fma said in Invitation to share your conditional GCode scripts:

                Once reading I²C bus is implemented (it is maybe already done in current release, I didn't check yet), using a I²C EEPROM can be a way to identify a device; this is often used in consumer products (Gopro does or did that for their accessories).

                It also opens the possibility to store calibration data etc in the tool independent of the machine, ref IEEE1451-ish. Although Duet3d avoided using I2C for their fillament sensor (unlike Prusa) as the bus isn't intended for long runs. Maybe we'll see 1-wire or something in the future?

                1 Reply Last reply Reply Quote 0
                • fmaundefined
                  fma
                  last edited by

                  Well, the filement sensor needs continuous readings, which is not the case for calibration or so.

                  Frédéric

                  1 Reply Last reply Reply Quote 0
                  • Nemesis1782undefined
                    Nemesis1782
                    last edited by

                    Nice! This will allow me to implement tool switching without the hassle of managing multiple config files!

                    1 Reply Last reply Reply Quote 0
                    • Ozzzzzzyundefined
                      Ozzzzzzy
                      last edited by Ozzzzzzy

                      This post is deleted!
                      1 Reply Last reply Reply Quote 0
                      • Phaedruxundefined
                        Phaedrux Moderator @OwenD
                        last edited by

                        @OwenD said in Invitation to share your conditional GCode scripts:

                        Perhaps a forum section dedicated to this might be in order?

                        This now exists here: https://forum.duet3d.com/category/34/gcode-meta-commands

                        Z-Bot CoreXY Build | Thingiverse Profile

                        1 Reply Last reply Reply Quote 1
                        • T3P3Tonyundefined T3P3Tony referenced this topic
                        • First post
                          Last post
                        Unless otherwise noted, all forum content is licensed under CC-BY-SA