Monday, November 11, 2019

Building the Key of Aaravos


A few months ago, my wife and I binge-watched the first two seasons of The Dragon Prince on Netflix.  It’s a cute little cartoon show with some really good writing and well fleshed out characters, and with only 18 episodes so far it doesn’t take long to catch up on the whole thing.
In the show, there is a magical device initially referred to as the “Primal Cube” initially, though revealed in the second season to be more properly called the Key of Aaravos.



The Primal Arcanum Cube
aka
The Key of Aaravos

The cube has six sides, each with a symbol of one of the types of primal magic in the show, that lights up when in the presence of each type of magic.  After watching the show, I wondered if anyone had published 3D files of it for printing. A quick search on Thingiverse brought up a few results. I was considering printing one, but my wife pointed out that I should make one that lights up.  It shouldn’t be too hard, I thought. Just a few colored LEDs, right?

I downloaded one of the better Key of Aaravos files from Thingiverse to use for reference, but ended up redrawing everything essentially from scratch anyway. I tried to guess based on stills from the TV show just how large it was supposed to be, which was difficult as we really don’t know how large Callum’s hands are. I scaled the cube relative to my own hands, which may have resulted in a slightly oversized cube in retrospect - I have large hands.

To test how it would look, I split the cube into faces, and split the raised illuminated sections on each face into a separate section that would be printed in translucent plastic and pressed into the face pieces. I was lucky to have a reel of a beige color that fairly closely matched the color of the cube on the show, and a reel of ‘natural’ translucent PLA, both of which I had no other immediate use for. The test print, held up to the ceiling light for backlighting, revealed some issues with how light bled through both the transparent and the opaque plastics. Too much light was bleeding through the parts of the structure that were meant to be opaque, and the transparent parts didn’t look right either, but I was pretty sure I knew how to solve both issues.


Initial illumination test. Still needs a lot of work.

At this point, I needed to choose internal components, so I could design the final printed parts. My initial plan had been to simply grab some ultrabright LEDs in various colors, but I wasn’t sure I could exactly match the right shades of colors with easily available LEDs. It occurred to me that I might need to mix multiple colors of LEDs to get it just right. Fortunately, there’s an off the shelf solution for that. Neopixel LEDs have red, green, and blue LEDs along with a control chip all combined in one package, programmable through a serial data link that’s daisy-chained from one LED to the next. I had never worked with them before, and this would be a good excuse.

I decided to use one Adafruit Neopixel Ring, and one Neopixel Jewel, inside each face of the cube, for a total of 19 Neopixels in each. In retrospect, this was far more than I needed. I didn’t realize just how bright these things are, it actually hurts to look at the LEDs at full brightness without the printed faces over them.

Neopixels require a microcontroller to command them, something with enough memory and a sufficiently fast port for the required serial data signal. I had originally considered an arduino, but looking through the Adafruit catalog I noticed the Trinket M0, a remarkably small and inexpensive control board capable of running CircuitPython. I’ve been using Python for various projects for years on larger computers, and was surprised and somewhat skeptical that it was even possible to make it run on an embedded controller. I decided to try using it to control this project.

The cube would need a battery, for which I chose the 1200mAh Lithium Ion Polymer cell from Adafruit. I also chose the Adafruit Powerboost 1000 to act as a charger and 5V regulator. I’d used it on previous projects with success, and it would handle more than enough current to drive a single face at full brightness.

One problem was that while the Trinket M0 would accept 5V input power, it would only output 3.3V on its data pins, and the Neopixels really want the serial data signal to be at the same voltage as the power line. I added in a little bi-directional voltage level shifter to do the conversion from the Trinket to the Neopixels. It has four channels, but I’m only using one.

Being able to just buy simple drop-in breakout boards makes designing things like this so much easier. I remember back in the day, when I first started doing electronics, I would have to draw and etch my own circuit boards, ironing transfers onto bare copper boards and then carefully washing them in tubs of unsafe chemicals. These days, having companies like Adafruit that make everything available on breakout boards just makes everything so much easier.

With power and serial data control of the LEDs worked out, I needed a way for a person to indicate which side of the cube should light. Adafruit didn’t have any primal magic detecting sensor boards available, so I’d have to fake it. I considered building a separate remote control with buttons for each side of the cube, but I really wanted this to be a single-piece build. I also considered using a Bluetooth connection to control it from a cell phone, but that was more work than I wanted to spend on this project. Another idea was to use an accelerometer, and have the person holding the cube gesture or angle the cube a certain way to indicate which side to light. Awkward, but Adafruit did have an inexpensive accelerometer board available. Then I saw the 12 channel capsense board, and though that it might be possible for the cube to detect your hand and light the side opposite where it was being held by. I wasn’t sure if the capacitive sensing would work well enough, so I included the accelerometer anyway as a backup.
Final schematic and parts list



All of the parts were conveniently available from Adafruit. A few days later, and I had a pile of boards ready to start working with.


Always a nice day when my Adafruit order has arrived.

