Hello Guest it is May 07, 2021, 07:23:02 AM

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.


Topics - AXYZ_WI

Pages: 1
1
I have a toggle switch set up to to change the value of a register when the switch is up its a 1 and when the switch is down its a 0, that value is written to the profile ini.
Heres the button code, down sets it to 0 and up, a 1.

Code: [Select]
local inst = mc.mcGetInstance() -- Get the instance of Mach4
local setter = 0
mc.mcProfileWriteString(inst, "Tool Setter", "Probe", string.format (setter))

The register value is used in my M6 to either use the tool setter or a movable touch plate.
 
What I would like to do is to read that register value and change the state of the toggle switch based on that value during Mach4 startup, if its a 1 the switch state is up and visa versa.

I tried putting the following code in the screen load script

Code: [Select]
local setter = mc.mcProfileGetString(inst, "Tool Setter", "Probe", "setter")
setter = tonumber(setter)
if setter == 1 then
scr.SetProperty('tog_setter','Botton State', 'Up')
else
scr.SetProperty('tog_setter','Botton State', 'Down')
end

But that failed to change the state of the button. As it stands there is a possibility that the feedback from the toggle switch and the actual value of the register are not the same and the machine can act differently then what the operator expects. Any insight would be appreciated.

Thanks
Josh

2
Mach4 Toolbox / M6 Tool change for the rest of us.
« on: March 29, 2020, 05:21:34 PM »
Here's my Mach4 tool change. I took many concepts from others on this forum so thank you. It has user parameters that let you tell it if you use a tool setter permanently located or a movable touch plate.  You can also tell it it you control the spindle or if Mach4 does with M3/M5 commands.

Here's a video of it in action and a quick explanation of the code.

https://youtu.be/kVqPkZG9ha4

Quote
-----------------------------------------------TLAR SMART TOOL CHANGE - Rev.1 03/2020------------------------------------------------------------
---------------------------https://www.youtube.com/channel/UCVMC1IaXdFonuWAGrmyUNmg?view_as=subscriber-------------------------------------------
------------------This tool change script assumes your spindle uses a collet and collet nut to retain the tool.----------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------Before continuing, insure your input signals and mapping are correct---------------------------------------------
------Manual tool change uses a G31 command, AutoTool change with the tool setter uses a G31.1 command. The difference is the imput signal!!-----
function M6()
   local inst = mc.mcGetInstance();
   -------------------------------------------User inputs--------------------------------------------------------------------------------------
   local ManualChange = false             --True for manual change false for auto change You ****YOU MUST HAVE RELIABLE HOMING X Y and Z FOR AUTO TOOL CHANGE!!****
   local SpindleControl = true           -- Can Mach4 controll your spindle? True for M3/M5commands, false for manual spindle control.
   --------------------------------Auto Tool Change specific----------------------------------------------------------------------------------
   local xprobe = 93.6                    --Machine Coordinate of the tool setter on X axis
   local yprobe = 2.375               --Machine Coordinate of the tool setter on Y axis
   local XToolchangePosition = 93.6332    --Machine Coordinate of where you want to change your tool on X axis
   local YToolchangePosition = 5          --Machine Coordinate of where you want to change your tool on Y axis
   ------------------------------------Tool information----------------------------------------------------------------------------------------
   local DefaultToolLength = 2            -- Must be at least as long or longer then your longest tool This is what's used if your tool table is not filled in.
   local ColletAtProbeZCoordinate = -6.07 -- This is the distance from home Z must travel for the collet without a tool to hit the tool setter
   local ExtraProbeDistance = .75         -- This is your margin of error the smaller this number the larger the pucker factor.
   local ProbePrepSpeed = 20              -- This is how fast Z travels before it slows down to probe. The larger this number, the larger the pucker factor.
   local ProbeOperationDistance = -2.25   -- This is how far Z will move while looking for a probe hit.
   local ProbeSpeed = 5                   -- This is how fast Z will probe at. Keep this number small for acuracy.
   local SpindleDwell = 10000             -- this is the amount of time to wait in microseconds for the spindle to stop or start spinning. Example is 10 seconds
