Showing posts with label Scooter. Show all posts
Showing posts with label Scooter. Show all posts

Tuesday, January 22, 2013

Introducing the BE3P

In a bit of a departure from my typical posts, I'm going to write one about something that doesn't actually physically exist yet: a brushless 3-phase motor controller I've spent the last week working on with my friend Erik; the BE3P (Banks Erik 3-Phase). Traditional brushed motor control effectively provides the motor with an average DC voltage and then brush contacts in the motor shift as it rotates, causing the magnetic field generated by the coils to always attract the next set of magnet poles, producing torque. Brushless control is a bit trickier, because this switching of the field needs to be handled in software, i.e. the controller needs to determine where the motor coils are in relation to the magnets in order to switch current through them accordingly. We got a bit of a crash-course in brushless motor control from our friend Shane as well as a few online resources, then we immediately started browsing for the major components. We decided to make the controller optimized for the hub motor I built, which probably isn't able to handle more than about 1200 Watts peak. My battery runs around 40V, meaning we're aiming for ~30A peak. Since exploding your components is kind of bad, we over-specced everything a bit (especially the MOSFETs) in order to (hopefully) be able to handle 30A at 40V peak without substantial heatsinking. We centered our design around an Atmega328 microcontroller, an HCPL3120 optocoupled gate drive, and surface-mount MOSFETs rated to 120A at 60V.

Just to warn you, I'm going to try to start basic but this post is necessarily going to get progressively more difficult to understand if you don't already have some idea of motor control theory.

Okay, quick intro: the easiest way to control the average voltage (voltage relates to speed) given to a motor is by taking your battery voltage and pulsing it (relatively quickly, on the order of 10's of kHz) across the motor. You can vary the exact average by controlling the duty cycle (percentage of time that you're applying battery voltage) of the pulses. This type of voltage control is called PWM. So, how do you quickly switch between battery voltage and ground? Transistors! A MOSFET (metal-oxide-semiconductor field-effect transistor) is a type of transistor that can turn on quickly and takes relatively little power to do so. Effectively, the MOSFET has a capacitor ("gate") inside it that turns the "switch" on when you give it a voltage on the order of ~5-15V. "Okay, sweet, my Arduino can do that!", you say? No, not exactly. The problem is that the MOSFET doesn't behave nearly as nicely while the gate capacitance lies between 0V and the "turn-on" voltage of ~5-15V. While your Arduino would (actually it wouldn't, Arduinos have fairly fragile output current limits) be able to drive an "ideal" MOSFET (zero resistance between your output pin and the gate capacitor), in reality there's some amount of resistance along that path, which means that there'll some nonzero amount of time required to charge the gate up. Why? Physics. It ends up being much more efficient to drive the gate with higher voltages (~12-15V) in order to throw higher currents (remember that current is rate of charge flow) into your gate, charging it faster.

