Let's Make Robots!

Who doesn't want one? I want a mini autonomous segway!

It started with a garage sale. I came across a guy selling a lot of old school digital Vernier lab tools. I bought the good stuff and went home to plot an evil mastermind project. One of the things I bought was an accelerometer. I thought jokingly "now I can build a self balancing robot." The more I thought about it though, the more I planned. I went to Trossen Robotics' website and bought some necessary self balancing parts.

  • 2 Solarbotics gm3 (may be gm9) motors
  • 2 solarbotics wheels
  • 1 6 volt NiCd battery (AAA cells)

And then from Acroname:

  • 1 SN754410 quadruple half H-bridge

I already had an OOPIC II, but I was having program problems and it died (sort of, look for my OOPIC II sob story in the genral forum). In the main picture, the robot looks broken in half, that is because the OOPIC is a backbone of sorts. When I first built the robot, I was very excited but cautious. I decided to take it slow and just test the motors first. So I programmed the OOPIC to drive the motors forward 2 seconds, then backward two second and loop. I turned it on after programming, the motors turned forward two seconds, aaaaand didn't stop. Wonderful.  I tried again and this time the motors did totally random things. Stop, start, reverse, one stops, both go opposite directions. Ugh. I decided it was the H-bridge's fault so I sent it in for an exchange of a new one (gotta love returns). I tried again but with the same results. Doubler ugh. So then I took a very critical look at my program and found no errors. I also tried suggestions from members of the Trossen Robotics forum (which is pretty good. Interesting stuff on there). Nothing worked, so now I am convinced the OOPIC II was a little wicky in the wacky-woo. But that doesn't matter anymore cause it is half dead (again, general forum sob story). Oh well, here it is so far.

H-bridge

 

 

That is a close up of the H-bridge.

The himstergims on the right is the connector for the Vernier Accelerometer. I had to use the connector because the accelerometer itself had that goop stuff to prevent hacking. Doh!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
OddBot's picture
So far I've seen a few self balancing bots but usually that's about as far as they get. I hope you'll be able to get it to go beyond just balancing (which is no mean feat in itself) and have it roaming about. I think the secret will be having motors that have speed and torque to spare to handle being bumped but acurrately controllable so it's not constantly overcorrecting.

I've built a balancing robot.  (See it here:   http://www.justin.tv/clip/aa7f9ae5ece )

Torque isn't as important as speed, since you don't need much strength to keep an object near its balance point.  But as you get away from your balance point the required torque grows exponentially -- thus speedy, responsive, motors can keep you out of trouble while infinitely torquey motors will still fail if they can't move fast enough.

Backlash is a huge problem.  It's possible to use filters and advanced modeling to handle backlash, but for a first time balancing algorithm just find the tightest gearboxes you can.  You should feel little or no slop when turning the wheel by hand.

An accelerometer alone is not enough to balance.  A gyroscope alone is enough to balance for a while, but eventually gyro drift will cause the robot to fall over.  This is why all successful inertial balancers use a gyro/accelerometer pair.  (If you want a balancer without the inertial hassle, check out IR-based balancers like Legway.)

The reason you can't use an accelerometer alone for balancing goes back to the motors -- your speedy motors will cause the robot to jerk rapidly, and without a gyroscope, the accelerometer will be unable to distinguish the jerk from angular rotation.  There is no way to filter or model this away.  Dozens of smart people have documented their attempts to build inertial balancers with accelerometers alone, and none of them have come close to working.  (But it's still fun to learn from other people's attempts.)

Finally, do all your initial testing on carpet.  It really makes balancing a lot easier.  When you put your robot on a smooth surface like a table or floor, your motion control algorithm has to be near perfect or it will slide all across the surface as if it were on ice skates.  Carpet is much more forgiving.  Once you are running around on carpet, you'll find that balancing on tabletops requires wheel encoders or some other position measurement device to zero out the inevitable bias in your inertial measurements.  Nothing short of a perfect IMU (no such thing) can prevent this.

Good luck!  This is an incredibly cool project.

gimmelotsarobots's picture

Thanks for the tips. I have a RC helicopter with a gyro, would that work? Or do I have to buy something different? 

The world's best motto: When all else fails, use a bigger hammer.

I have read that RC gyros work okay.  Hopefully your microcontroller has a way to efficiently measure a PWM signal.  (Mid-range uCs usually have a timer/counter module that can do this without using CPU cycles.)

My first attempt at a balancing robot failed completely, so on my second attempt I overengineered everything.  Here's a video of my second, successful, attempt:  http://www.youtube.com/watch?v=0n7wx4HaUvY

I use the IDG-300 gyro on all my robots.  This returns an analog signal that I sample a 125Hz with a 12-bit ADC.  You can probably get by with a 10-bit ADC, but sensitivity counts.  (Same thing applies to your RC gyro -- you want 10 or more bits of precision in your pulse timer.)

Here's a good place to find gyros for balancing robots, including the IDG-300 I used on a convenient little break-out board:  http://www.sparkfun.com/commerce/advanced_search_result.php?keywords=gyro&sidx=p.products_price

In my first attempt, I had a noisy gyro connected to a low resolution ADC, a bendy plastic backbone connected to sloppy, weak, slow, motors with wobbly, soft tires, and very little weight above the axles...  I wasted weeks and it was clear it would never balance.

So on my second attempt, I eliminated all the mechanical slop in my design.  You can pick it up, swing it around, and have it feel like a single solid unit with nothing loose, rattly, or bendy.  That especially applies to motors and wheels.  They should be very stiff and not rattly.  The wheels should be hard plastic or metal with rubber grip but nothing soft or squishy.

I suspended the battery high above the motors using an aluminum tube, positioned so that the robot was balanced at ninety degrees from the floor. This weight distribution allows very small motions to translate into large corrections.  I also kept the PCB low near the axle, so it wouldn't receive as much shock when the robot hit the floor.

I had the new platform balancing on carpet within a few days.  So build it right the first time, and the software part will be easier than you expect.  After that, balancing on hard floors or tables becomes a much more interesting software challenge...

Nicola's picture

wow, i just saw you robot (is the first on the video, right?). Very stable! why don't you put it here on LMR? i'd be really interested to check your design. 

Yeah, i've found myself that carpets are much easier to balance over :) I'm not completely sure why :P 

About balancing with a single accelerometer, you're right it's kind of impossible. As Einstein kindly pointed out, there's no way to distinguish between acceleration and gravity :)

fritsl's picture
Why are you not using gyroscopes? The gas-modulation-type?