Hello Guest it is October 17, 2019, 02:10:37 AM

Author Topic: Lua Fails Me  (Read 1378 times)

0 Members and 1 Guest are viewing this topic.

Lua Fails Me
« on: January 13, 2018, 03:30:45 PM »
Just when I think i am starting to understand lua I run into this.  The code below is a macro that I have used many times and today I wanted to alter it a bit.  When the changes didn't do what I thought it should i started putting in wxMessagBox calls in to see where it was failing.  When the first message box didn't pop up I was surprised, but even more surprised that the macro continued to execute including the second popup telling me to switch gearing.  What am I missing?  I deleted the .mcc and .mcs.bak several times and completely restarted windows with the same results.  I am at a total loss on this one.

Code: [Select]
function m6691(hVars)
  local xNow,zNow,maxVal,rc
  local ts,tr,te,sCode
  local currPos
  local plungeFeed=1
  local roughDOC=0.018
  local roughFeed=18
  local roughSpeed=1200
  local finishDOC=0.004
  local finishFeed=8
  local finishSpeed=1800
  local endX=.850 --param1()
 
  local inst=mc.mcGetInstance()

  wx.wxMessageBox('nil')  --HOW  IS THIS SKIPPED?
 
  if mc.mcSpindleGetCurrentRange(inst)~=1 then
    --rt.rtAudio("notify")
    --wx.wxSound('C:\\mach4Hobby\\Sounds\\Notify.wav',0):Play()
    wx.wxMessageBox('Set Spindle Gearing to High Speed')    --THIS ONE DOES GET EXECUTED!!!
    mc.mcSpindleSetRange(inst,1)
  end
  if (hVars ~= nil) then
    local DFlag = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_D)
    if(DFlag == 1) then
      endX = mc.mcCntlGetLocalVar(inst, hVars, mc.SV_D)
      mc.mcCntlSetLastError(inst,"Turning Diameter to "..endX)
    end
  end
  xNow,rc = mc.mcAxisGetPos(inst,0)
  zNow,rc = mc.mcAxisGetPos(inst,2)
  if xNow<=endX then
    rt.rtAudio("chord")
    wx.wxMessageBox("start X diameter "..xNow.." is <= to end diameter of "..tostring(endX))
    return
  end
  if zNow<=0 then
    rt.rtAudio("chord")
    wx.wxMessageBox("start Z is less than or = to 0")
    return
  end
  ts=os.time()

--rough cuts 
  mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(roughSpeed).."\ng04 p3.0")
  currPos,rc=mc.mcAxisGetPos(inst,0)
  while ((currPos-2*roughDOC)>(endX+finishDOC*2)) do
    maxVal=math.max(endX+2*finishDOC,currPos-roughDOC)
    sCode="G01 F"..tostring(plungeFeed).." X"..tostring(maxVal-roughDOC)
    mc.mcCntlGcodeExecuteWait(inst,sCode)
    currPos,rc=mc.mcAxisGetPos(inst,0)
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z0")
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      rt.rtAudio("chord")
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    currPos,rc=mc.mcAxisGetPos(inst,0)
    maxVal=math.max(endX+2*finishDOC,currPos-roughDOC)
    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
      rt.rtAudio("chord")
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z"..tostring(zNow))
    if (currPos)==endX+2*finishDOC then
      break
    end 
  end
  tr=os.difftime(os.time(),ts)/60
  mc.mcCntlSetLastError(inst,"Roughing Time: "..string.format("%.1f min",tr))

  --finish cuts
  mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(finishSpeed))
  while (mc.mcAxisGetPos(inst,0)>=(endX+finishDOC)) do
    currPos,rc=mc.mcAxisGetPos(inst,0)
    maxVal=math.max(endX,currPos-finishDOC)
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(maxVal))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      rt.rtAudio("chord")
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z0")
    currPos,rc=mc.mcAxisGetPos(inst,0)
    if currPos==endX then
      break
    end 
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(endX))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      rt.rtAudio("chord")
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z"..tostring(zNow))
    currPos,rc=mc.mcAxisGetPos(inst,0)
    if currPos==endX then
      break
    end 
  end
  mc.mcCntlGcodeExecuteWait(inst,"M5\nM9")
  te=(os.time()-ts)/60
  mc.mcCntlSetLastError(inst,"Roughing Time: "..string.format("%.1f min",tr).." - Total Time: "..string.format("%.1f min",te))
