├── readme.md ├── xy.nc └── xyz.nc /readme.md: -------------------------------------------------------------------------------- 1 | # cncjs-macros 2 | 3 | Some CNCJS macros I used on my Shapeoko 3, but I suppose they could work elsewhere too! 4 | 5 | - [xyz.nc](./xyz.nc) This is designed for a touch plate which has a hole centered on XY position you wish to find and will also use the probe surface to find the depth. It includes a "tool change" pause to allow you to remove the probe and then will move back to 0,0,0 (ie: the corner of your workpiece.) It is designed to be used on the lower left WCS of your workpiece. 6 | - [xy.nc](./xy.nc) Same as above, but reduced to just find the XY position. 7 | 8 | Here's [a video showing off what this does](https://youtu.be/YRHsWt38QY8). 9 | -------------------------------------------------------------------------------- /xy.nc: -------------------------------------------------------------------------------- 1 | 2 | ;Start with probe in hole, BELOW Z surface 3 | 4 | ; Wait until the planner queue is empty 5 | %wait 6 | 7 | ; Set user-defined variables 8 | %PROBE_DISTANCE = 100 9 | %PROBE_FEEDRATE_A = 150 10 | %PROBE_FEEDRATE_B = 50 11 | 12 | ; for restoration at the end 13 | %UNITS=modal.units 14 | %DISTANCE=modal.distance 15 | 16 | G91 ; Relative positioning 17 | G21 ; Use millimeters 18 | 19 | G10 L20 X0 Y0 ; set current position as xy zero for now 20 | 21 | ; Probe rear, slight right 22 | G38.2 X1 Y[PROBE_DISTANCE] F[PROBE_FEEDRATE_A] 23 | G1 Y-1 F[PROBE_FEEDRATE_B] ; back off a bit 24 | G38.2 Y3 F[PROBE_FEEDRATE_B] ; probe again, slowly 25 | G4 P1 ; wait for 1 second to ensure clear and accurate measure 26 | %p1x = posx ; set the x/y coords for later 27 | %p1y = posy 28 | 29 | ; set back to absolute mode and return to original spot 30 | G90 31 | G0 X0 Y0 32 | G91 33 | 34 | ; Probe 45deg 35 | G38.2 X[PROBE_DISTANCE] Y[PROBE_DISTANCE] F[PROBE_FEEDRATE_A] 36 | G1 X-1 Y-1 F[PROBE_FEEDRATE_B] ; back off a bit 37 | G38.2 X3 Y3 F[PROBE_FEEDRATE_B] ; probe again, slowly 38 | G4 P1 ; wait for 1 second to ensure clear and accurate measure 39 | %p2x = posx ; set the x/y coords for later 40 | %p2y = posy 41 | 42 | ; set back to absolute mode and return to original spot 43 | G90 44 | G0 X0 Y0 45 | G91 46 | 47 | ; Probe slight rear, far right 48 | G38.2 X[PROBE_DISTANCE] Y1 F[PROBE_FEEDRATE_A] 49 | G1 X-1 F[PROBE_FEEDRATE_B] ; back off a bit 50 | G38.2 X3 F[PROBE_FEEDRATE_B] ; probe again, slowly 51 | G4 P1 ; wait for 1 second to ensure clear and accurate measure 52 | %p3x = posx ; set the x/y coords for later 53 | %p3y = posy 54 | 55 | ; Figure out proper center https://stackoverflow.com/a/30106470 and set it 56 | %ma = (p2y - p1y) / (p2x - p1x) 57 | %mb = (p3y - p2y) / (p3x - p2x) 58 | %cx = (ma * mb * (p1y - p3y) + mb * (p1x + p2x) - ma * (p2x + p3x)) / (2 * (mb - ma)) 59 | %cy = (-1 / ma) * (cx - (p1x + p2x) * 0.5) + (p1y + p2y) * 0.5 60 | 61 | ; Return to origin, move to true center, wait, set zero 62 | G90 63 | G0 X0 Y0 64 | G91 65 | G0 X[cx] Y[cy] 66 | G4 P1 67 | G10 L20 X0 Y0 68 | 69 | [UNITS] [DISTANCE] ;restore unit and distance modal state 70 | -------------------------------------------------------------------------------- /xyz.nc: -------------------------------------------------------------------------------- 1 | 2 | ;Start with probe in hole, BELOW Z surface 3 | 4 | ; Wait until the planner queue is empty 5 | %wait 6 | 7 | ; Set user-defined variables 8 | %PROBE_DISTANCE = 20 9 | %PROBE_FEEDRATE_A = 150 10 | %PROBE_FEEDRATE_B = 50 11 | %HOLE_DEPTH = 15 12 | %PLATE_THICKNESS = 10 13 | 14 | ; for restoration at the end 15 | %UNITS=modal.units 16 | %DISTANCE=modal.distance 17 | 18 | G91 ; Relative positioning 19 | G21 ; Use millimeters 20 | 21 | G10 L20 X0 Y0 ; set current position as xy zero for now 22 | 23 | ; Probe rear, slight right 24 | G38.2 X1 Y[PROBE_DISTANCE] F[PROBE_FEEDRATE_A] 25 | G1 Y-1 F[PROBE_FEEDRATE_B] ; back off a bit 26 | G38.2 Y3 F[PROBE_FEEDRATE_B] ; probe again, slowly 27 | G4 P1 ; wait for 1 second to ensure clear and accurate measure 28 | %p1x = posx ; set the x/y coords for later 29 | %p1y = posy 30 | 31 | ; set back to absolute mode and return to original spot 32 | G90 33 | G0 X0 Y0 34 | G91 35 | 36 | ; Probe 45deg 37 | G38.2 X[PROBE_DISTANCE] Y[PROBE_DISTANCE] F[PROBE_FEEDRATE_A] 38 | G1 X-1 Y-1 F[PROBE_FEEDRATE_B] ; back off a bit 39 | G38.2 X3 Y3 F[PROBE_FEEDRATE_B] ; probe again, slowly 40 | G4 P1 ; wait for 1 second to ensure clear and accurate measure 41 | %p2x = posx ; set the x/y coords for later 42 | %p2y = posy 43 | 44 | ; set back to absolute mode and return to original spot 45 | G90 46 | G0 X0 Y0 47 | G91 48 | 49 | ; Probe slight rear, far right 50 | G38.2 X[PROBE_DISTANCE] Y1 F[PROBE_FEEDRATE_A] 51 | G1 X-1 F[PROBE_FEEDRATE_B] ; back off a bit 52 | G38.2 X3 F[PROBE_FEEDRATE_B] ; probe again, slowly 53 | G4 P1 ; wait for 1 second to ensure clear and accurate measure 54 | %p3x = posx ; set the x/y coords for later 55 | %p3y = posy 56 | 57 | ; Figure out proper center https://stackoverflow.com/a/30106470 and set it 58 | %ma = (p2y - p1y) / (p2x - p1x) 59 | %mb = (p3y - p2y) / (p3x - p2x) 60 | %cx = (ma * mb * (p1y - p3y) + mb * (p1x + p2x) - ma * (p2x + p3x)) / (2 * (mb - ma)) 61 | %cy = (-1 / ma) * (cx - (p1x + p2x) * 0.5) + (p1y + p2y) * 0.5 62 | 63 | ; Return to origin, move to true center, wait, set zero 64 | G90 65 | G0 X0 Y0 66 | G91 67 | G0 X[cx] Y[cy] 68 | G4 P1 69 | G10 L20 X0 Y0 70 | 71 | ; Move up over the top, up and right to get over metal, probe down twice (quick, then slow) to get z height 72 | G0 Z[HOLE_DEPTH] 73 | G0 X15 Y15 74 | G38.2 Z-25 F[PROBE_FEEDRATE_A] ;Fast Probe 75 | G1 Z1 F[PROBE_FEEDRATE_B] 76 | G38.2 Z-5 F[PROBE_FEEDRATE_B] ;Slow Probe 77 | G10 L20 P1 Z[PLATE_THICKNESS] 78 | 79 | ; Move back up and over to the XY 80 | G0 Z5 81 | M6 ; Remove the probe 82 | ; Rapid back to zero for validation 83 | G90 ; absolute positioning 84 | G0 X0 Y0 85 | G0 Z0 86 | 87 | [UNITS] [DISTANCE] ;restore unit and distance modal state 88 | --------------------------------------------------------------------------------