balancing, we know that on average, it must be close to vertical. So if we constantly, gradually shift the
angle
variable towards zero, it will not build up any significant error due to gyro drift. In our balancer
example, that just takes a single line of code, called whenever the robot is balancing:
Now that we have good measurements of the robot’s angle and rate of rotation, we can talk about
how to make it actually balance. The next section discusses the approach to balancing used in our
example code.
7.2. An example balancing algorithm
Angle convention used by the Balboa 32U4 balancing example.
The gyro measurements we described in the previous section gave us two important variables:
•
angle
: the angle relative to vertical
•
angleRate
: the rate of rotation
When thinking about these variables, it is helpful to make a plot that shows the trajectory of the
robot over time. Suppose we take a Balboa
with its motors off
, start it leaning forward, and give it a
little push toward vertical. Initially,
angle
is positive and
angleRate
is negative. As the robot rises
toward vertical,
angleRate
decreases until it runs out of momentum, stops, and starts falling forward.
It continues to fall forward, faster and faster, until it hits the floor. The blue curve in the graph below
shows approximately what the trajectory looks like:
1
angle = angle * 999 / 1000;
Pololu Balboa 32U4 Balancing Robot User’s Guide
© 2001–2019 Pololu Corporation
7. How to make a Balboa balance
Page 80 of 97