2009/6/13  <cmg...@sover.net>:
>
> I have an older Graphtec Flat bed pen plotter that has it's own "language"
> to accomplish many graphics tasks.  Is it possible to use EMC and it's
> port connection to send simple text commands to this unit?

I am sure it could be made to be possible, but I don't see what it
would achieve. The "expected" workflow with g-code is that a CAM
package produces a set of simple positioning commands in G-code. EMC
or another interpreter then acts on those commands. In effect, then,
EMC occupies a position equivalent to the onboard logic of the pen
plotter.
In practice the EMC interpreter offers a great deal more
"software-like" abilities than an as-conceived G-code interpreter, but
I still feel that inserting into the data flow between the high-level
data-creation software (even if that is running in your head) and the
output device makes much sense.

I have a flat-bed plotter myself, and I use it for making PCBs (using
OHP pens to directly write the etch-mask) and also for a rapid
prototyping system using a vinyl-cutting knife to slice out many
layers of label paper which can be assembled on a jig to create models
of components for casting patterns etc.

I use Gnu Octave ( http://www.gnu.org/software/octave/ )to drive the
plotter. This is free software that copies the functions of the Matlab
language. Like Matlab it auto-indexes though lists and matrices making
it very suitable for handling lists of data. It also has built-in
functions for sorting, indexing, determinants etc, etc, etc,
As a picture is worth 1000 words, here is a picture of the sort of
thing the system produces.
http://www.bodgesoc.org/brackets.jpg
And, assuming 1000 words is worth a picture, here is the Octave code
that creates slices from a .stl file and cuts them out on a plotter
(it also outputs each sheet as postscript, but I never found a use for
those files). This might give you some other ideas on how to control
your plotter.

---------------CODE--------------------

filename = '/Users/andy2/Documents/work/Front Right v10t.stl'

z = input('Start position (-Inf for beginning)')

iter = 3;

% set up plotter

a = system ('stty -f /dev/cu.usbserial0 evenp cstopb 9600 ...
                        -crtscts -mdmbuf clocal cread')
                        
f = 0; p = 0; pagenumber = 1;

eps_scale = 72/25.4 % conversion from mm to points
plot_scale = 40 % conversion from mm to RD-GL
thickness = 0.59/7 % thickness of layers
pagewidth = 260; % paper size
pageheight = 190;

[F V C] = stl_read(filename);

X = [V(F(:,1),1) V(F(:,2),1) V(F(:,3),1)]; % X coords for each face
Y = [V(F(:,1),2) V(F(:,2),2) V(F(:,3),2)]; %Y
Z = [V(F(:,1),3) V(F(:,2),3) V(F(:,3),3)]; %Z

T = Z; %quick and dirty rotation
Z = X;
X = T;

clear T

% find extents

zmin= min(Z(:))
zmax = max(Z(:))

page_x = pagewidth; page_y = pageheight+10; % force file initialisation
old_ymin = 0;

%for z = zmin:thickness:zmax
for z = max(z, zmin):thickness:zmax
        
        disp(z)
        
        I1 = find(sum((Z>z),2) == 1); % Index of faces with 1 vertex greater 
than z
        I2 = find(sum((Z>z),2) == 2); % index of faces with 2 > z
        
        C = [];
        
        for a = 1:length(I1)
                [zs i] = sort(Z(I1(a),:)) ;% put biggest Z last, and store order
                xs = X(I1(a),i);
                ys = Y(I1(a),i);
        
                x1 = xs(1)+(xs(3)-xs(1))*(z-zs(1))/(zs(3)-zs(1));
                x2 = xs(2)+(xs(3)-xs(2))*(z-zs(2))/(zs(3)-zs(2));
        
                y1 = ys(1)+(ys(3)-ys(1))*(z-zs(1))/(zs(3)-zs(1));
                y2 = ys(2)+(ys(3)-ys(2))*(z-zs(2))/(zs(3)-zs(2));
                
                C = [C; x1 y1 x2 y2];
                
        end
        
        for a = 1:length(I2)
        
                [zs i] = sort(Z(I2(a),:)) ;% put biggest Z last, and store order
                xs = X(I2(a),i);
                ys = Y(I2(a),i);
                
                x1 = xs(2)+(xs(1)-xs(2))*(z-zs(2))/(zs(1)-zs(2));
                x2 = xs(3)+(xs(1)-xs(3))*(z-zs(3))/(zs(1)-zs(3));
        
                y1 = ys(2)+(ys(1)-ys(2))*(z-zs(2))/(zs(1)-zs(2));
                y2 = ys(3)+(ys(1)-ys(3))*(z-zs(3))/(zs(1)-zs(3));
                
                C = [C; x1 y1 x2 y2];
                
        
        end
        
        xmax = max(max(C(:,[1 3])));
        xmin = min(min(C(:,[1 3])));
        ymax = max(max(C(:,[2 4])));
        ymin = min(min(C(:,[2 4])));
        
        pstr = '';
        
        if (xmax-xmin > pagewidth | ymax-ymin > pageheight)
                clc();
                disp("Page not large enough for object")
                stop
        endif
        
        if (page_x + xmax - xmin) > pagewidth % not enough room on page
                page_x = 0;
                page_y = page_y + old_ymin;
                old_ymin = 0;
        endif
        
        if (page_y + ymax - ymin > pageheight) % top of page reached
                
                if (f ~= 0) % file already open
                        fprintf(f, 'stroke\n');
                        fprintf(f, '%%%%EOF\n');
                        fclose(f);
%                       fprintf(p, "SP 0;");
                        clc();
                        disp("change paper and press any key")
                        fflush(stdout);
                        k = kbhit();
%                       fprintf(p, "SP 1;")
                        
                endif
                
                if (p ~= 0) % have a plotfile
                        fclose(p)
                
                endif
                        
                
                page_y = 0 ; page_x = 0;
                
                stroke = '';
                
                f = fopen(['/Users/andy2/Documents/gash' num2str(z) '.eps'], 
'wt');
        
                fprintf(f, '%%!PS-Adobe-3.0 EPSF-3.0\n')
                fprintf(f, '%%%%BoundingBox: %0.2f %0.2f %0.2f %0.2f\n', ...
                        0, 0, (pagewidth)*eps_scale, (pageheight)*eps_scale)
                fprintf(f, '0.75 setlinewidth\n')
                pfilename = 
sprintf('/Users/andy2/Documents/work/plotfile%02.0f.hpgl',
pagenumber);
                pagenumber = pagenumber + 1;
                
                p = fopen('/dev/cu.usbserial0', 'w+');
                msg = fcntl (f, F_SETFL, O_NONBLOCK)
                fprintf(p,'%c.R', 27); % Turn on hardware handshaking
                fprintf(p,'%c.M 100;13;;13;10;0:', 27);
                fprintf(p, "IN;");
%               fprintf(p, 'SP 1;');
                fprintf(p, 'VS 6;');
                fflush(p);

                
                clg
                hold on
                plot([0 ;pagewidth; pagewidth; 0; 0], [0; 0; pageheight; 
pageheight;
0;], 'r');
                        
                legend("off")

                
        endif
        
        plot([page_x; page_x+xmax-xmin; page_x+xmax-xmin; page_x; page_x],
[page_y; page_y; page_y+ymax-ymin; page_y+ymax-ymin; page_y], 'b');

                                
        %Try to string line segments together into loops.
        
        g = 1:length(C); % use this vector to store indices to the currently
unassigned segments
        
        lastx = 0 ; lasty = 0;
        
        pstr = '';
        
        while (any(g))
        
                        % find closest point in either start or end sets
                        
                        if length(g) > 1
                                [dist gi] = min(abs(C(g,[1 
3])-lastx)+abs(C(g,[2 4])-lasty));
                        else
                                gi = 1;
                        end
                                                
                                %find which column of the located row the min 
dist was in and call it ti
                                [dist ti] = min(dist);
                                gi = gi(ti);
                                
                        if dist > 0.05 % not at or very close to the last point
                        
                                if pstr ~= ''
                                        %Plot the previous loop iter times
                                        pstri = [find(pstr == ';') 
length(pstr)];
                                        fprintf(p,(pstr(1:pstri(1)))); % move 
to start of loop
                                        for i = 1:iter
                                                for a = 1:10:length(pstri)
                                                        
                                                        
fprintf(p,(pstr(pstri(a):(pstri(min(a+10,length(pstri)))))));
                                                        
                                                        do      
                                                                fprintf(p, 
"%c.B\n", 27);
                                                                usleep(30000);
                                                                buff = 
fgets(p,4);
                                                                fclear(p)
                                                        until str2num(buff) > 
1000
                                                        
                                                end
                                        end
                                end

                                pstr = '' % start a new loop
                                
                                fprintf(f, '%s', stroke)
                                fprintf(f, '%0.2f %0.2f moveto\n', ...
                                        (C(g(gi), [1 3](ti)) - xmin + 
page_x)*eps_scale, ...
                                        (C(g(gi), [2 4](ti)) - ymin + 
page_y)*eps_scale);
                                fprintf(f, '%0.2f %0.2f lineto\n', ...
                                        (C(g(gi), [3 1](ti)) - xmin + 
page_x)*eps_scale, ...
                                        (C(g(gi), [4 2](ti)) - ymin + 
page_y)*eps_scale);
                                        
                                pstr = sprintf('PU %0.2f, %0.2f;PD %0.2f, 
%0.2f;', ...
                                        ((C(g(gi), [1 3](ti)) - xmin + 
page_x)*plot_scale), ...
                                        ((C(g(gi), [2 4](ti)) - ymin + 
page_y)*plot_scale), ...
                                        ((C(g(gi),[3 1](ti)) - xmin + 
page_x)*plot_scale), ...
                                        ((C(g(gi),[4 2](ti)) - ymin + 
page_y)*plot_scale));

        
%                               plot([C(g(gi), [1 3](ti)) C(g(gi), [3 1](ti))] 
- xmin + page_x , ...
%                                       [C(g(gi), [2 4](ti)) C(g(gi), [4 
2](ti))] - ymin + page_y, 'b');
        
                                lastx = C(g(gi),[3 1](ti)) ; lasty = C(g(gi), 
[4 2](ti));
                                stroke = 'stroke\n'; % done this way to 
suppress spurious one
                        
                        else % Actually at previous point
                        
                                fprintf(f, '%0.2f %0.2f lineto\n', ...
                                        (C(g(gi), [3 1](ti)) - xmin + 
page_x)*eps_scale, (C(g(gi), ...
                                        [4 2](ti)) - ymin + page_y)*eps_scale);
                                
                                pstr = strcat( pstr, sprintf( 'PD %0.2f, 
%0.2f;', ...
                                        (C(g(gi), [3 1](ti)) - xmin + 
page_x)*plot_scale, (C(g(gi), ...
                                        [4 2](ti)) - ymin + 
page_y)*plot_scale));
                                        
                                
                                
%                               plot([lastx C(g(gi), [3 1](ti))] - xmin + 
page_x, ...
%                                       [lasty C(g(gi), [4 2](ti))] - ymin + 
page_y, 'b')                               
                                
                                lastx = C(g(gi),[3 1](ti)) ; lasty = C(g(gi), 
[4 2](ti));
                        endif
                        
                        g = [g(1:gi-1) g(gi+1:end)]; % remove used index from 
list
                                
        endwhile
        
        if pstr ~= ''
                %Plot the lasr loop of the slice iter times
                pstri = [find(pstr == ';') length(pstr)];
                fprintf(p,(pstr(1:pstri(1)))); % move to start of loop
                for i = 1:iter
                        for a = 1:10:length(pstri)
                                
                                
fprintf(p,(pstr(pstri(a):(pstri(min(a+10,length(pstri)))))));
                                
                                do      
                                        fprintf(p, "%c.B\n", 27);
                                        usleep(30000);
                                        buff = fgets(p,4);
                                        fclear(p)
                                until str2num(buff) > 1000
                                
                        end
                end
        end

        
        fprintf(p, 'PU;');
        fflush(p)
        
        pstr = ''
        
        page_x = page_x + (xmax - xmin)*1.04;
        
        old_ymin = max(old_ymin , (ymax - ymin) * 1.04);

end

fprintf(f, '%s', stroke)
fprintf(f, '%%%%EOF\n')

fclose(f)
fclose(p)



-- 
atp

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to