Saturday, 30 October 2010

y-Axis Gantry Design - Draft

I had some time today and am moving along nicely with the y-axis design for the cnc router. Here is a quick update with a couple of design images. Comments are welcome, but beware, it's work in progress. Evidently, some items are virtually floating in free air, so thanks for not pointing that out.

There are a couple of design decisions that might deviate somewhat from the 'standard' router configurations and might be worth discussing:

First, I intend to have the target 'cutting surface' positioned below x-axis shaft level. In a sense, the router will "cut down below". The idea is that this will decrease the required height of the gantry and it works in conjunction of the second point below. In effect, the lower y-axis shaft could be at around the same height as the x-axis shafts - or even below. This will reduce the all-over gantry height and bring everything closer to the x-axis mounting points. It helps, as I am using a fairly tall z-axis (shaft 400mm; z-axis movement range 210mm).

Second, I intend to avoid the "bridge" configuration, where the x-axis drive setup, eg, belt drive or threaded bolt, is centered below the floating cutting surface and connected across to both sides of the gantry. This is probably my greatest fear that it could go wrong (precision issues, or worse, lock-ups). The x-axis will be driven on the side, not the centre as my theory is that side versus centre improves alignment only by a factor of two (you are encouraged to disagree with some maths), and I found the ball bearing setup to resist alignment problems very well.

Cnc y-axis gantry. Work in Progress...
For reference, y-axis shaft length is 600mm.

If you look closely at the design, you will also notice that some of the board positioning has been chosen very carefully to be able to reach screws during assembly, for example, the inner mounting screw for the rear x-axis ball bearings. On that note, have a guess how I assembled the z-axis' nut that sits quite invisibly under the small square mdf board and is held in place by a piece of small mdf board.

Cnc y-axis gantry - from behind.

In other news, I bought a few nuts and bolts today to assemble idlers from my wide ball bearings. I think this will work very well.

Thursday, 28 October 2010

Belt and Pulleys

It didn't take long. I ordered the timing belt and pulleys on Monday from Sydney and they arrived on Wednesday, all nicely packaged.

Making friends...

 The pulleys have two small hex-screws to tighten them onto the motor shaft. The specs are: T5 15-tooth 16mm width. Hence, pitch 5mm, circumference 75mm, effective radius 11.94mm. And because you asked: Weight 26g.

Up close.

The T5 timing belt is 16mm wide and made from Urethane and Kevlar. Notably one of the Kevlar threads is exposed. I can only assume that is as intended. Does anyone know ? The belt "looks fun" and I almost wish I had bought more.

I had considered two different options of mounting the belt: The standard open belt model where the belt is stretched in mid-air from end to end, with an S-type curve around an idler and the pulley. The second option was to place two open belts against each other, teeth interlocked and on a hard surface, with the upper belt having a short travelling noose come out to go around the pulley and the noose edges held down by two idlers. However, when I place the belt teeth against each other, they lock, but not tightly enough. There is a tiny bit of play, maybe 0.4mm, so it's probably no more accurate than option one, which uses only half as much belt.

These belts are the latest fashion this summer!
Note the exposed kevlar thread at the top.

Finally, I got myself some wire for the steppers. 12 metres in all, just to have some spare for playtime. It's 4-core 1mm-square, shielded. It was kind of an educated guess if 1mm-square is enough, but we'll see. If anyone has a good formula for this sort of thing, I'd like to hear about it. Remember, it's not just about current, but also high frequency chopped signals.

Current Affairs or 4 Corners ?

Well, time to finish those y and x axis plans. It's all paper scribbles right now, but I hope this weekend I will be able to finallise it.

Monday, 25 October 2010

Belt Me !

While I was in the middle of designing the y-axis for the cnc router, I came across some reasonable offers for timing belts (vee belts) and matching pulleys. I was very tempted as the speed-power profile is much better suited to my needs than the threaded rods.

After some pondering, spreadsheeting and paper sccribbling, I took the plunge and ordered 3 metre of T5 16mm Kevlar & Urethane open belt and two matching T5 16mm 15 tooth pulleys from AusXmods, the same shop I bought the steppers and PSU from.

The only issue/fear I have is to judge if 16mm or 10mm belts would be more suitable. AusXmods unfortunately didn't have any technical specifications, so it's trial and error. I tried to predict what I'm getting by referring to the product catalogue from Gates Mectrol.

