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.

Saturday, July 23, 2011

Finished!

Now that I've written the title for this post, I have to admit that a project like this is never finished. I mounted and wired the limit switches, so all the minimal requirements have been met. I just hot-glued the switches to the machine.

I set about testing the switches. I wrote earlier about the control process in the firmware. After opening the limit switch circuit (they are wired in series) the steppers shut down. Obviously you need to then back the machine out of the corner you're in. So pressing the throttle button switches to "escape mode" and the limit switches are ignored. I ran the spindle into the upper Z axis switch and it stopped as designed. I entered escape mode to pull away from the switch. Then I moved the table to the front edge to test that switch. It's possible I forgot to exit escape mode because the table plowed through the switch popping it off and then ran into the hard stop. This caused the screw holding the coupler to the end of the lead screw to come loose. The stepper just spun in place without moving the table. I had to remove the stepper motor and re-tighten the screw. After restarting I completed testing all 6 switches.

So now I have all the hardware in place, but it's time to start making it better. What's really cool about a project like this is that I can now use the machine to make the machine better. First I need to write a G-Code interpreter to build tool paths in my Java object format. This will allow me to use a plethora of other tools to generate tool paths. I have some tools for designing circuit boards and generating milling paths. It looks like I'll be back on the computer for a while now. I'll be designing 2 PCB boards, one for inside the control box, the other for the control panel.

Sunday, July 10, 2011

Limit Switches, Limited Progress, Reduced Backlash

Progress has been slow. After school got out we took a vacation, then we had a holiday weekend. Weather has been great, lots of barbecues. I spent most of the day yesterday doing some nature photography. Just before vacation I realized I needed to order some parts and I didn't want to do that until we got back.

I have the Sherline DRO that has special collars for mounting the encoder wheels. The X and Y collars mount on the back shaft of the steppers nicely. The Z axis collar is very different. I needed to order another one like the X/Y collar design. Sherline makes a device for the Z axis that allows tightening the saddle nut lock bar to reduce the backlash. I decided to get that, too. The kit includes a new saddle nut and lock bar which I really don't need. I'm not going to use it, just stick it in a drawer until my current Z axis wears out. I also thought it would be good to use Dremel bits with the mill for engraving so I got a 1/8" collet.

After getting the DRO handwheels remounted I was able to check the backlash. The DRO has electronic backlash compensation, basically not counting a certain number of clicks when the direction is changed. Prior to mounting the steppers, the backlash on my mill was 3-5 mils. After mounting the steppers and the Z-axis saddle nut kit, my backlash is now 1-2 mils. That's quite an improvement. The stepper mounts are so solid, there's no play at that end, so that just leaves the backlash nuts to tighten up.

I've been thinking about how I'm going to deal with backlash. I may write about that some other time. For now, I'm going to ignore it altogether since it's so low. I want to move on to getting productive with the system.

I'm supposed to be working on the limit switches now. It's not obvious how to mount the switches, certainly not in a way that looks good and is out of the way.

I did do a functional test, though. I measured the movement of the switch. The switch would move some amount I can't recall before getting to the "click" point, then another distance before bottoming out. I made a quick estimation of how many steps the motor would take to move from the click point to the bottom out point. The limit switch signal is polled in the main loop of the firmware so there would be a delay from the change of the switch to the time the steppers would be told to stop. I don't remember the numbers but it seemed likely the steppers would stop before bottoming out on the switch.

I used my favorite prototyping tool, the hot glue gun, to mount a switch and a stop block to the table. Then I ran the table into it at full speed. The steppers came to a stop even before the switch got to the click point. Sweet. The hot glue held well. I messed up the controls a few times and ran it further into the switch and the piece of plastic I used as a stop block would pop off.

My first automated project will be 2 circuit boards for the stepper box and control panel. I happened to be at the hardware store that sold Dremel bits. They didn't have a certain engraving point I wanted but I did pick up a cutting bit that looks to have like a 45 degree point on it. I mounted it in the mill and mounted a scrap PCB on the table. I brought the spindle down and nearly or lightly ran it into the hard stop. This was my first operation with the "power feed" or manual control. So, uh, yeah, I need limit switches on this thing.

I made a very light cut, maybe 6-8 mils deep. I cut a trace in two with a pretty thin line. It looks like it will do the job of cutting my PCBs just fine.