jeudi 21 juillet 2011

Extending the "cnc" plotter script

We worked with a CNC script, making lines of an image.
Since the plotter can only plot lines, the script scans an image for instance horizontally, and depending on a value you can chose of brightness, starts a vertical line where the brightness is under this value and ends it where the brightness becomes above this value.
The script found on the internet uses only one direction, which is enough for milling. We extended the script for two directions, horizontal and vertical, and you can also make variable spacing between the lines.
The fun thing with plotters is that you can add several images on the paper, using different pens, so different colors. You can plot over other images.





Here you see how this plotter script makes it own version of drawings.





An image of several drawings combined together:



The Processing cnc plotter script:
http://www.contrechoc.com/blogPics/plot/cnc_plotter.zip


photo = loadImage("walkers.jpg");
drawLinesH(photo, 2, 55, 550, 50); //horizontal lines
drawLinesV(photo, 2, 65, 500, 90); //vertical lines


You have to load the image form the "data" folder of the Processing sketch
drawLinesH makes horizontal lines,
drawLinesV, vertical lines,
the second parameter is the spacing.
the third parameter is the valua at which a line starts being drawn.
The last two parameters is where the image will be positioned.

Here is the start of the function:


void drawLinesH(PImage photo, int spacing, float offsetDL, int setX, int setY)


In an extra TAB in the script are the plotter functions of our simple plotter lib.

what is important is the scaling (and rotating) of the totality of lines plotted. Every plotter has its own size and coordinates. In the function plotterLine these are visible and can be modified:


void plotterLine(float x1, float y1, float x2, float y2) {
if ( portAvailable == 1 ){
myPort.write("PU");
myPort.write("PA" + str( 10000 - x1) + "," + str(1000 + y1) +";");
myPort.write("PD");
myPort.write("PA" + str( 10000 - x2) + "," + str(1000 + y2) +";");
myPort.write("PU");
}
}

The str( 10000 - x1) means the x coordinate is mirrored and starts from 10000. This is a A3 plot format. For other plots A4, or A0 you have to change the 10000 value.

Of course you have to experiment...

Aucun commentaire:

Enregistrer un commentaire