Remember, my steppers have 2.7Nm nominal holding torque, so let's make some assumptions...
  • Holding torque: 2.7Nm
  • Low speed torque: 80% of 2.7Nm = 2.16Nm
  • Top speed: 5,000 full-steps per second
  • High speed torque: 20% of 2.7Nm = 0.54Nm
  • Let's ignore belt and threaded rod friction for now.

Option 1: M12 threaded Rod
Rod Pitch: 1.75mm
Top linear speed: 5000/200x1.75mm/s = 43.75mm/s
Force at low speed: 2.16Nm * 1000 * 2 * PI / 1.75mm = 7755N = 790kgf
Force at high speed: 0.54Nm * 1000 * 2 * PI / 1.75mm = 1938N = 197kgf
Micro-step length: 1.75mm/2000 = 0.000875mm

Clearly, precision and force are way too high, and movemement is slow.

Option 2: T5 10mm belt with 10-tooth pulley
Top linear speed: 5000/200*10*5mm= 1250mm/s
pulley radius: 5*10/2/PI=7.95mm
Force at low speed: 2.16Nm*1000/7.95=271N=27.7kgf
Force at high speed: 0.54Nm*1000/7.95=68N=6.9kgf
Micro-step length: 5mm*10/2000 = 0.025mm

Top speed is obviously theoretical, but precision is good.

Option 3: T5 16mm belt with 15-tooth pulley (no 10-tooth is available)
Top linear speed: 5000/200*15*5mm= 1875mm/s
pulley radius: 5*15/2/PI=11.93mm
Force at low speed: 2.16Nm*1000/11.93=181N=18kgf
Force at high speed: 0.54Nm*1000/11.93=45N=4.6kgf
Micro-step length: 5mm*15/2000 = 0.0375mm

Top speed is again theoretical, precision is not as good, but still acceptable.

As a comparison, the maximum belt tension for a Gates Mectrol T5 10mm Kevlar belt is 320N, and for the 16mm belt it is 512N. In option 2, the stepper exerts 271N on the belt, which is a bit close to 320N, in particular considering shock when things come to a sudden stop etc. Option 3 seems a better match with the stepper exerting 181N and the belt accepting 512N.

In terms of acceleration, the gantry might weigh up to 20kg. Assuming a linear bearing friction coefficient of 0.1, we lose 2kgf, and maybe another 2kgf for the cutting force. So, we would have 18-4=14kgf remaining for acceleration at low speed, and about 2.6kg (excluding cutting force) at top speed.

To summarise all that maths in everyday language: My top speed with the threaded rod is around 44mm/s which is not much at all. With the belts, I have a chance to move rapids somewhat more rapidly, and if I get to move them at 300mm/s, I'd be very proud. So, after some plain theoretical maths, I ordered the 16mm belt. It's experimental, and if it doesn't work, I'll revert to using the threaded rods.

And I hope it's all true...

