Hello Guest it is December 07, 2019, 12:08:01 AM

Author Topic: input signals  (Read 488 times)

0 Members and 1 Guest are viewing this topic.

Offline Bill_O

*
  •  250 250
    • View Profile
input signals
« 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
Re: input signals
« Reply #1 on: March 21, 2019, 02:04:02 PM »
Hi,
where are you going to put this code, the PLC script, a macro?

Craig
My wife left with my best friend...
     and I miss him!
Re: input signals
« Reply #2 on: March 21, 2019, 02:40:47 PM »
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
My wife left with my best friend...
     and I miss him!

Offline Bill_O

*
  •  250 250
    • View Profile
Re: input signals
« Reply #3 on: March 21, 2019, 03:05:48 PM »
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
Re: input signals
« Reply #4 on: March 21, 2019, 03:31:34 PM »
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)

Offline Bill_O

*
  •  250 250
    • View Profile
Re: input signals
« Reply #5 on: March 21, 2019, 03:38:49 PM »
jbuehn,

I just found that myself.
Was coming in to say never mind I was just being a dumba**.

Thanks all again.

Bill

Offline Bill_O

*
  •  250 250
    • View Profile
Re: input signals
« Reply #6 on: March 21, 2019, 03:53:03 PM »
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
Re: input signals
« Reply #7 on: March 21, 2019, 04:02:51 PM »
Is the state of that signal changing to 0 when the switch is not physically activated?

Offline Bill_O

*
  •  250 250
    • View Profile
Re: input signals
« Reply #8 on: March 21, 2019, 04:16:55 PM »
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
Re: input signals
« Reply #9 on: March 21, 2019, 10:51:40 PM »
Hi,
if its supposed to be in a macro then code it as such.

A macro must start with a line like;

Code: [Select]
function m120()
local inst=mc.mcGetInstance() etc etc.
....
....
....
end

And finish with these lines:

Code: [Select]
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??

Quote
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
My wife left with my best friend...
     and I miss him!