Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: Sweep on September 24, 2012, 06:05:26 PM

Title: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on September 24, 2012, 06:05:26 PM
I am wanting to stop my spindle as it passes the speed monitoring proximity switch, which is assigned as "index" on the ports and pins screen, to align the drive dogs of the spindle with those of the tool mounted in the carousel.
I will, of course, have dropped the speed to, say, S60 to reduce the effects of inertia over-run.
Is the statement SystemWaitFor(INDEX) sensible or will I have to duplicate my input pin to a true Input# for it to work, e.g. SystemWaitFor(INPUT1), and does this command look for a high or low state?
I was going to use IsActive(INDEX) or IsActive(INPUT1) but I don't know how to leave the command 'open' and looking for the state of the input to change as it would be only chance that the proximity was active when the script line was processed.

thanks again ...Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Graham Waterworth on September 24, 2012, 07:14:07 PM
you could do a while isactive() loop and check any input, if you have a servo spindle you could do swapaxis(x,y) and do a home command to find the signal.

Graham
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on September 24, 2012, 07:31:22 PM
With a servo drive as Graham says with a VFD use the jog feature of the VFD to slowly rotate the Spindle and have MAch3 watch for the signal then stop and use DC brake of the VFD to lock the rotor. OR use a simple spring loaded  shaped cam to move the spindle into position after it has stopped

Just a thought, (;-) TP
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 12, 2012, 05:13:52 PM
isn't it annoying when you type out a long post and the system times out before you submit it. grr

Anyway, I have been away from playing with my machine for a few weeks due to work commitments and have now started to complete the missing link of my toolchanger macro, namely the spindle dog alignment.
I have tried various combinations of If and While commands but have failed at every step and I am coming perilously close to causing some serious damage after crashing the carousel into the still spinning spindle on more than one occasion. ouch!
What I am trying to do, as mentioned in the original post, is to run the spindle at a very low speed, say 60rpm, and then switch off the spindle relay as the INDEX proximity passes the detector. As the detector is about 90degrees off from the correct dog position i am also trying to put in a Sleep delay so I can 'tune' the position. If this is impractical I could physically move the proximity to perfectly align with the dog position which might be better.
As I wasn't getting much success with IsActive(INDEX) I have duplicated the Index port and pins for a seperate input so I can use IsActive(INPUT2). Whilst I can get the spindle running, Code "M3 S60", I don't seem to be able to figure how to get the thing to stop before the program steps further into the macro and sends the carousel into the spindle.
I don't suppose it really matters at what early point in the macro the spindle alignment commmands are executed, be it before or after the table moves safe (Code "G00 G53 Z" & z etc), so please feel free to make any suggestions.
I am just worried that if I carry on 'trying' to get it right i'm going to detroy my machine in the process.

As always, your assistance would be greatly appreciated ...Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 12, 2012, 06:15:11 PM
Are you using a VFD to run the spindle ?

Does it have an index feature built in?

Does it have a creep feature ?

Can your VFD do DC injection?

With a rotating mass IF you hit stop at a certain place inertia will carry the load on to an unknown position. Not possible to garrantee the same spot every time.

Some Machines use a stop pin as the spindle CREEPS into position the pin fires and locks the spindle at the same point every time.

Just a thought, (;-) TP
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 12, 2012, 06:26:25 PM
Normally you would do a stop and confirm that motion has stopped .
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 12, 2012, 07:22:28 PM
Hi TP,
The spindle drive is a DC motor and Lynx 08 DC controller which is a pretty basic. Both motor and controller are the original equipment of the machine and are probably 20+ years old.
I appreciate that the inertia will carry the the spindle beyond the switch off point, hence the point about the delay for tuning the stop position, but there is also quite a lot of friction in the system as there is also a 1:1 timing belt between the motor and the spindle. This is also the reason why I have dropped the speed down to 60rpm to reduce the affect of the inertia to a minimum. At this speed I am witnessing maybe a 1/4 turn of the spindle when the relay disengages.
There is also a mechanical self-aligning mechanism in the spindle which will take up around +/- 15degrees misalignment when the air operated tool holder release is operated.
The system that i am suggesting is really the same that was installed with the machine from new. The only thing that I am doing is operating it from Mach as opposed to the obsolete motherboard.

...Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 12, 2012, 07:46:50 PM
I found an old video of the original machine sequence which I am trying to replicate. Is there any way that I can post it on here as it will show better than words what's happening?
 
...Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 12, 2012, 08:27:42 PM
yOu could upload it to YouTube and give us the link.

Love a good movie, (;-) TP
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 13, 2012, 02:56:48 AM
Ladies and Gentlemen, for your entertainment and edification this evening I proudly present ...a video of an old milling machine

