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

    Feature Request - workpiece angle compensation CNC

    Scheduled Pinned Locked Moved
    Firmware wishlist
    11
    54
    2.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.
    • CanDo415undefined
      CanDo415 @Exerqtor
      last edited by

      @Exerqtor
      like:

      If var.y_2>var.y_3																; workpiece Zero coordinates
      set var.x_5=var.x_4+(COS(ARCTAN(var.m_1))+COS(ARCTAN(var.m_2)))*var.d_probe/2
      set var.y_5=var.y_4+(SIN(ARCTAN(var.m_1))+SIN(ARCTAN(var.m_2)))*var.d_probe/2
      end if
      
      If var.y_2<var.y_3
      set var.x_5=var.x_4+(COS(ARCTAN(var.m_1))-COS(ARCTAN(var.m_2)))*var.d_probe/2
      set var.y_5=var.y_4+(SIN(ARCTAN(var.m_1))-SIN(ARCTAN(var.m_2)))*var.d_probe/2
      end if
      

      ?

      Exerqtorundefined dc42undefined 2 Replies Last reply Reply Quote 0
      • Exerqtorundefined
        Exerqtor @CanDo415
        last edited by Exerqtor

        @CanDo415
        No like:

        if var.y_2 > var.y_3																; workpiece Zero coordinates
          set var.x_5 = var.x_4 + (COS(ARCTAN(var.m_1)) + COS(ARCTAN(var.m_2))) * var.d_probe / 2
          set var.y_5 = var.y_4 + (SIN(ARCTAN(var.m_1)) + SIN(ARCTAN(var.m_2))) * var.d_probe / 2
        
        if var.y_2 < var.y_3
          set var.x_5 = var.x_4 + (COS(ARCTAN(var.m_1)) - COS(ARCTAN(var.m_2))) * var.d_probe / 2
          set var.y_5 = var.y_4 + (SIN(ARCTAN(var.m_1)) - SIN(ARCTAN(var.m_2))) * var.d_probe / 2
        
        CanDo415undefined 1 Reply Last reply Reply Quote 0
        • CanDo415undefined
          CanDo415 @Exerqtor
          last edited by

          @Exerqtor
          i tried this before in another case... everything unter the 2nd if wasnt done if the if doesn't match.
          the problem of the missing end if

          Exerqtorundefined jay_s_ukundefined 2 Replies Last reply Reply Quote 0
          • Exerqtorundefined
            Exerqtor @CanDo415
            last edited by Exerqtor

            @CanDo415
            Then you simply must have done something wrong in the other case you're mentioning.

            As reference to conditional construct have look at this.

            1 Reply Last reply Reply Quote 0
            • jay_s_ukundefined
              jay_s_uk @CanDo415
              last edited by

              @CanDo415 as @Exerqtor said, there's no end if.
              Things have to be indented to be part of the if

              Owns various duet boards and is the main wiki maintainer for the Teamgloomy LPC/STM32 port of RRF. Assume I'm running whatever the latest beta/stable build is

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

                @CanDo415 you also need to replace SIN by sin, COS by cos, ARCTAN by atan etc. See https://docs.duet3d.com/User_manual/Reference/Gcode_meta_commands#functions.

                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

                CanDo415undefined 1 Reply Last reply Reply Quote 1
                • CanDo415undefined
                  CanDo415 @dc42
                  last edited by

                  @dc42
                  thanks so far.
                  Error promt is:
                  M292 S3
                  Error: Bad command: If (var.y_2) >= (var.y_3)
                  Error: in file macro line 179 column 8: meta command: expected "'"

                  Makro:

                  G68 A0 B0 R0
                  var y_1 = 0
                  var x_1 = 0
                  var x_2 = 0
                  var x_3 = 0
                  var x_4 = 0
                  var x_5 = 0
                  var delta_x = 0
                  var y_2 = 0
                  var y_3 = 0
                  var y_4 = 0
                  var y_5 = 0
                  var delta_y = 0
                  var z0 = 0
                  var d_probe = 0
                  var z_probe = 0
                  var m_1 = 0
                  var m_2 = 0
                  var m_1_rads = 0
                  var m_1_deg = 0
                  var buff1 = 0
                  var buff2 = 0
                  var buff3 = 0
                  var speed = 1500
                  
                  M291 P"probe Diameter" R"enter diameter of probe" S5 							; Pop up box asking for operator input diameter of 
                  set var.d_probe = input															; set the diameter of the probe
                  M291 P"probe size in z" R"enter z-size of probe" S5 							; Pop up box asking for operator input diameter of 
                  set var.z_probe = input															; set the size of the probe in z-direction (mostly same as diameter, for plate probes 0)
                  M291 P"position probe over front left corner of workpiece" S2 X1 Y1 Z1			; Pop up box asking for operator input
                  
                  M558 F{var.speed/5}																; Set the initial movement speed
                  G38.2 Z-10 P0 K0																; Probe the material on top
                  M558 F50																		; Set the final probing speed
                  G38.4 Z50 P0 K0																	; Move away from workpiece in Z
                  M400																			; Make sure all movement is complete
                  set var.z0 = move.axes[2].machinePosition										; Record the stop position z_first_measurement
                  M400																			; Make sure all data recording is complete
                  
                  G1 Z{move.axes[2].machinePosition+5}											; Lift probe 5mm
                  G1 X{move.axes[0].machinePosition-20} Y{move.axes[1].machinePosition+5}			; Move 20mm to the left of the initial point and 5mm deeper into the material direction
                  G1 Z{var.z0 - 1 - var.z_probe / 2}												; Move to probe depth
                  
                  M558 F{var.speed}																; Set the initial movement speed
                  G38.2 X1000 P0 K0																; Probe the material as a first pass
                  M558 F50																		; Set the final probing speed
                  G38.4 X-10 P0 K0																; Move away from workpiece in X
                  M400																			; Make sure all movement is complete
                  set var.y_1 = move.axes[1].machinePosition										; Record the stop position y_first_measurement
                  set var.x_1 = move.axes[0].machinePosition										; Record the stop position x_first_measurement
                  M400																			; Make sure all data recording is complete
                  
                  G1 X{move.axes[0].machinePosition-5}											; Move 5mm away from the material
                  G1 Z{var.z0+5}																	; Move 5mm above material
                  G1 X{move.axes[0].machinePosition+15} Y{move.axes[1].machinePosition-20}		; Move to point 2
                  G1 Z{var.z0 - 1 - var.z_probe / 2}												; Move to probe depth
                  
                  M558 F{var.speed}																; Set the initial movement speed
                  G38.2 Y1000 P0 K0																; Probe the material as a first pass
                  M558 F50																		; Set the final probing speed
                  G38.4 Y-10 P0 K0																; Probe the material again
                  M400																			; Make sure all movement is complete
                  set var.y_2 = move.axes[1].machinePosition										; Record the stop position y_second_measurement
                  set var.x_2 = move.axes[0].machinePosition										; Record the stop position x_second_measurement
                  M400																			; Make sure all data recording is complete
                  
                  G1 Y{move.axes[1].machinePosition-20}											; Move 10mm away from the material
                  G1 X{move.axes[0].machinePosition+50}											; Move 50mm along the workpiece in X
                  
                  M558 F{var.speed}																; Set the initial movement speed
                  G38.2 Y1000 P0 K0																; Probe the material as a first pass
                  M558 F50																		; Set the final probing speed
                  G38.4 Y-10 P0 K0																; Probe the material again
                  M400																			; Make sure all movement is complete
                  set var.y_3 = move.axes[1].machinePosition										; Record the stop position y_third_measurement
                  set var.x_3 = move.axes[0].machinePosition										; Record the stop position x_third_measurement
                  M400																			; Make sure all data recording is complete
                  
                  ;calculation
                  set var.delta_y = {var.y_3-var.y_2}
                  set var.delta_x = {var.x_3-var.x_2}
                  set var.m_1 = {var.delta_y/var.delta_x}											; m of the staight P2-P3
                  set var.m_2 = {(-var.delta_x)/var.delta_y}										; m of perpendicilar to straight P2-P3
                  set var.m_1_rads = atan(var.m_1)												; workpiece rotation in rad
                  set var.m_1_deg = degrees(var.m_1_rads)											; workpiece rotation in degrees
                  
                  ;calc the corner of workpiece
                  ;set var.x_4 = {((var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1)-(var.y_2-((var.y_3-var.y_2)/(var.x_3-var.x_2)*var.x_2)))/(((var.y_3-var.y_2)/(var.x_3-var.x_2))-(-(var.x_3-var.x_2)/(var.y_3-var.y_2)))}
                  ;set var.y_4 = {(-(var.x_3-var.x_2)/(var.y_3-var.y_2))<>*((var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1)-(var.y_2-((var.y_3-var.y_2)/(var.x_3-var.x_2)*var.x_2)))<>/(((var.y_3-var.y_2)/(var.x_3-var.x_2))-(-(var.x_3-var.x_2)/(var.y_3-var.y_2)))+(var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1)}
                  
                  
                  set var.buff1 = {var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1}
                  set var.buff2 = {var.y_2-((var.y_3-var.y_2)/(var.x_3-var.x_2)*var.x_2)}
                  set var.buff3 = {((var.y_3-var.y_2)/(var.x_3-var.x_2))-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))}
                  set var.x_4 = {(var.buff1-var.buff2)/var.buff3}
                  set var.buff1 = {(-(var.x_3-var.x_2)/(var.y_3-var.y_2))}
                  set var.buff2 = {((var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1)-(var.y_2-((var.y_3-var.y_2)/(var.x_3-var.x_2)*var.x_2)))}
                  set var.buff3 = {(((var.y_3-var.y_2)/(var.x_3-var.x_2))-(-(var.x_3-var.x_2)/(var.y_3-var.y_2)))+(var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1)}
                  set var.y_4 = {var.buff1*var.buff2/var.buff3}
                  
                  If (var.y_2) >= (var.y_3)																; workpiece Zero coordinates
                  set var.x_5 = {var.x_4+(cos(atan(var.m_1))+cos(atan(var.m_2)))*var.d_probe/2}
                  set var.y_5 = {var.y_4+(sin(atan(var.m_1))+sin(atan(var.m_2)))*var.d_probe/2}
                  echo 'X= '{var.x_5}', Y= '{var.y_5}
                  If (var.y_2) < (var.y_3)
                  set var.x_5 = {var.x_4+(cos(atan(var.m_1))-cos(atan(var.m_2)))*var.d_probe/2}
                  set var.y_5 = {var.y_4+(sin(atan(var.m_1))-sin(atan(var.m_2)))*var.d_probe/2}
                  ;echo X= {var.x_5}, Y= {var.y_5}
                  
                  ;move above workpiece zero and set tool x&y to 0
                  M558 F{var.speed}																; Set the initial movement speed
                  G1 Y{move.axes[1].machinePosition-1}											; Move 1mm away from the material
                  G1 Z{var.z0 + 5}																; Move above workpiece
                  G1 X{var.x_5} Y{var.y_5}														; go to Zero
                  G10 X0 Y0																		; set x&y to Zero
                  G68 A0 B0 R{-var.m_1_deg}														; set Rotation
                  

                  X seems to be working, on a psitive angle.
                  Y is getting some wrong outputs

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

                    @CanDo415 replace all If by if.

                    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

                    CanDo415undefined 1 Reply Last reply Reply Quote 1
                    • CanDo415undefined
                      CanDo415 @dc42
                      last edited by

                      @dc42
                      i don't know why. sometimes it works. sometimes it fails.
                      getting Error: line 89 column 20: meta command: unknown value 'atan'
                      i have no idea.
                      the calculation seems to be correct. but using G10 moves the tool right down to Y=0

                      G68 A0 B0 R0
                      var y_1 = 0
                      var x_1 = 0
                      var x_2 = 0
                      var x_3 = 0
                      var x_4 = 0
                      var x_5 = 0
                      var delta_x = 0
                      var y_2 = 0
                      var y_3 = 0
                      var y_4 = 0
                      var y_5 = 0
                      var delta_y = 0
                      var z0 = 0
                      var d_probe = 0
                      var z_probe = 0
                      var m_1 = 0
                      var m_2 = 0
                      var m_1_rads = 0
                      var m_1_deg = 0
                      var m_2_rads = 0
                      var m_2_deg = 0
                      var buff1 = 0
                      var buff2 = 0
                      var buff3 = 0
                      var speed = 1500
                      
                      M291 P"probe Diameter" R"enter diameter of probe" S5 							; Pop up box asking for operator input diameter of 
                      set var.d_probe = input															; set the diameter of the probe
                      M291 P"probe size in z" R"enter z-size of probe" S5 							; Pop up box asking for operator input diameter of 
                      set var.z_probe = input															; set the size of the probe in z-direction (mostly same as diameter, for plate probes 0)
                      M291 P"position probe over front left corner of workpiece" S2 X1 Y1 Z1			; Pop up box asking for operator input
                      
                      M558 F{var.speed/5}																; Set the initial movement speed
                      G38.2 Z-10 P0 K0																; Probe the material on top
                      M558 F50																		; Set the final probing speed
                      G38.4 Z50 P0 K0																	; Move away from workpiece in Z
                      M400																			; Make sure all movement is complete
                      set var.z0 = move.axes[2].machinePosition										; Record the stop position z_first_measurement
                      M400																			; Make sure all data recording is complete
                      
                      G1 Z{move.axes[2].machinePosition+5}											; Lift probe 5mm
                      G1 X{move.axes[0].machinePosition-20} Y{move.axes[1].machinePosition+5}			; Move 20mm to the left of the initial point and 5mm deeper into the material direction
                      G1 Z{var.z0 - 1 - var.z_probe / 2}												; Move to probe depth
                      
                      M558 F{var.speed}																; Set the initial movement speed
                      G38.2 X1000 P0 K0																; Probe the material as a first pass
                      M558 F50																		; Set the final probing speed
                      G38.4 X-10 P0 K0																; Move away from workpiece in X
                      M400																			; Make sure all movement is complete
                      set var.y_1 = move.axes[1].machinePosition										; Record the stop position y_first_measurement
                      set var.x_1 = move.axes[0].machinePosition										; Record the stop position x_first_measurement
                      M400																			; Make sure all data recording is complete
                      
                      G1 X{move.axes[0].machinePosition-5}											; Move 5mm away from the material
                      G1 Z{var.z0+5}																	; Move 5mm above material
                      G1 X{move.axes[0].machinePosition+15} Y{move.axes[1].machinePosition-20}		; Move to point 2
                      G1 Z{var.z0 - 1 - var.z_probe / 2}												; Move to probe depth
                      
                      M558 F{var.speed}																; Set the initial movement speed
                      G38.2 Y1000 P0 K0																; Probe the material as a first pass
                      M558 F50																		; Set the final probing speed
                      G38.4 Y-10 P0 K0																; Probe the material again
                      M400																			; Make sure all movement is complete
                      set var.y_2 = move.axes[1].machinePosition										; Record the stop position y_second_measurement
                      set var.x_2 = move.axes[0].machinePosition										; Record the stop position x_second_measurement
                      M400																			; Make sure all data recording is complete
                      
                      G1 Y{move.axes[1].machinePosition-20}											; Move 10mm away from the material
                      G1 X{move.axes[0].machinePosition+50}											; Move 50mm along the workpiece in X
                      
                      M558 F{var.speed}																; Set the initial movement speed
                      G38.2 Y1000 P0 K0																; Probe the material as a first pass
                      M558 F50																		; Set the final probing speed
                      G38.4 Y-10 P0 K0																; Probe the material again
                      M400																			; Make sure all movement is complete
                      set var.y_3 = move.axes[1].machinePosition										; Record the stop position y_third_measurement
                      set var.x_3 = move.axes[0].machinePosition										; Record the stop position x_third_measurement
                      M400																			; Make sure all data recording is complete
                      
                      ;calculation
                      set var.delta_y = {var.y_3-var.y_2}
                      set var.delta_x = {var.x_3-var.x_2}
                      set var.m_1 = {var.delta_y/var.delta_x}											; m of the staight P2-P3
                      set var.m_2 = {-(var.delta_x/var.delta_y)}										; m of perpendicilar to straight P2-P3
                      set var.m_1_rads = atan(var.m_1)												; workpiece rotation in rad
                      set var.m_1_deg = degrees(var.m_1_rads)											; workpiece rotation in degrees
                      set var.m_2_rads = atan(var.m_2)												; workpiece rotation in rad
                      set var.m_2_deg = degrees(var.m_2_rads)											; workpiece rotation in degrees
                      
                      ;calc the corner of workpiece
                      ;set var.x_4 = {((var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1)-(var.y_2-((var.y_3-var.y_2)/(var.x_3-var.x_2)*var.x_2)))/(((var.y_3-var.y_2)/(var.x_3-var.x_2))-(-(var.x_3-var.x_2)/(var.y_3-var.y_2)))}
                      ;set var.y_4 = {(-(var.x_3-var.x_2)/(var.y_3-var.y_2))<>*((var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1)-(var.y_2-((var.y_3-var.y_2)/(var.x_3-var.x_2)*var.x_2)))<>/(((var.y_3-var.y_2)/(var.x_3-var.x_2))-(-(var.x_3-var.x_2)/(var.y_3-var.y_2)))+(var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1)}
                      
                      
                      set var.buff1 = {var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1}
                      set var.buff2 = {var.y_2-((var.y_3-var.y_2)/(var.x_3-var.x_2)*var.x_2)}
                      set var.buff3 = {((var.y_3-var.y_2)/(var.x_3-var.x_2))-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))}
                      set var.x_4 = {(var.buff1-var.buff2)/var.buff3}
                      set var.buff1 = {(-(var.x_3-var.x_2)/(var.y_3-var.y_2))}
                      set var.buff2 = {((var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1)-(var.y_2-((var.y_3-var.y_2)/(var.x_3-var.x_2)*var.x_2)))}
                      set var.buff3 = {(((var.y_3-var.y_2)/(var.x_3-var.x_2))-(-(var.x_3-var.x_2)/(var.y_3-var.y_2)))+(var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1)}
                      set var.y_4 = {var.buff1*var.buff2/var.buff3}
                      
                      var a = 0
                      set var.a= {var.y_3-var.y_2}
                      ;if var.a >= 0														            	; workpiece Zero coordinates
                      set var.x_5 = {var.x_4+(cos(var.m_1_deg)+cos(var.m_2_deg))*var.d_probe/2}
                      set var.y_5 = {var.y_4+(sin(var.m_1_deg)+sin(var.m_2_deg))*var.d_probe/2}
                      ;echo 'X= '{var.x_5}', Y= '{var.y_5}
                      ;if var.a < 0
                      ;set var.x_5 = {var.x_4+(cos(atan(var.m_1))-cos(atan(var.m_2)))*var.d_probe/2}
                      ;set var.y_5 = {var.y_4+(sin(atan(var.m_1))-sin(atan(var.m_2)))*var.d_probe/2}
                      ;echo X= {var.x_5}, Y= {var.y_5}
                      
                      ;move above workpiece zero and set tool x&y to 0
                      M558 F{var.speed}																; Set the initial movement speed
                      G1 Y{move.axes[1].machinePosition-1}											; Move 1mm away from the material
                      G1 Z{var.z0 + 5}																; Move above workpiece
                      G1 X{var.x_5} 
                      G1 Y{var.y_5}														            ; go to Zero
                      ;G10 L20 X0 Y0																	; set x&y to Zero
                      ;G68 A0 B0 R{-var.m_1_deg}														; set Rotation
                      
                      infiniteloopundefined 1 Reply Last reply Reply Quote 0
                      • infiniteloopundefined
                        infiniteloop @CanDo415
                        last edited by infiniteloop

                        @CanDo415

                        getting Error: line 89 column 20: meta command: unknown value 'atan'

                        @Exerqtor already pointed you at the proper doc - better read it completely. In the section Expressions, it says:

                        … when RepRapFirmware is running in CNC mode, any use of ( ) to enclose a subexpression or function parameter list must be within an expression enclosed in { }

                        Within your macro, you apply the curly braces inconsistently, Instead of

                        set var.m_1_rads = atan(var.m_1) ;  may not work in CNC mode, (var.m_1) is regarded as a comment
                        

                        write

                        set var.m_1_rads = {atan(var.m_1)}
                        

                        Same is true for other function calls like degrees().

                        In general, if writing macros, you should study the GCode meta commands completely and in-depth.

                        CanDo415undefined 1 Reply Last reply Reply Quote 1
                        • CanDo415undefined
                          CanDo415 @infiniteloop
                          last edited by CanDo415

                          thank you all. finally it works as inteded.

                          G68 A0 B0 R0
                          G10 L20 X{move.axes[0].machinePosition} Y{move.axes[1].machinePosition} Z{move.axes[2].machinePosition}
                          var y_1 = 0
                          var x_1 = 0
                          var x_2 = 0
                          var x_3 = 0
                          var x_4 = 0
                          var x_5 = 0
                          var delta_x = 0
                          var y_2 = 0
                          var y_3 = 0
                          var y_4 = 0
                          var y_5 = 0
                          var delta_y = 0
                          var z0 = 0
                          var d_probe = 0
                          var z_probe = 0
                          var m_1 = 0
                          var m_2 = 0
                          var m_1_rads = 0
                          var m_1_deg = 0
                          var m_2_rads = 0
                          var m_2_deg = 0
                          var buff1 = 0
                          var buff2 = 0
                          var buff3 = 0
                          var buff4 = 0
                          var speed = 1500
                          
                          M291 P"probe Diameter" R"enter diameter of probe" S5 							                ; Pop up box asking for operator input diameter of 
                          set var.d_probe = input														                	; set the diameter of the probe
                          M291 P"probe size in z" R"enter z-size of probe" S5 				            		    	; Pop up box asking for operator input diameter of 
                          set var.z_probe = input														                	; set the size of the probe in z-direction (mostly same as diameter, for plate probes 0)
                          M291 P"position probe over front left corner of workpiece" S2 X1 Y1 Z1		                	; Pop up box asking for operator input
                           
                          M558 F{var.speed/5}														    	            	; Set the initial movement speed
                          G38.2 Z-10 P0 K0													                   			; Probe the material on top
                          M558 F50														    		            		; Set the final probing speed
                          G38.4 Z50 P0 K0												                					; Move away from workpiece in Z
                          M400												            	    						; Make sure all movement is complete
                          set var.z0 = move.axes[2].machinePosition           										    ; Record the stop position z_first_measurement
                          M400																            		    	; Make sure all data recording is complete
                           
                          G1 Z{move.axes[2].machinePosition+5}					            				    		; Lift probe 5mm
                          G1 X{move.axes[0].machinePosition-20-var.d_probe/2} Y{move.axes[1].machinePosition+5}           	; Move 20mm to the left of the initial point and 5mm deeper into the material direction
                          G1 Z{var.z0 - 1 - var.z_probe / 2}			            									    ; Move to probe depth
                           
                          M558 F{var.speed}				            							    					; Set the initial movement speed
                          G38.2 X1000 P0 K0	            										    					; Probe the material as a first pass
                          M558 F50													    				            	; Set the final probing speed
                          G38.4 X-10 P0 K0												                				; Move away from workpiece in X
                          M400													            			    			; Make sure all movement is complete
                          set var.y_1 = move.axes[1].machinePosition	            							    		; Record the stop position y_first_measurement
                          set var.x_1 = move.axes[0].machinePosition									                	; Record the stop position x_first_measurement
                          M400																	            		    ; Make sure all data recording is complete
                           
                          G1 X{move.axes[0].machinePosition-5}					            						            ; Move 5mm away from the material
                          G1 Z{var.z0+5}									        			    				        	    ; Move 5mm above material
                          G1 X{move.axes[0].machinePosition+15+var.d_probe/2} Y{move.axes[1].machinePosition-20-var.d_probe/2}	; Move to point 2
                          G1 Z{var.z0 - 1 - var.z_probe / 2}	            											            ; Move to probe depth
                           
                          M558 F{var.speed}           															    	; Set the initial movement speed
                          G38.2 Y1000 P0 K0			            													    ; Probe the material as a first pass
                          M558 F50								            										    ; Set the final probing speed
                          G38.4 Y-10 P0 K0									            							    ; Probe the material again
                          M400											    			            					; Make sure all movement is complete
                          set var.y_2 = move.axes[1].machinePosition			    					            		; Record the stop position y_second_measurement
                          set var.x_2 = move.axes[0].machinePosition	            			    						; Record the stop position x_second_measurement
                          M400													            	    					; Make sure all data recording is complete
                           
                          G1 Y{move.axes[1].machinePosition-20}							                				; Move 10mm away from the material
                          G1 X{move.axes[0].machinePosition+50}								    		            	; Move 50mm along the workpiece in X
                          
                          M558 F{var.speed}           		    														; Set the initial movement speed
                          G38.2 Y1000 P0 K0			                													; Probe the material as a first pass
                          M558 F50						    	            											; Set the final probing speed
                          G38.4 Y-10 P0 K0					    			            								; Probe the material again
                          M400									    					            					; Make sure all movement is complete
                          set var.y_3 = move.axes[1].machinePosition	    							            		; Record the stop position y_third_measurement
                          set var.x_3 = move.axes[0].machinePosition          		    								; Record the stop position x_third_measurement
                          M400												                							; Make sure all data recording is complete
                           
                          ;calculation
                          set var.delta_y = {var.y_3-var.y_2}
                          set var.delta_x = {var.x_3-var.x_2}
                          set var.m_1 = {var.delta_y/var.delta_x}					    	            					; m of the staight P2-P3
                          set var.m_2 = {-(var.delta_x/var.delta_y)}					    			            		; m of perpendicilar to straight P2-P3
                          set var.m_1_rads = {atan(var.m_1)}								    	            			; workpiece rotation in rad
                          set var.m_1_deg = {degrees(var.m_1_rads)}	            										; workpiece rotation in degrees
                          set var.m_2_rads = {atan(var.m_2)}						            			    			; workpiece rotation in rad
                          set var.m_2_deg = {degrees(var.m_2_rads)}							            				; workpiece rotation in degrees
                          
                          ;calc the corner of workpiece
                          set var.buff1 = {var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1}
                          set var.buff2 = {var.y_2-((var.y_3-var.y_2)/(var.x_3-var.x_2)*var.x_2)}
                          set var.buff3 = {((var.y_3-var.y_2)/(var.x_3-var.x_2))-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))}
                          set var.x_4 = {(var.buff1-var.buff2)/var.buff3}
                          set var.buff1 = {(-(var.x_3-var.x_2)/(var.y_3-var.y_2))}
                          set var.buff2 = {((var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1)-(var.y_2-((var.y_3-var.y_2)/(var.x_3-var.x_2)*var.x_2)))}
                          set var.buff3 = {(((var.y_3-var.y_2)/(var.x_3-var.x_2))-(-(var.x_3-var.x_2)/(var.y_3-var.y_2)))}
                          set var.buff4 = {(var.y_1-(-(var.x_3-var.x_2)/(var.y_3-var.y_2))*var.x_1)}
                          set var.y_4 = {var.buff1*var.buff2/var.buff3+var.buff4}
                          var a = 0
                          set var.a= {var.y_3-var.y_2}
                          if var.a < 0														            	            ; workpiece Zero coordinates
                              set var.x_5 = {var.x_4+(cos(atan(var.m_1))+cos(atan(var.m_2)))*var.d_probe/2}
                              set var.y_5 = {var.y_4+(sin(atan(var.m_1))+sin(atan(var.m_2)))*var.d_probe/2}
                          if var.a > 0
                              set var.x_5 = {var.x_4+(cos(atan(var.m_1))-cos(atan(var.m_2)))*var.d_probe/2}
                              set var.y_5 = {var.y_4+(sin(atan(var.m_1))-sin(atan(var.m_2)))*var.d_probe/2}
                          if var.a =0
                              set var.x_5 = {var.x_1+var.d_probe/2}
                              set var.y_5 = {var.y_2+var.d_probe/2}
                          echo "ZERO X = ", var.x_5," ; Y = ", var.y_5
                          
                          ;move above workpiece zero and set tool x&y to 0
                          M558 F{var.speed}							    									            ; Set the initial movement speed
                          G1 Y{move.axes[1].machinePosition-1}			    					            			; Move 1mm away from the material
                          G1 Z{var.z0 + 5}									    	            						; Move above workpiece
                          G1 X{var.x_5} Y{var.y_5}						            		    						; go to Zero
                          M400
                          G10 L20 X0 Y0						            						    					; set x&y to Zero
                          G68 A0 B0 R{-var.m_1_deg}										    			            	; set Rotation
                          
                          dc42undefined 1 Reply Last reply Reply Quote 0
                          • dc42undefined
                            dc42 administrators @CanDo415
                            last edited by dc42

                            @CanDo415 the reason is that standard CNC GCode uses ( and ) to enclose comments, which is an unfortunate choice. In order to be compatible with this, RRF does the same when in CNC mode unless the ( ) are themselves inside { }.

                            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

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