SpindleView CNC Camera Software

Spindle Cameras Part III

Mark Zachmann
Home Wireless
4 min readApr 1, 2022

--

So, after showing how to make a sealed Wi-Fi spindle camera (part I), and describing why you want one (part II), this is all about the software.

The source for SpindleView is now available on Github.

SpindleView screen capture

Background

The original version of SpindleView was written 10 years ago. It used Microsoft C# and .NET and took 35,000 lines of code, using DirectX to read the video stream and OpenCV to image process. It included a fair amount of AI image processing to set focus, determine camera center, and determine positioning errors by auto-reading a ruler.

That was great, but for the next version I wanted a browser-based application that would work on anything and just needed a streaming image source, rather than a known USB camera. That’s SpindleView.

For V1 this is the bare-bones requirement to be extremely useful. It does no AI stuff to help characterize the hardware and doesn’t do things like measure hole size. That’ll be V2.

Summarize what it does

The system is a >1000dpi down-pointing camera with the ability to a) read the location of a visible feature (such as an edge of stock or the center of a hole) to high precision and b) position the spindle at any pixel on the display.

It works perfectly with (or without) a bit in the collet.

The camera offset restricts the visible range of the system so usually it is mounted as close as possible to the spindle. In the large CNC it is 2" forward. In the micro-mill it is 2 inches to the right of the spindle.

The software works with any mjpg streaming source such as the TinyCam. A very simple application if you have the camera connected via USB is cam2web for PC/Windows. For now it only supports the Duet3d RepRap because it has a REST Api for GCode.

How to Run It

SpindleView is written in TypeScript (which compiles to JavaScript) using Angular. It runs in a browser but prefers a minimal local web server to host the code. Here’s one way to provide the web server->

Installation

  1. Place all of the SpindleView release files in any folder (there are about 7; some have long strange names). I randomly use C:\SpindleView in Windows.
  2. Find Npm (node.js installer) at Download | Node.js (nodejs.org) and install it.
  3. Install the node.js application http-server in the global namespace (so it is in the path and can just be invoked). Type in a command prompt:

Execution

Run a command prompt and then type http-server in the SpindleView folder.

This simple web server serves up the SpindleView JavaScript files. All browser security applies so it can’t, for example, read or write a local file without explicit by-file approval.

Then run any browser and browse to: http://localhost:8080 (the default http-server port). You can use http-server -p80 to use port 80 if it isn’t in use (in Linux these require ‘sudo’).

Running SpindleView via http-server

Once the application is visible click the Settings button and set the URLs for the image stream and the command stream as well as the focus point and resolution.

Camera Software

If you built a camera using a Raspberry Pi then it already streams. If you have a local USB camera then the simplest streamer I’ve found is Cam2Web. It simply streams the USB mjpeg data to a local IP address (localhost:8000 or so).

Unfortunately all of the binary links are broken for Cam2Web. Since the binary is hard to find, here’s the Windows binary.

Demonstration

The below video is moderately watchable and entirely at x1 (normal) speed. It begins with a split screen of an in-room video stream of the CNC on the let side and the RepRap GUI on the right to show the head moving left/right. Then it starts up spindle view (here called tinycam gui) on the right and finally full-screen.

A demo of SpindleView

Options

SpindleView today has three primary sets of options.

  • Reticles — this is an overlay on the image with a target and a ruler of some sort.
  • Zoom — zoom in or out on the image
  • Measurement mode, such Machine or Workspace or Distance.

Actions

  • Move the head to center the camera on the clicked spot.
  • Center the spindle at the camera center spot, as if to drill there.
  • Based on the height of stock move the camera for best focus and distance measurements highest accuracy.

It also shows the CNC location of spots underneath the mouse.
Note: the camera must be fixed focus for precise measurement.

--

--

Mark Zachmann
Home Wireless

Entrepreneur, software architect, electrical engineer. Ex-academic.