Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: dude1 on June 29, 2015, 07:03:06 PM

Title: tool height probing
Post by: dude1 on June 29, 2015, 07:03:06 PM
can some one test the attached code I am not sure if it`s working properly it look`s to be working but keeps come up with no probe signal found.

I am run M4 with no license on a ESS

this is the code use from the zip not here
Code: [Select]
-----------------------------------------------------------------------------
-- Auto Tool Setting Macro
-----------------------------------------------------------------------------
--[[
 Requires the following instance registers to be defined
 TS_XPos-----------X position of probe (machine position)
 TS_YPos-----------Y position of probe (machine position)
 TS_Type-----------Offset type (1 or 2)
 TS_TouchPos-------Z position of touch off surface (machine position)
 TS_ProbeH---------Height of probe above touch off surface
 TS_DefaultL-------Default tool length guess
 TS_Retract--------Retract distance after probe touch
 Offset Type 1-----Length of tool from gauge line to tip
 Offset Type 2-----Distance from tip of tool to the touch position
]]
--The function GetRegister() must be defined for use by macros


 function m1005()
 local inst = mc.mcGetInstance()

function GetRegister(regname)
      local rc;
      local inst = mc.mcGetInstance();
      local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname));
      return mc.mcRegGetValueString(hreg);
   end

 ------------- Define Vars -------------
 local ProbeSignal = mc.ISIG_DIGITIZE
 ------------- Get current state -------------
 local CurTool = mc.mcToolGetCurrent(inst)
 local CurHNum = mc.mcCntlGetPoundVar(inst, 2032)
 local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
 local CurZOffset = mc.mcCntlGetPoundVar(inst, 4102)
 local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
 local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)
 ------------- Get touch off parameters -------------

 local XPos = GetRegister("TS_XPos", 1)
 local YPos = GetRegister("TS_YPos", 1)
 local OffsetType = GetRegister("TS_Type", 1)
 local TouchPos = GetRegister("TS_TouchPos", 1)
 local ProbeHeight = GetRegister("TS_ProbeH", 1)
 local RetractDistance = GetRegister("TS_Retract", 1)
 local ToolLengthGuess = GetRegister("TS_DefaultL", 1)
 ------------- Check Probe -------------
 local hsig = mc.mcSignalGetHandle(1,inst, ProbeSignal,mc.ISIG_INPUT11)
 local ProbeState = mc.mcSignalGetState(hsig)
 if (ProbeState == true) then
 mc.mcCntlSetLastError(inst, "ERROR: Probe signal is activated")
 do return end
 end

 ------------- Calculations for Gcode -------------
 local StartHeight = TouchPos + ProbeHeight + ToolLengthGuess + .5

 ------------- Generate GCode -------------
 AutoToolSetGCode = ""
 AutoToolSetGCode = AutoToolSetGCode .. "G00 G80 G40 G49 G90\n"
 AutoToolSetGCode = AutoToolSetGCode .. "G00 G53 Z0.0\n"
 AutoToolSetGCode = AutoToolSetGCode .. string.format("G00 G53 X%.4f Y%.4f\n", XPos, YPos)
 AutoToolSetGCode = AutoToolSetGCode .. string.format("G00 G53 Z%.4f\n", StartHeight)
 AutoToolSetGCode = AutoToolSetGCode .. "G91 G31 Z-2.0 F25.\n"

 mc.mcCntlGcodeExecuteWait(inst, AutoToolSetGCode)
 --Check probe contact
 ProbeState = mc.mcSignalGetState(hsig)
 if (ProbeState ~= 1) then
 mc.mcCntlSetLastError(inst, "ERROR: No contact with probe")
 mc.mcCntlGcodeExecuteWait(inst, "G0 G90 G53 Z0.0\n")
 do return end
 end

 AutoToolSetGCode = ""
 AutoToolSetGCode = AutoToolSetGCode .. string.format("G91 G00 Z%.4f\n", RetractDistance)
 AutoToolSetGCode = AutoToolSetGCode .. "G91 G31 Z-1.0 F10.\n"

 mc.mcCntlGcodeExecuteWait(inst, AutoToolSetGCode)
 --Check probe contact
 ProbeState = mc.mcSignalGetState(hsig)
 if (ProbeState ~= 1) then
 mc.mcCntlSetLastError(inst, "ERROR: No contact with probe")
 mc.mcCntlGcodeExecuteWait(inst, "G0 G90 G53 Z0.0\n")
 do return end
 end

 AutoToolSetGCode = ""
 AutoToolSetGCode = AutoToolSetGCode .. "G90 G00 G53 Z0.0\n"
 mc.mcCntlGcodeExecuteWait(inst, AutoToolSetGCode)
 ------------- Get touch position and set offset -------------
 local ZProbed = mc.mcCntlGetPoundVar(inst, 5063)
 local ZOffset = ZProbed - ProbeHeight + CurZOffset
 if (OffsetType == 1) then
 ZOffset = math.abs(TouchPos - ZOffset)
 end

 mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, CurTool, ZOffset)
 mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f",
