Hello Guest it is May 17, 2021, 07:21:04 PM

Author Topic: hold all axis also on jog  (Read 1215 times)

0 Members and 1 Guest are viewing this topic.

Offline smurph

*
  • *
  •  1,402 1,402
  • "That there... that's an RV."
    • View Profile
Re: hold all axis also on jog
« Reply #20 on: April 02, 2019, 09:40:59 AM »
when checking return codes, is it preferred to use the actual error definition versus the number?

Yes.  The underlying number could change, although not very likely.  However, the possibility exists, so use the constant whenever possible.  You just can't go wrong using constants. 

Steve

Re: hold all axis also on jog
« Reply #21 on: April 02, 2019, 11:19:15 AM »
Thanks!

Offline smurph

*
  • *
  •  1,402 1,402
  • "That there... that's an RV."
    • View Profile
Re: hold all axis also on jog
« Reply #22 on: April 02, 2019, 06:50:50 PM »
To expand further with some more best practices, break the code up into functional elements.  The OP's original question was about inhibiting motion and jogs.  So let's make the code a bit more modular. 

Code: [Select]
function InhibitMotion(inhibit)
    local inst = mc.mcGetInstance('InhibitMotion()')
    local rc, hSigInhitbitMotion

    hSigInhitbitMotion, rc = mc.mcSignalGetHandle(inst, mc.ISIG_MOTION_INHIBIT)
    if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
        mc.mcCntlMacroAlarm(inst, 600, 'Could not retrieve ISIG_MOTION_INHIBIT signal handle!')
return
end

if (inhibit) then
rc = mc.mcSignalSetState(hSigInhitbitMotion, 1) -- raise the mc.ISIG_MOTION_INHIBIT signal
if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
mc.mcCntlMacroAlarm(inst, 602, 'Could not set ISIG_MOTION_INHIBIT signal state to 1!')
return
end
else
rc = mc.mcSignalSetState(hSigInhitbitMotion, 0) -- lower the mc.ISIG_MOTION_INHIBIT signal
if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
mc.mcCntlMacroAlarm(inst, 604, 'Could not set ISIG_MOTION_INHIBIT signal state to 0!')
return
end
    end
end

function InhibitJog(inhibit)
    local inst = mc.mcGetInstance('InhibitMotion()')
    local rc, hSigInhitbitJog

    hSigInhitbitJog, rc = mc.mcSignalGetHandle(inst, mc.ISIG_JOG_INHIBIT)
    if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
        mc.mcCntlMacroAlarm(inst, 601, 'Could not retrieve ISIG_JOG_INHIBIT signal handle!')
return
end

if (inhibit) then
rc = mc.mcSignalSetState(hSigInhitbitJog, 1) -- raise the mc.ISIG_JOG_INHIBIT signal
if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
mc.mcCntlMacroAlarm(inst, 603, 'Could not set ISIG_JOG_INHIBIT signal state to 1!')
return
end
else
rc = mc.mcSignalSetState(hSigInhitbitJog, 0) -- lower the mc.ISIG_JOG_INHIBIT signal
if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
mc.mcCntlMacroAlarm(inst, 605, 'Could not set ISIG_JOG_INHIBIT signal state to 0!')
return
end
    end
end

function InhibitMotionAndJog(inhibit)
InhibitMotion(inhibit)
InhibitJog(inhibit)
end


There are three functions in that code snippet; InhibitMotion(), InhibitJog(), and InhibitMotionAndJog().  Each takes one parameter called inhibit.  InhibitMotionAndJog() simply calls InhibitMotion() and InhibitJog().  Breaking the functions up like this give you the option of using these function in other piece of code, if needed.  What if you simply wanted to inhibit jogs?  Well...  there is a function for that.  :)

Now that we have them inhibit functions, we can call them a variety of ways.  Through the PLC script, through the signal script, or the siglib in the screen load script.   

Example for the PLC script checking if the machine is homed:
Code: [Select]
-- the following functions should reside in the screen load script.
function CheckHomed()
    local inst = mc.mcGetInstance('CheckHomed()')
    local homedX, homedY, homedZ, homed, rc, hSigInhitbitMotion, inhibitMotion
    homedX, rc = mc.mcAxisIsHomed(inst, mc.X_AXIS)
    if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
        mc.mcCntlMacroAlarm(inst, 5000, 'Could not retrieve X axis homed condition!')
return
end
    homedY, rc = mc.mcAxisIsHomed(inst, mc.Y_AXIS)
    if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
        mc.mcCntlMacroAlarm(inst, 5001, 'Could not retrieve Y axis homed condition!')
return
end
    homedZ, rc = mc.mcAxisIsHomed(inst, mc.Z_AXIS)
    if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
        mc.mcCntlMacroAlarm(inst, 5002, 'Could not retrieve Z axis homed condition!')
return
end

    hSigInhitbitMotion, rc = mc.mcSignalGetHandle(inst, mc.ISIG_MOTION_INHIBIT)
    if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
        mc.mcCntlMacroAlarm(inst, 5003, 'Could not retrieve ISIG_MOTION_INHIBIT signal handle!')
return
end

    inhibitMotion, rc = mc.mcSignalGetState(hSigInhitbitMotion)
    if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
        mc.mcCntlMacroAlarm(inst, 5005, 'Could not retrieve ISIG_MOTION_INHIBIT signal state!')
return
end

homed = homedX and homedY and homedZ
   
if ((homed == 0) and (inhibitMotion == 0)) then
InhibitMotionAndJog(true)
elseif ((homed == 1) and (inhibitMotion == 1)) then
InhibitMotionAndJog(false)
    end
end

-- and a line in the PLC script like:
CheckHomed()

Example for the siglib using inputs 1, 2 and 3.
Code: [Select]
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
machEnabled = state;
    ButtonEnable()
end,

[mc.ISIG_INPUT0] = function (state)
   
end,

[mc.ISIG_INPUT1] = function (state)
if (state == 1) then   
InhibitMotion(true)
else
InhibitMotion(false)
end
end,

[mc.ISIG_INPUT2] = function (state)
if (state == 1) then   
InhibitJog(true)
else
InhibitJog(false)
end
end,

[mc.ISIG_INPUT3] = function (state)
if (state == 1) then   
InhibitMotionAndJog(true)
else
InhibitMotionAndJog(false)
end
end

Steve
Re: hold all axis also on jog
« Reply #23 on: April 02, 2019, 07:31:37 PM »
That's great info Steve. I've been learning (sometimes the hard way) the advantages of using return codes! It definitely makes debugging / logging easier.
Re: hold all axis also on jog
« Reply #24 on: April 02, 2019, 10:14:52 PM »
Hi Smurph,

Code: [Select]
local inst = mc.mcGetInstance('CheckHomed()')
It is the first time I have seen, that I recall, a string as an argument passed to the mcGetInstance API. Is there a particular
reason you have done it?

Craig
My wife left with my best friend...
     and I miss him!

Offline smurph

*
  • *
  •  1,402 1,402
  • "That there... that's an RV."
    • View Profile
Re: hold all axis also on jog
« Reply #25 on: April 02, 2019, 10:48:17 PM »
 That string is a marker that is associated with the instance handle.  It is used with API function call tracing in the Mach Log.  It makes it so that you can see what called the API function. 

Steve