Friday, September 13, 2013

Helmet Required: Self balancing unicycle, part 1

2nd post!  I'm blogging like a real boy now, though hopefully this second go around is along the lines of an Empire Strikes Back/Godfather II, as opposed to a Two Towers/Boondock Saints II.  It's pretty jargon heavy, though, just to warn anyone who's not intrigued by microcontrollers, serial communication interfaces, and feedback control systems.

A little less than a year ago I was killing my lunch hour at work by sifting through the various posts on Hackaday when I came across a project that I found very intriguing.  A self-balancing unicycle is not a novel project anymore (a quick search on Hackaday yields about half-a-dozen similar projects), but I liked the look of this one; the handlebars would give it a motorcycle feel while zipping around on one wheel, cool! After reading about this project and a few similar ones, I decided that I wanted one.  More importantly, I wanted to build one. I had started a project the year before that involved using a motor controller and a PID feedback loop to control a small robotic arm that never got finished for a lack of time and money. It wasn't my robotic arm, but one that belonged to the Robotics and Automation Society at Portland State, and has since been absorbed into another project. The unicycle will be highly reliant on a well-tuned feedback system, however, so I can still experiment with PID and build something that is potentially harmful to those who use it, namely me...perfect!

The project from Hackaday was built using an Arduino microcontroller, a pre-built inertial measurement unit (IMU) from SparkFun.com, and a SyRen 25A motor controller.  In other words, the fundamental electronics alone are going to run about $170.  This seems a little spendy, especially considering that some of the IMUs from SparkFun are just the gyro and accelerometer ICs on a small PCB with some minimal bypassing caps and pull-up resistors.  By laying out all of the necessary ICs and passive components from the above three units on a single custom PCB, one could have all of the same features with a smaller overall footprint, less interconnect wires, and also some cool peripherals for probably 2/3 the price.  Granted, this means a massive amount more time to look up the right component values, build parts and footprints in EagleCAD, and layout a board, but that's kind of part of the fun of doing a project like this myself. So I decided early on that I would design my own PCB that incorporates a microcontroller, 3-axis accelerometer, 3-axis gyroscope, appropriately sized motor controller, and terminals to wire up lighting, a display of some sort, safety interlocks, and maybe some shooting flames...intentional ones!

Now to choose some components.  For the microcontroller, I had initially decided to go with the Atmega328P, mostly because I've done some projects with it before, both on Arduinos and as a stand-alone chip, so I'm fairly familiar with it's architecture, how to wire it up, and laying it out. It also has a relatively inexpensive programmer/deubugger in the AVR Dragon. I've also done some projects with some of the microprocessors from the LPC family of ARM devices from NXP, though I've never done any of the programming for these, so I may switch further down the road to get more familiar with an ARM device.  I think at this point I want to stick with what I know, though, or the learning curves on too many fronts (PID, I2C, IMU, AVR/ARM...FML) may appeal to my intrinsic laziness and keep this project from ever happening.

The ICs that will make up the IMU are a L3G4200D 3-axis MEMS gyroscope by ST Micro and an ADXL345 accelerometer from Analog Devices. I have no knowledge of either of these types of devices to make much of an intelligent decision, but they will both operate on a 3.3V I2C bus, and they can output data at rates in excess of 100Hz, which is the read rate of a Segway.  With a maximum gyro resolution of 2000 dps (5.56 revolutions per second) and an accelerometer with a tunable full scale range of 4g to 32g, bi-polar, I should have lots headroom for dialing in the PID loop. To assist in working with an IMU for the first time, I want to put in some kind of graphic display to view the output of the two ICs in realtime.  Newhaven makes a 2x20 character LCD display that also operates over I2C for $10...done.

That takes care of the core components for the unicycle's 'brain'.  The drive system is something that I haven't entirely pieced together yet, other than looking at some hefty H-bridge ICs.  I think a conservative approach that will lend itself nicely to prototyping sans hematomas will be to use a scaled down battery and motor with a test jig that will allow me to work on getting all of the components to play nice-nice.  Ideally, the jig will only allow the scaled down vehicle to tip in 1 dimension as well as translate in that same dimension, removing the need for a rider to make balance adjustments in the second horizontal dimension.  Once I get something balancing in the jig, then it will be a matter of scaling to a system with more torque (bigger motor, bigger battery, more current) and a higher moment of inertia (me on a padded seat).

That's the game plan so far.  A quick look at Digi-Key and OSH Park for the devices mentioned above and they're related necessary circuitry puts the price at about $72.00.  For the next part of this series, I hope to have some electronics in hand and a better idea of how the jig is going to work.  Grad school is starting soon, and work is getting a little crazy, so it's possible that this has to sit on the back burner for a while.  On the other hand, fall is nearly upon us in Portland which means the amount of time spent inside due to inclement weather is going to be going up sharply soon.

No comments:

Post a Comment