ZOffset))
 
 ------------- Set previous state -------------
 mc.mcCntlSetPoundVar(inst, 2134, CurFeed)
 mc.mcCntlSetPoundVar(inst, 4001, CurFeedMode)
 mc.mcCntlSetPoundVar(inst, 4003, CurAbsMode)

end
if (mc.mcInEditor() == 1) then
 m1005()
end
Title: Re: tool height probing
Post by: Screwie Louie on June 30, 2015, 12:32:01 AM
Does your hardware support G31?
Title: Re: tool height probing
Post by: dude1 on June 30, 2015, 01:48:46 AM
I can run the G31 Macro B with no problems
Title: Re: tool height probing
Post by: Screwie Louie on June 30, 2015, 02:49:06 AM
Do you have all your registers set up? ie. TS_XPOS defined in the Register plug-in?
Title: Re: tool height probing
Post by: dude1 on June 30, 2015, 03:14:47 AM
yer the code runs but keep getting no probe contact even if I trigger the probe it works but says no probe contact and yes the probe does work I tested with M3 first it`s all good in M3 it may be that I have no  license.

only the Mach boys can answer this one unless someone with a license test`s it if it happens to work for them that`s what I need if they have same problem it will be the input code is wrong I have it set to input 11 as its on input 11 I may need to change it to ISIG_PROBE  as it maped to probe not input 11.
Title: Re: tool height probing
Post by: Screwie Louie on June 30, 2015, 04:17:22 AM
Could be Dan. G31 commands and execution may just be mapped to the Probe input....vs. Input XX. Good looking out. I bet you're right! By the way, how old is my New Zealand friend? I'm 37...16 yrs in military service (federal acquisitions and contracting). But, I think I know what I actually want to do now after retirement...
Title: Re: tool height probing
Post by: dude1 on June 30, 2015, 04:43:44 AM
the same I think you have a knack for it if you mean being a cnc machine operator or working in the cnc field you seem to be picking up this Lua ********* fast what Cad do you use
Title: Re: tool height probing
Post by: Screwie Louie on June 30, 2015, 12:10:16 PM
I have Solidworks and HSM Express. I'm just learning. I won't let myself start on Solidworks until I understand Mach 4, gCode, macros, etc. I am forcing myself to start from the ground up so I am able to read gCode and understand the machine language. I just got Peter Smid's book on FANUC custom scripts (I believe it was ya-nvr-no's recommendation in one of the threads). I'm just having too much fun! There is so much to learn.
Title: Re: tool height probing
Post by: dude1 on June 30, 2015, 07:46:16 PM
sounds good
Title: Re: tool height probing
Post by: dude1 on June 30, 2015, 07:47:26 PM
well I tryed ISIG_PROBE did not help MACH boy`s please help
Title: Re: tool height probing
Post by: dude1 on July 03, 2015, 03:10:35 AM
I give up
Title: Re: tool height probing
Post by: Screwie Louie on July 03, 2015, 03:24:40 PM
local hsig = mc.mcSignalGetHandle(1,inst, ProbeSignal,mc.ISIG_INPUT11)