A test with a single side and just enough electronics to make it light up showed a bit more of a spotlight effect than I’d like, but it was acceptable.


Far brighter than expected.  I could probably have used fewer LEDs

Before doing anything further, I needed to do a detailed design of the interior. The structure ended up a lot more complex than I initially expected. Each face has a LED assembly consisting of one Neopixel ring and one Neopixel jewel, centered in a truncated pyramid which acts as a light baffle to block light from one side from bleeding into another. In the center is a roughly cubical space where most of the electronics go, although the Powerboost charger/regulator board and the Trinket needed to be arranged such that their respective USB ports were accessible from the outside of the cube. Fitting the battery in place was tricky, as it had to extend slightly into the diagonal spaces between the light baffles. The Trinket ended up having to go into a corner behind the Star arcanum space, as it was the only place it wouldn’t block any light.


Each edge of the cube needed to contain an antenna for capacitive proximity sensing. I experimented with a few different ideas before deciding to use strips of copper tape. The Adafruit Captouch board that I was using was really meant for touch sensing, but I needed to detect a person’s hands through some distance of plastic, since the electrodes wouldn’t be on the surface. I had a challenge in how to route the wires from the breakout board to each of the edge electrodes, as I wanted to route them away from potentially electrically noisy components in the center. I also wanted to keep the wires away from the outside to avoid incorrect sensing of user’s hand. This meant carefully routing the wires through carefully designed holes and channels inside the walls between faces, avoiding the battery charger and other components.

Capsense wires in red, fanning out to antennas on edges.

The segments of the core took about six hours to print each. There were a few iterations of the design, mostly as I figured out how to route the capsense antenna leads. The final design did make it difficult to install them, and results in them essentially stitching the pyramids together, but does keep them away from the LEDs and other electronics. These pieces were printed in black, with a high infill, to keep them opaque and prevent light from bleeding over from one side to another.

Printing core segments on my sweet custom Delta printer.

For the outer shell of the cube, I had a reel of tan filament on hand that was a near perfect match for the color of the cube.  I also had a reel of translucent ‘natural’ PLA which I’d been looking for an opportunity to use.  You can’t really print transparent parts with a printer like mine, but I was hoping I could get a decent frosted-glass look that would let the light through while also diffusing enough to prevent hot spots.

The initial test print showed several problems.  The plastic I chose for the shell just wasn’t opaque enough.  There was far too much bleed through when any bright light was behind it.  I had really underestimated just how bright the Neopixels were, and although I liked the brightness and how they illuminated the runes, I didn’t like how much bled through the parts that were supposed to be opaque.  The nice tan plastic that matched the color of the cube just wasn’t very opaque.

Too much light bleeding through the center.

I considered a few different options for making the faces block light better.  I considered lining the inside with dark tape, printing an inner shell out of black plastic, or even taping copper foil over the inside, which I briefly thought might have been required for proper capsense function.  The simplest solution - several coats of black spray paint - turned out to work very well.

Careful masking to keep the paint on the inside.

The other issue was the proper appearance of the translucent parts.  I discovered very quickly that the infill pattern would be highly visible due when illuminated.  I wanted the lit parts to look smooth and without pattern, which wasn’t really possible with a printed translucent part.  After a few experiments I found that printer settings with no infill, no top and bottom, but very high side wall thickness, worked the best.  This setting resulted in a part that was made up entirely of concentric shells.  When illuminated, the pattern was barely visible, and when not illuminated it had a shimmering, almost crystalline look that I really liked.

All six faces, with translucent parts inserted.

I had a challenge in figuring out how to attach the faces to the core.  I decided early on that I wanted it to be possible to completely disassemble the cube without breaking or cutting anything.  No glue or plastic-weld, it had to be fit together with fasteners.  For the initial design I had small wood screws hidden in the leaf detailing near the corners.   I built up a full prototype cube this way before deciding it was unacceptable.  The screw heads stood out far too well against the plastic, and the edges of the plastic faces tended to curl away from each other resulting in visible seams.  It looked terrible.


Unacceptable.  Time to re-think the design.

I went back to the drawing board on the faces, and ended up redesigning the core too.  I decided to attempt a friction interlocked, puzzle-box type design.  The faces would have edges that locked into each other in a way that was designed to hide the seam between faces from the viewer, breaking up the seam and hiding it in the detailing.  The resulting design relied on friction and interlocking geometry to attach the faces edge-to-edge.  The corners became separate pieces which were inserted after the faces were in place, to furner lock them together and pin them to the core.  The resulting design was surprisingly strong, had no visible screws or other fasteners, and did a good enough job of concealing the seams.  I could probably have done a bit more work to make the seams harder to see, but at this point I was getting tired of the project and was also running low on tan filament from having printed so many prototypes.

Of course, I had to completely re-print the core, since I had redesigned them to interlock with the corners and also to address some assembly issues found earlier. 

Much better.

With the design finished and all parts printed, it was time for the final build.  Assembling the core was difficult, as it’s very tightly packed in there.  All of the boards and other parts had pockets to hold them in place, and routes for wiring built into the plastic.  Everything had to fit in just exactly the right spots.

