Hello Guest it is November 29, 2021, 04:23:22 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.


Messages - NeonWave

Pages: 1
1
Mach4 General Discussion / Sharing my 6 Tool Turret M6 Macro
« on: July 06, 2020, 03:35:10 AM »
Sharing this for helping others and for feedback.

Neutron lathe is retrofit with Pokeys57cnc.
6 Tools on rotation with movement/change in one direction and locking in the other.
6 Sensors on the back with a magnet to sense when the tool goes past the locking point.
An induction sensor to ensure the turret has moved fully into lock.
24V brushed DC motor with IBT_2 driver. One pin for direction one for enable. Can set motor speed with PWM on enable.

Code: [Select]
inst = mc.mcGetInstance()
-- Grabs register value in string format
function GetRegister_Str(regname)
--inst = mc.mcGetInstance()     
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))     
return mc.mcRegGetValueString(hreg)
end
-- Grabs register value in number format
function GetRegister_Num(regname)
--inst = mc.mcGetInstance()     
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))     
hreg = tonumber(hreg)
return mc.mcRegGetValueString(hreg)
end
--Writes to a register
function WriteRegister(regname, regvalue)     
--inst = mc.mcGetInstance()     
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
mc.mcRegSetValueString(hreg, tostring(regvalue))
end
--Writes to a POKEYS register
function WritePokeysReg(regname, regvalue)     
--inst = mc.mcGetInstance()     
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_42110/%s", regname))
mc.mcRegSetValueString(hreg, tostring(regvalue))
return
end
--Grabs the state of a signal
function GetSignal(signame)
--inst = mc.mcGetInstance()
local hsig = mc.mcSignalGetHandle(inst, signame)
return mc.mcSignalGetState(hsig)
end
--Writes to a signal
function WriteSignal(signame, setval)
--inst = mc.mcGetInstance()
local hsig = mc.mcSignalGetHandle(inst, signame)
mc.mcSignalSetState(hsig, setval)
return
end

function m6()
local nTools = 6
local turretMove = false
local turretLock = false
local selectedTool = mc.mcToolGetSelected(inst)
selectedTool = math.tointeger(selectedTool)
local currentTool = mc.mcToolGetCurrent(inst)
currentTool = math.tointeger(currentTool)
local toolReached = 0

--map an array of tool turret position signals to tool numbers
local Tools = {
        [1] = mc.ISIG_INPUT1,
        [2] = mc.ISIG_INPUT2,
        [3] = mc.ISIG_INPUT3,
        [4] = mc.ISIG_INPUT4,
        [5] = mc.ISIG_INPUT5,
        [6] = mc.ISIG_INPUT6}

local toolSig={}; --empty array for storing signal values

--if selected tool is invalid msg and exit
if (selectedTool>nTools) or (selectedTool<1) then
mc.mcCntlSetLastError(inst, "Invalid Tool! Must be 1-6")
do return end
end
--if tool is the same exit tool change
if selectedTool == currentTool then
mc.mcCntlSetLastError(inst, "Tools are the same no change needed!")
do return end
end
--Check if turret is locked if not msg and exit
turretLock = GetSignal(mc.ISIG_INPUT0)
--turretLock = mc.mcSignalGetState(ISIG0_hand)
if turretLock == 1 then
mc.mcCntlSetLastError(inst, "Turret may not be locking properly or lock sensor may be misaligned")
do return end
end
--Remove this line if you would not like the Z axis to move
--mc.mcCntlGcodeExecuteWait(inst, "g90 g53 g0 z0");--Move the Z axis to 400 out of the way

----Go forward until tool sensor input matches selectedTool----
WriteSignal(mc.OSIG_OUTPUT0, 1) --Set direction to move turret
--mc.mcSignalSetState(OSIG0_hand, 1)
WritePokeysReg("PWM 20 duty", 0.77)-- Set motor output PWM level ie turn motor on
turretMove = true
while (turretMove == true) do
--Grab all the states of the turret sensors
for i=1,nTools,1 do
toolSig[i] = GetSignal(Tools[i])
end
--Check if the turret sensor we want has triggered
--if so turn off motor
if toolSig[selectedTool] == 0 then
WritePokeysReg("PWM 20 duty", 0)-- Set motor OFF
turretMove = false
end
end
----lock turret in place and check locked----
WriteSignal(mc.OSIG_OUTPUT0, 0)--Set direction to lock turret
--mc.mcSignalSetState(OSIG0_hand, 0) --Set direction to lock turret
WritePokeysReg("PWM 20 duty", 0.77)-- Set motor output PWM level ie turn motor on
turretMove = true
while (turretMove == true) do
turretLock = GetSignal(mc.ISIG_INPUT0) --get lock signal
--if turret is locked and we stopped on the selected tool then all good
if (turretLock == 0) then
WritePokeysReg("PWM 20 duty", 0)-- Set motor OFF
turretMove = false
mc.mcToolSetCurrent(inst, selectedTool) --set current tool
mc.mcCntlSetLastError(inst, "Auto Tool Change Complete")
do return end
--elseif (turretLock == 0) and (toolSig[selectedTool] == 1) then
-- WritePokeysReg("PWM 20 duty", 0)-- Set motor OFF
-- turretMove = false
-- mc.mcCntlSetLastError(inst, "Tool locking error check correct tool check lock sensor")
-- do return end
--end
end
do return end
end
if (mc.mcInEditor() == 1) then
 m6()
