Hello Guest it is March 28, 2024, 03:58:04 PM

Author Topic: Code Won't Load  (Read 10739 times)

0 Members and 1 Guest are viewing this topic.

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Code Won't Load
« Reply #10 on: January 02, 2007, 05:28:54 PM »
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


fun times
Re: Code Won't Load / Back Again
« Reply #11 on: January 02, 2007, 06:11:25 PM »
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

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Code Won't Load
« Reply #12 on: January 03, 2007, 12:58:56 PM »
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
« Last Edit: January 03, 2007, 01:11:03 PM by poppabear »
fun times
Re: Code Won't Load
« Reply #13 on: January 03, 2007, 05:23:38 PM »
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

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Code Won't Load
« Reply #14 on: January 03, 2007, 06:52:56 PM »
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


fun times
Re: Code Won't Load / Success!!!
« Reply #15 on: January 05, 2007, 12:11:41 AM »
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

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Code Won't Load
« Reply #16 on: January 05, 2007, 09:54:59 AM »
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).
fun times
Re: Code Won't Load
« Reply #17 on: January 05, 2007, 06:00:22 PM »
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