Balancing bot with ultrasonic sensor - no gyros

Here's my slightly unusual balancing bot.

Normally balancing bots use motors and gyros,but my minimal bot uses just servos and an untrasonic distance sensor.

 

Used an old boe-bot platform:

2x continuous rotation servos

Aluminium base

The boe-bot came with a a basic stamp MCU, so I replaced that with an Arduino Uno

Boe-bot's are normally rover type bots, but I moved the servo/wheel mountings to the edge

and stood it up on its end to make a balancing robot.

You need accelerometers and gyros for a balancing bot, right ?

Not here - I just used a HC-SR04 ultrasonic distance sensor pointed at the floor:

 

shorter distance = falling forward,

longer distance = falling backward.

 

Feeding that into a PID loop got some balancing, at least for several seconds,

and longer with some tuning (0:14 onwards in the video)

 

Connected the ultrasonic like this:

HC-SR04

 

 

The two servos on top are just for weight

- balancing works better with the centre of gravity  higher up

 

I've put the full arduino source code on github here:

https://github.com/mikerr/SonicBalancer

Balances without gyros - arduino, hc-sr04, continuous servos


This is a companion discussion topic for the original entry at https://community.robotshop.com/robots/show/balancing-bot-with-ultrasonic-sensor-no-gyros

Congratulatons!
As long as it balances!

Neato!

Neato!

Some out-of-the-box thinking

Some out-of-the-box thinking here, I like it. How do you prevent it from tipping over when it suddely encounters a surface with radically different acoustic properties?

Wow,your code is like

Wow,your code is like mininal too! I’m going to plug it into my latest and see what happens.

In your PID function you

In your PID function you divide your DRIVE result in half. Is that  to reduce the total effect of the DRIVE variable? I found I needed to divide by 10 to get a decent effect on my servos - perhaps because I have such large wheels? 

Thanks for posting
With a single sensor there are orientations near vertical that return the same value for forward and backwards tilt. Moving the sensor away from the body will increase the dynamic range for the backwards tilt. Adding a second sensor on the back and a little programming may help.

As Oddbot mentioned, IR distance sensors have a faster response plus you can get units that are built for short range. You can also mount them on a slight angle to remove the problem at true vertical.

A 2 dimension drawing might give a better explanation.

Yes, I was aware of that -

Yes, I was aware of that - it basically balances best while leaning slightly one way.

I mostly solved that by biasing the weight more one side than the other -so it always "falls back"

I was aiming for simplicity/minimalism here, so didn’t want to add an extra sensor, or more appropriately an accelermoter/gryo etc.