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