Hi Everyone,
First time posting here, made my 4x8 CNC 4 years ago and going strong with UCCNC & a C94 with UC300 EITH. So I decided to buy Ger's UCCNC 2022 Screen Set, still waiting for him to send it after only being 12hrs, it is what it is (I am excited to use it)... Maybe he should have Paypal do automation to send the file to your email after purchase, just a suggestion (as Digital Download)
Anyway, so while I am waiting I decided to see if Chat GPT could write me a script for the main features that I initially wanted the screen set for.
So this is what I have asked it...
Q:
Can you create a script for UCCNC that let me assign two buttons on the screen to do Auto Tool Zero for a mobile prob, and one for a fixed probe? When moving to the probes I what each option to go to a Safe Z height in Machine Coordinates. Also, can you have the Safe Z height not go past soft limits?
A: (From Chat GTP)
-- Script for UCCNC to assign buttons for Auto Tool Zero with mobile and fixed probes
-- Define the safe Z height in machine coordinates for moving to the probes
local safeZ = 10
-- Define the Auto Tool Zero function for the mobile probe
function autoToolZeroMobile()
-- Move to the safe Z height, but make sure not to exceed soft limits
local currX, currY, currZ = mc.mcCntlGetCurrentPos(inst)
local newZ = math.min(safeZ, mc.mcCntlGetLimitPos(inst, mc.Z_AXIS))
mc.mcCntlGcodeExecute(inst, "G0 X" .. currX .. " Y" .. currY .. " Z" .. newZ)
-- Prompt the user to attach the mobile probe
local response = mc.mcMessageBox("Attach Mobile Probe", "Please attach the mobile probe and click OK.", 1)
-- If the user clicked OK, run the Auto Tool Zero sequence for the mobile probe
if response == 1 then
mc.mcCntlSetLastError(inst, "Setting mobile probe as tool zero.")
mc.mcCntlProbeMobile(inst)
end
end
-- Define the Auto Tool Zero function for the fixed probe
function autoToolZeroFixed()
-- Move to the safe Z height, but make sure not to exceed soft limits
local currX, currY, currZ = mc.mcCntlGetCurrentPos(inst)
local newZ = math.min(safeZ, mc.mcCntlGetLimitPos(inst, mc.Z_AXIS))
mc.mcCntlGcodeExecute(inst, "G0 X" .. currX .. " Y" .. currY .. " Z" .. newZ)
-- Prompt the user to attach the fixed probe
local response = mc.mcMessageBox("Attach Fixed Probe", "Please attach the fixed probe and click OK.", 1)
-- If the user clicked OK, run the Auto Tool Zero sequence for the fixed probe
if response == 1 then
mc.mcCntlSetLastError(inst, "Setting fixed probe as tool zero.")
mc.mcCntlProbeFixed(inst)
end
end
-- Define the button functions
function buttonMobile()
autoToolZeroMobile()
end
function buttonFixed()
autoToolZeroFixed()
end
-- Assign the button functions to buttons on the screen
local buttonMobileID = mc.mcIntLoad(inst, "UserButton99")
local buttonFixedID = mc.mcIntLoad(inst, "UserButton100")
mc.mcCntlSetToolTip(inst, buttonMobileID, "Auto Tool Zero with Mobile Probe")
mc.mcCntlSetToolTip(inst, buttonFixedID, "Auto Tool Zero with Fixed Probe")
mc.mcCntlSetButton(inst, buttonMobileID, buttonMobile)
mc.mcCntlSetButton(inst, buttonFixedID, buttonFixed)
Note from Chat GTP:
In this updated version of the script, the mc.mcCntlGetCurrentPos() function is used to get the current position of the machine, and the mc.mcCntlGetLimitPos() function is used to get the soft limit position for the Z axis. The math.min() function is then used to ensure that the Safe Z height doesn't exceed the soft limit before moving the spindle to that position. This modification should help prevent any collisions that could occur if the Safe Z height were set higher than the soft limit.
What do some of the scriptwriters here think of its output? I have not tried it yet btw...