Hello Guest it is March 28, 2024, 04:26:49 PM

Author Topic: Predefined action does not perform the expected operation "Zero X"  (Read 2289 times)

0 Members and 1 Guest are viewing this topic.

Offline Bx3mE

*
  •  68 68
    • View Profile
My problem is that when i press "Zero Y" the dro changes its value from the current value to 570.000, 575 or a random (to me) position after restarting mach4.

Steps to reproduce:
Turn on and enable the machine.
Ref. All Home
- I have a custom script see below RefAllHomeWithOffset()
press Zero X (or Zero Y or Zero Z) one of them will fail with this wired behaviour.

The value changes if i run my M6 Script. Machine coordinates are still correct.

I have a PMDX-126 and a Warp9td ESS.
I Run Windows 10 Pro version 20H2
Mach Version is 4.2.0 build 4574
I completly rebuilt my machine and started with a new profile based on the Mach4Mill Profile.

I tried to find where the actions are defined but can not find any information in the API Documentation or in the scripting or Operation manuals.
If i change the button to just run the RefAllHomeWithOffset() without creating a coroutine and remove all Yield commands it homes but does not execute any gcode. Zero Y behaviour is still setting the DRO to 570.0000 or 575.0000
The only place where i can remember using this value (570.0000) is in the RefAllHomeWithOffset script.


Here are my scripts:
ScreenLoad additions:

---------------------------------------------------------------
-- Set Soft Limits () function.
---------------------------------------------------------------
function SetSoftLimits(inst, state)  -- legal params = 0 and 1.
    --local inst = mc.mcGetInstance (mInst)
    for i=0, (11) do
        if mc.mcAxisIsEnabled (inst,i) == 1 and state == 1
then mc.mcSoftLimitSetState (inst,i,1) end
if mc.mcAxisIsEnabled (inst,i) == 1 and state == 0
then mc.mcSoftLimitSetState (inst,i,0) end
    end
end
---------------------------------------------------------------
-- Ref All Home With Offset() function.
---------------------------------------------------------------
function RefAllHomeWithOffset()

    SetSoftLimits(inst,0)
    mc.mcAxisDerefAll(inst)
    mc.mcAxisHomeAll(inst)
    coroutine.yield() --yield coroutine so we can do the following after motion stops
    mc.mcCntlGcodeExecuteWait(inst, "G92 X-5 Y575 Z5")
    wx.wxMessageBox('Referencing is complete')
    mc.mcCntlGcodeExecuteWait(inst, "G1 X0 Y570 Z0 F2000")
    SetSoftLimits(inst,1)

end