So now we need something that can quickly switch between 0 and 15V to drive our MOSFET which can quickly switch between 0 and ~40V. What, you thought this was going to be simple? (I'm not even going to go into other problems like the necessity of bootstrapping your high-side nFETs to enforce gate drive voltage between the gate and the source by leaving the source voltage floating). Well, this is where gate drivers come into play. Gate drivers are devices that can throw quick bursts of charge onto your MOSFET gates. Perfect! The gate drivers we picked out are opto-coupled, which basically means they have a tiny LED inside them and they dump charge onto your FET gates whenever the LED is turned on. This is great, because it means that all your little 5V microcontroller has to do is turn on an LED in order to drive the motor. Additionally, it means that your 5V systems and your 15V systems are only connected by light, which protects your low-voltage electronics and prevents high noise levels on your signal wires.

All of the above basically needs to be copy/pasted 3 times for brushless 3-phase control, which I'm not going to try to explain too heavily so as to avoid turning this blog post into a dissertation. The main important thing is that for "sensorless" control, meaning the controller doesn't directly know where the motor coils are relative to its magnets, it needs to have voltage sensors on each of the phases such that it can turn one off at a time and sense the voltage coming back out of it, from which you can determine the "electrical position" (basically the position of the coils relative to the magnet poles) of the motor, which in turn lets you drive it to the next desired position.

Okay, now that we've gotten physics/theory out of the way, let's move on to the interesting part: actually designing. Not only is this my first foray into brushless motor control, it's also my first time using Eagle CAD for a major board as well as using surface mount parts at all. This was basically a "learn everything as you go" style project for me, so I just kind of jumped into Eagle and started designing.


Here's an early schematic which shows the absolute basics. I'll explain starting from the far left, because that's sort of the direction of flow for this design. First there's a 15V switching regulator, which converts the 40 volts off of the battery down to something more manageable. Next, a feedback and filtering circuit which allows the 15V regulator to operate and cleans up its output a bit. I then have a 5V linear regulator which converts the 15V down to 5V in order to power the microcontroller. The giant box with lots of pins is the microcontroller itself (Atmega328), which then connects to a couple of status LEDs, as well as the three giant boxes you see in the middle of the schematic. The boxes are inverters and they along with the little resistor and capacitor to the right of them form a little circuit that takes the PWM signal from the microcontroller, splits it into two opposite signals and adds a little delay between turning each side off and turning the next on. This delay is a form of shoot-through protection, which means it avoids allowing the high-side and the low-side to turn on at the same time, which would directly short your battery through both FETs and explode everything. To the right of this inverting circuit you can see all 6 gate drivers, and finally the 6 FETs that they're driving.

Next, I moved on to adding the voltage and current sensing circuits. The current sensing consists of a very small (.001ohm), high current resistor in series with the motor phase, connected to a sensitive differential amplifier, which determines the voltage drop across the resistor and thus allows you to calculate current passing through the whole phase. Current sensing is extremely useful for a variety of reasons: (warning: physics) it allows you to calculate the phase-lag between your drive voltage and the current response of your phase (because your motor is an RL circuit), and since current is what you really care about in terms the position of the motor (because current creates flux which in combination with the field of the magnets applies torque), you need to offset the voltage by that detected phase-lag in order to time the torque with your phases switching electrical positions. Current sensing also allows you to do some nice things like over-current protection, constant-torque control, and the ability to detect shorts between the outputs and (hopefully) save your FETs from detonation.

As for voltage sensing, it's absolutely essential for DC sensorless control because, as I said above, it's the only way you can determine the electrical position of the motor.


Here you can see the current sensors (small boxes to the right of the FETs, and only on 2 phases) followed by the voltage sensors to the far right. The voltage reading is passed through a 2-stage RC low-pass filter, because there are lots of high-frequency voltage transients across the undriven phase due to the PWM on the other two and you want a smooth signal to determine the electical position.

With the absolute basics out of the way, I moved on to adding various extra stuff, including bus capacitors to smooth the voltage across the FETs/provide them with clean-ish power, a battery voltage sensor, a 20MHz oscillator for the microcontroller, an ISP header so I can actually program the microcontroller, throttle/extra input (or output) pins, and finally an XBee header so that the controller will be able to support wireless data transmission.


Yay! With the schematic finished (after like 4 days of staring at datasheets), I moved on to actually laying out the board. I definitely wanted it to be able to fit in my scooter, so I decided to make the outline 2.75" by 3.75".


I'd never laid out a board before, so this was my chance to learn Eagle's board layout features. I experimented with a couple of different general layouts before I settled on one I actually liked, the picture above is one of those early layouts.


This is the general layout I ended up settling on, you can see the massive power and ground traces on the left side of the board, and away from everything but the FETs and bus capacitors.


Here's a snapshot from the end of the first day of laying out, I got a little panicked about how much space things were taking and started trying to cram everything together towards the bottom, which in retrospect was a little bit of a mistake. It turns out I had more space than I thought, so cramming made my layout look pretty disorganized. On the plus side, however, this meant that the last third or so of routing went extremely quickly because there was an abundance of space available.


Here's the finished board design with everything routed, and I also added a logo on the back as well as name/date/credits on the front middle.

Erik and I each independently created our own boards and schematics because we wanted the additional practice, and for our PCB order we just put 2 of each of our boards on a panel. We also ordered enough components for 4 boards, so if all goes well we'll end up with 2 controllers each.

For now, it's time to wait for parts to arrive, which we can fill by starting on the code for the microcontroller. Basically, I'm going to enjoy spending a few days staring at massive spreadsheets which tell me which registers do what.

Hopefully that was at least somewhat intelligible for people of varying levels of experience, let me know if you have questions about the design/components/whatever.

Monday, December 3, 2012

Big update part 2 of 2: Finally!!

Well, it's certainly been an adventure, but I'm pleased to announce that I actually have a finished fully custom scooter frame! I'll save you some anticipation and just give you a look at the final product first:

aergaerga

There it is, in all its water-jetted aluminum glory. No Gorilla tape this time, I swear!

Alright, now let's dive into the juicy build report:

I started off blocking out a general shape I wanted the deck to end up looking like, using rough dimensions from my battery pack and how big I estimated a scooter should be. I wanted a slight natural curve for the deck, so I made a few splines and then tweaked them until I liked how they looked. I also disassembled my stock scooter to take measurements of the plate to fasten the front fork. This is about where I was as of my last post, part 1 of the mega scooter build series. After I had a basic shape I was happy with, I fiddled around with the orientation of the battery pack by CADing it up and spinning it around. I decided I liked the vertical orientation best because it actually minimizes the height of the scooter (which is important, considering how tall it has to be to accommodate the battery at all), at the expense of widening it a bit. I also played around with the spacing of the motor controller until I had something that was about as closely-packed as it could get.

I decided to primarily build the scooter out of 1/8" aluminum rather than 1/4" to minimize its weight, and building the entire thing out of 1/4" would probably make it a lot stronger than it actually needs to be. However, this requires some additional design considerations because 1/8" is too thin to just drive screws into its end. I ended up going with three different fastening schemes across my scooter, because each made the most sense in its own area of application. Here you can see all three schemes I used in one shot:


So, why the three different fastening methods?

I didn't want to be riding around in a pure right-angled box, so I wanted the front to have a somewhat visually interesting look, resulting in the angled nose design. The problem, however, is that traditional waterjet T-nut corner blocks are inherently 2D extrusions, which wouldn't be able to hold the separate front plates together. I decided to instead waterjet the top profile of the corner supports, and then post-machine and tap holes on the front (angled) faces.

In the middle of the body, I had a long stretch of top deck I needed to link to the sides, but I was extremely constrained by the width of the battery (I wanted to build the smallest frame I could). I decided to place 2D T-nut blocks on the outside of my side plates, sticking up into the top deck, so that they didn't take up space in the interior.

For the back, however, I had some space to spare because the motor controller has a smaller cross-section than the battery. I was able to fit in some angle brackets to hold the whole body together in the rear.

Here's a shot where you can see how the basic body all came together, this is just really an extension of the previous picture:


And another shot with transparent walls so you can see the insides:


Somewhere around here I realized that I'd probably want a brake eventually, so I just added a mount for a brake shaft to the sides near the rear wheel:


I was pretty impatient to start on the body itself, so I decided to finish the brake later and go ahead with cutting the parts for the frame.

Yaay, the magic of the metalprinter!
I decided that the easiest way to place the holes in the front end of the front plates (remember, the ones I said I'd have to post-machine) would be to just clamp the whole front assembly together and drill the holes by hand using the holes the waterjet cut from the front plates as guides.


I also went ahead and just attacked everything with a countersink, I decided it was worth the effort to use flat-head screws and not leave pan-heads sticking out of every surface on my scooter.

Here you can see the front assembly mostly complete:


I also made a slight design error and placed the nuts holding the front fork mount a little too close to the front corner blocks, so I had to bandsaw away some material to allow the nuts to clear the corner block.



Next there was a lot of tedious counter-sinking and tapping, but I was able to put most of the body together and it ended up looking pretty nice:


I had really wanted to finish this scooter for Maker Faire New York, but I was still lacking a front fork and some basic necessary components. Some attempts involved hand-drill and hacksaw insanity with my original front fork, as well as trying to fuse my scooter body with Shane's:


I didn't quite manage to get either method working, so I decided to just enjoy the fair for a while and let my scooter sit until I got home and had access to a real shop.

When I got back to Boston I started working on a brake and handlebars. I wanted a small-profile brake that would spring back, so I designed a little aluminum brake with a slot in it for a leaf spring:


I then cut it out and put it together.


And mounted it on the back of the frame.


I also noticed that I had made a small design error on my hub motor: the nylon nuts were on the same side that the wires exited, causing them to clip the wires a bit and shred off some of the insulation.


I just put some additional heatshrink over the parts that were ripped up, and backed out and reversed all of the screws holding the motor together.

I had to extend my original front fork because the much thicker deck required a lot more ground clearance. I also had a bit of a problem because the original scooter's fork is made of welded sheet steel in geometries that are really hard to fasten to. Originally I'd intended to just drill holes in the steel, build an aluminum cage around it with bolts going all the way through both sides. I had also put a couple of haphazard hand-drilled holes through the original during Maker Faire, which made things a bit trickier.


I ended up not completely compensating for the bends in the original fork, so it refused to quite fit into its intended slot. I ended up just throwing the whole aluminum cage in the mill and attacking the corners with a giant endmill. The original fork took quite a lot of coercion (of the hammering variety) until it would fit in the cage, at which point the holes were no longer in alignment. I decided that due to how solidly it was pressed in and because it's only ever really getting loaded downward, I would just leave it sans through-bolts.

I added a throttle to my original handlebars, then some wiring and loctite, and it was done! The battery, motor controller, and motor were all identical to the previous iteration, so it handled about the same as the sketchy Johnscooter conversion, but it certainly felt better not having the battery just taped onto the deck.

Hopefully I can post a video of it cruising soon.

I've also spent the last month starting two new major projects, so I'll have posts for those written up shortly!

Monday, October 1, 2012

Big update part 1 of 2: Scooter progress!

I feel sort of guilty about writing a blog post when I don't actually have any substantial progress done, so I've had a bit of a blogging hiatus while classes started up and my projects slowed down. However, at this point I've definitely gotten far enough to justify a blog post (well, a two-part one, you'll see a logical separation point here), so I'll just pick up where I left off last time:

The battery!

Well, as mentioned previously, I decided to go with a 12S 3P (12 cells in series and 3 of those in parallel, for 36 cells total) LiFePO4 chemistry battery, cells courtesy of an A123 donation to the MIT Electric Vehicles team. I started off just grabbing a big pile of battery cells and metering them to ensure they were at or close to their nominal 3.3V potential, then running hot glue down the sides and sticking the pack into the shape I wanted. Next, I started glomming solder down on the ends of the cells where I'd be connecting them.


You can also see I've started to add thick copper braid to the cells on the left, which serves as the power line through the battery. I went ahead and connected each set of 3 cells in series, then soldered on small (24 gauge) balancing wires which were color coded for my own convenience. These wires allow the cells to be balanced individually to the same voltage when charging, and prevent degradation of your battery (or possibly exploding cells) which would result from trying to charge the pack while some cells were at significantly lower voltages than others.

I hot glued everything down to prevent it from shifting around
I then soldered on the main power outputs at the very front and back of the pack, and finally flipped everything over and repeated the same process using the braid to form the power line, only instead of balancing outputs I placed wires across the parallel points to help the battery discharge evenly.

You can see the gray wires equalizing the cells in parallel
Finally, I obtained some of the biggest heatshrink tubing I've ever seen, and slid the battery into it:


Half an hour later (okay, maybe a slight exaggeration...) with a small heat gun:

VoilĂ !
A battery!

Only... it turns out I forgot the middle power outputs, which basically break the battery up into two separate packs that can be charged individually at half the voltage of the entire pack, enabling balancing by most hobby chargers. Oops. Time for some battery-surgery.

Here's the heatshrink cleanly separated at the top
I pulled the pack back out of the heatshrink, soldered on the other two sets of power output wires, and slathered hot glue over everything.


Finally, I applied a new section of heatshrink, charged it up (in something on the order of 20 minutes. Turns out this ~6.6 Amp-hour pack can happily charge at 15-20A within ratings), and was possibly a bit over-eager to ride around with the extra power. The result?

Notice how the brake no longer looks functional? Yeah, the brake was no longer functional.
I successfully made everyone at MITERS cringe by mounting my battery exclusively with Gorilla tape. Don't worry, 100% legit engineering here.

In the meantime, I actually received my slightly more powerful shady Chinese brushless motor controller in the mail, and immediately proceeded to snip off most of the useless cables on the box (powered brakes? side-lighting? Hah!), disassembled the case, and stuck a nice new coating of solder across the built-in current limiting resistor, halving its resistance and drastically increasing the output of the controller.

Current limiting resistor circled red
I reassembled the case, applied motor controller to scooter, applied battery to motor controller, and guess what? Everything actually worked! My scooter received an immediate upgrade to scary-fast, and at 6.6Ah, the battery will last much longer as a result. Assuming an average consumption of about 600W going at 20mph, the ~43V pack should last for about 28 minutes, or a little over 9 miles.

That's all for Part 1, but I'll throw in a sneak peak for next time right here:


Expect Part 2 to come in the couple weeks or so!

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!