Balancing vehicle parts & instructions
The goal of this page is to have enough information for hobbyists to make their own balancing vehicle: a scooter, unicycle, autonomously balancing robot, or whatever else. I'm sure I've left some important details out, so feel free to ask me questions and I'll try to both answer them and add the answer to this page. It's a few solid days of work to build one after you have all the parts, so this page is pretty dense.

Circuit boards

There are two circuit boards, one for the microcontroller, gyros and accelerometers and one for driving the motors. There's a 20-pin cable between them. The main reason to have two separate boards is to keep the sensitive analog electronics away from the high current switching transients in the motor driver. You'll want to plan ahead to mount them several inches apart.

Both board use mainly surface mount components. If you haven't built these kind of boards before, you might want to practice on a simpler one first. While you can solder these with a regular fine-tipped soldering iron, it's better to use a temperature-controlled hot plate so you can place all the components with solder paste, and melt the solder all at once. This process is fast, and makes rugged and reliable circuit boards. Some of the components are 0402 size, meaning about 1 mm by 0.5 mm. Unless your fingers are nearly this small, you'll want to use tweezers. I use a 20x stereo microscope to make sure everything is aligned right, but you can probably manage without one if your eyes are good. Sparkfun has a good tutorial on reflow.

The yaw gyro, which needs lower precision, is on board. You can either solder the 32-pad BGA version or a DIP version. Unless you have experience soldering BGA chips, use the DIP.

The design uses the fairly recently developed high-capacitance MLCC ceramic capacitors, which provide up to 10 microfarads in a tiny package. They're now better and cheaper than tantalum capacitors.

The microcontroller board has space for some extra stuff which you may or may not want. It supports 2 strain gauge inputs, 2 optical quadrature encoder inputs, 4 foot pressure sensor inputs, 3 gyro inputs, and a RS-232 serial interface. You can leave off some of the components if you don't need all the above features as indicated in the BOM. Currently, my scooter uses 1 strain gauge input (for steering,) zero quadrature encoder inputs, zero foot pressure sensor inputs, 2 gyro inputs, and the serial interface.

The board calls for some 10k, 0.1% precision resistors. They aren't very expensive, about $10 altogether. You can use 1% resistors, but you'll have to do more calibration.

For each board, you can download the Gerber files (which you can send to a board shop to get them to make you a PCB,) a bill of materials (giving parts numbers and sources for each component) and a PDF showing where to place the components in places where the silkscreen on the board isn't quite legible. Someday I'll get a batch of PCBs made and sell them at cost. Or if someone else wants to do this, let me know.

Here are the design files for the microcontroller board:

  • PCB Gerber files for sending to a PCB shop: download
  • PCB design files for Eagle: download

Now for the power driver board with all the big MOSFETs. Ideally, this board should be fabricated with thicker copper layers (4 oz rather than the standard 1 oz) to handle the high currents.

The MOSFETs are mounted up through the bottom of the board and bent outwards, so they can be bolted down to a heat sink plate. The IRFP2907 MOSFETs have an insulated mounting hole so all you need are the silicone pads, Digikey part BER120-ND. You use them dry, without grease. Be careful: some similar looking parts like BER131 are not electrically insulating.

Rather than one huge wire connecting the board to the motors & batteries, it uses several 16 gauge wires in parallel. (By the way, 4 16AWG wires have the same amount of copper cross section as a 10AWG wire.) It's easier and more reliable to solder multiple small wires than one large wire. There are 8 wires each for battery positive and negative, and 4 wires each for the motor leads. For current sensing to work, you have to route some of the wires through the holes in the current sensors. The 8 B+ wires go through the current sensor at far right. The 4 MA wires go through the left current sensor and the 4 MC wires go through the middle current sensor, all in the obvious direction. The wires terminate in connectors a few inches away from the board, with 10 AWG wires on the other side. See the wiring diagram and picture.

The board also calls for ceramic decoupling caps placed on the bottom of the board to handle the large current spikes from switching MOSFETs.

Be careful about changing any of the wiring. I had something specific in mind when I designed it to ensure that current is shared evenly among the batteries, wires, PCB traces and MOSFETs. There are lots of other ways to wire it up that will seem to work, but will cause failures such as melted wires, melted PCB traces, blown MOSFETs, or overheated batteries under hard operation. It will show up when the scooter suddenly fails and tips over at high speed or during aggressive maneuvers. You'll wish you'd done it right in the first place.

