Hello Guest it is March 28, 2024, 08:04:16 AM

Author Topic: Mach4 Spindle At Speed, Spindle Zero Problem  (Read 20812 times)

0 Members and 1 Guest are viewing this topic.

Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #10 on: September 30, 2017, 04:38:09 PM »
Hi,
try these macros, they must be in your current profile:
for m3
Code: [Select]
function m3();
local inst=mc.mcGetInstance();
mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_FWD);
mc.mcCntlSetLastError(inst,"m3 waiting");
while (AtSpeed~=1) do;
    mc.mcCntlGcodeExecuteWait(inst,"P1");
end;
mc.mcCntlSetLastError(inst,"m3 at speed");
end
if (mc.mcInEditor() == 1) then
    m3()
end

for m4
Code: [Select]
function m4();
local inst=mc.mcGetInstance();
mc.mcSpindleSetDirection(inst, mc.MC_SPINDLE_REV);
mc.mcCntlSetLastError(inst,"m4 waiting");
while (AtSpeed~=1) do;
    mc.mcCntlGcodeExecuteWait(inst,"P1");
end;
mc.mcCntlSetLastError(inst,"m4 at speed");
end
if (mc.mcInEditor() == 1) then
    m4()
end

for m5
Code: [Select]
function m5();
local inst=mc.mcGetInstance();
mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_OFF);
mc.mcCntlSetLastError(inst,"m5 stopping");
while (IsStopped~=1) do;
    mc.mcCntlGcodeExecuteWait(inst,"P1");
end;
mc.mcCntlSetLastError(inst,"m5 Is Stopped");
end
if (mc.mcInEditor() == 1) then
    m5()
end

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #11 on: September 30, 2017, 06:00:22 PM »
Hi,
just realised that while I set the direction in m3 and m4 I didn't actually turn the spindle on, not sure what output signals you are using
to control the VFD but they may have to be added to m3, m4.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #12 on: September 30, 2017, 09:25:55 PM »
Hi Hakan,
I've been doing some testing and the code I've posted has lots of faults.

The first was my inclination to set up two global variables AtSpeed and IsStopped. They don't pass into the m3,m4 and m5 macros...don't quite understand why
at the moment. What I've done as a working alternative is in each macro get the signal handle and signal state and use that to control the wait loop.

Second issue is that if for whatever reason the spindle doesn't respond, in my case I'm using my laptop so clearly the signal will never go active, then the machine
hangs and will eventually crash.

What I did was set up a timeout variable in each macro which means that if the spindle doesn't respond after ten seconds or so the macro will end, report
an error rather than hang and crash out.

For m3
Code: [Select]
function m3();
local inst=mc.mcGetInstance();
local timeout=0;
mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_FWD);
mc.mcCntlSetLastError(inst,"m3 waiting");
local hsig= mc.mcSignalGetHandle(inst,mc.ISIG_SPINDLE_AT_SPEED);
local AtSpeed=mc.mcSignalGetState(hsig);
    while (AtSpeed~=1) do;
        mc.mcCntlGcodeExecuteWait(inst,"g4 p1000");
        timeout=timeout+1;
        if (timeout>=10) then;
            wx.wxMessageBox("Spindle does not respond");
            break;
        end;
    end;
    if (AtSpeed==1) then;
        mc.mcCntlSetLastError(inst,"m3 at speed");
    else;
        mc.mcCntlSetLastError(inst,"spindle does not respond");
        mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_OFF);
    end;
end
if (mc.mcInEditor() == 1) then
    m3()
end

For m4
Code: [Select]
function m4();
local inst=mc.mcGetInstance();
local timeout=0;
mc.mcSpindleSetDirection(inst, mc.MC_SPINDLE_REV);
mc.mcCntlSetLastError(inst,"m4 waiting");
local hsig= mc.mcSignalGetHandle(inst,mc.ISIG_SPINDLE_AT_SPEED);
local AtSpeed=mc.mcSignalGetState(hsig);
    while (AtSpeed~=1) do;
        mc.mcCntlGcodeExecuteWait(inst,"g4 p1000");
        timeout=timeout+1;
        if (timeout>=5) then;
            wx.wxMessageBox("Spindle does not respond");
            break;
        end;
    end;
    if (AtSpeed==1) then;
        mc.mcCntlSetLastError(inst,"m4 at speed");
    else;
        mc.mcCntlSetLastError(inst,"spindle does not respond");
        mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_OFF);
    end;
end
if (mc.mcInEditor() == 1) then
    m4()
end