http://pictures.pollz.co.uk/#8.
There are two videos in a album called Denford Triac.
The site is my daughter's in case anybody was wondering!

Everything has been programmed except the spindle stop position. When I have donetool changes with the spindle isolated and manually positioned with the drive dog in the correct position I have never once had a toolchange failure. The last tricky bit is to align the drive dog from a spinning spindle before the carousel starts moving. I chose 60rpm as the speed as it looks pretty close to what the original on-board controller was using, is not too slow to become lumpy, and pretty much gets rid of most inertia overun with either a light tool (centre drill) or heavy tool (face mill).

...Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 13, 2012, 11:54:14 AM
It appears that the OLD machine ramped the spindle down to a stop. The Drive has a setting for ramp up/down values. Have you tried adjusting the stop side to ramp down faster.

Modern machine bring the spindle to dead stop THEN creep the spindle over to the index point and CAN provide an offset to align the dawgs. 

IF you ramp the spindle to a stop  what is the slowest you can reliably move(creep) the spindle from a dead stop? 

(;-) TP

Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 13, 2012, 02:29:37 PM
My problem isn't the ramping down of the speed or disengaging the relay at 60rpm, it is that I can't figure out the VBscript to look for the index, or Input2, pulse and then disengage the relay. Every time I try it it either doesn't see the index or doesn't hold the next line of the program until the spindle has stopped.
An extract of what the program currently looks like is shown below in black with what I think should be used for the spindle alignment in RED. I have put a Sleep 25 as a tunable deceleration figure but it will probably be better to move the sensor to exactly the position I need it.
So, is the code any good or a recipe for disaster?

x = GetUserDRO(1200)
y = GetUserDRO(1201)
z = GetUserDRO(1202)
Code "G00 G53 Z" & z
While IsMoving ()    'pause to allow Z axis to move to change position
Sleep 100
Wend

Code "M3 S60" 'spindle run at minimum speed
Sleep 5000 'allow spindle speed to stabilise
While Not IsActive(INPUT2) 'look for spindle proximity switch
Sleep 500
Wend
If IsActive(INPUT2) Then
              Sleep 25 'alter figure to tune deceleration
              Code "M5" 'stop spindle
End If

Code "G00 G53 X" & x & "Y" & y
While IsMoving ()   'pause to allow XY axis to move to change position
Sleep 100
Wend

Slot1 = GetUserDRO(1101)
Slot2 = GetUserDRO(1102)
Slot3 = GetUserDRO(1103)
Slot4 = GetUserDRO(1104)
Slot5 = GetUserDRO(1105)
Slot6 = GetUserDRO(1106)
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 13, 2012, 03:08:52 PM
With you line of thinking there are several things working against you .

1 CB is incredibly slow reacting to inputs it can ONLY read the line 10 times per sec in a perfect world. Could be that Mach3 never sees the input before the event is over. Depends on the dwell of the event at 60rpm(;-).

2 you are assuming that mach3 KNOWs when the spindle has stopped and can proceeed. ARE you looking for rpms of the spindle to determine that?

Has the light come on yet?

(;-) TP
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 13, 2012, 04:46:01 PM
SO thinking about this you need to get to the driver level operations to control the stopping of the spindle. The driver ops operate at kernal freq and are very fast to react.

SO if you use a phantom axis say C and set up the home with your output from the sensor.

WHen you need to TC stop spindle

Refhome C it rotates until it sees the trip then stops. You will have to adjust the trip position so it stops where you want.


 Use the DIR pins to run a relay(DPDT) to turn ON the motor to home then as the sensor trips it reverses the dir pin (turns off ) the motor and resets the HOME switch so that C axis Rehome is completed and it clears the function.  Feed the relay(motorside) through a resistor to set the voltage level for the spindle to get 50 rpm or so. The slower you can run the better and more accurate the stop point.  I would also set the stop side ramp to be more agressive. TO help stop the spindle.



That would be one way to garranty that the sensor is seen and the operation be an auto function.

Just a thought, (;-) TP
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 13, 2012, 05:10:14 PM
Hi TP,

I have had a tweak of my DC controller and can drop the speed down to 20rpm. I then measured the arc of detection of the spindle proximity switch and got about 13 degrees.
Considering 20rpm/60 = 0.33r/s or 3sec/rev, and 360/13 = 27, then 3/27 = 0.11seconds the switch is active. Is that sufficient for a reliable trigger?
I suppose we could also set a timer cycle at the same time so if it doesn't detect in, say, 5 revs bail out of the toolchange program and call an alarm.

