Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: cnc-kursk on February 08, 2018, 07:01:00 AM

Title: No way to switch soft limits from lua script?
Post by: cnc-kursk on February 08, 2018, 07:01:00 AM
Hi.

I use this script:
Code: [Select]
mc.mcSoftLimitSetState(inst, mc.Z_AXIS, MC_ON);
mc.mcSoftLimitSetState(inst, mc.Y_AXIS, MC_ON);
mc.mcSoftLimitSetState(inst, mc.X_AXIS, MC_ON);

1. SoftLimit not worked.
2. No Output signal:
Code: [Select]
[mc.OSIG_SOFTLIMITS_ON] = function (state)
    mc.mcCntlSetLastError(inst,"OSIG_SOFTLIMITS_ON " .. tostring(state));
    if( state == 1) then
       scr.SetProperty('tbtnSoftLimits', 'Button state', '0');
    else
       scr.SetProperty('tbtnSoftLimits', 'Button state', '1');
    end
end,

If I switch by button action, softlimits are worked and OSIG_SOFTLIMITS_ON triggered.

Possible need switch softlimits globally?
Can I switch softlimits by code?

M4 ver.4.2.0.3658

Title: Re: No way to switch soft limits from lua script?
Post by: Cbyrdtopper on February 08, 2018, 09:03:38 AM
I will be watching this thread.  I tried to turn on the soft limits with an Initialize Code on startup.  It never worked properly.  It would turn the button Yellow, like I had pressed it, but it wouldn't actually turn the soft limits on.  Frustrating.

That would be a nice feature.  Have an option to have soft limits turn on as a default from the general config.
Title: Re: No way to switch soft limits from lua script?
Post by: Overloaded on February 08, 2018, 09:13:40 AM
Anything to do with the axis needing to be referenced first ?
Don't see it mentioned in above examples.
(might have overlooked it though)
Title: Re: No way to switch soft limits from lua script?
Post by: bryannab on February 08, 2018, 09:14:31 AM
I'm going to be including this in a homing/soft limits video in the near future, but it may help with what you're trying to do. Replacing the Ref All Home chunk in the screen load script with the following will turn the soft limits on immediately after homing.

Code: [Select]
---------------------------------------------------------------
-- Ref All Home() function.
---------------------------------------------------------------
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
    ----See ref all home button and plc script for coroutine.create and coroutine.resume
    wx.wxMessageBox('Referencing is complete.\nSoft Limits Set.')
    SetSoftlimits()
end

-------------------------------------------------------
--  Set Soft Limits
-------------------------------------------------------
function SetSoftlimits()
    for v = 0, 5, 1 do --start, end, increment
        mc.mcSoftLimitSetState(inst, v, mc.MC_ON)
        
    end
    scr.SetProperty("tbtnSoftLimits", "Button State", tostring(SLState))
    scr.SetProperty("tbSoftLimits", "Button State", tostring(SLState))
    
end
Title: Re: No way to switch soft limits from lua script?
Post by: Cbyrdtopper on February 08, 2018, 09:21:41 AM
Thanks Bryanna.
Title: Re: No way to switch soft limits from lua script?
Post by: thosj on February 08, 2018, 09:34:26 AM
Whoa Bryanna, been sitting thinking on how to do exactly that just lately. Thanks a LOT  :D

IMHO, Mach4 should just DO that, but there are likely reasons to NOT do it by default, like people not having soft limits configured!!!

Anyway, I'll be implementing this TODAY. I might have to do something differently because I've modified my Ref All Home script in the screen load script a bit already, so hopefully I can figure it out.

Thanks again, I'm actually starting to finally LIKE Mach4!

Tom
Title: Re: No way to switch soft limits from lua script?
Post by: DazTheGas on February 08, 2018, 11:35:43 AM
Heres a topic from the past that might help.

http://www.machsupport.com/forum/index.php/topic,33813.0.html

DazTheGas
Title: Re: No way to switch soft limits from lua script?
Post by: joeaverage on February 08, 2018, 06:42:27 PM
Hi Tom,

Quote
Thanks again, I'm actually starting to finally LIKE Mach4!

it took a wee while but once I started to make progress with Mach/Lua I felt exactly the same way.

Craig
Title: Re: No way to switch soft limits from lua script?
Post by: cnc-kursk on February 09, 2018, 03:45:31 AM
Hi, Bryanna.

I'm going to be including this in a homing/soft limits video in the near future, but it may help with what you're trying to do.

My script very similar (on top page).
Please check, IRL softlimits after mcSoftLimitSetState are ON?
Why OSIG_SOFTLIMITS_ON doesn't triggered?
Title: Re: No way to switch soft limits from lua script?
Post by: DazTheGas on February 09, 2018, 04:48:56 AM
Had a quick look today and spotted the small mistake MC_ON should be mc.MC_ON

mc.mcSoftLimitSetState(inst, mc.Z_AXIS, mc.MC_ON);
mc.mcSoftLimitSetState(inst, mc.Y_AXIS, mc.MC_ON);
mc.mcSoftLimitSetState(inst, mc.X_AXIS, mc.MC_ON);

DazTheGas
Title: Re: No way to switch soft limits from lua script?
Post by: cnc-kursk on February 09, 2018, 06:11:44 AM
 ::)

Thanks.
Title: Re: No way to switch soft limits from lua script?
Post by: MegaMoog on February 09, 2018, 04:46:56 PM
ThanX Bryanna...... that works great....
All it took was a quick copy n paste n all was good!

Sometimes I was forgettin to turn on soft limits n would go the WRONG DIRECTION by mistake n work through the recover / limits over ride stuff after the HOMING sequence!

Your a life saver.... probably a RED one. LOL

MegaMoog :)