[Home]Rastering With A Laser

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org


There are many applications that needs to run faster than usual. Especially laser rastering and high-resolution vectorial movements.

But there are several factors which slow down the system, like the time that EMC2 takes to execute each line of Gcode.

Taking into account these difficulties, this guide aims to bring rastering to users to the least painful way possible.

1. Difference between Vector and Raster Images

Raster images are rectangular grids of pixels, or points of color, as it is typically used for the representation of photographic images. They are stored in image files with varying formats (BMP, JPG, PNG, etc).

Vector graphics is the use of geometrical primitives such as points, lines, curves, and shapes or polygons, which are all based on mathematical equations, to represent images.


EMC2 is usually used for engrave vector graphics, moving a drill or a laser along the edges of a shape, for example. Rastering mode means move to the next pixel and update the laser power rapidly in one axis (like X axis). This movement should be at constant speed at X axis. You can find videos on youtube about rastering to have a clearer idea.

Actually, if you go from X0 to X100 to X200 to X300, EMC2 will stops at X100, then goes to X200 and stop then goes to X300 and stops. That means the laser will burn more time at the points 0, 100, 200, 300, etc. If you're engraving a picture, then the laser will stop at each pixel. So, the actual configuration is impractical for this type of applications, and it is necessary to make some changes to solve this problems.

2. Available Solutions

2.1. "Graster"

From Hacklab Toronto, "Graster" is the name of a Image to Gcode converter (made in Ruby language), and it's designed to work with a particular kind of HAL component for EMC2.

Graster produce two types of files: .NGC and .gmask files. NGC files contains the X and Y movements, and gmask files contains only the laser on/off commands. One reason to separate these instructions in two different files is that EMC2 interrupts the motion each time that normal Gcode on/off commands appears.

The laser is wired to spindle on/off (M3/M5) and is on if and only if the spindle is on and one or both of the Z axis (-0.002/+0.002) and digital out ("M62 P0"/"M63 P0") are on.

Controlling the laser with the Z axis can be tricky because EMC2 thinks that there is a moving physical object attached to the axis and tries to constrain its motion. The M62/M63 commands are realtime and instantaneous, meaning that they can be used to turn the laser on/off without affecting X/Y motion, at least in theory. You can put these commands on the same line as a motion command, in which case the laser will be turned on/off at the *beginning* of the motion.

The HAL component stream the laser on/off and moves the X axis at constant speed.

2.1.1. Installation

Graster installation:

If you want to use Graster to generate the Gcode and commands, you need to meet the following requirements:

HAL scripts and INI files installation:

Files required:

Look at the references [2] to get this files.

2.1.2. Configuration

HAL scripts and INI files configuration:

This is the "hard" part. The HAL script and the INI file were purpose-built for the laser machine at Hacklab. Some work is required to adapt it to other hardware. The position of the laser is controlled by the X and Y axes, and the height of the table is the W axis. Finally, Z axis is used to on/off the laser.

So, you need to modify the machine parameters (like max speed, acceleration, step duration, etc) for your X,Y,Z axis (X,Y,W axis in this files). You also need to rewrite the pinouts of the parallel port.

If you run EMC2, and appears a error mesage about the buffer size, try to increase the buffer size in the emc.nml file.

2.1.3. Usage

Run graster.rb for usage instructions. (in a terminal, run "./graster.rb")

The image can be any common format. PNG is probably best. A job can be configured with command line options or a configuration file. You can generate a default config file with the -g option. A config file looks like this:

 dpi: [500, 500]
 on_range: [0.0, 0.5]
 overshoot: 0.5
 offset: [1.0, 1.0]
 repeat: [1, 1]
 tile_size: [3, 1]
 tile_spacing: [0.125, 0.125]
 feed: 120
 cut_feed: 20
 corner_radius: 0.125

2.1.4. Graster Job Output

Graster output consists of a cut G-code file (filename.cut.ngc), a raster G-code file (filename.raster.ngc) and a mask file (filename.raster.gmask).

2.1.5. Examples

PNG image and its converted files, to get an idea of what graster does when it works:



This files also can be useful if you don't want install graster but want to try it (if you already have configured the HAL and INI files for your machine).

3. Acknowledgements

I slumped over my keyboard, frustrated and defeated. After an untold number of attempts, I finally came to the solution to get rastering working. Some googling showed me lists of pages talking about adding modules to blacklists, downloading the latests packages and building them and compiling kernels, etc. Sometimes Linux is a pain. But thanks to the help and patience of Hacklab and EMC2 community, this guide could be finished.

4. Links and References

[1] [LaserManual From Hacklab Toronto] (a bit outdated, but may be helpful the troubleshooting section)

[2] [EMC2 configuration and scripts for the hacklab.to laser]

[3] [Graster download]

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited June 17, 2010 8:32 am by Penguin (diff)
Published under a Creative Commons License