Gcode from Flatcutter, STLcutter, nurbs and bezier patches..

Welcome to BoardCAD forums Software BoardCAD developers Gcode from Flatcutter, STLcutter, nurbs and bezier patches..

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #3548

    surfineurope
    Participant

    Here is a quick comparison between the gcode generated with Flatcutter and STLCutter (with an stl model of a flatcutter), and between nurbs surfaces and bezier patches. I used the following script to generate the gcode since the normal machine interface only works with the STLCutter and uses some old surface methods that doesn’t work well with bezier patches:


    """
    Generating g-code from jython script
    """

    import boardcad.BoardCAD
    from javax.swing import *
    import math

    # machine configuration

    filename='gcode.ngc'
    zsafe='g0 z400n'
    feedrate=10000
    cutter=boardcad.FlatCutter()
    #cutter=boardcad.STLCutter()
    #cutter.init('flatcutter.stl');

    # get a copy of the deck surface from BoardCAD
    """
    The board has two surfaces meeting at tucked under
    deck is the deck surface
    bottom is the bottom surface
    """

    boardhandler=boardcad.BoardCAD.getInstance().getBoardHandler()
    board=boardhandler.getActiveBoard();

    deck=board.getDeck()

    # find parameter value for outline
    """
    Each surface is parameterized in t and s
    t goes from tail=MinT to nose=MaxT
    s goes from right=MinS to left=MaxS

    we want to find s at the outline,
    i.e. the widest point of the board
    """

    max_width = 0.0
    s=deck.getMinS()

    p = deck.getPoint((deck.getMaxT()-deck.getMinT())/2, s)

    while (max_width - math.fabs(p.z) < = 0):
    s=s+0.01
    p = deck.getPoint((deck.getMaxT()-deck.getMinT())/2, s)
    if (math.fabs(p.z) > max_width):
    max_width = math.fabs(p.z)

    s_outline=s

    # open a file and write some g-code
    """
    We let:
    s change from outline left to right
    t change from MinT to MaxT and back to MinT
    for each t,s:
    read surface point and normal
    do tool compensation
    write tool position in machine coordinates
    """

    f=open(filename, 'w')

    f.write(zsafe);

    step=(deck.getMaxS()-deck.getMinS()-2*s_outline)/32
    s=s_outline
    t=deck.getMinT()

    while (s while (t p=deck.getPoint(t,s)
    n=deck.getNormal(t,s)
    p=cutter.calcOffset(p,n)
    f.write('g1 x%.3f y%.3f z%.3f f%dn' % (p.x, -p.z, p.y, feedrate))
    t=t+step
    s=s+step
    while (t>deck.getMinT()):
    p=deck.getPoint(t,s)
    n=deck.getNormal(t,s)
    p=cutter.calcOffset(p,n)
    f.write('g1 x%.3f y%.3f z%.3f f%dn' % (p.x, -p.z, p.y, feedrate))
    t=t-step
    s=s+step

    f.write("M2");
    f.close()

    JOptionPane.showMessageDialog(None, "Finished g-code generation")
    #4244

    surfineurope
    Participant

    First I generated a nurbs model of the standard shortboard and created gcode using the STLCutter (as it in the normal machine interface).

    You can notice some jagged lines, especially close to the nose of the board…

    #4245

    surfineurope
    Participant

    Next I changed the STLcutter to a Flatcutter:


    cutter=boardcad.FlatCutter()
    #cutter=boardcad.STLCutter()
    #cutter.init('flatcutter.stl');

    Running the script again results in a smoother cutting path

    #4246

    surfineurope
    Participant

    I also tested to generate surfaces using Bezier patches with the following script:


    import boardcad.BoardCAD

    boardhandler=boardcad.BoardCAD.getInstance().getBoardHandler()
    bezierboard=boardcad.BoardCAD.getInstance().getCurrentBrd();
    boardhandler.approximate_bezier_patch(bezierboard, False)

    #switch deck normals

    board=boardhandler.getActiveBoard()
    deck=board.getDeck()
    i=0
    while (i j=0
    while (j p=deck.get_control_point(i,j)
    deck.set_control_point(i,j, boardcad.myPoint(p.x,p.y,-p.z))
    j=j+1
    i=i+1

    deck.evaluate_surface()

    The generated surface contains more control points and fits the 2D curves of the outline, rocker, and cross section much better than the previous surface model.

    The gcode is generated with the same script as above and the cutting lines are similar.

    #4247

    surfineurope
    Participant

    Finally I wanted to show that the Bezier patches are especially useful where normal nurbs surface fail to approximate the Bezier curves.

    Below is a board that has been imported from surfcad and therefore has a completely straight rail. I also added a winger.

    While the traditional nurbs approximation always creates a very smooth surface (with continuous curvature), the bezier patches maintain the sharp edges of the Bezier curves.

    Again we can create gcode with the same script as before.

    #4248

    sm02463
    Member

    Nice work on the comparison.

    Once again, I don’t like the STLCutter and it’s pretty obvious to me it should be eliminated. Nurbs vs bezier patches…they both seem pretty good so I don’t really have any strong opinion.

    On another note, someone has going to the trouble to create an AbstractCutter but I’m surprised to see it not being used abstractly. I’m hoping to see the next version of gcode export passed an AbstractCutter, hiding the specifics to the section of code that selects which cutter to use.

    #4249

    surfineurope
    Participant

    @sm02463 wrote:

    On another note, someone has going to the trouble to create an AbstractCutter but I’m surprised to see it not being used abstractly. I’m hoping to see the next version of gcode export passed an AbstractCutter, hiding the specifics to the section of code that selects which cutter to use.

    The AbstractCutter was used before I added 4 axis support. Currently only the STLCutter does 4-axis tool compensation so I choose to use that directly instead of updating the AbstractCutter and forcing everyone to implement 4 axis support to their cutters. I’m not sure which is the best way to go here. We have similar problems with AbstractBoard.

    Personally I don’t like the abstract classes. I think it would be better to define some interfaces for 3, 4, and 5 axis cutting that the Cutters could implement…

    /Jonas

    #4250

    sm02463
    Member

    Something that really bothers me is your scripts use the BoardCAD coordinate system whereas the BoardMachine gcode functions use the machine coordinate system. This is with respect to what the cutter’s calcOffset() uses.

    I think this means the STLCutter cannot be used correctly from a script and the FlatCutter cannot be used correctly from the BoardMachine class.

    You results don’t look all that bad so maybe I’m incorrect here…but it sure seems like a problem to me…

    #4251

    surfineurope
    Participant

    The old g-code methods (used in BoardMachine) uses the coordinate system of my Shapebot machine. This made it difficult to adapt the code to different machines. In the scripts I therefore decided to do tool compensation in BoardCAD coordinates and added a new calcOffset method to STLCutter and FlatCutter that automatically does the transformation.

    In the next version of BoardCAD I would like to remove the old g-code methods and provide the new simplified methods. When doing so we can also provide new stl-files with the tools in BoardCAD coordinates and remove the current transformation.

    We really need to start using a common coordinate system and common units in the 2D, 3D, and machine views.

    /Jonas

    #4252

    sm02463
    Member

    So I wrote a version of BullNoseCutter that works with 3-axis cutters and it shouldn’t be too difficult to make it work with a 4th axis. How do you usually test something like this? I’ve run it through a sample board I designed but maybe there’s a proven test board I should be using?

    Do you want me to check this in somewhere? I’m not even sure I have priveledges to do so.

    #4253

    surfineurope
    Participant

    Great! You can add it to the boardcam package in the trunk and I will have a look at it. We don’t have any real test cases. I simply generate gcode with and without tool compensation in order to compare…

    /Jonas

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.