my blog

Hilbert Curve Desk Toy

My coworker dropped a cool looking print on my desk the other day. Using open scad, he was able to code a Hilbert curve and sweep a cut of the profile wide enough to hold a 5mm ball bearing. Over lunch we were seeing how fast we could get the ball through the length of the fractal (it fits ~17 meters of track in a 100mm x 100mm square). Based on how long it took us to get the ball through the smaller version, we estimated it would take around 15 minutes to get the ball through the 100x100 version.

image (2).png

After that we got talking about how fast you could reasonably get the ball all the way though using a robot…

We started firing off some ideas. We knew we needed 2 degrees of freedom, rotating along the X and Y axis - maybe a Stewart platform? Overkill. We initially settled on two servos, one for each axis but ended up coming up with a pretty clever mechanism that covers both degrees of freedom and only requires one motor.

The design uses a fixed pillar that houses a diametric magnet. On the outside of the pillar, a rotor with an angled top surface spins around. The printed Hilbert curve (shown above) has a matching diametric magnet and rests on the angled surface of the rotor. By spinning the rotor, we can orient the sloped surface in different directions and thus angle the Hilbert curve but what’s cool is that we’re only changing the angle of the Hilbert curve on the XY plane and not introducing any rotation because of the diametric magnet pair. Check out a video of the mechanism below.

My vision is to have this plugged into a usb port with an on / off button near the back that will start the rotating pattern to get the ball through the curve. The motors and electronics will be completely concealed and you’ll just see the rotor and Hilbert curve. I picked a NEMA 13 stepper which only needs ~200mA to run this system paired with an Ardiuno Nano and TMC2208 stepper driver. It’ll move nice and slow and be a silent piece of desk art that goes about it’s business.

I’m working on setting up the code right now but at a high level I’m going to structure 3 functions:

  • rotateCW
  • rotateCCW
  • flip

the two rotate commands will move the stage angle either 90º clockwise or 90º counter-clockwise. The flip command will be used at either end point of the maze and will flip the stage angle 180º. With these three I think I’ll be able to cover all the required movements given that the curve never has any directional changes more than 90º at a time. The last things I need to figure out are:

Setting the starting point of the routine:

There needs to be a predictable starting point for the maze in order for the order of commands to work out. Easy way is to design some alignment features into the rotor and base for the user to align before turning it on. Harder way would be a homing process - could maybe utilize a hall effect sensor to track a magnet in the rotor as it spins.

Removing system slop

The gears I printed actually mesh really well so there isn’t a ton of slop when the rotor changes direction. Keeping the direction changes tight got tricker when dealing with the curve itself. The diametric magnet holding the curve rotationally fixed isn’t as strong as I’d like and initially the movement was very choppy. I added 2 dowels that key into the maze piece to help and it did make it a bit better. I’m probably going to try to tighten up the holes for the dowels but the office axis rotation makes it tricker to size.

Here’s a video of it actually spinning a mock maze piece so you can get a better idea of the mechanics.


Nathaniel BermanComment