Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: cd_edwards on August 08, 2016, 02:32:23 PM
-
I don't pretend to be a programmer all that often anymore, but this was needed I believe. This will set Soft Limits off before a RefAllHome(). And after the RefAllHome() is done set it back on so you don't forget to do it.
create a mcSoftLimits.lua in your modules directory with the following
-- mcSoftLimits.lua
-- local CDFuncs = {}
function autoSoftLimitsToggle (togglevalue)
local mInst = 0
local rc = 0
local inst = mc.mcGetInstance (mInst)
-- mc.mcCntlSetLastError(inst, string.format('In Auto Soft Limits Toggle = ' .. togglevalue));
for i=0, 11 do
if mc.mcAxisIsEnabled (inst,i) == 1
then
mc.mcSoftLimitSetState (inst,i,togglevalue)
end
end
end -- of mcSoftLimits.lua
Now in your screenset load script. This script is only run once, and we need an initial value for the variable.
machSoftLimits = -1 -- add this near the top of the script
Now find RefAllHome() and add the two lines to it.
function RefAllHome()
autoSoftLimitsToggle(0) -- ****** ADD we want to make sure and turn this off at this point.
mc.mcAxisDerefAll(inst) --Just to turn off all ref leds
mc.mcAxisHomeAll(inst)
coroutine.yield() --yield coroutine so we can do the following after motion stops
----See ref all home button and plc script for coroutine.create and coroutine.resume
wx.wxMessageBox('Referencing is complete')
machSoftLimits = 1 -- ******* ADD this line to your RefAllHome() function
end
Add this in the section that loads required modules.
package.loaded.SoftLimits = nil
sl = require "mcSoftLimits"
Finally at the bottom of your PLC script add the following
if ((machSoftLimits == 1) and (machState == mc.MC_STATE_IDLE)) then -- after we finish the toggle, set machSoftLimits to 0 so we don't come back here until needed.
autoSoftLimitsToggle(1);
machSoftLimits = 0; -- RefAllHome() set's this for us when we need it
end
if (machSoftLimits == -1) then -- Don't care what the state of Mach4 is here. We just are disabling them for first run.
autoSoftLimitsToggle(0);
machSoftLimits = 0;
end
-
Hi Colten,
Thank you for the tip I need. ;)
Would you let me know what exactly "Add this in the section that loads required modules."? Which file or script, and where should I open?
-
I know your going to hate this but can I say it again :) PMC! You can do that in the PMC! PMC solve everything :) I guess I need to start making examples....
-
PMC, PMC, PMC!!!!!!
Can you tell that I love the PMC!
Thanks for implementing something that doesn't require me to learn LUA when I already understand ladder logic.
Mike
-
Brian and Totally,
I understand what you are saying but I personally want to know how to do this stuff in Lua.
I am sure some things can not be done in PMC.
Bill
-
cd_edwards,
I did something similar depending on if they Referenced the machine.
If they did Reference the machine soft limits are active if they did not the soft limits are inactive.
Good job on the code.
Bill