Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: hyildiz on September 29, 2017, 06:24:53 PM

Title: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on September 29, 2017, 06:24:53 PM
Hi,

When all necessary adjustments made Mach4 does not wait spindle to come at speed entered in gcode or MDI before starting machining.

Delta brand VFD is adjusted to send signals of Spindle at speed and spindle at zero to 2 inputs and they can be seen in diagnostics page and they function ok, in spindle tab wait for spindle to stabilize is selected, but when i hit cycle start machine dive into gcode whlie spindle is still accelerating.

This is clearly a bug in Mach4, is there a solution for this?

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on September 29, 2017, 06:51:55 PM
Hi Hakan,
can you confirm that the spindle setup tab you are looking at is Configure/Mach/Spindle?

If so I think you are misinterpreting the setup you are making. If as you say you've checked the 'wait to stabilise' setting then Mach will be looking
for some spindle feedback to determine whether the speed has in fact stabilised. I expect that Mach is looking for an index pulse or encoder pulse stream.

You have signals from the VFD to indicate whether its up to speed or when stopping that it is stopped. Could you not take the m3/m4 macros and add code
to delay until your upto speed signal comes true? Likewise your m5 script could wait until your stopped signal comes true before returning to the calling
program.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on September 30, 2017, 05:02:49 AM
Hi Craig,

When i select 1 input as Spindle At Speed and 1 as Spindle At Zero shouldnt Mach4 automatically look for those signals to check whether spindle is at desired speed or at zero? otherwise why those signals are in the setup? When i said bug i meant this, those signals are not connected to anything whether u assign an input to them or not Mach4 does not take them in to consideration but it should logically.

Well i am not good at in writing codes, can you help me with that? Thanks in advance.

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on September 30, 2017, 05:54:45 AM
Hi Hakan,
I don't know for sure but I believe Mach4 is expecting some sort of feedback pulse and it uses that pulse stream to calculate the
actual spindle speed and display it.
Quote
droTrueSpindle
the name of the DRO in the upper lefthand corner of the Spindle block of controls.
I've yet to find any code that describes how the DRO is updated, I think its part of Machs core nor have I worked out how a pulse input is directed
to the module.

Without some sort of pulse feedback how could Mach ever know the actual spindle speed, it's almost sure that it will differ from the programmed speed.
Exactlty how the signal is assigned and the calculations done I don't know yet.

My understanding is this is the primary method Mach uses to monitor the spindle. I imagine it could be modified to reflect the available input data,
so it could accommodate an index pulse once per rev or an encoder of hundreds of pulses per rev. I note that many VFDs have programmable outputs
to simulate an encoder. Further I note that VFDs can output an analogue voltage equivalent to spindle speed. While direct monitoring of spindle speed
may be the primary method there are alternatives.

The input signals Spindle at Speed and Spindle at Zero are inputs which have been predefined in Mach. The Probe signal is another predefined signal
but it maybe your machine doesn't use it and therefore has no input pin assigned to it. Because Probe is such a widely if not universally used input
it makes sense to have a signal name defined. It analogous fashion the two signals you're talking about are available on just about every VFD and so
make useful candidates as predefined signals.

In your case given that you have wired the controller inputs with these two signals you can assign Mach predefined signals and then use those signals to
effect behaviours you wish, for instance triggering delays in the m3/m4 and m5 scripts. You are already half way to achieving the behaviour you want or
you could abandon that approach and use the more conventional pulse monitoring approach above. May I suggest that you complete the control solution
you've already started. It will require some code additions to m3,m4 and m5. Once you have that operational then you might consider the other approach.
I think that a lot of the required functionality required to make the pulse approach work are already included in Mach and really only requires
settings to be made for it to work. You could then compare the two ideas to see which is best and learn a bunch about Mach/LUA as you do so.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on September 30, 2017, 12:40:21 PM
Hi Craig,

"Without some sort of pulse feedback how could Mach ever know the actual spindle speed, it's almost sure that it will differ from the programmed speed.
Exactlty how the signal is assigned and the calculations done I don't know yet."

I am not trying to see spindle's rpm or Mach4 does not need to know the rpm, Delta VFD has a function which makes it send a signal when the spindle reached the commanded rpm by controller this is an internal function, for example in gcode it says M3 S6000, when Mach4 send 6000rpm signal to VFD(pwm signal) VFD reads that as commanded rpm and when spindle reaches 6000rpm it closes a relay and if u connect that relay to an input of pmdx126 u get an input signal of Spindle At Speed so when Spindle At Speed signal turns on Mach4 knows the spindle is at 6000rpm.

So the thing i am trying to do is make Mach4 to acknowledge Spindle At Speed signal as u said it is predefined in it but it does not take that signal into consideration to make the machine stand by until Spindle At Speed signal turns on.

I am not sure if you can make this by altering the M3 M4 or M5 scripts. For example at first i thought to make it work like you but in M3 script it just defines the Spindle to turn in Clockwise direction there is nothing associates with rpm, the rpm is in the gcode after M3 command so how can u read the spindle speed from each gcode by M3 script?

The logical way is this, when u assign the input to Spindle At speed function in Mach4 it should automatically says "Spindle At Speed is assigned" and "i need to wait for that signal to turn on before letting the axis move when Cycle Start pressed". This is why u have Spindle At Speed function am i wrong? Is there any other use of it? Professional machines use that signal like this and every machine waits Spindle At Speed input to turn on before diving in to gcode.
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on September 30, 2017, 01:36:53 PM
Hi,
the desired behaviour is that the machine wait until the spindle is up to speed before setting off on its moves.

The machine must therefore measure the spindle speed and compare it against its programmed speed, that is the meaning and use of
'Wait on Spindle to Stabilise' and 'Percentage' entries on Configure/Mach/Spindle page.

If you don't want to use that functionality then use Spindle Up To Speed signal. It is as it stands just a predefined signal, it doesn't do anything.
If you wish it to do something then YOU must program that something.

It certainly is possible to modify the existing m3,m4 and m5 scripts.

I think it will be necessary to add the two signals to the Signal script.
Then have a delay in m3,4,5 until the signal state is true.

If you haven't done any programming in LUA then I suggest
https://www.lua.org/pil/contents.html (https://www.lua.org/pil/contents.html)

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on September 30, 2017, 02:41:44 PM
Hi Craig,