I even made mounting brackets to hold these four electrolytic capacitors, added to ensure a stable regulated voltage with the LEDs being PWM-switched.  These are almost certainly overkill electrically, but they were a convenient place to tie all of the 5V supply lines to.

First side of the core to be assembled.

The lithium-polymer battery is crosswise across the internal cubical space, as that’s the only place it will fit, and actually extends slightly into the space between faces.  Note the fanout from the capsense board.  Each antenna wire has its own channel in the plastic from the board to the antennas.  I hadn’t worked much with capacitive sensing before, and was worried about electrical interference and crosstalk, so I tried to keep each of the antenna wires away from the parts in the core.

Stitching the sides together with wire

Blue painter’s tape was used to hold parts in place temporarily until the rest of the cube was assembled around them.  The final steps of assembly were very tricky, as I was trying to carefully tuck wires and parts into pockets in the plastic as I closed the core parts up.

Almost there.  Just have to tuck these last wires in place.

The final wiring was installing the actual capacitive sensing antennas.  The wires from the capsense breakout board were each run out to one edge of the cube.  Initially I had planned to simply have metal rods running along each edge for the actual antennas, but that did not work well.  When using capacitive proximity sensing, the more surface area you have in your antenna, the more sensitive it will be.  I ended up using adhesive-backed copper foil along each edge, soldered to the antenna lead in the middle, and this gave me acceptable antenna sensitivity.  It did however slightly violate my initial goal of not having anything glued together, and if I ever want to disassemble the cube I’ll need to cut off the copper foil.
Taped together, but I'll live with that.

One thing that I was never completely happy with on this design was the charging port.  I needed to leave open a USB port where I could plug in a charger to charge the internal battery.  I couldn’t figure out a good place to integrate the charger into the cube’s design, and ended up just putting it behind one of the corners of the cube.  It’s not ideal, as you have to take the corner off to charge it, and the corner piece actually falls off easily as it’s not held in nearly as securely as the other corners are.  This would be something to think about if I ever decide to redo this design.

Not ideal, but where else am I going to put it?

This project was my first experience with embedded Python.  I’ve been programming in Python for years, but never tried the embedded CircuitPython version, and I was curious as to what you could actually do with it.

What I learned was that while it’s easy and fun to work with, and amazing that it works on such a small processor at all, CircuitPython is severely limited in its capabilities.  I was fighting with memory and processor speed limitations throughout this project.  Though it was a fun learning experience, if I had to do this again I’d just write it in C.

The code on this cube has to talk to three external devices:  the MPR121 capsense board, the LIS3DH accelerometer, and the chain of NeoPixel devices.  It also has to keep track of the state of 216 NeoPixels, and have unique animation routines for all six sides of the cube.  I discovered very quickly that the Trinket M0 running CircuitPython just doesn’t have the memory for all of this.  I couldn’t even load all of the libraries for the devices I was trying to talk to.  I ended up not using the LIS3DH library, instead using direct I2C access to read the accelerometer registers.  Along with careful pruning and optimization of my code, that got all of the functionality I needed to work.

For all the difficulty in getting it to work, the only thing that I ended up using the accelerometer for was to detect when the cube is being held.  I had originally planned to use a gesture-based system to select which side to light if I couldn’t get the proximity sensing to work.  I did ultimately get that to work, so the accelerometer is simply used as an on-off switch, to shut the cube off if it’s not being held.  The main loop polls the accelerometer and looks for changes in the readings, and only permits the lights to be on if there’s been enough change in the readings to indicate that the cube is being held.

The MPR121 capacitive touch board is really intended for touch sensing, with essentially no distance between the touch antenna and someone’s hand.  Unfortunately, I needed to have the foil antennas on the inside of the casing, with a shell of plastic between the antenna and the user’s hand.  With the initial settings, the sensors would almost never register contact.  With a bit of searching online, I found a register I could write to in the MPR121 that would increase the sensitivity enough to detect a hand at a distance.  This was also done with a direct I2C write, as the MPR121 driver did not include this function.

Glowy.

The code contains an animation engine which illuminates one side of the cube at a time, as determined by the location of the hand holding it.  Each side has a slightly different algorithm to generate the RGB values for the 19 LEDs making up the face, with a random effect to make a unique shimmering appearance for each side.  I tried to match the appearances to the arcanum runes shown on the show, although I had to completely guess for the Star and Earth runes as they haven’t been shown on the show yet.  There is also a ramp function, so that the sides will gradually fade in and fade out as needed.



The resulting cube probably runs for a few hours continuously, which should be enough for doing cosplay at a convention, if I was inclined to do that.  The truth is, I don’t really do cosplay, and mostly built this just as a learning experience.  Building the cube was educational and fun, but I’m not really sure what if anything I’ll be doing with it now.


Came out pretty well.  I think this is about the best match I can get, considering the materials and parts I have to work with.

I have posted all the files needed to re-create this, including the schematic and Python code, on Thingiverse at https://www.thingiverse.com/thing:3970763.

