Wiki source code of Макрос для формирования карты высот
Last modified by writer on 2025/07/15 19:27
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | For certain tasks (for example, PCB milling) it becomes necessary to scan the surface with subsequent correction of unevenness in Z. | ||
| 2 | |||
| 3 | A height map is prepared using a macro (show example below) and the G-code is modified based on this height map. | ||
| 4 | |||
| 5 | You can generate a G-code with new coordinates, for example, in the G-Code Ripper program. | ||
| 6 | |||
| 7 | {{code language="lua"}} | ||
| 8 | function m155() | ||
| 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" | ||
| 18 | |||
| 19 | PushCurrentDistanceMode() | ||
| 20 | PushCurrentMotionMode() | ||
| 21 | |||
| 22 | if (IsProbingPinConfigured()) then | ||
| 23 | -- open the file | ||
| 24 | file, msg = io.open(ProbeFilename, "w") | ||
| 25 | |||
| 26 | if (file == nil) then | ||
| 27 | DisplayMessage("Could not open probe output file ("..msg..")") | ||
| 28 | Stop() | ||
| 29 | return | ||
| 30 | end | ||
| 31 | |||
| 32 | ExecuteMDI("F "..Feed) | ||
| 33 | ExecuteMDI("G90 G38.2 Z-100") | ||
| 34 | |||
| 35 | -- set the current location to 0,0,0 | ||
| 36 | ExecuteMDI("G92 X0Y0Z0") | ||
| 37 | ExecuteMDI("G0 Z"..SafeZ) | ||
| 38 | |||
| 39 | local direction = 0 | ||
| 40 | for y = 0, YWidth, StepY do | ||
| 41 | if (direction == 1) then | ||
| 42 | direction = 0 | ||
| 43 | else | ||
| 44 | direction = 1 | ||
| 45 | end | ||
| 46 | |||
| 47 | for x = 0, XWidth, StepX do | ||
| 48 | if (direction == 1) then | ||
| 49 | ExecuteMDI("G0 X"..x.." Y"..y.." Z"..SafeZ) | ||
| 50 | else | ||
| 51 | ExecuteMDI("G0 X"..(XWidth - x).." Y"..y.." Z"..SafeZ) | ||
| 52 | end | ||
| 53 | |||
| 54 | ExecuteMDI("G38.2 Z"..ProbeZ) | ||
| 55 | LogCurrentPos(TipHeight) | ||
| 56 | ExecuteMDI("G0 Z"..SafeZ) | ||
| 57 | end | ||
| 58 | end | ||
| 59 | |||
| 60 | if (direction == 1) then | ||
| 61 | ExecuteMDI("G0 X"..XWidth.." Y"..YWidth.." Z"..SafeZ) | ||
| 62 | else | ||
| 63 | ExecuteMDI("G0 X".."0".." Y"..YWidth.." Z"..SafeZ) | ||
| 64 | end | ||
| 65 | |||
| 66 | local HighZ = 5 | ||
| 67 | ExecuteMDI("G0 Z"..HighZ) | ||
| 68 | ExecuteMDI("G0 X0Y0") | ||
| 69 | |||
| 70 | file:close() | ||
| 71 | else | ||
| 72 | DisplayMessage("Probe input is not configured") | ||
| 73 | return | ||
| 74 | end | ||
| 75 | end | ||
| 76 | |||
| 77 | function LogCurrentPos(tipHeight) | ||
| 78 | local CurrX = AxisGetPos(Axis.X) | ||
| 79 | local CurrY = AxisGetPos(Axis.Y) | ||
| 80 | local CurrZ = AxisGetPos(Axis.Z) | ||
| 81 | |||
| 82 | local fmt = "%.5f" | ||
| 83 | file:write(string.format(fmt, CurrX)..","..string.format(fmt, CurrY)..","..string.format(fmt, CurrZ - tipHeight), "\n") | ||
| 84 | end | ||
| 85 | {{/code}} | ||
| 86 | |||
| 87 | **[[Download macro>>attach:M155.pm]]** |