Machsupport Forum

Mach Discussion => Mach4 General Discussion => Mach4 Toolbox => Topic started by: compewter_numerical on May 30, 2019, 10:16:04 PM

Title: Enable Soft Limits via Script
Post by: compewter_numerical on May 30, 2019, 10:16:04 PM
Hello,

I set up soft limits for XYZ axes in Mach4 config. I want to enable the soft limit feature (ie, press Soft Limits On/Off programmatically). I tried doing this in the RefAllHome function, the soft limit on/off button turns green as if it is active but I am still able to jog past the software limit into the hardware limit. When I physically press the button, the software limits work. I tried putting the software limit code into a button to test to see if it was the coroutine causing the problem but it still doesn't work properly. Is there a better way to do this? Maybe a pound var I can set directly? Any help is much appreciated.

(http://compewternumerical.com/SoftLim1.PNG)

Code: [Select]
function RefAllHome()
    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
   
    mc.mcSoftLimitSetState(inst, 0, 1)
    mc.mcSoftLimitSetState(inst, 1, 1)
    mc.mcSoftLimitSetState(inst, 2, 1)

    local softLimSig = mc.mcSignalGetHandle(inst, mc.OSIG_SOFTLIMITS_ON)
    mc.mcSignalSetState(softLimSig, 1)

    -- set G54 to table offsets @ G55
    local xOffset = mc.mcCntlGetPoundVar(inst, 5241)
    local yOffset = mc.mcCntlGetPoundVar(inst, 5242)
    local zOffset = mc.mcCntlGetPoundVar(inst, 5243)

    mc.mcCntlSetPoundVar(inst, 5221, xOffset)
    mc.mcCntlSetPoundVar(inst, 5222, yOffset)
    mc.mcCntlSetPoundVar(inst, 5223, zOffset)

    exitCondition = false
end
Title: Re: Enable Soft Limits via Script
Post by: KatzYaakov on June 20, 2019, 05:25:37 PM
did you get any answer?
i have same problem must control this from code
thanks
Title: Re: Enable Soft Limits via Script
Post by: Chaoticone on June 20, 2019, 10:32:35 PM
https://www.youtube.com/watch?v=IXuuGRACU1I

Look in the Show more for some script.
Title: Re: Enable Soft Limits via Script
Post by: compewter_numerical on June 21, 2019, 07:43:29 PM
Wow! That is awesome source thanks!

It still doesn't work for us so, I'll have to look into the screen more to find out why.

Thanks again!
Title: Re: Enable Soft Limits via Script
Post by: Stuart on June 22, 2019, 03:42:50 AM
The show all is correct but the video is wrong last two lines should be 1  not SLState

If you use industrial

You need to mod the plc script to enable coroutine.yield
And the ref all button script to call a coroutine


If that’s the case just look into the screen for a hobby and cut and paste the bits across
Title: Re: Enable Soft Limits via Script
Post by: compewter_numerical on June 22, 2019, 02:10:21 PM
I verified it's not the coroutine because the button changes state and I can print the state of the soft limits on or off with mcSoftLimitGetState but I can still bypass the soft limits when jogging. In the PLC script I already have the coroutine resume code. It was working before I updated to the latest version of Mach4. I'll try downgrading to see if that is the issue. We are using Mach4 Industrial.
Title: Re: Enable Soft Limits via Script
Post by: Stuart on June 23, 2019, 02:54:04 AM
All I can say is the latest public build that I dl did not have the yield routine in the PLC round about line 7  nor did the ref all button call the co routine


What I did was to have a look at the hobby screen checked the button code and followed the trail that the code took


Then copied the code into my modded industrial screen set my offset page fills in the WCS and Tool table into the tabs etc.

And yes I do have a industrial licence else the tabs on the offset page will not work as you cannot mod them in hobby

Stuart
Title: Re: Enable Soft Limits via Script
Post by: compewter_numerical on June 24, 2019, 02:33:49 PM
Yes sir, I did exactly that. Thank you for the help but I think it may be something else so I'll look further into it.