Sunday, July 19, 2015

Papercraft Pluto, and a papercraft planet pattern generator

Several years ago a friend of mine asked me to make a program for mapping a globe onto a twenty-sided die.  I wrote a simple Python script, some basic coordinate remapping and image processing with a simple GUI wrapped around it.  The script takes an image that's a flat projected map of a planet, builds a virtual icosahedron around it, projects the image of each part of a globe onto the faces of the icosahedron, and then arranged them on an output image along with fold lines and glue tabs where needed.

Other than sending it to the friend who requested it I didn't do anything else with the software until the recent flyby of Pluto by the New Horizons probe.  Seeing the images coming down I thought I'd try to make a papercraft globe of Pluto, once good surface maps were available.  The 20-sided shape that my script generated was a crude approximation of a globe, so I reworked it to generate an 80-sided geodesic that better approximates a sphere.

You can download the finished Python script here.  You will need Python 2.7.8 to run it, and you will also have to install the Python Image Library.  The program should be fairly self-explanatory.  There are buttons to load the source file, and save the finished destination file.  You can adjust the scale - by default it makes the output file have about the same DPI as the image file, but you may want to scale it up if working from a low-resolution image.  You can turn the glue tabs off if you wish, and set the color for the fold lines and cut lines.


There are also three sliders which are used to optionally rotate the pattern relative to the globe.  This is helpful if you want to arrange it so that some feature of the globe isn't on a cut line or vertex.

I'm still waiting for a good global map of Pluto to use.  So far the best I've found was unofficial and incomplete, but I was able to use it to make this:





(you can download the pattern to make your own here)  Once better imagery has been downloaded and released I'll put together a better globe.  But you don't need to wait, you can download the script and make your own.

7/29/2015 update:  I found a better surface map here and used it to make a higher resolution papercraft model.

Monday, June 8, 2015

Building my PSP (PiStation Portable) Retropie gaming station.



After seeing this project on Thingiverse, I decided to build my own portable Retropie gaming console.  It looked easy enough to do, there were software builds available ready to install on a SD card, and it would be an excuse for me to gain more experience with Linux and on the Raspberry Pi.  Of course, I couldn’t just build the existing design as-is, eventually redesigning the entire case for the features I wanted.  I really wanted to improve the ergonomics and packaging efficiency of the design, to make something that would fit well in my hands and be easy to play and that wouldn’t be any larger or heavier than absolutely necessary, something that I could sit and play on a long car or train ride for hours without getting hand cramps.  I also wanted some features lacking on the designs I saw, including built-in battery charging, headphone jack, and a USB port available for loading ROMS.

I designed the printed parts in Solidworks.  I've been slowly teaching myself Solidworks over the last half a year, after finally getting completely fed up with the terrible 3D drawing capabilities of AutoCAD.  AutoCAD is a fine 2D drafting program, but a terrible 3D drawing program, and I'd been hitting against its limitations for a while.

Of course, I bought the original parts for this project about a week before the Raspberry Pi 2 was announced.  The Pi 2 would have made certain parts easier, having more processing power, more convenient mounting holes, and more USB ports, but I decided to press ahead with the parts I already had rather than start over with new parts.  If I build another one of these, I’ll redesign it for the Pi 2.

Nearly all of the parts came from Adafruit, the main exception being the video screen which is a cheap car backup camera.  The screen claims to need a 12V input, but I found that it runs just fine on 5V - the 3.3V switching regulator on the screen interface PCB still handles the lower voltage.  It does get a bit warm, and I suspect that there are parts in the regulator that are running more current that intended at the lower voltage.

I initially was going to use the same cheap multi-color membrane pushbuttons that everyone seems to use, but after trying them didn’t like the way they felt.  Too stiff and too clickey for my tastes.  I decided to use these slightly more expensive illuminated mechanical pushbuttons instead.  They cost more and take up a lot more space behind the panel, but they have a really smooth action and actual mechanical contacts inside instead of a membrane switch.  Being illuminated in a range of colors was a nice added cosmetic bonus.  I’m still using one of the membrane buttons for a control mode switch, and intend to use a second for a power switch once I get the soft power circuit working.

The controls are all managed through a Teensy 2.0 acting as a joystick/keyboard USB device.  The Raspberry Pi doesn’t have analog input, and I wanted an analog joystick, so the USB solution was the easiest way to go.  

I originally had a design involving 2 analog joysticks plus a D-pad and about a dozen buttons before coming to my senses and realizing that a single joystick and 8 buttons were enough for any game I’d be emulating.

There is one additional button not being directly used by the joystick.  This button is an input to the Teensy which changes its mode from a joystick to a keyboard.  When in keyboard mode, the joystick is mapped to arrow keys, and the buttons are mapped to a handful of selected keyboard buttons:  escape, return, tab, and some of the function keys.  This lets me navigate the setup menus and file transfer utilities without having to plug in an external keyboard.  The second USB port on the Pi is still accessible from the outside of the case, so I can still plug a keyboard in if I need to.  Mostly the external USB port is to be used to transfer game ROMs with a USB thumb drive.