you are telling me to learn Lua so that i can implement any function i want, i get it, what i wanted to point out in here is, if it doesnt do anything what is the meaning of predefining it, user can name any input as Spindle At Speed, so if user see a defined signal then he/she assumes it does something..

I will try to modify M3 M4 M5 scripts.

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on September 30, 2017, 02:53:28 PM
Hi,
first you need to add the two signals into the signal library, its a table called SigLib in the screen load script, add the following:
Code: [Select]
[mc.ISIG_SPINDLE_AT_SPEED] = function (state)
    if (state==1) then
        AtSpeed=1
    else
        AtSpeed=0
    end
end,
[mc.ISIG_SPINDLE_AT_ZERO]= function (state)
    if (state==1) then
        IsStopped=1
    else
        IsStopped=0
    end
end,

This allows you to use AtSpeed and IsStopped global variables throughout Mach. If you have a look at the bottom of page 9 and the top of page
10 of the LUA Scripting Guide in your Mach4 Help Docs you will see that Mach4 has built-in m3, m4 and m5 which cannot in fact be altered. What
you can do is write your own m3, m4 or m5 and Mach will execute your script instead. Any functionality in Machs internal script will have to be duplicated
in your external script in addition to whatever extra 'fruity bits' you want to happen.

Next little trap is that you should name your scripts with lowercase m and the script number without leading zeros. Thus M03 is likely to result in error
whereas m3 will be fine. Remember if Mach doesn't find your script it will use its own, if you name your script badly it may miss the fact that its there.

I will gather some more info and comeback with some suggestions.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on September 30, 2017, 03:04:08 PM
Hi,
in modern programming there is a distinction between an object and its action.

In this case we have two signals which have conveniently been predefined by the developers of Mach. We can easily connect them to an input pin
for instance but we could also connect it to some other software event.

So we have a signal defined and logically connected to a trigger of some description. We now have to define what that will mean.

You have a signal Spindle at Speed, what do you want Mach to do with it? Machs not magic nor are the developers clairvoyant....you have to decide what
behaviour the machine should exhibit and fortunately there are some clever and flexible tools for you to do that, it will require some learning.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on September 30, 2017, 03:22:50 PM
Hi,
sick of me yet...

On the screen edit page the spindle control button at the lower right of the screen Spindle CW/Stop and SpindleCCW/Stop have two associated
event functions SpinCW() and SpinCCW(). The functions are in the screen load script and are interesting enuf even if simple.

What I suggest is that you replace the event scripts for these two buttons with:
for the left-up script for btnSpindleCW
Code: [Select]
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 1) then;
    mc.mcCntlGcodeExecuteWait(inst,"m5");
else;
    mc.mcCntlGcodeExecuteWait(inst,"m3");
end;

and for the left-up script for btnSpindleCCW
Code: [Select]
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 1) then;
    mc.mcCntlGcodeExecuteWait(inst,"m5");
else;
    mc.mcCntlGcodeExecuteWait(inst,"m4");
end;

Now when your Gcode program encounters a spindle start instruction, m3, the macro runs as normal. If you however manually turn your spindle
on it too will execute the m3 macro rather than the built in SpinCW() function which won't have the delay behaviour you want.

Will comeback with some suggestions for the all important m3,m4 and m5 macros shortly.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 02, 2017, 12:54:21 PM
Hi Craig,

Ok, thanks for helping me out.

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: Chaoticone 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.
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: ger21 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.
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage 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
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 04, 2017, 10:37:59 AM
Hi Craig,

I wont be able to test new macros for a week but when i test it i will write u the results.

When we finish this lets open a new topic in mach4 forum with name " Macros for Mach4" and lets put working macros under it so all users can find and use them easily.

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 04, 2017, 01:09:19 PM
Hi,
the daughter board 'Mach4 Toolbox' is the right spot.

It is my experience that a large fraction of users don't read or search the forum. Would they find anything?

Generating some useful code is worthwhile but learning how to write it and the thinking that goes on to improve and develop the code is
even more valuable.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 16, 2017, 11:13:50 AM
Hi Craig,

The last M3 code you sent does not work, the one before works fine but the last one says "m3 at speed" but it does not wait "spindle at speed" input to turn on, it dives in to gcode while spindle still accelerating.

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 16, 2017, 01:39:04 PM
Hi Hakan,
I've tested it and have the same problem. The return code from the mcSignalWait is MERROR_INVALID_ARG
yet as far as I know all the arguments are valid. Will make further investigations.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 16, 2017, 02:14:05 PM
Hi Hakan,
so far what I've discovered is that the API call works with ISIG_INPUT0 but not ISIG_SPINDLE_AT_SPEED.
I have checked and ISIG_SPINDLE_AT_SPEED does evaluate to a number so why the API fails is a mystery. Have started a ticket to ask.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 17, 2017, 02:50:03 AM
Hi Hakan,
found out a little more about the mcSignalWait API... it accepts signal ID arguments in the range 1-64. Those IDs correspond
to ISIG_INPUT0 thru ISIG_INPUT63.

The two input signals we have used are
ISIG_SPINDLE_AT_SPEED    signal ID =181
ISIG_SPINDLE_AT_ZERO      signal ID=182

So the mcSignalWait API call wont work for these two inputs, but is in all other respects perfect for your purpose.
My suggestion is rather than use ISIG_SPINDLE_AT_SPEED and ISIG_SPINDLE_AT_ZERO chose any two signals from ISIG_INPUT0 to ISIG_INPUT63
instead. You don't have to change any wiring, just assign the pin to your chosen input.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 17, 2017, 03:01:40 AM
Hi Hakan,
assign Input#62 to your spindle-at-speed pin and Input#63 to your spindle-stopped pin:
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_INPUT62,mc.WAIT_MODE_HIGH,10);
    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

and:
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_INPUT62,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
and:
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_INPUT63,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

See how that works.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 17, 2017, 06:59:06 AM
Thanks Craig,

I will check and reply.

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 18, 2017, 09:49:22 AM
Hi Craig,

