Макрос для формирования карты высот
Редактировал(а) writer 2023/09/20 17:07
Для определённых задач (например, фрезеровки печатных плат) может возникнуть необходимость сканирования поверхности с последующей корректировкой неровностей по Z.
Карту высот на основе сканирования поверхности можно подготовить с помощью макроса (пример ниже) и затем, используя эту карту высот, модифицировать G-код.
Сформировать G-код с готовыми координатами поможет, например, программа G-Code Ripper.
function m155()
local XWidth = 70
local YWidth = 50
local SafeZ = 3
local ProbeZ = -3
local StepX = 15
local StepY = 15
local Feed = 50
local TipHeight = 0
local ProbeFilename = "C:\temp\probe.txt"
PushCurrentDistanceMode()
PushCurrentMotionMode()
if (IsProbingPinConfigured()) then
file, msg = io.open(ProbeFilename, "w") -- open the file
else
DisplayMessage("Probe input is not configured")
return
end
if (file == nil) then
DisplayMessage("Could not open probe output file ("..msg..")")
Stop()
return
end
ExecuteMDI("F "..Feed)
ExecuteMDI("G90 G38.2 Z-100")
ExecuteMDI("G92 X0Y0Z0") -- set the current location to 0,0,0
ExecuteMDI("G0 Z"..SafeZ)
local direction = 0
for y = 0, YWidth, StepY do
if (direction == 1) then
direction = 0
else
direction = 1
end
for x = 0, XWidth, StepX do
if (direction == 1) then
ExecuteMDI("G0 X"..x.." Y"..y.." Z"..SafeZ)
else
ExecuteMDI("G0 X"..(XWidth - x).." Y"..y.." Z"..SafeZ)
end
ExecuteMDI("G38.2 Z"..ProbeZ)
LogCurrentPos(TipHeight)
ExecuteMDI("G0 Z"..SafeZ)
end
end
if (direction == 1) then
ExecuteMDI("G0 X"..XWidth.." Y"..YWidth.." Z"..SafeZ)
else
ExecuteMDI("G0 X".."0".." Y"..YWidth.." Z"..SafeZ)
end
local HighZ = 5
ExecuteMDI("G0 Z"..HighZ)
ExecuteMDI("G0 X0Y0")
file:close()
end
function LogCurrentPos(tipHeight)
local CurrX = AxisGetPos(Axis.X)
local CurrY = AxisGetPos(Axis.Y)
local CurrZ = AxisGetPos(Axis.Z)
local fmt = "%.5f"
file:write(string.format(fmt, CurrX)..","..string.format(fmt, CurrY)..","..
string.format(fmt, CurrZ - tipHeight), "\n")
end
local XWidth = 70
local YWidth = 50
local SafeZ = 3
local ProbeZ = -3
local StepX = 15
local StepY = 15
local Feed = 50
local TipHeight = 0
local ProbeFilename = "C:\temp\probe.txt"
PushCurrentDistanceMode()
PushCurrentMotionMode()
if (IsProbingPinConfigured()) then
file, msg = io.open(ProbeFilename, "w") -- open the file
else
DisplayMessage("Probe input is not configured")
return
end
if (file == nil) then
DisplayMessage("Could not open probe output file ("..msg..")")
Stop()
return
end
ExecuteMDI("F "..Feed)
ExecuteMDI("G90 G38.2 Z-100")
ExecuteMDI("G92 X0Y0Z0") -- set the current location to 0,0,0
ExecuteMDI("G0 Z"..SafeZ)
local direction = 0
for y = 0, YWidth, StepY do
if (direction == 1) then
direction = 0
else
direction = 1
end
for x = 0, XWidth, StepX do
if (direction == 1) then
ExecuteMDI("G0 X"..x.." Y"..y.." Z"..SafeZ)
else
ExecuteMDI("G0 X"..(XWidth - x).." Y"..y.." Z"..SafeZ)
end
ExecuteMDI("G38.2 Z"..ProbeZ)
LogCurrentPos(TipHeight)
ExecuteMDI("G0 Z"..SafeZ)
end
end
if (direction == 1) then
ExecuteMDI("G0 X"..XWidth.." Y"..YWidth.." Z"..SafeZ)
else
ExecuteMDI("G0 X".."0".." Y"..YWidth.." Z"..SafeZ)
end
local HighZ = 5
ExecuteMDI("G0 Z"..HighZ)
ExecuteMDI("G0 X0Y0")
file:close()
end
function LogCurrentPos(tipHeight)
local CurrX = AxisGetPos(Axis.X)
local CurrY = AxisGetPos(Axis.Y)
local CurrZ = AxisGetPos(Axis.Z)
local fmt = "%.5f"
file:write(string.format(fmt, CurrX)..","..string.format(fmt, CurrY)..","..
string.format(fmt, CurrZ - tipHeight), "\n")
end