Machsupport Forum
Mach Discussion => Mach4 General Discussion => Mach4 Toolbox => Topic started by: cd_edwards on June 07, 2015, 02:49:58 PM
-
Add this to the beginning of the Screen loading script. Shamelessly stolen from someone here :)
--//////////////// This is the REQUIRED Header code, Begin //////////////////////
package.path = "./?.lua;c:/Mach4Hobby/Modules/?.mcc;" --where the module file is.
ff = require "FuncModule";--load the module file, call it ff
--/////////////// This is the REQUIRED Header code, End ///////////////////////
create this script in the Modules directory.
function autoSoftLimitsToggle (togglevalue)
local mInst = 0
local rc = 0
local inst = mc.mcGetInstance (mInst)
-- mc.mcCntlSetLastError(inst, 'In Auto Soft Limits Toggle = ');
for i=0, 11 do
if mc.mcAxisIsEnabled (inst,i) == 1 then mc.mcSoftLimitSetState (inst,i,togglevalue) end
end
end
-- End of funcModule.mcs Don't forget to compile this script Doh!
In your PLC script add the following.
package.path = "./?.lua;c:/Mach4Hobby/Modules/?.mcc;" --where the module file is.
ce = require "funcModule";--load the module file, call it ce
Near the end of the PLC add the following
if ((machSoftLimits == 1) and (machState == mc.MC_STATE_IDLE)) then
autoSoftLimitsToggle(1);
machSoftLimits = 0;
end
if (machSoftLimits == -1) then -- Don't care what the state of Mach4 is here. We just are disabling them.
autoSoftLimitsToggle(0);
machSoftLimits = 1;
end
And finally in your Ref All Home button script add the following
machSoftLimits = -1;
This will cause Soft Limits to be turned off while you are Referencing ALL Home. Once homed, Soft Limits will be re-enabled.
I attempted to run the autoSoftLimitsToggle() directly from the button. This would get rid of the machSoftLimits = -1 crap. no matter what I tried this failed.
-
if your going to put that function in a module then you need to put it in a table and return it.
i.e.:
--create this script in the Modules directory.
local MyFuncs = {}; --the table
-- |
-- |
-- \/
function MyFuncs.autoSoftLimitsToggle (togglevalue) --attach it to the table
local mInst = 0;
local rc = 0;
local inst = mc.mcGetInstance (mInst);
-- mc.mcCntlSetLastError(inst, 'In Auto Soft Limits Toggle = ');
for i=0, 11 do
if mc.mcAxisIsEnabled (inst,i) == 1 then mc.mcSoftLimitSetState (inst,i,togglevalue); end
end
end
return MyFuncs;
--save the module table and call it, funcModule.mcs
--then compile it, so that it takes on the .mcc extension
--Scott
-
Love the toggle value argument pass to the function! Great idea. alright now we are talking....global function tables! Someday I'll learn about metatables/methods too. haha.
--josh
-
Thanks poppabear. That's what I was missing. Kept telling me it was a Boolean when I was using the require function.
-
Only problem I'm having now is that SoftLimitsToggle() used for the softlimits button will not toggle. Always is on once I've run the RefAllHome.
-
use this function instead...don't place it in the button because Lua will return false as it has already executed the function while the axes are still homing. gotta put the function in the screen load up script and call it from PLC based on a flag or output status (like if axeis is homed and true then turn on output 50 // <- put in signal table)...so in plc the function call will be if output 50 = true then call your soft limits function.
rc = mc.mcAxisHomeCompleteWithStatus(
number mInst,
number axisId
number success);
-
nevermind that function, I re-wrote something else for you in the other thread.