Saturday 23 February 2013

Progress thus far

If you think about it a CNC machine is a simple thing. just read the contents of a file, parse the data and execute the commands. Yeh right!!

After reading in the file you need check it for errors and just to be annoying two different dialects of Gcode will consider each others commands as errors, for this reason most machine implement their dialect. Then you have to translate any commands you think you might come across but know that your machine won't accept. then feed those comands to the machine and allow the user to say at any moment "STOP!!" and then maybe "Whoops, my mistake, carry on...." and the problems continue.
Now most programmers will recognize this as the art of programming, but none the less it can be quite down heartening when you find another hole to patch up.

So what have I actually done then?

Well...

For the CNC machine, I have simply plonked and Arduino UNO in the control box and wired it to the stepper drivers and limit switches.  Then I spent a good month of spare time writing C to control it and debugging with a n AVR Dragon (if you cut the little track in the solder jumper just behind the USB socket it works well, but I haven't worked out how to get the chip out of Debug-Wire mode yet)

The basic structure of this code is 3 files; a main code file, a library for working with ring buffers used by the serial port and a file containing all the global variables and #defines. Not the best structure but it works and is quite navigable with code folding. First we initialize everything, then home the axes, then drop into the main loop where we tell the hast we are ready for a line, get that line, then process the M codes and then the G codes. all the serial coms are done with interrupts as is the step timing which uses a timer interrupt to get the steppers to move at the right time.

For the host machine I have been playing with pyGTK. I tied using Glade to design the GUI but when I imported it and run it in pyscripter I couldn't get it to close gracefully so I did it the old fashioned way by defining sizes and position of controls.
 My initial plan was to use a separate thread to be the host controller and handle coms with the machine and let the main thread just keep the GUI alive, however I need to work on my use of Queues and thread control as many of my attempts ended up with the control thread blocking and then still waiting to quit when the app closed. So for now all the coms are handled by a routine called every 100ms  in the GUI. The GUI is also very basic for the moment but there are a few useful methods in the Programme class that can be used to get your machine to do almost anything. Still need to get acceleration done and put some backlash compensation in there but that's for the future.

code produced thus far


No comments:

Post a Comment