RepRap Controlling Laser – RepZap?

RepZap

I recently got my laser to do 3D printing via RepRap electronics.  I thought a fun exercise in hacking would be to get the ReplicatorG program and the RepRap controllers to control the laser.  Is this practical?  It is probably not the ideal solution, but if you are trying to make a dual purpose machine with the ultimate lowest cost it might work.  The biggest drawback is that RepRap does not do acceleration (yet).  This means there is a limit to how fast you can go before you loose steps or shake the crap out of your machine.  Also, there are not any fail safe features, like if you stop the machine in the middle of a run, does it turn the laser off.   This would be added to the ReplicatorG configuration, but was not done for this experiment.  Bottom line – no snarky, comments please, this was done for fun and learning only at this time.

I already had RepRap controlling the 3 axes for 3D printing, so that was done.  The next part was to figure out how to turn the laser on and off.  I needed to find something in RepRap flavored G-Code that would do this.  In G-code, there are  Gxx codes and Mxx codes.  The Gxx codes generally control motion and geometry setup and the Mxx codes control things like spindles and coolant devices.

Replicat.org has a partial list of the M-Code here.  The fan on/off M106 and M107 commands looked promising.  I wrote some quick G-Code to test this.  BTW: You can just type in G-Code in ReplicatorG and click the Build button to run it.

M106 (Fan on)

G4 P1000 (dwell .. Wait 1000ms)

M107 (Fan off)

I ran it from ReplicatorG and it worked great.  Fortunately, there is an LED to indicate the condition of the outputs, so I was able to see the state change without any probing.  LED7 lit up indicating circuit C was being used.  The problem is, this is a 12V output.  The laser wants TTL (5V).

RepRap Extruder controlle

A quick look at the extruder controller schematic showed that pin D12 signal is turning on the FET for this output and D12 is also connected  to the ICSP header pin 6.  This is a 5V TTL signal that will be perfect for my laser enable.

RepRap Extruder Controller Schematic

See this schematic for the basic configuration.  I used my G540 steppers drivers, but standard RepRap drivers would work too.

Now this is going to require some pretty special G-Code to run.  No off the shelf CAM program is going to produce it.  I have written post processors before, but in keeping with the free, open source nature of this device, I decided to modify some existing open source Python code.  I saw a reference to cam.py on the replicat.org generators page.   This program can already generates generic g-code for a milling machine along with a lot of other outputs.   If I created another output based on the g-code flavor I needed, that should do it.

cam_buildlog.py

I had to change a few lines near the top to add the new format choice (*.gcode), but the bulk of the changes are in a new function called write_RG().  This was a copy from the standard G-code write_G(), modified for the g-code I wanted.  You can diff the code against cam.py if you want all the changes.   I added comments to the g-code that is is output, so you can understand what is going on.  I found that cam.py is far from perfect and has issues with a lot of DXF entities, but it is totally hackable/fixable.

def write_RG():
   global boundarys, toolpaths, xmin, ymin, zmin, zmax
   #
   # RepRap G code output
   #
   xyscale = float(sxyscale.get())
   zscale = float(sxyscale.get())
   dlayer = float(sthickness.get())/zscale
   feed = float(sfeed.get())
   xoff = float(sxmin.get()) - xmin*xyscale
   yoff = float(symin.get()) - ymin*xyscale
   cool = icool.get()
   text = outfile.get()
   file = open(text, 'w')
   file.write("%\n")
   file.write("(G Code for RepRap Control of Laser)\n")
   file.write("(from cam_buildlog.py www.buildlog.net based on cam.py Neil Gershenfeld MIT 2006)\n")
   file.write("G21 (Metric Units - FTW)\n")
   file.write("G90 (Absolute Positioning)\n")
   file.write("G92 X0 Y0 Z0 (You are now at 0,0,0)\n") # absolute positioning with respect to set origin
   nsegment = 0
   for layer in range((len(boundarys)-1),-1,-1):
      if (toolpaths[layer] == []):
         path = boundarys[layer]
      else:
         path = toolpaths[layer]
      if (szdown.get() == " "):
         zdown = zoff + zmin + (layer-0.50)*dlayer
      else:
         zdown = float(szdown.get())
      for segment in range(len(path)):
         nsegment += 1
         vertex = 0
         x = path[segment][vertex][X]*xyscale + xoff
         y = path[segment][vertex][Y]*xyscale + yoff
         file.write("G00X%0.4f"%x+" Y%0.4f"%y+" (Rapid Motion)\n") # rapid motion
		 #
         file.write("M106 (Laser Enable)\n")
         for vertex in range(1,len(path[segment])):
            x = path[segment][vertex][X]*xyscale + xoff
            y = path[segment][vertex][Y]*xyscale + yoff
            file.write("G1 X%0.4f"%x+"Y%0.4f"%y+" F%0.3f"%feed+" (Coordinated motion at specified feed rate)\n")
         file.write("M107 (Laser disable)\n")
   file.write("M30 (program end)\n") # program end and reset
   file.write("%\n")
   file.close()
   print "wrote",nsegment,"RepRap G code toolpath segments to",text

