Hello Guest it is June 15, 2025, 02:10:43 PM

Author Topic: Automatic Soft Limit Activation Code Question  (Read 890 times)

0 Members and 1 Guest are viewing this topic.

Automatic Soft Limit Activation Code Question
« on: April 29, 2025, 10:33:12 AM »
I added the script from the video posted in 2018 and it doesn't activate the soft limits.  I checked the script for the Ref All Home button and it only has RefAllHome() in it.  Did the coroutine script get removed in a later version of Mach4?  I can't find what it should be anywhere.  According to the new script there should be something for the coroutine in it, I thought.

----See ref all home button and plc script for coroutine.create and coroutine.resume
Re: Automatic Soft Limit Activation Code Question
« Reply #1 on: May 19, 2025, 08:51:46 AM »
It is in the screen load script; you add it to the code there.
To get to it, see attached picture.
Open the script and search "refall"; you'll find the code that is embedded in the RefAll button.
modify the script there.  You can't modify the script in the button since this edited script adds the "sefsoftlimits" fuction.
Chad Byrd
Re: Automatic Soft Limit Activation Code Question
« Reply #2 on: May 22, 2025, 08:41:59 AM »
Chad, I added the code they have in the video to that already. My question was about the coroutine that the code references.  There is nothing like that in the ref all home button script, so it doesn't work.
Re: Automatic Soft Limit Activation Code Question
« Reply #3 on: May 22, 2025, 09:29:53 AM »
It doesn’t need it in the routine it is a function by itself, called one time in the refall function.  Did you make sure to add the SofimitsSet() or whatever the function is called to the bottom of the refallfunction?

I add this to nearly every machine I put mach4 on and have never had a problem, I’m talking about 15+ machines.
Chad Byrd
Re: Automatic Soft Limit Activation Code Question
« Reply #4 on: May 22, 2025, 09:43:50 AM »
Thanks Chad, I'll check it out.
Re: Automatic Soft Limit Activation Code Question
« Reply #5 on: May 22, 2025, 09:45:33 AM »
There are two changes to the refall function. The text in the message box line ir code to tell you the soft limits are now active and the set soft limits function gets called.
Chad Byrd
Re: Automatic Soft Limit Activation Code Question
« Reply #6 on: May 22, 2025, 09:49:40 AM »
Here's what I have in it:

---------------------------------------------------------------
-- 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(1))
    scr.SetProperty("tbSoftLimits", "Button State", tostring(1))
   
end
Re: Automatic Soft Limit Activation Code Question
« Reply #7 on: May 22, 2025, 10:07:44 AM »
Alright, I checked your code against what I have on a machine in the shop and what I have on my desktop for testing and it is all the same. 
So, let's back up and make sure the RefAll() Function works as intended.  Does it reference all the axis of you machine like it should?
Chad Byrd