External subroutine with parameter doen't work

More
02 Mar 2011 11:02 #7532 by ioiotutu
Hi,
i got this problem.

main program:

G90 G0 X0
O<posi> call [20]
M02


file posi (external soubroutine):
O<posi> sub
G0 X#1
G0 X100
O<posi> endsub
M02


The main program call the subroutine, the X axis move to 100 but doen't move before to 20.
I think that the external subroutine doesn't read the parameter. Is there a mistake?
any suggestions?

Thanks

Please Log in or Create an account to join the conversation.

More
02 Mar 2011 12:10 #7542 by BigJohnT
You would have to put a G4P1 between the moves to see the first one or move a different axis.

John

Please Log in or Create an account to join the conversation.

More
02 Mar 2011 12:37 #7543 by andypugh
BigJohnT wrote:

You would have to put a G4P1 between the moves to see the first one or move a different axis.

To elaborate: G-code specifies a path, and EMC2 won't stop at a point on the path unless told to do so. In your example the X=20 point is on the path from X=0 to X=100, so EMC2 carries on through it without stopping.

If the X100 were changed to X10 (for example) you ought to see the move to 20 first.

Please Log in or Create an account to join the conversation.

More
03 Mar 2011 15:05 #7560 by ioiotutu
Thanks, you are right! I didn't see the stop because the two point are on the same line. I changed axis movement and all work fine.

Another question, can i see in a external soubroutine a global variable?

example:

main program:

G90 G0 X0
#102=1000
O<posi> call [20]
M02


file posi (external soubroutine):
O<posi> sub
G0 X#1
G0 Y100
G0 Y#102
O<posi> endsub
M02

Thanks.

Please Log in or Create an account to join the conversation.

More
03 Mar 2011 15:30 #7561 by ioiotutu
Hi,
in this moment i am understanding the origin of all my problems!!!!!!

At the biginning I created a file named "posi" for my external soubroutine and the O<posi> call had a problem to open the file because it search for "posi.ngc".
After this i created "posi.ngc" and all worked fine. In a second moment i modified "posi" file instead "posi.ngc" and this confused me.

The right call for an external sabroutine is:

o<FILE_NAME> call

This istruction search the file on hard disk path named "FILE_NAME.ngc"

It works also with global variable.

Tested on EMC 2.4.6

Thanks.
Michele

Please Log in or Create an account to join the conversation.

More
03 Mar 2011 15:31 #7562 by andypugh
ioiotutu wrote:

Another question, can i see in a external soubroutine a global variable?

Yes.
www.linuxcnc.org/docview/devel/html//gco...sub:Named-Parameters
(precede the variable name with an underscore)

Please Log in or Create an account to join the conversation.

More
12 Mar 2011 08:33 #7743 by ArcEye

ioiotutu wrote:

Another question, can i see in a external soubroutine a global variable?

Yes


However, to do so violates all the principles behind object oriented programming, that give rise to the use of discrete subroutines in the first place.

This may sound pedantic, but there is good logic behind it.

A subroutine should not be reliant on any external data, just the parameters passed when it is called.
That way if you find a far better way of implementing the moves in the subroutine, you can rewrite it and so long as the parameter interface is the same, it will continue to work with all the code which previously used it.

If you use a global variable then you might just as well write the whole lot in-line and dispense with the separate file.

The subroutine you wrote will not work unless each piece of code you use it with, has the same global declaration

So what you should do is just pass as a parameter

O<posi> call [20] [1000]

regards

Please Log in or Create an account to join the conversation.

Time to create page: 0.090 seconds
Powered by Kunena Forum