Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Bill_O on March 21, 2019, 01:58:36 PM
-
Well all I am back with another episode of "I just don't get it" or "What the hell did I do wrong this time".
Once again thanks to everyone for all the previous help.
I thought I was getting to be a Mach4 Lua Guru........screeching halt here we are. LOL
I need to check if the motor 0 home switch is active and move off of it.
Through much searching I am unable to find anything that makes sense to me and I can get working.
Here is the code I tried.
local inst = mc.mcGetInstance()
local hsig = mc.mcSignalGetHandle(inst, ISIG_MOTOR0_HOME)
local MatHmLimit = mc.mcSignalGetState(hsig)
if MatHmLimit == 1 then
mc.mcCntlGcodeExecute(inst, "G91 G0 X-5")
mc.mcCntlGcodeExecute(inst, "G90")
end
Any and all suggestions other than jumping off a cliff are greatly appreciated.
Bill
-
Hi,
where are you going to put this code, the PLC script, a macro?
Craig
-
Hi,
you need to give some thought as to when this code executes, and if it executes repeatedly every few milliseconds or
so, what prevents the movement code executing multiple times.
As it is written it looks like this ode should go in the PLC script. So you are polling the input, it works
but is inefficient.
So lets assume the signal changes state, ie the conditional MatHmLimit==1 then the movement codes execute.
Because you have not used GcodeExecuteWait() the movement codes return immediately. This could mean that
BEFORE your machine has had the time to move off the home switch the PLC script will run again the conditional
is still true so a second lot of movement codes is executed. Is that what you want?
The second issue is that you are attempting to execute Gcode, that is your motion codes, yet you have not tested to
see whether Mach is in the idle state and can accept motion codes.
I suspect that what you are hoping that will happen is that this will happen when you hit <RefAllHome>. You will
be dissapointed because when RefAllHome is running, being in the screen chunk Mach will never be in idle state
and therefore your motion codes can't run.
Please explain what you are trying to achieve and when you are trying to achieve it.
Craig
-
Craig,
The script goes in a macro.
It is at the start of a special homing macro I made.
Sometimes the Home Switch will be activated at the time I need to do the special homing routine.
So I want to look and see if the switch is activated then move back a set distance.
Bill
-
From the code you posted, it could be that it's not returning a valid handle. I believe it should be:
local hsig = mc.mcSignalGetHandle(inst, mc.ISIG_MOTOR0_HOME)
instead of:
local hsig = mc.mcSignalGetHandle(inst, ISIG_MOTOR0_HOME)
-
jbuehn,
I just found that myself.
Was coming in to say never mind I was just being a dumba**.
Thanks all again.
Bill
-
ok.
I was a little quick like normal.
My hopes of being a Mach4 Lua Guru are being dashed. LOL
I no longer get an error but it executes the move regardless of weather the switch is activated or not.
Bill
-
Is the state of that signal changing to 0 when the switch is not physically activated?
-
jbuehn,
That is one of those things I do not know how to check or see.
The error code stuff is still so far above my head that I might see the fact that there is error code.
bill
-
Hi,
if its supposed to be in a macro then code it as such.
A macro must start with a line like;
function m120()
local inst=mc.mcGetInstance() etc etc.
....
....
....
end
And finish with these lines:
If (mc.mcInEditor()==1) then
m120()
end
Without this last bunch of code you can't single step through the code in debug mode......tell me you do use the debugger
don't you??
The error code stuff is still so far above my head that I might see the fact that there is error code.
Tuff s*********t, its part of the business of coding, you need to get onto it because it makes your coding better and easier...
not harder.
Craig
-
Craig,
The parts at the start and end are in the actual code.
It all works other than the part I mentioned.
Here is the whole thing.
-
Hi,
kool, now we can see the context.
Have you single stepped through it?
Craig
-
Craig,
Yes I have and it does not matter if the switch is active or not.
It enters the If-Then loop.
Trying to read as much on how signals word as I can I saw something about needing to put something in the screen load.
Is that maybe what I am missing?
Bill
-
Hi,
Trying to read as much on how signals word as I can I saw something about needing to put something in the screen load.
That is appropriate if you want to do something anytime a signal changes. In your case all you want is to test a signal
when you run a macro.
Craig
-
Hi,
may I suggest holding the home switch closed, or even disconnect the wires to it and short them together
to see whether the code detects the signal if it is deliberately held in opposite state.
Craig
-
Craig,
It does not make any difference.
For some reason it always enters the If-Then loop
Bill
-
Hi,
I can only guess then that you have made a mistake in the pin assignment, or may be the logogical
connection of the pin to mc.ISIG_MOTOR0_HOME
Craig
-
Craig,
Normally I would agree with you.
But the switch works fine for a homing switch.
Bill
-
Hi,
is the switch doing double duty, ie a home switch and also a limit switch?
Craig
-
Craig,
Only as a homing switch.
Bill
-
Hi,
then disconnect the switch and use the pin assignment to ensure the pin is low and run the code again.
Craig
-
Craig,
I give it a shot.
Bill
-
Craig,
I know I sound crazy but now it works.
The only thing I can think of is maybe I did not exit Mach so a new Lua.mcc could be written.
I am very sorry for taking up your time on this.
Bill