Originally I planned to use a large 5V USB power pack for power.  This did not work out well.  These battery packs are designed for charging cell phones and don’t like to be used for other purposes.  The output protection circuit trips very easily, I wasn’t able to get it to play nice with a Mausberry soft power switch, and trying to use an audio amplifier to power speakers would trip the battery off when any loud sound played.  The voltage output from this pack is badly regulated, the screen would flicker as the voltage varied and there was a lot of noise in the audio from the Pi when using it.  It was also impossible to play games while charging the battery - when the charger was active the voltage output would get very low and erratic, the screen would flicker and the audio buzz, and plugging or unplugging the charge cord would cause a momentary power interruption that would reset the Pi.  










That battery pack was also a giant inconvenient brick that I had trouble fitting in the case.  

 After several frustrating weeks trying to get it to work I switched to a discrete battery and power boost /charger board, which works much better.












I still haven’t managed to get a soft power function working, with power on via button and power off automatically after shutting down Linux. The Mausberry doesn’t seem to have any easy way to work with the boost/charger board, so I’m working on my own latch circuit that uses the enable pin on the boost regulator.  It shouldn’t be hard to get to work, but until then I’m just using a toggle switch for manual power control.

The audio noise went away when I changed the battery, but the audio quality is still not great.  This is mostly due to the default audio output on a Raspberry Pi being rudimentary at best, but also apparently partly due to the game emulators not being quite powerful enough to smoothly reproduce the audio output on some of the consoles.  The SNES is especially bad, when there is a lot of movement on the screen the audio output gets really choppy.  If I really cared I could install a HifiBerry I2S plugin board, and then overclock the Pi to better handle SNES emulation.

I went through a lot of design iterations getting the shape right.  I wanted something that I could print in as few pieces as possible, with controls that were comfortable for my large adult man hands.  Widely spaced mechanical buttons and an smoothly-acting analog joystick won out over a D-pad and membrane buttons, even if it made the wiring and placement harder.  I struggled with getting everything to fit until I decided to solder the video, power, and USB connections directly to the Raspberry Pi board rather than use the provided connectors.  This saved a tremendous amount of space, especially for the composite video feed, although it means the Pi isn’t likely to be re-used for another project now.


The other breakthough on the design was having the video screen front panel outside the printed case.  I figured that it had a nice-looking front bezel already, so why not use it as-is?  Fitting the screen outside the case rather than wrapping the case around it saved space and made the packaging easier.  With directly soldered connections to the Pi I was able to fit the Pi, Teensy joystick board, battery, and power boost/charge board entirely in the space behind the screen.  That just left small extensions on either side for the joystick and buttons.  This was the point that I decided on the “PiStation Portable” name.  I hadn’t originally intended to model it after a PSP, everything just came together that way.  Ironically PSP games are quite hard to emulate, well beyond the capabilities of a Raspberry Pi.


The end result is quite compact and comfortable to hold, and I was just barely able to print the front and back halves as single pieces on my 3D printer.  It was very tight - the case is about 237mm wide at the widest point, and my printer has a 250mm diameter circular print area, so it was coming really close to the edges of the print space.  It did take several tries to get the back case to print successfully, it has some really difficult overhangs.






I’m running a standard copy of Emulationstation 2.6 on an 8gb flash drive.  I know that 3.0 is out now, but it looks like changing over to that will mean having to replace all of my ROMs from scratch.

So far I have Atari 2600 games working very well.  I found a ROM pack of what appears to be every 2600 game ever made and installed it - they only take up a few kilobytes each, so I had plenty of room.  Most of them haven’t aged well, but I do still enjoy Yar’s Revenge.  I have managed to get the Gameboy and Gameboy Colors emulators to work, but Gameboy Advance emulation still doesn’t work.









NES emulation seems to be the sweet spot for this design - there are a lot of fun games available, and the Pi emulates the NES very well.  













SNES emulation works, but the framerate suffers at times and the audio is choppy.  Getting MAME working will be my next goal, I should be able to play a lot of the older classic arcade games on this.

The only remaining hardware changes I intend to make to this one are to try to figure out a soft power switch as mentioned above, and to add a low battery light to the front panel.  There is a low battery light on the power management board, but it’s shining out the back of the case at the moment.  I need to find a spot to put another light visible from the front, so I have some warning to save my game and shut down before the battery dies.

If I had to do this over from scratch now, I’d start with a Raspberry Pi 2.0.  More USB ports, faster processor, better audio circuitry, and a more compact SD card slot.  It would mean a significant redesign of the case, and probably different wiring for the video and audio connections.  I’d also try to fit miniature speakers in somehow, so I could at least have some sound without having to plug in headphones.  An amplifier board and volume control would also be nice - the full volume output of the Pi is still fairly quiet.  The joystick/keyboard mode switch should probably be a small slide switch instead of a button, but other than that the ergonomics are perfect.



Plans, such as they are, are posted here.

Friday, September 5, 2014

