Hello Guest it is March 28, 2024, 08:15:17 AM

Author Topic: Soft Limits toggle  (Read 5246 times)

0 Members and 1 Guest are viewing this topic.

Soft Limits toggle
« 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.

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Soft Limits toggle
« Reply #1 on: June 07, 2015, 05:47:25 PM »
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
fun times
Re: Soft Limits toggle
« Reply #2 on: June 07, 2015, 05:49:02 PM »
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


« Last Edit: June 07, 2015, 05:53:12 PM by Screwie Louie »
Re: Soft Limits toggle
« Reply #3 on: June 07, 2015, 05:53:30 PM »
Thanks poppabear. That's what I was missing. Kept telling me it was a Boolean when I was using the require function.
Re: Soft Limits toggle
« Reply #4 on: June 07, 2015, 07:08:30 PM »
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.
Re: Soft Limits toggle
« Reply #5 on: June 07, 2015, 07:19:24 PM »
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);
Re: Soft Limits toggle
« Reply #6 on: June 08, 2015, 06:30:03 AM »
nevermind that function, I re-wrote something else for you in the other thread.