Hello Guest it is September 19, 2019, 06:02:11 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 - smurph

371
Mach4 General Discussion / Re: Lua Macro Parameters
« on: February 25, 2017, 07:53:52 PM »
The first thing to understand is if you do ANYTHING from a GUI event that is long running, it will lock the GUI for that duration.  Why?  Because you have directed the thread that runs the GUI to run your code.  While it is doing that, it can't sit there and update DROs and work the buttons.  So the thing to do is hand off the task to another thread.  That is what mc.mcCntlMdiExecute() does.  It executes your code in a thread in the core. 

If you are running the stock screen set, take a look at the Modules directory.  mcMasterModule.lua.  That is a module file that is "required" by the screen load script.  This is the lua method of "including" common code.  Open up the screen load script in the screen editor and see how it is implemented. 

Otherwise, there is a bunch of really dry reading in the LUA programming manuals.  :(  The manuals are good, but damn...  painful to read.  LOL

Steve

372
Mach4 General Discussion / Re: Lua Macro Parameters
« on: February 25, 2017, 04:16:03 PM »
Use mc.mcCntlMdiExecute() from the button script.  It will be the same as running it in the mdi window.

Otherwise, the more proper way to run code from both the screen and a macro is to put the common code in a module.  Then require the module in both the screen script and the macro script.  Then all you need to do is call the lua module function.

Steve

373
Mach4 General Discussion / Re: Offset image in tool path window
« on: February 25, 2017, 04:10:04 PM »
After you set a work offset, you will have to regenerate the tool path. 

Steve

374
Mach4 General Discussion / Re: Preload-Tool Macro
« on: February 25, 2017, 04:07:27 PM »
No modbus on that thing at all.  I see where someone is working on Modbus integration, but nothing more.  I'm not sure how one would communicate with that PLC at all at the moment.  I can assure you, there will be NO threads about how to hook Mach 4 to that one.  So you are own you own.  Nothing like being the first to try and do something!!  :)

We do have serial comms via LUA.  http://lua-users.org/lists/lua-l/2012-09/msg00554.html  That may be what you have to do.  

For the price (in fact, cheaper), the Automation Direct Click PLCs are comparable and a LOT more powerful.  Stackable.  Need more I/O in the future, no problem.  https://www.automationdirect.com/adc/Shopping/Catalog/Programmable_Controllers/CLICK_Series_PLCs_(Stackable_Micro_Brick)/PLC_Units

Steve

375
That would be on the motor tuning page.  The velocity setting.  That will be the maximum velocity that the motor will do.  e.g. your rapid velocity.  The jog rate can then be set as a percentage of this max velocity.

Steve

376
Mach4 General Discussion / Re: Lua Macro Parameters
« on: February 24, 2017, 06:13:32 PM »
It is hard to simulate a macro with parameters because hParam is a handle to the parameters which just does not exists in the editor environment.  What I do is just set the variable to what you want to test with and ignore the parameter retrieval stuff while developing.  e.g. Set endX to a value and start debugging. 

Code: [Select]
--Reel Seat Insert
--Turn from current Z down to 0 from current X down to parameter D or .850

function m6690(hParam)
  local xNow,zNow,maxVal
  local TS,TR,TT --timer values Mach3 niy
  local plungeFeed=6
  local roughDOC=0.015
  local roughFeed=15
  local roughSpeed=900
  local finishDOC=0.004
  local finishFeed=8
  local finishSpeed=1400
  local inst=mc.mcGetInstance()
  local endX=.850 --param1()
 
  local inst=mc.mcGetInstance()

  mc.mcCntlSetLastError(inst,'')

  if (mc.mcInEditor() == 1) then
    endX = .850 --param1()
  else
    if (hParam ~= nil) then
      local DFlag = mc.mcCntlGetLocalVarFlag(inst, hParam, mc.SV_D)
      if(DFlag == 1) then
        endX = mc.mcCntlGetLocalVar(inst, hParam, mc.SV_D)
      end
    end
  end
  xNow = mc.mcAxisGetPos(inst,0)
  zNow = mc.mcAxisGetPos(inst,2)
  if xNow<=endX then
    wx.wxMessageBox("start X is less than end Diameter of "..tostring(endX))
    return
  end
  if zNow<=0 then
    wx.wxMessageBox("start Z is less than or = to 0")
    return
  end
  --ts=Timer
 
--rough cuts 
  mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(roughSpeed))
  while (mc.mcAxisGetPos(inst,0)>(endX+finishDOC*2)) do
    currPos=mc.mcAxisGetPos(inst,0)
    maxVal=math.max(endX+2*finishDOC,currPos)
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(maxVal-roughDOC))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z0")
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    currPos=mc.mcAxisGetPos(inst,0)
    maxVal=math.max(endX+2*finishDOC,currPos)
    if currPos==endX+2*finishDOC then
      break
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(math.max(endX+2*finishDOC,currPos-roughDOC)))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z"..tostring(zNow))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end 
    if currPos==endX+2*finishDOC then
      break
    end 
  end
  -- tr=Timer-ts
  --wx.wxMessageBox("Roughing Time: "..tostring(tr))

  --finish cuts
  mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(finishSpeed))

  while (mc.mcAxisGetPos(inst,0)>=(endX+finishDOC)) do
    currPos=mc.mcAxisGetPos(inst,0)
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(currPos-finishDOC))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z0")
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
        return
    end
    currPos=mc.mcAxisGetPos(inst,0)
    if currPos==endX then
      break
    end 
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(currPos-finishDOC))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z"..tostring(zNow))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    currPos=mc.mcAxisGetPos(inst,0)
    if currPos==endX then
      break
    end 
  end
  mc.mcCntlGcodeExecuteWait(inst,"M5\nM9")
--te=Timer-ts
--wx.wxMessageBox("Roughing Time: "..tostring(tr).." - Total Time: "..tostring(te))
end
 
if (mc.mcInEditor() == 1) then
    m6690()
end   

Steve

377
Mach4 General Discussion / Re: Startup problem with Mach 4
« on: February 24, 2017, 06:03:08 PM »
It was time, Vic.  It was time.  :)

Steve

378
On the axis mapping tab of the configuration dialog.  Simply choose a second motor for the Y axis. 

There is no such thing as motor A.  Motors are numbered.  Axes are lettered.  An axis represents a plane of motion.  This motion can be driven by 1 or more motors.  This is an important distinction from Mach 3.  You no longer have to sacrifice an axis to have multiple motors. 

Steve

379
Mach4 General Discussion / Re: Preload-Tool Macro
« on: February 24, 2017, 05:58:16 PM »
Sending data to a PLC almost ALWAYS uses Modbus.  Modbus is the protocol.  It can be used over any transport method that both the Modbus master and Modbus slave have in common.  RS232 and Ethernet are what Mach 4 supports as a Modbus master.  You can use RS485 or RS422 with the appropriate RS323 converter, if you wish. 

There are lot's of threads about Modbus and even the how-to that Steve referred to.  However, we don't attempt to document industry standards that are already very well documented.  Here is a link that summarizes Modbus quite nicely:  http://www.modbusdriver.com/doc/libmbusmaster/modbus.html  Once you understand the mechanism that is Modbus, and along with your PLC documentation, you will then have the glue to put the pieces together. 

And you never mentioned what PLC you are using.  We have no idea and can't read your mind so...  :)

Steve

380
Ahh...  good to know.

Loading G code is an assumed reset.  Because you really want the control in a known state.  Say you had a file that was loaded previously that used G68 rotation.  If the control wasn't reset before loading the new file, it would gank the tool path (and the part!) when the new file is loaded. 

Steve