GenCon 2014 recap



 I went to GenCon 2014 and had a great time.  I made the two-day drive out along with my wife and another friend, staying over in western PA because I'm getting a little too old and weary to drive 13 hours in one day.  Next year I might fly instead.

GenCon itself was, as always, hugely crowded (something like 56,000 attendees this year?).  Despite that the convention itself ran smoothly.  The Will Call line was amazingly fast and efficient this year, and the convention center itself seems to still have plenty of room.  The surrounding city is showing more strain, getting housing was a nightmare and getting food required waiting an hour or more in line.

Most of my time at the convention was spent gaming.  I go to GenCon for the gaming events, and this year I was fortunate enough to get into nearly all of my first choice of events.  When I wasn't at games, running between events, or waiting in line at the food trucks I did manage to get several hours of demo time in with the new little walking robot.  The robot did great - held up through the entire convention, and ran through about four of the five battery packs I had for it each day Thursday, Friday, and Saturday.  Radio reception was only a problem when the antenna came loose from the transmitter - easily fixed by screwing it back on tightly, but I might want to secure it better for next time.  It had enough traction to walk well on the convention center carpet.  Tile floors were a problem, so I avoided them, and I never got around to trying it outside.

I don't have any video of the robot at GenCon yet.  Running the robot takes two hands, and I can't work a camera and make the robot walk at the same time.  I've been looking on Youtube for uploaded videos of it, but haven't found any yet.

I did go through some spare parts.  I had two servos fail due to the robot switching on while still in my carrying bag.  I was in the habit of keeping a battery half-inserted while walking around with the robot in the bag, so it would be easier to pull out and switch on for a demo.  It turns out that if I hit the robot just right I would jostle the battery into place enough to power on the robot.  The first thing that the robot does when powered on is center all the servos, and when this happens while in a confined bag it can result in stripped servo gears.  I will be updating the software in the robot so that it doesn't send any motion commands to the servos until it receives a valid radio signal.

I had two servos in the robot destroyed when someone stepped on it.  I don't know if it was on purpose - I had originally thought not, but the person who did laughed and ran off when I confronted them, so it may have been intentional after all.  Fortunately it was easy enough to repair the damage to these and the other two failed servos.  I didn't even have to remove them from the robot, just open them up enough to swap the gears out.

One servo failed spontaneously when the feedback system failed.  It locked up at one end stop, and then when I tried to test it erratically smashed back and forth between the travel limits until the gears failed.  I haven't taken it apart enough to find out what the problem was - I suspect a broken wire or solder joint, but when the servos cost less than $3 each I'm not inclined to put much effort into troubleshooting them.  This was a slightly more difficult job than the others since I had to replace the entire servo, which also required taking the core of the robot apart to get at the wiring.  Still not a big deal, the bot was designed to be modular and I had all the tools and spare parts in my convention bag.




Late on Saturday night the transmitter failed, a broken connection in the wiring to the left-hand joystick.  I didn't have the tools with me to troubleshoot or repair the damage, and was just about ready to collapse in exhaustion anyway, so I just packed it up and was done with the robot for the convention.  The transmitter was re-used unchanged from the previous robot, and is really in need of a complete tear-down, redesign and rebuild soon anyway.  The failure only meant that I wasn't able to show the robot off on Sunday, which was not much of a loss since Sunday morning was when we were packing up and heading home anyway.

The robot was a great success at GenCon.  Up; until Sunday my demo time was only limited by the amount of free time I had between events, which admittedly wasn't much.  I never ran out of battery packs, but I did get down to my last pack for the day more than once, so I didn't have much wasted capacity.  I only had one servo fail due to non-external causes.  That last bit really surprised me - I was expecting these cheap servos to fail just from the effort of walking around, but they held up far better than I expected them to.


The big question everyone kept asking was where I got the robot - and when I told people I made it myself, was I planning to sell them?  I'm still not ready to actually sell working, finished, consumer-ready robots.  It's a huge investment in time and money to actually set up, and I really don't want to be the one doing customer support for a potentially large number of hand-made robots breaking in the field.  While the robot itself seems to work for a while without breaking, the servos are fragile and easy to break with careless handling.  Furthermore, I'd still be hand-making each robot, and even with the 3D printer it takes a while to build all the pieces for one.  That means a lot of my time invested in each sale, and I'd have to charge an unreasonable amount to make it worth my time.


I do plan on publishing the 3D files, schematics, and source code so people can make their own reproductions of the robot.  I may be willing to sell kits of parts at some point as well.  Stay tuned.

Tuesday, August 26, 2014

Building the new robot for GenCon 2014

My little walking robot, that this blog was originally created to describe, gradually beat itself to death through performing at conventions and Makerfaires over a period of several years.  Broken servos were easy (if expensive) to replace, but eventually welds cracked in the legs and the servo control board developed intermittent faults.  Fixes to the structural problems just made it heavier and pushed the already overloaded servos further.  About a year ago I gave up and declared it dead.

