Wednesday, July 27, 2011

Two Thousand Dollar Spirograph

I may be dating myself with the title of this post. Back when I was a kid, there was a toy called Spirograph. It was an art toy. There were a series of geared rings, wheels, and multi-colored pens. You arranged the parts various ways and put a pen through a hole in a wheel. You used the pen to turn the wheel inside or outside a ring and it made a repetitive design like this:


I ran my first automated CNC operation yesterday. I wrote a little program to make a simple pattern that reminded my of Spirograph. I decided to run it in the air first.  The steps-per-inch setting way wrong and the pattern was too large. The mill table hit a limit switch. I fixed that up, put a pencil in my drill chuck and taped a piece of paper to the mill table. The first attempt failed when the mill pushed the pencil into the table instead of lifting it up. My Z axis direction is inverted. I got a chance to test the E-stop button! Both safety measures working!

The run was excruciatingly slow as my "Full Acceleration Distance" (see Acceleration post) was way too high. I patched up the program and ran it again. It ran much faster and completed without incident:


This is a pretty lousy picture, I know. It looks like the foreground is out of focus. Maybe it is, but the lines are very faint as the surface wasn't perfectly flat. There's a circle in there somewhere. Maybe you can see it in the full size. Here's the code:


m.setHeading(0.0f);
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 4; j++) {
m.forward(0.25f);
m.right(90.0f);
}
m.right(45.0f);
}
m.down(0.25f); // todo: Z is inverted
m.setHeading(0.0f);
m.forward(0.125f);
m.up(0.25f);
m.setHeading(90.0f);
int steps = 16;
float step = (float) (2 * 0.125 * Math.PI) / steps;
float turn = 360 / (float) steps;
for (int i = 0; i < steps; i++) {
m.forward(step);
m.right(turn);
}
m.moveTo(0, 0, 0);

The circle is off center. Can you spot the error in the code?

All in all I'm pretty happy with it. I've got quite a bit of tuning of various parameters to do. My steppers are 200 turns per revolution running in 1/2 step mode, so 400 turns per revolution. The screws are 20 turns per inch, so the steppers make 8000 steps per inch. I ran another simple path to move the table one inch and my DRO says it's a bit short. I ran it at full speed and it went farther than at half speed. I believe this indicates the deceleration phase was too short and the machine (the motor most likely, I think) was overrunning. I tweaked the FAD and got the same distance from full and half speed runs. Unfortunately the distance was not 1.000 inches. I compensated for backlash but it was still short. Not sure what's going on there.

No comments:

Post a Comment