(Corrections and suggestions to my layman's physics equations are most welcome)
And I need some idlers now !

Tuesday, 12 October 2010

Stepper Motor Control Theory

The mathematical and computational aspects of stepper motor control turn out to be quite interesting. The goal is to write an efficient microcontroller algorithm that can issue step signals to 3 (or more) motors simultaneously so that the drill bit follows a pre-defined path with a desired, possibly changing velocity profile.

The opponents are the limited microcontroller processing power, and complex modeling dynamics of real-world stepper motors.

I've started on my own home-brew version, but for now, a bit of an introductory summary with pointer for more reading...

Stepper Motor Modeling

At level one, we are interested in modeling stepper motor behaviour. A very nice introduction to this topic was published by D W Jones - Control of Stepping Motors - A Tutorial. It's an all-round introduction to stepper motors and discusses stepper motor types, stepper motor physics, basic control circuits, current limiting circuits, H-bridges and decay modes, micro-stepping and torque issues, and real-time control algorithms. The algorithms are a bit theoretical, but nevertheless, they provide a sound foundation to the topic.

Some more mathematical approaches are listed below - perfect for your lonely nights...
Without making you wade through pages of maths, just imagine a stepper motor like a damped pendulum that is subject to viscous friction. A model should take into account physical behaviour (inertia, friction, etc) as well as electrical characteristics (LR-circuitry, etc).

Interestingly, the actual approximation algorithms (discussed below) effectively ignore stepper motor modeling complexities and simply assert that three values, namely maximum acceleration, maximum deceleration, and maximum velocity, are all that are needed to build a working algorithm. They probably know why!

The proposed algorithms I've found are based on the concept of constant acceleration. I'd be interested to know why "constant acceleration" seems the accepted norm as the starting point, other than for mathematical elegance and simplicity? My car does not have constant acceleration. Every time I reach 150km/h in my local suburb, a car with flashing blue lights gets in the way and slows me down.

Maybe I should put my z-axis through some load testing to see what type of maximum acceleration profile works best, just to check against the maths.

For good measure, some more maths of my own...

It was raining outside...

The G251 Controller

The Gecko G251 controller sits between the Arduino and the stepper. Modeling stepper motor physical behaviour and then creating an acceleration algorithm based on the model will be difficult, as the G251 itself applies optimisation and I don't know its internal algorithm. For example, it smoothly changes from micro-stepping to full-stepping at higher speeds and also avoids mid-band resonance. This reinforces the suggested approach of "all you need to consider is maximum acceleration to get your stepper model".

Acceleration Algorithms

The microcontroller algorithm needs to issue a pulse train to the stepper/controller. The time between each pulse can be calculated from the desired velocity/acceleration profile. To cut to the chase, for constant acceleration, you need to calculate square-roots, which isn't the kind of thing a microcontroller wants to do 50,000 times per second.

A few good approximation schemes to get you started can be found here:
  • Atmel - Linear Speed Control of Stepper Motors (pdf): Outlines acceleration algorithm, including Taylor Series approximation. Also touches on resonant frequency issues.
  • D Austin - Generate stepper-motor speed profiles in real time: A very detailed derivation of Taylor Series approximation and enhancements. Probably the best article of the bunch, but it requires division, which is an expensive instruction for an Arduino (in the order of 100 clock cycles).
  • Aryeh Eiderman detailed the Leib Ramp (pdf), which is an approximation that does not require divisions. Probably the fastest version. Notably, he makes a possibly unintended (incorrect but workable and simplifying) assumption in equation 7 where he calculates the "real time delay" using the instantaneous velocity "vi' instead of the integral of velocity over the time period in question. Someone tell me if I'm wrong here.
  • There is also a compact implementation proposal by Atmel: Atmel AVR360: Step Motor Controller (pdf). They describe a 10-byte interrupt service routine to drive a stepper. Not exactly applicable to my needs, but interesting nevertheless.
A number of semi-related topics can be found in this list of articles: Discover Circuits - Motor Control Circuits.
Multi-Dimensional (2D, 3D, and beyond)

Once you've figured out how to drive a single stepper to its edge, you are left with the challenge to orchestrate all 3 of them to work together.

The guys at RepRap (forum, site) seem to have solved the problem by using a linear Bresenham algorithm and a single "interrupt" (discussed in this post). That means, they track the fastest axis and pull along the slower axes.

I think there is a flaw in that logic. Consider the extreme example of a path for a line with an dx:dy ratio of 1.5:1, for example from (0,0) to (15,10). The Bresenham algorithm steps x nicely and regularly by one step for each interrupt (assume constant velocity throughout). However, y is stepped as (0,1,1,2,3,3,4,5,5,6,7,7,8,9,9,10). This means y velocity changes by 50% up/down every other step. I guess it is workable because the stepper just smoothes over these bumps, but I'm not sure about all-over efficiency or issues with resonance. I'd be happy to stand corrected on this one.

Bresenham example: y-movement is not smooth.

So where to go from here ?

Firstly, I'm still interested in first-principles and would like to see if I can squeeze some nice maths & approximating algorithm out of a simplified physical stepper motor model, but I'm also aware that time is moving.

Second, none of the above methods suit my multi-dimensional requirements. I can either keep browsing, or continue my own path to enlightenment. DIY is much more fun. My constraints are going to be a challenge. Since the G251 is fixed at 10 microsteps, I will have to be able to run my steppers at around 50,000 steps per second. The Arduino clocks at 16Mhz, so that's only 320 clock cycles (and fewer instructions) per step. And that's for one axis only. I may have to accept some compromises, for example, not all axes might run at full throttle at the same time.

But only time and maths will tell...

Speaking of maths: I discovered that "router project progress" is indirectly proportional to "amount of sunshine". But you knew that already...

Monday, 11 October 2010

Secret Tapes Revealed

I'm happy and relieved to report that my wobbly ball bearing problem has been solved. I can't say that I'm greatly proud of the solution, but at my target budget, it was the best I could come up with..

It turns out that the movement of the ball bearing comes indeed from the small space between the bearing and the threaded rod. That's surprising, because for the larger bearing, there is almost no movement. It just shows the relative level of precision required for these sorts of constructions, even at a hobby level.

The options to create a tight fit were
  1. Get the threaded rod machined. Expensive and I would need new, smaller-size bearings. Once I start spending money to machine things, I might as well buy a proper solution.
  2. "Slim down" the threaded rod an find a small metal or plastic sleeve that could fit over it, making it just the right size for the bearing. Probably possible, but not easy with no machining tools at home.
  3. Fit something thin, for example, paper, adhesive tape, etc between rod and bearing. Cheap, but not exactly professional.
Well, I had a go with adhesive tape and it worked. The bearing now sits steady and there is no wobble and no modulation of the linear movement. The main worry is if the tape will give way over time, eg, due to heat or ageing.

I'd like to figure out a better method, but for now I find it acceptable enough to move on to Y and X axis and to the more detailed prorgamming challenges.

Any alternative suggestions would be welcome.

Tuesday, 5 October 2010

Wobbly Ball Bearing

Well, here comes the first design problem: The z-axis ball bearing near the stepper motor does not seem exactly perpendicular to the threaded rod, so when the rod turns, the outer rim of the ball bearing moves back and forward, which in turn puts force on its mounting.

Wobbly Illustration.
All very wobbly, really...

I'm still guessing and searching, but... The surface of the nuts I use to fix the bearing to the threaded rod may not be exactly perpendicular to their thread, and/or the nuts twist slightly when they press against the bearing. Secondly, the ball bearing does not have a tight fit to the threaded rod (spacing is less than the thickness of a sheet of paper). This may cause mis-alignment when mounted, though the "wobble" effect seems more than that.

I haven't been able to fix it yet, so suggestions are welcome...

Sunday, 3 October 2010

Visual Studio 2010 Intellisense for Arduino

I use Visual Studio 2010 for work, I thought it would be nice to use it to write Arduino sketches, in particular because of Intellisense.

(Update 1 March 2011: added a #define to set the target Arduino board.)

On the web, various suggestions exist, including the Visual Studio plugin from (which didn't work on my PC and feels like it needs a bit more rounding-off). Another alternative method is described on Arduino Playground and Instructables instruct on compiling avr hex files from Visual Studio.

Anyway, I was able to get Intellisense using the following steps. I hope it works for you too...

Objective 1: Make Visual Studio treat .pde files like .cpp files
  1. Start Visual Studio 2010
  2. Go to Tools >> Options >> Text Editor >> File Extensions
  3. Add extension "pde" with Editor "Microsoft Visual C++"
  4. Click OK
Objective 2: Create a MakeFile project and point it at the Arduino libraries
  1. Create a new project of type "MakeFile" (Visual C++ >> Makefile Project)
  2. Give it a name, for example, ArduinoVS. (This is also the name of the Arduino Sketch)
  3. Click through the wizard. You need not enter anything. We don't intend to build, only edit.
  4. Go to Project >> Properties >> Configuration Properties >> VC++ Directories
  5. Set "Include Directories" to the following 3 paths (this depends on where you installed the Arduino IDE on your computer):
  6. C:\Users\Thomas\Arduino\arduino-0018\hardware\arduino\cores\arduino;
  7. Set "Source Directories" to the same paths as above.
Objective 3: Let Intellisense get around the pre-compile actions of the Arduino environment
  1. Add a new C++ file to your project. Name it exactly like the project and give it a .pde extension, for example, "ArduinoVS.pde". This is your main sketch.
  2. At the top of that file, add
     #ifdef _MSC_VER
     // Select your target Arduino board here
     #define __AVR_ATmega1280__
     #define __attribute__(x)
     #define __inline__
     #define __cplusplus
     #define __builtin_va_list int
     #define __asm__(x)
     #include "WProgram.h"
  3. You should now have intellisense support.
Objective 4: Tell the Arduino IDE to use an external editor
  1. Start the Arduino environment and open the above .pde file (ArduinoVS.pde)
  2. Go to File >> Preferences
  3. Check "Use external editor"
  4. You should now be able to compile and deploy with the standard Arduino IDE and be able to edit in Visual Studio with Intellisense. Whenever you rebuild, the Arduino IDE checks for file changes before building.
By the way, Visual Studio 2010 Express is free.

Now, back to CNC...