Here is the resulting G-code

%
(G Code for RepRap Control of Laser)
(from cam_buildlog.py www.buildlog.net based on cam.py Neil Gershenfeld MIT 2006)
G21 (Metric Units - FTW)
G90 (Absolute Positioning)
G92 X0 Y0 Z0 (You are now at 0,0,0)
G00X-0.0000 Y0.0000 (Rapid Motion)
M106 (Laser Enable)
G1 X0.0000Y2.0000 F5.000 (Coordinated motion at specified feed rate)
M107 (Laser disable)
G00X-0.0000 Y2.0000 (Rapid Motion)
M106 (Laser Enable)
G1 X2.0000Y2.0000 F5.000 (Coordinated motion at specified feed rate)
M107 (Laser disable)
G00X2.0000 Y2.0000 (Rapid Motion)
M106 (Laser Enable)
G1 X2.0000Y0.0000 F5.000 (Coordinated motion at specified feed rate)
M107 (Laser disable)
G00X2.0000 Y0.0000 (Rapid Motion)
M106 (Laser Enable)
G1 X-0.0000Y-0.0000 F5.000 (Coordinated motion at specified feed rate)
M107 (Laser disable)
G00X1.5000 Y1.0000 (Rapid Motion)
M106 (Laser Enable)
G1 X1.4729Y0.8377 F5.000 (Coordinated motion at specified feed rate)
G1 X1.3946Y0.6929 F5.000 (Coordinated motion at specified feed rate)
G1 X1.2735Y0.5814 F5.000 (Coordinated motion at specified feed rate)
G1 X1.1227Y0.5153 F5.000 (Coordinated motion at specified feed rate)
G1 X0.9587Y0.5017 F5.000 (Coordinated motion at specified feed rate)
G1 X0.7992Y0.5421 F5.000 (Coordinated motion at specified feed rate)
G1 X0.6614Y0.6321 F5.000 (Coordinated motion at specified feed rate)
G1 X0.5603Y0.7620 F5.000 (Coordinated motion at specified feed rate)
G1 X0.5068Y0.9177 F5.000 (Coordinated motion at specified feed rate)
G1 X0.5068Y1.0823 F5.000 (Coordinated motion at specified feed rate)
G1 X0.5603Y1.2380 F5.000 (Coordinated motion at specified feed rate)
G1 X0.6614Y1.3679 F5.000 (Coordinated motion at specified feed rate)
G1 X0.7992Y1.4579 F5.000 (Coordinated motion at specified feed rate)
G1 X0.9587Y1.4983 F5.000 (Coordinated motion at specified feed rate)
G1 X1.1227Y1.4847 F5.000 (Coordinated motion at specified feed rate)
G1 X1.2735Y1.4186 F5.000 (Coordinated motion at specified feed rate)
G1 X1.3946Y1.3071 F5.000 (Coordinated motion at specified feed rate)
G1 X1.4729Y1.1623 F5.000 (Coordinated motion at specified feed rate)
G1 X1.5000Y1.0000 F5.000 (Coordinated motion at specified feed rate)
M107 (Laser disable)
M30 (program end
%
Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks

1 Response to “RepRap Controlling Laser – RepZap?”


  1. RepRap-Rays: turning a RepRap into a Laser Cutter « amk – lasers, RepRap…

    [...] had a quick look at SFACT for generating g-code but I didn’t have any success. I found that bdring previously had some of the same electronics and software issues. He modified a python script called [...]

*