--------------------------------------End of user input-----------------------------------------------------------------------------------------   
    local selectedtool = mc.mcToolGetSelected(inst)
    local currenttool = mc.mcToolGetCurrent(inst)
    local xstart = mc.mcAxisGetPos(inst,0)
    local ystart = mc.mcAxisGetPos(inst,1)
   
   if selectedtool == currenttool then
      mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required, That Looks About Right")
   return
   end
   mc.mcCntlSetLastError(inst, "TLAR Smart Tool Change Activated!")
   if SpindleControl == true then
      mc.mcCntlGcodeExecute(inst, "M5 G4 P"..SpindleDwell)
   else
      wx.wxMessageBox("Turn off your spindle\nClick ok to continue.")
   end
   
   if ManualChange == true then
      wx.wxMessageBox("Click OK, Then Jog to A Safe Tool Change Position\nJog Z axiz close to the touch plate,\nThen Click Cycle Start.","Click OK to continue")
      mc.mcCntlToolChangeManual(inst,true)
   else
      mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0 \n G90 G53 G0 Y"..yprobe.."\n G90 G53 G0 X"..xprobe)
   end
   
   RunProbe(currenttool, DefaultToolLength, ColletAtProbeZCoordinate, ExtraProbeDistance, ProbePrepSpeed, ProbeOperationDistance, ProbeSpeed, ManualChange)
    local toolz = mc.mcAxisGetPos(inst,2)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
   
   if ManualChange == false then
      mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X"..XToolchangePosition.."Y"..YToolchangePosition)
   end
   
    local changetoo = mc.mcToolGetDesc(inst,selectedtool)
    wx.wxMessageBox("Please change too tool number "..selectedtool.."\n "..changetoo.." and press ok to continue")
   
   if ManualChange == true then
      wx.wxMessageBox("Click OK, Then jog Z axis close to the touch plate and press Cycle Start.\nClick OK to Continue ")
      mc.mcCntlToolChangeManual(inst,true)   
   else
      mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 X"..xprobe.."Y"..yprobe)
   end
   
   RunProbe(selectedtool, DefaultToolLength, ColletAtProbeZCoordinate, ExtraProbeDistance, ProbePrepSpeed, ProbeOperationDistance, ProbeSpeed, ManualChange)
    mc.mcAxisSetPos(inst, 2 ,toolz)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
   
   if ManualChange == true then
      wx.wxMessageBox("Remove touch plate and aligator clip from router\nGantry will move and motor will spin and continue GCode\nPress ok to Continue")
   end
   
    mc.mcToolSetCurrent(inst, selectedtool)
   
   if SpindleControl == true then
      mc.mcCntlGcodeExecute(inst, "M3 G4 P"..SpindleDwell)
   else
      wx.wxMessageBox("Turn on spindle\nClick ok to continue")
   end
   mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X"..xstart.." Y"..ystart)
    mc.mcCntlSetLastError(inst, "TLAR Smart ToolChange Finished")

end

function RunProbe(tool, DefaultToolLength, ColletAtProbeZCoordinate, ExtraProbeDistance, ProbePrepSpeed, ProbeOperationDistance, ProbeSpeed, ManualChange)
    local inst = mc.mcGetInstance()
    local toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, tool)
      if toollen == 0 then toollen = DefaultToolLength -- User Preference
      mc.mcCntlSetLastError(inst, "Changing to default tool length Fill in your tool table!")
      end
    local probestart = ColletAtProbeZCoordinate + ExtraProbeDistance + toollen
      if ManualChange == true then
         mc.mcCntlGcodeExecuteWait(inst,"G91 G31 Z"..ProbeOperationDistance.." F"..ProbeSpeed)
      else
         mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."F"..ProbePrepSpeed.."\n G91 G31.1 Z"..ProbeOperationDistance.." F"..ProbeSpeed)
      end
end
if (mc.mcInEditor() == 1)
then M6()
end
--Rev 1 Change log.
   --Added Spindle Control true/false
   --Added manualChange true/false
   --Added SpindleDwell parameter

Pages: 1