A faster and more precise way to square a gantry
Gantry auto-squaring as a part of machine homing is a great feature of modern motion control software. Typically, one creates a large square or rectangle with the machine, measures the diagonals and then adjust one of the homing targets to change a homing sensor target point. This requires a trial and error process to bring the gantry into square and relies on the accuracy of a tape measure. The process is described here.
The basic idea
That process works but, in measuring the diagonals, you have all the information you need to know how much to change the homing sensor targets by. And, modern motion controllers allow you to enter that value directly. In grblHAL, this is called a dual axis offset. Even if your motion controller software doesn't support that, you can still use this method, see below. The reasoning for this comes from the Pythagorean Theorem. When your gantry is not square and you try to cut a square what you get is a parallelogram. The diagonals will be of different lengths.
The dotted line shows what you told the machine to cut, the blue shaded area is the actual cut and d is the distance you have to move the the gantry to get a true square. By using the Pythagorean Theorem, we can determine d. The amount of squaring error is exaggerated in the above figure. The amount will typically be fairly small.
The actual dual axis offset value needs to be scaled by the size of your machine - specifically scaled by the ratio of the width between your homing sensors and the size of your test block (h). See the diagram below. We will use the distance between the homing sensors divided by h to scale the value of d. You will need to carefully measure that distance in order to properly calculate the value you enter as the dual axis offset.
Note: the diagrams are set up for a moving gantry on the Y rails. You will need to adjust if your gantry moves on the X or other rails.
The gory details
The process starts with cutting a square block on your machine and measuring the diagonals - we will call them r1 and r2. We use them to create 2 right triangles. See the figures and formulas below for how to get a value of d from each of them. But fear not about the math, a worksheet is available - you just plug in h, r1, r2 and width between sensors and it gives you the dual axis offset value to enter into your machine settings. See below.
The process
If you have grblHAL on your CNC machine, make sure you have a recent firmware build with auto-squaring enabled. (Look for $17x in the axis settings.) Also make sure you have calibrated your machine. If not, see here. Digital calipers will give you a more accurate measurement but a tape measure or even simple ruler can work. Do this in metric to keep it simple.
Using your favorite CAD/CAM application, create a GCode program for a square measurement block. Remember the size of the square, you will use it in the spreadsheet as h.
If you have digital calipers, cut a square block. Pick a size that will work for them. 80 to 100 mm is good size for 6" calipers. MDF is a good choice of material.
If you don't have digital calipers, instead of cutting a block, drill four peg holes in a square. You can mount 4 pieces of scrap wood on your machine if you want to avoid drilling into your spoilboard. The larger you can make it, the more accurate it will be.
Cut the measurement block on your machine.
Measure the two diagonals. Get the most accurate measurement you can. R1 runs from the left primary motor side to the right secondary motor side. R2 is the other one.
Enter h, r1 and r2 into the spreadsheet cells highlighted in green.
Measure the width between the centers of your two homing sensors (Y1 and Y2) and enter into the spreadsheet. Take the dual offset value (highlighted in yellow) and enter into the $17x setting for your axis. Fora moving gantry on the Y rails, it is $171.
We calculate 2 values of the dual offset, one each from r1 and r2 and use the average. This is to try to minimize measurement error. If the two dual offset values are not close, try to get better measurements.
Error, accuracy, redundancy and simplicity
Because we are physically measuring the diagonals, there will be some measurement error. It is important to get the best possible measurements you can. One trick is to rotate the cut block to force the calipers to the widest measurement. That should be the true diagonal distance. If using holes and pegs, try to keep the ruler/tape measure exactly parallel to the true diagonal.
You should repeat the process to verify it worked.
Both diagonals are used to check for and minimize measurement error. If the two calculated values of d are not close then there was a significant measurement error and you will need to go back and remeasure.
The mathematically inclined will recognize that the above method makes a simplification. The height of the block (along the gantry) will actually not be h, but rather h' in the diagram. The length of the side is h and h' <h. However, if d, the true dual offset value, is small then the computed dual offset value will be very close the true value. For a 100 mm square, 6 mm (about 1/4 inch, relatively large) of offset error results in a 0.2 mm offset error after adjusting. An offset error of 1.6mm (1/16") results in a 0.017mm offset error after adjusting. Repeating the process with either adjustment results in an offset error below 0.001 mm. Well better than the granularity of most machines.
My motion control software doesn't support dual axis offset
If your MCS supports auto-squaring but not dual axis offset, you can still use the computed dual axis offset to adjust your homing sensor target on the primary motor side. Simply measure the original distance of the target from a fixed point and adjust the target to that plus the dual axis offset value. Note that a negative value indicates you subtract it from the original distance.
About Me.
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.