Sub with no motion command?

More
21 Aug 2014 04:06 #50119 by Tom_R2E3
I was looking for a way to write the current position of my machine to a file on request. I found a method by JohnT on an old forum post and put it in a macro as:

%
O<p_log> sub
G21

(LOGAPPEND,pos_log.ngc)

G92 x0 y0 z0 (store position)
g92.2

#<x> = #5211
#<y> = #5212
#<z> = #5213

(LOG,X#5211 Y#5212 Z#5213)
(LOGCLOSE)

g92.1

(MSG, done)

O<p_log> endsub

M2
%

It works as intended, however the sub never finishes, I have to kill it myself. If I add a motion command to the sub, G0 X10 or whatever then it completes. So, is there a way to make the sub complete without including a move? I couldn't find anything in the O sub info saying that there must be a motion command included.

Also, is there a simple way to write the date and time to file along with the positions?

Or (probably) is there another method for doing this altogether?

Many thanks

tom

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

More
21 Aug 2014 06:55 #50121 by BigJohnT
Without some exit code the subroutine will run forever. You could increment a counter and when it reaches some number exit the sub.

JT

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

More
21 Aug 2014 14:50 #50131 by ArcEye
Replied by ArcEye on topic Sub with no motion command?

Also, is there a simple way to write the date and time to file along with the positions?


The simplest is to just run date >> filename.log which will append the time and date to the file named

You can put this in a user M code file

Or (probably) is there another method for doing this altogether?


There are always other ways, depends why you are doing it.

If it is some kind of probing routine to replicate or map a shape, you might be better going the whole hog and using a probe and probing routines

regards

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

More
21 Aug 2014 17:34 #50140 by Rick G
Replied by Rick G on topic Sub with no motion command?
Not sure what you are trying to do, but a couple thoughts.

Is this a sub that called from another program? Or is this a program you want to run from the MDI line or a file to load and run?

What you posted starts and ends with a % which if an ngc file that runs by itself you could just get rid of the sub and endsub.

If it is a sub that is called you do not need the % at the beginning and end.

It also has a M2 to indicate you want to end the program there.

linuxcnc.org/docs/html/gcode/m-code.html#sec:M2-M30

Rick G

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

More
22 Aug 2014 02:23 #50157 by Tom_R2E3
Hi, thanks everyone for your input.

I was doing it with probing in mind, I just thought it to be a useful tool to have. I could add it to the end of the probe_hole sub but I don't really want it to log coordinates every time I probe, which is why I was trying to make it a separate button.

So I guess the aim is: a single button press to log machine position, date and time.

This is my first attempt at setting up a button. I'm using Gmoccapy and I set it up as a "macro" so its a file to load and run and needs the sub, end sub (but doesn't need %). I haven't looked in to glade buttons yet and this seemed to be the simplest way.

Arceye, thanks for the suggestion regarding user M code. I created M101, then put M101 in the sub and it works, appends date to the same file after logging coordinates.

John, I've seen a loop which increments a parameter to a given number, but how would you signal to end a sub based on this?

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

More
22 Aug 2014 04:29 #50161 by BigJohnT
I'm really not clear on what your trying to do can you spell it out for me?

JT

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

Time to create page: 0.103 seconds
Powered by Kunena Forum