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

    Yet more conditional gcode help required

    Scheduled Pinned Locked Moved
    Gcode meta commands
    6
    36
    1.9k
    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
      last edited by

      You could use the built-in 'iterations' variable to adjust the movement amount and/or speed.

      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

      deckingmanundefined 1 Reply Last reply Reply Quote 0
      • deckingmanundefined
        deckingman @dc42
        last edited by deckingman

        @dc42 said in Yet more conditional gcode help required:

        You could use the built-in 'iterations' variable to adjust the movement amount and/or speed.

        Thanks. Would I be right in assuming the "iterations" is a counter which increments by 1 every time the while loop runs?

        Scratch that - found it.

        Ian
        https://somei3deas.wordpress.com/
        https://www.youtube.com/@deckingman

        1 Reply Last reply Reply Quote 0
        • deckingmanundefined
          deckingman
          last edited by

          That's all working now although the code is a bit "clunky".

          I'm guessing that once variables are introduced, I ought to be able to do something like ....

          MoveAmount= 0.5+(iterations/5) 
          G1 X MoveAmount..............
          

          .......or some such. Anyway, this is what I've ended up with which may not be elegant but works.

          
          G91; Set relative
          M400; wait for any moves to finish
          G1 F3000 ; set feedrate to 100mm/sec
          M118 S"Trigger 5 - Joystick"
          while sensors.gpIn[5].value=0 | sensors.gpIn[6].value=0 | sensors.gpIn[7].value=0 | sensors.gpIn[8].value=0
          	
          	if sensors.gpIn[5].value=0; joystick left 	
          		
          		if sensors.gpIn[7].value=0 ; joystick left and forwards 
          			M400 
          			if iterations<3
          				G1 X-0.5 U-0.5 A-0.5 Y-0.5 V-0.5 B-0.5
          			elif iterations<5
          				G1 X-1 U-1 A-1 Y-1 V-1 B-1
          			elif iterations<7
          				G1 X-2 U-2 A-2 Y-2 V-2 B-2
          			elif iterations<9
          				G1 X-5 U-5 A-5 Y-5 V-5 B-5	
          			elif iterations<11
          				G1 X-10 U-10 A-10 Y-10 V-10 B-10
          			else 
          				G1 X-20 U-20 A-20 Y-20 V-20 B-20	
          			
          			
          		elif sensors.gpIn[8].value=0; joystick left and backwards	
          			M400
          			if iterations<3
          				G1 X-0.5 U-0.5 A-0.5 Y0.5 V0.5 B0.5
          			elif iterations<5
          				G1 X-1 U-1 A-1 Y1 V1 B1
          			elif iterations<7
          				G1 X-2 U-2 A-2 Y2 V2 B2
          			elif iterations<9
          				G1 X-5 U-5 A-5 Y5 V5 B5	
          			elif iterations<11
          				G1 X-10 U-10 A-10 Y10 V10 B10
          			else 
          				G1 X-20 U-20 A-20 Y20 V20 B20
          			
          			
          		else ; joystick left only
          			M400
          			if iterations<3
          				G1 X-0.5 U-0.5 A-0.5 
          			elif iterations<5
          				G1 X-1 U-1 A-1 
          			elif iterations<7
          				G1 X-2 U-2 A-2 
          			elif iterations<9
          				G1 X-5 U-5 A-5 
          			elif iterations<11
          				G1 X-10 U-10 A-10 
          			else 
          				G1 X-20 U-20 A-20
          			
          						
          	elif sensors.gpIn[6].value=0; joystick right 	
          		
          		if sensors.gpIn[7].value=0 ; joystick right and forwards 
          			M400
          			if iterations<3
          				G1 X0.5 U0.5 A0.5 Y-0.5 V-0.5 B-0.5
          			elif iterations<5
          				G1 X1 U1 A1 Y-1 V-1 B-1
          			elif iterations<7
          				G1 X2 U2 A2 Y-2 V-2 B-2
          			elif iterations<9
          				G1 X5 U5 A5 Y-5 V-5 B-5	
          			elif iterations<11
          				G1 X10 U10 A10 Y-10 V-10 B-10
          			else 
          				G1 X20 U20 A20 Y-20 V-20 B-20
          			
          			
          		elif sensors.gpIn[8].value=0; joystick right and backward	
          			M400
          			if iterations<3
          				G1 X0.5 U0.5 A0.5 Y0.5 V0.5 B0.5
          			elif iterations<5
          				G1 X1 U1 A1 Y1 V1 B1
          			elif iterations<7
          				G1 X2 U2 A2 Y2 V2 B2
          			elif iterations<9
          				G1 X5 U5 A5 Y5 V5 B5	
          			elif iterations<11
          				G1 X10 U10 A10 Y10 V10 B10
          			else 
          				G1 X20 U20 A20 Y20 V20 B20
          			
          			
          		else ; joystick right only
          			M400
          			if iterations<3
          				G1 X0.5 U0.5 A0.5
          			elif iterations<5
          				G1 X1 U1 A1 
          			elif iterations<7
          				G1 X2 U2 A2 
          			elif iterations<9
          				G1 X5 U5 A5 
          			elif iterations<11
          				G1 X10 U10 A10 
          			else 
          				G1 X20 U20 A20 
          			
          	
          	elif sensors.gpIn[7].value=0 ; joystick forwards only	
          		M400
          		if iterations<3
          				G1 Y-0.5 V-0.5 B-0.5
          			elif iterations<5
          				G1 Y-1 V-1 B-1
          			elif iterations<7
          				G1 Y-2 V-2 B-2
          			elif iterations<9
          				G1 Y-5 V-5 B-5	
          			elif iterations<11
          				G1 Y-10 V-10 B-10
          			else 
          				G1 Y-20 V-20 B-20
          				
          	elif sensors.gpIn[8].value=0 ; joystick backward only
          		M400
          		if iterations<3
          				G1 Y0.5 V0.5 B0.5
          			elif iterations<5
          				G1 Y1 V1 B1
          			elif iterations<7
          				G1 Y2 V2 B2
          			elif iterations<9
          				G1 Y5 V5 B5	
          			elif iterations<11
          				G1 Y10 V10 B10
          			else 
          				G1 Y20 V20 B20
          		
          		
          	else break
          	
          

          Ian
          https://somei3deas.wordpress.com/
          https://www.youtube.com/@deckingman

          1 Reply Last reply Reply Quote 0
          • dc42undefined
            dc42 administrators
            last edited by dc42

            Another way is to use your original code but replace all the XYUVABC coordinates in the G1 commands by calculated values, something like this:

            G1 X{0.5+0.1 * iterations} Y{-(0.5+0.1 * iterations)} ...

            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

            deckingmanundefined 1 Reply Last reply Reply Quote 0
            • deckingmanundefined
              deckingman @dc42
              last edited by

              @dc42 said in Yet more conditional gcode help required:

              Another way is to use your original code but replace all the XYUVABC coordinates in the G1 commands by calculated values, something like this:

              G1 X{0.5+0.1 * iterations} Y{-(0.5+0.1 * iterations)} ...

              Ahhh - that looks good! I tried something similar but it didn't work - because I used plain braces rather than curly ones. I'll give that a go..............

              Ian
              https://somei3deas.wordpress.com/
              https://www.youtube.com/@deckingman

              1 Reply Last reply Reply Quote 0
              • deckingmanundefined
                deckingman
                last edited by

                For the sake of completeness, here is the final code that I ended up using. After playing around with it, I ended up using just G1 X{0.5+interations}........etc, rather than using fraction's of "iterations".

                G91; Set relative
                M400; wait for any moves to finish
                G1 F6000 ; set feedrate to 100mm/sec
                M118 S"Trigger 5 - Joystick"
                while sensors.gpIn[5].value=0 | sensors.gpIn[6].value=0 | sensors.gpIn[7].value=0 | sensors.gpIn[8].value=0
                	
                	if sensors.gpIn[5].value=0; joystick left 	
                		
                		if sensors.gpIn[7].value=0 ; joystick left and forwards 
                			M400 
                			G1 X{-(0.5+iterations)} U{-(0.5+iterations)} A{-(0.5+iterations)} Y{-(0.5+iterations)} V{-(0.5+iterations)} B{-(0.5+iterations)}
                			echo "Left and forward"
                			
                		elif sensors.gpIn[8].value=0; joystick left and backwards	
                			M400
                			G1 X{-(0.5+iterations)} U{-(0.5+iterations)} A{-(0.5+iterations)} Y{0.5+iterations} V{0.5+iterations} B{0.5+iterations}
                			
                			echo "Left and backwards"
                			
                		else ; joystick left only
                			M400
                			G1 X{-(0.5+iterations)} U{-(0.5+iterations)} A{-(0.5+iterations)}
                			echo "Left"
                			
                	elif sensors.gpIn[6].value=0; joystick right 	
                		
                		if sensors.gpIn[7].value=0 ; joystick right and forwards 
                			M400
                			G1 X{0.5+iterations} U{0.5+iterations} A{0.5+iterations} Y{-(0.5+iterations)} V{-(0.5+iterations)} B{-(0.5+iterations)}
                			echo "Right and forward"
                			
                		elif sensors.gpIn[8].value=0; joystick right and backward	
                			M400
                			G1 X{0.5+iterations} U{0.5+iterations} A{0.5+iterations} Y{0.5+iterations} V{0.5+iterations} B{0.5+iterations}
                			echo "Right and backwards"
                			
                		else ; joystick right only
                			M400
                			G1 X{0.5+iterations} U{0.5+iterations} A{0.5+iterations}
                			echo "Right"
                	
                	elif sensors.gpIn[7].value=0 ; joystick forwards only	
                		M400
                		G1 Y{-(0.5+iterations)} V{-(0.5+iterations)} B{-(0.5+iterations)}
                		echo "Forward"
                		
                	elif sensors.gpIn[8].value=0 ; joystick backward only
                		M400
                		G1 Y{0.5+iterations} V{0.5+iterations} B{0.5+iterations}
                		echo "Backwards"
                		
                	else break
                
                

                Thanks for all the help guys.

                Ian
                https://somei3deas.wordpress.com/
                https://www.youtube.com/@deckingman

                1 Reply Last reply Reply Quote 2
                • deckingmanundefined
                  deckingman
                  last edited by

                  For further completeness, I've added a "turbo button". So instead of increasing the distance using "iterations", I simply press the button in conjunction with moving the joystick. What that does is move the gantries 20mm if the button is pressed or 0.5mm if it isn't. I prefer this method but either one works.

                  I've also wrapped the entire thing in a "if state.status != "processing"" statement (thanks for the suggestion @T3P3Tony). What that does is checks to make sure that a print is NOT in progress which will do what the M581 R2 parameter will do in the next firmware. Here is that version of the code

                  
                  if state.status != "processing" ; make sure that a print is NOT running
                  	G91; Set relative
                  	M400; wait for any moves to finish
                  	G1 F3000 ; set feedrate to 100mm/sec
                  	M118 S"Trigger 5 - Joystick"
                  	while sensors.gpIn[5].value=0 | sensors.gpIn[6].value=0 | sensors.gpIn[7].value=0 | sensors.gpIn[8].value=0
                  	
                  		if sensors.gpIn[5].value=0; joystick left 	
                  		
                  			if sensors.gpIn[7].value=0 ; joystick left and forwards 
                  				M400
                  				echo "Left and forward"
                  				if sensors.gpIn[4].value=0 ; check for long move button press
                  					G1 X-20 U-20 A-20 Y-20 V-20 B-20
                  				else
                  					G1 X-0.5 U-0.5 A-0.5 Y-0.5 V-0.5 B-0.5
                  			
                  			elif sensors.gpIn[8].value=0; joystick left and backwards	
                  				M400
                  				echo "Left and backwards"
                  				if sensors.gpIn[4].value=0 ; check for long move button press
                  					G1 X-20 U-20 A-20 Y20 V20 B20
                  				else
                  					G1 X-0.5 U-0.5 A-0.5 Y0.5 V0.5 B0.5
                  			
                  			else ; joystick left only
                  				M400
                  				echo "Left"
                  				if sensors.gpIn[4].value=0 ; check for long move button press
                  					G1 X-20 U-20 A-20
                  				else
                  					G1 X-0.5 U-0.5 A0.5
                  			
                  			
                  		elif sensors.gpIn[6].value=0; joystick right 	
                  		
                  			if sensors.gpIn[7].value=0 ; joystick right and forwards 
                  				M400
                  				echo "Right and forward"
                  				if sensors.gpIn[4].value=0 ; check for long move button press
                  					G1 X20 U20 A20 Y-20 V-20 B-20
                  				else
                  					G1 X0.5 U0.5 A0.5 Y-0.5 V-0.5 B-0.5
                  			
                  			elif sensors.gpIn[8].value=0; joystick right and backward	
                  				M400
                  				echo "Right and backwards"
                  				if sensors.gpIn[4].value=0 ; check for long move button press
                  					G1 X20 U20 A20 Y20 V20 B20
                  				else
                  					G1 X0.5 U0.5 A0.5 Y0.5 V0.5 B0.5
                  			
                  			else ; joystick right only
                  				M400
                  				echo "Right"
                  				if sensors.gpIn[4].value=0 ; check for long move button press
                  					G1 X20 U20 A20 
                  				else
                  					G1 X0.5 U0.5 A0.5 
                  			
                  	
                  		elif sensors.gpIn[7].value=0 ; joystick forwards only	
                  			M400
                  			echo "Forward"
                  			if sensors.gpIn[4].value=0 ; check for long move button press
                  				G1 Y-20 V-20 B-20 
                  			else
                  				G1 Y-0.5 V-0.5 B-0.5 
                  		
                  		
                  		elif sensors.gpIn[8].value=0 ; joystick backward only
                  			M400
                  			echo "Backwards"
                  			if sensors.gpIn[4].value=0 ; check for long move button press
                  				G1 Y20 V20 B20 
                  			else
                  				G1 Y0.5 V0.5 B0.5 
                  		
                  		else break
                  	
                  else break
                  

                  Ian
                  https://somei3deas.wordpress.com/
                  https://www.youtube.com/@deckingman

                  appjawsundefined 1 Reply Last reply Reply Quote 2
                  • appjawsundefined
                    appjaws @deckingman
                    last edited by

                    @deckingman I have followed this with interest but then I thought what was the actual problem? When I use the XY buttons in DWC my main XY and UV carriages move together and in sync. Have I not understood the problem?

                    appjaws - Core XYUV Duet Ethernet Duex5
                    firmware 3.5.0-rc.4 Web Interface 3.5.0-rc.4
                    Ormerod 1-converted to laser engraver, Duet wifi
                    OpenSCAD version 2024.03.18
                    Simplify3D 5.1.2

                    deckingmanundefined 1 Reply Last reply Reply Quote 0
                    • deckingmanundefined
                      deckingman @appjaws
                      last edited by

                      @appjaws said in Yet more conditional gcode help required:

                      @deckingman I have followed this with interest but then I thought what was the actual problem? When I use the XY buttons in DWC my main XY and UV carriages move together and in sync. Have I not understood the problem?

                      Hiya. I've changed things around a bit so that I no longer combine the axes after homing. So the DWC buttons only work for individual axes. i.e. XY moves will only move the hot end - not the hot end and extruder gantry (as they used to do when the axes were combined)

                      The reason being that I've exploited the fact that, because the extruders are connected to the hot end via short Bowden tubes, that extruder gantry doesn't have to exactly follow the hot end gantry. It doesn't have to replicate every tiny move that the hot end does - it only has to follow it within an allowable tolerance. So if there are small features (say a hole or a cylinder) then I can "park" the extruder gantry in the centre of that feature and let it sit there while the hot end does all those short moves which make that feature. The same applies to other short zig-zag type moves where the extruder gantry sits still while the hot end does the short zig-zags.

                      I made a couple of YouTube videos which explain it in a bit more detail
                      https://www.youtube.com/watch?v=rOP9QYAlhZU
                      and
                      https://www.youtube.com/watch?v=mTPV3Ss1D-4

                      So that's the reason why the axis button on DWC are no longer much use to me. A fuller explanation of what I wanted the joystick to do, and how that works in practice is here
                      https://www.youtube.com/watch?v=wCR5Ao0iH-c

                      Ian
                      https://somei3deas.wordpress.com/
                      https://www.youtube.com/@deckingman

                      1 Reply Last reply Reply Quote 0
                      • appjawsundefined
                        appjaws
                        last edited by

                        Hi again,
                        Very impressive videos @deckingman . Is it possible to have a copy of your python script that generates the movement please.
                        My machine really vibrates during short movements so your solution should solve it for me.

                        appjaws - Core XYUV Duet Ethernet Duex5
                        firmware 3.5.0-rc.4 Web Interface 3.5.0-rc.4
                        Ormerod 1-converted to laser engraver, Duet wifi
                        OpenSCAD version 2024.03.18
                        Simplify3D 5.1.2

                        deckingmanundefined 1 Reply Last reply Reply Quote 0
                        • deckingmanundefined
                          deckingman @appjaws
                          last edited by

                          @appjaws Sure. It's been a few years since we last communicated. Is your email address still the one ending ......ve.co.uk? If not, pm me with the address to use.

                          Be aware, that it's quite a lot of work to run the machine in "true" CoreXYUV mode. You need to change all you homing files so that they do not re-combine the axes, and change the "P" parameter in M581 so that the 5 axes are visible. Also any macros or gcode start and end scripts that have XY moves will need to be changed to incorporate XYUV moves.

                          Also be aware that, although the python code gets the job done, I'm not a writer of code, so it ain't pretty.

                          Ian
                          https://somei3deas.wordpress.com/
                          https://www.youtube.com/@deckingman

                          1 Reply Last reply Reply Quote 0
                          • appjawsundefined
                            appjaws
                            last edited by

                            @deckingman Yes same email address.
                            I was wondering if I could just change the XYUV to be individual just during a print similar to the way homeall.g works.
                            M584 X0 U3 Y1 V4 Z7:8:9 E2:5:6 P5 ; temporarily separate and map drives to U and V axes

                            complete the modified gcode part file using separate XYUV axes

                            M584 X0:3 Y1:4 Z7:8:9 U10 V11 E2:5:6 P3 ; put motor mapping back to normal so that X uses drives 0 and 3 Y uses 1 and 4

                            then once the printed part is removed from the bed run homeall.g

                            can you see any problems with this?

                            Thanks for your help

                            appjaws - Core XYUV Duet Ethernet Duex5
                            firmware 3.5.0-rc.4 Web Interface 3.5.0-rc.4
                            Ormerod 1-converted to laser engraver, Duet wifi
                            OpenSCAD version 2024.03.18
                            Simplify3D 5.1.2

                            deckingmanundefined 2 Replies Last reply Reply Quote 0
                            • deckingmanundefined
                              deckingman @appjaws
                              last edited by

                              @appjaws said in Yet more conditional gcode help required:

                              @deckingman Yes same email address.
                              I was wondering if I could just change the XYUV to be individual just during a print similar to the way homeall.g works.
                              M584 X0 U3 Y1 V4 Z7:8:9 E2:5:6 P5 ; temporarily separate and map drives to U and V axes

                              complete the modified gcode part file using separate XYUV axes

                              M584 X0:3 Y1:4 Z7:8:9 U10 V11 E2:5:6 P3 ; put motor mapping back to normal so that X uses drives 0 and 3 Y uses 1 and 4

                              then once the printed part is removed from the bed run homeall.g

                              can you see any problems with this?

                              Thanks for your help

                              I can't think of a reason why that wouldn't work. That is to say, it'll allow you to use the DWC buttons to jog all the axes in sync before and after a print, and also run any macros that aren't run during a print.

                              What I mean by that, is that I use macros to wipe and purge the nozzle, and these macros are called by the slicer gcode as part of the start and end scripts. As the axes are separated before the print starts, then these particular macros have to be modified. But of course, if you don't call any macros from the slicer gcode file that have G1 moves, then you won't need to worry about it.

                              Ian
                              https://somei3deas.wordpress.com/
                              https://www.youtube.com/@deckingman

                              1 Reply Last reply Reply Quote 0
                              • deckingmanundefined
                                deckingman @appjaws
                                last edited by

                                @appjaws Email sent....

                                Ian
                                https://somei3deas.wordpress.com/
                                https://www.youtube.com/@deckingman

                                1 Reply Last reply Reply Quote 0
                                • appjawsundefined
                                  appjaws
                                  last edited by

                                  @deckingman This is my simplify3D start and end scripts

                                  Starting script
                                  M98 P"0:/macros/extra/Set LED Red"
                                  if !move.axes[0].homed || !move.axes[1].homed
                                  G28
                                  G28 Z
                                  ;M98 P"0:/macros/Conditional/Auto_Bed_Levelling"
                                  M98 P"0:/macros/Auto Nozzle Cleaning"
                                  M98 P"0:/macros/Move to Print Position"
                                  M98 P"0:/macros/extra/Set LED Blue"
                                  M98 P"0:/macros/MapDrivesXYUV"
                                  T0

                                  Ending script
                                  M98 P"0:/macros/End of Print"
                                  M98 P"0:/macros/CombineDrivest"
                                  M291 P"Print Completed " ; Display message

                                  These are untouched by the the generator
                                  Will be running the whole system later today, have sent you an email, requesting some advice.

                                  Paul

                                  appjaws - Core XYUV Duet Ethernet Duex5
                                  firmware 3.5.0-rc.4 Web Interface 3.5.0-rc.4
                                  Ormerod 1-converted to laser engraver, Duet wifi
                                  OpenSCAD version 2024.03.18
                                  Simplify3D 5.1.2

                                  deckingmanundefined 1 Reply Last reply Reply Quote 0
                                  • deckingmanundefined
                                    deckingman @appjaws
                                    last edited by

                                    @appjaws Yup, the script only adds UV (and AB) moves to existing gcode files. It doesn't modify any macro which might be called by the slicer start or end codes. But it looks like you are keeping the axes mapped to XY to do the other stuff, then mapping them to XYUV just before the print starts - so that ought to work I would have thought (make sue that you use an M400 at the start of your "MapDrivesXYUV" macro to ensure any moves are completed first).

                                    I've replied to your email.

                                    Ian

                                    Ian
                                    https://somei3deas.wordpress.com/
                                    https://www.youtube.com/@deckingman

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