m6 Script:
function m6()
local inst = mc.mcGetInstance()
if mc.mcAxisIsHomed(inst, 0) and mc.mcAxisIsHomed(inst, 1) and mc.mcAxisIsHomed(inst, 2) and mc.mcAxisIsHomed(inst, 3) then
M6SetSoftLimits(inst,0)
local changeToTool = mc.mcToolGetSelected(inst)
local changeFromTool = mc.mcToolGetCurrent(inst)
local XPositionBeforeToolChange = mc.mcAxisGetPos(inst,0)
local YPositionBeforeToolChange = mc.mcAxisGetPos(inst,1)
local XToolProbePosition = "17.0"
local YToolProbePosition = "0.3"
local XManualToolChangePosition = "17.0"
local YManualToolChangePosition = "0.3"
local ColletAtProbeZCoordinate = -248 -- Machine Z-coordinate when collet tip touches TouchPlate (Must be more than ProbeOperationDistance - DefaultToolLength
local ExtraProbeDistance = 15 -- SafetyMargin
local ProbeOperationDistance = -30 -- Length of Probemove before giving up
local ProbePrepSpeed = 750
local ProbeSpeed = 100
local DefaultToolLength = 70 -- Used if tool info is not found. (Should be a value slightly longer than the longest tool in the shop :D)
-- QUICK REFERENCE
-- G90 - Absolute (Go to coordinate)
-- G91 - Incremental (Godistance along axis from current position)
-- G53 - Machine Coordinate Move
wx.wxMessageBox("ToolChange from T"..changeFromTool.." to T"..changeToTool.." Press OK to run M6 cript")
if changeToTool == changeFromTool then
mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
return
else
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0\nM5" )
RunProbe(inst,changeFromTool,XToolProbePosition,YToolProbePosition,DefaultToolLength,ColletAtProbeZCoordinate,ExtraProbeDistance,ProbePrepSpeed,ProbeSpeed,ProbeOperationDistance)
local ToolZCoordinate = mc.mcAxisGetPos(inst,2)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0 \n G90 G53 G0 X"..XManualToolChangePosition.." Y"..YManualToolChangePosition)
local changeToToolDescription = mc.mcToolGetDesc(inst,changeToTool)
wx.wxMessageBox("Please change to tool number "..changeToTool.." "..changeToToolDescription.." and press ok to continue")
RunProbe(inst,changeToTool,XToolProbePosition,YToolProbePosition,DefaultToolLength,ColletAtProbeZCoordinate,ExtraProbeDistance,ProbePrepSpeed,ProbeSpeed,ProbeOperationDistance)
mc.mcAxisSetPos(inst, 2 , ToolZCoordinate)
mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X"..XPositionBeforeToolChange.." Y"..YPositionBeforeToolChange)
mc.mcToolSetCurrent(inst, changeToTool)
wx.wxMessageBox("If Toolchange was Sucessful - click ok to continue")
mc.mcCntlSetLastError(inst, "ToolChange Finished")
end
M6SetSoftLimits(inst,0)
else
wx.wxMessageBox("M6 Toolchange can not run Machine is not Referenced to home. All operations should be aborted!!!")
end
end

function RunProbe(finst,ftool,fXToolProbePosition,fYToolProbePosition,fDefaultToolLength,fColletAtProbeZCoordinate,fExtraProbeDistance,fProbePrepSpeed,fProbeSpeed,fProbeOperationDistance)
    mc.mcCntlGcodeExecuteWait(finst, "G90 G53 G0 X"..fXToolProbePosition.." Y"..fYToolProbePosition)
    local toollen = mc.mcToolGetData(finst, mc.MTOOL_MILL_HEIGHT, ftool)
    if toollen == 0 then
        toollen = fDefaultToolLength
        mc.mcCntlSetLastError(finst, "Tool length not found - using Default Length")
    end
    local probestart = fColletAtProbeZCoordinate + fExtraProbeDistance + toollen
    local GCODE = "G91 G31 G0 Z"..probestart.." F"..fProbePrepSpeed
    GCODE = ""..GCODE.." \n G91 G0 Z1 F"..fProbePrepSpeed.." \n G91 G31 Z"..fProbeOperationDistance.." F"..fProbeSpeed
    mc.mcCntlGcodeExecuteWait(finst,GCODE)
end

function M6SetSoftLimits(inst, state)  -- legal params = 0 and 1. They are the X and Y extents
    --local inst = mc.mcGetInstance (mInst)
    for i=0, (11) do
        if mc.mcAxisIsEnabled (inst,i) == 1 and state == 1
then mc.mcSoftLimitSetState (inst,i,1) end
if mc.mcAxisIsEnabled (inst,i) == 1 and state == 0
then mc.mcSoftLimitSetState (inst,i,0) end
    end
end

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



Offline Bx3mE

*
  •  68 68
    • View Profile
Re: Predefined action does not perform the expected operation "Zero X"
« Reply #1 on: January 21, 2021, 09:23:26 AM »
It seems that any position update i do like 'mc.mcCntlGcodeExecuteWait(inst, "G92 X-5 Y575 Z5")' or 'mc.mcCntlGcodeExecute(inst, "G54 X0 Y570 Z0")' within the RefAllWithOffset coroutine theese values seem to stick to the Zero Action.

I have tried all Yield implementations like:
-no yield , results in mcCntlGcodeExecute not running
-yield after homing, results in mcCntlGcodeExecute executing as expected buy Zeroing Y does not work until Mach4 is restarted
-yield after homing and after mcCntlGcodeExecute, results in erratic or unpredictable behavior like machine crashing into Y Limit switch.
--yield only after mcCntlGcodeExecute results in mcCntlGcodeExecute not running.
What can be the error?

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Predefined action does not perform the expected operation "Zero X"
« Reply #2 on: January 21, 2021, 09:58:23 AM »
I did a lot of custom stuff in our mach4.
The script has a lot of extra stuff but it does work to zero everything and then do a move.

Here is the code from my Referance button;
-RefAllHome()
wait = coroutine.create (RefAllHome) --Run the RefAllHome function as a coroutine named wait.
--See RefAllHome function in screen load script for coroutine.yield and PLC script for coroutine.resume


Here is my script from RefAllHome;
---------------------------------------------------------------
-- Ref All Home() function.
---------------------------------------------------------------
function RefAllHome()
   
   --turn off max depth
   local MaxDepRegH = mc.mcRegGetHandle(inst, 'iRegs0/MaxDepth')
   mc.mcRegSetValue(MaxDepRegH, -22.0)
   mc.mcCntlSetParameter(1801, -22.0)
   scr.SetProperty('ledMaxDepth', 'Value', '1')
   --  set head shift to 0
   mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_X, 0.000)
   mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Y, 0.000)
   mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Z, 0.000)
   --turn off Tang
   mc.mcCntlGetParameter(502)
   mc.mcCntlSetParameter(502, 0) --tk off
   mc.mcCntlSetLastError(inst, 'TK OFF')
    mc.mcAxisDerefAll(inst)  --Just to turn off all ref leds
   mc.mcCntlGcodeExecuteWait(inst, "G49") --turn off tool height comp
   --set Project Home 1 registers and led to 0
   hreg = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm1Set')
   mc.mcRegSetValue(hreg, 0)
   scr.SetProperty('ledProjHm1Set', 'Value', '0')
   hreg1X = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm1X')
   mc.mcRegSetValue(hreg1X, 0)
   hreg1Y = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm1Y')
   mc.mcRegSetValue(hreg1Y, 0)
   --set Project Home 2 registers and led to 0
   hreg = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm2Set')
   mc.mcRegSetValue(hreg, 0)
   scr.SetProperty('ledProjHm2Set', 'Value', '0')
   hreg2X = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm2X')
   mc.mcRegSetValue(hreg2X, 0)
   hreg2Y = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm2Y')
   mc.mcRegSetValue(hreg2Y, 0)
   --set Surface register and led to 0
   hreg = mc.mcRegGetHandle(inst, 'iRegs0/SurfSet')
   mc.mcRegSetValue(hreg, 0)
   scr.SetProperty('ledSurfaceSet', 'Value', '0')
   --reference all
    mc.mcAxisHomeAll(inst)
    coroutine.yield() --yield coroutine so we can do the following after motion stops
    ----See ref all home button and plc script for coroutine.create and coroutine.resume
    -------------------------------------------------
   --set machine home register to 1
   hreg = mc.mcRegGetHandle(inst, 'iRegs0/MachHmd')
   mc.mcRegSetValue(hreg, 1)
   -----------------------------------------------
   --set extra cut depth to 0 and turn off leds
   local Extrareg = mc.mcRegGetHandle(inst, 'iRegs0/ExtraDepth')
   mc.mcRegSetValue(Extrareg, 0)
   mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Z, 0.000)
   scr.SetProperty('led010', 'Value', '0')
   scr.SetProperty('led030', 'Value', '0')
   scr.SetProperty('led050', 'Value', '0')
   --Set all positions to 0
   mc.mcCntlGcodeExecute(inst, "G53")
   mc.mcCntlGcodeExecute(inst, "G92 x0.0y0.0z0.0a0.0")
   mc.mcCntlGcodeExecute(inst, "G54")
   mc.mcCntlGcodeExecute(inst, "G92 x0.0y0.0z0.0a0.0")
   mc.mcAxisSetPos(inst, 0, 0.0)
   mc.mcAxisSetPos(inst, 1, 0.0)
   mc.mcAxisSetPos(inst, 2, 0.0)
   mc.mcAxisSetPos(inst, 3, 0.0)
   mc.mcAxisSetHomeOffset(inst, 0, 0.0)
   mc.mcAxisSetHomeOffset(inst, 1, 0.0)
   mc.mcAxisSetHomeOffset(inst, 2, 0.0)
   mc.mcAxisSetHomeOffset(inst, 3, 0.0)
   mc.mcCntlGcodeExecute(inst, "G53")
   mc.mcCntlGcodeExecute(inst, "G92 x0.0y0.0z0.0a0.0")
   mc.mcCntlGcodeExecute(inst, "G54")
   mc.mcCntlGcodeExecuteWait(inst, "G92 x0.0y0.0z0.0a0.0")
   mc.mcCntlGcodeExecuteWait(inst, "G1 x0.1 y0.1 F100.0")
   wx.wxMilliSleep(100)
   --rewind file
   mc.mcCntlRewindFile(inst)
   --regenerate toolpath
   mc.mcToolPathGenerate(inst)
