Last modified by writer on 2024/07/11 12:09

Hide last authors
Edgar Allan Poe 9.1 1 For certain tasks (for example, PCB milling) it becomes necessary to scan the surface with subsequent correction of unevenness in Z.
abolgov 3.1 2
Edgar Allan Poe 9.1 3 A height map is prepared using a macro (show example below) and the G-code is modified based on this height map.
writer 7.1 4
Edgar Allan Poe 9.1 5 You can generate a G-code with new coordinates, for example, in the G-Code Ripper program.
writer 7.1 6
Edgar Allan Poe 9.1 7 {{code}}
abolgov 3.1 8 function m155()
Edgar Allan Poe 9.1 9 local XWidth = 70
10 local YWidth = 50
11 local SafeZ = 3
12 local ProbeZ = -3
13 local StepX = 15
14 local StepY = 15
15 local Feed = 50
16 local TipHeight = 0
17 local ProbeFilename = "C:\temp\probe.txt"
writer 4.1 18
Edgar Allan Poe 9.1 19 PushCurrentDistanceMode()
20 PushCurrentMotionMode()
21
22 if (IsProbingPinConfigured()) then
23 -- open the file
24 file, msg = io.open(ProbeFilename, "w")
writer 4.1 25
26 if (file == nil) then
Edgar Allan Poe 9.1 27 DisplayMessage("Could not open probe output file ("..msg..")")
28 Stop()
29 return
writer 4.1 30 end
31
32 ExecuteMDI("F "..Feed)
33 ExecuteMDI("G90 G38.2 Z-100")
34
Edgar Allan Poe 9.1 35 -- set the current location to 0,0,0
36 ExecuteMDI("G92 X0Y0Z0")
writer 4.1 37 ExecuteMDI("G0 Z"..SafeZ)
38
39 local direction = 0
40 for y = 0, YWidth, StepY do
Edgar Allan Poe 9.1 41 if (direction == 1) then
42 direction = 0
43 else
44 direction = 1
45 end
46
47 for x = 0, XWidth, StepX do
writer 4.1 48 if (direction == 1) then
Edgar Allan Poe 9.1 49 ExecuteMDI("G0 X"..x.." Y"..y.." Z"..SafeZ)
writer 4.1 50 else
Edgar Allan Poe 9.1 51 ExecuteMDI("G0 X"..(XWidth - x).." Y"..y.." Z"..SafeZ)
writer 4.1 52 end
53
Edgar Allan Poe 9.1 54 ExecuteMDI("G38.2 Z"..ProbeZ)
55 LogCurrentPos(TipHeight)
56 ExecuteMDI("G0 Z"..SafeZ)
57 end
writer 4.1 58 end
59
60 if (direction == 1) then
Edgar Allan Poe 9.1 61 ExecuteMDI("G0 X"..XWidth.." Y"..YWidth.." Z"..SafeZ)
writer 4.1 62 else
Edgar Allan Poe 9.1 63 ExecuteMDI("G0 X".."0".." Y"..YWidth.." Z"..SafeZ)
writer 4.1 64 end
65
66 local HighZ = 5
67 ExecuteMDI("G0 Z"..HighZ)
68 ExecuteMDI("G0 X0Y0")
69
70 file:close()
Edgar Allan Poe 9.1 71 else
72 DisplayMessage("Probe input is not configured")
73 return
74 end
abolgov 3.1 75 end
76
77 function LogCurrentPos(tipHeight)
Edgar Allan Poe 9.1 78 local CurrX = AxisGetPos(Axis.X)
79 local CurrY = AxisGetPos(Axis.Y)
80 local CurrZ = AxisGetPos(Axis.Z)
writer 4.1 81
Edgar Allan Poe 9.1 82 local fmt = "%.5f"
83 file:write(string.format(fmt, CurrX)..","..string.format(fmt, CurrY)..","..string.format(fmt, CurrZ - tipHeight), "\n")
abolgov 3.1 84 end
85 {{/code}}
86
Edgar Allan Poe 9.1 87 **[[Download macro>>attach:M155.pm]]**