Wednesday, August 22, 2012

The long and (not so) tragic tale of the hub motor

Alright, where to begin... I've spent most of the last week in the EC (my dorm) courtyard working on a variety of large Rush projects (showing the new freshmen what we're about with some large-scale engineering insanity), but I squeezed in a bit of time towards my hub motor because I really wanted to finish it before classes start.

I knocked out the rest of the winding from about 2-3:30am leading up to my 5:30am flight:

Note that my C phases (top right and bottom left, here) look far cleaner, I got better at winding as I went

Then, everything ever arrived! I carefully marked one end of each of my magnets with a Sharpie (it doesn't matter which end, just that I was consistent)

Shipped with plastic spacers so that they're actually, you know, separable...
I also got two 1" thick 4" diameter aluminum rods, a big sheet of 1/4" 1018 alloy steel (high magnetic permeability), a whole bunch of #4 screws and nylocks, and two 1/2" ID 1-1/8" OD sealed bearings. I decided to start with machining the aluminum into my endcaps, because the Edgerton shop happened to be open, and they have Nice Machines.

I started by drilling a 1" hole with the most monstrous thing I've ever seen in a tail stock:



This gave me room to fit in a very large boring bar, so I could take big swaths out of the inside of the part to create the internal features. Here's the part with most of the dimensions rough-cut to about .02" from their final finishes:



To get the feature which holds the bearing in place, I actually had to run the lathe in reverse and work the boring bar across the backside of my part:



And here's the final pass which I did with a much smaller boring bar:



Yay! Now, for the holes which I've been dreading...

Actually, I was very happy to discover that Edgerton's CNC-capable mills have a circular hole pattern function built in, where you just zero the machine on the center of your part, enter in your pattern parameters, and hit go!

Post-magic shot 

After machining both endcaps, I went ahead and Magic'd my can out of my 1/4" steel plate:



I had to file down a couple of the slots to fit magnets better, but overall the can didn't require much finishing on my end. Anyway, with most everything else completed, I decided to move on to wiring connectors onto my stator. I realized that the slot I'd cut into my axle wasn't going to be deep enough to allow 16 gauge wire to pass through, so I had to mill it wider. I just eyeballed this one, since precision isn't a factor and it doesn't need to look pretty.




And with the bearing fit on over the wires:

I had to mash these down with some pliers to get them to lie flush, but they did comply eventually.


Okay, time to actually place magnets! I just used superglue because I didn't want to wait on epoxy to cure, but it still ended up being something of a lengthy process. I started out with the screws in for alignment, but after I'd gotten several of the magnets in they held the can together pretty rigidly.



Some of the way into this process I made a very poor decision and wanted to find out if the clearance between the magnets and the stator was actually large enough to prevent them from scraping.



My shirt got a bit eaten in the process. Oh well, at least the clearance was good! Anyway, here's both halves of the can, which I later stuck together using J-B weld due to its magnetic properties (the steel paste wicks into the gap between the can halves and creates a pathway for the magnetic field between the closest two magnets).



I then bored out the core of one of my scooter wheels (oh yeah, the scooter I bought shipped) to be a good press-fit with the larger center can segments, and pressed it on:



Starting to look like something now. Well, time to actually place the stator into the can! And when I say place, I mean "oh god lower it slowly and not by hand otherwise explosion and death". Here's a picture of my somewhat hilarious looking rig to accomplish this:



I put a bolt on the end of the axle and then chucked it into a drill press to lower it carefully and in control. The strength of the magnets was actually shifting the drill press table, the clamp, and the vise all around in order to force itself into alignment with the stator.

Immediately after dropping the stator into the can, I realized that I hadn't remembered to actually align the holes, and sure enough they were completely off. Well. Time to get creative? I used the dual-vise method (what, you think I have vise-grips that big?) to force the can around and align it with the holes in the cap.

I wish I could tell you this was the lulziest rig I used all night, but sadly...

Alright, almost done! Now to just put the other endcap on and tighten a few screws...



And bolt it to a random plate to actually take it for a spin...

You can see Shane in the background hooking up an airplane ESC to a power supply to drive my motor
And... crap. It just sort of jerks around and it's quite hard to spin by hand. Charles identified the motion as consistent with when he placed one of the magnets backwards in a motor, so I took everything back apart. Yes, that means this again:



I identified the incorrect magnet using one of my spares and checking which had the wrong orientation, and then chiseled it out with a hammer and small flathead screwdriver. I glued in a new magnet, this time in the correct orientation, and placed the stator back into the can. And tried to run it again. And... Crap. Again. This time it would rotate almost a full revolution and then suddenly kick back, as well as still being difficult to rotate by hand. Apparently this was consistent with when Charles wound one half of a phase backwards (i.e. two teeth are wound incorrectly). Evidently he's encountered most of the problems you can find while building hub motors, which is fortunate considering that I'm managing to experience most of them on my first build alone. Well, back to the drill press.

Fortunately, the fix wasn't as terrible as I'd initially anticipated, because I only had to swap the lead of one tooth from star point to input, and the opposite for the other. After that, I got to put the stator back into the can one final time, reassembled everything and tested it out:



Yay! It actually works! Now to mount it in a scooter...

Fortunately, Johnscooter had been lying about rather dejectedly, so I got the honors of dropping my motor into it to ride it around. There was, however, a small problem: my motor is about 1/8" wider than the mount at the back of Johnscooter. Time for the double-clamp-spreader-clamp! Amidst cries of "oh god no" and "that is a terrible idea", this monstrosity happened:



And, well, it actually worked. Here's a final picture of the motor bolted onto the frame:


And a video of me taking it for a quick spin:


Fortunately, the "tokka tokka tokka" noise evidently resolved itself shortly after this was taken. Also note that I'm using a placeholder motor driver here which is outputting about 500W, the final one I'll be using will be capable of something more like 1000W. Overall though, looks good!

Next I'll make a big battery pack, I'm thinking of 3 packs of 12 A123 cells each, which should provide quite a substantial amount of battery life (and at ~40V nominal, no less). I'm also going to be making a full custom scooter frame, hopefully before classes start. It might be a couple weeks until I post again, given that my time is going to get progressively more eaten by Rush, but I promise that as soon as I finish my custom frame I'll write it up!

Wednesday, August 8, 2012

Hub motor! (ohgodherewego)

Since clearly I wasn't feeling MITERS-y enough having built just a quadcopter, I opted to tackle a scooter as well. (Okay, that's kind of false, really I've been wanting a faster way around campus for a while and Charles had a super giant BLDC motor stator he threw my way on the cheap).


68mm x 38mm 12 tooth stator in all its massiveness

Also of interest is how I'm building a scooter, which as far as I can tell amounts to approximately the weirdest way that one could possibly conceive of/design a scooter - I'm designing a scooter around a motor which in turn I'm designing around a stator. The only reason for this is that I just happened to acquire a stator before anything else (generally just getting a stator that matches your other constraints is probably a good idea).

If you'd like a crash course in BLDC motors, read the really super handy hub motor Instructable. No, really. Read it. Basically the stator is a big chunk of iron made up of a bunch of thin iron sheets which are then laminated together, and epoxy (that green stuff) is slathered all over the inside. The sheets/lamination allow for a high degree of magnetic permeability in the radial direction and much less in the axial, which helps direct the magnetic fields generated by the coils outward, towards the motor can/permanent magnets (don't worry, I'll show you what these are in a second!) and back inwards towards the next coil.

So, without further ado - the actual motor!

Together and with kinda transparent endcaps
Fancy exploded view!

So, from left to right, we have:
  1. Left endcap
  2. Left bearing
  3. Axle
  4. Tire/wheel
  5. Can
  6. Magnets
  7. Stator (shown with coils)
  8. Right bearing
  9. Right endcap
The endcaps are to be turned from solid aluminum stock, the bearings are 1/4" ID 1-1/8" OD high-load sealed McMaster bearings, the axle was turned from a giant aluminum rod found lying in MITERS scrap, the wheel... well, we'll get to the wheel a bit later, the can is a solid steel tube with channels for screws to pass through, and the magnets are 1-1/2" x 1/2" x 1/8" high strength rare-earth neodymium.

Let's get on with the first machining work for the project, the axle:

Note that this is AFTER a significant portion of material has already been removed

Here you can see a giant chunk of pre-axle aluminum, chucked into one of the super classy lathes at the Edgerton student shop. I did some huge passes until I got close to the flange sticking out of the left end of the axle (rendered above in the exploded view), which serves to easily place the axle into the stator without worrying about positioning it. I then worked the right end of the axle down to the correct sizes, arbitrarily deciding that I'd treat the end currently chucked as the left side. Finally, I drilled out the end with a #7 drill bit (.201") so I could put 1/4"-20 threads in it later.

This thing spawned an incredible amount of aluminum chips

I then flipped the part and chucked the center to finish off the left side as well:



I decided that I didn't want the axle to be press-fit with the stator because then it's less easy to take out/replace and I don't trust press-fits quite as much as axle pins. Thus, of course I had to do it the Classy Way and machine a rounded channel to stick a pin through. I threw the axle on a mill, cut out the channel for the output wires to escape from, and like 8 slooowwww eyeballed passes of a 1/16" ball mill later I had a reasonably good approximation of a 2mm pin channel.

Did I mention how much cutting oil I went through?

And a couple shots of the finished product:

Shiny!

You can't see the pin, but trust me it's there. And yes, it's just the unfluted half of a #47 drill bit. Whoops.

Threads were added to the ends a bit later.

Alright, as for the down-and-dirty motor-y bits: coils are on 3 independent phases - the A, B, and C phases. Each phase, in turn, has two each of both capital and lowercase winds (where capital indicates one chirality and lowercase indicates the opposite), so if you were to write out a typical (dLRK if you know what that means) winding 'scheme' it would look like this: A a b B C c a A B b c C. Note how there's one letter for each tooth, and in my case I used capitals for clockwise and lowercase for counterclockwise. I calculated I'd need about 88 winds per phase to get the amount of torque I want (how? READ IT) and I decided I could probably cram that much 20 gauge wire around each tooth. This was a bit of a mistake, as I discovered when I tried to wind it in series with two strands of 20 gauge and found that I couldn't quite manage to pack it in close enough. After failing at winding this in series, I settled on a parallel winding scheme to make winding the motor physically easier. The capital teeth all connect to a common "star" point and the lowercase teeth each go to their respective letter's output cable. With the parallel approach, instead of 22 turns with two strands of 20 gauge wire it's 44 turns of one strand of 20 gauge, which is a bit physically easier to manage.

As you can see, "a bit" easier still isn't easy

Well, it was a fun several hours of wrestling wire into areas smaller than it wanted to go, and after the experience I have a few pieces of advice for anyone else wanting to do this:

  • MAKE SURE that your iron core is fully epoxied everywhere the magnet wire will be coiled around. If you see a gap then seal it with super glue otherwise you'll be stripping coating off the wire and causing a short
  • Take a small wooden dowel to pack down your windings to create more room. I ended up whittling the end of one down as I went so I had something small and pointy to manipulate the wire with. DON'T use a metal flathead screwdriver/metal anything else to do this, or you WILL strip off your coating and have to restart
  • Measure (multimeter) and make sure your windings aren't shorted to each other/your axle/the stator core as you finish them, so you don't have to redo them later
  • Double (and triple, and quadruple) check your chiralities before you start wrapping! Make sure you stay consistent with direction between your windings
I only got as far as 8 teeth wound (2/3rds done!) before I was somewhat displaced from the area I was winding in. I'm going to finish while I'm at home Friday, I promise! I don't want to let this hang over me when I'm back in Boston starting Saturday.

Anyway, here's where I'm at:

A couple of the teeth look downright disgusting, but if it works, it works!

tl;dr if anyone links me this or this I may get slightly irritated. It's quite possible I'm terrible at the whole patience thing.

Anyway, now that I'm at a bit of a stalled point as far as windings go, I decided to go ahead and order the scooter I want - this one, owing primarily to its 140mm wheels, which are large enough to comfortably accommodate the rather fat stator (and magnets, and can). The current plan is to get the scooter, measure/CAD the handlebar attachment and wheels, and then design my entire frame around the constraints of my hub motor, the front wheel, the handlebar, and the vast amount (well, 30) of the A123 3.3V battery cells I picked up.

I've also decided I'm far too lazy to want to machine all those slots in the steel can, so instead I'm going to opt to kitmotter it and just waterjet a bunch of half-circles complete with screw slots out of 1/4" steel (this will also give me the advantage of being able to include placement slots for the magnets so I don't have to worry about making separate spacer plates for them just to glue them in the correct places). I'm also going to have a fun time of drilling all the through holes in the aluminum endcaps, but frankly that's about the laziest solution I could come up with for holding everything together, so I can live with it.

