Hello Guest it is March 28, 2024, 05:20:06 AM

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

0 Members and 1 Guest are viewing this topic.

Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #20 on: October 02, 2017, 07:38:18 PM »
Hi Hakan,
your welcome of course, the truth is though that by doing this I'm learning too so I should also
thank you for the oppurtunity.

I've been thinking a bit more about this code. The state of the two signals is required to control the wait loops.
The signals are however registered in Machs core. So it will require a specific read via the API to get the signal state.
If the signals were registered in the Gcode interpreter then a simple variable read would work, but they're not.
There is no advantage either of duplicating the signal state in the Register Plugin, it would still require an API read
of the registers.

I propose altering the code along these lines:
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);
    while (mc.mcSignalGetState(hsig)~=1) do;
        mc.mcCntlGcodeExecuteWait(inst,"g4 p1000");
        timeout=timeout+1;
        if (timeout>=10) then;
            wx.wxMessageBox("Spindle does not respond");
            break;
        end;
    end;
    if (mc.mcSignalGetState(hsig)==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

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 #21 on: October 03, 2017, 12:16:59 PM »
Hi Craig,

I tried your last M3 code it works fine spindle waits for the signal and then goes on to gcode, but i found out something which u can say "bug" for the code ;)

When i write a code in MDI i write it as "M3 S6000" in a same line but i tried one of the gcodes roadrunner.tap to test it and in that gcode M3 and S60 commands are in different lines its like this;

F60.000000
G0 X0.000000 Y0.000000 Z0.200000
M3 (start Spindle)
S60.000000
G43H5
G0 X0.000000 Y0.000000 Z5.00000
G0 X1.179950 Y4.004260 Z0.200000

(I changed S60 to S6000 in the test)

When u press cycle start with this code M3 macro came up with "spindle does not respond" message.

So because S6000 was not at the same line with M3, it didnt start the spindle and because of that Spindle At Speed signal did not turn on and M3 macro could not see the signal so it gave "spindle does not respond" message.

I dont know why in roadrunner code it is in different lines but in general M3 and S command should be in same line in gcodes so it wont be a problem i think.

I will change the M4 M5 macros  and button scripts, spindle cw and spindle ccw on screen according to this M3 macro so they all should work correctly.

Thanks for your help, i couldnt came up with that code for a month.

Regards,

Hakan
Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #22 on: October 03, 2017, 02:14:33 PM »
Hi Hakan,
hadn't found that bug...I will give it some thought.

Get into the habit of using lowercase m for macros, I've caused myself plenty of grief by not doing so. Windows is by and large NOT case sensitive
about script and filenames but now you are relying on Windows to come up with the right file....it will fail occasionally so use lower case m.

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 #23 on: October 03, 2017, 10:24:09 PM »
Hi Hakan,
not convinced that the macros are responsible for the behavior that you describe but rather the way the interpreter
works.

My understanding is:
When the interpreter encounters a macro, m3 for instance it passes control the the function in the macro and
when the macro returns it goes back to the next line of code. Any other Gcodes on the line after the remote
function call are missed.

Would like to test it out. Maybe one of  the Mach/Lua gurus will chime in.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #24 on: October 03, 2017, 10:45:55 PM »
Craig, I haven't read this whole topic (just read your last 2 replies) so not sure what I might be missing about it so take this with a grain of salt........ instead of the while loop you might want to use the mc.mcSignalWait api call.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #25 on: October 03, 2017, 10:50:35 PM »
I don't think they need to be on the same line. But if they are not, you may need to specify the S word first.
S6000
M3

If you don't specify the RPM first, you are in effect trying to start the spindle at 0 RPM.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: Mach4 Spindle At Speed, Spindle Zero Problem
« Reply #26 on: October 03, 2017, 11:45:28 PM »
Hi,
kool guys, thanks for that.
mcSignalWait sounds very promising. I had a loop which introduced a 1 second delay until the signal came good.
One advantage of doing that was I had an incrementing counter so that if the signal didn't come good after a
reasonable time it would fault rather than hang.

Every time I think 'Oh yeah, that looks easy I'll help the bloke with that' I end up with my sleeves rolled up and
end up learning as much as the person I was supposedly helping. Keeps me off the streets.

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 #27 on: October 04, 2017, 03:00:14 AM »
Hi Hakan,
Chaoticone is spot on, mcSignalWait is perfect.

Quote
rc = mc.mcSignalWait(
   number mInst,
   number sigId,
   number waitMode,
   number timeoutSecs);

Description:
Wait on a signal to change state.

Parameters: Parameter Description
mInst The controller instance.
sigId A valid signal ID. (NOT a signal handle)
waitMode An integer specifying whether to wait on the signal to go high (WAIT_MODE_HIGH) or low (WAIT_MODE_LOW).
timeoutSecs A double specifying a timeout period.


Returns: Return Code Description
MERROR_NOERROR No Error.
MERROR_INVALID_INSTANCE The mInst parameter was out of range.
MERROR_INVALID_ARG sigId or wiatMode is out of range or timeoutSecs is negative.
MERROR_NOT_ENABLED The control is not enabled.
MERROR_TIMED_OUT The timeout period was reached without a change of state.

Should be able to simplify the macros really well, don't even need  the signal handle!

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 #28 on: October 04, 2017, 03:15:07 AM »
Hi Hakan,
try this for m3:
Code: [Select]
function m3();
local inst=mc.mcGetInstance();
mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_FWD);
mc.mcCntlSetLastError(inst,"m3 waiting");
local returncode=mc.mcSignalWait(inst,mc.ISIG_SPINDLE_AT_SPEED,mc.WAIT_MODE_HIGH,10.0);
    if (returncode==mc.MERROR_TIMED_OUT) then
        mc.mcCntlSetLastError(inst,"spindle does not respond");
        mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_OFF);
    else;
        mc.mcCntlSetLastError(inst,"m3 at speed");
    end;
end
if (mc.mcInEditor() == 1) then
    m3()
end

Tidy and tight!

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 #29 on: October 04, 2017, 03:26:29 AM »
Hi,

Code: [Select]
function m4();
local inst=mc.mcGetInstance();
mc.mcSpindleSetDirection(inst, mc.MC_SPINDLE_REV);
mc.mcCntlSetLastError(inst,"m4 waiting");
local returncode=mc.mcSignalWait(inst,mc.ISIG_SPINDLE_AT_SPEED,mc.WAIT_MODE_HIGH,10.0);
    if (returncode==mc.MERROR_TIMED_OUT) then
        mc.mcCntlSetLastError(inst,"spindle does not respond");
        mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_OFF);
    else;
        mc.mcCntlSetLastError(inst,"m4 at speed");
    end;
end
if (mc.mcInEditor() == 1) then
    m4()
end

Code: [Select]
function m5();
local inst=mc.mcGetInstance();
mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_OFF);
mc.mcCntlSetLastError(inst,"m5 stopping");
local returncode=mc.mcSignalWait(inst,mc.ISIG_SPINDLE_AT_ZERO,mc.WAIT_MODE_HIGH,10.0);
    if (returncode==mc.MERROR_TIMED_OUT) then
        mc.mcCntlSetLastError(inst,"spindle does not respond");
        mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_OFF);
    else;
        mc.mcCntlSetLastError(inst,"m5 is stopped");
    end;
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.'