For m5
Code: [Select]
function m5();
local inst=mc.mcGetInstance();
local timeout=0;
mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_OFF);
mc.mcCntlSetLastError(inst,"m5 stopping");
local hsig=mc.mcSignalGetHandle(inst,mc.ISIG_SPINDLE_AT_ZERO);
local IsStopped=mc.mcSignalGetState(hsig);
    while (IsStopped~=1) do;
        mc.mcCntlGcodeExecuteWait(inst,"g4 p1000");
        timeout=timeout+1;
        if (timeout>=10) then;
            wx.wxMessageBox("Spindle does not respond");
            break;
        end;
    end;
    if (IsStopped==1) then;
        mc.mcCntlSetLastError(inst,"m5 Is Stopped");
    else;
        mc.mcCntlSetLastError(inst,"spindle does not respond");
    end;
end
if (mc.mcInEditor() == 1) then
    m5()
end

You can ignore the code added to the SigLib in the signal load script, I don't think it will effect m3,m4 or m5 but I deleted the extra SigLib entries to
be sure.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #13 on: September 30, 2017, 09:38:13 PM »
Hi Hakan,
I've found another mistake...
the wait command is
Code: [Select]
mc.mcCntlGcodeExecuteWait(inst,"g4 p1000");
so the machine waits for 1000ms or 1 second. The loop repeats in m3 and m5 macros 10 times before faulting out whereas the m4 macro
waits 5 times before faulting. Depending on your spindle, the vid you posted sounds like it takes some seconds to speed up, you may need to adjust
both the wait state length, say p1500, and you may want the timeout delay to be longer, 12 instead of 10 for example. I imagine you'll want to correct
my mistake in the m4 macro by only having the loop repeat 5 times before faulting, it should have been 10 but I missed it!

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #14 on: October 01, 2017, 05:23:01 AM »
Hi Craig,

I will try the last M3 M4 and M5 codes u sent and get back to u, thanks alot.

Regards,

Hakan
Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #15 on: October 02, 2017, 11:41:18 AM »
Hi Hakan,
you may have noticed that I've had another thread running trying to work out why the global variables I'd wanted to use didn't work.
DazThe Gas has come back with an explanation and a solution. Its just as well because the macro code I given you STILL won't work.

In particular the state of the input signal is read prior to the wait loop but is not read again thereafter. There is no opportunity for the
while/do loop condition to change. The code could be modified by reading the input pin within the loop and so would be read every 1 second
or so, used to be called 'polling'. It would work fine but is not as elegant as having a live variable that reflects the input pin state within
microseconds and does not require our code to force it to update.

Daz's solution is to have a registers populated with our global variables. I've used them before and should have thought of them myself.
The register setup in Mach is precisely to allow data communication between Lua chunks. My previous use of registers was to recall a file path
from a previously executed script into a currently executing script, so registers allowed me to communicate data between two objects
separated in time. In our current circumstance the data we require is in one chunk, the GUI, and yet we need it in the Gcode Interpreter chunk,
ie separated by scope.

I will, if you permit, take a little more time to write some code, this time hopefully correct first time! I was guilty of writing and posting the code above
on the fly with consequent errors and in this case a serious logic error; a faulty loop conditional.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #16 on: October 02, 2017, 12:08:07 PM »
Hi Craig,

I tested your code it works like this;

When following code entered to MDI and pressed Cycle start,

M3 S6000
G1 X50 Y100 Z50 F500
G1 X0 Y0 Z0
S0

- It turns on the spindle and waits, at the bottom it says "m3 waiting",
- spindle at speed led turns on in diagnostics but code does not see it
- after a while it says at the bottom "spindle does not respond" and turns off the spindle
- executes the gcode

shortly it couldnt see/read the 'spindle at speed' input.

u can see my configuration related with the spindle at speed and spindle at zero in attached images.

well your code works fine it just couldnt read the input if u can find a way to read that input it will be perfect.

At the beginning because of that i told you that it should have been implemented in Mach4 source code, when user assigns an input to "spindle at speed" Mach4 automatically should wait the signal before moving the axis in case of gcode/MDI, or when user hit spindle CW button it should wait for the signal and disable jogging. This is the logical way, if user has to implement it from outside that he/she has to be a programmer like u, i tried and couldnt do it.

Regards,

Hakan
Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #17 on: October 02, 2017, 12:21:09 PM »
Hi Hakan,
the logic error I described above is why its not working. I think your Mach/ESS is setup OK.

Mach 4 is configurable. Artsoft has no idea what you want to do with your machine. If they assumed that most users would want Gcode to be delayed
then what about all those situations where that's not correct? This sort of basic scripting is normal, go and have a look at all the little customisations
that occur in the average Mach3 users machines. What is putting people off is that their not familiar with Lua and want to blame everyone else for
not learning it. Which camp are you in?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #18 on: October 02, 2017, 12:28:50 PM »
Hi,
in fact Artsoft already provided exactly what you wanted with the 'Wait on Spindle to Stabilise' and 'Percent' settings. You chose not to use what
is ready for use so surely you're prepared to make the effort to fill in the gap for that which is not provided.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #19 on: October 02, 2017, 12:54:21 PM »
Hi Craig,

Ok, thanks for helping me out.

Regards,

Hakan