Hello Guest it is October 21, 2019, 09:14:18 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - smurph

61
Allan hit the nail on the head.  All of the probes, 31, 31.1, 31.2, and 31.3 will write to those variables.  The 4 probe moves are there so that a tool setting probe can be differentiated from a surface probe, etc...

Steve

62
mc.OSIG_SPINDLEON means the spindle is moving.  And there are also mc.OSIG_SPINDLEFWD and mc.OSIG_SPINDLEREV.

The motor enable is separate.  You don't need to even look at it because the above signals will do what you want. 

Steve

63
Mach4 General Discussion / Re: hold all axis also on jog
« 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

64
Mach4 General Discussion / Re: hold all axis also on jog
« 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

65
Mach4 General Discussion / Re: hold all axis also on jog
« 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


66
Mach4 General Discussion / Re: hold all axis also on jog
« on: April 01, 2019, 07:58:18 PM »
Read the code again.  Those alarm conditions are only there if an API return code indicates failure.  In the case of an API failure, you probably WANT to stop the machine.  All of those tests are there to make the code bullet proof and safe, as all production machine should be.  In normal operation, the script would just prevent all movement unless the machine has been homed.  Of course, you could change the script to be trigger on any condition.  Say another input that is raised when the label cylinder is down. 

Steve

67
Mach4 General Discussion / Re: hold all axis also on jog
« on: April 01, 2019, 07:50:33 PM »
BTW,

mc.mcCntlMacroAlarm(inst, 5005, 'Could not set ISIG_MOTION_INHIBIT signal state to 1!')

is the same as the following G code line:

#3000 = 5005 (Could not set ISIG_MOTION_INHIBIT signal state to 1!)

There is also mcCntlMacroStop() which will just stop a cycle but it does NOT raise an alarm (or OSIG_ALARM) and thus does not need a reset to clear it.  Is it the same as the following G code line:

#3001 = 1001 (This is a macro stop!)

Steve

68
Mach4 General Discussion / Re: hold all axis also on jog
« on: April 01, 2019, 07:44:19 PM »
Yes.  ISIG_MOTION_INHIBIT can also be use with safety devices like a light curtain to stop the machine if the operator crosses the boundary. 

It is one of the three following inhibit signals. 

Motion Inhibit  ISIG_MOTION_INHIBIT
Jog Inhibit  ISIG_JOG_INHIBIT
MPG Inhibit  ISIG_MPG_INHIBIT

Motion is ALL motion.  But Jog and MPG can be inhibited separately. 

Steve

69
Mach4 General Discussion / Re: hold all axis also on jog
« on: April 01, 2019, 07:32:17 PM »
It does just that.  Forces an alarm state.  An alarm will stop the machine if it is running a G code file.  And it requires a Reset to clear the alarm condition.  It also raises the OSIG_ALARM signal (that could be used to drive a flashing light, for example).  The number is arbitrary.  I used 5000 and walked it up so that if something happens, you could tell where in the script by matching the alarm number.  The the alarm number and text is put in the status history. 

Steve

70
Mach4 General Discussion / Re: hold all axis also on jog
« on: April 01, 2019, 07:10:59 PM »
Use the motion inhibit input signal.  ISIG_MOTION_INHIBIT

In the Screen load script:
Code: [Select]
function Checkhomed()
local inst = mc.mcGetInstance('CheckHomed')
local homedX, homedY, homedZ, homed, rc, hSig, inhibit
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

hSig, rc = mc.mcSignalGetHandle(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
inhibit, rc = mc.mcSignalGetState(hSig)
if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
mc.mcCntlMacroAlarm(inst, 5004, 'Could not retrieve ISIG_MOTION_INHIBIT signal state!')
return
end

homed = homedX and homedY and homedZ
   
if ((homed == 0) and (inhibit == 0)) then
rc = mc.mcSignalSetState(hSig, 1) -- raise the mc.ISIG_MOTION_INHIBIT signal
if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
mc.mcCntlMacroAlarm(inst, 5005, 'Could not set ISIG_MOTION_INHIBIT signal state to 1!')
return
end
elseif ((homed == 1) and (inhibit == 1)) then
rc = mc.mcSignalSetState(hSig, 0) -- raise the mc.ISIG_MOTION_INHIBIT signal
if (rc ~= mc.MERROR_NOERROR) then -- check retun codes!
mc.mcCntlMacroAlarm(inst, 5006, 'Could not set ISIG_MOTION_INHIBIT signal state to 0!')
return
end
end
end

Then call Checkhomed() from the PLC script
Steve