Two Wheel Dynamic Balancing Robot
If GainAmp < 1.0 then
GainAmp = 1.0
Also, be careful with your variable types and conversions;
some of them truncate your values and reduce resolution or
produce unwanted results. I usually sample ADC in integer
values (0 to 1,023) and then convert them to floats or singles
to make it easier to code and to make things more compatible
with other trigonometric functions and equations. Make sure
that your variables are scaled to match mathematics from
other variables involved.
These are the basics of balancing; however, there are
many other details that need to be covered in order to
achieve a proper balancing robot that can hover on two
wheels and also move around gracefully for days or months.
GainAmp is very useful to make the robot stiffer and
tougher; however, you must be careful not to make it too
tough or it will go into resonance and wiggle until it gets out
of control. This type of attenuation from the feedback gain is
not achieved through “GainAmp,” but rather through the
speed limit for a particular maneuver you want the robot to
perform. This sets a tolerance and allows the “brain” to react
accordingly and track if something goes faster than expected.
I track speed through an integral of the torque and so
the tolerance is set by a speed limiter. The speed limit is
dependent on what I am trying to do. If I want the unit to
hover, then my speed limit is close to zero. If I want to allow
the unit to move around, then my speed limit is set higher.
This allows the unit to compensate for external physical
changes. Speed can best be tracked through the use of
encoders, but the integral works very nicely for this purpose.
With a robot, speed limiting is not that important, but, if
we take the speed limit as a factor to compensate for external
forces acting on the unit, then the robot most know how fast
it is going and how fast it is allowed to go. If the unit goes faster
than the tolerance, then it has an external force influencing it. If
Figure 8. A peek inside: batteries, BX- 24, and the Roboteq.
we want the robot to cruise at 5 mph, then the speed limit
should allow 5 mph ± a threshold, but nothing more.
If we exceed 5 mph and the known angle to achieve 5
mph, then there is an external force affecting the unit —
either a change in weight, someone pushing it, a bump,
or something else. In order to limit the speed that the
platform is allowed, we need to move faster toward the same
direction, thus forcing the robot to tilt to the opposite side
and then slow down the torque. Yes, you have to move faster
toward the same direction in order to tilt the platform to the
opposite side and then allow it to slow down. If you simply
reduce the speed to the motors, then the robot will slam to
When a force pushes the robot, the speed limiter kicks in
because it detects more movement than expected; the software
quickly applies more force toward the external force’s
direction to counteract it. This might actually mean tilting a
bit to the opposite side. We must also be careful because, if
wwwOur .npcWoebbsite! r otics.com
NPC Robotics, Inc. • 4851 Shoreline Drive • PO Box 118 • Mound MN • 55364 • 800-444-3528 • Fax: 800-323-4445 • E-mail: firstname.lastname@example.org
SERVO 07.2004 33