Re: [CAD_CAM_EDM_DRO] g-code parsers
Posted by
Alan Marconett KM6VV
on 2001-01-03 14:28:54 UTC
Les,
What you need is a "Get Token" routine, that knows about the these
special command letters (more if you like):
"N", "F", "G", "M", "A", "X", "Y", "Z", "R",
"I", "J", "K", "S", "T", "*", "(", ")",
" ", "\r", "\n"
These are returned separately. The GetToken routine also returns the
other stuff ( " 0.001") as strings, so that they can be scanned for
parameters:
sscanf(TokPtr, "%d", &n_parm) /* line number */
or an XYX coordinate, etc. Upon finding a command letter (search an
array), you dispatch to a line in a state machine where the next token
found will be the parameter: Y 1.00.
Typical parms needed:
int n_parm, g_parm, m_parm, t_parm;
double a_parm, x_parm, y_parm, z_parm;
double r_parm, i_parm, j_parm, k_parm;
double s_parm, f_parm;
Typical nodal parameters (nodal groups), and some default values:
int MoveMode = MOVE_LINEAR_INTERP;
int MovePlane = MOVE_PLANE_XY;
int MoveUnits = MOVE_INCH_UNITS;
int PositioningMode = MOVE_ABSOLUTE;
int ToolLengthComp = MOVE_TOOL_LEN_CANCEL;
int ToolMode = NO_TOOL;
int Mcode = 0;
As you "parse" a block (line), you set the nodal parameters (MoveMode =
G1), and the X,Y,Z parms, etc. We expect no more then one parm from
each nodal group (G1 X 1.0 Y 1.0 G17 G90).
After having parsed a line, we "use" the parms, a G1 and x_parm give us
enough info to move. We use the existing "state" of the Plane, Units,
ABS etc. parms to decide HOW to move.
Add as much error detection and error reporting as you desire (NEED).
Really not much more to it then that. We stay in a loop getting blocks
(lines), and parse each one, and then act upon them as necessary. Many
parms just get set as we find them (G17, G90 etc), others we wait until
the end of the line (a move, for example). If we want to get really
serious, we "read ahead", and put moves in a queue, and decide when and
when not to accelerate and decelerate (look ahead). Left as an exercise
for the reader.
Hope I haven't muttled this up to badly. But I think you get the gist
of it.
Alan KM6VV
PS, This might also give others a little bit of an idea what's going on
"under the hood".
PPS You don't really need string tests. Just look up tokens, and act
upon them in a well defined state machine. ;>)
New Year's Eve, just before our guests arrived, I got my first circle
cut using a controller I'm writing!
Les Watts wrote:
What you need is a "Get Token" routine, that knows about the these
special command letters (more if you like):
"N", "F", "G", "M", "A", "X", "Y", "Z", "R",
"I", "J", "K", "S", "T", "*", "(", ")",
" ", "\r", "\n"
These are returned separately. The GetToken routine also returns the
other stuff ( " 0.001") as strings, so that they can be scanned for
parameters:
sscanf(TokPtr, "%d", &n_parm) /* line number */
or an XYX coordinate, etc. Upon finding a command letter (search an
array), you dispatch to a line in a state machine where the next token
found will be the parameter: Y 1.00.
Typical parms needed:
int n_parm, g_parm, m_parm, t_parm;
double a_parm, x_parm, y_parm, z_parm;
double r_parm, i_parm, j_parm, k_parm;
double s_parm, f_parm;
Typical nodal parameters (nodal groups), and some default values:
int MoveMode = MOVE_LINEAR_INTERP;
int MovePlane = MOVE_PLANE_XY;
int MoveUnits = MOVE_INCH_UNITS;
int PositioningMode = MOVE_ABSOLUTE;
int ToolLengthComp = MOVE_TOOL_LEN_CANCEL;
int ToolMode = NO_TOOL;
int Mcode = 0;
As you "parse" a block (line), you set the nodal parameters (MoveMode =
G1), and the X,Y,Z parms, etc. We expect no more then one parm from
each nodal group (G1 X 1.0 Y 1.0 G17 G90).
After having parsed a line, we "use" the parms, a G1 and x_parm give us
enough info to move. We use the existing "state" of the Plane, Units,
ABS etc. parms to decide HOW to move.
Add as much error detection and error reporting as you desire (NEED).
Really not much more to it then that. We stay in a loop getting blocks
(lines), and parse each one, and then act upon them as necessary. Many
parms just get set as we find them (G17, G90 etc), others we wait until
the end of the line (a move, for example). If we want to get really
serious, we "read ahead", and put moves in a queue, and decide when and
when not to accelerate and decelerate (look ahead). Left as an exercise
for the reader.
Hope I haven't muttled this up to badly. But I think you get the gist
of it.
Alan KM6VV
PS, This might also give others a little bit of an idea what's going on
"under the hood".
PPS You don't really need string tests. Just look up tokens, and act
upon them in a well defined state machine. ;>)
New Year's Eve, just before our guests arrived, I got my first circle
cut using a controller I'm writing!
Les Watts wrote:
>
> In anticipation of getting the big gantry mill mechanically done
> I have been writing the control code in c. I am still waiting for some
> spiral bevel gears and angular contact bearings for the
> twin ball screw transmissions I have built.
>
> I began today on a g-code parser function. I want it to be very non-hardware
> specific- just a function that puts the commands and coordinates in a nice
> neat set of little arrays. Other functions will use that for hardware
> specific commands (to servo card with arc or NURBS interpolation). Most of
> those are written.
>
> I can do this but I really feel like I am reinventing the wheel.
> Parsing is noy the most fun code to write either. A gazzillion
> string tests.
>
> I wonder if anyone can point me to an already written c function that does
> this? I am not a c++ type but could be if it
> happens to be of that implementation.
>
> Thanks
>
> Les
>
> Leslie Watts
> L M Watts Furniture
> Tiger, Georgia USA
> http://www.rabun.net/~leswatts/wattsfurniturewp.html
>
> Welcome to CAD_CAM_EDM_DRO@...,an unmoderated list for the discussion of shop built systems, for CAD, CAM, EDM, and DRO.
>
> Addresses:
> Post message: CAD_CAM_EDM_DRO@egroups.com
> Subscribe: CAD_CAM_EDM_DRO-subscribe@egroups.com
> Unsubscribe: CAD_CAM_EDM_DRO-unsubscribe@egroups.com
> List owner: CAD_CAM_EDM_DRO-owner@egroups.com, wanliker@...
> Moderator: jmelson@... [Moderator]
> URL to this page: http://www.egroups.com/group/CAD_CAM_EDM_DRO
> FAQ: http://www.ktmarketing.com/faq.html
> bill,
> List Manager
Discussion Thread
Les Watts
2001-01-03 13:41:18 UTC
g-code parsers
andy@o...
2001-01-03 14:18:43 UTC
Re: g-code parsers
Alan Marconett KM6VV
2001-01-03 14:28:54 UTC
Re: [CAD_CAM_EDM_DRO] g-code parsers
Les Watts
2001-01-03 15:43:11 UTC
re:g-code parsers
Jon Elson
2001-01-03 16:27:55 UTC
Re: [CAD_CAM_EDM_DRO] re:g-code parsers
Alan Marconett KM6VV
2001-01-03 16:27:59 UTC
re:g-code parsers
Alan Marconett KM6VV
2001-01-03 16:35:27 UTC
Re:g-code parsers
Les Watts
2001-01-03 17:44:11 UTC
Re: [CAD_CAM_EDM_DRO] re:g-code parsers
Carlos Guillermo
2001-01-03 19:56:00 UTC
RE: [CAD_CAM_EDM_DRO] re:g-code parsers
ballendo@y...
2001-01-03 19:57:06 UTC
re:re:g-code parsers
Alan Marconett KM6VV
2001-01-03 20:00:39 UTC
Re: [CAD_CAM_EDM_DRO] re:g-code parsers
ballendo@y...
2001-01-03 20:06:04 UTC
re:Re: re:g-code parsers