# Thread: Programming a Display Program for GCode

1. ## Programming a Display Program for GCode

Hi,
I'm currently a software engineering for a laser company and am programming a GCode display program in C#. How would I go about displaying arcs using I/J values?

As far as drawing arcs goes here are my options:
x, y, width, height, startAngle, sweepAngle
Rectangle, startAngle, sweepAngle

How would I gather the startAngle and sweepAngle from the GCode? Another option would be just to draw an arc using straight lines... How should I approach this?

2. There is some info here that may give you some ideas:

http://www.cnczone.com/forums/austra...e_indexer.html (Building a software Indexer)

3. Don't think that's what I'm looking for...

4. The best place I found that describes the different methods of arcs in G code is the Mach3 manual.
It can be found at http://www.machsupport.com/docs/Mach3Mill_1.84.pdf
Look at section 10.7.3.1 and 10.7.3.2

George

5. Originally Posted by george4657
The best place I found that describes the different methods of arcs in G code is the Mach3 manual.
It can be found at http://www.machsupport.com/docs/Mach3Mill_1.84.pdf
Look at section 10.7.3.1 and 10.7.3.2

George
Thanks I'll take a look! If anyone else has any input I'd love some more help, I'm fairly new to the GCode scene (Only been working at this job for a few weeks).

6. Originally Posted by ZSamuels28
Hi,
I'm currently a software engineering for a laser company and am programming a GCode display program in C#.
A graphical display, what most of us here would call a backplotter ?
Example NCPlot.
NCPlot.com - Tools for CNC Programmers

How would I gather the startAngle and sweepAngle from the GCode?
Arc Buddy is a simple python script that does what you want in reverse. I'm not sure if it helps at all but the code won't cost much time to read.
EMC Documentation Wiki: Simple EMC G-Code Generators

"Axis" does the backplotting for EMC2. It's open source but wading through the code will take a lot of effort. More python.

Another option would be just to draw an arc using straight lines... How should I approach this?
No idea.
G02 and G03 defines arcs so why go there ?

edit/ G02 and G03 use 'start point/end point/distance from center' (or alternatively R). If sweep is needed the program will need to make the calculation, it helps to think in quadrants.

7. Originally Posted by cyclestart

Arc Buddy is a simple python script that does what you want in reverse. I'm not sure if it helps at all but the code won't cost much time to read.
EMC Documentation Wiki: Simple EMC G-Code Generators

"Axis" does the backplotting for EMC2. It's open source but wading through the code will take a lot of effort. More python.

No idea.
G02 and G03 defines arcs so why go there ?

edit/ G02 and G03 use 'start point/end point/distance from center' (or alternatively R). If sweep is needed the program will need to make the calculation, it helps to think in quadrants.
Thank You! Looks good! I'll have to test it out and see if it does what I need.

8. Originally Posted by ZSamuels28
Hi,
I'm currently a software engineering for a laser company and am programming a GCode display program in C#. How would I go about displaying arcs using I/J values?

As far as drawing arcs goes here are my options:
x, y, width, height, startAngle, sweepAngle
Rectangle, startAngle, sweepAngle

How would I gather the startAngle and sweepAngle from the GCode? Another option would be just to draw an arc using straight lines... How should I approach this?
Using the X,Y plane as the example, circular interpolation (G02, G03) is coded using I,J or R. In some controls the I and J values describe the Absolute coordinates of the arc center point and in others, the Incremental distance from the start point of the arc. When using R in the circular interpolation coding, the R value is passed to the control where the arc center is calculated based on the start and end point of the arc.

When writing software to display the tool path, you can:
1. Easily calculate the arc center point in systems using I and J to describe the center point incrementally, by applying the I and J values to the arc start point.
2. In systems using I and J to describe the arc center in Absolute terms, the center requires no calculation.
3. In systems using R, the center point is calculated using the Start, End points and the R value. I can give you the algorithm for this if its a help to you.

Once the arc center is known the Start and End angle of the arc is calculated using simple trigonometry.

If the software is to display the cutter path of a laser machine (top view of XY plane) then using arc center, start angle, sweep angle, and radius is the best solution. If the display is an Isometric view, then the properties of the arc will still have to be calculated based on the G code data, but the acr will be drawn using short, straight lines because the representative curve drawn in the display will not be a true arc.

Regards,

Bill

9. ZSamuels, if I understand your question correctly, you're trying to write a g-code simulator in C++ to be used with your laser. Is that correct?

If so, there's quite a lot for you to consider. I've got a simulator in Beta Test called G-Wizard Editor:

GWizard Editor: A G-Code Editor and Simulator

Something you may find useful about GWE is it has a facility called "Hints" for folks that are not dyed in the wool g-code experts (actually it is helpful to many experts too, LOL). It pumps out a lot of information about each line of g-code in easy to understand English.

Here is a typical hint with information on an arc, for example:

You might find it useful just because it provides a lot of information about the arc that is not immediately obvious just looking at the raw g-code.

As for the other considerations of a g-code simulator, the language has all sorts of ways to modify what's going on that you'll need to be aware of depending on which dialect your laser's controller plans to support.

For example, you'll need to be prepared to plot the arc when scaling, work offsets, coordinate rotation, and various other factors are in play. Quite a bit of work required to build a general purpose simulator, LOL.

Probably the best place to drill down and see at least one way things are done is to go check out the source code for EMC2.

Best,

BW

### About CNCzone.com

We are the largest and most active discussion forum from DIY CNC Machines to the Cad/Cam software to run them. The site is 100% free to join and use, so join today!

### Follow us on

Search Engine Friendly URLs by vBSEO ©2011, Crawlability, Inc.