end

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Predefined action does not perform the expected operation "Zero X"
« Reply #3 on: January 21, 2021, 10:09:50 AM »
And here is my zero for the Zero X.
I do both x and y at the same time.

Button;
wait = coroutine.create (SetWorkZero)

Function script;
Once again a lot of extra stuff.
---------------------------------------------------------------------------
--Set Work Zero() function
-----------------------------------------------------------------------------
function SetWorkZero()
   --remove head shifts
   mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_X, 0.000)
   mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Y, 0.000)
   --get offset number
   local hregPHN = mc.mcRegGetHandle(inst, 'iRegs0/ProjHmPos')
   local ProjHmNum = mc.mcRegGetValue(hregPHN)
   if (ProjHmNum == 1) then
      --turn project home 1 set led off
      scr.SetProperty('ledProjHm1Set', 'Value', '0')
      --set to project coordinates
      mc.mcCntlGcodeExecute (inst, "g54")
      --set coordinates to 0
      mc.mcAxisSetPos(inst, 0, 0.0)
      mc.mcAxisSetPos(inst, 1, 0.0)
      --get and set 1x offset
      local Offset1X = mc.mcCntlGetOffset(inst, 0, 5201)
      hregX1 = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm1X')
      mc.mcRegSetValue(hregX1, Offset1X)
      --get and set 1y offset
      local Offset1Y = mc.mcCntlGetOffset(inst, 1, 5201)
      hregY1 = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm1Y')
      mc.mcRegSetValue(hregY1, Offset1Y)
      
      --set Project Home 1 register to 1
      hreg = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm1Set')
      mc.mcRegSetValue(hreg, 1)
      --turn project home 1 set led on
      scr.SetProperty('ledProjHm1Set', 'Value', '1')
      
      --rewind file
      mc.mcCntlRewindFile(inst)
      
      --regenerate toolpath
      mc.mcToolPathGenerate(inst)
      
   end
   if (ProjHmNum == 2) then
      --turn project home 2 set led off
      scr.SetProperty('ledProjHm2Set', 'Value', '0')
      --set to project coordinates
      mc.mcCntlGcodeExecute (inst, "g54")
      --set coordinates to 0
      mc.mcAxisSetPos(inst, 0, 0.0)
      mc.mcAxisSetPos(inst, 1, 0.0)
      --get and set 1x offset
      local Offset2X = mc.mcCntlGetOffset(inst, 0, 5201)
      hregX2 = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm2X')
      mc.mcRegSetValue(hregX2, Offset2X)
      --get and set 2y offset
      local Offset2Y = mc.mcCntlGetOffset(inst, 1, 5201)
      hregY2 = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm2Y')
      mc.mcRegSetValue(hregY2, Offset2Y)
      
      --set Project Home 2 register to 1
      hreg = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm2Set')
      mc.mcRegSetValue(hreg, 1)
      --turn project home 2 set led on
      scr.SetProperty('ledProjHm2Set', 'Value', '1')
      
      --rewind file
      mc.mcCntlRewindFile(inst)
      
      --regenerate toolpath
      mc.mcToolPathGenerate(inst)
      
   end
