Installing LinuxCNC

I think its fair to say there are two big players in the DIY CNC market when it comes to control software Mach3 and LinuxCNC (formerly EMC2). Pretty much the whole time I was designing my machine I was completely sold on the idea of going the Mach3 route but I thought I should at least give LinuxCNC a test drive and so far I have to say I’m pleased with what I’m seeing. I should say that I have had a fair bit of experience with various Linux distributions in the past so that aspect of it wasn’t at all daunting. To be fair though Ubuntu (the version of Linux used in the LinuxCNC distribution) is so easy to use now you’d be hard pushed to point to that as a reason not to use it.

Step 1: Download LinuxCNC

First things first you need to get hold of a copy of LinuxCNC. As with everything to do with Linux there’s a dozen different ways to install LinuxCNC but by far the simplest and most likely to work is to just download the dedicated distribution from the LinuxCNC website as an ISO disk image. This is a complete operating system that you install on a machine and it is optimised for performing CNC work.

Alternative options include installing just the LinuxCNC software on a regular Linux installation (such as Ubuntu) but that is less than ideal as the software won’t then be running on a real time kernel.

Step 2: Prepare the Download

I’m going to assume that you have downloaded the ISO on a modern Windows based machine. If this isn’t the case a similar process is available for other operating systems and instructions can be found here.

In days gone by you would burn an ISO image onto a CD or DVD and then use that to install the operating system onto the target machine. That’s fine and will still work but I have a probem with it: I never seem to be able to find a blank CD when I need one. To solution is to install from a USB stick instead and that is what I’ll describe here. It’s a tiny bit more involved and it requires your target machine to support booting from USB but most modern machines do.

There are numerous pieces of software that will create a bootable USB from an ISO image but the one I have most success with is LinuxLiveUSB (LiLi). Download, install and start “LiLi”. Select the USB drive you want to make bootable in the first box, pick the ISO image you just downloaded in the second box and set persistence to 0MB. Now for an important setting: select “Format the key as FAT32”. This last setting is necessary because many BIOSes will only recognise USB hard drives as boot devices and the default will create a USB stick that looks like a CD, it also avoids the USB stick becoming unrecognisable in Windows.

When all the settings are made click the lightening bolt to begin the writing process, it will take about 10 minutes normally.

Step 3: Install LinuxCNC

This step, by necessity, is a little vague. The problem is that while there are only a few big BIOS manufacturers they use hundreds of different layouts which makes instructions very difficult to write. The basic steps should be the same for all systems though.

Plug in your USB stick and power on the machine. At the first screen you should see something like “Press Del to enter setup” Del could be F1 or Esc or some other key. Press the key given to enter BIOS setup mode. Be careful in the BIOS settings you can render your computer unable to boot – please don’t be scared off though, with a dose of common sense and not touching things you don’t understand it’s easy enough. Somewhere, probably under advanced settings, there will be a list of devices you computer will use to boot your machine. At the top of the list will probably be the primary hard disk. You need to move that down the list one place and put USB-HDD or similar at the top. Once you have completed this save your BIOS settings (often F10) and reboot your machine. If all has gone according to plan you should find your machine boots from the USB stick.

Don’t worry if you don’t get it first time, I often end up having two or three stabs as getting a machine to boot from USB. Check for additional screens that define boot order (that had me going on my LinuxCNC machine for a while). Assuming you get your machine to boot from the USB stick you are pretty much home and dry as far as the installation is concerned. The machine will boot into a live version of the LinuxCNC distribution and there will be a file on the desktop that you simply double click to install the OS onto the hard drive. This is the standard Ubuntu install procedure and very user friendly.

Step 4: Test and Tweak

