Friday 12 August 2011

The G code interpreter

I have previously written a CNC controller for a Boxford Duet I also have, it didn't work very well and all the maths was done on the PC and then stepping data sent  to a PIC18f4550 in the machine over a USB to serial bridge. For this project I wanted to drip feed the machine with G codes and do all the maths on the machine. the Arduino provides a nice basic environment to develop simple projects like this so it seamed like a logical choice. I had looked at the software developed for RepRap project (http://reprap.org) but it would have taken me as  long to work out what they were doing and then how to modify it for my own ends as it would to write it from scratch.

So this is the result

(I should point out that it is no where near finished yet and needs lots of tidying (might be a bit of maths wrong in the circle algorithm too) but it mainly works. If you have anything to add to it drop me a comment or email.)

To make life easy the first version takes in commands in fixed length words (e.g. G, M and T codes are all 2 digits long (e.g. G00 or T27)) with leading zeros where needed. Also all distances are measured in steps, all distances are absolute and (0,0,0) is the home position and everything is measured from their so all positions are positive. All this makes the little micro controllers brain do less and so the code is simpler and easy to follow. the drip feeder just needs to convert from real units to steps and remove or add offsets as required then pad out the numbers to 7 digits, reconstruct the line of code and send it with a '*' to execute the line.

More details can be seen in the comments in the code.

So next thing to to is write the drip feeder. I am thinking Python....


 

No comments:

Post a Comment