Friday, March 11, 2011

Improved image carving

JGCGen now has better support for image carving. Since the previous post, I've added two major features. The first is a roughing strategy for removing lots of material fast and in multiple passes so you can carve deeper. The second is the decoupling of image resolution from carving resolution. Stepover distance can now be smaller than a single pixel and jgcgen will interpolate the values in between. Another important change was a rather embarrassing bug fix: the tool shape profiles for flat and ballnose endmills were swapped! No wonder the previous test looked flatter than I expected...

Still on the TODO list: optimize rough path generation to minimize rapids and implement a waterline strategy.

Friday, March 4, 2011

Image carving

JGCGen now includes rudimentary support for heightmap carving. You can see the first test carving below. (source)


 Currently only a simple scanning style toolpath generation strategy is implemented, but different methods can be added easily.
Current limitations are:
  • No interpolation. The minimum stepover is image width or height divided by target width or height. This results in the striated look visible in the above image. A workaround is to use a higher resolution image.
  • Single pass only. This limits the depth of the image to the maximum depth your bit can handle.
My current plan is to add a strategy for a roughing pass that can be run with a bigger bit before running the finishing pass.

Tuesday, March 1, 2011

A BF interpreter in g-code


The unfortunately (but aptly) named brainf*ck is my favorite esoteric programming language. The whole language has only 8 commands, yet is Turing equivalent, meaning it has the same computational power as a Turing machine. As amazing as it sounds, this means any computable function can be computed with a BF program! A simple way to prove that a language is Turing complete is to use it to implement another which already has been proven Turing complete. Due to its simplicitly, BF lends itself well to this task.

So, here is a simple BF interpreter written in EMC's RS274 dialect:

(print, PROGRAM START)
o100 while [##<_pc> ne 0]
#1 = ##<_pc>
o101 if [#1 eq 1] (memory increment)
        ##<_p> = [##<_p> + 1]
o101 endif
o102 if [#1 eq 2] (memory decrement)
        ##<_p> = [##<_p> - 1]
o102 endif
o103 if [#1 eq 3] (pointer increment)
        #<_p> = [#<_p> + 1]
o103 endif
o104 if [#1 eq 4] (pointer decrement)
        #<_p> = [#<_p> - 1]
o104 endif
o105 if [#1 eq 5] (loop start)
        ##<_sp> = #<_pc>
        #<_sp> = [#<_sp> + 1]
o105 endif
o106 if [#1 eq 6] (loop end conditional)
        #<_sp> = [#<_sp> - 1]
        o1060 if [##<_p> ne 0]
                #<_pc> = [##<_sp>-1]
        o1060 endif
o106 endif
o107 if [#1 eq 7] (print value)
        #3 = ##<_p>
        (print, ASCII: #3)
o107 endif
g0 x1
#<_pc> = [#<_pc> + 1]
o100 endwhile
(print, PROGRAM END) 

This interpreter doesn't support the input command (but that isn't needed for Turing completeness anyway) and just prints out the output in numeric format. This is pretty boring, so I added a set of functions for carving out letters. See the complete source code.