Boot the machine and log in. You should be presented with a blank desktop with a menu across the top. Under applications you’ll find a CNC sub-menu that contains the LinuxCNC short-cuts. Initially you want to run the Latency Test application to test the machine and discover if it will be any good for use as a CNC control box. Essentially what this test is doing is asking the computer to generate a pulse every millisecond and measuring when it actually happened, the difference is called jitter and jitter gets worse as latency gets worse. For the test to be valid you have to make your computer work as hard as it can and the easiest way to do that is run the system tests which can be found under System > Administration > System Testing. Run all the tests and find out what the latency test application reports.

For example my first run of the latency test gave the following results:

Test Max Time (ns)  Max Jitter (ns) 
Servo (1ms) 1046571 50091
Base (25us) 64521 39609

Nearly all the jitter appeared when I tried to play sound in one of the system tests, prior to that point I my system had been firmly around the 5000ms mark for 15 minutes. A jitter of 50,000ns is usable (just) but it will limit the maximum step speed that can be achieved without problems such as missed steps so it’s well worth doing some digging to see if there is anything that can be done to improve this.

In my case I think I got very lucky in that I spotted that the jitter jumped up when I played some sound, since I don’t care about sound on this machine the obvious first thing to try is turning off the sound. The motherboard in this machine has a built in sound card and my guess was that the hardware for this is probably about as cheap and nasty as it gets. I entered the bios, found the audio setting (AC97) and set it to disabled. I then rebooted the machine and re-ran the latency test. I ran three instances of glxgears to really pound the CPU and some heavy disk access for good measure, my maximum jitter dropped to just 9444ns on the servo thread.

I noticed that the maximum jitter jumped up when I started glxgears running for the first time (from about 4500 to the 9500 I finished with). Since this was a fresh install of Ubuntu it wasn’t running the latest packages or the nVidia graphics driver. The next step was, therefore, to do a package update and install the recommended nVidia binary only driver. Package updates are done through System > Administration > Update Manager although the system will typically nag you to do them. Hardware drivers are best installed through System > Administration > Hardware Drivers.

My experience is that you should not install the nVidia binary drivers. While the animation was much smoother (better frame rate) once glxgears was up and running starting the demo caused a 250,000ns spike in the max jitter which renders the machine completely unusable as a control box. Quite why this is I don’t know but I could hazard a guess. Unlike other most other drivers graphics drivers run with special low level access to the kernel. My guess is that this low level access allows the drivers to briefly hog the CPU to achieve better performance. This makes some sense because if you are looking for optimal frame rates for gaming you don’t really care if your spreadsheet in the background takes a few milliseconds longer to complete – for CNC though this is a disaster so it’s better to stay away from the binary drivers.

Note: your system will probably offer to upgrade your LinuxCNC install to Ubuntu 12.04 though the package updater DO NOT take it up on this offer! If you perform a full system upgrade LinuxCNC will stop working and you’ll need to perform a re-install. In the fullness of time I’m sure the LinuxCNC developers will put together an ISO built around 12.04 but until that time stick with 10.04 – it’s not like you’ll be getting anything new by upgrading to 12.04 because the machine will only be running LinuxCNC.

After installing all the latest packages and switching off on-board sound I re-ran the latency test under very heavy load (three instances of glxgears, firefox, chromium, package installs, heavy disk access, etc) for at least an hour. the results were:

Test Max Time (ns)  Max Jitter (ns) 
Servo (1ms) 1003322 7654
Base (25us) 35141 10419

I’m a little disappointed by the base threads maximum jitter but it’s still well below the 15000ns target necessary for good performance. Reading the documentation on how the test works a repeatability to within 1000ns should be expected so even if I assume my recorded jitter to be unusually good for my machine and add 2000ns I’m still doing well.

I had to replace the BIOS battery as the machine I’m using had been switched off for so long. I decided to run the latency test a second time (under the same conditions) to double check the result and make sure I’d correctly set up the BIOS. second run gave:

Test Max Time (ns)  Max Jitter (ns) 
Servo (1ms) 1003299 6819
Base (25us) 33817 9159

As the instructions for the latency test application state the measurement is very accurate but the repeatability can be less than brilliant. Values within about 1000ns of each other are about as good as can be expected.