end

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Predefined action does not perform the expected operation "Zero X"
« Reply #4 on: January 21, 2021, 10:12:46 AM »
And last my M6;
function m6()
   local inst = mc.mcGetInstance()
   --get registers
   local hregMHmd = mc.mcRegGetHandle(inst, 'iRegs0/MachHmd')
   local valMHmd = mc.mcRegGetValue(hregMHmd)
   local ATCReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCOnOff')
   local ATCRegVal = mc.mcRegGetValue(ATCReg)
   local MTCReg = mc.mcRegGetHandle(inst, 'iRegs0/ManToolChg')
   local MTCRegVal = mc.mcRegGetValue(MTCReg)
   local ATCClrReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCZClear')
   local ATCClrVal = mc.mcRegGetValue(ATCClrReg)
   local ATCDnReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCZDown')
   local ATCDnVal = mc.mcRegGetValue(ATCDnReg)
   local ATCYP1Reg = mc.mcRegGetHandle(inst, 'iRegs0/ATCYPos1')
   local ATCYP1Val = mc.mcRegGetValue(ATCYP1Reg)
   local ATCYPDReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCYPosDist')
   local ATCYPDVal = mc.mcRegGetValue(ATCYPDReg)
   local ATCMaxTlsReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCMaxTools')
   local ATCMaxTlsVal = mc.mcRegGetValue(ATCMaxTlsReg)
   
   local ATCToolHReg = mc.mcRegGetHandle(inst, 'iRegs0/ATCToolHolder')
   
   --tk signals
   local TKSSigH = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT7)
   local TKOSigH = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT8)
   local TKOscSigH = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9)
   
   --tk registers
   local TKSReg = mc.mcRegGetHandle(inst, 'iRegs0/TKStdOnOff')
   local TKOReg = mc.mcRegGetHandle(inst, 'iRegs0/TKOscOnOff')
   local TKOnOffReg = mc.mcRegGetHandle(inst, 'iRegs0/TKOnOff')
   local TKOnOffVal = mc.mcRegGetValue(TKOnOffReg)
   
   --get tool numbers
   local NewTool = mc.mcToolGetSelected(inst)
   local OldTool = mc.mcToolGetCurrent(inst)
   
   --if max depth set turn off
   local MinZRegH = mc.mcRegGetHandle(inst, 'iRegs0/MaxDepth')
   local MinZ2RegH = mc.mcRegGetHandle(inst, 'iRegs0/MaxDepth2')
   local MinZ = mc.mcCntlGetParameter(1801)
   if (MinZ >= -20.0) then
      mc.mcRegSetValue(MinZ2RegH, MinZ)
      mc.mcCntlSetParameter(1801, -22.0)
      mc.mcRegSetValue(MinZRegH, -22.0)
   end
   
   --if new tool is in range do atc / mtc
   if (NewTool <= ATCMaxTlsVal) or (NewTool == 100) or (NewTool == 101) or (NewTool == 102) then
      --if manual tool change off do atc
      if (MTCRegVal == 0) then
         --if new tool is same as old tool
         if (NewTool == OldTool) then
            mc.mcCntlSetLastError(inst, "Same Tool")
         else   
            --turn off tool comp and change to machine coordanants
            mc.mcCntlGcodeExecuteWait(inst, "g49")
            mc.mcCntlGcodeExecuteWait(inst, "g53")
            
            --if mist on turn off and set MistWasON
            local hMistWas = mc.mcSignalGetHandle(inst, mc.OSIG_MISTON)
            local MistWasVal = mc.mcSignalGetState(hMistWas)
            mc.mcSignalSetState(hMistWas, 0)
            if (MistWasVal == 1) then
               local hrMistWas = mc.mcRegGetHandle(inst, 'iRegs0/MistWasOn')
               mc.mcRegSetValue(hrMistWas, 1)
            elseif (MistWasVal == 0) then
               local hrMistWas = mc.mcRegGetHandle(inst, 'iRegs0/MistWasOn')
               mc.mcRegSetValue(hrMistWas, 0)
            end
            
            --if spindle on turn off and set SpinWasOn
            local hSpinWas = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON)
            local SpinWasVal = mc.mcSignalGetState(hSpinWas)
            mc.mcSignalSetState(hSpinWas, 0)
            if (SpinWasVal == 1) then
               local hrSpinWas = mc.mcRegGetHandle(inst, 'iRegs0/SpinWasOn')
               mc.mcRegSetValue(hrSpinWas, 1)
               
               local hrSpinType = mc.mcRegGetHandle(inst, 'iRegs0/SpindleType')
               local SpinType = mc.mcRegGetValue(hrSpinType)
               if (SpinType == 0) then
                  wx.wxMilliSleep(1500)
               elseif (SpinType == 1) then
                  wx.wxMilliSleep(5500)
               elseif (SpinType == 2) then
                  wx.wxMilliSleep(28000)
               end
               
            elseif (SpinWasVal == 0) then
               local hrSpinWas = mc.mcRegGetHandle(inst, 'iRegs0/SpinWasOn')
               mc.mcRegSetValue(hrSpinWas, 0)
            end
            
            --if machine homed and atc on do tool change
            if (valMHmd == 1) and (ATCRegVal == 1) then
               local NewTool = mc.mcToolGetSelected(inst)
               local OldTool = mc.mcToolGetCurrent(inst)
            
               --is new tool camera
               if (NewTool == 100) then
                  --wx.wxMessageBox("Camera")
                  mc.mcCntlSetLastError(inst, "CAMERA")
            
                  -- do shift to cam position
                  headshift()

                  --put current tool in tool holder and set current tool to 100
                  if (OldTool <= ATCMaxTlsVal) then
                     mc.mcRegSetValue(ATCToolHReg, OldTool)
                  end
                  mc.mcToolSetCurrent(inst, 100)

               --is new tool Tang Knife Standard
               elseif (NewTool == 101) then
            
                  -- do shift to tks position
                  headshift()
                  --lift head to clear for knife lower
                  local TempTKPos = string.format("G0 G53 Z"..ATCDnVal)
                  mc.mcCntlGcodeExecuteWait(inst, TempTKPos)
                  
                  --wx.wxMessageBox("Tang Knife Std")
                  mc.mcCntlSetLastError(inst, "TANG KNIFE STD")
                  --put current tool in tool holder and set current tool to 101
                  if (OldTool <= ATCMaxTlsVal) then
                     mc.mcRegSetValue(ATCToolHReg, OldTool)
                  end
                  mc.mcToolSetCurrent(inst, 101)
                  --turn on tk mode
                  mc.mcCntlSetParameter(502, 1)
                  mc.mcRegSetValue(TKOnOffReg, 1)
                  
                  --turn on and off tks reg and signals
                  mc.mcRegSetValue(TKOReg, 0)
                  mc.mcRegSetValue(TKSReg, 1)
                  mc.mcSignalSetState(TKSSigH, 1)
                  mc.mcSignalSetState(TKOSigH, 0)
                  mc.mcSignalSetState(TKOscSigH, 0)
                  
               --is new tool Tang Knife Oscillating
               elseif (NewTool == 102) then
         
                  headshift()
                  --lift head to clear for knife lower
                  local TempTKPos = string.format("G0 G53 Z"..ATCDnVal)
                  mc.mcCntlGcodeExecuteWait(inst, TempTKPos)
                  
                  mc.mcCntlSetLastError(inst, "TANG KNIFE OSC")
                  
                  --put current tool in tool holder and set current tool to 102
                  if (OldTool <= ATCMaxTlsVal) then
                     mc.mcRegSetValue(ATCToolHReg, OldTool)
                  end
                  mc.mcToolSetCurrent(inst, 102)
                  --turn on tk mode
                  mc.mcCntlSetParameter(502, 1)
                  mc.mcRegSetValue(TKOnOffReg, 1)
                  
                  --turn on and off tko reg and signals
                  mc.mcRegSetValue(TKOReg, 1)
                  mc.mcRegSetValue(TKSReg, 0)
                  mc.mcSignalSetState(TKSSigH, 0)
                  mc.mcSignalSetState(TKOSigH, 1)
                  mc.mcSignalSetState(TKOscSigH, 1)
                  
                  -- do shift to tko position
                  
               --is new tool atc tool
               elseif (NewTool >= 1) and (NewTool <= ATCMaxTlsVal) then
                  
                  --if old tool is cam, tks or tko then put old tool back to tool holder value
                  if (OldTool == 100) or (OldTool == 101) or (OldTool == 102) then
               
                     headshift()
                     
                     local ATCToolHolder = mc.mcRegGetValue(ATCToolHReg)
                     OldTool = ATCToolHolder
                     --turn off tk mode
                     mc.mcCntlSetParameter(502, 0)
                     --retract tks and tko
                     local TKSRetReg = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT7)
                     local TKORetReg = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT8)
                     local TKOOscReg = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9)
                     mc.mcSignalSetState(TKSRetReg, 0)
                     mc.mcSignalSetState(TKORetReg, 0)
                     mc.mcSignalSetState(TKOOscReg, 0)
                     --set registers to tk off
                     local TKStdReg = mc.mcRegGetHandle(inst, 'iRegs0/TKStdOnOff')
                     local TKOscReg = mc.mcRegGetHandle(inst, 'iRegs0/TKOscOnOff')
                     local TKOOReg  = mc.mcRegGetHandle(inst, 'iRegs0/TKOsc')
                     mc.mcRegSetValue(TKStdReg, 0)
                     mc.mcRegSetValue(TKOscReg, 0)
                     mc.mcRegSetValue(TKOOReg, 0)
                     --turn off tk mode
                     mc.mcCntlSetParameter(502, 0)
                     mc.mcRegSetValue(TKOnOffReg, 0)
                     --turn on and off tks and tko reg and signals
                     mc.mcRegSetValue(TKOReg, 0)
                     mc.mcRegSetValue(TKSReg, 0)
                  end
                  
                  --if old tool is not cam, tks or tko drop old tool
                  if (NewTool == OldTool) then
                     mc.mcCntlSetLastError(inst, "SAME TOOL TO DROP")
                  else
                  if (OldTool <= ATCMaxTlsVal) then
                     --get tool drop position
                     local TempToolMinus = (OldTool - 1)
                     local TempToolDist = (TempToolMinus * ATCYPDVal)
                     local YTempPos = (ATCYP1Val + TempToolDist)
                     --move to tool drop position
                     local TempDropPos = string.format("G0 G53 Y"..YTempPos.."Z"..ATCDnVal)
                     mc.mcCntlGcodeExecuteWait(inst, TempDropPos)
                     --fire rack
                     local Rackhsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT6)
                     mc.mcSignalSetState(Rackhsig, 1)
                     wx.wxMilliSleep(3000)
                     --drop tool
                     local DBarhsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5)
                     mc.mcSignalSetState(DBarhsig, 1)
                     wx.wxMilliSleep(1000)
                     --raise z to clear
                     ZTempUpPos = string.format("G0 G53 Z"..ATCClrVal)
                     mc.mcCntlGcodeExecuteWait(inst, ZTempUpPos)
                     --retract rack to clear
                     local Rackhsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT6)
                     mc.mcSignalSetState(Rackhsig, 0)
                     wx.wxMilliSleep(2250)
                  end
                  end
                  -- if new tool is standard atc number pick up new tool
                  if (NewTool == OldTool) then
                     mc.mcCntlSetLastError(inst, "SAME TOOL TO PICK")
                  else
                  if (NewTool <= ATCMaxTlsVal) then   
                     --fire draw bar
                     local DBarhsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5)
                     mc.mcSignalSetState(DBarhsig, 1)
                     --get tool pickup position
                     local TempToolMinus = (NewTool - 1)
                     local TempToolDist = (TempToolMinus * ATCYPDVal)
                     local YTempPos = (ATCYP1Val + TempToolDist)
                     --move to tool pickup position
                     local TempGrabPos = string.format("G0 G53 Y"..YTempPos.."Z"..ATCClrVal)
                     mc.mcCntlGcodeExecuteWait(inst, TempGrabPos)
                     --fire rack
                     local Rackhsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT6)
                     mc.mcSignalSetState(Rackhsig, 1)
                     wx.wxMilliSleep(3000)
                     --lower z to grab
                     ZTempDnPos = string.format("G0 G53 Z"..ATCDnVal)
                     mc.mcCntlGcodeExecuteWait(inst, ZTempDnPos)
                     --grab tool
                     local DBarhsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5)
                     mc.mcSignalSetState(DBarhsig, 0)
                     wx.wxMilliSleep(1000)
                     --retract rack to clear
                     local Rackhsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT6)
                     mc.mcSignalSetState(Rackhsig, 0)
                     wx.wxMilliSleep(2250)
                  end
                  end
               end
            end
         end
         mc.mcToolSetCurrent(inst, NewTool)
         wx.wxMilliSleep(10)
         mc.mcCntlGcodeExecuteWait(inst, "g54")
         mc.mcCntlGcodeExecuteWait(inst, string.format("G43 H" .. tostring(NewTool)))
         --if mist was on turn back on
         local hrMistWas = mc.mcRegGetHandle(inst, 'iRegs0/MistWasOn')
         local MistWasVal = mc.mcRegGetValue(hrMistWas)
         if (MistWasVal == 1) then
            local hMistWas = mc.mcSignalGetHandle(inst, mc.OSIG_MISTON)
            mc.mcSignalSetState(hMistWas, 1)
         end   
      else
         --manual tool change
         mc.mcCntlGcodeExecuteWait(inst, "G49")
         --raise z
         MTCPos = mc.mcAxisGetPos(inst, 2)
         MTCPos = (MTCPos + .5)
         mc.mcCntlGcodeExecuteWait(inst, string.format("G0 Z" .. tostring(MTCPos)))
         --stop spindle
         local hSpindle = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON)
         mc.mcSignalSetState(hSpindle, 0)         
         --wx.wxMessageBox("Manual Tool Change")
         mc.mcCntlToolChangeManual(inst, true)
