Advertisements

MPCNC: Spirograph Exerciser

Both bCNC and GCMC include Spirograph generators with more-or-less fixed patterns and sizes, because the code serves to illustrate the software’s capabilities:

MPCNC - bCNC Spirograph patterns

MPCNC – bCNC Spirograph patterns

GGMC Cycloids test patterns

GGMC Cycloids test patterns

I wanted to exercise my MPCNC’s entire range of travel, familiarize myself with some new GCMC features, and, en passant, mimic the actual gears in a classic Spirograph, so, of course, I had to write a Spirograph emulator from scratch:

MPCNC - Full-platform Spirograph - multicolor

MPCNC – Full-platform Spirograph – multicolor

The perspective makes a 29×19 inch sheet of paper (made from three B sheets and one A sheet) look not much larger than the 17×11 inch B size sheets in the first two pictures. IRL, it’s a billboard!

My GCMC code uses notation and formulas from a paper (tidy PDF) on a Gnuplot spirograph generator, with a dash of error checking from the GCMC source.

The code enumerates the possible gear tooth counts in a pair of vectors from which you select the desired stator and rotor gears using integer subscripts. Because I eventually scale the results to fit the plot area, there’s no need to keep track of actual gear pitch diameters.

Similarly, the pen offset from the center of the rotor gear is a pure number, which you can think of as the ratio of the offset to the rotor diameter. It can have either sign and may exceed unity, as needed, either of which would be difficult with a physical gear.

Figuring the number of rotor turns required to complete the pattern requires reducing the gear ratio to a fraction with no common factors, so I wrote a Greatest Common Divisor function using Euclid’s algorithm adapted for GCMC’s bitwise tests and shifts.

With those values in hand, a loop iterates around the entire pattern to produce a list of XY coordinates in normalized space. Because the formula doesn’t have the weird properties of the Superformula I used with the HP 7475 plotter, I think there’s no need to prune the list to eliminate tiny moves.

Scaling the entire plot requires keeping track of the actual extents along both axes, which happens in the loop generating the normalized coordinates. A pair of gears producing an odd number of lobes can have different extents in the positive and negative directions, particularly with only a few lobes (3, 5, 7 …):

Spirograph - 3 lobes - QnD Simulator

Spirograph – 3 lobes – QnD Simulator

So I accumulate all four, then scale based on the absolute maximum; I added scalar min() and max() functions.

Converting the list of scaled points into G-Code turns out to be a one-liner using GCMC’s tracepath() library function. Previewing the results in a Web-based simulator helps weed out the duds.

The code needs cleanup, in particular to let a Bash script set various parameters, but it’s a good start.

The GCMC source code as a GitHub Gist:

Advertisements

, ,

  1. #1 by Jason Doege on 2017-12-19 - 18:10

    Question. Why are you using the Protoneer/Arduino/GRBL controller instead of the Mini-RAMBo that they sell with the kit? Cheaper? Better? What you are familiar with?

    • #2 by Ed on 2017-12-19 - 19:06

      Marlin on RAMPS is so tightly coupled to 3D printing that using it for anything else requires fighting its assumptions to a standstill.

      GRBL implements nearly the entire LinuxCNC G-Code dialect, including good support for work coordinate systems, along with a bunch of handy M-Codes, so it’s better suited for three-axis subtractive machining. Given its intended application, the Protoneer board has just what’s needed and nothing more.

      I’ve also been using bCNC on a Raspberry Pi for the UI and like it a lot. At some point, I’ll mount a Z axis probe on the tool holder and let bCNC map out the table surface, which should make it possible to do fine engraving with a hulk like the MPCNC.

      GRBL seems a whole lot more mature than Marlin and, in fact, is in a steel-cage death match with program space; without room to grow, it’s entered de-facto feature freeze. I like stability in a CNC control program …

      Ryan recently added de-racking homing to (feature-frozen!) Marlin, using two extruder stepper drivers as separate X and Y motor drivers. I expect the GRBL-Mega branch will eventually include de-racking, which would justify switching to a RAMBO/RAMPS board, but that won’t happen for a while.

      • #3 by Jason Doege on 2017-12-19 - 21:00

        Thanks! I knew you had reasons. I’m considering building one of these because I don’t want to invest $2k in something I might play with for a few months and then never use again. And because sometimes the journey is as much fun as the destination. :-)

  2. #4 by Jason Doege on 2017-12-20 - 08:12

    In one of your posts on this topic you mentioned a drag chain being over-kill. You might be interested: recently on Hack-a-day they posted a low-cost, lightweight drag-chain solution involving woven cable-wrap and tape-measure tape. Quite clever. https://hackaday.com/2017/12/17/diy-cable-chain-looks-great-stays-cheap/

    • #5 by Ed on 2017-12-20 - 09:01

      A perfect solution: thanks for the pointer!

      Now, if only I hadn’t given away a box of steel tapes … [sigh]

  1. MPCNC: GCMC Text vs. Speed | The Smell of Molten Projects in the Morning
  2. A Spirograph for Christmas | The Smell of Molten Projects in the Morning
  3. MPCNC: Spirograph Generator with Tool Changes | The Smell of Molten Projects in the Morning
  4. MPCNC: Z Height Probe vs. Tempered Glass Sheet | The Smell of Molten Projects in the Morning