Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: Aeroshade on March 01, 2011, 12:30:46 PM
-
I'm having a problem getting my M3 macro to change pulleys for me. My machine has a high gear and low gear that is changed by outputs.
I have tried the "SetOemDRO(56,1)" to change the pulley and "SetPulley(1)", neither seem to work. When I issue an M3 and I check the "Settings" tab and I see that "Spindle Pulley" does not change. I also get the error "Too Fast for Pulley..Using Max.".
I have my pulleys set up like this:
Pulley 1 = 0min. 910 max.
Pulley 2 = 911min. 5000max.
This is what I have, maybe someone can tell me where I'm going wrong.
Spin = GetRPM()
If Spin < 911 Then
SetOemDRO(56,1)
Call LowGear
End If
If Spin > 910 Then
SetOemDRO(56,2)
Call HighGear
End If
Sub LowGear
ActivateSignal(OUTPUT8)'Low Gear (OUTPUT)
Sleep (50)
Do Until IsActive(OEMTRIG2)'Low Gear Switch (INPUT)
Loop
If IsActive(OEMTRIG2) Then
Call SpinSpindle
End If
End Sub
Sub HighGear
ActivateSignal(OUTPUT7)'High Gear (OUTPUT)
Sleep (50)
Do Until IsActive(OEMTRIG1)'High Gear Switch (INPUT)
Loop
If IsActive(OEMTRIG1) Then
Call SpinSpindle
End If
End Sub
Sub SpinSpindle
DoSpinCW()
End Sub
Exit Sub
Any help would be great
Thanks,
Aero
-
Try with
If GetRPM<911
Hood
-
Try with
If GetRPM<911
Hood
Still not getting the pulley to change. Is there a setting some where that needs to be set for auto pulley select?
Thanks,
Aero
-
Not that I know of and seems to work here when I try to set the pulley, didnt have the rest of your VB though.
Try putting the pulley change in the spindlespeed.m1s
If you want to attach your xml I will try with that and see if I can find where its going wrong
Hood
-
Just tried here with your code in the M3 and its fine so must be something in your xml.
Hood
-
OK, so I used M999 to test something. I put this in M999:
SetOemDRO(56,1)
I saved it then ran it in MDI. It changed my "Spindle Pulley" under the "Settings" tab to 1. So I changed M999 to this:
SetOemDRO(56,2)
I saved it then ran it in MDI and it changed the "Spindle Pulley" under the "Settings" tab to 2. I can't see why it works fine with the M999 but not in my M3.
In my spindlespeed.m1s I only have this:
rpm = GetRPM() SetSpinSpeed( rpm )
I attached my .xml file.
Thanks for the help :)
Aero
-
Ok working fine here with your xml.
One thing is I think the spindlespeed macros should be on two lines, ie
rpm = GetRPM()
SetSpinSpeed( rpm )
but not sure how that would make a difference, definitely worth trying though.
Hood
-
Ok working fine here with your xml.
One thing is I think the spindlespeed macros should be on two lines, ie
rpm = GetRPM()
SetSpinSpeed( rpm )
but not sure how that would make a difference, definitely worth trying though.
Hood
I tired that, no change. This is really strange. Is there anyway to link to a different Mcode from a VB script?
Thanks,
Aero
-
I am crap at VB so not the best to advise on that but I think you have to be careful calling another macro from a macro.
Have you definitely got the macro named correctly, ie m3.m1s and placed in the correct folder?
I suppose if your output switches you must but not sure if you said whether it does or not?
Hood
-
Yes, if I manually change the pulley I can see that the relays for the gear change are working. It's just this darn SetOemDRO thing thats holding me back :(
Aero
-
I have actually just noticed something funny going on, the spindle override is being set to funny numbers when your macro is run, will check it out and see if I can figure whats going on.
Hood
-
What are you using with Mach as I notice you have some weird numbers in Ports and Pins, example Output 1 is Port 1 Pin 51.
Hood
-
I have a Galil DMC-2162. I have a daughter card hooked to it for extra I/O's. I use the extra I/O's as userLED's.
Aero
-
I have had REALLY weird things happening with this machine.
I have a door switch, air pressure switch and a lube level switch that when either are low, or open, they trigger an e-stop. I do this with a brain and when I link them all to the reset it makes my E-stop button stop working.
I have a tool unclamp button, real button, and I use brains to make it work. When I have that brain enabled and I try to make a tool change the tool unclamp in my M6 macro wont work.
Today hasn't been a very good day... I think I might go home and watch Netflix movies all night and call in sick for the next two months :P
Aero
-
Ok, it may be the Galil plugin that is causing the issue.
Do you see the Spindle override DRO getting set when calling the speed change?
Hood
-
Yes. If I use M3S100 the "RPM" shows 0 the "S-ov" shows 100 and the "Spindle Speed" shows 100.
I hope this helps.... I REALLY do hope :)
Thanks,
Aero
-
Probably doesnt help LOL but I will try a few things and see if I can figure it out, I think though I wont manage very much as I dont have a galil to test with :(
Hood
-
Do you actually control your spindle from Mach?
Hood
-
Do you actually control your spindle from Mach?
Hood
Yes, it doesn't work like I would hope... but it does work.
OK, this is my new M3 macro:
1 SpinCW = GetRPM() 'I use SpinCW to test how fast the spindle needs to go
2 ActivateSignal(OUTPUT1) 'This OUTPUT enables my spindle drive, VFD
3
4 If SpinCW < 901 Then 'Low gear. My spindle gear goes from 0-900 for low then 901-5000 for high
5 Call LowGear 'Calls sub program LowGear
6 End If
7
8 If SpinCW > 900 Then 'High gear
9 Call HighGear 'Calls sub program HighGear
10 End If
11
12
13 Sub LowGear 'LowGear sub program
14 ActivateSignal(OUTPUT8)'Low Gear 'Engage the Low gear solenoid
15
16 SetPulley(1) 'Set pulley to Pulley #1
17
18 While IsActive(OEMTRIG2) = False 'This is the INPUT, switch, for low gear
19 Sleep 10
20 Wend
21
22 Call SpinSpindle 'Call sub Spinspindle
23
24 End Sub
25
26 Sub HighGear 'HighGear sub
27 ActivateSignal(OUTPUT7)'High Gear 'Engage the High gear solenoid
28
29 SetPulley(2) 'Set pulley to Pulley #2
30
31 While IsActive(OEMTRIG1) = False 'This is the INPUT, switch, for high gear
32 Sleep 10
33 Wend
34
35 Call SpinSpindle 'Call sub Spinspindle
36
37 End Sub
38
39
40 Sub SpinSpindle 'SpinSpindle sub program
41
42 DoSpinCW() 'Spin spindle CW
43
44 End Sub
45
46 Exit Sub
OK, so when I step through this everything seems to work fine, I step through it with the e-stop on. The pulley changes and INPUTS and OUTPUTS seem fine. I save it then MDI M3S100, that would choose LowGear. If the Pulley under the settings tab is already one it works fine, but if it's two I get the pulley error. It seems to be running the macro so fast that it's not running every command. Is it possible that only certain commands work in the M3 macro? I changed the pulley manually, changed the DRO, to two and ran in MDI M3S100, the spindle started to spin up before the gear was fully engaged. REALLY bad sound... let me tell you :P.
If anyone has a clue on why this code isn't working please let me know. I'm at a stop tell I can figure this out.
Thanks,
Aero
P.S. Helping at my son's little league practice + watching Bones on Netflix yesterday, made me have the ability to try this all over again today :P
-
So how do you actually start and stop the spindle?
Hood
-
We have decided to drop the Galil and go with a DSPMC from Vital Systems. I'm hoping this will take care of a few things.
Thanks,
Aero
-
OK, I have got the new DSPMC from Vital Systems hooked up and running. BUT I'm still running into the same problem that I had with the Galil.
Here is a copy of my M03 macro:
SpinCW = GetRPM()
Message "S-Word = " & GetRPM()
'high gear input OEM#1, output#7
'low gear input OEM#2, output#8
'DeActivateSignal(OUTPUT2)'Spin Reverse
'ActivateSignal(OUTPUT1)'Spin Forward
If SpinCW < 901 Then
Call LowGear
SetPulley(1)
End If
If SpinCW > 900 Then
Call HighGear
SetPulley(2)
End If
Sub LowGear
DeActivateSignal(OUTPUT7)'HG=7 LG=8
ActivateSignal(OUTPUT8)'Low Gear
While IsActive(OEMTRIG2) = False'HG=1 LG=2
Sleep 10
Wend
Sleep 100
If IsActive(OEMTRIG2) Then
Message "Low gear input is active"
End If
Call SpinSpindle
End Sub
Sub HighGear
DeActivateSignal(OUTPUT8)'HG=7 LG=8
ActivateSignal(OUTPUT7)'Low Gear
While IsActive(OEMTRIG1) = False'HG=1 LG=2
Sleep 10
Wend
Sleep 100
If IsActive(OEMTRIG1) Then
Message "High gear input is active"
End If
Call SpinSpindle
End Sub
Sub SpinSpindle
'DoSpinCW()
End Sub
Exit Sub
I'm just trying to test the gear changer without running the spindle, note the noted out 'DoSpinCW(). I can step through the macro just fine, I get all the messages and the wends work perfect. As soon as I try to run it through MDI, aka M3S100, I don't see the message from "Message "S-Word = " & GetRPM()". It still seems like it is running so fast through the program that it isn't reading it correctly. Even the Sleep 100's are not working in MDI, but work fine when stepping through it.
Any help would be great!!
Thanks,
Aero
-
Some systems run the VB so fast it skips over commands.
For testing I would place a
While Ismoving()
Sleep(2000)
Wend
between each command and see if it slows it down enough. If it does then start reducing the number a little at a time untill you find the magic delay time to make it all work.
If it all works fine while stepping throught the code then it is just timing issues. You have to regulate the process speed with hold states to keep mach from missing commands.
(;-) TP
-
Some systems run the VB so fast it skips over commands.
For testing I would place a
While Ismoving()
Sleep(2000)
Wend
between each command and see if it slows it down enough. If it does then start reducing the number a little at a time untill you find the magic delay time to make it all work.
If it all works fine while stepping throught the code then it is just timing issues. You have to regulate the process speed with hold states to keep mach from missing commands.
I find the IF then goto sub# works much better and is more dependable as it tends to stay in order sync. BUT that is just my opinion.
(;-) TP
-
I will increase my sleeps to see if I can slow it down a bit. I was think that maybe when an M03 is commanded that it reads some other file first for the pulley settings. It seems like it is seeing that the pulley isn't set to the right number before it runs the macro. Anyone have any thought on this?
Thanks,
Aero
-
don't just add more sleep add the other statements as well.
(;-) TP
-
OK, I GOT IT WOOOT!!!!
SpindleSpeed macro:
If GetRPM() <901 Then
SetPulley(1)
End If
If GetRPM() > 900 Then
SetPulley(2)
End If
rpm = GetRPM() SetSpinSpeed( rpm )
Works like a charm!!! And BR549 thanks for the suggestion on increasing the sleeps, now I can see everything working, and my messages are coming up like they should. Now I just need to test it with the spindle enabled and I'm off to make sure my tool changer still works properly!!!
P.S. Should I set all my gear changing in the SpinSpeed macro, so I can declutter my M3 macro?
Thanks,
Aero
-
Good Job Areo, Just do whatever works well for you. I have learned over the years that each application can be different as to the computer used.
(;-) TP
-
OK, I got Mach to change the gear AND the pulley automatically. And I got it to pause before turning the spindle on, to allow time for the gear change to take effect (AKA no grinding gears... BIG plus :P). NOW for some reason, it is running the VFD at full speed in low and high... no matter what RPM I put in M03S?. It does changes the gears at the proper commanded speed.
I have my pulley 1 set at 0-900 and pulley 2 set at 901-5000. I haven't set the ratio yet and that might be what the problem is...it did work before though. Why would Mach send a full 10v to my VFD?
Thanks,
Aero
-
The ratio setting may not be what you think it is. It is a divisor for the pulse input to correct the rpm reading for use with a gearbox were the signal is dirived from the gearbox input (Bridgeport style).
(;-) TP
-
OK, I have a new problem. When I MDI m3s100 it goes through its gear change beautifully, and starts the spindle and runs at 100rpm. I then MDI m5 the spindle stops, I then MDI m3s1000 and the gear changes and the spindle spins to 1000rpm... so far so good, OK now the strange part. I then MDI m5 to stop the spindle then put m3s100 again, the gear changes to low gear like it should but it runs the spindle at max RPM. When I look at the "Spindle Speed" windows it shows 900 in the S ov and 100 in S, 900% Override. It seems to me that either the GetRPM() isn't working properly for me or I have another problem I'm not aware of. Here is a copy of my SpinSpeed macro and M3 macro.
Spinspeed:
Spin = GetRPM()
If Spin < 901 Then
SetPulley(1)
Call LowGear
End If
If Spin > 900 Then
SetPulley(2)
Call HighGear
End If
Sub LowGear
DeActivateSignal(OUTPUT7)'HG=7 LG=8
ActivateSignal(OUTPUT8)'Low Gear
While IsActive(OEMTRIG2) = False'HG=1 LG=2
Sleep(10)
Wend
If IsActive(OEMTRIG2) Then
Message "Low gear input is active"
End If
Call SpinON
End Sub
Sub HighGear
DeActivateSignal(OUTPUT8)'HG=7 LG=8
ActivateSignal(OUTPUT7)'Low Gear
While IsActive(OEMTRIG1) = False'HG=1 LG=2
Sleep(10)
Wend
If IsActive(OEMTRIG1) Then
Message "High gear input is active"
End If
Call SpinON
End Sub
Sub SpinON
Sleep(5000)
rpm = GetRPM()
SetSpinSpeed( rpm )
End Sub
M3:
SpinS = GetRPM()
If SpinS < 901 Then
Call LowGearON
End If
If SpinS > 900 Then
Call HighGearON
End If
Sub LowGearON
While IsActive(OEMTRIG2) = False
Sleep(10)
Wend
If IsActive(OEMTRIG2) Then
Sleep(5000)
Message "Spindle On"
DeActivateSignal(OUTPUT2)'Spin Reverse
ActivateSignal(OUTPUT1)'Spin Forward
DoSpinCW()
End If
End Sub
Sub HighGearON
While IsActive(OEMTRIG1) = False
Sleep(10)
Wend
If IsActive(OEMTRIG1) Then
Sleep(5000)
Message "Spindle On"
DeActivateSignal(OUTPUT2)'Spin Reverse
ActivateSignal(OUTPUT1)'Spin Forward
DoSpinCW()
End If
End Sub
If anyone can see a problem in my code please let me know.
Thanks,
Aero
-
I was thinking that I might need to zero out a DRO at the beginning of my SpinSpeed macro. Any thoughts?
Thanks,
Aero
-
Exactly how are you using the programs. How are you calling them to work.
(;-) TP
-
Exactly how are you using the programs. How are you calling them to work.
(;-) TP
Not sure what you mean. I thought they are called up by using the M03 command. Please explain.
Thanks,
Aero
-
Isee where you have a program called SpinSpeed and then a portion of code in the M3 macro?
Where does the SpinSpeed program reside and what tiggers it? Is it in a macropump?
Can you explain the sequence of events to make it all take place.
(;-) TP
-
I had that same problem, I was fighting to get the SetPulley() to work in M3 macro, but wouldn't work... once I put it in the SpinSpeed macro it worked great. I'm guessing that the SpinSpeed macro and the M3 macro run at the same time, or the Spinspeed macro runs first then the M3 macro, since I got it to change gears before it ran the M3 macro. But my question is that something is being set when I put the spindle at a higher speed then try to go to a lower speed, the lower speed is overran by the high speed I programed.
Aero
-
Add: The SpindleSpeed macro is located in the macro folder of Mach3. Sorry I have been calling it SpinSpeed macro I should have called it SpindleSpeed macro, sorry or the confusion :)
Aero
-
I still need the sequence of events that make it all work to test it.
(;-) TP
-
Not sure what you are asking, but here is a better picture of what the M3 and SpindleSpeed macro are doing.
SpindleSpeed MACRO:
Spin = GetRPM()
If Spin < 901 Then
SetPulley(1)
Call LowGear
End If
If Spin > 900 Then
SetPulley(2)
Call HighGear
End If
Sub LowGear
DeActivateSignal(OUTPUT7) 'High gear OUTPUT off
ActivateSignal(OUTPUT8) 'Low Gear OUTPUT on
While IsActive(OEMTRIG2) = False 'Checks to make sure Low gear INPUT is active
Sleep(10)
Wend
If IsActive(OEMTRIG2) Then
Message "Low gear input is active"
End If
Call SpinON
End Sub
Sub HighGear
DeActivateSignal(OUTPUT8) 'Low gear OUTPUT off
ActivateSignal(OUTPUT7) 'High Gear OUTPUT on
While IsActive(OEMTRIG1) = False 'Checks to make sure High gear INPUT is active
Sleep(10)
Wend
If IsActive(OEMTRIG1) Then
Message "High gear input is active"
End If
Call SpinON
End Sub
Sub SpinON
Sleep(5000)
rpm = GetRPM() 'this is what was in the SpindleSpeed macro
SetSpinSpeed( rpm ) 'this is what was in the SpindleSpeed macro
End Sub
M3 MACRO:
SpinS = GetRPM()
If SpinS < 901 Then
Call LowGearON
End If
If SpinS > 900 Then
Call HighGearON
End If
Sub LowGearON
While IsActive(OEMTRIG2) = False 'Makes sure Low gear INPUT is active
Sleep(10)
Wend
If IsActive(OEMTRIG2) Then
Sleep(5000)
Message "Spindle On"
DeActivateSignal(OUTPUT2) 'Turns off Spindle reverse (CCW) OUTPUT
ActivateSignal(OUTPUT1) 'Turns on Spindle forward (CW) OUTPUT
DoSpinCW() 'this is what was in the M3 macro
End If
End Sub
Sub HighGearON
While IsActive(OEMTRIG1) = False 'Makes sure High gear INPUT is active
Sleep(10)
Wend
If IsActive(OEMTRIG1) Then
Sleep(5000)
Message "Spindle On"
DeActivateSignal(OUTPUT2) 'Turns off Spindle reverse (CCW) OUTPUT
ActivateSignal(OUTPUT1) 'Turns on Spindle forward (CW) OUTPUT
DoSpinCW() 'this is what was in the M3 macro
End If
End Sub
Thanks for the help,
Aero
-
It looks like you are calling a macro from inside of a macro. NOT a recomended practice in Mach3. Only in the very latest version is there "some "support to do this.
I would suggest combining all the code in the M3 macro and getting it sorted out there (;-) I can see where it would require a bit MORE timing controll but should work fine from the M3.
(;-) TP
-
I'm not calling a macro from the program. Mach3 reads M3 and SpindleSpeed on it's own. You can test it by putting a message in your SpindleSpeed macro and it will show when you run the M3 macro (AKA M03S100)
Aero
-
OK I go what you are doing(;-) I was hopping between projects and was not paying attention to detail.
I'll test it here later tonight.
(;-)TP