end

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


TIA

RT
Re: Lua Fails Me
« Reply #1 on: January 14, 2018, 02:42:04 PM »
Update:

Decided to give up figuring this out for now so I just deleted the wxMessagebox.

THEN, I changed the finishSpeed and finishFeed to be the same as the roughing feed and speed. Saved it and ran it from the MDI: m6691.  It ran with the old speed and feed for the finish cycle.  Deleted the m6691.mcc and ran it again.  Same result.  Shut windows down and unplugged the pmdx411, restarted windows and plugged the pmdx back in.  Deleted the mcc again and went into the editor checked to make sure that the finish numbers were the same as the roughing and they were, hit compile and the mcc was created again.  Ran it but it still ran the finish cycle with the old numbers!!!

I have searched the computer for any old copies of the mcc file and deleted those in a backup directory along with the mcs and removed them from dropbox as well.  How is it that it is running a file that no longer exists?

TIA

RT
Re: Lua Fails Me
« Reply #2 on: January 14, 2018, 03:12:57 PM »
Further update:

copied and saved the m6691.mcs as m7791.mcs

ran m7791 from the mdi and nothing happened.

deleted the m6691.mcc and moved the m6691.mcs to another directory.  ran m6691 from the mdi and nothing happened.

copied the m6691.mcs back to the macros directory and ran m6691 from the mdi and it created the new m6691.mcc but still ran with the old finish numbers.

Any ideas?

RT

Offline Chaoticone

*
  • *
  •  5,607 5,607
  • Precision Chaos
    • View Profile
Re: Lua Fails Me
« Reply #3 on: January 14, 2018, 06:45:11 PM »
Did you also delete the lua.mcc file? Anytime you update marcos I would close Mach, delete all .mcc and .bak files in the macros directory. Relaunch Mach and test.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Lua Fails Me
« Reply #4 on: January 15, 2018, 11:02:47 AM »
I did not find a lua.mcc on my machine but I did find a mcLua.mcc.  I deleted it, after shutting down m4, and the result was the same.  I then deleted all mcc and bak files and restarted m4, the result was the same. 

I have searched the computer for any files of m6691* and found only the mcs and new mcc created on reload.  I have changed the feeds and speeds in the m6691 script and can confidently state that the file is not being run.   It's as if m4 has retained a compiled version somewhere else.  I am totally baffled on this one.

Offline DazTheGas

*
  •  750 750
  • DazTheGas
    • View Profile
Re: Lua Fails Me
« Reply #5 on: January 15, 2018, 11:42:27 AM »
Just had a quick look at code, are you using the load modules.mcs?? as there is a bit of code looking for a table at line 34 "rt.rtAudio("chord")"

DazTheGas
Theres always time for a choccy biccy
Re: Lua Fails Me
« Reply #6 on: January 15, 2018, 12:28:28 PM »
Hi Daz,

Yes I am using it.  I have another macro, m6000 that calls one of the functions and it works,

function m6000()
rt = require 'rtMyModule'
if rt== nil then
  wx.wxMessageBox('rt==nil')
  return
end
local subj='Lathe'
local msg='test m6000'
rt.sendSMS(subj,msg)
end

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

So it seems that rtMyModule located in the profile's 'modules' directory is successfully compiled and loaded by this macro.

Does this help narrow down the problem?
Re: Lua Fails Me
« Reply #7 on: January 15, 2018, 02:07:00 PM »
Had to go blow some snow for the last hour, going to get to below 0 f here later.

Here now is the sum total of the m6691.mcs.  Deleted all bak and mcc in the macro folder and then started m4.