I'm hoping to tear through the rest of this when I get back on campus, hopefully I can have most everything out of the way prior to REx because my life is going to get completely sucked away by EC stuff for about a week.

New blog and old projects!

Alright, so while I'm over in Washington jumping out of planes and with very limited shop access, I decided my downtime would present the perfect opportunity with which to categorize some old projects, as well as things I'm currently working on. Hence the start of yet another generic Mechanical Engineering blog!

I figured I'd start with an old project of mine which I recently got working again: Derpcopter! This is one of the few of my projects lying in the "Actually Finished" category of stuff I built/am building.

Derpcopter was initially conceived as both a good way to make my first foray into CAD, and to satisfy my high school graduation requirement of a senior project.

So, the first Real Thing I ever CADed:


Yes, that's right. AutoCAD for a 3D assembly. It was all I knew at the time, and it got the job done. Notice how this design is currently lacking any motor mounts whatsoever, if I recall correctly I actually just made those in Visio (the only drawing software available on the computer hooked up to the laser cutter). I was initially intending for the lasercut parts to be acrylic, but ended up settling on polycarbonate because it's much stronger/less brittle. (Note: don't ever ever lasercut polycarb, unless you want all manner of delightful brain damage which I probably have by now).

The platform was based on the Arducopter build of the beginning of 2011, when the project was still very much in beta. Knowing approximately squat about electronics at the time (not that I can really say much has changed on that front), I just went with their default Ardupilot Mega hardware and Arducopter firmware, some 30A ESCs, APC 10x4.7 props, and these actually pretty decent motors.

I specced out 5/16" aluminum squaretube for the arms, 1/4" polycarb for the frame and 1/8" polycarb for the electronics mounts. It turns out 5/16" squaretube with 1/16" wall is commonly used in upscale railings (who knew?) so I picked up a few lengths for free from a contractor who no longer had use for them (not to mention they came pre-painted a sexy matte black). As for the polycarb, TAP Plastics has this great scrap bin in their stores where you can pick up excess sheets for practically free.

After making three or four passes on the 1/4" polycarb at max laser power with low speed and succeeding at nothing other than charring lines all over the place (and throwing around all manner of nasty fumes), I opted to swap all the structural components to 1/8" as well.

From that point, machining/assembly went pretty smoothly, and I was able to finish the wiring/electronics assembly with much digging through old forum posts to find any and all relevant info. If you're looking to build an Arducopter now you'll have a much more pleasant time of it, considering documentation by this point is far more substantial.

Finished build, weighing in at a whopping ~2.6 lbs with battery:


I uploaded the firmware, calibrated ESCs, mounted props and decided to see if Derpcopter would lift itself a bit. I applied what I thought was just a little bit of throttle, and immediately WHRRR-CRACK!
Derpcopter flung itself sideways straight into a wall, instantly shattering three of the props. Not only did I grossly underestimate the amount of thrust the over-specced motors I used could produce, I'd also failed to double check directionality of the props and one of them was backwards. Well, crap. I'd only bought one extra of each direction of propeller, so I was stuck waiting over a week for new props to ship (and yes, this time I bought like 10 spares).

Unfortunately I had to present the project before the new props actually came in, so I just spun it up a bit without props mounted to show my teachers that yes, it actually seemed to do what it was supposed to, which evidently was enough for me to pass with the project.

New props came, I put them on in the correct direction, flew around my neighborhood a bit, and then I must have given it a few too many hard landings because eventually Derpcopter became pretty much uncontrollable. I monitored direct sensor outputs from the Ardupilot on my PC and noticed that one of the accelerometers was spitting values completely all over the place. Derpcopter thought it was shaking like crazy, so the reason it was impossible to fly was that it was actually just trying to stabilize itself (even though it was already stable) and thus jerking all over the place. At this point I was nearing the end of senior year, and shelved the project in the "I'll fix it eventually" basement shelf.

Come the end of freshman year at MIT, I started spending some time over with these guys, who inspired me to dust off Derpcopter and bring it back to life. I noticed an inadvertent but quite convenient feature in my design:

It folds!
It turns out that converting Derpcopter into travel mode only requires taking out a total of 6 screws, yay! Anyway, I brought Derpcopter into my lab to work on, where a perceptive friend noticed that a smoothing cap on the APM board was toast. Whoa, that would explain bad accelerometer readings! Here's a picture with the rather hilarious looking not-at-all-surface-mount replacement cap:



Looks good! Now to upload the new firmware, and.... crap. It turns out that APM has upgraded their boards and are now based on ATmega2560s instead of 1280s. This means my old board doesn't have enough memory to support the modern Arducopter firmware. The solution? Upload firmware manually using Arduino, after having commented out parts that are irrelevant to my uses (there is a lot of bloat on the main Arducopter code, there are ridiculous amounts of features).

Somehow in the process of screwing with firmware I managed to get the plane edition of the code. My quadcopter spent several hours fully convinced that it was a plane before I finally got correct code to compile and upload. Planes like to go at mid throttle when the throttle stick of their controller is all the way down. See why a quadcopter that thinks it's a plane is a very bad thing? Fortunately I didn't have props mounted on it, so Derpcopter just spent a while happily spinning all motors when given no throttle input as I tried to figure out what it could possibly be doing.

I finally got Derpcopter running, fixed orientation issues, and adjusted PID values to get something flyable.


Yay! No one is dying! It still flies backwards (the taped arm should be the front, at the moment it's treated as the back), but I can live with that for now. When I get back to Boston I'll take some footage if it doing crazier stuff over Briggs Field, but for now you'll have to be satisfied with the first working test flight.