How to take an image like this:
and in one step generate the gcodes required to do this:
All credit for cad.py goes to the original creator Neil Gershenfeld of MIT Center for Bits and Atoms and David Carr of Make Your Bot who optimised the code that is in use here.
By attaching a pen to a 3D printer it is easy to turn it into a basic pen plotter. However producing the G-codes require to drive your 3D printer as a pen plotter can be anything but easy. This short guide seeks to change that. There are currently a number of ways of producing plotting paths from images. A selection includes:
- The five step Unicorn Tutorial
- The Scribbles Method
- Using the Reprap host software
- Using cad.py (A python script with GUI)
Download the following software for your respective OS. Note that python 2.6 must be used for cad.py to work. Either un-install newer versions or dirct cad.py to work with python2.6 only.
- 1. python-2.6.5.msi (Python 2.6 Website)
- 2. numpy-1.6.1-win32-superpack-python2.6.exe (Numerical Python)
- 3. PIL-1.1.7.win32-py2.6.exe (Python Imaging Library)
- 4. scipy-0.10.1-win32-superpack-python2.6.exe (Scientific Library for Python)
- 5. Cad.py and some test images (SourcForge)
Generating the gcodes.
Run the Cad.py that suits your hardware. I have included three types all with the same interface but each outputs slightly different gcodes.
- (Cad.py) Plotting with Z axis movement.py -> For use with a three axis Cartesian bot such as a reprap, Makerbot etc. where the pen is lifted off the page due to the movement of the Z (vertical) axis.
- (Cad.py) Plotting with solenoid or laser.py ->For use with a 2 axis bot where the pen is lifted of the page by an action such as a solenoid or a cutting action like a laser is required. (Use fan port for solenoid as it is switched on off with gcode M106 and M107. Commands need to be switched for use with a laser, see “Optimisation” below.)
- (Cad.py) Plotting with Makerbot Unicorn.py -> For use with Makerbot Unicorn system which uses a servo to lift the pen off the page.
When the program begins do the following to test your setup:
- Select the test image.png file by clicking the “Input File” button and navigating to the “Test Images” folder.
- Set “in. per unit”: 25.4
- Click “Cam” button
- Click “Output Format” and select file type: “.gcodes”
- Set the following values:
- maximum vector: 0.75
- tool diameter: 0.03
- tool overlap: 0.1
- contours: 1
- Click “contour” and wait for the paths to be generated. They appear as red lines over the image at its edges.
- Click the save butting and the file will be output to the input directory.
Thats it, your done. Now load up your desired host, run the gcode and watch your bot draw. Here is a timelaps of my plotter at work.
Now that you hopefully have the basics out of the way you may want to know a little more detail. It appears that cad.py takes a black and white image, performs edge detection on the black areas and then calculates tool paths based on that. When choosing your image I recommend you keep its size under 1000pixels or else the rendering time will be come very long (hours+). For best effect use images with clear distinctions between white and black. Although other image formats such as .jpg do work they dont appear to give the same results as png images. Therefore I recommend you convert .jpg to .png and make sure the image is in black and white with high saturation using your desired image software such as irfanview. When the plotting is started the image will be plotted in the positive dictions from where ever the pen is when printing begins. Therefore you can print many images on the same page by moving the pen to a new position between prints.
Furthermore you can copy and past past multiple gcode files into one as long as you add the new starting position at the end of each file. As mentioned above you have a number of variables to play with in Cad.py. To the best of my knowledge this is their functions:
- Window sizes – Changes the size of the display window of cad.py. A larger window can make it easier to see when you have the settings right.
- X Width and Y Width - The size of the image when printed. Roughly equates to the size of the image printed in cm when a .png file is used. Best to do a ‘dry run’ with out a pen first to check the size of your image then adjust accordingly.
- Zmin and Zmax – The distance the pen is lifted using the z axis (Works for (Cad.py) Plotting with Z axis movement.py only)
- Intensity min/max – Change these to change the level of darkness that cad.py interpreted as an edge in an image. Often a low “Intensity Max” value will help the edge detection pickup less distinct areas.
- Inches per unit – At 24.5 roughly 1cmx1cm image should plot an 1cmx1cm image. Change the value to change the size of your image.
- Maximum vector fit error – How closely the edge detection fits to the image. Very small values (eg <0.2) take longer to process and can lead to jagged edges. Very high values (eg >1) can lead to corner cutting.
- Tool Diameter – The most important parameter. The size of the pen end. Lower values mean more detail but longer processing time. To big a value (eg 0.05) and you will not see the detail. Too small (0.001) and you will get artefacts in the edge detection seen as small boxes and dots.
- Tool overlap – How close two plotted paths are next to each other when more than one contour is used (see below)
- Contours - The number of layers of infill that will be plotted in dark areas. Set to 1 only the outline will be plotted while -1 will give a complete infill.
- Feed rate, spindle speed and tools – all not used.
If you wish to go even further then use a text editor to modify the python script its self (eg (Cad.py) Plotting with Z axis movement.py). Remember to back up the original before making changes.
- Movement speed – Open with text editor, Use Replace All (Crtl + H for notepad) to replace “F2000″ with your desired feed rate (eg F1500) and for the x/y axis or replace all “F300″ for z axis. Then save the file. Gcode generated will now use that speed.
- Reverse solenoid direction – Replace all “M106 S255 (Pen Up)” with “M106 (Pen Down)” and vice versa to change the solenoid direction or for using a laser. Currently the solenoid is off when the pen is down.
- Change unicorn serve travel distance – Change the S value (eg S50 to S60) in the “M300 S50 (Pen Up)” and “M300 S40 (Pen Down)” commands to change the servo travel distance.
- Change delay time after pen up and down – Replace all “G4 P120″ commands with your desired delay time in miliseconds. Eg P120 (120 miliseconds) to P150 (150 miliseconds.
Finally as cad.py was originally designed to create tool paths for milling there is nothing to stop you from attaching an engraver, laser or similar and engraving your favourite pattern or quote on something interesting.