Two Wheel Dynamic Balancing Robot
Figure 4. Forces acting on the balanced load.
so long as you use common sense. The larger the wheels, the
more momentum you will have. The more momentum, the
more traction, and the more traction, the faster you can
respond. However, if you choose a very large wheel, your
robot will balance even before moving forward without allowing
it to tilt to navigate. So, it’s a “balance” between the PWM
module, motors, gears (backlash), and wheels that determines
how smooth the robot’s movement can be. If the wheels are
too small, the robot will be a bit too jerky while in hover.
If you don’t mind your robot being a bit jerky in hover,
the gears can be standard. If you want superior precision,
then your gears need to be low on backlash; however, for
normal operations with very small and maybe unnoticed
jerkiness, you can get away with standard gears. The ones I
used came attached to the motors by the factory (see Parts
List). Clever programming can work around lots of physical
problems. Keep this in mind!
The frame — or platform — I used in the prototype is less
than optimal, but it works. It is a simple, stainless steel box,
but this will soon change to a temporary, fiberglass chassis
and then to its permanent, carbon fiber chassis. Both of
Figure 5. Note that all the weight is above the wheel axis.
30 SERVO 07.2004
these were provided free by some associates who do a lot of
work with these kinds of materials. I recommend doing your
tests with some kind of hard platform, like aluminum — or
whatever might define “hard” for your robot’s scale.
When choosing a material, bear in mind that it will hit
the floor hard (no matter how good you are) and, if the
material is not tough enough, it will break. I discovered is
that, as long as you use strong common sense, the first
balancing act will be forgiving. Just try the best you can to
use precision from the beginning — along with good quality
materials and precision in your algorithms — since this will
result in greater performance and smoothness potential later.
For brains, I chose NetMedia’s BasicX microcontroller; it
gives me the ability for rapid development with a great deal
of power. It runs wonderfully and makes the prototype
easier, since it requires fewer parts than other MCUs (actually,
almost no additional parts). The Basic language also provides
good, readable code and it can be programmed from any
serial port from your computer, straight out of the box.
The MCU is very well-made and powerful enough for this
and other applications. It allows you to start solving the real
problems right away instead of setting up a peripheral — you
just plug and play. The BX- 24 also has enough memory to
support a much bigger program than the one required by my
application, so there is room for expansion. Tech support is
also great, so I decided to use it.
The software I wrote is actually not that large; the actual
balance routine was placed in less than 50 lines of code. As
I mentioned earlier, it is in Basic and I am using some custom
serial port routines to output values to the PC console and
to the PWM driver at the same time. The Kalman filter will
bring the MCU to its knees, but I am predicting that — with
optimization — it will be powerful enough.
Put It All Together
The hardware part that is used for control is very simple.
It actually does not use any components that are not found
onboard the BX- 24; the only extra, low power components
are the sensors and the pot(s) that make the unit turn.Since
the robot doesn’t have any intelligence or autonomy built in,
I used a set of potentiometers to steer and drive it around.
I recommend using a separate battery to power the
logic; also, make sure that all your grounds come from the
same place (PWM module, MCU, batteries, etc.).
The connections between these modules are fairly
simple. You read your sensors through the ADC pins in the
BX- 24 (pins 13-16) and talk to the PWM module with either
a DAC port or through the serial port, as I did. The serial port
of the Roboteq controller is configured at 9600 baud, one
start bit, seven data bits, one stop bit, and even parity. So,