the last ones u sent works fine, but in my case vfd sends a signal to input62 for a 2-3 milisecond when spindle starts, it just turns it on for some miliseconds and closes it then when spindle reaches the entered frequency it turns it on, i dont know why it does that but when it turns it on for a 2-3 milisecond or so the m3 code sees the input62 gets high and it says "m3 at speed" and continues the gcode while spindle is still accelerating. In m5 it works correctly because input63 does not do that glitch.

I also checked whether if ISIG_SPINDLE_AT_SPEED did not work because of this glitch but no it doesnt work for m5 either.

So the last code works fine, i will contact with delta vfd support to sort it out.

Regards,

Hakan

Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: DazTheGas on October 18, 2017, 01:18:34 PM
Have you thought about putting a short delay in the script to counteract the short signal.

DazTheGas
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 18, 2017, 01:41:14 PM
Hi,
Daz has a useful solution.

I wonder why its happening. Could it be that the spindle gets told to turn on and THEN gets its new commanded frequency. So just for a wee while it believes
its already up to frequency....its just that frequency is zero?

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: DazTheGas on October 18, 2017, 02:47:19 PM
This should get you going, just tried on my machine and works fine.

Code: [Select]
function m4()
local inst = mc.mcGetInstance();
   
mc.mcSignalSetState (mc.mcSignalGetHandle (inst, mc.OSIG_SPINDLEON),0)
mc.mcSpindleSetDirection(inst, mc.MC_SPINDLE_REV)
    wx.wxSleep(10) -- Change to how many seconds you require
end

if (mc.mcInEditor() == 1) then
 m4()
end

DazTheGas
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 18, 2017, 04:14:31 PM
Hi Daz,
that code introduces a straight delay. Hakans intent was to use a signal from the VFD to indicate that the spindle
is at commanded speed.

If you are using a small diameter endmill the spindle could accelerate quickly whereas a large face mill would take longer.
The advantage of waiting only until a signal comes good is clear.

Hakan hasn't said how he commands frequency/speed of the spindle. If he is using modbus whats the bet that the
start signal is arriving before the frequency command.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 18, 2017, 04:43:27 PM
Hi Daz,

Our purpose was to get the "spindle at speed" input HIGH before moving the gantry, so that while using MDI or Gcode machine will not move before vfd does not send the signal.

Which reminds me Craig, in this code if vfd does not send the signal m3 code gives "spindle does not respond" and continues the gcode when spindle is not moving. Can u add a code there if input62 is not HIGH machine should not move.

I am trying to make this logic work because there will be a AC line lost procedure which will be controlled by arduino, machine has internal ups, basically while machine working for hours if AC line lost occur arduino will take control and feed hold the machine first then record the coordinates and gcode line then it will park all axises to a location and shut down the power. Then it will start to listen the AC line, when line comes back it will turn on the machine, goes to the coordinates recorded, input the gcode to Mach4 and goes to the last line and start from there. During this procedure it will check the spindle input but to be sure i need that function also in Mach4 so it wont dive in to part with spindle off which is very dangerous.


Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 18, 2017, 05:00:34 PM
Hi Hakan,
what code are you referring to... I personally don't think Daz's code is suitable as is, it could be made so but it is only
a barest sketch of what it would need to be in practice.

May I suggest that you use Mach to detect phase loss and if you wish it phase rotation. Mach can therefore shut down
or refuse to engage if it detects power fault.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 18, 2017, 06:13:21 PM
Hi Craig,

Das's code is not suitable for my purpose.

I was referring to the m3 code u sent last, when it can not see the input62 it says "spindle does not respond" and then instead of stopping it goes on to gcode/MDI code and all axis moves with spindle turned off. Is there a way to stop it when there is no input62 HIGH signal?

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 18, 2017, 07:55:22 PM
Hi Hakan,
I understand what you mean. We have code that waits for the spindle to accelerate or detects thats the spindle
is un-responsive. In the event of an un-responsive spindle what do you want the machine to do?
You could cause an Estop or a Feedhold easily enuf.

I think you could incorperate into your power detection/protection strategy. I would suggest that you get a power
monitor relay, for under $100 you can get a relay which monitors under/over voltage, phase failure and phase rotation.
The contact of the relay could be monitored by Mach easily. Why bother with another device like an Arduino?

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 19, 2017, 01:47:31 AM
Hi Hakan

Quote
I am trying to make this logic work because there will be a AC line lost procedure which will be controlled by arduino, machine has internal ups, basically while machine working for hours if AC line lost occur arduino will take control and feed hold the machine first then record the coordinates and gcode line then it will park all axises to a location and shut down the power.

This can be done quite easily and I don't think an Arduino is required or desirable.

Quote
Then it will start to listen the AC line, when line comes back it will turn on the machine, goes to the coordinates recorded, input the gcode to Mach4 and goes to the last line and start from there. During this procedure it will check the spindle input but to be sure i need that function also in Mach4 so it wont dive in to part with spindle off which is very dangerous.

This is a nightmare idea. I suspect that in New Zealand it would be illegal to have a machine start itself unless that machine were completely isolated from all
human contact. A restart of this nature should be under operator control.

In Mach3 there was the possibility to 'Run From Here', although many a CNCer came to rue the code, if it wasn't buggy it certainly seemed unpredictable and many
a job was wrecked as a result. There is no such code in Mach4, you would have to construct it. It really comes down to fictitiously running the Gcode up to the point
of the restart to determine the modals which were in operation prior to shutdown and incidentally the X,Y,Z cords  at the point of shutdown. The restart requires the
machine drive to the required co-ords whether derived from the fictitious run or from memory as stored at the moment of shutdown, restart the spindle and <cycle start>.

All in all quite a programming undertaking for someone who confesses to be a Lua newbie. If you want a hand to code some sort of safe shutdown procedure as a result
of power failure or spindle speed failure I will help. I am VERY dubious about helping anyone code 'Run From Here' functionality particularly and especially if it is to be
automatic.

Craig

Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 19, 2017, 04:37:56 AM
Hi Craig,

Its not that complicated actually, arduino is C based programming and i can do it (as long as its not too complicated) and as u know it has a wide resources for projects of all kind including communication with Mach4 via Ethernet. I will use arduino mega, ethernet and usb host board connected and its peripherals because i already start the machine with a fingerprint reader and arduino is controlling the power up procedure with relays. So it is already installed and later, through usb host i will add 3dconnexion 3d mouse to control the machine by wireless 3d mouse in all axis.