above line doesn't look right....if you want the handle to ISIG_PROBE is should be:

local hSig = mc.mcSignalGetHandle (inst, mc.ISIG_PROBE)

if mc.mcSignalGetState (hSig) == 1 then do something end


--on a side note, once I finish moving and reassemble my machine and equipment, I'll work on this for you....pending, I can get G31 working for me.

Title: Re: tool height probing
Post by: poppabear on July 06, 2015, 07:41:36 AM
Look over, and try this one, and see if it works......

Scott
Title: Re: tool height probing
Post by: dude1 on July 06, 2015, 03:10:34 PM
thanks scott that was a simple one
Title: Re: tool height probing
Post by: dude1 on July 06, 2015, 05:34:15 PM
well it`s still not quite right it comes up with this now

mcLua ERROR: Lua: Error while running chunk
[string "C:\Mach4Hobby\LuaExamples\m1005.mcs"]:27: bad argument #2 to 'tonumber' (base out of range)
stack traceback:
   [C]: in function 'tonumber'
   [string "C:\Mach4Hobby\LuaExamples\m1005.mcs"]:27: in function 'GetRegister'
   [string "C:\Mach4Hobby\LuaExamples\m1005.mcs"]:45: in function 'm1005'
   [string "C:\Mach4Hobby\LuaExamples\m1005.mcs"]:112: in main chunk


mcLua ERROR: Lua: Error while running chunk

I changed this

function GetRegister(regname, num)--Added the return type def param
      local rc;
      local inst = mc.mcGetInstance();
      local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname));
      local ReturnValue = 0;
      if num == 1 then
         ReturnValue = tonumber(mc.mcRegGetValueString(hreg));
      else
         ReturnValue = mc.mcRegGetValueString(hreg);
      end
        return ReturnValue;
      end

back to this
function GetRegister(regname)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
return mc.mcRegGetValueString(hreg)
end

and ran through fine but still with the no probe contact error
Title: Re: tool height probing
Post by: Pedio on July 06, 2015, 06:21:38 PM
Look over, and try this one, and see if it works......

Scott
well it`s still not quite right it comes up with this now

mcLua ERROR: Lua: Error while running chunk
[string "C:\Mach4Hobby\LuaExamples\m1005.mcs"]:27: bad argument #2 to 'tonumber' (base out of range)
stack traceback:
   [C]: in function 'tonumber'
   [string "C:\Mach4Hobby\LuaExamples\m1005.mcs"]:27: in function 'GetRegister'
   [string "C:\Mach4Hobby\LuaExamples\m1005.mcs"]:45: in function 'm1005'
   [string "C:\Mach4Hobby\LuaExamples\m1005.mcs"]:112: in main chunk


mcLua ERROR: Lua: Error while running chunk

I changed this

function GetRegister(regname, num)--Added the return type def param
      local rc;
      local inst = mc.mcGetInstance();
      local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname));
      local ReturnValue = 0;
      if num == 1 then
         ReturnValue = tonumber(mc.mcRegGetValueString(hreg));
      else
         ReturnValue = mc.mcRegGetValueString(hreg);
      end
        return ReturnValue;
      end

back to this
function GetRegister(regname)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
return mc.mcRegGetValueString(hreg)
end

and ran through fine but still with the no probe contact error

Papa Bear - I tried putting the script into the "left up script" on the auto tool zero button on the Mach4 main screen. Nothing happens

I have the latest PMDX SmartBOB plugin that supports probing. I have assigned the digitizer to pin 15 and attached the touch plate. When I touch the magnet to the plate the probe LED lights.

Not sure if I need to do anything else. I am a newbie so please forgive me of my ignorance.
Title: Re: tool height probing
Post by: Pedio on July 06, 2015, 06:23:54 PM
I quoted the wrong thread - I used the Papa Bear script in the zip file.
Title: Re: tool height probing
Post by: dude1 on July 06, 2015, 06:37:26 PM
it`s ok pedio it dont work yet