Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: 01sporty on January 02, 2007, 02:19:33 PM
-
I wrote the following routine to cycle an air cylinder. It work just fine when run from MDI. But, when I put it in a program, Mach3 loads until it reaches the line with this macro then quits loading.
While IsActive(Input2)
ActivateSignal(OUTPUT8)
Wend
While IsActive(Input3)
DeActivateSignal(OUTPUT8)
Wend
Could I get suggestions on how to fix this??
TIA
Walt
-
Is this an M code macro?
Graham.
-
Sorry, I should have specified that. Yes, I'm using M110 for this bit.
Walt
-
Have you got the macro saved in the correct directory.
If you are using a profile it must be in the profile's macro directory. If not then in Mach3mill or Mach3turn's directory.
Graham.
-
Yup. I already made that mistake. (see my post of a few days ago) I always try to make sure my mistakes are new and fresh (to me anyway).
Like a said, if I run the macro from the manual data input line, it does just fine. It just doesn't like to load once I put it in a program. Once again, I'm sure I must be overlooking some small but significant detail.
Regards,
Walt
-
Has the last line of the macro got a carriage return on it?
Will you post the macro and let me have a try here.
Graham.
-
You don't have double parenthesis any where do ya? (ActivateSignal(OUTPUT8)).
Brett
-
More info.
The M code is just what I originally posted:
While IsActive(Input2)
ActivateSignal(OUTPUT8)
Wend
While IsActive(Input3)
DeActivateSignal(OUTPUT8)
Wend
Input2 & 3 are micro switches. Output8 is to a solenoid to activate the air cylinder.
Everything is being run through a G100 & Mach3 version 2.0.010.
The code appears to run just fine on another computer that isn't actually driving anything. The other computer is also running version 2.0.028.
I suppose I should try upgrading the machine computer to 2.0.028 and see if that helps. But, before I do that, I'll probably try the xml file from the computer that doesn't work in the computer that does work. If the problem follows the xml file I may be a bit closer.
Regards,
Walt
-
Well, upgrading to 2.0.028 did the trick. I get so used to Mach3 being bullet proof, it just doesn't occur to me to check it.
Now, if I could just solve the limit switch problem...............
Thanks for all the support. Sometimes it just takes a couple of fresh perspectives to get pushed in the right direction.
Regards,
Walt
-
NOTE: you also have to put ALL caps in the word "INPUT", from my understanding, when your looking at one of the functions, i.e. INPUT, OUTPUT, INDEX, (whatever). The all caps lets the vb interpreter recongize the Mach specific call. At least that is my understanding. (see below).
While IsActive(INPUT2)
ActivateSignal(OUTPUT8)
Wend
While IsActive(INPUT3)
DeActivateSignal(OUTPUT8)
Wend
see if that doesn't clear up your input problem.
Scott
-
Oh, one other thing, and this is something Art told me, he said stay as FAR away from While loops as possible, since it realy hogs procssor and can cause lockups/crashes.........yep, been there, lots of times. That is UNLESS you have to wait, then you might want to look at a "SystemWait()" command, instead of the While loop.
So you could do something like this if you don't need a "Hand shaking function":
If IsActive(INPUT2) Then
ActivateSignal(OUTPUT8)
End If
If IsActive(INPUT3) Then
DeActivateSignal(OUTPUT8)
End If
One other Note: If for some reason, you need the signal status of OUTPUT8 to "Stay on or off" after the switch is made. You can send your signals through the Modbus to a PLC, or peters board or other Modbus device. When you turn on a signal, in Modbus, it stays on, till you turn it off. Another option: if you need that, but don't want to use a modbus device. You could send you PP signal to a self Latching relay, and the off signal, would "cut" the coil.
Scott
-
After more playing, things weren't working as well as I thought.
You're exactly right about the while loop. Things started hanging and running really, really s l o w. Checked my processes and Mach3 was using 98-99 percent CPU. Yikes.
I really like the idea of the SystemWaitFor command, but it just isn't happening for me. Here's what I scripted:
ActivateSignal(OUTPUT8)
SystemWaitFor(INPUT2)
DeActivateSignal(OUTPUT8)
SystemWaitFor(INPUT3)
It sure looks simple enough but it just sits there when I try to run it. (I think I heard it chuckling. Must be time for a nap.)
Regards,
Walt
-
Sorry that wasn't clear, the "SystemWaitfor()" You need to put it on your INPUTS, before the Outputs that are slaved to it.
But you would have to rewrite your code somewhat like the example below. All it will do there, is when INPUT2 turns on OUTPUT8 turns on, then the system will pause for 2 seconds then it will move on.
If IsActive(INPUT2) Then
ActivateSignal(OUTPUT8)
Code "G4 P2" 'Pause for 2 seconds for what ever mecanical action is happening to complete
End If
While IsMoving ()
WEnd
If IsActive(INPUT3) Then
DeActivateSignal(OUTPUT8)
Code "G4 P2" 'Pause for 2 seconds for what ever mecanical action is happening to complete
End If
While IsMoving ()
WEnd
Scott
-
Hi Scott,
I see what you're saying. That's really not what I want to happen. I'm trying to avoid simply putting in a timing delay if possible. I want all my actions to occur in a linear fashion. That way, the machine runs at it's maximum speed and has no chance of crashing if there is any decrease in air supply.
To expand on this, here's what I'd like to see happen: The INPUT3 switch is on the air cylinder in it's normally relaxed position. The INPUT2 switch is at the end of the stroke of the air cylinder. The air cylinder is OUTPUT8. Both switches are normally closed but I don't think that matters since Mach3 lets you define normally high or low. So, what I'm trying to accomplish is: trigger the cylinder, wait for the cylinder to reach the end of stroke, de-activate the cylinder, wait for the cylinder to get back to the beginning of its stroke and finally, continue the program.
The while loop routine I originally came up with accomplished this very well, --- when run by itself from the MDI line. I still find it odd that it runs there but won't run inside a program.
As confused as ever,
Walt
-
Your choices are timing delay, OR, While Loop.........
Try this code:
'Piston Macro M********* (Label the Macro number instead of *********).
'It wasn't clear, so I am assuming that this is a macro in your running G-code, if it is a button, then paste it in.
'Using SystemWaitFor(), and While Loops, will both suck down, major processor time.
ActivateSignal(OUTPUT8) 'Solinoid to extend cylinder.
Code "G4 P1" 'Pauses for 1 second for cylinder to extend, set pause higher if needed.
While Ismoving() 'Waits for pause to time out.
WEnd
If IsActive(INPUT2) Then 'After 1 second, if INPUT2 (extended limit switch), is active then deactivate cylinder.
DeActivateSignal(OUTPUT8) 'Drop Air cylinder
Else
Question("Did your Cylinder Extend? Check your Air") 'So if INPUT2 don't turn on, and pause times out, error message.
End If
Code "G4 P1" 'Pause 1 second, for cylinder to drop.
While Ismoving() 'Waits for pause to time out.
WEnd
If NOT(IsActive(INPUT3)) then 'If INPUT3 (cylinder back home), is not on/closed, then Error
Question("Did your Cylinder Retract?") 'Error question.
End If
Let me know,
Scott
-
In a nutshell, The Code Won't Load because there's no IsLoading() function.
To elaborate. The following code works fine by itself:
While IsActive(Input2)
ActivateSignal(OUTPUT8)
Wend
While IsActive(Input3)
DeActivateSignal(OUTPUT8)
Wend
But when Mach3 loads a program, it does a run simulation as it loads each command. This way it checks commands for syntax and draws the toolpath display. When it encounters code that depends on a mechanical action to continue, it will sit there and wait for that action to occur. Obviously this will never happen since it's a simulation.
Fortunately, there's a command just for this situation. IsLoading: "Returns true if the part program is loading rather than being actually run (e.g. so the toolpath is being generated or regenerated)."
So my little while loop code becomes:
If IsLoading() Then
Else
While IsActive(Input2)
ActivateSignal(OUTPUT8)
Wend
While IsActive(Input3)
DeActivateSignal(OUTPUT8)
Wend
End If
This tells Mach to go on to the next command if it's loading, otherwise do the code.
I knew I had to be missing something simple.
Then again, I guess it's only simple once you've figured it out.
Regards,
Walt
-
Perhaps, I misunderstood what you where doing. If your wanting that to run in your code, why don't you just make a custom Macro??
If you are worried about it trying to activate the Macro, you can avoid that by Loading the code while the machine is in a "Reset" active condition.
I have a machine that will "Hang", if I try to load a certain macro, since it requires an hand shake with a PLC. BUT, I can load that same program with the RESET button activated.
Scott (perhaps you will post up some pics of what ever it is, your building doing, sounds neat).
-
Oh yes, I'll certainly put together a picture album but it will be a while. Other jobs have a higher priority right now and I've got a couple of engineering changes that I'd like to implement not to mention a couple of things that need changing just because they're wrong. I figure it will be a month before it's completely on line.
Oh, it's a float wire bender for gas tank manufacturer.
Regards,
Walt