Workshop notebook · CNCNovember 2026

Lutherie · milling · machine vision

Finding the point again

A cheap USB endoscope on a hobby CNC, a little linear algebra and an AI collaborator: how I learned to pick up a guitar rosette exactly where I had left it, after losing the coordinates.

The CNC head with spindle, dust shoe and the endoscope mounted beside it, above the spoilboard
The Stepcraft in its enclosure: spindle, dust shoe and, on the orange bracket, the endoscope that serves as the machine’s eye.

The rosette I am building is called Eiffel: forty small arched towers, each a few millimetres wide, engraved into a 1 mm sheet of ebony and later filled with copper powder. The grooves are 0.3 mm wide and 0.8 mm deep. They are cut by a Stepcraft running UCCNC, with cutters that break if you look at them sideways.

At this scale a tenth of a millimetre shows to the naked eye. And a hobby machine loses its reference more often than you would think: a PC crash, an emergency stop, a carriage that drifts while the motors are off. Each time, the work zero has to be found again. This post tells how we managed it, Claude and I. Over these weeks Claude wrote the G-code, read the photos and moved the machine remotely, always with me standing at the machine.

The problemThree offset groups

On 6 November I started a full column of rosette segments, four hours of cutting. At the seventh segment the CNC PC blue-screened because of its Wi-Fi driver. On restart UCCNC reopened with the offsets and coordinates from its last clean shutdown, which were wrong. I restarted from a zero set by eye.

The result: on the same sheet there were three groups of segments, shifted by 3.9 and 11.4 mm from one another. Between two segments the gap had shrunk to 0.68 mm. The border grooves and cut-outs still to come had to follow each group precisely. By eye, that was hopeless.

The eyeAn endoscope next to the spindle

The first camera was a 640×480 USB endoscope, the kind sold for inspecting pipes. It does not speak the standard webcam protocol, so Claude wrote a small program that reads it directly over USB. At first it sat in the collet in place of the cutter. From 16 November it has a fixed bracket next to the spindle, and on 20 November it was replaced by a 1080p endoscope that behaves like an ordinary webcam. I recommend the second kind: any UVC camera works with the scripts below.

The dust shoe with its brush skirt and the vertical endoscope beside it
Dust shoe with the brush skirt fitted. The endoscope stays outside, vertical, clamped to a small block on the spindle mount.

CalibrationFrom pixels to millimetres

A photo alone says nothing. You need to know how many millimetres a pixel is worth, and which way the image moves when the machine moves. The method is simple. Take a photo, move the machine 2 mm in X, take another, then 2 mm in Y and a third. Comparing the three images by phase correlation gives a small 2×2 matrix that turns pixels into machine millimetres, rotation and mirroring included.

With the first endoscope the scale was about 0.036 mm/pixel over a 23 × 17 mm field. The image was rotated by 34° and mirrored, with a 2% scale difference between X and Y. None of that matters once you know it: the matrix absorbs it. With the new endoscope the scale is 0.030 mm/pixel.

A mosaic of many close-up photos showing a row of rosette segments, some filled with copper
A grid of photos stitched into one map using the calibration. It is the first way to find out where things are on the sheet.

MeasuringThe G-code on top of the photo

With a calibrated camera you can do the most useful thing of all: take the toolpath from the .nc file and lay it over a photo of the grooves already cut. If the drawing lands exactly on the grooves, the zero is right. If it is shifted, the shift reads out in millimetres.

On grooves filled with copper the precision was about 0.02 mm in X and 0.1 mm in Y. Empty, dark grooves needed a different detector: with the copper one the measurement went wrong and looked like a rotation.

Six panels, each with the theoretical toolpath of one tower drawn over the photo of the cut groove
Theoretical toolpath over the real grooves, segment by segment. Top row filled with copper, bottom row still empty.

Milestone · 9 NovemberTower N7_5

The first real test. On the evening of 6 November I had left the machine with the camera over the last tower of the new segment, N7_5, at X −7.662 Y 50.159. Three days later the work offset in UCCNC was no longer the same, and the coordinates meant nothing.

Claude searched for the tower by successive approximation: photo, comparison with a reference image (even rotated, with a filter that removes the wood grain), computed move, new photo. Three iterations and the tower was back where the reference had it.

First photo
1 · first photo
Photo after a computed move
2 · computed move
Third photo, aligned with the reference
3 · aligned

Result

N7_5 today: X 18.57 · Y −104.40 (±0.03)
today’s coordinates = 6 Nov coordinates + (26.232 ; −154.559)

Checked on another tower, N7_4, with a 0.06 mm discrepancy. No lost steps, even after hitting a limit switch. From there, border grooves and purfling arcs were cut on all seven segments.

That day also brought an instructive mistake. UCCNC does not execute G10 L20, the standard command to rewrite the work zero from MDI: it ignores the G10 and treats X and Y as a move. A “zero change” became a 155 mm run into the limit switch, twice. Since then I set the zero with UCCNC’s own buttons, and any command never tried before goes through me first.

Milestone · 12 NovemberThe pilot hole

On the evening of the 11th I hit the emergency stop because the motors were humming. The hum was normal, just holding current; without current, though, the steppers do not hold. The next day, while I changed spindle and cutter, the carriage moved without UCCNC knowing. The cut-out of the segments started 24.7 mm to one side.

