5757
« on: December 03, 2017, 04:11:34 AM »
Hi RT,
index homing is usually enacted by the motion controller. The ESS certainly is and that's what I'm familiar with.
The reason is that if Mach were monitoring the index signal there will be a delay of milliseconds at the least before it could make some sort of decision
and stop the motor. If enacted within the FPGA or DSP chip of the external controller it could respond within microseconds, this is exactly what the ESS does
and so it can very quickly detect and act on an index pulse.
Within the limitation that Mach is going to respond slowly with consequences re the accuracy of the homed position I can see several ideas that would allow
you to monitor the index pulse.
One I've had some success with is:
LUA Syntax:
rc = mc.mcSignalWait(
number mInst,
number sigId,
number waitMode,
number timeoutSecs);
This responds at the rate of the signal script, ie pretty damn quick. If I understand Machs treatment of signals then within a millsecond or so.
Another possibility is to have code within the PLC script which reads the index input. The PLC script in Mach4 runs a lot faster than the macro pump in Mach3
but would still represent a potential delay in reading an index pulse of 10milliseconds or so.
Your code does something similar, you read the index pin and if not active then sleep for 25ms and read it again. In the mean time Mach can do nothing
else. You've given it a job to do so it tries to do it...but it can only do one thing at a time. If for whatever reason it can't do the job you've given it
then Mach is said to block, and you've seen messages to that effect.
I am no Lua expert but I believe that either of the two strategies I've mentioned allow Machs GUI to run while its waiting for an index pulse. In the case of the
first API call approach if an index pulse does not ocurr within a given time it will timeout rather than block.
The broad strategy I'm proposing is:
1) Issue a motion command that allows the spindle to rotate at slow speed for at least one complete revolution. This would require a
mc.mcCntlGcodeExecute() API call so that the function returns immediately.
2)Have a small block of code to store and manipulate the machine co-ords that would execute when the index signal came active with the mc.mcSignalWait()
API above.
3) Abort the remainder of the move. Note I'm not sure that a clearing of the motion planner is possible in Lua, it may be restricted to C++ in a plugin.
Should that prove to be the case then it could be worked around...just let the motion command run its course and then back up to the co-ords stored
as a result of step 2.
Does any of that sound like it might work to you?
Craig