end

IMG-20200706-172659" border="0 IMG-20200706-172708" border="0

2
Mach4 General Discussion / Re: Custom ATC M6 not running
« on: June 26, 2020, 06:31:51 AM »
Thanks Graham that was one part. The other was adding M30 to the MDI so it didn't loop.
One other thing I did wrong was creating custom functions GetSignal() etc. in the screen load script.
I tried to use these in the m6() function but they couldn't be run unless I added them to the start of the m6.mcs.
I incorrectly assumed these could be declared in the screen load script and called in a macro.
I'll post the final code here for others when I get back to the workshop next week.

3
Mach4 General Discussion / Custom ATC M6 not running
« on: June 25, 2020, 08:32:16 AM »
I have a 6 position turret toolchanger on an old lathe (pokeys57cnc retrofit) that takes a PWM signal for motor speed and IO signal for changing tools and/or locking the turret.
It also has 6 hall sensors on the back for sensing current tool and a sensor for ensuring the turret is in lock. This will be used for changing tools automatically.
I have a custom m6.mcs script in the macro folder of the lathe profile. 
Whenever I hit cycle start using any combination of TX M6 Mach4 starts doing the original manual m6.mcs that was in that folder.
Renaming/deleting the old macro didn't seem to delete it?

I don't have access to the up to date script but it looks something like the below.
Ignore how I'm handling turning the motor on I've fixed that.

Code: [Select]
function m6()
local nTools = 6
local turretMove = false
local turretLock = false
local inst = mc.mcGetInstance()
local selectedTool = mc.mcToolGetSelected(inst)
selectedTool = math.tointeger(selectedTool)
local currentTool = mc.mcToolGetCurrent(inst)
currentTool = math.tointeger(currentTool)

--map an array of tool turret position signals to tool numbers
local Tools = {
        [1] = mc.ISIG_INPUT1,
        [2] = mc.ISIG_INPUT2,
        [3] = mc.ISIG_INPUT3,
        [4] = mc.ISIG_INPUT4,
        [5] = mc.ISIG_INPUT5,
        [6] = mc.ISIG_INPUT6}

--if selected tool is invalid msg and exit
if (selectedTool>nTools) or (selectedTool<1) then
return "Tool Number out of range", false
end
--if tool is the same do nothing just exit
if selectedTool == currentTool then
return false
end
--Check if turret is locked if not msg and exit
turretLock = GetSignal(mc.ISIG_INPUT0) --gets lock signal
if turretLock == 1 then
return "Turret may not be locking properly", false
end
--Remove this line if you would not like the Z axis to move
--mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z400");--Move the Z axis to 400 out of the way

--Go forward until tool sensor input matches selectedTool
WriteSignal(mc.OSIG_OUTPUT0, 0) --Set direction to move turret
WriteSignal(mc.OSIG_OUTPUT7, 0.77) -- Set motor output PWM level ie turn motor on
turretMove = true
while (turretMove == true) do
local toolSig={}; --empty array for storing signal values
--Grab all the states of the turret sensors
for i=1,nTools,1 do
toolSig[i] = GetSignal(Tools[i])
end
--Check if the turret sensor we want has triggered
--if so turn off motor
if toolSig[selectedTool] == 0 then
WriteSignal(mc.OSIG_OUTPUT7, 0) -- turn off motor
turretMove = false
end
end
--lock turret in place and check locked
WriteSignal(mc.OSIG_OUTPUT0, 1) --Set direction to lock turret
WriteSignal(mc.OSIG_OUTPUT7, 0.77) -- Set motor output PWM level ie turn motor on
turretMove = true
while (turretMove == true) do
turretLock = GetSignal(mc.ISIG_INPUT0) --get lock signal
if turretLock == true then
WriteSignal(mc.OSIG_OUTPUT7, 0) --turn off motor
turretMove = false
end
end
mc.mcToolSetCurrent(inst, selectedTool) --set current tool
end

4
Mach4 General Discussion / Re: Limit Override Visual Indication
« on: October 03, 2018, 12:39:41 AM »
I found out why it wouldn't work.  I thought Output Signal was for a signal FROM the button and Input Signal was a signal TO the button.  It's the other way around.  And the default Limit Overide toggle button doesn't have any signals attached.  I just added an LED with Limit Overide as the Output Signal and it works fine!

5
Mach4 General Discussion / Re: Limit Override Visual Indication
« on: October 02, 2018, 06:50:58 PM »
I haven't checked, on the road at the moment, but the code to change the button color could just be in the button's script.  You may be able to edit the PLC script to toggle the button cor with your xbox controller input

I don't think that will work the default Limit Override button doesn't use scripts rather one of the built in actions which my PMC script is already toggling.

6
Mach4 General Discussion / Limit Override Visual Indication
« on: October 02, 2018, 02:34:05 AM »
I'm using an Xbox360 controller and am controlling Limit Override with a trigger.  When I press the trigger the Limit Override toggles (I know because I bumped a limit to test) but the GUI button doesn't indicate that it is enabled/disabled it just stays grey the entire time.  It only indicates when using the mouse to toggle it. 

Why does the Enable/Disable indicate correctly via the controller while the Limit OV not?  I couldn't find any relevant settings in the screen editor after a quick search.

Cheers.

Pages: 1