With all the drives running happily, I switched back to the machine build and Mach 4.
I wanted to break the ice with LUA scripting in MAch 4 so I found a nice example of how to accomplish a timer and used it to get my power drawbar working.
There will be a nice faceplate on the machine when I get it running (first project!), but for now the drawbar pushbutton hangs out of the front. It is an Allen Bradley 800FP series flush operator with N.O. contacts
The PDB is mounted and air tight, but the drawbar needs a simple operation of the lathe and the beville spring washers installed. I want to make sure the cylinder works 100% before I do this last step.
Side view showing the routed pneumatic hoses and AC servo connectors. The servo cables need to be routed still.
Here is the solenoid hooked up. Again it is a 5 port, 4 way, 3 position, center exhausting valve. What this means is that the air cylinder can be driven both in and out, but when neither valve is energized the cylinder vents to the atmosphere and remains depressurized.
Cables will tuck behind the mounting plate. A little organization is needed.
M12 cable attached to the output port. Second order of business once this machine is up and running will be to route out some label tags.
Now for the code:
In the Mach 4 screen load LUA script, I added the following code:
--------------------------------------
-- PDB Timer Code --
--------------------------------------
PDBTimerPanel = wx.wxPanel (wx.Null, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize )
--This line creates a Window which has properties exposed to Win10. This window will not appear on screen, but the Windows event will be tied to it.
PDBTimer = wx.wxTimer(PDBTimerPanel)
--This line creates the actual timer 'PDBTimer' which will be referenced throughout the code
PDBTimerPanel:Connect(wx.wxEVT_TIMER,
function(event)
local PDBRetract, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2) -- Is mapped to ESS PDB Retract
mc.mcSignalSetState(PDBRetract, 0)
mc.mcCntlSetLastError(inst, "PDB Retracted")
PDBTimer:Stop()
end)
This creates a hidden "Window" which is a Windows object. Once this is made, you can take advantage of the Windows event timer to create a delay which does not use any processor time to track. Once the timer expires, the code inside the function(event) will be run. This code writes to the PDB retract output to shut it off, displays a message at the bottom of the control, and kills the timer so it doesn't continue to loop.
In the Signals LUA script, I added the following code:
---------------------------------------------------------------
-- Power Drawbar Pushbutton
---------------------------------------------------------------
if (sig == mc.ISIG_INPUT3) and (state == 1) then
local PDBExtend, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT0)
mc.mcSignalSetState(PDBExtend, 1)
mc.mcCntlSetLastError(inst, "PDB Retracted")
end
if (sig == mc.ISIG_INPUT3) and (state == 0) then
local PDBExtend, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT0)
local PDBRetract, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2)
mc.mcSignalSetState(PDBExtend, 0)
mc.mcSignalSetState(PDBRetract, 1)
PDBTimer:Start(500)
mc.mcCntlSetLastError(inst, "PDB Timer Started")
end
Whenever any change in signal state is detected by Mach 4, the signal script runs. By checking which signal was changed, you can execute particular chunks of code. In this case, if the changed signal was the PDB pushbutton AND the pushbutton is active, set the output PDB Extend HIGH. This energizes the "A" side of the solenoid and extends the cylinder. If the changed signal was the PDB pushbutton AND the pushbutton is not active, then the extend output is turned off, the retract output is turned on, and the timer created above is started (with an expiration time of 500ms). This causes the cylinder to retract, and that output will shut off and depressurize the cylinder 500ms later.
It is a little more complicated that the PLC stuff I normally use, but not too bad.
Finally I made a simple sheet metal bracket that will trigger the Y++ limit switch.
Poor lighting, but the switch will mount on the base casting and trigger when the folded flag gets close by.
Sorry about all the dark photos, I had already turned most of the lights off and forgot to take pictures.