Arduino will watch the ac line with a voltage sensor so it will know the value of the voltage because in here sometimes it fall below 220V which is bad for electronics. Installed UPS will balance the voltage but if it takes too long to return to normal state arduino will interfere in that case too.

As u know some gcodes takes 9-10 hours to finish, with this setup i will be able to leave the machine on its own at nights so if lights out it will park and wait, when AC line comes back it will go on from the point which it stopped. In case of flickering in AC line or phase lost installed UPS take care of that. Its some kind of helpful automation ;-) installed UPS and batteries have enough power for running the machine about 10minutes with full functionality so it will give more than enough time to arduino for parking and recording the states of DROs, machine coordinates, gcode file, gcode line, etc. Arduino has external separate ups which holds it on for 1-2 days, so it will park the machine and shut down the power and wait for AC line to come back by itself.

Related with the signal glitch problem,

In this Delta VFD there is 2 outputs, 1 is a relay and 1 is an output signal(not relay), i connected the spindle at speed to relay output which is making that glitch so today i will change it with signal output and connect the relay to spindle at zero i think it will solve the problem because signal output does not make that glitch.


Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 19, 2017, 05:47:26 AM
Hi Hakan,
trying to have your machine restart and resume a Gcode job automatically is likely to prove an expensive mistake.

As far as stopping the Gcode file from running if the spindle is un-responsive you could try
Code: [Select]
mc.mcCntlCycleStop( number mInst)
or
Code: [Select]
mc.mcCntlEStop(number mInst)
or
Code: [Select]
mc.mcCntlFeedHold(number mInst)

That's the easy part.
How are you controlling the VFD?. I think the start signal is arriving before the frequency/speed command and therefore you are getting a glitch.
Do you want to solve the glitch or just have some workaround to the problem?

Craig

Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 19, 2017, 10:27:20 AM
Hi Craig,

I changed the relay output with signal output and it does the same glitch.

I am controlling the VFD with 0-10V, PWM signal and i think u are right about the start signal and frequency signal but logically u adjust the vfd to turn that signal on when spindle is at commanded frequency not when start running, so i think there is a bug in vfd's logic also.

In m3 code it checks the input62 whether it is HIGH or LOW and if its HIGH it goes on to script, is it possible to put a time constraint to alter the momentary signal? for example is it possible to say if input62 is HIGH for lets say 2 seconds go on, if it is not for lets say 10 seconds feed hold the machine and display a message in window and ask user if he wants to go on or not with spindle off, because sometimes u may run the code without turning on the spindle to check if the code is ok for some reason..

if this is too complicated we can just feed hold the machine.

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 19, 2017, 02:05:56 PM
Hi,
the fault is your Gcode. It should set the PWM with a Snnnn command, wait for 5-10ms for the PWM to propagate to the VFD THEN issue a start command.

You can cheat to overcome this if you can't be bothered to fix your Gcode by having a delay before calling mcSignalWait so that the glitch has been and gone
before Mach requires it.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: Steve Stallings on October 19, 2017, 02:50:58 PM
The fault is not necessarily with the G code. It is common to issue an M3 and an S word on
the same line of G code.

Even if the S word is issued in advance, that does not guarantee that the PWM to analog
conversion will happen before the M3 takes effect. That will be dependent on how the
motion device handles the signals. PMDX products will inhibit the analog out until the
M3 is issued. Indeed, Mach3's own parallel port driver will not generate a PWM signal
until the M3 or M4 command is issued.

Using a pause for spin up, or using feedback are valid approaches to the problem.



Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 19, 2017, 03:43:25 PM
Hi Steve,
kool thanks for that explanation. A simple delay will probably work. Thanks again.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 20, 2017, 11:20:21 AM
Hi Craig,

I didn't fix the signal glitch problem from VFD but i changed the code as follows so it works for me like this;

Code: [Select]

function m3();
local inst=mc.mcGetInstance();
mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_FWD);
wx.wxSleep(1)
mc.mcCntlSetLastError(inst,"m3 waiting");
local returncode=mc.mcSignalWait(inst,mc.ISIG_INPUT62,mc.WAIT_MODE_HIGH,10);
    if (returncode==mc.MERROR_TIMED_OUT) then
        mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_OFF);
        mc.mcCntlSetLastError(inst,"spindle did not respond, cycle stop");
        mc.mcCntlCycleStop(inst, 0);
       
    else;
        mc.mcCntlSetLastError(inst,"m3 at speed");
    end;
end
if (mc.mcInEditor() == 1) then
    m3()
end


i am not sure if this "mc.mcCntlCycleStop(inst, 0);" is the correct usage of it but it works fine like this.

this code jumps over the glitch problem by waiting for a second or so before checking the input62 so when spindle reaches the commanded rpm vfd turns on the input62 and code says "m3 at speed" and goes on to gcode.

Also in case of missing input62 HIGH, it says "spindle did not respond, cycle stop" and stops the gcode.

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 20, 2017, 03:02:55 PM
Hi Hakan,
kool, that is very much what I had in mind for your machine.

Only a week or so ago you were convinced that you couldn't write or didn't want to write any Lua code now you're doing it on your own!

An alternative that you might wish to explore in the future is having another macro, m100 for instance, that when called does things like
record the name of the current G code file, the line number being executed.....and so on. All the features you might require in a shutdown script.
In the case of your m3, m4 or m5 scripts an unresponsive spindle might qualify as a shutdown event. If that were the case you'd substitute

mc.mcCntlGcodeExecuteWait(inst,'m100') for your current shutdown statement mc.mcCntlCycleStop(inst, 0).

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 20, 2017, 03:36:55 PM
Hi Hakan,
the Lua syntax:
Code: [Select]
rc = mc.mcCntlCycleStop(
number mInst)

So you don't need the extra  ",0 in the cycle stop API. I doesn't hurt it though, Lua matches arguments one for one and leaves the rest. So the "0" input
argument would be ignored.
Mach4s API help docs are in the <Help Docs> library of the File Ops tab. I use it that much that its now pretty much permanently on the task bar.

Craig.
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 20, 2017, 05:50:57 PM
Hi Craig,