First we tried to find the spindle axis by rotating the collet and watching through the camera. Three pairs of measurements disagreed by up to a millimetre: useless. Then the idea that became the method: a pilot hole. With a 1 mm cutter I drilled a 1 mm deep hole in the scrap next to segment R1. The hole is where the machine thinks it is. The grooves of R1 are where the machine really was. If both appear in the same photo, the difference between them is the error.

Colour photo: the pilot hole in the scrap and the grooves of segment R1 below
hole and segment in one photo
The same photo in greyscale with the theoretical toolpath of R1 drawn in yellow
R1 toolpath overlaid
Close-up of the pilot hole with the computed centre
hole centre

Result

true position = DRO + (+24.69 ; +0.04) ±0.06 mm

With X and Y rewritten in the DRO, the cut-out with the 1 mm cutter restarted with a 0.15 mm margin, the edge of the cut running down the middle of the border groove. Finished the same day: seven segments cut free, clean.

The methodCamera-to-cutter offset

With the camera fixed beside the spindle you need one more number: how far it sits from the cutter. We measure it the same way, with a hole. The cutter drills a piece of scrap, the camera goes to where the hole should be, the script finds the centre and corrects.

The first time the value was wrong: the camera had centred on a light-coloured hole in the spoilboard that was not the one the cutter had just made. Hence the rule: always verify the offset with a hole drilled by the cutter and photographed afterwards. A ring of black ink around the hole gives excellent contrast, and the centre comes out with a residual of a pixel and a half.

Verification hole on the light spoilboard seen by the camera
17 Nov · verification hole
6 mm hole with a square of black ink around it, seen by the 1080p endoscope
20 Nov · inked hole, 1080p endoscope
DateCameraScaleOffset X ; YNotes
6 Nov640×480 endoscope in the collet0.036 mm/px—image rotated 34°, mirrored
17 Novsame, on a fixed bracket0.143 mm/px+44.87 ; +37.25camera tilted: 0.05 mm per mm of Z
19 Novsame0.10 mm/px+44.63 ; +35.889% distortion at the edges
20 Nov1080p UVC endoscope0.030 mm/px+41.88 ; +31.99 (±0.05)always measured at Z home; Y backlash 0.045

The bracket is plastic and moves a little, so the offset is re-measured at the start of every session until I make an aluminium block. Measurements are always taken at the same height, because the camera is not perfectly vertical, and always approaching from +Y, to avoid paying the axis backlash.

On the soundboardFrom the sheet to the guitar

The same tools were used to mill the rosette channel straight into the soundboard. The centre comes from a 3.2 mm locating pin. The camera measured the direction of the neck from two points on the pencilled centre line; the pencil got lost in the grain and had to be found with perpendicular intensity profiles. With two points the camera offset cancels out. At the end, a ring of photos around the channel to check walls and floor, and two segments dry-fitted: they go in nicely.

Eight photos of the circular rosette channel taken every 45 degrees
The ring of photos around the channel, one every 45°. A dry-fitted segment shows in some of them.

Reproduce itThe scripts and the procedure

Everything is in the repository gionci/cnc-camera: small Python scripts (OpenCV and NumPy, nothing else), with the real photos from these sessions as examples, so you can run each step before touching your machine. Any CNC controller works: the scripts only need photos and coordinates you read off your DRO.

pip install numpy opencv-python cd tools python calibrate.py base.jpg x.jpg y.jpg -o cal.json # 1. pixels to mm python offset.py hole.jpg cal.json XT YT XC YC # 2. camera vs cutter python overlay.py photo.jpg cal.json X Y part.nc # 3. lost zero, from cut grooves python align.py reference.jpg current.jpg cal.json # 4. back to a photographed spot
  1. Mount any UVC camera rigidly next to the spindle, looking straight down. Fix one Z height for all photos.
  2. Calibrate: one photo, move +2 mm in X, photo, move +2 mm in Y, photo.
  3. Drill a small hole in scrap with the cutter, ring it with black ink, photograph it. That gives the camera offset.
  4. Before stopping a job, photograph a distinctive spot and write down its coordinates.
  5. After losing the zero: photograph grooves already cut (or the reference spot) and let the script tell you the correction. Look at the overlay image before trusting the number.

What I learnedWorkshop rules

  1. Write down the zero of every run. Each restart with a new zero creates a shifted group.
  2. After a crash, do not restart by eye: measure the grooves already cut with the camera and derive the zero from them.
  3. Emergency stop or power off between two programs on the same part means X and Y are at risk. Check against a known reference before restarting.
  4. The most reliable reference is a hole drilled by the cutter and photographed together with the work already done.
  5. Never home the machine between two programs on the same part.
  6. Before Cycle Start, look at the preview and the file header: there may be near-identical files with an old zero.
  7. Short files, one part at a time: a crash costs at most one part.

NextTowards a machine that looks for itself

An aluminium block for the camera, so the offset stops drifting. A start-of-session routine that drills the hole, finds it and saves the offset on its own. And the rosette itself is changing: single tiles, one tower per tile, engraved with a V-bit. The camera will measure the real angle of the V-bit before it ever has to find a zero.

Getting back to the exact point after losing it was what scared me most about this machine. Now it is a ten-minute procedure.