Hello Guest it is December 03, 2020, 06:03:13 AM

Author Topic: auto soft limits again  (Read 887 times)

0 Members and 1 Guest are viewing this topic.

auto soft limits again
« 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
              mc.mcSoftLimitSetState (inst,i,togglevalue)
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
    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

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.
    machSoftLimits = 0; -- RefAllHome() set's this for us when we need it

if (machSoftLimits == -1) then -- Don't care what the state of Mach4 is here. We just are disabling them for first run.
   machSoftLimits = 0;
« Last Edit: August 08, 2016, 02:33:57 PM by cd_edwards »