--         wx.wxMessageBox("Replace Tool\nSurface Tool")
--         --set surface register to 0
--         hreg = mc.mcRegGetHandle(inst, 'iRegs0/SurfSet')
--         mc.mcRegSetValue(hreg, 0)
--         --turn surface set led off
--         scr.SetProperty('ledSurfaceSet', 'Value', '0')
         
--         SMHit == 0
         
         --surface
--         --get sm on or off register
--         local SMReg = mc.mcRegGetHandle(inst, 'iRegs0/SMOnOff')
--         local SMRegVal = mc.mcRegGetValue(SMReg)
--         mc.mcCntlGcodeExecuteWait(inst, "G49")
--         mc.mcToolSetCurrent(inst, 0)
--         --surface tool
--         --If SM turned OFF
--         if (SMRegVal == 0) then
            --set to 0 and lift 0.5
            wx.wxMilliSleep(100)
            mc.mcAxisSetPos(inst, 2, 0.0)
            wx.wxMilliSleep(100)
            mc.mcCntlGcodeExecuteWait(inst, "g0 z0.5")
--            mc.mcCntlMdiExecute(inst, "g0 z0.5")
            wx.wxMilliSleep(500)
--            SMHit = 1
--         end
--         --If SM turned ON
--         if (SMRegVal == 1) then
--            --set jog speed to 100%
--            scr.SetProperty('sliJogRate', 'Value', tostring(100))
--            --wx.wxMessageBox("SM Used")
--            mc.mcCntlGcodeExecuteWait(inst, "g31 z-8.0 f20.0")
--            --check to see if sm hit
--            SMHit = 0
--            SMHit, rc = mc.mcCntlProbeGetStrikeStatus(inst)
--            if (SMHit == 1) then
--               mc.mcAxisSetPos(inst, 2, 1.5)
--               --wx.wxMilliSleep(100)
--               mc.mcCntlGcodeExecuteWait(inst, "g0 z2.0")
--            else
--               wx.wxMessageBox("DID NOT HIT SURFACE MOUSE")
--               wx.wxMessageBox("MUST CLICK RESET BEFORE NEXT ATTEMPT")
--            end
--         end

