View Full Version : Books or info on writing an basic not BASIC interpreter
03-07-2007, 02:46 AM
Hi does anybody have any useful links or books on writing a basic (simple)·interpreter. I need to write an interpreter for G-Codes for my little CNC mill i'm starting to build. I've read through the very large post on the forum concerning building a CNC mill and it's not quite what i'm after.
I would like the prop to control the whole system using VGA for the display and input programs directly or save/load programs to an SD card thanks to rockicki.
Any info is appreciated
03-07-2007, 03:02 AM
How about starting with FemtoBasic. There's a version that uses a VGA display and already can save/load to an SD card (and read/write data to an SD card). It's fairly straightforward to add specialized statements. Have a look: http://forums.parallax.com/showthread.php?p=634092.
03-07-2007, 03:05 AM
Thanks Mike, are you familiar with G-code syntax? Do you have enough free time to write an introduction or tutorial? I'm fairly novice programmer and it would be a nice for a gentle introduction to the subject
03-07-2007, 03:19 AM
Never heard of G-code. It will be some time before I get around to documenting much more. Have a look at two routines in FemtoBasic.spin, "factor" and "texec". Both are big case statements using an initial token code to identify the statement or expression factor to be handled. There is a table near the beginning with the text for the tokens (tok00, tok01, etc.). The program is stored with the tokens replaced by a byte from 128 (token 0) and up which makes parsing much easier. A routine "spaces" skips blanks and stops (and returns) the first non-blank. A routine "skipspaces" moves ahead to the next character, then skips over any blanks. For example, if you're looking for a left bracket followed by an expression and a closing bracket, you'd do
if spaces <> "["
abort @syn ' abort with a syntax error message
value := expr ' process any expression value
if spaces <> "]"
03-07-2007, 03:22 AM
Cheers Mike, I'll get stuck in shortly.
Just for reference. http://en.wikipedia.org/wiki/G-code
03-07-2007, 03:42 AM
g-code is kind of like logo , but instead of moving a turtle your moving a tool bit. :- )
·"Imagination is more important than knowledge..." ·· Albert Einstein
03-07-2007, 03:43 AM
How are you going to generate the Gcode? If it is a large file do you intend to read it in line by line or in chuncks off the SD reader? Are you using steppers with step/direction for motion? Do you need arc/circular interpolation? I would think that just running lines of XYZ would be fairly simple on the Propeller, just read each line and have each motor move to it's new coordinate, then read the next line. Circles and arcs are another thing, there are few guys here that have some machines running non-Gcode machine code, they are doing circles and arcs and could probably explain where to start looking to get that code done.
Do you have a software that will run the steppers already? Mach3 is a good software to borrow some ideas from for the Prop concept.
You need different headers for different routines: Routing would be one routine, drilling is another.
//drill command here includes tool height above material during travel, drill depth, drill method(one move or peck=X distance per Zdrill move)
Post Edited (originator) : 3/6/2007 8:51:02 PM GMT
03-07-2007, 04:32 AM
For a start, FemtoBasic is an integer arithmetic interpreter and you will need fixed point (probably not floating point because of the loss of accuracy in conversion to binary). Circles and arcs will take some work. Maybe you'll want to convert to floating point to use the trig functions, then back to fixed point. The G-code looks really simple to process (other than what you actually do with the commands). I'd throw out most of FemtoBasic and just use it as a guide. How would you edit it? FemtoBasic uses a simple line number based scheme and G-code doesn't require line numbers. I don't think anyone has done a finished editor for the Propeller.
03-07-2007, 05:03 AM
Typical Gcode uses numbers to .0000
A circle or arc requires the starting coordinate for XY, and the radius start and end (I,J). Here is a circle with its center at X0 Y0, 1" radius, F = Inches Per Minute
There are variations of how this is done, but here is a simple version of a 1" radius circle with center at 0,0
G2 CW interpolate
G3 CCW interpolate
G0 X1.0000 Y0.000 Z2.000 'start here
G1 Z-0.3000 F5 'plunge tool into material .3 deep Punge into material at F5 speed
G3 I-1.0000 J0.0000 F10 'move tool at F10 to route the circle
G0 Z2.000 'done, move tool back up to 2 above material surface
The software reading this code will move the stepper(or servo) in the correct steps and direction(interpolated)
A 1" x 1" square Gcode: G0 is a rapid move to position the motors for a cut. The Z(Tool) is referenced to 0 by lowering tool to material surface, then Zero out the axis. G1 is a linear move, for any new coordinate, move the tool that direction at the speed. A circle can actually be cut this way, just use many short lines based on some resolution.
G0 X0.0000 Y1.0000 Z2.0000 'get into position to start
G1 Z-0.3000 F5 'plunge into material
X1.0000 F10 'move tool at 10 ipm
G0 Z2.0000 'done, move tool back up
Post Edited (originator) : 3/6/2007 10:48:28 PM GMT
Phil Pilgrim (PhiPi)
03-07-2007, 05:25 AM
Another option you might consider is to write a PC program to preprocess the G-codes and output integer data that's easier for your mill to interpret. In the worst case, it could even interpolate arcs into a series of short, straight-line segments.
03-07-2007, 07:25 PM
I was going to use a PC to draw/model what I want and get it to output G-Code, using the prop for basic editing and monitoring of position. Hopefully I'd like to read the whole program and display it if possible. Bearing in mind i'm very new to this stuff and I learn by doing, an I know some of what i'm proposing may not be possible.
I would like circular/arc interpolation and line numbers wouldn't be a problem
I'm fairly certain most of the background work as far as the control side is concerned has been achieved by a helpful fellow on these forums called NEWZED.
I believe his positioning info/program is embedded inside his spin program and he must upload a new program to the prop everytime he needs to machine something different, hopefully NEWZED may be nice enough to clarify this.
That just leaves the display, interpreter and SD card to figure out. I realise I may need two props for this.
Thanks for everyones input so far :)
Edit: Sorry it took me so long to reply. I'm in England and have to sleep
Post Edited (Damien Allen) : 3/7/2007 12:34:22 PM GMT
03-08-2007, 01:48 AM
Have you checked on Amazon.com (http://www.amazon.com/s/ref=nb_ss_b/002-3013299-3564853?url=node%3D1000%2C5&field-keywords=interpreter&Go.x=11&Go.y=10&Go=Go)?
(Links to a search for 'interpreter' in the Computers & Internet category)
Don't visit my new website...