Arduino / CNC

Hey all,

I've been working on a project where I use the Arduino to drive a three axis plotter (that uses various drawing / printing tools). The plotter uses three stepper motors and I'm using stepper drivers that require a step/direction signal. Everything has been going quite well, I've got a good implementation of the Bresenham algorithm for linear interpolation (based on the one used in the RepRap project). I would really like to have your advice on the following: when I have the plotter draw curves (which are split up in small straight line segments), the serial communication (currently at 28800kbps) can't keep up and starts to interfere with having a smooth movement. I have a kind of flow control set up between Processing and the Arduino, when the Arduino buffer runs low, it sends an ascii character through the serial connection, and processing replies with a new set of commands. But each time the arduino receives this new set of commands, it seems to slow down about 4 milliseconds.

Since hardware flow control is not available (correct me if I'm wrong), I will need another solution, what could be an option is to buffer the full sequence of commands, but since this won't fit in the RAM, some kind of external memory should be used. But using external memory requires reading data serially once again. My question is, can the Arduino read at fair speeds from an external EEPROM or CF card, and would this be a solution?

Any advice / comments / suggestions are most welcome!

I'm not completely sure what the problem here is, but then, nor am I any sort of expert. =P

Does the 4ms delay mean the plotter keeps moving in the direction set for 4ms too long? I am imagining your plotter drilling a line in a piece of wood, and the line becomes too long because the plotter keeps moving while the Arduino spends 4ms getting and processing the new command..

If the problem is simply that you want perfectly smooth movement I'd advice you to make your programming keep filling up the Arduinos RAM as much as possible and if the plotter works faster than you can buffer new commands from the computer, simply stop the plotter for a few, measly milliseconds for the buffer to completely fill up again.

I mean, we are talking about a serial connection here, and if the bandwidth isn't good enough to do it live and the buffer isn't big enough to contain the entire job... What else can you do apart from trying to max the bandwith to keep the buffer full at all times, and if the buffer runs because the plotter hits a segment of many short commands (like drawing a curve), you simply stop to rebuffer.

Have to say, this sounds really impressive! Would be fun to see pictures and perhaps even a video of your contraption! =D

You can also increase the serial buffer size, maybe that will help. It is in wiring_analog.c.

Hi , Just a suggestion: the arduino can obviously handle SD cards http://www.adafruit.com/index.php?main_page=product_info&cPath=17_21&products_id=94

and there is the vinculum http://www.vinculum.com that interfaces to an USB-Stick Eberhard

Hi ,
Just a suggestion:
the arduino can obviously handle SD cards http://www.adafruit.com/index.php?main_page=product_info&cPath=17_21&products_id=94

and there is the vinculum http://www.vinculum.com
that interfaces to an USB-Stick
Eberhard

How fast is this? I vaguely remember reading about interfacing an SD-card, and seem to recall it beeing horribly slow. Am I right, or do I need to smack my memory about a bit? =P

Hi,

How fast is this? I vaguely remember reading about interfacing an SD-card, and seem to recall it beeing horribly slow. Am I right, or do I need to smack my memory about a bit? =P

I have no idea, these are just the 2 things I read about and remembered. But since the adafruit-shield uses the sd-card to store 22kHz audio, it must be possible to read at least 22000 bytes a second.

What are the timing restrictions of your project? And how much memory would you need to store a command sequence?

It should solve your problem anyway. When you have all the CNC-Data replayed from the SD-card there will be no varying latency inside a command-sequence. The USB-Serial-connection to the arduino has a minimum latency of 1 millisecond. I'm pretty sure reading from a SD-card is much faster.

Eberhard

I built an X-Y plotter back in the 70s controlled by a 6800 micro all written in machine code. It accepted ASCII strings for start and end points and even did a scaling routine. You moved the pen to one point, pressed a button and that was the origin. Moved it to another point pressed a button and that was the maximum X & Y values for stepper. Then a software command told the plotter what plotting units I was going to use. I didn't use Bresham's but a much neater algorithm I found in Byte. Basically you only move a step when the start and end point of a line is less than a point away (which is practically never the case), so you push the end coordinates on a stack and split the line in half (shift operation) and test again. Repeat this recursively until you do get just a step away then make the step, change your start point to the end point (one step away) and pop your new end point off the stack. When you come out of recursion your line is drawn. Sounds complex but is quite simple to implement, once you have got your head round positive and negative line slopes.

I have just had a thought, are you implementing the Bresham's algorithm in Processing or in the Arduino it rearly should be in the latter. Otherwise you are constantly firing step commands to your motors. If this is the case I would not have any buffer in place at all, just take in the step command, do it, acknowledge it and then wait for the next. It's inefficient I know but would stop your stuttering.

Otherwise step your motor from pulses derived from a hardware time triggering an interrupt routine. In that way arrival of new commands shouldn't cause it to stutter.

Hi, i know this is an old post but it looks very interesting. Did you manage to correct the issue?

I'd like to see this thing working and have a go at building one myself.

Maybe this is a dead end thread now but worth a pop

Cheers.

Does this help? I wrote an instructable about wiring Arduino for a plotter/CNC.

http://www.youtube.com/v/wZ6c9nbNAnQ

I would really like to have your advice on the following: when I have the plotter draw curves (which are split up in small straight line segments), the serial communication (currently at 28800kbps) can't keep up and starts to interfere with having a smooth movement. I have a kind of flow control set up between Processing and the Arduino, when the Arduino buffer runs low, it sends an ascii character through the serial connection, and processing replies with a new set of commands. But each time the arduino receives this new set of commands, it seems to slow down about 4 milliseconds.

28800kbps ? 3MB/s should be fast enough! More seriously is there not a faster baud rate you can use? 28.8kbaud is less than 3 bytes per ms, so a 4ms delay isn't surprising - is 115.2kbaud or higher not available?