--         if (SMHit == 1) then
--            hreg = mc.mcRegGetHandle(inst, 'iRegs0/SurfSet')
--            mc.mcRegSetValue(hreg, 1)
--            --turn surface set led on
--            scr.SetProperty('ledSurfaceSet', 'Value', '1')
--         end
--         mc.mcCntlToolChangeManual(inst, true)
      end   
   else
      --tool number out of range
      wx.wxMessageBox("New Tool Number is too large.")
      mc.mcCntlCycleStop(inst)
   end   
   local MinZTemp = mc.mcRegGetValue(MinZ2RegH)
   if (MinZTemp >= -20.0) then
      mc.mcCntlSetParameter(1801, tonumber(MinZTemp))
      mc.mcRegSetValue(MinZRegH, MinZTemp)
      mc.mcRegSetValue(MinZ2RegH, -22.0)
   end
end
if (mc.mcInEditor() == 1) then
   m6()
end

Offline Bx3mE

*
  •  68 68
    • View Profile
Re: Predefined action does not perform the expected operation "Zero X"
« Reply #5 on: January 21, 2021, 04:01:51 PM »
Thanks a million for the feedback! I have serveral Questions and one feedback back...

I notice a lot of differences in your approach. But this makes me think that i have issues with the ESS which will require me to do some waiting in the script. Also i had to install c++ Redist after Mach installation which was not optimal so i will test your script (the parts i need :) ) and see if the behavior persists, and also try a reinstall.

