Dynomotion

Group: DynoMotion Message: 12664 From: allsoft01a Date: 1/4/2016
Subject: Looping in G-Codes

I am using KmotionCNC and G-Codes to program a pick and place robot.  I am just getting started.  I am able to working with the I/O without too much problem.  However, I need to figure out how to loop back and start a new cycle.  Is there a G or M code to loop either back to the start or to a line in G-Code?


Thanks

Group: DynoMotion Message: 12665 From: alhaladaoc Date: 1/4/2016
Subject: Re: Looping in G-Codes
There's a few web resources on g-code I use for reference. 

I'm a fan of CNCCookbook, so there is that abbreviated series. 

The first thing you'll run across about G-Code is despite there being a standard, there are eerie parallels to HTML and the early days of the web. By that I mean, people extend and thereby make proprietary "their" version of such.  The KMotion is based on the EMC interpreter (from: http://dynomotion.com/Help/GCodeScreen/GCodeScreen.htm). Here is the Dynomotion link: 

"(Only the G Code portions of the manual, Chapters 10-14 pertain toKMotion G Code)"


For quick lookups, I prefer the linuxCNC formatted pages:

http://linuxcnc.org/docs/html/gcode.html


You may find those handy. As to your question, here's the LinuxCNC section on stopping/stopping and recycling to start:
http://linuxcnc.org/docs/html/gcode/m-code.html#mcode:m2-m30

 

Tormach is also a nicely formatted source:

Looping
Here is CNCCookbook on the subject:

LinuxCNC on flow control:
http://linuxcnc.org/docs/html/gcode/o-code.html

 

Note: None of my G-Code requires much in the way for flow control, so I personally have not attempted use of O codes to see if they function in the KMotion interpreter. Perhaps someone with experience can provide their own experience on that particular point.





 