Earlier this year I decided to rebuild a new walking robot from scratch.  I had at one point looked at tiny inexpensive plastic-geared micro servos as a possibility for a walking robot.  Initially I thought them too weak and small for use in any walking robot, but after seeing several successful robots using them I decided to try and rebuild my walking robot based around them.


I knew from my earlier experimenting that these micro servos would burn out if I ran them at 6V like I had in the earlier robot.  Rather than drop the 8V from a two-cell LiPoly down to 5V or lower, I decided to just run the servos directly off a single cell LiPoly instead.  4V is less than the maximum these servos should be run at, but I figured that it would help them last longer without overheating.  I wasn’t going to be getting much torque out of them, so I’d need to make the robot as lightweight and small as possible.


I made as much of the structure as possible out of 3D-printed parts.  My original justification for getting the 3D printer was to print parts for robots.  I spent a few years making homemade transformers and other fun things instead, but now I’d finally be getting to making robot parts.  The printer was really great for this job, the fact that I could make parts in complex arbitrary shapes, compound curves which would be very difficult to make with sheet metal and internal stiffening ribs without welding or machining, really helped with my goal of making the bot with as few overall parts and fasteners as possible.  


Thanks to the 3D printer I was quickly able to go through multiple sets of test hardware, tweaking the design to get the clearances and geometry just right. It also meant I could fairly easily make an entire set of spare structural parts.  I didn’t expect to need them, but once I had the design finished it cost very little in materials or time to print more out.


I kept the same overall proportions as the previous robot, but scaled down everything by about five-eighths compared to the original.  I wanted to try and make the legs as short as I could get away with, reducing the torque load on the servos while still keeping the legs long enough for decent speed and mobility.  The center sphere, which in the original had been made from a three-inch copper tank float, would now be a plastic ball about two inches in diameter.  The leg span at full extension would be just about eleven inches.  I expected to be able to reduce the weight to about a quarter of the previous design. 

Sadly the printed plastic parts don’t quite have the aesthetic charm that the old polished metal ones did.  My robot’s gone from a steampunk inspired hand-made design to one that looks more like a mass-produced toy.  The final colors were somewhat accidental - I had a different color scheme in mind originally.  I printed out some test pieces in white, then switched to red and yellow, colors I don’t use much outside of test prints.  I liked the resulting look enough to make the entire robot in those colors.



I decided to switch to easily replaceable battery packs rather than attempt to cram in a single battery capable of running for an entire convention.  I got a really good deal on five single-cell 380mAh battery that would just fit inside the two-inch sphere, with enough space left over for the radio receiver. Of course, I added battery protection boards onto each of them to make sure that the robot wouldn’t go up flames in case of a short circuit.  I designed a printed shroud to go around the battery which I hoped would make it easy to swap out batteries without needing tools at the convention.  Unfortunately the plastic snaps came out stiffer than I'd have liked, and I needed to use pliers to pull the battery out at the convention.  It was still reasonably easy to swap the battery packs out.




With the battery pack and the Xbee radio taking up nearly all the space inside the robot, there wasn’t enough room for the Xbee breakout board I had used previously, let alone that and a Pololu SSC or Arduino Mini to do the serial-to-servo conversion.  I had to make my own controller board, using tiny right-angle headers mounted sideways on the board and fitting the PCB itself directly between the pin headers on the Xbee radio.  The board would have to hold a PIC16LF873A microcontroller, 3.3V regulator for the MCU and radio, clock generator and other required components, as well as the connectors for the battery and servos.  The servo leads and connectors actually took up a lot of the interior space - when you only have a 2 inch sphere to work with, trying to fit 8 3-pin headers takes up a painfully large chunk of the available real estate.

I designed the PCB using the layout tools I have available at work, and then ordered it through OSH Park.  OSH Park was quite easy to work with and helped me configure my PCB design software to produce the right output files for their process.  The cost for the three boards they sent me was amazingly low compared with other prototyping services, only $9 for three identical boards which was even less than it would have cost me to set up to etch them at home.  The quality was a lot better than I’ve ever been able to do with etching myself too.  They also had no problems with the boards being odd, non-rectangular shapes, unlike most prototyping services that require rectangles of predetermined sizes.  The only downside to OSH Park’s service is that it’s not speedy, the batch-process system they use to keep costs down means they have to wait until they get enough orders before they can send boards to be manufactured.



The radio receiver, controller board, battery, and connectors occupy a box about an inch square down the center of the two inch sphere center body.  It's really tightly packed in there.  I had to make cutouts in the PCB and battery support structure for the inner mounting tabs of the leg servos, and leave channels in the surrounding support structure wide enough to feed the servo leads through.


The firmware I wrote for the controller in the robot is really simple.  It’s essentially doing the same job as the Pololu SSC I used previously, but with a simpler protocol, lower data rate, and coarser resolution.  The receiver takes a data stream at 8929 baud (it was supposed to be 9600 baud, but a PIC16LF873A running off a 4mhz crystal can’t actually match a 9600 baud rate) with each servo encoded as a single byte of data, and outputs eight 0.524ms to 2.500ms pulses, one for each servo.  The output resolution is fairly coarse (about 0.7 degrees per LSB) but I figure that these cheap all-plastic servos are going to be lucky to be within five degrees of the commanded position anyway so it really doesn’t matter.

