May 18, 2024, 07:37:13 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Text parser

Started by Zig, August 21, 2009, 01:57:50 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zig

Hello group,

I need some advice please.

I have a text file which consists of lines of text.

Each line has in general string tokens which may have numeric values associated with them and which followo the token with or without a white space  immediately.
There is a number of tokens which do not have a corresponding numeric value associated with them and affect how the line is to be interpreted.


an example might be something like   

G61                                ' set motion to exact stop
G00 Z1 F300                    'move to z=1 at high traverse speed and set machine to move at 300 units / minute
G00X31.91514Y91.44004  ' move to x= 31.9154 y=91.4404 at high speed traverse
G01 Z-0.005 F750             'move to Z= -0.005 at set speed of 750 units /minute
G01X31.91514Y91.43996  'move to x=.. y=.. at the last set speed
G01X31.91510Y91.43996
G01X31.91510Y81.47539
G01X32.20992Y81.18057
G02X31.97643Y80.94708I0.17508J-0.40857  ' describe a clockwise circle centred on circle center offset by i=,,, and j= .. from the (X,Y) from the previous line and finisheng at x= 31.97643 .. y= 80.94708 at set speed
G01X31.63326Y81.29026  ' from the end of arc go to x=31.63326   y= 81.29026 at the last set speed

I hope you get the idea. This is standard G code file used in CNC control.

I would like to be able to parse the lines with a subset of possible tokens in order to be able to derive some statistics abut the motion.

I need some guidance on how to think about this problem

a) determining the type and position of token

b) restructuring data for further processing and storing ( into a new file) to facilitate future acces to data and may be new analysis algorithms.

At the moment no code is needed just a discussion on the better approaches.






Ficko

Hi Zig.

Quote
a) determining the type and position of token

b) restructuring data for further processing and storing ( into a new file) to facilitate future acces to data and may be new analysis algorithms.

a)
I think the parsing isn't that difficult since you have a standart set of letters (X,Y,I,J...) followed by numbers so a simple "INSTR" positioning would do the trick.

b)
After you have the parsing sub done you don't really have to save it in different format because you can parse it again any time you want it don't you? :D

sapero

August 21, 2009, 05:10:18 AM #2 Last Edit: August 22, 2009, 04:21:05 AM by sapero
I would parse it sequentially and build a array or command-parameter pairs for each line.
For example G61 will return single pair: G=61 (parameter type = int)
G00X31.91514Y91.44004 will return three pairs: G=0 (integer), X=31.91514 (double), Y=91.44004 (double).

I have already coded it, the parser supports the slash character (ignore next pair), a and the example code displays all pairs for each line. Parser outputs the pairs into a structure and returns informational error codes, like OK, EOF, invalid command, missing parameter.
There is a todo: return an error (or convert it to double) if the number after command name does not fit into integer variable.

Zig

Ficko,

Thanks for Your comments. I think that may be reformating data may be " a nice" thing to do as I intend to be able to do a few things readily.
a) simulate time to carry out instructions
b) estimate length of traversed path
c)plot the motion graphic


Sapero thank You too for Your input.

Man You scare me. How long did it take You to write that code? I am having problems with basics and You just knock it out. I mean I am trying to learn to crawl and you ask me to do a Usein Bolt and run for a gold medal. It will take me a bit of time to get into the code contribution before i have any meaningful questions.

Thanks to both of You.

ZeroDog

August 22, 2009, 10:24:17 AM #4 Last Edit: August 22, 2009, 10:32:30 AM by ZeroDog
From the looks of the G codes, I would guess that you're running a Strippit CNC punch press?  Maybe not, as alot of the G codes are similar on other machines.  I used to program and run one of these for a living... It was an older model, and instead of inputting the programs into the machine on the keypad, we had a guy come in and modify the hardware so that we could automatically pass the programs out of the serial port on a PC, and into the CNC.   Saved us alot of time... They are fun machines... except when the punches stick... or when someone accidentally puts in a 1/4" x 1" punch in perpendicular to the die ...  ::)  ooops...  :D

Zig

I am milling printed circuit boards...
The G code is output by a gerber editor( in fact Gerber and G code are closely related). Gerber comes in two flavours 274-D plus apperture table and 274X with embedded apperture table.
The G code is 274 NGC.

I wish to be able to generate statistics such as lengrh of cut in order to be able to determine when to change tool or how much life there is in the tool.
How long a particular file will run for and a couple of smaller tricks such as optimising the sequence of G code file..

ZeroDog

oh nice.  I didnt get to play with the mills at the shop too much, but I did use them on occasion.