function m6691(hVars)
wx.wxMessageBox('hello')
--[[
 local rt = require 'rtMyModule'
  if rt== nil then
    wx.wxMessageBox('rt==nil')
  return
  end
  local xNow,zNow,maxVal,rc
  local ts,tr,te,sCode
  local currPos
  local plungeFeed=1
  local roughDOC=0.018
  local roughFeed=18
  local roughSpeed=800
  local finishDOC=0.018
  local finishFeed=18
  local finishSpeed=800
  local endX=.850 --param1()
 
  local inst=mc.mcGetInstance()
 
  if mc.mcSpindleGetCurrentRange(inst)~=1 then
    --rt.rtAudio("notify")
    --wx.wxSound('C:\\mach4Hobby\\Sounds\\Notify.wav',0):Play()
    wx.wxMessageBox('Set Spindle Gearing to High Speed')
    mc.mcSpindleSetRange(inst,1)
  end
  if (hVars ~= nil) then
    local DFlag = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_D)
    if(DFlag == 1) then
      endX = mc.mcCntlGetLocalVar(inst, hVars, mc.SV_D)
      mc.mcCntlSetLastError(inst,"Turning Diameter to "..endX)
    end
  end
  xNow,rc = mc.mcAxisGetPos(inst,0)
  zNow,rc = mc.mcAxisGetPos(inst,2)
  if xNow<=endX then
    rt.rtAudio("chord")
    wx.wxMessageBox("start X diameter "..xNow.." is <= to end diameter of "..tostring(endX))
    return
  end
  if zNow<=0 then
    rt.rtAudio("chord")
    wx.wxMessageBox("start Z is less than or = to 0")
    return
  end
  ts=os.time()

--rough cuts 
  mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(roughSpeed).."\ng04 p3.0")
  currPos,rc=mc.mcAxisGetPos(inst,0)
  while ((currPos-2*roughDOC)>(endX+finishDOC*2)) do
    maxVal=math.max(endX+2*finishDOC,currPos-roughDOC)
    sCode="G01 F"..tostring(plungeFeed).." X"..tostring(maxVal-roughDOC)
    mc.mcCntlGcodeExecuteWait(inst,sCode)
    currPos,rc=mc.mcAxisGetPos(inst,0)
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z0")
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      rt.rtAudio("chord")
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    currPos,rc=mc.mcAxisGetPos(inst,0)
    maxVal=math.max(endX+2*finishDOC,currPos-roughDOC)
    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
      rt.rtAudio("chord")
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z"..tostring(zNow))
    if (currPos)==endX+2*finishDOC then
      break
    end 
  end
  tr=os.difftime(os.time(),ts)/60
  mc.mcCntlSetLastError(inst,"Roughing Time: "..string.format("%.1f min",tr))

  --finish cuts
  mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(finishSpeed))
  while (mc.mcAxisGetPos(inst,0)>=(endX+finishDOC)) do
    currPos,rc=mc.mcAxisGetPos(inst,0)
    maxVal=math.max(endX,currPos-finishDOC)
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(maxVal))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      rt.rtAudio("chord")
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z0")
    currPos,rc=mc.mcAxisGetPos(inst,0)
    if currPos==endX then
      break
    end 
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(endX))
    if mc.mcSpindleGetSensorRPM(inst)==0 then
      rt.rtAudio("chord")
      wx.wxMessageBox("Spindle Stopped")
      return
    end
    mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z"..tostring(zNow))
    currPos,rc=mc.mcAxisGetPos(inst,0)
    if currPos==endX then
      break
    end 
  end
  mc.mcCntlGcodeExecuteWait(inst,"M5\nM9")
  te=(os.time()-ts)/60
  mc.mcCntlSetLastError(inst,"Roughing Time: "..string.format("%.1f min",tr).." - Total Time: "..string.format("%.1f min",te))
  local subj='Lathe'
  local msg='Roughing Complete'
  rt.sendSMS(subj,msg)
--]]
end

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



Guess what,  it still ran the old macro code that doesn't exist!!!

 
Re: Lua Fails Me
« Reply #8 on: January 19, 2018, 12:45:56 AM »
I may have an answer for you.  I just figured out a similar problem I had on my computer.  I had named a file "write_test" or something, but inside that file I had an old macro function name (M91050) that I forgot to delete, and it screwed everything up until I happened to find it.  Go through all your lua files and look for an m6691 somewhere.
Fingers crossed.
Re: Lua Fails Me
« Reply #9 on: January 20, 2018, 12:26:23 PM »
dbt3000files,

I thought you were on to something so I checked my macros directory and I had saved a copy of m6691.mcs as test.mcs.  So I changed it to test.sav so it wouldn't get compiled and deleted all mcc and bak files and fired up mach.

Ran m6691 in the mdi and same old s..t!! Drat.

I have a ticket in with MFS and James has been able to duplicate it with my package so hopefully they will find where I screwed up.