Is there software that I can run on my pc that will take a G code file and turn it into a serial stream of x,y and z commands, so that my Arduino, which can do the inverse kinematics and control a robot arm, can receive that data? The Arduino takes care of the inverse kinematics and stepper control, but I now want to find a way to feed it the x,y and z coordinates contained in a G code file in an automated manner.
I wrote a similar program using Processing to read a line at a time from an SD card and output to the serial port for a plotter program running on an Uno. My program just sent the gcode, though.
The Serial input basics tutorial can help with formatting data packets, reliably receiving and parsing the data.
It's not all that difficult to write a GCode interpreter, especially if you only need to deal with a few of the GCode elements.
You need to know whether your Arduino program expects absolute or relative references. By relative I mean, move another 3.7mm in the X direction from where you are now.
...R
I currently have my program written so that it responds to absolute values.
There are programs that output Gcode for grbl, and will interpret various formats of gcode files, but I have no idea as to what format their output is in. If I knew they might be suitable, I could try to format my C++ program so that it receives and interprets their output. Currently, I simply have my program receive serial in the format of <x,y,z> and it acts upon that. I'd like to be able to say scan a drawing, have a program convert that to Gcode, then have my robot arm trace out the drawing.
There is lots of online stuff that explains the GCode "language". It is actually very simple/
Produce a GCode file and open it in your text editor so you can see it. To start with maybe delete all but the first 100 lines of code to make the reading more manageable.
...R
take a G code file and turn it into a serial stream of x,y and z commands,
Basically that is what G code is, a sequence of x,y, and z commands. You just need to write into the Arduino to ignore anything that does not start with a G0.
For those interested, here is a link to Interfacing with grbl. It explains the communication protocol that grbl uses.
I also found this work done by Marginally Clever to write code to interpret Gcode in two dimensions. I'll test it out and see if I can use some of his ideas.