Stop button performs an automatic feed hold
Mach4 controls Step/Dir spindles. When you press the stop button, EVERYTHING stops instantly., which is why it clunks to a stop. I am not sure why Mach4 then commands the Step//Dir spindle to go back to the speed it was at before decelerating to a stop.
However, the real problem is that you are pressing the Stop button on the scree set. You should never do that directly. You should always Feed Hold first, and then press the stop button. Feed hold will decelerate everything to a nice controlled stop, at which point you may press the stop button.
If you need to do an emergency stop, then you pres the Red EStop button.
Some people can't help themselves, and will always press the red stop button on the screen, instead of the Feed hold first. In that case you could modify the lua script for the stop button to call the lua PLC script of the screen set. In a function in there, it would first call feed hold, and then once the motors stopped, it would automatically call the Stop function.
Step 1
Start editing the screen.
Step 2
Open the Screen Load Script, by clicking in the area just to the right of where it says "Screen Load Script". Then click on the "..." that appears. In the Screen Load Script, add these next two lines near the top, in order to create global variables:
FeedHoldAndThenStop = 0
FeedHoldRequested = 0
Go to Menu -> Project -> Compile and make sure that no errors are reported.
Save and close this script.
Step 3
Open the PLC Script, by clicking in the area just to the right of where it says "PLC Script". Then click on the "..." that appears.
The PLC script will run at your PLC Interval (frequency ) which defaults to 50 Hz. You don't want to declare a global variables in here, but local variables (that will be overwritten every time) are fine. This is where you will add this script functionality, to request the FeedHold before the CycleStop.
---------------------------------------------------------
--- Feed Hold Before Cycle Stop code
---------------------------------------------------------
if (FeedHoldAndThenStop >= 3) then
mc.mcCntlLog(inst, "Screen set PLC: Stop button pressed 3 times, calling CycleStop()", "", -1)
CycleStop()
FeedHoldAndThenStop = 0
FeedHoldRequested = 0
elseif (FeedHoldAndThenStop > 0) and (FeedHoldAndThenStop < 3) then
if (FeedHoldRequested < 1) then
-- Feed hold once before stopping
mc.mcCntlLog(inst, "FHBC: Stop button pressed, but calling Feed Hold before cycle stop", "", -1)
mc.mcCntlFeedHold(inst)
FeedHoldRequested = 1
end
-- Check if axes are still
local allStill = true
for i = 0, 5 do
local isEnabled, rc = mc.mcAxisIsEnabled(inst, i)
if (rc == mc.MERROR_NOERROR) and (isEnabled == 1) then
local isStill, rc = mc.mcAxisIsStill(inst, i)
if (rc == mc.MERROR_NOERROR) and (isStill ~= 1) then
allStill = false
break
end
end
end
if allStill then
FeedHoldAndThenStop = 0
FeedHoldRequested = 0
mc.mcCntlLog(inst, "FHBC: Motors still, now calling CycleStop()", "", -1)
CycleStop()
end
end
Go to Menu -> Project -> Compile and make sure that no errors are reported.
Save and close this script.
Step 4
3. In the Red Stop Button, edit the Left Up Script (or whichever script it is using) so that it no longer calls CycleStop(). Mine looks like this:
Add this code to the script area:
--CycleStop()
local inst = mc.mcGetInstance("Cycle Stop button");
FeedHoldAndThenStop = FeedHoldAndThenStop + 1
mystring = "Cycle Stop requesting Feed Hold #" .. FeedHoldAndThenStop
mc.mcCntlLog(inst, mystring, "", -1)
Go to Menu -> Project -> Compile and make sure that no errors are reported.
Save and close this script
The reason we do the FeedHoldAndThenStop = FeedHoldAndThenStop + 1 is so that it could count up to 2 or 3.... In the loop checking to see if the motors are still, the if (FeedHoldAndThenStop >= 3) then will see that it is a panic situation and just stop the motors since the user was clicking frantically, because they wanted an EStop.
Step 5
Close out of the Screen editor by clicking:
Click "Yes" to save your changes. If you click "No", they will all be lost.
Step 6
Test the Stop button while you are moving, and you should see that it now feed holds instead of stops.