Hello Guest it is March 29, 2024, 09:16:39 AM

Author Topic: auto soft limits again  (Read 2148 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
        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
« Last Edit: August 08, 2016, 02:33:57 PM by cd_edwards »
Re: auto soft limits again
« Reply #1 on: February 08, 2021, 11:05:55 AM »
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?
Re: auto soft limits again
« Reply #2 on: February 08, 2021, 12:18:55 PM »
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....
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com
Re: auto soft limits again
« Reply #3 on: February 23, 2021, 06:13:41 AM »
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
We never have the time or money to do it right the first time, but we somehow manage to do it twice and then spend the money to get it right.

Offline Bill_O

*
  •  563 563
    • View Profile
Re: auto soft limits again
« Reply #4 on: February 23, 2021, 05:22:11 PM »
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

Offline Bill_O

*
  •  563 563
    • View Profile
Re: auto soft limits again
« Reply #5 on: February 23, 2021, 05:28:24 PM »
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