Welcome, Guest. Please login or register.
Did you miss your activation email?
June 24, 2018, 06:10:40 AM

Login with username, password and session length
Search:     Advanced search
* Home Help Search Calendar Links Login Register
+  Machsupport Forum
|-+  Mach Discussion
| |-+  Mach4 General Discussion
| | |-+  "Screenset 2010"-like tool and zero macros?
Pages: 1   Go Down
Print
Author Topic: "Screenset 2010"-like tool and zero macros?  (Read 236 times)
0 Members and 1 Guest are viewing this topic.
lesspaul
Active Member

Offline Offline

Posts: 18


View Profile
« on: May 30, 2018, 05:47:00 PM »

After sitting on a license for several years I'm finally going to give Mach4 the old college try, but I'm pretty wedded to the simple and multi-tool zero functions in Gerry's 2010 screenset, as well as his X/Y zero to laser crosshairs feature.

I'm well aware that in cases such as this, Lua is my friend, and I'm no stranger to coding. However, there is never a point to reinventing the wheel so I thought I'd ask if anyone already has scripting similar in function. If not, time to knock the dust off my ol' friend UltraEdit.

(DaTheGas -- I've already seen your excellent youtube videos on modifying M6!)

Thanks!
-- Paul
« Last Edit: May 30, 2018, 05:49:43 PM by lesspaul » Logged
joeaverage
Active Member

Offline Offline

Posts: 3,350



View Profile
« Reply #1 on: May 30, 2018, 05:57:19 PM »

Hi,
whats wrong with the probing module?

Craig
Logged

My wife left with my best friend...
     and I miss him!
lesspaul
Active Member

Offline Offline

Posts: 18


View Profile
« Reply #2 on: June 13, 2018, 03:13:01 PM »

I've been diverted as life often does.

What I want to do is this:

Initial tool zero:
Probe to zero offset by the thickness of a plate on top of the material. - Probing module does this.
then proceed to a fixed plate on side of work area and note offset between material zero and this plate.  - Probing module does not do this as far as I can tell.

M6 for subsequent tools:
Change tool. Tool probes to fixed plate. Offset from fixed plate to material determined above applied to set tool zero. -- this would be a custom M6

I've gathered a few existing scripts and it won't be a big deal to write the scripts and modify the screenset.

I've already done a quick and dirty "Zero to laser crosshairs" which is here for anyone interested. Create or edit a button to launch this script with offsetX and offsetY adjusted to your machine:

Code:
local inst = mc.mcGetInstance();

local offsetX = -4.7335 -- X axis distance from laser crosshairs to spindle center
local offsetY = -0.0137 -- Y axis distance from laser crosshairs to spindle center

-- wx.wxMessageBox("Zeroing to \nX: "..offsetX.."\nY: "..offsetY)

mc.mcAxisSetPos(inst,0,offsetX)
mc.mcAxisSetPos(inst,1,offsetY)
mc.mcCntlSetLastError(inst, "Workpiece X/Y zeros set to laser crosshair")
Logged
joeaverage
Active Member

Offline Offline

Posts: 3,350



View Profile
« Reply #3 on: June 14, 2018, 04:25:28 AM »

Hi,
have you had a look at the Offsets Tab? It might be possible to snafu various bits of code attached to the buttons.

Craig
Logged

My wife left with my best friend...
     and I miss him!
joeaverage
Active Member

Offline Offline

Posts: 3,350



View Profile
« Reply #4 on: June 14, 2018, 04:36:53 AM »

Hi,
yes...the Set Tool button to the right of the screen has code attached, reasonably simple code at that. You could copy it, add a GcodeExecuteWait() type move to
your fixed plate then  use the tool offset code .

Craig
Logged

My wife left with my best friend...
     and I miss him!
lesspaul
Active Member

Offline Offline

Posts: 18


View Profile
« Reply #5 on: June 15, 2018, 10:24:57 AM »

I've worked a bit more and have a working initial tool Zero routine (below).

My approach will (hopefully) be as follows:

Initial tool zero:
  Set  Z-zero to top of material
  Set  fixed_plate_offset = NOT_SET

M6:
  If "(fixed_plate_offset = NOT_SET)
     Probe to fixed plate with current tool
     Record offset
     set "fixed_plate_offset" to SET"
  Change tool
  Probe fixed plate and apply offset to tool zero.

Here is my messy but working initial tool zero (using coroutine for screen updating) which is assigned to a screen button.

Code:
probeMove = coroutine.create(function()
  local inst = mc.mcGetInstance()
  local TouchPlate = 0.622 -- Thickness of touchplate above material
  local SlowProbeRate = 0.7  -- IPM
  local FastProbeRate = 5.0  -- IPM
  local JogRate = 60
  local Pos
  
  wx.wxMessageBox("1) Check that touch plate is connected.\n2) Position the tool\'s tip above and within 2\" of the plate.\n            Press ENTER.")
  
  -- Fast probe Z zero
  mc.mcCntlSetLastError(inst, "Probing for Z Zero . . .")
  mc.mcCntlGcodeExecute(inst,"G91 G31 Z-2.0 F".. FastProbeRate)
  coroutine.yield()  
  
  -- Retract slightly  
  mc.mcCntlGcodeExecute(inst,"G91     Z0.05  F".. JogRate)  
  coroutine.yield()
 
  -- Slow probe Z zero
  mc.mcCntlGcodeExecute(inst,"G91 G31 Z-0.07 F".. SlowProbeRate)  
  coroutine.yield()
  
  -- Get touch position (G53) and jog to it in case of overshoot  
  Pos = mc.mcAxisGetProbePos(inst, mc.Z_AXIS, 0)  -- Get Touch Position (work coordinates)
  mc.mcCntlGcodeExecute(inst,"G90 Z".. Pos .. " F".. SlowProbeRate)
  coroutine.yield()

  -- Set DRO to height of touchplate and retract to a safe height
  mc.mcAxisSetPos(inst, mc.Z_AXIS, TouchPlate)
  mc.mcCntlGcodeExecute(inst,"G91 Z1.0 F".. JogRate)
  coroutine.yield()
  
  mc.mcCntlSetLastError(inst, "Z Zero set")

  mc.mcCntlReset(0)
  
end)
Logged
lesspaul
Active Member

Offline Offline

Posts: 18


View Profile
« Reply #6 on: June 15, 2018, 06:37:27 PM »

The final piece is in place: the m6 macro.

I've more-or-less duplicated the functionality of my favorite Screenset 2010 features via two button scripts and an M6. Hopefully I've commented them enough to make the journey a bit easier for someone in the future. Other than assigning the scripts to two buttons and editing m6.mcs, the only other setup is using the Regfile plugin to create an Instance Register named "Tool_Offset" with an initial value over 90. (an arbitrary flag value as the Register is dual use -- as a flag (unset) and a value (set).)

There is a lot of room for adding elegance and error checking, but those are both for another day. In the words of Red Green, "This is only temporary. Unless it works."

The M6 has some DazTheGas code, some ArtSoft code, and a bunch of ugly by your's truly.
Code:
function m6()
  local inst = mc.mcGetInstance();
  local offset = mc.mcRegGetHandle(inst,"iRegs0/Tool_Offset")
  local selectedTool = mc.mcToolGetSelected(inst)
  local currentTool  = mc.mcToolGetCurrent(inst)
  local FixedPlateX = 16.212 -- machine coordinate of fixed plate
  local FixedPlateY = 0.153  -- machine coordinate of fixed plate
  local initialX = mc.mcAxisGetPos(inst,0)
  local initialY = mc.mcAxisGetPos(inst,1)

  if selectedTool == currentTool then
    mc.mcCntlSetLastError(inst, "Current tool == Selected tool")
  else
     mc.mcCntlSetLastError(inst, "ToolChange Activated ...")
     mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0 X".. FixedPlateX .. " Y".. FixedPlateY); -- Position for tool change and probing

     if mc.mcRegGetValue(offset) >= 99 then
     wx.wxMessageBox("Initial tool. Press enter to probe for offset")
     mc.mcRegSetValue(offset, probePlate()) -- Store offset
     mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0") -- move up for toolchange
     end
 
    mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to zero") --Message at beginning of tool change
    mc.mcCntlToolChangeManual(inst, true) --This will pause the tool change here and wait for a press of cycle start to continue

    mc.mcAxisSetPos(inst, mc.Z_AXIS, probePlate()) -- Set new tool to fixed plate offset value
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")           -- goto machine Z Zero
    mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X".. initialX.." Y".. initialY .. "F40")  -- return to starting positions

    mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. "   Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
    mc.mcToolSetCurrent(inst, selectedTool)
    mc.mcRegSetValue()

    end
end

if (mc.mcInEditor() == 1) then
    m6()
end

function probePlate()
  local inst = mc.mcGetInstance()
  local SlowProbeRate = 0.7  -- IPM
  local FastProbeRate = 5.0  -- IPM
  local JogRate = 60
  local Pos

  -- Fast probe Z zero
  mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z-2.5") -- Pre-position
  mc.mcCntlSetLastError(inst, "Probing for Z Zero . . .")
  mc.mcCntlGcodeExecute(inst,"G91 G31 Z-3.0 F".. FastProbeRate)

  -- Retract slightly  
  mc.mcCntlSetLastError(inst, "Retract . . .")
  mc.mcCntlGcodeExecute(inst,"G91     Z0.05  F".. JogRate)  
 
  -- Slow probe Z zero
  mc.mcCntlSetLastError(inst, "Slow Probing for Z Zero . . .")
  mc.mcCntlGcodeExecute(inst,"G91 G31 Z-0.07 F".. SlowProbeRate)  
  
    -- Get touch position and jog to it in case of overshoot  
  Pos = mc.mcAxisGetProbePos(inst, mc.Z_AXIS, 0)  -- Get Touch Position (work coordinates)
  mc.mcCntlGcodeExecute(inst,"G90 Z".. Pos .. " F".. SlowProbeRate)
  
  return Pos  
end

The initial tool zero button routine communicates through a register to let M6 know an offset needs to be measured.
Code:
probeMove = coroutine.create(function()
  local inst = mc.mcGetInstance()
  hreg = mc.mcRegGetHandle(inst, "iRegs0/Tool_Offset")  
  local TouchPlate = 0.622 -- Thickness of touchplate above material
  local SlowProbeRate = 0.7  -- IPM
  local FastProbeRate = 5.0  -- IPM
  local JogRate = 60
  local Pos
    
  wx.wxMessageBox("1) Check that touch plate is connected.\n2) Position the tool\'s tip above and within 2\" of the plate.\n            Press ENTER.")
  -- Fast probe Z zero
  mc.mcCntlSetLastError(inst, "Probing for Z Zero . . .")
  mc.mcCntlGcodeExecute(inst,"G91 G31 Z-2.0 F".. FastProbeRate)
  coroutine.yield()  
  
  -- Retract slightly  
  mc.mcCntlGcodeExecute(inst,"G91     Z0.05  F".. JogRate)  
  coroutine.yield()
 
  -- Slow probe Z zero
  mc.mcCntlGcodeExecute(inst,"G91 G31 Z-0.07 F".. SlowProbeRate)  
  coroutine.yield()
  
  -- Get touch position (G53) and jog to it in case of overshoot  
  Pos = mc.mcAxisGetProbePos(inst, mc.Z_AXIS, 0)  -- Get Touch Position (work coordinates)
  mc.mcCntlGcodeExecute(inst,"G90 Z".. Pos .. " F".. SlowProbeRate)
  coroutine.yield()

  -- Set DRO to height of touchplate and retract to a safe height
  mc.mcAxisSetPos(inst, mc.Z_AXIS, TouchPlate)
  mc.mcCntlGcodeExecute(inst,"G91 Z1.0 F".. JogRate)
  coroutine.yield()
  
  mc.mcCntlSetLastError(inst, "Z Zero set")
  mc.mcRegSetValue(hreg,99.9)

  mc.mcCntlReset(0)
  
end)

And lastly a very simple button code to set X/Y zero to my laser crosshairs:
Code:
local inst = mc.mcGetInstance();

local offsetX = -4.7335 -- X axis distance from laser crosshairs to spindle center
local offsetY = -0.0137 -- Y axis distance from laser crosshairs to spindle center

mc.mcAxisSetPos(inst,0,offsetX)
mc.mcAxisSetPos(inst,1,offsetY)
mc.mcCntlSetLastError(inst, "Workpiece X/Y zeros set to laser crosshair")


Logged
Pages: 1   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!