"Only a week or so ago you were convinced that you couldn't write or didn't want to write any Lua code now you're doing it on your own!"

Come on, u wrote the code i just added 2 lines in there and i took one from Daz's code ;)

I want to learn Lua and write scripts with it to program Mach4 also want to make the interface with it which has animated readouts etc. but Lua has very limited resources on the web. For example as a programmer those resources may be enough for you but for people like me it has to be more like the arduino resources, it has to be more detailed with much examples.

But the thing that u and Daz do in here, helping people for beginning in Lua is something very valuable, i really appreciate your help, thanks once again.

Today when i made the code work, i enjoyed watching the machine act more aware of whats happening, u know it listens an input, waits and when spindle gets to desired rpm it moves the machine, it acts more smart. Machines should not move blind or operator dependent, they can be more reliable with these kind of small add-ons.

M100 idea is a very good idea, it will be wise to make it write the all collected data to a file and make arduino keep the file or load it to restart sequence of the controller after the AC line restored..

Regards,

Hakan




Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 20, 2017, 06:29:18 PM
Hi Hakan,
I felt exactly the same way only a few months ago, I thought I had made a big mistake trying to learn Lua. You're right there doesn't seem to be that much useful
stuff about Lua. There is in fact enuf about Lua, Lua is in itself very simple, where it gets tricky is adding API calls, wxWidget calls and Machs software structure.
In that regard there is no substitute for rolling up your sleeves and getting stuck in. That's what I did and with the help of Daz and smurph I have made progress.
Progress is very satisfying as you've found. Despite your beginner status you've already surpassed the efforts of many.

As I commented before helping someone else code something new is a perfect opportunity for me to learn new things about Lua.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 21, 2017, 04:10:51 PM
Hi Hakan,
I had a reply from Rob at Artsoft about the input signal snafu I blundered into. He confirms that we would require an expansion board to use ISIG_SPINDLE_AT_SPEED.
This poses another question. Certainly we know that ISIG_SPINDLE_AT_SPEED is defined and it works, we can see the LED turn on and off. We wished to
make use of it in our mc.SignalWait() API call but it didn't work there and Rob confirms that some expansion would be required for it to work.

I'm guessing here, but based on a few related observations ALL of Machs input are numbered 1 thru to whatever. Internally Mach has no idea what ISIG_INPUT#17
or ISIG_SPINDLE_AT_SPEED means, it recognises input #17 and input #181. So the labels are defined for our benefit because we don't immediately recognise
input #181 for instance. It would appear however that not all API calls are created equal, in this case mc.SignalWait will accept inputs 1-64 but not higher
but mc.SignalGetHandle() will tolerate an input higher than 64, our #181 being the numeric equivalent to ISIG_SPINDLE_AT_SPEED for example.

What is not clear to me is what sort of 'expansion' is required. Given that input #181 can be read and interpreted by Mach in some instances suggests there
are enuf bits for several hundred inputs so it won't require a hardware expansion. I can only guess that mcSignalWait requires software extension.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 21, 2017, 05:06:18 PM
Hi Craig,

The reason why we couldnt use ISIG_SPINDLE_AT_SPEED is because they assigned it to something but didnt complete the code for it.

Why do u assign a name to a function? because it does something, if it doesnt do anything then why did u assign a name to it? user can use any input(which we did, we used input62) to implement this function.

I assume that they had this idea to implement it to Mach4 but for some reason they didnt, and the extension Rob is talking about is a new version of Mach4 in which Spindle at speed is defined ;)

It has to be like this, when u select Spindle At Speed from the menu and assign it to a pin number, Mach should automatically see it and wait for that signal to turn HIGH after Cycle Start pressed and if not it should display a message which asks user if he/she wants to go on without spindle running.

I was saying this from the beginning and that is the reason why we couldnt use the ISIG_SPINDLE_AT_SPEED and ISIG_SPINDLE_AT_ZERO because they assigned to some function but function is not defined within Mach4 and software does not let user to define that function.

Spindle at speed signal is the best and cheapest way to make the machine know that spindle is at commanded speed, most of the VFDs providing this function, if u dont use it u have to buy a spindle which has encoder installed or u have to install a encoder or rpm sensor to the shaft of the spindle, first one is expensive and second one is dangerous so best and industrial way of knowing that the spindle is at commanded speed is using this function and it must be implemented to industrial version.

Regards,

Hakan

Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 21, 2017, 06:00:34 PM
Hi Hakan,
Quote
I was saying this from the beginning and that is the reason why we couldnt use the ISIG_SPINDLE_AT_SPEED and ISIG_SPINDLE_AT_ZERO because they assigned to some function but function is not defined within Mach4 and software does not let user to define that function.
Rubbish! The SIGNAL is defined the ACTION is not. The modern programming paradigm is the an object and its action are separate. You create what ever function
you require to achieve the behaviour you want and then you LINK the OBJECT (input signal ISIG_SPINDLE_AT_SPEED) to your desired ACTION ( your function)
In this case we used a particular API call to make our function (mc.SignalWait()) but unfortunately that particular API has limited input range but otherwise
preforms perfectly. If we chose to use a different way to make our function that didn't use that particular API call the we could have used ISIG_SPINDLE_AT_SPEED
throughout.

Quote
Spindle at speed signal is the best and cheapest way to make the machine know that spindle is at commanded speed, most of the VFDs providing this function, if u dont use it u have to buy a spindle which has encoder installed or u have to install a encoder or rpm sensor to the shaft of the spindle, first one is expensive and second one is dangerous so best and industrial way of knowing that the spindle is at commanded speed is using this function and it must be implemented to industrial version.
Certainly using the At Speed or Is Stopped signals provided by VFD is cheap and easy...look you've done it yourself. My VFD and its hardly unique, a Delta, synthesises
and encoder output which can be read by Mach. Its built in...no cost involved. Yes if you require exact and/or physically confirmed rotation then you'll need a tacho
or similar. The At Speed signal cannot determine if the rotor is spinning except indirectly and so would fail a safety test which might be required of a coolant pump
or a lift motor. Such applications require a tacho or indexer, safety requires it and is in effect leaglly mandated by Codes of Practice and various National Standards.

