Hello Guest it is April 26, 2024, 06:28:10 PM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - lesspaul

Pages: « 1 2 3 4 »
21
Allan,

Thank you for the clarification. The initial curve of learning the Mach4 basics, Lua, and the ins/outs of scripting for Mach4 can be daunting at first.

Paul

22
I figured it out. Dumb mistake.

The correct way is to put it in _both_ the screen load and the load_modules. Not just one or the other.

23
Mach4 General Discussion / Can't seem to get load_modules.mcs working
« on: June 17, 2018, 11:42:37 AM »
RHTuttle posted in January about launching functions as coroutines from his scripts using load_modules.mcs to load his custom module, a user module, and a button script
 http://www.machsupport.com/forum/index.php/topic,36474.0.html

I had no success trying to duplicate his efforts. I reduced my code to a minor test case, and it seems that I'm doing something wrong regarding load_modules.mcs.

The file 'load_modules.mcs' in my profile's '\Macros' subdirectory
Code: [Select]
---------------------------------------------------------------
-- Load modules that you want to be able to use from Mcodes
---------------------------------------------------------------
inst = mc.mcGetInstance()
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)

package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;"
--package.path = path .. "\\Modules\\?.lua;" .. path .. "\\Profiles\\" ..  profile .. "\\Modules\\?.lua;"

--ErrorCheck module
package.loaded.mcErrorCheck = nil
ec = require "mcErrorCheck"

ph = require "phModule"     -- resides: C:\Mach4Hobby\Profiles\MyCNC\Modules

'phModule.lua' in my profile's '\Modules' subdirectory.
Code: [Select]
local phModule = {}

   function phModule.bigMac()
      mc.mcCntlSetLastError(inst, "Special Sauce?")
   end

return phModule


Button code
Code: [Select]
ph.bigMac()

When I activate the screen button, I get the following error message:
C:\Mach4Hobby\ScreenScript.lua:1029: attempt to index global 'ph' (a nil value)
stack traceback:
   C:\Mach4Hobby\ScreenScript.lua:1029: in function <C:\Mach4Hobby\ScreenScript.lua:1028>
   
However, if I add the load_modules code to the Screen Load Script, my button functions as expected.
Code: [Select]
--My Stuff (Paul)
ph = require "phModule"

Yes, I got the code working, but I'm perplexed as to what I was doing wrong initially. Any and all help much appreciated.

24
Thanks Allen!

25
Craig, you are too humble. And thank you.
-- Paul

26
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: [Select]
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: [Select]
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: [Select]
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")



27
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: [Select]
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)

28
I have a state flag that I need to be accessible in multiple scripts.

It looks like this could be done by creating a register in the register plugin or I could create a LED on the screenset and use its state to communicate. Or ??

Related questions
-- what are the differences between an "instance" and a "global" register?
-- is there a hook to trigger or launch a script when a new g-code file has been loaded?
 

29
Mach4 General Discussion / Reset required after G31 probing moves?
« on: June 14, 2018, 03:10:32 PM »
I am seeing something that seems unusual to this Mach4 newbie. I just got done writing my second script -- tool zero probing -- and found a strange behavior. Following a G31 probing move the MDI is disabled.  Test code:

Code: [Select]
mc.mcCntlGcodeExecuteWait(0,"G91 G31 Z-2.0 F5.0)
however, if I press [Reset] or add mc.mcCntlReset(0) to the script all is well and the MDI works as expected.

Code: [Select]
mc.mcCntlGcodeExecuteWait(0,"G91 G31 Z-2.0 F5.0)
mc.mcCntlReset(0)

I am using the most recent release version of Mach4 (4.2.0.3804) and Ethernet Smoothstepper with firmware #220.

So my questions are: Is this normal? And if not, which is the most likely culprit, something I did, Mach4 or ESS?

For completeness sake, here is my entire tool zero script:

Code: [Select]
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

mc.mcCntlSetLastError(inst, "Probing for Z Zero . . .")
wx.wxMessageBox("Ensure touch plate properly positioned and connected, then press ENTER.")

mc.mcCntlGcodeExecuteWait(inst,"G91 G31 Z-2.0 F".. FastProbeRate)  -- Probe TouchPlate at FastProbeRate
mc.mcCntlGcodeExecuteWait(inst,"G91     Z0.05  F".. JogRate)        -- Retract
mc.mcCntlGcodeExecuteWait(inst,"G91 G31 Z-0.07 F".. SlowProbeRate)  -- Probe TouchPlate at at SlowProbeRate

Pos = mc.mcAxisGetProbePos(inst, mc.Z_AXIS, 0)  -- Get Touch Position (work coordinates)

mc.mcCntlGcodeExecuteWait(inst,"G90 Z".. Pos .. " F".. SlowProbeRate) -- Move back to touch point in case of overshoot
mc.mcAxisSetPos(inst, mc.Z_AXIS, TouchPlate) -- set DRO to height of touchplate
mc.mcCntlGcodeExecuteWait(inst,"G91 Z1.0 F".. JogRate)        -- Retract

wx.wxMessageBox("Z Zero Set. Remove touch plate and press Enter")
mc.mcCntlSetLastError(inst, "Z Zero set")

mc.mcCntlReset(0)

30
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: [Select]
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")

Pages: « 1 2 3 4 »