Update: see this later post before following the instructions below.
I don’t care for most of the DXF editors available. They seem a bit clunky and not too friendly. But I do like Inkscape. Unfortunately it doesn’t export DXF files.
Here is a way of getting Inkscape 0.46 to export DXF files which can then be processed in a CAM program to generate g-code for a CNC machine.
Firstly install Inkscape 0.46. It must be this version.
Next go to this post on BobandEileen.com, right click on the link to “dxf_templates.py” and save it in C:\Program Files\Inkscape\share\extensions.
Next step is to go to another post on BobandEileen.com, right click on the two .py files (“simpletransform.py” and “better_dxf_outlines.py”) and save in the same place. Then do the same for “better_dxf_outlines.inx”.
Create a drawing and then move it to the bottom left corner of the page. This corner ends up being the origin. If you want your drawing centered on the origin then center it on the corner of the page.
Go to File -> Save As…
From the list of file types in the save dialog window choose “Better DXF Output (*.dxf)” and save the file.
Now open the DXF file in your favourite CAM program, such as CamBam.
Note that you may need to scale the drawing in your CAM program. Even though I had my drawings correctly sized in Inkscape, they seemed to be quite a bit bigger. If anyone knows how to solve that please post a comment.
The next step in testing the CNC machine is to try cutting a hole. For this I needed thinner wood than the scrap pine I’ve been using. Home Depot sells small boards of oak and poplar so I picked up a piece of poplar. It’s 1/4″ thick.
I also needed to raise the sacrificial platform so the tip of the end mill can reach the bottom of the wood. To do that I just cut some more 16″ x 9″ pieces of 1/4″ MDF and stacked them (see the post on fixtures for more information and pictures on what I am talking about).
I used CamBam to draw a 0.5″ x 0.5″ square and then created a profile on the inside using my 1.45mm (0.0571″) end mill. CamBam showed me that I would have slightly rounded corners, but that’s ok. I decided to cut the profile in passes, increasing the depth by 0.05″ each time. This results in five passes to get to the bottom of the wood. Tedious, but better than stressing the end mill and Dremel.
I was afraid that the tip of the end mill might bind in the sticky double-sided carpet tape so I held on to the poplar with one hand and kept my finger on the power button with the other hand just in case. I was also afraid that the cube being cut might fly out as it came free.
It turned out pretty good. No sticky residue on the end mill and no gouging of the sacrifical platform. The cube in the center held in place during cutting and while I lifted the poplar. It came out when I removed the carpet tape.
The cut is nice and clean with no burrs. I guess the carpet tape is a good method to continue using.
Today I took my first steps cutting some scrap pine. I started off with a 2″ diameter circle then measured it. This is an acid test to check the CNC machine for accuracy and squareness. I used a 1.45mm four flute carbide end mill, 10″ per minute speed and cutting to 0.05″ deep.
Next I used CamBam to cut my wife’s name. That also went well, however even with the text 1.5″ high I was running into a limitation of the end mill. A small mill would have improved the detail.
Then I downloaded a DXF file of a horse and tried cutting that. Came out very nicely. The thin strip of wood left between the body and mane is thin enough to see light through it.
Here is a video shows the horse being made.
For all these I used the same end mill and cutting depth as I did for the circle.
This article describes how I measured the backlash on my CNC machine and then applied software compensation.
To measure backlash I used a Mitutoyo dial indicator with 0.0001″ markings and a full scale of 0.01″. The dial indicator was attached to an adjustable stand so the plunger could be placed against various surfaces on the machine. The stand had a heavy base to ensure the dial indicator and stand didn’t move when pressure was applied to the plunger.
The picture below shows the set up ready to measure the backlash of the X axis.
Here is the method I used:
- Position the plunger on the dial indicator a short distance from a surface that moves in the direction of the axis being measured. The plunger should be perpendicular to the surface.
- Jog 0.001″ along the axis being measured into the plunger, until the needle moves at least 0.001″.
- Note the value shown on the dial indicator. We’ll call this ‘S’ for start.
- Jog the axis 0.001″ seven times into the plunger. Each jog will cause the needle to move. Be careful not to cause the needle to move to the maximum position.
- Jog the axis 0.001″ seven times away from the plunger. The first one, two or three jogs may not cause the needle to move. This is the slack being taken up and hence the backlash.
- Note the value shown on the dial indicator. We’ll call this ‘F’ for finish.
- Calculate the difference between the finish value and the start value (F -S). This is the amount of backlash.
- Jog the axis away from the plunger
- Repeat two more times then work out the average value.
The next picture shows the position of the dial indicator used to measure the Y axis.
The last picture shows the position of the dial indicator used to measure the Z axis.
For my machine I measured the backlash as (averages):
- X = 0.00538″
- Y = 0.00250″
- Z = 0.00030″
EMC2 provides software compensation for backlash. This isn’t as good as using anti-backlash nuts, but I was curious to see how well it would perform. One thing to keep in mind is that over time wear will cause the backlash to change. To configure EMC2 simply add the backlash values to the axis sections of the INI file. Nice and simple. For example:
I then remeasured the backlash and obtained the following values (averages):
- X = 0.00073″
- Y = 0.00010″
- Z = 0.00013″
The Y axis saw the greatest improvement (96%) followed by the X axis (86%) and the Z axis (56%). I think this is pretty good.
There are many ways to configure EMC2, suiting many different uses. But perhaps the most common is control of three stepper motors. This post describes the process I went through to configure EMC2 for my CNC machine, which is a Fireball CNC V90. These steps may not match exactly your needs, but perhaps it will help as a starting point for further exploration.
It assumed that you have managed to get EMC2 installed and have run the latency tests with no overruns. If you are seeing overruns then try the hints on the EMC2 Troubleshooting page.
When you see ‘$’ in this post, it represents the user prompt. Don’t type it, only type the commands that follow. Replace “andy” with your own user name.
First we need to know how many steps per second your PC can generate. To do that we run the kernel latency test:
$ cd /usr/realtime*/testsuite/kern/latency
$ sudo ./run
The test will output a set of numbers. Use the PC to browse the web, play music and check email for a few minutes. However don’t run EMC2. Stop the test and note the largest value in the “ovl max” column. In my case it was 92,191. Values over 100,000 may not give good performance. In general the larger the value the worst CNC performance will be. There are some hints in the EMC2 wiki on how to lower this value.
92,191 means 92.191us (us = microseconds). Between the PC at the stepper motor is a driver chip, such as the SLA7078MR. This chip has some delays that are required for each edge. By reading the datasheet for the driver chip we can find out what this is, and for the SLA7078MR it is 12us. If you don’t know or not sure, I would suggest you pick a value similar to this and err on the side of caution by making the value a bit larger.
So we have 93us (rounded up) + 12us = 105us = 105,000ns (ns = nanoseconds). This is the BASE_PERIOD (more on that in a bit).
Therefore the maximum step rate for my PC is 1 / (105us x 2) = 4,762 steps per second.
It’s possible to tweak the steplen, stepspace, dirsetup and dirhold values to achieve better results than this, but that topic is outside the scope of this post. See the EMC2 documentation for details.
We next need to calculate how many steps are needed to move one inch with 1/4 microstepping. If you wish to use a different microstepping configuration or millimeters then adjust the following calculations accordingly.
My stepper motors require 200 pulses per revolution. This is a very common amount. With 1/4 microstepping it will take 200 x 4 = 800 steps per revolution.
On the X and Y axis of my machine the lead screw has 10 turns per inch but it is has two starts, which makes it 5 turns per inch. This is a pitch of 1 / 5 = 0.2 inches.
Therefore 0.20in / 800 steps per rev = 0.00025in per step.
Therefore 1 / 0.00025in = 4000 steps per inch. 4000 becomes the INPUT_SCALE value for X and Y.
The maximum speed is 4762 steps per second / 4000 = 1.1905in per second = 71.43in per minute. 1.1905 is the MAX_VELOCITY for X and Y.
On the Z axis of my machine the lead screw has 12 turns per inch. This is a pitch of 0.0833in.
Therefore 0.0833in / 800 steps per rev = 0.000104166in per step.
Therefore 1 / 0.000104166in = 9600 steps per inch. 9600 becomes the INPUT_SCALE value for Z.
The maximum speed is 4762 steps per second / 9600 = 0.4960416667in per second = 29.7625in per minute. 0.4960416667 is the MAX_VELOCITY for Z.
We now have all the information needed to complete the configuration of EMC2. First we must copy the example configuration files and then customize them.
$ mkdir /home/andy/emc2/
$ cp /etc/emc2/sample-configs/stepper /home/andy/emc2/
$ sudo chown andy:andy /home/andy/emc2/*
Rename all values to remove “dpkg-new” from the end of the file names. Then:
$ cd /home/andy/emc2
$ mv stepper_inch.ini mymachine_inch.ini
$ nano -w mymachine_inch.ini
Scroll down to the BASE_PERIOD line and set it to the value calculated in nanoseconds. In my case it is 105000.
Scroll down to the trajectory planner and set the MAX_VELOCITY value to the largest MAX_VELOCITY value of all the axis. In my example it is 1.1905.
Scroll down to the section that configures the first axis (X) and set the INPUT_SCALE to the value calculated. In my example it is 4000. Set the MAX_VELOCITY and STEPGEN_MAXVEL to the MAX_VELOCITY value for the axis. In this example it is 1.1905.
Repeat for the Y and then Z axis.
The final step is to edit standard_pinout.hal to match the pinout of your controller board. The important section in the file looks something like:
linksp Xstep => parport.0.pin-03-out
linksp Xdir => parport.0.pin-02-out
linksp Ystep => parport.0.pin-05-out
linksp Ydir => parport.0.pin-04-out
linksp Zstep => parport.0.pin-07-out
linksp Zdir => parport.0.pin-06-out
Simply change the “03”, “02”, etc. values to match the pin numbers used by your board. “Xstep” means the step input for the X axis.
Now run EMC2 using:
$ emc /home/andy/emc2/mymachine_inch.ini
Set the jog rate to the maximum for each axis in turn and jog the axis. It is possible that the axis may stall or lose steps. This is because the value we calculated is a theoretical maximum. However it gives you a starting point to reduce the speed of the axis until it works reliably. To do this lower the jog speed slightly until it works then using the INPUT_SCALE work out a new value for the number of steps per axis. For example, assuming we had to lower the jog speed to 60.000 in per minute on the X axis:
60.000 in per minute / 60 = 1.000 in per second. 1.000 in per second x 4000 steps per inch (INPUT_SCALE) = 4000 steps per second
Now a new value for BASE_PERIOD can be calculated:
1 / 4000 steps per inch / 2 = 125,000ns
Edit mymachine_inch.ini and set the new BASE_PERIOD value. Note that this will lower the speed of all axis. Recalculate the MAX_VELOCITY value for all axis and update the configuration file with the new values. Then retest.
I found that on my PC it can operate at the theoretical maximum speed without problems. I hope this helps you configure EMC2 for your machine.
I wanted an easy way to resize images for email after importing them from a digital camera when using Gnome. Gnome by default uses gThumb for the import and it seems like an easy to use program. The problem is that in order to resize images several mouse clicks are needed, followed by a file rename.
So I wrote this quick little script to perform the resizing for me. Note that it only works with one picture at a time. To install copy to somewhere like /usr/share/scripts and make sure it is executable by everyone (
sudo chmod 755 /usr/share/scripts/resizeimage). Then in gThumb go to the preferences and click on the Hotkeys tab. Add the following to one of the hotkeys (I used zero):
/usr/share/scripts/resizeimage %f %n %e
Then in gThumb select an image and press the hotkey (on the numeric keypad). The image will be resized and renamed in one step.
The script is written to resize the image so the longest side is 800 pixels, while maintaining the aspect ratio. You need to have ImageMagick installed. If the original image is called foo.jpg, then the resized image will be called foo.resized.jpg, just like the Nautilus Image Converter does.
# resizes an image for email, preserving aspect ratio
# requires imagemagik
# call: resizeimage /home/andy/foo.jpg /home/andy/foo .jpg
# in gthumb: resizeimage %f %n %e
convert "$1" -resize "800x800>" "$2.resized$3"
After spending quite some time trying different pieces of software I have come up with a collection and a workflow that I think will fit my needs.
I wanted to be able to accurately design parts in 3D, see how the parts will fit together to make sure they are right, and produce traditional engineering drawings of the parts, if possible. Also it is necessary once a part has been designed to be able to convert it into toolpaths, which is the path that a drill bit would move along to make the part. The toolpaths are represented using g-code which can be processed by EMC2 to move the stepper motors. Another requirement was to use free software where possible to try and keep costs down.
I start with Alibre Design Xpress. This is an excellent 3D design program that is also free. However free comes with a price, that is limitations. The key limitations are a limited number of export options and limited number of parts in an assembly. An assembly is a collection of parts fitted together to build something. However with enough perseverance these limitations can be overcome. In Design Xpress I created a simple test part that contains two holes for bolts:
Creating this 2D profile is very quick and easy. The holes are 0.174″ in diameter, which should be big enough for a #8 bolt. Next step is to extrude the 2D profile into a 3D part:
The part can be rotated and viewed from any angle. I decided to make the part 0.250″ thick. At this point Design Xpress can produce various numbers regarding the part, depending on the material it is made of. Choosing “Wood – southern pine” resulted in:
Volume = 1.480147117 in³
Mass = 1.576592260E-2 kg
Surface Area = 1.453202145E1 in²
The software only allows five unique parts in an assembly, unless you register then it is 10. However this is quite a severe limitation in my opinion. Fortunately there is a way around this. Alibre has written an add-on called 3D Publisher for Google Sketchup that allows parts to be exported in Google’s Sketchup format. It’s not a requirement that the parts be uploaded to Google’s 3D Warehouse. Instead the exported parts can be saved to your hard drive. The following screenshot shows an assembly of two of the test parts along with size #8 bolts and nuts. The exact bolts are ANSI PHN, CRSHD TYPE II, B18.6.3, .164-36 UNF, 0.75, which gives an indication of the accuracy expected from designing parts and assembling them.
Again, this assembly can be rotated and the parts can be made transparent, along with plenty of other options. There is even a free add-on for Google Sketchup that provides a ray tracer. Assembling two parts confirmed my intention that the holes will line up.
With a few mouse clicks Design Xpress can convert the 3D part into traditional engineering drawing:
This can be printed out, emailed, etc. and provides all the measurement details for someone else to reproduce the part without having access to electronic files. The drawing can also be exported as a DXF (without the annotations), which is needed for the next step.
I found an excellent application to generate toolpaths for a part called CamBam. It takes a DXF file and provides an easy to use user interface in which you can select which items are profiled, drilled, pocketed, etc. Once the DXF file is loaded into CamBam all the unneeded views are deleted to leave the original 2D profile. For this part I added a 2.5D profile operation to cut the outline of the shape and two sprial drill operations for the holes:
Cam Bam then generates the g-code which can be loaded in the AXIS interface in EMC2:
This process may seem convoluted, and it requires both Windows and Linux, but all the software can be obtained for free and is high quality. I haven’t completed my CNC machine yet, but I can watch the part being made in the AXIS interface without having the motors connected. I would expect that all the software will work in a Virtual Machine in Linux, however note that Design Xpress requires a lot of RAM to run (300Mb I believe).
April 2008 – Update – I’ve modified the instructions so that EMC2 can now be run as a user.
April 2008 – Update – Fixed some mistakes.
The following instructions will describe how to install the latest version of EMC2/LinuxCNC in Ubuntu 7.10 Gutsy Gibbon.
Why would you want to do this? You would do this if you don’t want to wait for new .deb files from the EMC2 team or you want to install EMC2 in the latest version of Ubuntu to take advantage of all the new features. The alternative is to use the Ubuntu 6.06 LTS live CD, install and then either stick with the software versions supplied or upgrade to the latest versions (such as device drivers, Gnome, Xorg, etc.), which is a big task itself.
Why would you not want to do this? I don’t recommend following these steps if you are unfamiliar with Linux and the shell/command prompt. It will either be a great learning experience or a very frustrating waste of time.
I am sure these steps can be simplified and improved, however they were created from many hours of experimenting and following dead-ends. I wanted to try and give you exactly what I ended up using, rather than an optimization. For example I’m sure that not all the reboots are needed, but they only take 60 seconds on my PC anyway.
These steps should work on a stock installation of Ubuntu 7.10, however I don’t make any claims that they will work for anyone else. If the software didn’t install correctly and the motors go crazy and move something that destroys your house, don’t blame me – these instructions are provided “as is” and without any warranty. Use at your own risk. If you spot a mistake please let me know and I will update the instructions.
Where you see “andy” replace with your own username, unless it is also “andy”.
‘$’ represents the prompt, to show you where the start of lines are. Don’t enter this, just what follows.
The process looks like this:
Get a vanilla kernel and patch it with RTAI support.
Build and test RTAI modules.
Enable universe repository in /etc/apt/sources.list. Open a terminal window and then:
$ sudo apt-get update
$ sudo apt-get install build-essential libncurses5-dev kernel-package
$ cd /usr/src
$ sudo wget -c http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.22.tar.gz
$ sudo tar xzvf linux-2.6.22.tar.gz
$ sudo mv linux-2.6.22 linux-vanilla-2.6.22
$ sudo ln -s linux-vanilla-2.6.22 linux
$ cd linux
$ sudo cp /boot/config-2.6.22-14-generic .config
$ sudo make menuconfig
At this point a menu will appear. Make the following choices:
Loadable module support > Module versioning support (N)
Loadable module support > Set version information on all module symbols (N)*
Processor type and features > Preemption model > Preemptible kernel (low latency desktop)
Processor type and features > Symmetric multi-processor support (N)**
Processor type and features > Local APIC support on uniprocessors (N)
Power management options (ACPI, APM) > ACPI support (N)
Power management options (ACPI, APM) > APM BIOS support (N)
Power management options (ACPI, APM) > CPU frequency scaling (N)
Kernel hacking > Compile the kernel with frame pointers (N)
* only if you have it in the menu
** only if your PC is not dual or quad core
Download rtai-3.6-test1.tar.bz2 from www.rtai.org (click on “RTAI Repository” link) to the desktop.
$ cd /home/andy/Desktop
$ bunzip2 rtai-3.6-test1.tar.bz2
$ tar xvf rtai-3.6-test1.tar
$ cd /usr/src/linux
$ sudo patch -p1 < /home/andy/Desktop/rtai-3.6-test1/base/arch/i386/patches/hal-linux-2.6.22-i386-1.10-09.patch
$ sudo make-kpkg --initrd --revision=1 --append-to-version=-realtime kernel_image kernel_headers
Some questions may appear which need to be answered (answer Y to any others that appear):
Interrupt pipeline – Y
Interrupt pipeline maintain backwards compatibility – Y
Interrupt pipeline debug – N
Now go and do something else for a while. On my P4 1.6GHz PC the kernel took 2 hours and 50 minutes to build.
$ cd ..
$ sudo dpkg -i linux-image-2.6.22-realtime_1_i386.deb
$ sudo nano -w /boot/grub/menu.lst
Find the line that looks like:
and change it to:
If your PC already dual-boots (for example Ubuntu and Windows) then the hiddemenu is probably already commented out (using the ‘#’).
Save and exit nano.
Reboot and choose the realtime kernel from Grub menu.
$ uname -a
and you should get something like:
Linux pepper 2.6.22-realtime #1 PREEMPT Sun Oct 28 10:54:43 MST 2007 i686 GNU/Linux
Make sure everything works ok (browsing, editing files, etc.)
Now we need to build the RTAI modules. This has to be done while running the realtime kernel we just built and booted into.
$ cd /home/andy/Desktop/rtai-3.6-test1
$ make menuconfig
Again a menu appears. Make the following selections:
Machine (x86) > Number of CPUs (enter the number you have here)
Exit and save configuration
$ sudo make install
Reboot back into the realtime kernel.
$ cd /usr/realtime/bin
$ sudo nano -w rtai-load
Change the first line from:
and save. Then:
$ sudo nano -w /etc/init.d/create-rtai-devices.sh
mknod -m 666 /dev/rtai_shm c 10 254
for n in `seq 0 9`
mknod -m 666 $f c 150 $n
$ sudo chmod 755 /etc/init.d/create-rtai-devices.sh
$ sudo update-rc.d create-rtai-devices.sh defaults
Reboot back into the realtime kernel.
Then test the RTAI support with:
$ cd /usr/realtime/testsuite/user/latency
$ sudo ./run
$ cd /usr/realtime/testsuite/user/preempt
$ sudo ./run
$ cd /usr/realtime/testsuite/user/switches
$ sudo ./run
$ cd /usr/realtime/testsuite/kern/latency
$ sudo ./run
$ cd /usr/realtime/testsuite/kern/preempt
$ sudo ./run
$ cd /usr/realtime/testsuite/kern/switches
$ sudo ./run
These tests spit out lots of numbers. The thing we are looking for here are kernel panics, system crashes, etc. Also make sure there are no overruns in the tests that display an overruns column.
If you get something like:
insmod: error inserting '/usr/realtime/modules/rtai_hal.ko': -1
Operation not permitted
$ sudo nano -w /boot/grub/menu.lst
and find the kernel line for the realtime kernel. Add “lapic” to the end of it and reboot, then run the tests again. For example:
kernel /boot/vmlinuz-2.6.22-realtime root=UUID=45d21232-cf0d-cc3d-87ce-8453214d7a6f ro quiet splash vga=794 lapic
Once you have the real time tests working continue with:
$ sudo nano -w /etc/modprobe.d/emc2
install parport_pc /bin/true
Save then reboot back into the realtime kernel. Now to build and install EMC2.
$ sudo apt-get install python python-imaging python-imaging-tk python-numarray python-dev
$ sudo apt-get install tcl8.4-dev tk8.4-dev yapps2
$ sudo apt-get install libgtk2.0-dev libpth-dev libreadline5-dev libxmu-dev libxaw7-dev libglu1-mesa libglu1-mesa-dev libgl1-mesa-dev
$ sudo apt-get install pciutils-dev bwidget cvs latex2html preview-latex-style libaiksaurus-1.2-0c2a libgnomeprintui2.2-dev
$ sudo apt-get install imagemagick lyx
$ cd /usr/src
$ sudo dpkg -i linux-headers-2.6.22-realtime_1_i386.deb
$ cd ~
$ cvs -z5 -d:ext:email@example.com:/cvs co emc2
$ cd emc2/src
$ ./configure --with-realtime=/usr/realtime --with-kernel-headers=/usr/src/linux-headers-2.6.22-realtime
$ sudo make install
$ sudo nano -w /etc/security/limits.conf
Add the line:
* hard memlock 20480
Save and reboot into the realtime kernel.
To run EMC:
A window should appear with a choice of configurations. Choose Axis -> Sim and the Axis window should open. Congratulations EMC2 is now running!
Note that when running the realtime kernel the computer may not power itself off when the shutdown option is chosen. This is because the power management options have been disabled in the kernel. On my PC I wait a couple of minutes after the screen goes blank then press the power button on the front of the PC. This turns it off.
I just completed the first test of running EMC2/LinuxCNC on Ubuntu with the HobbyCNC board. I connected a motor to the X-axis and started EMC2 with the “Axis” interface. I then told it to execute the default G-code file it loads with. Lo and behold the motor started spinning! I then moved the motor to the Y and Z axis and repeated. Seems to work well.
I didn’t notice any stalling so the problems I experienced with Windows XP and Mach3 must be due to Windows XP…
Here is a video:
Details on how to install EMC2 from source along with RTAI will follow when I have them ready. Also I will post the configuration files for the HobbyCNC board a bit further on in the project when I have more confidence that they are correct.
I am still working on getting EMC2 working in Ubuntu 7.10, but in the meantime I decided to give Virtual Box a try. The Virtual Box website has deb files for Ubuntu so installation was easy. I created a new virtual machine with 192MB of RAM and 6Gb of drive space and stuck the XP SP2 CD in the drive and started the machine. From that point the XP installer went through it’s machinations until I had the desktop running.
I am pretty impressed. The speed of XP is almost as fast as if it were running on it’s own. It’s perfectly usable, has network access and can resize the desktop to match the window on the fly. It automatically captures the mouse pointer when it goes over the window, and it is possible to take snapshots of the PC and restore them. In other words, no waiting for XP to boot up; just go straight to the desktop.