My spindle can use the 'Wait on Spindle to Stabilise' and 'Percentage' functions already in Mach4 for exactly that purpose. You may recall early in the piece I advised you
that you could use either of two methods to achieve what you wanted. You chose to go with the  At Speed/Is Stopped route whereas the other method reqired
you program your VFD to produce a pulse output and have Mach use its inbuilt functions to read and act on it.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 21, 2017, 06:25:48 PM
Hi Craig,

U know these programming things better than me so i trust your word on it ;)

Quote
whereas the other method reqired you program your VFD to produce a pulse output and have Mach use its inbuilt functions to read and act on it.

How did u program your VFD to produce pulse output?

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 21, 2017, 07:13:24 PM
Hi Hakan,
the output is called 'Digital Frequency Meter' or DFM and has a programmable parameter per attached.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 21, 2017, 07:44:13 PM
Hi Hakan,
this is pulse output that is equal or at least proportional to the output frequency of the VFD. As you know an induction machine will not rotate at
the frequency on its terminals but at some slower speed determined by the slip. With a good installation and motor the slip is seldom more than a few
percent of the input frequency. This signal is a fair representation of spindle speed.

If however the spindle is stalled for whatever reason the frequency would still be applied to the stator but the rotor would not turn. The output signal
would indicate wrongly that the spindle is rotating. The machine would very likely fault out 'current overload'. The essential point is that the pulse signal
is a reasonable estimate of spindle speed except under fault conditions and potentially inaccurate at start up conditions. If you called for the frequency
to ramp up too much faster than the spindle can accelerate and yet be within its fault current limit the output signal may get to 50Hz say while the spindle
is still trying to accelerate and is spinning at only 40Hz.

Most recent VFDs offer sensorless vector control, the VFD very cleverly uses current fluctuations to guess at the rotor actual speed and position. As such they
can be thought of as a servo. They can't achieve position control and their accurate speed control has a span of 10:1 or thereabouts. Of course a servo with
a proper encoder blows them into the weeds but none the less a very clever use of the digital signal processing power available to manufacturers. My Delta
does sensorles vector control but doesn't provide a derived rotor speed pulse, just the input frequency as above.

The signals At Speed and Is Stopped suffer the same problem, they represent whether the applied frequency is at speed or stopped but it can't actually tell
what the rotor is doing. If it was a matter of safety that the motor was rotating then would would need a device to measure it like an encoder. Even a sensorless
vector control VFD is still a derived measurement and wouldn't satisfy me in a lift application for instance.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 22, 2017, 05:03:52 AM
Hi Craig,

My VFD is also a Delta VFD-E series and it is sensorless vector control, i couldnt find DFM in the user manual but in my VFD it is called MO1 and MCM i guess, i am using that terminal to get the spindle at speed signal.

From your description i think they are basically the same thing right? VFD is guessing the rpm by the frequency so the result of your way and my way is same.

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 22, 2017, 12:24:29 PM
Hi Hakan,
my VFD is a B series unit. It has the Multifunction Opto Outputs as well, but they are just digital IO, they do not switch on and off that fast
to my knowledge. The DFM and DCM terminals are separate and dedicated to that one job.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 22, 2017, 12:41:32 PM
Hi Hakan,
just downloaded the Delta E series manual and it doesn't appear to have apulse output.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on October 22, 2017, 05:04:39 PM

I couldnt see that either Craig,

but we solved the problem anyway so its ok.

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on October 22, 2017, 11:05:51 PM
Hi Hakan,
yes you've already got the basis of a solution and the code to do it.

If you had or wanted to adding an indexing unit need not be that hard. This little Hall effect sensor requires 5V, 0V and output all for $2.03 NZD. Add a little
button magnet for another dollar and you're done.
http://nz.element14.com/honeywell/ss411p/sensor-hall-effect-bipolar-to/dp/1784734 (http://nz.element14.com/honeywell/ss411p/sensor-hall-effect-bipolar-to/dp/1784734)

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on December 26, 2017, 12:47:35 PM
Hi Craig,

I am back  ;D

the spindle at speed function we(you) implemented to Mach4 works just fine machine acts more like a professional machine and now i decided to upgrade the spindle to more professional one i ordered one BT40 ATC belt driven spindle from CELLS.I remember u saying something like that i can add an encoder to the spindle, so that Mach4 will know the exact rpm of the spindle. This will also help in other functions like threading etc.

I searched some suppliers and found an encoder which has 12000rpm max. speed but 100ppr as resolution(u can see details in the attached document), i have couple questions to u since u know these technical stuff better than me;

- do u think this encoder is suffice for Mach4 in means of ppr?
- what output type(NPN, Voltage Output, etc) should i choose?
- what output phase(A, A+B, etc.) should i choose?

to make this work with Mach4, and i have PMDX126+ESS setup also using PMDX107 board for pwm spindle control.

Thanks in advance,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on December 26, 2017, 01:28:30 PM
Hi,
you don't really need an encoder. Mach requires an index pulse, that is one pulse per revolution, and it ca calculate the rpm from there.
Many encoders have the normal quadrature A and B channel but often an index pulse as well, sometimes called I or Z signal. If you wish to fit
such an encoder go to it but realize that you'll only be using a small fraction of it capabilities.

I suggest a small Hall sensor and a small magnet glued to the spindle shaft.

http://nz.element14.com/honeywell/ss443a/sensor-hall-effect-140g-unipolar/dp/3111507 (http://nz.element14.com/honeywell/ss443a/sensor-hall-effect-140g-unipolar/dp/3111507)

A suitable example.

Note that Mach is not a closed loop controller, it can use an index pulse to calculate the actual speed but it does not use that speed to adjust the PWM to your target
speed. You can with a bit of clever programming make it do that but the response is very slow. There are a number of external motion controllers that enact closed loop
control, good ones tend to be expensive. Just recently Warp9 have added a simple PID closed loop control to their Ethernet Smoother Stepper. I haven't used it yet but
it would be ideal for this application. Do you have or use an ESS?

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on December 26, 2017, 01:45:46 PM
Hi Craig,

Yes i am using an ESS with my current setup, i installed the new plugin to test the backlash compensation and i saw some new boxes added to spindle tab, is that PID closed loop control function?