To comment on your last post. The spindle is controlled by PWM and will run a steady 20rpm now I have tweaked the pot, but currently I don't have a seperate relay to reverse the spindle. I only have to get close, however, as don't forget the spindle will centre when the pnematic ram operates if it is +/- 20 degrees or so from perfect alignment

...Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 13, 2012, 05:33:30 PM
well at a perfect 10 hz that is .1 sec detection time. I think it best to IF isactive then SetUserLed(on) so once it gets seen and it sets the led on you no longer rely on the sensor to drive the function. It only has to be seen one time out of many.



After that I would add a safety line that IF the index is not seen in say 2 sec then assume the spindle has stopped and good  to go.

Just remember somewhere along the line as the TC function ends to turn OFF the LED(;-)
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 13, 2012, 05:39:32 PM
Just had a bit of an experiment with your C axis suggestion which seemed quite neat. Unfortunatley because Mach is sending a PWM signal to the relay, as it thinks it is driving a motor, there isn't enough continuous current to open the relay. My LED relay tell-tale light illuminates dimly but the relay doesn't engage.

...Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 13, 2012, 05:41:05 PM
I will have to close down now as it's 10:40pm over here and my eyes are getting tired.
Thanks for your help TC and goodnight.

...Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 13, 2012, 06:00:53 PM
YOU would USE the Dir PIN to switch the relay it is 5v or 3v. When the Refhome is called the axis is sent in a specific direction to the home switch. SO it has to set the DIR pin one way or the other.  Once it trips then the DIR pin reverses.

I am working on a CB version as well and may even try a brain version   HOPEFULLY somewhere we find the secret handshake to make it work for you.

Question for tomorrow WHat drives your spindle drive  PWM, +10v,step dir, ???

There is always tomorrow, (;-) TP
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 14, 2012, 10:16:43 AM
When You get a chance see IF this Button code can see the index signal . Notice that we did NOT jump out to the GCode anywhere so should be stable.

It sets the spindle speed to 20 then turns ON the spindle and watches for the index signal. IF it does not see it in about 5 secs it errors out and stops spindle with message.

If it sees it then it stops the spindle with message .

SetOemDro(817,20)
SetUserDRO(2001,0)
DoSpinCW()

Do While Not Isactive(index) And GetUserDro(2001)<6
SetUserDro(2001,(GetUSerDro(2001)+1))
Sleep(1000)
If GetUSerDro(2001) >5 Then
DoSpinStop()
Message"Spindle Detect Timeout"
End
End If
Loop

SetUserLEd(2000,1)
While Ismoving()
Wend

DoSpinStop()
Message"Ready For Tool Change"


End     

Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 14, 2012, 03:50:12 PM
Good evening TP,

Thanks again for your support. Lets see what happens!
Will report in 15 minutes.

Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 14, 2012, 04:26:31 PM
It has worked but only intermittantly. I have tried increasing the look time from 5 to 20seconds, to allow the spindle speed to stabilise at 20rpm, but this hasn't improved things.
I have had one r two instances where the spindle has stopped right on the proximity but this has only happened around 10% of the times I have run the cycle. Most of the time I am getting the 'time out' message.
I have also tried utilising a seperate INPUT instead of INDEX but the effect is the same.
I will try have another go with the C axis idea using the DIR output to control the relay.

Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 14, 2012, 04:29:03 PM
Question for tomorrow WHat drives your spindle drive  PWM, +10v,step dir, ???

The spindle drive is by the PWM output from Mach3 converted to the 0-10v required by the DC controller by a homemade circuit board.
Using the closed loop spindle control I get speeds that are normally +/- 1rpm from that requested all the way from 20 to 3000rpm. There is a bit of an overspeed when the spindle first starts but this will stabilise within 3 or 4 seconds as the PID learns.

...Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 14, 2012, 04:42:40 PM
I think time for a brain try to see IF it can see it.

(;-) TP
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 14, 2012, 05:08:34 PM
OK Brains  on this VISTA machine do not work.

You may want to try it on your machine. It is a very simple brain it looks for 2 things the userdro(2000) to be off and the index signal to be ON. IF it sees it it will turn the UserLED(2000) on.

You must have the UserLed(2000) where you can see it . ONCE on it stays on so make sure you turn it off before testing.

(;-) TP
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 14, 2012, 05:34:29 PM
What are Brains?
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 14, 2012, 05:37:10 PM
Here is another thought that may be easier than the flipping of a relay from the dir channel. When the Crefhome trips the switch it SETS a LED on.

When you rehome c it looks for a switch,revs dir then looks for the closing of the switch then STOPS and turns ON the LED.

In your case you call the C refhome and as soon as it sees the signal it does its thing AND the passing lug that trips the switch has moved away and the switch resets which should allow the LED to set on.

