Hello Guest it is March 28, 2024, 08:30:10 PM

Author Topic: VB script converstion to Mach4  (Read 2130 times)

0 Members and 1 Guest are viewing this topic.

VB script converstion to Mach4
« on: January 19, 2019, 12:57:35 PM »
Hello!

I am in process of upgrading my Lathe to Mach4.  Unfortunately I have a non-standard toolchanger that was part of the original commercial machine.  With a lot of forum help I was able to get a VB script that works the toolchanger perfectly, and now I need to make it work in Mach4 if I want to upgrade.  It is a 4-position horizontal rotary tool changer, air activated, which only rotates one direction (counterclockwise as viewed from above). I have a VBscript for Mach3 which was developed with forum help and it works perfectly. I am looking to migrate this to Mach4. Any help with converting this would be great. Following so some background info on how it works to help understand the VB script.

The turret has one each input and output switches. Output 2 is a momentary relay which starts the toolchanger to cycle one 90 degree step. Input 2 is active when air pressure is missing (checked at beginning of script) and also is active while turret is cycling between steps. Tools are assigned by basis of each face (some faces can hold more than one tool, so tool in same face is given next number increment of plus 4). A math function is used to calculate the current face and face requested, (ToolNumber-1) Mod 4, and also to calculate number of steps needed (see below).

'M6Start.m1s

If IsActive(Input2) Then
MachMsg ("Connect Air Pressure to Turret!!","Turret Index Warning",MachMsgTypeOK)
End If

selectedTool = GetSelectedTool()
currentTool = GetCurrentTool()
currentFace = (currentTool - 1) Mod 4
targetFace = (selectedTool - 1) Mod 4

'rotate turret required number of "clicks"
For click = 1 To (targetFace - currentFace + 4) Mod 4 'rotate accounting for rollover

ActivateSignal(Output2) 'activate momentary command to rotate
Sleep (500)
DeActivateSignal(Output2) 'deactivate momentary command and wait for movement signal
Sleep (1500)
While IsActive(Input2) 'wait for turret to stop
Sleep (100)
Wend
Next

'not forgetting to update to the new tool
SetCurrentTool selectedTool

Any help would be appreciated.
Thanks!

Offline reuelt

*
  •  520 520
    • View Profile
Re: VB script converstion to Mach4
« Reply #1 on: April 27, 2019, 01:30:13 AM »
"Any help would be appreciated"

Hi
I have just translated your m6start.mls (for MACH3)
to m6.mcs  (for MACH4)

It is an OFF THE CUFF draft, so you need to check for syntax errors with the zerobrane editor and do all the debugging by yourself and/or with the help of others.
Without knowing what will be your MACH4 motion controller, I can only do this much.


 ‘m6.mcs - untested
function m6()
local inst = mc.mcGetInstance()
local hsig = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEFWD)
local spinstate = mc.mcSignalGetState(hsig)
[mc.ISIG_INPUT2]=function(input2State)
local SelectedTool = mc.mcToolGetSelected(inst)
local CurrentTool = mc.mcToolGetCurrent(inst)
local TurretClickOut =  mc.mcSignalGetHandle (inst,mc.OSIG_OUTPUT2)
local Turretsig = mc.mcSignalGetHandle(inst, TurretClickOut)
------ Get current state ------
local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)
if input2State ==1 then
mc.mcCntlSetLastError(inst, string.format(‘Connect Air Pressure to Turret!!'))
   else
mc.mcCntlSetLastError(inst, string.format(‘Turret Index Warning '))
   end
end
currentFace = (currentTool - 1) % 4
targetFace = (selectedTool - 1) % 4
'rotate turret required number of "clicks"
For click = 1, (targetFace - currentFace + 4) % 4,1  'rotate accounting for rollover
Do
mc.mcSignalSetState(Turretsig, 1)
wx.wxMilliSleep(500)
mc.mcSignalSetState(Turretsig, 0)
wx.wxMilliSleep(1500)
if input2State ==1 then
wx.wxMilliSleep(100)
end
end
return
"the gift of God is eternal life through Jesus Christ our Lord"
Re: VB script converstion to Mach4
« Reply #2 on: April 27, 2019, 07:40:50 AM »
reuelt;

Thank you very much, I will take a look at debugging and try running it! 

Not sure if it matters but I am running an ethernet smoothstepper with PMDX 126 BOB. 

Thanks again.