As far as i test it its backlash compensation does not work yet i dont know why but as the movement of the axis keeps longer the compensation gets bigger and it results an error on the axis isntead of fixing it. I have 0.003mm backlash because of the ballscrew on one of the axis and i coulnt be able to fix it with ess backlash compensation, this is another topic but i am not sure that spindle PID control works as u said it needs to be tested.

The reason i wanted to use this encoder: it is more suitable to my setup in means of assembling, it has 22mm bore so spindle motor shaft output is 22mm in diamater at the back of it, it will be more compact and professional looking in this way  ;)

Do u think encoder can be connected with ESS PID function and can be used in getting the exact rpm and also in threading type processes?

Hakan

Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on December 26, 2017, 02:05:55 PM
Hi,
by all means use the encoder, its way more expensive, but that's your call.

The ESS PID function at this time accepts one pulse per revolution, ie an index pulse. Provided the encoder has an index pulse it will work.
Andy at Wapr9 has suggested that at a future time a multi pulse per rev PID controller will be enacted but when?

You may have noted that the backlash compensation feature of the ESS is only a month or two old and is still in its Beta test phase. If its not working correctly
get onto the Warp9 forum, Andy needs all the feedback he can get to perfect backlash compensation.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on December 26, 2017, 02:26:27 PM
Hi Craig,

I know its expensive but as u said for future implementations it will be ready, so as far as i understand i should ask to manufacturer that the encoder should provide an index pulse which is 1 pulse per revolution it will be usefull to zero the spindle like an axis. I will implement some other features which i can use that indexing function also so its a good idea, i am not sure if they provide it in incremental encoders but i will ask..

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on December 26, 2017, 02:36:34 PM
Hi,
if the encoder doesn't have an index pulse don't waste your money, it wont't work.

Our previous conversations in the thread were about a VFD. A VFD is not really position capable.  For that you need a servo, in which case the encoder is built
in and you won't need PID of the ESS, the servo and controller offer way way WAY tighter control than that.

If you want an indexing or co-ordinated spindle a VFD and induction motor are not the right choice. Is there any point in trying to provide 'future expansion'
when the existing motor technology wont manage it?

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on December 26, 2017, 03:02:00 PM
Well Craig,

Once again u are right.

The thing is old spindle could not do steel, i installed it to test the positioning and machining accuracy of the machine on Aluminum but i couldnt stop my self since the machine body is strong i tried it on steel so spindle couldnt take it  ;D

so i had to change it with lowest cost possible, i sent it back to manufacturer and engineer in there is a good guy and he made me a new induction motor with 4 poles 400mhz 12000rpm specs. and i paid 50 bucks for that. As u know i had 4kw delta inverter so no need to change the inverter i already got the motor and tested it. Its better than the old one, bigger motor 130x130mm and i will use it to drive the CELLS spindle. So at the beginning i thought to go with Servo motor but it would be more expensive and as u know servo motor max. speed is about 3000rpm. I will use this induction motor with direct coupling to the belt driven spindle because my Zth axis has no space for belt setup.

As u say for now best way is to use the hall effect sensor with a small magnet on the output shaft, i think ESS PID should work with that as u suggested. Any programming needed to make it work?

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on December 26, 2017, 03:27:39 PM
Hi Hakan,
no special programming that I know of.

You were lucky to get a new motor that cheaply. I have a much smaller (750W) German made spindle and a Delta VFD capable of 24000 rpm.
I thought I would be able to do steel to....didn't work. The problem with high speed spindles is they have very little torque and so spinning a tool slowly,
as is required by steel, is just their weakest point.

To cut steel and stainless I made my own spindle with a RegoFix cylindrical ER25 tool holder, ABEC7 angular contact bearings and a second hand 1.8kW
Allen Bradley servo and drive. The servo is rated to 3500 rpm and I have it direct coupled to the toolholder. Rated torque of 6Nm and temp overload of
18Nm. Works really really well in steel and stainless. My little mill can't really handle the torque but man sure makes chips!

One of the advantages that come with using a servo is that they are superbly position controlled so I can do rigid tapping for instance. Speed control when
you have such good position control is trivial. Despite the servo and drive being second hand all up its cost about $2000 to make it, not cheap. I did use
absolute top class toolholder and bearings which added to the cost considerably.

Excepting indexing and rigid tapping your spindle will work well. I think the cheap way of a Hall sensor and a tiny button magnet are the way to go.
Save your dollars for a servo type spindle in years to come.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on December 26, 2017, 04:30:56 PM
Craig,

I think best way is to get a high torque 3000rpm servo motor and connect it to the spindle with 1/4 ratio pulley so it will have less torque but spindle will turn in 12000rpm and u can have absolute control of it. But in my current setup i can not make it because of the shape of the Zth axis, in next machine i will do that altough pulley and belt setup has its negative sides like u can not get smooth surface because of the belt vibration..

Or better than servo-pulley setup i can buy one of these new type high torque high rpm induction servo motors  ;)

https://ctbservo.en.alibaba.com/product/60413434018-802808822/CTB_7_5kw_CNC_milling_servo_spindle_motor.html?spm=a2700.8304367.prewdfa4cf.2.49792a76dr9rjN

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on December 26, 2017, 05:17:57 PM
Hi,
high power, high speed induction motors certainly make good spindle drives but they are not so good at position control.

An induction motor relies on the rotating magnetic field of the stator windings being faster than the rotation of the rotor, the difference, called slip
is what 'induces' current in the squirrel cage rotor and how induction motors get their name. If it were necessary to back the rotor up half a turn say,
as in a position control application, the field windings have to reverse and sufficiently so that there is enough slip for the rotor to be magnetized. If the rotor
overshot then the field windings would have to reverse again including the required slip. Induction motors are not good for position control.

If the rotor is permanently magnetized as they are in servos there is no need for slip. The rotor is synchronous with the field windings. The resulting position
control is way tighter than an induction, also called asynchronous, motor. Additionally there is no requirement for the field windings to supply the induced
rotor current. As a consequence permanent magnet servos are smaller than induction motors for the same power. Further the torque characteristics of a servo
are linear with current and extend to zero rpm. You can use a servo as a torque motor, many thousands are used in this manner in printing presses which is
possible but harder to ensure than with an induction motor.

Induction motors are simple and cheap but if you want position control they are not the right way to go.