I used the same transmitter as on the previous version of the robot.  The only change I made was for the new serial output format for talking to my controller instead of the Pololu SSC board.  I did have some problems with the transmitter at the convention, and I’ll probably be completely redesigning it for next year.

The controller board was the long pole in the project, once it was done and programmed everything came together quickly.  There were a few design issues with the board that I had to fix with cutting traces and soldering additional parts on. For one thing, the Xbee receiver uses a lot more current than I realized, requiring me to solder a larger 3.3V regulator on.  I’ll be updating the PCB files and publishing them once I’ve cleaned up the design.

With these cheap little servos, and my previous experiences with them failing after a few seconds of running under load, I wasn’t sure that this robot would even be able to hold up its own weight without breaking.  I was therefore pleasantly surprised when the new robot not only stood but nimbly walked around, waved and rolled over just as well as the old one had.  Some quick testing showed that a single fully charged battery would be good for fifteen minutes of solid walking, and that I was able to go through several full batteries walking the robot around my living room without any servo failures.  Testing at work showed that the radio range was more than sufficient for the robot to still walk while at the other end of the longest hallway in the building, something that I had been worried about as there was no room for any kind of external antenna on the robot.



With everything tested and seeming to work, I packed the robot and all its spare parts and was off to GenCon.

Monday, August 4, 2014

Adding a second hinge point to cheap micro servos

Several years ago when looking for cheap servos to use for my walking robot I purchased a handful of HXT900 micro servos from HobbyKing.  They seemed like an incredible deal for less than $3 each, but after brief experimenting I gave up on them.  They were very jittery, not terribly strong, and when run at 6V the motor would burn out quickly if the output was stalled.  I tossed them in the junk box and forgot about them, writing them off as not usable for my robots.

Later, at Makerfaire NYC I talked to a maker who was developing kits for a hexapod robot that used 18 HXT900 servos, who had been having some success getting them to work.  I also some very impressive projects online of robots based on these servos, which was enough to make me reconsider my first impression.  My old quadruped walking robot was completely wrecked from many weekends of running demos, so I decided to build a completely new one from scratch based around the HXT900 servos.

The first thing I needed to do with these servos was add a second hinge point to them.  The knee design my robot has uses the servo case as half the hinge joint.  I'm using the same design as on the previous robot, but scaled down, using a 4-40 weld nut, 1/4" OD spacer, and 4-40 machine screw for each servo.






The first thing that needs to be done is completely removing all the stickers from the outside of each servo.  They'll prevent you from opening the case, and the tolerances on my design were tight enough that the stickers were being damaged when I installed the servos into the prototype chassis anyway.





The hole for the rear axle needs to be directly opposite the output shaft.  In theory I should have made up a jig for this, but just eyeballing it seemed to be close enough.  The hole doesn't precisely locate the axle point anyway, so it only needs to be approximate.





For plastic this thin, a drill bit would be overkill, and would probably risk shattering the case.  I used a good sharp Exacto knife to carve out the hole.  Again, the diameter of the hole is not critical, it just needs to be large enough to clear the barrel on the weld nut.


 Then glue a weld nut to the inside of each servo case.  The weld nuts I used just barely fit inside the rear of the servo case.  This helped with alignment - the sides of the servo case held the nut in place, so the position of the hole in the case didn't really matter so much.  You'll also want to make sure to remove any inspection sticker or other residue from the inside of the case before this step so the glue bonds effectively.


The spacer and screw are then temporarily put on to help clamp the weld nut against the inside of the case while the glue sets.  I'll be having to remove them later to install the servo in the knee joint.


 Finally here are two of the servos (pre-modification) installed in a test prototype for the new 3D-printed knee joint, next tot he same structure on the old robot.  You can see that the new design will be much smaller and lighter weight.  I'll also be taking a lot of advantage of the 3D printer's ability to make complex arbitrary shapes for the new robot's structure.

Monday, May 12, 2014

Gencon 2014 scheduler update

 I have updated my scheduling script for GenCon 2014. I had originally not expected to have to make any changes to the code, but GenCon this year moved the location of their event catalog files, and decided to only release the event catalogs in xlsx format instead of csv.  While you can still use last year's version of my scheduler by manually downloading and converting the catalog files, I've modified my code to use a converter utility to do the conversion.

The latest version of it can be found here.

In order to use this, you will need to install Python 2.7.  You will also need to install this xlsx to csv converter code. After installing xlsx2csv, you'll have to copy the xlsx2csv.py file from the install directory into the same directory that the schedule solver python file is located.

The GenCon event registration system is also limiting event wish lists to 50 items this year, so the wishlist generator will limit itself to that number of wishlist items.

As before, this is an experimental and somewhat crude schedule optimization utility.  It allows you to search the event catalog with a text-based interface, add events to your wishlist with assigned priorities, and then generates an optimal schedule for you, as well as a wishlist to enter into the GenCon registration system.