This board has a tricky combination of parts on both sides. Here's the best way to build it:

  1. Apply solder paste to top SMT pads.
  2. Place all components with tweezers.
  3. Check that everything is aligned perfectly.
  4. Reflow the board on a hot plate.
  5. Cut and drill the aluminum heat sink plate (drawing below.)
  6. With pliers, bend the leads of the TO-247 MOSFETs 90 degrees just above where the lead thickens.
  7. Lightly screw them all into the heat sink plate with leads pointing up.
  8. Settle the board down on top of the MOSFETs so all the pins stick through.
  9. Solder the MOSFET leads on the top side.
  10. Trim the leads sticking out of the top of the board.
  11. Unscrew the MOSFETs from the heat sink plate. The board is free again.
  12. Solder across SJ1 (under the DC-DC converter.)
  13. Mount the thru-hole components (capacitors, connectors, DC-DC converter.)
  14. Mount the current sensors. Solder the fat mounting pins while holding it in place, then the small pins.
  15. One at a time, route the power wires through the current sensors, into the hole and solder them on the bottom. You should bend them on the bottom side to actually touch the MOSFET lead they're connected to. Remember, solder has high resistance so you want copper touching copper. Make sure the wire doesn't stick down below the back side of the MOSFET, because it'll contact the heat sink plate.
  16. Group the power leads together, cut them to length, and put connectors on the end. Refer to the chassis wiring diagram below.
  17. Solder the ceramic decoupling caps on the bottom of the board.
  18. Using tweezers so as not to get skin oil on them, place the heat sink pads onto the heat sink plate aligned with the holes. Place the PCB over them, and insert the screws. Make sure the pads are aligned straight and tighten down the screws.
The point of soldering the MOSFETs while they're held in place by the mounting holes in the heat sink plate is to make sure the solder joints won't be under any mechanical stress when you do bolt them down. Since the MOSFETs can get hot, solder will creep under any stress. Also, you should try to make sure the wires aren't under much stress by wiggling them back and forth a couple times near the MOSFET after everything's soldered in place.

Here are the design files for the power board:

Electrical

The batteries, disconnect relay, and wiring need to be fairly beefy to handle the large currents drawn by the motors during a maneuver. At cruise it only draws 10A or so, but it can peak at over 200A during an abrupt acceleration or deceleration.

You'll need:

  • 2, 36 volt 3AH NiMH batteries to get a 4 mile range. The best bet is to buy two 30-cell GP3300SCHR NiMh packs from Robot Combat. You can put in more if you like, using additional relays to connect them when active. I've got the equivalent of 4 of the above packs to provide a 10 mile range. You could also use Li-Po cells, but they'll lighten your wallet more than the scooter. The back of the envelope calculation is that for an extra $1000, you can save 3 lbs and still get a 4 mile range. More range costs proportionally more. It wasn't worth it to me, since the scooter's weight is just part of the whole system including a 200 lb rider, who really ought to lose 3 lbs himself. A unicycle, on the other hand, benefits greatly in maneuverability from shaving a few lbs.
  • 1 CRS03-02 gyro made by Silicon Sensing Systems, available from Newark.
  • 1, 5 volt beeper, Digikey part 102-1120-ND.
  • 1 on-off switch. One of the interlocked kind, where you have to pull it out before toggling it, might be a good idea. McMaster part 7337K97 looks good. Neither this switch nor the kill switch needs to handle high currents.
  • 1 "deceased individual's" switch (a boating supply store will have nice replacement units for jet skis)
  • 2, 5k potentiometers and knob.
  • 1, 20-pin cable between boards, Digikey part A3CCG-2006G-ND
  • 1 high-current relay, Digikey part PB491-ND
  • 2 fuse holders, Digikey part F1087-ND. Get some 10 amp fuses for early testing (Digikey part F1015-ND) and some 40 amp fuses for street use (Digikey part F1220-ND.)
  • Some 10AWG stranded, 16AWG stranded, and 20AWG stranded wire.
  • 12, 45A Powerpole connectors from Powerwerx.
  • Heat shrink tubing. Don't use electrical tape for this project, no matter how half-assed you usually are.

Follow the chassis wiring diagram. The two batteries are normally connected to individual charging jacks. When you turn on the switch, it engages the relay which connects the batteries to the motor driver board and to each other. This gives you redundancy if one battery fails, and lets you charge them separately. It's important to charge them separately: NiMH batteries can go boom if you charge them in parallel.

