Calibrating grblHAL CNC system movement.
Every CNC motion control system relies on being able to move something like a spindle, laser, extruder, cutter and so on. And, it is expected to do so precisely. A command to move something 1.235 inches must be fulfilled exactly. This is accomplished by knowing how many steps it will take to go from the current position to the desired position. In Grbl systems, this is controlled by the Steps per Millimeter setting (SPMM). Each axis has its own value. If the value is wrong, the machine will not produce correct results. So, you might ask, how do I make sure my machine is precise? Well, read on.
Steps to Motion
The vast majority of CNC machines use stepper or servo motors that move the axes. These motors take two inputs: a direction signal and a step pulse. Direction tells the motor which way to turn - clockwise or counterclockwise (anticlockwise in the King's English). The step pulse tells the motor to move exactly one step in the direction designated by the direction signal. To move the desired distance, the controller sends a series of step pulses to the motor. The motor, in turn, drives a linkage that translates a rotary motion into a linear one. (Though, in a lathe, it may turn the spindle.) Most motor (stepper or servo) drivers are set up to define how many steps it will take to make one full revolution of the motor. There may be gearing that increases or decreases the distance that the axis moves as the motor turns. For example, if the motor is connected to a screw that has 1 thread per millimeter, one full turn of the motor will move the axis 1mm. If the motor's driver is set up for 1600 steps per rotation, the SPMM is 1600. If there is a 2 to 1 gear between the motor and the screw, the screw turns once for every 2 motor rotations and thus the SPMM is 3200.
Grbl is controlled by settings which are numbers designated with a $ sign. These are basically variables that hold special values. Each axis has a SPMM setting. $100 holds the X Axis SPMM, $101 holds the Y Axis SPMM, $102 for Z, $103 for A and so on. You can set these by sending grblHAL a command like this:
That would set the Y Axis SPMM to 240. If you are using ioSender you do it the Settings:Grbl tab.
The actual value for SPMM is dependent on your machine's design. There are so many different schemes that we can't begin to cover them all here. But, it is likely that the machine's manufacturer has the info about how far each axis will move based on one full revolution of it's motor. To get SPMM , you need to know how many steps it takes to cause the stepper driver to turn the motor one full revolution as well as any gearing ratios. Often there are switches on the driver that determine the steps per revolution. The formula for that is:
SPMM = Steps_per_Revolution/mm_per_revolution.
If your machine is specified in Imperial/Inches, convert the distance traveled per motor revolution into mm. Use the resulting SPMM value to plug into the Grbl settings. If you can not find any information about your machine's SPMM, see the note below.
Tuning for precision
You could plug the manufacturers SPMM numbers in and call it good. However, they are not always accurate. Often there are manufacturing variations that lead to some level of inaccuracy. For some machines, it can be significant. To get the best accuracy, we have to tune the SPMM for each axis.
This entails a simple process:
Move the axis a specific distance, call it D.
Measure how far it actually moved, call it A.
Calculate the ratio of D/A.
Multiply the ratio by the current SPMM and replace the old value with the result.
Repeat the process until D and A are equal.
This works quite well and will give a very accurate machine.
How to do the measurement and tips for increasing accuracy
There are several ways to do the measurement. The easiest is with a ruler. For X and Y, place a piece of paper on your machine bed and position the head to one side of the machine. Install a bit in your spindle, if you have one, and lower it to just above the paper. I like V bits for this. Mark the position of the tip of the bit. With a laser, fire the beam at a low power to make a mark. Command the head to the other side of the machine (or a bit short of the farthest your ruler can measure) - this is the D value. You want the longest possible distance for better accuracy. You can use jogging or send a G0 command to Grbl. Mark the new position (with a laser fire the beam again) and measure the distance between the two marks - this is the A value. If A equals D, you are done for that axis. If not, find the value of A divided by D. Take the old SPMM and multiply by A/D. That is the new SPMM.
new_SPMM = old_SPMM * D / A
Save it into the SPMM setting for the axis you are testing ($100 for X, $101 for Y). Repeat the process until A equals D.
Z is a little different. Find something to hold the ruler vertically and then place it next to the Z Axis assembly. Move the Z assembly as low as possible. Place a piece of tape on the spindle or assembly, make a pen mark on it and note it's height on the ruler. Then move the assembly up by a certain distance - that is D. Note the new height of the mark and determine the distance from the first position - that is A. Just like above, calculate the new SPMM for Z and save that into the Z SPMM setting ($102). As with X and Y, repeat the process until A equals D. As a sanity check, measure the distance moving both up and down.
Using a dial indicator
The above ruler method is pretty good but, for accuracy, a dial indicator is hard to beat. If you are not familiar with a dial indicator, take some time to learn how it works. Note the maximum distance the dial indicator can measure and decide on a distance that is 50-80% of that - that is you D value. Position the finger against the spindle, move the axis just enough to fully engage the finger, set the rotating dial marker to 0 and move the axis D distance. Note the new value. That is A. As above take the ratio of A to D and multiply it times the old SPMM to get the new SPMM . If you have an Imperial indicator, you you can switch Grbl to Imperial (G20) and send it GCodes in inches. Repeat the process until A equals D.
A note on resolution
One thing that sometimes confuses people is resolution, often called accuracy. Because stepper and servo motors move in discrete steps, linear motion driven by the motor also moves in steps. If an axis has an SPMM of 200, that means it moves in steps of .005 mm. You can not tune your machine more accurately than that distance. This may be a major issue for machines with small values of SPMM .
I can not find information about my machine's SPMM
If you can not find the information, the above process will still work, you just have to make an initial guess. Pick a safe number like 200 and use it for the SPMM setting. If the real SPMM for the X Axis is, say, 400 then your first move distance of 100mm would yield an actual distance of 50. A = 50, D = 100 so
(D / A) * 200 = (100 / 50) * 200 = 2 * 200 = 400
You would then send grblHAL the following
Or use ioSender's Settings: Grbl tab and plug 400 into the X-Axis travel resolution setting. Repeating that process should yield D and A being equal.
Note: for your first move, try very small distances to see if they are reasonably close to your guess. If the actual distance is a lot longer than it should be, cut your SPMM guess in half. If if doesn't move very far, double your first SPMM guess. The general idea is to get reasonably close before measuring.
Well, that is all it takes. You should tune steps per mm when ever you move the machine or make repairs. We also recommend tuning your machine once every 6 to 12 months as wear can cause changes.
I'm Phil Barrett, a long time CNC enthusiast. I run a small company, Brookwood Design, that makes several breakout boards for grblHAL and love to help people get the most out of their CNC machines.