In the interests of portability I've been writing the various components in plain ANSI C (except the comments, I like my double slashes!). By doing this I expect the code to be portable across a wide variety of platforms, from AVRs to the Propoeller child to ARM to PCs, with minimal effort.
My hopes are that the firmware will conform to the NIST GCode specification as closely as is manageable. That said, some sacrifices will have to made as the spec calls for around 20k of addressable space for expressions, which exceeds the total RAM of Arduinos and even the Teensy 3.0. However I hope to get mostly spec-compliant in terms of order of operations, expressions (if not the addressable space) and features. Where possible I am also allowing the specific capabilities to be determined by preprocessor macros.
I've done a bit of work on the GCode interpreter, getting some test code together that parses GCode expressions (this led to my Mathematical Expression Parser in C) as well as an arbitrary dimension DDA implementation. To date these have been just simple tests, nothing actually running on real hardware. I've also done some early tests on doing feedrate optimization and
However today I made some good progress on actually getting some real firmware started. I got my early GCode interpreter stripped down and abstracted out all the hardware-specific stuff into a hardware layer. I then wrote the hardware abstraction layer for the Teensy 3.0 version of the Arduino environment and fired up the code, using the following string to test with:
N1229.0(This is a comment)G01x110.0 y330.0 M7 F20.0(MSG: another comment)
And it worked!
The screenshot above shows the GCode interpreter code loaded up in the Arduino environment, the Teensy loader application that programs the Teensy and the serial output of the parser. Note that this is not just reading the commands linearly, it is fully parsing the input, splitting it into distinct commands, sorting the commands by operation precedence (as described in the NIST spec) and finally calling back to the Arduino sketch with each command.
Parsing the string and calling back takes about 250 us (the remaining time taken is up by serial communications) so more than fast enough to fill up a lookahead buffer. Total RAM used is about 5k, so this won't run on an Uno but does run handily on the Teensy 3.0. Ditto goes for the flash at 33Kb currently. This is pretty hefty compared to other firmware, but I think portability and cleanness makes up for that.
The next steps will be to get the kinematic/motion control stuff fleshed out. I think I should be able to use by DDA implementation running with the Teensy timers pretty easily. Then it's just tweaking and adding features...