Make sure to use the appropriate gauge of wire as indicated in the wiring diagram. The fuses are pretty important, since fresh batteries can deliver several hundred amps, enough to melt copper wires. Two 40A fuses will give you enough power for any reasonable maneuver. (The recommended fuses can withstand a pulse of 200A for a second or so before blowing, which should be enough to get you over the top of the loop-dee-loop :-).

The diagram shows how to route the B+, MA and MC wires through the center of the current sensors. Pay attention to connecting the battery wires to the right terminals, since current sharing between the batteries depends on getting it right.

Do a good job crimping the connectors for the high-current lines from the batteries and to the motors. You don't want them melting at high currents, or opening due to vibration. I've tried to crimp them with pliers and vise grips, and it can't be done properly. Powerwerx sells an affordable crimp tool. The 45A powerpole connectors will accept either a 10AWG wire, or 4 16AWG wires. To connect to the relay you'll need yellow quick-disconnect female connectors, Digikey part WM18234-ND.

I used 5mm coaxial power connectors for the battery charge input, but I'd probably use Powerpole connectors if I were doing it again. I used Powerpole connectors at the battery terminals to make them easily removable.

If you're using a strain gauge for the steering sensor, connect it to connector XSG1 on the microcontroller board. The cable should be shielded.

The PCB allows for 3 adjustment knobs on the dashboard, but I only installed 2. I use one to set maximum speed and steering rate and one for whatever parameter I might be tinkering with at the moment. There's also a beeper to alert you when you're approaching any of the operating limits.

Connect the CRS03-02 gyro to the XPITCH connector. For the gyros and accelerometers to work right, orient things as shown in the picture.

Electromechanical parts

Mechanical parts

You'll get the best results if you make these parts with an accurate milling machine, but you can probably make something acceptable with hand tools if you're good at that sort of thing. There are machinist drawings for everything.


Top Plate

Handle Mounting

Wheel Hub

You can either build your own spoked wheels or buy some small & heavy wheels that bolt onto the NPC motors. The spoked wheels are larger and lighter, so you'll go 40% faster.

To build your own spoked wheels, you'll need a good-sized lathe (a Sherline won't work, but a 7" hobby lathe is probably enough,) a drill press, and layout tools. In addition to the hubs described in the drawings, you'll need:

  • 72, 178-mm spokes and nipples. Your local bike shop should have them. The length you need may vary depending on the exact rim you buy. Unfortunately, it's not that easy to calculate.
  • 2, 20" steel rims, tires and tubes, also from your local bike shop
or take the easy way out and buy:
  • 2 NPC-PT5306 wheels from Robot Combat.
  • 2 NPC-PH448 hub adaptors from the same place

Test, charging, and programming system

You'll need:

  • A PC running FreeBSD or Linux.
  • A 10 pin header to DB-9 adapter and a long serial cable.
  • An Atmel STK500 programming system, Digikey part number ATSTK500-ND.
  • 1 or 2 Astroflight 112D chargers, available from Tower Hobbies. (If you just get one, it'll take twice as long to charge the batteries.)
  • 1 or 2, 12V 20A power supplies for the above. Parts Express sells a good one.
First, get the source code and figure out how to compile it using avr-gcc to produce a .srec object file, which you can download to the flash memory on the microcontroller.

There are two ways to program it. The first is using a dedicated programmer like the STK500 connected through the 6-pin header labeled "PROG" on the microcontroller PCB. The STK500 connects through a serial port to your PC, where you run avrdude to download the .srec file through the STK500 into the microcontroller. The second, more convenient, way is to install a bootloader in the flash memory using the first method, then download new code to it over the serial port. The serial port is also useful for capturing debugging output. Avrdude should work with this, but I haven't tried it. There is some more technical detail in the README file in the source directory.

Getting it running

There are a bunch of things you can get wrong when hooking everything up. Most likely, you'll have one or both of the motors backwards so that the balance feedback goes the wrong way. This will cause the scooter to lurch when you start it, so start it gently with your hand on the kill switch. It works best to start with one motor disconnected. If the active wheel makes it sort of balance, then it's right. If it takes off, switch the wires and try again. Then get the other motor right. Finally, make sure the steering works in the right direction. If it doesn't, you can swap terminals 2 and 3 at the XSG1 connector.

...needs more...


Copyright 2007, Trevor Blackwell. Home