Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: KatzYaakov on April 01, 2019, 11:43:12 AM

Title: hold all axis also on jog
Post by: KatzYaakov on April 01, 2019, 11:43:12 AM
hi
i want add simple condition ,that if....
not any movement can happened
not on reference
not on G0
not on G1
and not on manual move
very very simple request but cant find hoe do it
Title: Re: hold all axis also on jog
Post by: joeaverage on April 01, 2019, 03:46:04 PM
Hi,
how about having a test in the PLC script that if the machine is not Homed then the
feed rate override, the raid rate override and jog seed are all set to zero?

Code: [Select]
local inst=mc.mcGetInstance()
local homedX=mc.mcAxisIsHomed(inst,mc.X_AXIS)
local homedY=mc.mcAxisIsHomed(inst,mc.Y_AXIS)
local homedZ=mc.mcAxisIsHomed(inst,mc.Z_AXIS)
local homed= homedX and homedY and homedZ
if (homed ==0)then
mc.mcCntlSetFRO(inst,0.0)
mc.mcCntlSetRRO(inst,0.0)
mc.mcJogSetRate(inst,mc.X_AXIS,0.0)
mc.mcJogSetRate(inst,mc.Y_AXIS,0.0)
mc.mcJogSetRate(inst,mc.Z_AXIS,0.0)
end

Craig
Title: Re: hold all axis also on jog
Post by: KatzYaakov on April 01, 2019, 06:08:46 PM
hi
thanks for fast answer
i already tried it
but in the Jog its not give 0 its give 20% even we put 0
Title: Re: hold all axis also on jog
Post by: joeaverage on April 01, 2019, 06:12:18 PM
Hi,

Quote
but in the Jog its not give 0 its give 20% even we put 0

It works fine on my machine.

Craig
Title: Re: hold all axis also on jog
Post by: KatzYaakov on April 01, 2019, 06:21:59 PM
now in my laptop its 29% while in the machine it was 20%  strange
Title: Re: hold all axis also on jog
Post by: KatzYaakov on April 01, 2019, 06:26:10 PM
second reason im not sure i can use it  ,is that i use external potenziometr to control both G0 G1
i think there will be conflict between that 2 commands
there must be much more easy way to hold all axis ,its basic safety command not only when no homing ,but also in some
mechanic sondition
Title: Re: hold all axis also on jog
Post by: joeaverage on April 01, 2019, 06:49:45 PM
Hi,

Quote
is that i use external potenziometr to control both G0 G1
i think there will be conflict between that 2 commands

I suspect that is the case, the rate overrides are looking to the potentiometer, even if you set them at zero
the potentiometer resets it to some minimum value almost immediately.

You can disable each axis with:

Code: [Select]
LUA Syntax:
rc = mc.mcAxisEnable(
                     number mInst,
                     number axisId,
                     number enabled);

Description:
Enable or disable the specified axis.

Parameters: Parameter Description
mInst The controller instance.
axisId The axis ID.
enabled Send true to enable or false to disable axis.


However I suspect that this would also prevent you from homing your machine, in fact I thin this would permanently
disable your machine. I'm reluctant to suggest you try it.

If your machine is not homed......then disable all axes
try to home your machine......can't home because axes are disabled
try to enable axes.......works for a little bit but THEN
if your machine is not homed......then disable all axes

IE you have created a loop which disables your axes continuously, not recommended.

Craig
Title: Re: hold all axis also on jog
Post by: KatzYaakov on April 01, 2019, 06:54:40 PM
when i disable the axis i think i will get the output enable "0" then servo driver will turn too "bb" insted of "run"
this very bad
as i mention its not condition only  before homing
its command to "hold" in some other cases
for example while force one of the cylinder that can accident
Title: Re: hold all axis also on jog
Post by: joeaverage on April 01, 2019, 07:06:33 PM
Hi,

Quote
when i disable the axis i think i will get the output enable "0" then servo driver will turn too "bb" insted of "run"
this very bad

Exactly.....this is why I suggested that you reduce the Rapid Rate Override, the Feed Rate Override and the axis Jog Rates
all to zero, it means that the servos are all still enabled but Gcode, MDI and Jogging causes no motion, or at least they do
cause motion but at zero speed. This still allows the servos to respond to movement instructions from the core to
home the machine.

If you don't like that idea or it wont work with your installation because of other stuff you have hooked up
then you will have to devise some other way.

Craig
Title: Re: hold all axis also on jog
Post by: smurph 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
Title: Re: hold all axis also on jog
Post by: KatzYaakov on April 01, 2019, 07:13:20 PM
i dont like this way because its look to complex for this base comand(do not forget
i need to remember the curent speed ,then put them again while condition pass ,so its become much complex ,and
as i mention its not only before homing its also in some other cases
so then i got what mach warning against ,try avoid heavy on plc script
but also other much more problem for me its that the jog command as i copy from yours sample not turn to "0"
in my laptop
Title: Re: hold all axis also on jog
Post by: KatzYaakov on April 01, 2019, 07:24:19 PM
thanks
can you please explain  about that command
mcCntlMacroAlarm(in document its that said its force in alarm state ,but its actually do?)
and what is parameter 5000-5006
Title: Re: hold all axis also on jog
Post by: smurph 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
Title: Re: hold all axis also on jog
Post by: joeaverage on April 01, 2019, 07:37:04 PM
Hi Smurph,
very smooth.

I take it that raising ISIG_MOTION_INHIBIT causes the core to stop producing movement?

Craig
Title: Re: hold all axis also on jog
Post by: smurph 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
Title: Re: hold all axis also on jog
Post by: joeaverage on April 01, 2019, 07:46:14 PM
Hi,
kool, I don't recall seeing them before. I can't find them in the API.chm input signal listing?

Craig
Title: Re: hold all axis also on jog
Post by: smurph 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
Title: Re: hold all axis also on jog
Post by: KatzYaakov on April 01, 2019, 07:51:11 PM
i do not want stop the gcode
its not alarm state
its just safty state
for example in this machine i have labeling system that apply label on parts
when the label cylinder is down i must hold any axis movement ,in any condition
no G0 no G1 no joging
but sure not stop the gcode
also in other machine i have safety ray protect  device
if you got into that area movement must hold at any case also
thanks
Title: Re: hold all axis also on jog
Post by: smurph 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
Title: Re: hold all axis also on jog
Post by: jbuehn on April 01, 2019, 07:59:40 PM
when checking return codes, is it preferred to use the actual error definition versus the number?
Title: Re: hold all axis also on jog
Post by: smurph 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

Title: Re: hold all axis also on jog
Post by: jbuehn on April 02, 2019, 11:19:15 AM
Thanks!
Title: Re: hold all axis also on jog
Post by: smurph 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
Title: Re: hold all axis also on jog
Post by: jbuehn 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.
Title: Re: hold all axis also on jog
Post by: joeaverage 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
Title: Re: hold all axis also on jog
Post by: smurph 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