There is a warning to, most induction motors are designed for 50-60 Hz line frequency. A motor driven by a VFD has a much higher insulation requirement.
If you use an ordinary induction motor on a VFD it will work provided your not silly but it may also blow up because of the extra insulation required.
'Inverter Ready' motors are available but not so cheap. I wouldn't trust a cheap Chinese induction motor.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on December 26, 2017, 05:30:15 PM
Hi Craig,

As much as i read from their web site they say its special designed servo-induction motor and it has high positioning accuracy, it is driven by a servo drive so i dont think its a regular encoder mounted induction motor, i think they put permenant magnets in it somehow, as u know there are special motors nowadays like magnomatics.. so they modified the induction motor and make an hybrid servo-induction motor as they state.

Also i saw some videos on youtube from ctb servo, by the way they also say it has an holding torque of 17.5Nm at 0 speed of 5.5kw 12000rpm motor so it cant be just a regular induction motor.

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on December 26, 2017, 06:12:44 PM
Hi Hakan,
believe it or not it COULD be an induction motor. If you've done any reading about Field Oriented Control then you will realize that a permanent magnet
motor differs from an induction motor only by the addition of quadrature phase flux to the rotating flux vector. A Google search and look out for some fascinating
videos from Texas Instruments. They get right into sensorless vector control as well, a control engineers wet dream!

Having said that a permanent magnet rotor is still more likely especially as neoydium magnets are now so cheap. There is a blurring here of naming.
Strictly any rotor which is magnetized by 'induced' currents is an induction or asynchronous motor whereas any permanently magnetized (or magnetized by a DC
current in a wound rotor supplied by slip rings) is called a synchronous motor but also called a brushless DC motor or an AC servo.

A brushless DC motor seems like a contradiction in terms. The rotor is permanently magnetized. The stator windings around the outside are required to provide a
rotating flux vector in order to rotate. An electronic control turns DC on and off to the windings to do that. If you think is sounds like a VFD its because they ARE
very similar. What differs with a VFD and a genuine servo drive is that the angular position of the flux vector is under closed loop control with encoder feedback
with a servo drive but not a VFD.

The simplest of switching systems is called trapezoidal control and can be enacted even without an encoder. These are commonly called brushless motors
and are particularly popular with radio control and modellers. The motion is a bit 'lumpy' though.

The other main way is 'Sinusoidal Pulse Width Modulation'. It requires an encoder (for postion control anyway) and results in very smooth and accurate motion
ideal for servos. These are widely called AC servos. The required computing power necessary to do the field oriented control calculations were expensive
back in the 90's but nowadays a 32 bit Microcontroller with single cycle floating point calculation and many many MANY hardware periphials are dirt cheap.
Consequently AC servos are the entry standard now.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on December 26, 2017, 06:31:55 PM

Thanks for the detailed explenation Craig, i didnt understand the half of it  ;D but u say an induction motor may have 17.5Nm torque on the shaft in 0 speed? if so my induction motor sucks because it has 0Nm at 0 speed  ;D

Regards,

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on December 26, 2017, 06:40:21 PM
Hi Hakan,
that can't be correct....if it had zero torque at zero speed when you turned it on it would never start to rotate.

Its certainly true that induction motors have poor and poorly controlled torque at start up and over the years vast sums have been spent
to improve that basic limitation.

Induction motors are great and with VFDs remarkably speed flexible. If you want position control they suck.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on January 10, 2018, 06:01:12 PM
Hi Craig,

It was not of course 0 but what i meant was it was very close to zero, actually what i meant was this;

https://www.youtube.com/watch?v=fzHWudx2wgU

but the strange thing is, this happens my case in the opposite way. When i adjust the vfd as vector drive there is no torque in low speed, but when i change it to v/f mode there is torque and u can not stop the shaft with hand.

As u suggested before i gave up from the idea of intalling an encoder at the end of the shaft, but now if i want to implement the ATC function i need to align the shaft of the spindle to an angle.
The reason is the drive dogs on the tip of the spindle has to go in to a slot in the bt40 holder(at the atc side). So to do this i need to stop the spindle shaft at a point lets say parallel to x axis.

As u know Delta Vfd s has encoder cards PG01 i think or something like that, i thought matbe i install an encoder on the shaft and connect it to vfd through this encoder card it may be possible to stop it at a count number of the encoder. For example if i is 1024 pulse per turn i can program the vfd to stop at pulse 512 in every stop command. I asked this to the Delta support in here they say it is not possible on VFD-E series but it is possible with VFD-C2000 series. But in VFD-E booklet it says u can make speed and position control with this card so i am confused.

do u know anything about this? i attached the related portions of the booklet.

If this is not possible according to u too, can u think of anyway other than the mechanical option?

Thanks in advance.

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on January 10, 2018, 09:25:49 PM
Hi Hakan,
to my knowledge you cannot use a VFD either V/F or sensorless vector mode to achieve position control. I don't think an encoder will help, my Delta VFD can use
an encoder, Delta call it a pulse generator, to get really good speed control but its still not capable of position control.

You need a decent AC servo and drive. I know they are expensive but once you get one you'll never look back.

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: hyildiz on January 11, 2018, 07:07:52 AM
Hi Craig,

I will go with servo option next time for sure but in this machine i need to solve it somehow, thanks anyway.

Hakan
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on January 18, 2018, 08:45:34 PM
Hi Hakan,
I just had a thought that may help you index your spindle. My VFD has a jog button, you can program it
turn the spindle very slowly. I've never used it. If you had an index switch on the spindle which operated
when the drive dogs lined up it might work.

1) Set an output to drive the jog terminal of your VFD
2) wait until the index switch activates
3) Reset the output

Craig
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: smurph on January 18, 2018, 10:26:28 PM
Machines with tool changers and induction motors on the spindle use a spindle key lock.  The spindle is rotated slowly at low torque and the key lock is engaged.  When the key lock drops into the notch on the spindle shaft, the VFD is turned off.  So it is a pure mechanical orientation. 

Steve
Title: Re: Mach4 Spindle At Speed, Spindle Zero Problem
Post by: joeaverage on January 18, 2018, 10:32:27 PM
Hi Steve,
kool, the jog feature would allow the spindle to turn at a slow enough speed that the lock would be effective.

Craig