Also i see you only yield once after Homing - I will pursue this route.

Also why do you do: (Is this not handled by the mc.mcAxisHomeAll?)
   --set machine home register to 1
   hreg = mc.mcRegGetHandle(inst, 'iRegs0/MachHmd')
   mc.mcRegSetValue(hreg, 1)
   -----------------------------------------------

And why do you do:  (G53 and G54 two times, why? Is setting G53 coords to "0" not handled by the mc.mcAxisHomeAll? same for mc.mcAxisSetPos? mc.mcAxisSetHomeOffsetis for plugin? and why the sleep?)
 --Set all positions to 0
   mc.mcCntlGcodeExecute(inst, "G53")
   mc.mcCntlGcodeExecute(inst, "G92 x0.0y0.0z0.0a0.0")
   mc.mcCntlGcodeExecute(inst, "G54")
   mc.mcCntlGcodeExecute(inst, "G92 x0.0y0.0z0.0a0.0")
   mc.mcAxisSetPos(inst, 0, 0.0)
   mc.mcAxisSetPos(inst, 1, 0.0)
   mc.mcAxisSetPos(inst, 2, 0.0)
   mc.mcAxisSetPos(inst, 3, 0.0)
   mc.mcAxisSetHomeOffset(inst, 0, 0.0)
   mc.mcAxisSetHomeOffset(inst, 1, 0.0)
   mc.mcAxisSetHomeOffset(inst, 2, 0.0)
   mc.mcAxisSetHomeOffset(inst, 3, 0.0)
   mc.mcCntlGcodeExecute(inst, "G53")
   mc.mcCntlGcodeExecute(inst, "G92 x0.0y0.0z0.0a0.0")
   mc.mcCntlGcodeExecute(inst, "G54")
   mc.mcCntlGcodeExecuteWait(inst, "G92 x0.0y0.0z0.0a0.0")
   mc.mcCntlGcodeExecuteWait(inst, "G1 x0.1 y0.1 F100.0")
   wx.wxMilliSleep(100)

