# 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.