ALL WE have to do to watch for the LED to go active IF it does(;-)

SO you would activate the spindle to 20 rpm let stabilise then call the C refhome  (Use the CB version not the Gcode version)
IF the LED goes active then Dostopspin()

(;-) TP
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 14, 2012, 07:47:33 PM
OK this works here as best I can simulate it. You need to activate the C axis then set Chome input the same port/pin as the spindle index input.

Place the code in a test button. AND give it a whirl.

'M2916 Macro for spindown Point
SetOemDro(817,20)       'set RPM
SetUserDRO(2001,0)   'Clear DRO to zero

DoSpinCW()
Sleep(2000)            'Adjust for stable RPM
RefCombination(32)

Do While  GetOemLED(812)  And GetUserDro(2001)<6
SetUserDro(2001,(GetUSerDro(2001)+1))
Sleep(1000)
If GetUSerDro(2001) >5 Then
DoSpinStop()
Message"Spindle Detect Timeout"
End
End If
Loop

Sleep(1000)             'Adjust for Spindown Stop point
DoSpinStop()
Message"Ready For Tool Change"

End 


(;-) TP         

Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 16, 2012, 01:01:45 PM
Good Evening TP,

Tried the latest solution last night but without success, although I was very tired so I am going to have another go now.
Having watched the Brains videos it seems that may offer a faster reacting solution but I have never used them before.
I thought I could insert a phantom output in the toolchange macro which Brain would recognise, say output 6, and then have the brain terminate with button press 110 Spindle on/off when it sees Spindle Index change state. Something like:

SetOEmDro(817,20)
DoSpinCW()
Sleep(5000)
SetTimer(11)
ActivateSignal(OUTPUT6)
While GetOEmDro > 0
          Sleep(1000)
Else DeActivateSignal(OUTPUT6)
If GetTimer(11) >10 Then
          Message ("Spindle alignment not achieved")
          Exit Sub
End If
Wend

I'm not sure how correct that is as I don't know if I've got the While, Else, and Ifs in the right order.
As far as the Brain is concerned I need to do an And that only executes it if Spindle speec is >0 and Output6 is =1

What are your thoughts?

...Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 16, 2012, 01:31:14 PM
The brains will NOT be faster at detecting the signal than the last routine I used. That routine ran at kernal freq to detect the index signal. HERE I could not outrun it as it looks for the signal at 25,000 times per sec.

The brains will run fast interally BUT STILL have a 10hz loop to read and write the I/O.

SO on the last routine I posted what failed to happen ?

(;-) TP
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 16, 2012, 02:32:56 PM
Let me try again with your last macro. 10 minutes please  :)
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 16, 2012, 02:55:41 PM
Ok. Just run the macro but the stop position varies wildly.
So far I've run the macro 4 times without changing the rundown time and I've had the stop position at (approx) 90 deg past once, 180 deg past twice, and 270 deg past detection point once.  :(
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 16, 2012, 03:11:38 PM
YEP that is how that approach usually ends up. You have absolutely ZERO control over the process.

Try it this way lets NOT give the spindle time to get wound up. As soon as it sees the first pass it shuts off the spindle back off.  hopefully friction will be our friend at that speed.


'M2920 Macro for spindown Point
SetOemDro(817,20)       'set RPM
SetUserDRO(2001,0)   'Clear DRO to zero

RefCombination(32)
DoSpinCW()

Do While  GetOemLED(812)  
Loop


DoSpinStop()
Message"Ready For Tool Change"

End  
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 16, 2012, 03:41:40 PM
The original principle seems fine, as the spindle really is creeping, but the reaction time must be affected by something that we are not considering.
I have just done a video which I am trying to upload as everything looks great except the ultimate stopping position.

...Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: Sweep on November 16, 2012, 04:45:53 PM
 :D happy, happy, happy  :D

Can't believe it. Run it 10 times with 10 perfect stop positions!!!!!
It may not be pretty or particularly fail safe, but that's something I/we can work on, but it works and works again.

SetOemDro(817,20)
DoSpinCW()
Sleep(5000)

While Not IsActive(INDEX)
Sleep(1)
If IsActive(INDEX) Then DoSpinStop()
Wend

It looks like the whole key to the problem was the Sleep prior to stopping the spindle. Now that this works I'll revisit some of your earlier, safer, macros with timeouts and see if I can get those to work. Result!
Your continued support has been, and will continue to be, much appreciated.

Thanks ...Sweep
Title: Re: SystemWaitFor(INDEX) ...will it work?
Post by: BR549 on November 16, 2012, 05:41:44 PM
GOOD JOB, (;-) TP