Produce Shopbot Code from Grasshopper

The objective of this tutorial is to demonstrate the process of generating machine paths and machine code for the Shopbot Desktop router using simple geometric and text operations in Grasshopper. This is an adaptation of last year’s tutorial on generating G-Code for other CNC machines. The approach of this tutorial will be based on graph nodes rather than C#.

script_shopbot

Procedure Overview

  1. We begin assuming that you have already drawn as series of curves (preferably within the positive quadrant of the world coordinate system) with the XY plane representing the top of material. The source of the curves is arbitrary, you may for instance hand-draw them using Rhino commands, generate through Grasshopper scripts or apply any process that extracts curves from surfaces etc.
  2. The only steps required to adjust in the script below are then:
    1. Import the curves into the Nurbs Curves component (lines and polylines are also ok)
    2. Set the feed rate (linear speed) to something that works with the target tool and material.
    3. Copy the data only from the terminal panel, paste them into Notepad and save the file with the *.sbp extension.
  3. As all CNC machines primarily understand polylines (sequences of points) the first section of the script converts all incoming geometry to polylines within some angle error tolerance. The default subdivision angle is set to 0.5 degrees. Smaller numbers will produce generally more points and thus bigger files, larger numbers will produce rougher approximations with fewer points and machine code instructions.
  4. The next step is to explode the polylines into point lists and also extract the start and end point of each. The terminal point extraction is used such that linking transfer segments are later inserted from one curve to the other making sure that the path is above a clearance level (set here to 25mm). We thus add a vertical displacement using basic vector math and merge back the polyline points into lists containing the additional lift points. For visualization purposes the lists of all points are flattened and fed into the orange node polyline (see below).
  5. The following segment extracts the point coordinates and formats text strings according to the Shopbot language specification. I am only using three decimal places seen as {0:0.000} because this is sufficient for this machine. Do note that the units of the Rhino document need to be millimeters for this to work (not meters etc). Otherwise you may need some additional units conversion logic.
  6. In similar fashion as with performing something special for the start and end points of each curve, here too I am producing Shopbot language comments to annotate the start and end of each curve point sequence and the merge all text into a list of sub-programs.
  7. The final steps include adding a so called program header and footer that take care of the initialization and finalization of the machine program. The initial instructions are commented and rather self-explanatory. Notice that I added an extra step of moving 20mm above the workspace zero before initiating the spindle as we cannot ensure the position of the machine before starting.
  8. The motion speed aka feed rate is expressed in millimeters per minute which is converted to millimeters per second (Shopbot requirement) and injected into the code using the format component.
  9. The three parts of the program (a) Header, (b) Body and (c) Footer are merged into one list and displayed on a panel which you may stream or copy/paste to a machine code file.
  10. As final demonstration that machine code generation is not akin to rocket science I compute approximately the time it will take to actually run the program by computing the total length of the machine path (just measuring the polyline) and dividing by the motion speed, which results to time.