One notice:
In the API reference it states:
calling multiple mc.mcCntlGcodeExecute in a row is considered an error
so if you ever change the code you might consider changing:
   mc.mcCntlGcodeExecute(inst, "G53")
   mc.mcCntlGcodeExecute(inst, "G92 x0.0y0.0z0.0a0.0")
   mc.mcCntlGcodeExecute(inst, "G54")
   mc.mcCntlGcodeExecute(inst, "G92 x0.0y0.0z0.0a0.0")
to
 mc.mcCntlGcodeExecute(inst, "G53\nG92 x0.0y0.0z0.0a0.0\nG54\nG92 x0.0y0.0z0.0a0.0")
and if adding any following "G1" commands include them as well and change to mcCntlGcodeExecuteWait for entire string...

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Predefined action does not perform the expected operation "Zero X"
« Reply #6 on: January 21, 2021, 04:47:48 PM »
The register  hreg = mc.mcRegGetHandle(inst, 'iRegs0/MachHmd')  is just a register i made and use in other scripts to ensure the machine has been Referenced.

I do the G53 and G54 two times because i was noticing occasionally depending on what happened before some settings were not actually changing to zero. This fixed that problem and it is no time at all for the pc to perform. I do not remember why i put the sleep in.

I do know how to do the multiple lines of code like you showed it is just harder for me to read so i dont. Lazy

Offline Bx3mE

*
  •  68 68
    • View Profile
Re: Predefined action does not perform the expected operation "Zero X"
« Reply #7 on: January 21, 2021, 05:38:20 PM »
Ok so iRegs0 is your custom register..... and i guessed that G53/G54 duplicates where some workaround thanks for confirming

What i meant with mcCntlGcodeExecute was that if you do two consecutive calls to the function it is not guaranteed that the first call is executed before the second one executes which in your case would be G53 is commanded but not executet when a new execution request arrives G92 X.... and cancels the first G53. The result is that G92 X... will be applied to whatever Workoffset was active before. So unpredictable behaviour which might be the reason you added it two times in the first place :)

so: mcCntlGcodeExecute once with multiple line string (like G53\nG1X1) is ok, consecutive mcCntlGcodeExecuteWait calls are ok BUT consecutive mcCntlGcodeExecute calls are not ok as they might cancel eachother...
If readabillity is an issue i suggest concat strings... ...but hey im lazy too :)

Thanks to your examples i can now RefAllHomeWithOffset and from what i can see everything works except the Zero X, Zero Y, Zero Z buttons from the mill screen. Pressing them before pressing the RefAllHomeButton shows they are working but after pressing the RefAllHomeButton and the referencing is complete they nolonger work as expected. ZeroX sets X DRO to -5 Zero Y sets Y DRO to -5 and Zero Z sets Z DRO to 5. I guess that ill have to live with this and change the button action to none and creating my own script instead...

Re: Predefined action does not perform the expected operation "Zero X"
« Reply #8 on: January 22, 2021, 04:11:24 AM »
I believe the issue you are seeing is because you are using G92. If you explain what you are trying to do with the offsets etc. someone may be able find an alternative method to achieve it
Re: Predefined action does not perform the expected operation "Zero X"
« Reply #9 on: January 22, 2021, 11:20:27 PM »
Offsets, gosh I like offsets! I can tell you that G92 and the fixture offsets system can not be used together. If you want to do shifts G52 is the best. We also have work shifts, head shift and tool offsets for every axis (yes tool offsets are not just for the z anymore). So please tell us what the end goal is and we will tell you what system will best do it for you.
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com