Group: DynoMotion Message: 12666 From: alhaladaoc Date: 1/4/2016
Subject: Re: Looping in G-Codes
I will answer my own ponder. As I suspected, the O-codes are a LinuxCNC extension to the EMC/RS274 standard, and likely will not function with KMotion (http://linuxcnc.org/docs/html/gcode/rs274ngc.html)

from the above link: 
O-codes

These codes are not defined in RS274/NGC


Group: DynoMotion Message: 12667 From: Eon deKoker Date: 1/5/2016
Subject: Re: Looping in G-Codes
Hi

I found that the syntax for KMotionCNC is different from LinuxCNC. For example to call a sub o100 I have to use M98 P100 and M99 to return from the sub. Also no flow control (repeat, if, while, etc).

You can do a loop by calling the subroutine this way:

M98 P100 L5

where L5 means loop 5 times. But L has a max limit of 99. All loops have to be in subroutines

The best is to look at manuals for Mach3 as it uses the same interpreter.





On Tue, Jan 5, 2016 at 8:32 AM, matthew.sekulic@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

There's a few web resources on g-code I use for reference. 


I'm a fan of CNCCookbook, so there is that abbreviated series. 

The first thing you'll run across about G-Code is despite there being a standard, there are eerie parallels to HTML and the early days of the web. By that I mean, people extend and thereby make proprietary "their" version of such.  The KMotion is based on the EMC interpreter (from: http://dynomotion.com/Help/GCodeScreen/GCodeScreen.htm). Here is the Dynomotion link: 

"(Only the G Code portions of the manual, Chapters 10-14 pertain toKMotion G Code)"


For quick lookups, I prefer the linuxCNC formatted pages:

http://linuxcnc.org/docs/html/gcode.html


You may find those handy. As to your question, here's the LinuxCNC section on stopping/stopping and recycling to start:
http://linuxcnc.org/docs/html/gcode/m-code.html#mcode:m2-m30

 

Tormach is also a nicely formatted source:

Looping
Here is CNCCookbook on the subject:

LinuxCNC on flow control:
http://linuxcnc.org/docs/html/gcode/o-code.html

 

Note: None of my G-Code requires much in the way for flow control, so I personally have not attempted use of O codes to see if they function in the KMotion interpreter. Perhaps someone with experience can provide their own experience on that particular point.





 









Group: DynoMotion Message: 12668 From: alhaladaoc Date: 1/5/2016
Subject: Re: Looping in G-Codes
Good to know; I will save that for future reference. I did see an interesting take on a conditional work-around for Mach3 on the CNCZone, but I did not delve deep enough to see if it was native to Mach3 only, or would work through the plug-in translation layer.

Condition gcode execution is possible in Mach3

 



Group: DynoMotion Message: 12669 From: Eon de Koker Date: 1/5/2016
Subject: Re: Looping in G-Codes
Tnx yes, this is interesting.

Sent from my iPhone

On 05 Jan 2016, at 10:27, matthew.sekulic@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:

 

Good to know; I will save that for future reference. I did see an interesting take on a conditional work-around for Mach3 on the CNCZone, but I did not delve deep enough to see if it was native to Mach3 only, or would work through the plug-in translation layer.


Condition gcode execution is possible in Mach3

 



Group: DynoMotion Message: 12675 From: allsoft01a Date: 1/5/2016
Subject: Re: Looping in G-Codes
So it sounds like unless I want to move to Mach 3 I need to move my application into a C program?

If that is the case what is the best way to create some type of user interface that allows the C program to be start/stopped/paused and status to be viewed?

Thanks.
Group: DynoMotion Message: 12676 From: Eon deKoker Date: 1/5/2016
Subject: Re: Looping in G-Codes
Hi

We also had this issue. We first wrote a program in G-Code and then found we could not make it run continiously. So then we had to rewrite it in C. We just use the Gcode screen in KMotion. You can assign the C program to a button to start and another button to stop. The lower portion of the screen displays messages.  It is actually a pity that there is no M command or something similar to have G-code run continuously.

Depending on how many times you want the G-Code to loop, I suppose you could do the following:

M98 P1 L99

O1
M98 P2 L99
M99

O2
M98 P3 L99
M99

O3
Put the program here

This will loop 99*99*99 times.  






On Tue, Jan 5, 2016 at 9:29 PM, steve@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

So it sounds like unless I want to move to Mach 3 I need to move my application into a C program?


If that is the case what is the best way to create some type of user interface that allows the C program to be start/stopped/paused and status to be viewed?

Thanks.


Group: DynoMotion Message: 12678 From: Hardy Family Date: 1/5/2016
Subject: Re: Looping in G-Codes
Hi Tom,

I hope there is not really a Gcode interpreter limitation of 99 loop executions.  We have some code out there in customer land that can potentially require thousands of loops, although it is not hard-coded.  It is more like

M98 Pxxx L[#123]

where the #123 value is determined by the number of laser probing cycles that occur in the preceding code.

I might have only had the patience to test up to 99 loops!

Regards,
SJH


On Tue, Jan 5, 2016 at 12:24 PM, Eon deKoker eondekoker@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Hi

We also had this issue. We first wrote a program in G-Code and then found we could not make it run continiously. So then we had to rewrite it in C. We just use the Gcode screen in KMotion. You can assign the C program to a button to start and another button to stop. The lower portion of the screen displays messages.  It is actually a pity that there is no M command or something similar to have G-code run continuously.

Depending on how many times you want the G-Code to loop, I suppose you could do the following:

M98 P1 L99

O1
M98 P2 L99
M99

O2
M98 P3 L99
M99

O3
Put the program here

This will loop 99*99*99 times.  






On Tue, Jan 5, 2016 at 9:29 PM, steve@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

So it sounds like unless I want to move to Mach 3 I need to move my application into a C program?


If that is the case what is the best way to create some type of user interface that allows the C program to be start/stopped/paused and status to be viewed?

Thanks.



Group: DynoMotion Message: 12679 From: allsoft01a Date: 1/5/2016
Subject: Re: Looping in G-Codes
I need to run continuously, possibly for days or weeks.  It is a shame there is no M code for this.  Who controls the G-Code interpreter is it possible to get it added?


Group: DynoMotion Message: 12680 From: Tom Kerekes Date: 1/5/2016
Subject: Re: Looping in G-Codes
Hi

The same approach should work with KMotionCNC as with Mach3.  Both support variable numeric subroutine labels.

With Mach3 the Interpreter should work the same regardless of what motion plugin is performing the motion.

KMotionCNC also supports a Variable loop count (L word) which includes zero calls.  To me that is a simpler form of conditional.

See the example: SubroutineWithConditionals.ngc

I'm not sure why Eon feels that the Loop Count must be less than 100.  Any value up to ~2 billion should be allowed.

Regards
TK

On 1/5/2016 12:27 AM, matthew.sekulic@... [DynoMotion] wrote:
 

Good to know; I will save that for future reference. I did see an interesting take on a conditional work-around for Mach3 on the CNCZone, but I did not delve deep enough to see if it was native to Mach3 only, or would work through the plug-in translation layer.


Condition gcode execution is possible in Mach3

 




Group: DynoMotion Message: 12681 From: Tom Kerekes Date: 1/5/2016
Subject: Re: Looping in G-Codes
Hi,

It isn't clear to me exactly what you are trying to do.

If you don't like using a subroutine with an infinite loop count you should be able to add an action to M30 to automatically re-cycle start.

Configure the M30 (stop rewind) with an additional action to execute:

#include "KMotionDef.h"
#define TMP 10
#include "KflopToKMotionCNCFunctions.c"

main()
{
    while (JOB_ACTIVE) ;  // wait until GCode Finishes
    DoPC(PC_COMM_EXECUTE);  // Cycle Start again
}


The source code for the Interpreter is there if you wish to add a new command.

Regards
TK



On 1/5/2016 2:27 PM, steve@... [DynoMotion] wrote:
 

I need to run continuously, possibly for days or weeks.  It is a shame there is no M code for this.  Who controls the G-Code interpreter is it possible to get it added?




Group: DynoMotion Message: 12682 From: Eon deKoker Date: 1/5/2016
Subject: Re: Looping in G-Codes
Hi Tom

The loop limit of 99 was mentioned in the Mach 3 support forum: https://www.machsupport.com/forum/index.php?topic=14476.0

Glad to know this does not apply to KMotion.

On Wed, Jan 6, 2016 at 2:45 AM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Hi,

It isn't clear to me exactly what you are trying to do.

If you don't like using a subroutine with an infinite loop count you should be able to add an action to M30 to automatically re-cycle start.

Configure the M30 (stop rewind) with an additional action to execute:

#include "KMotionDef.h"
#define TMP 10
#include "KflopToKMotionCNCFunctions.c"

main()
{
    while (JOB_ACTIVE) ;  // wait until GCode Finishes
    DoPC(PC_COMM_EXECUTE);  // Cycle Start again
}


The source code for the Interpreter is there if you wish to add a new command.

Regards
TK



On 1/5/2016 2:27 PM, steve@... [DynoMotion] wrote:
 

I need to run continuously, possibly for days or weeks.  It is a shame there is no M code for this.  Who controls the G-Code interpreter is it possible to get it added?





Group: DynoMotion Message: 12683 From: Steve Blackmore Date: 1/5/2016
Subject: Re: Looping in G-Codes
On Wed, 6 Jan 2016 09:13:01 +0200, you wrote:

>Hi Tom
>
>The loop limit of 99 was mentioned in the Mach 3 support forum:
>https://www.machsupport.com/forum/index.php?topic=14476.0

There is no loop limit.

Not sure what your trying to do but a simple M47 works for me with Mach3

Write all your code and stick M47 as last code line.

M47 - Repeat program from first line

From Mach manual

10.8.8 Return from subroutine
To return from a subroutine program M99 Execution will continue after
the M98 which called the subroutine.
If M99 is written in the main program, i.e. not in a subroutine, then
the program will start execution from the first line again. See also M47
to achieve the same effect.

Will run for ever until you stop it....

Steve Blackmore
--
Group: DynoMotion Message: 12684 From: allsoft01a Date: 1/6/2016
Subject: Re: Looping in G-Codes
Thank you all for your comments and input.

@TK:  You asked what I am trying to accomplish.  I have a pick and place robot that will be removing parts from a machine.  My hope was to program all in G-Code so it would be easy for non-programmers to make position changes.  

I think I will just stick with a C program for now.  As I gain more experience with KMotionCNC and KFLOP I might revisit the G-Code idea.

@Eon deKoker: You mentioned that you use a button to stop the program.  How do you do that?  

Is it possible to get the console display on the KMotionCNC screen so I can see printf messages from my program?

Thanks so much for the help.


Group: DynoMotion Message: 12686 From: Tapio Larikka Date: 1/6/2016
Subject: Re: Looping in G-Codes
Hi All,
 
M47 at end of Mach G-code results in endless loop. I have a custom macro (M599 in my case) at end of G-code.
 
Custom macro and script editor gives me conditional branching for M30(stop)/M47(repeat) based on parts counter and input from parts magazine part sensor.
 
I did look at adding M47 to KMotion interpreter as part of my ongoing quest to move from Mach to KMotion but it's still pending due to my illiteracy in C++
If anyone has need/interest an example can be found in my screenset in group/Files/Tapio/Threading.zip
 
 
Rgds,
Tapio