Machsupport Forum

Mach Discussion => Mach4 General Discussion => Mach4 Videos => Topic started by: DazTheGas on December 13, 2016, 03:54:53 PM

Title: Creating a function for the Screen Load Script
Post by: DazTheGas on December 13, 2016, 03:54:53 PM
Ever wanted a function to run in the PLC but not sure how to do it well try this way.

Click Here For Video (https://youtu.be/--Y0pKOz2ao)




Code: [Select]
local inst = mc.mcGetInstance()

mc.MC_ALL = 20

function SetSoftLimits(axis, state)
    local m_axis = 0
if axis == mc.MC_ALL then
repeat
enabled = mc.mcAxisIsEnabled(inst, m_axis)
if enabled == 1 then
mc.mcSoftLimitSetState(inst, m_axis, state)
end
m_axis = m_axis + 1
        until(m_axis == 6)
    else
        mc.mcSoftLimitSetState(inst, axis, state)
    end
end

SetSoftLimits(mc.MC_ALL, mc.MC_ON)

DazTheGas
Title: Re: Creating a function for the Screen Load Script
Post by: thespindoctor on December 13, 2016, 07:46:24 PM
DaztheGas,

I tried your nice script in the screen load and in the PLC script but nothing happens.  Not sure why.

 My version placed in the PLC script works.
 
     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);
Title: Re: Creating a function for the Screen Load Script
Post by: thespindoctor on December 13, 2016, 08:17:08 PM
Sure helped to watch the video.  I learned so much!  Thanks for the time you spent to make the video!

Keith
Title: Re: Creating a function for the Screen Load Script
Post by: Fledermaus on December 14, 2016, 07:16:09 AM
Great video Daz.

A point I havn't seen mentioned is that soft limits are defined as machine coordinates. Consequently, if the machine has not been homed these values will be incorrect and may not afford the expected protection. For this reason, I set soft limits on within the signal table, on receipt of  the signal that the axis has been homed. Just another way to skin that cat.

Allan
Title: Re: Creating a function for the Screen Load Script
Post by: DazTheGas on December 14, 2016, 07:45:16 AM
Thats a good point, prob could do with another if statement in the function like mcAxisIsHomed.

DazTheGas
Title: Re: Creating a function for the Screen Load Script
Post by: thespindoctor on December 14, 2016, 09:59:50 AM
This is an interesting issue of ref axes vs soft limits.  I feel that we don't need to look for referencing of axes because no machining should be done before referencing all axes.  I don't feel it would be safe to automatically ref the axes at startup and prefer to turn on the machine then reference as a purposeful move myself, if all is well.  So there never would be a time when there would be a conflict.  Therefore it seems unnecessary to look for referencing before applying soft limits.  Does that make sense?  Am I missing a condition where as an OEM developer that my users are going to get into trouble?  Thanks!

Keith
Title: Re: Creating a function for the Screen Load Script
Post by: Chaoticone on December 14, 2016, 10:01:11 AM
Could you run the soft limits enable function from the Ref All home function? Maybe twice........... once at beginning to disable then again after motion stops to enable?
Title: Re: Creating a function for the Screen Load Script
Post by: Chaoticone on December 14, 2016, 10:10:37 AM
If I was selling machines I would force a reference when needed, no doubt about it. Reset would force a dereference and only slow jogging would be allowed until referenced. Soft limimts would be active at all times........ unless referencing.
Title: Re: Creating a function for the Screen Load Script
Post by: thespindoctor on December 14, 2016, 10:46:50 AM
I like the idea of referencing first then forcing soft limits and some way to disable the machine until referencing is done.
Title: Re: Creating a function for the Screen Load Script
Post by: DazTheGas on December 14, 2016, 10:58:49 AM
Quote
no machining should be done before referencing all axes.

Well I have to admit, the fact that I know I have proximity switches kind of makes me lazy and dont always home the machine as small parts I just zero the axis. This being said it is good practice to home the machine.

I like Chaoticone`s idea of using the ref home btn as this would benefit those who use softlimits whether it be just for max limit - min limit - or home in place even, this combined with the ref home button flashing in red if any defined axis is not homed.

DazTheGas
Title: Re: Creating a function for the Screen Load Script
Post by: thespindoctor on December 14, 2016, 11:34:52 AM
So we put in the soft limits code as done by Daz in the load script and first run of Plc but add code to code plc script to disable axes until referenced and a message to pop up requesting ref if anything else is tried including program running, jog, probe etc.  Now to see if I can figure out how to do that...

Keith
Title: Re: Creating a function for the Screen Load Script
Post by: DazTheGas on December 14, 2016, 12:34:06 PM
You could achieve this from the Enable button itself using a dialog box.

On pressing enable can give you a dialog box with ok and cancel buttons, warning that pressing ok will home the machine and set softlimits and pressing cancel will leave machine disabled. A simple variable can be set withing the button to check if the machine is homed or not.

DazTheGas
Title: Re: Creating a function for the Screen Load Script
Post by: thespindoctor on December 14, 2016, 02:26:19 PM
Perfect, thanks!
Title: Re: Creating a function for the Screen Load Script
Post by: Chaoticone on December 14, 2016, 03:01:08 PM
You might want to enable "Deref Axes in E-Stop" in general Config. and see if it does about what you want. I don't think it will do all of it but should get you at least part of the way there.
Title: Re: Creating a function for the Screen Load Script
Post by: DazTheGas on December 14, 2016, 05:12:34 PM
Ok have a little play with something like this

in the events tab for the enable button delete the Down Action and place this in the Down Script

Code: [Select]
local inst = mc.mcGetInstance()

function CheckHomeState()
    local en_axis = 0
    repeat
        local Is_Enabled = mc.mcAxisIsEnabled(inst, en_axis)
            if Is_Enabled == 1 then
                local is_Homed = mc.mcAxisIsHomed(inst, en_axis)
                if is_Homed ~= 1 then
                   HomeDialog()
                return  
                end
            end
        en_axis = en_axis + 1
    until( en_axis == 6 )
mc.mcCntlEnable(inst, 1)
end

function HomeDialog()
local h_dialog = wx.wxMessageDialog(wx.NULL,"Clicking Ok will Home all Axis, Cancel will abort", "Warning Machine Not Homed",wx.wxOK + wx.wxCANCEL)
local test = h_dialog:ShowModal()
    if test == wx.wxID_OK then
        mc.mcCntlEnable(inst, 1)
        wait = coroutine.create (RefAllHome)
    else
        scr.SetProperty('tbutton2','Button State','Up')
        return
    end
end

CheckHomeState()

Seems to work ok on my machine :-)

DazTheGas
Title: Re: Creating a function for the Screen Load Script
Post by: thespindoctor on December 14, 2016, 09:04:28 PM
Thanks Daz, that did the trick and soft limits are on!  Wish I could return the favor but this Lua learning is slow...

Keith
Title: Re: Creating a function for the Screen Load Script
Post by: DazTheGas on December 15, 2016, 04:31:14 AM
Glad it helped :-)

DazTheGas
Title: Re: Creating a function for the Screen Load Script
Post by: Azalin on February 13, 2022, 12:38:40 PM
Thanks everyone.
Title: Re: Creating a function for the Screen Load Script
Post by: Rimmel on June 05, 2022, 01:25:15 PM
An interesting one this, as I was looking to do the same thing. So I looked at DaztheGaz's video... Great!

However something struck me, in this instance there is already a button on the screen that does exactly the same thing (marked on the image attached). The screenshot was taken directly from the video.

Why cannot the functionality that is already provided, be tapped into  - rather than reinventing thwe wheel (so to speak).

Genuine question.

Thanks