[chbot] PID notes

Richard Jones rjtp at ihug.co.nz
Mon May 5 21:14:36 BST 2008


The note below on motor control came from the HomeBrew Robotics Club
mailing list. It sets out motor control I such a pragmatic way that I
thought I would share it. Apologies to those who receive this directly.
Richard Jones

-------- Original Message --------
Subject: [HBRobotics] PID notes
Date: Sun, 04 May 2008 13:40:28 -0700
From: David Wyland <dcwyland at ix.netcom.com>
To: "Richard Jones" <rjtp at ihug.co.nz>

This was a response to a thread on the Seattle Robotics web site. For
your delight and amusement.

------------

You can see the problem with P (proportional) control by doing a little
Excel spread sheet simulation exercise. I did this for a talk on PID,
and it helped.

The classic problem is a force-position loop. This is where you measure
position error and drive the motor with a current proportional to the
error in a direction to reduce the error. Here is what happens.

You start out with an error. This generates a current in the motor. The
torque (force) from the motor starts accelerating the mass of whatever
is attached to the motor output (i.e., the robot wheel and robot mass).
Think of it as a flywheel with the same inertia as the robot/wheel combo.

The flywheel starts to accelerate. The velocity starts to climb. As the
velocity goes up, the position error decreases.

Even though the position error is decreasing, the error is not zero, so
you still have positive, though decreasing, acceleration. The velocity
will continue to increase until the position error is zero.

At some point, the position error will be zero. You will be just passing
where you want to be. However the velocity is *not* zero at this point.
Since you have inertia in the system (remember the flywheel effect), you
will continue on past the desired position.

Now, you will start to build up negative position error, and you will
start to apply current in the other direction.

You have just started to apply current in the other direction, but the
flywheel still has velocity, although the velocity is now just starting
to decrease.

The error and motor current will increase and the velocity will decrease
until the velocity is zero. This will take time.

The velocity is now zero, but you have a large negative error. The above
process starts again in the other direction. The result will be an
ever-increasing sine wave.

You can plot this in in Excel. You set up a number of columns showing
the position error and velocity of the motor versus time. You make an
arbitrary assumption about the constant defining acceleration of the
"flywheel" vs error so that the plot shows one or more sine waves  in a
reasonable number of columns.

This is the classic problem that founded control systems theory.
Battleships had Very Big Guns that were driven by Very Big electric
motors. The idea was to have a knob on the bridge that controlled where
the guns were pointing. They hooked it up, and the guns oscillated left
to right and back until they hit the stops. Very Undesirable.

The engineers came in, looked at it, tried math and figured that adding
a derivative term (velocity) to the position error term would make it
stop oscillating. A positive velocity would reduce the position error.
After tweaking the derivative term, the guns became well behaved. To the
observer, adding a few tiny components to the electronics made the huge
guns behave. Impressive.

A technical note. The derivative term is equivalent to adding friction
to the system! It is a perfect, viscous friction. Think cold maple
syrup. Coulomb friction, often called stick-slip or sticktion, is *not*
the same thing. Coulomb friction is usually a bad idea,  like backlash.
Some further notes.

The classic robot motor situation uses an H bridge driving a motor with
the position error going to the H bridge. This mostly works. Why? It is
because the H bridge is a *voltage* source at frequencies well below the
H bridge switching frequency. The effective voltage output is
proportional to the duty cycle of the H bridge.

The H bridge supplies a voltage, and applies it to the DC motor. If the
motor is at zero RPM, a big current flows equal to the H bridge output
voltage divided by the motor resistance.

Now the interesting part. As the motor builds up speed, there is
back-EMF from the spinning motor. If you spin a motor without connecting
it to anything and measure the voltage across the motor terminals, you
will see a voltage proportional to the speed of the motor. This is
called back electromotive force, or back-EMF. The motor is acting as a
generator. This is true even when the motor is connected to the H bridge.

As the motor builds up velocity, the back EMF is in the opposite
direction to the applied voltage: it *subtracts* from the applied
voltage. You can see this just putting the motor across a battery. The
motor will accelerate to its no-load speed, a velocity proportional to
the applied battery voltage. At this speed, the back-EMF exactly equals
the applied voltage, less a little for friction.

So our position-H bridge-motor circuit is not generating force, it is
generating velocity. It has a built-in velocity term. The advantage here
is that a position-velocity loop is always stable. The velocity is
forced to zero as the position error is forced to zero. When you hit the
desired position, the velocity is exactly zero, and you are done.

So everything is fine, right? Well, almost. This works fine at medium to
high velocities, when the error is large. As the velocity gets low near
the desired position, it falls apart a little. At low voltages, the
back-EMF is small with respect to non-linear things such as brush
voltage drop.

Brushes look like a little like a noisy diode. Below a certain voltage,
the current drops off rapidly as you reduce the voltage. Brush drop adds
a form of electronic "backlash," where you have to use a larger voltage
to generate the current to keep the motor moving.

When the applied voltage is low enough - below the non-linear brush
voltage drop, the motor sees no current even though there is a small
applied voltage.  The result is that the H bridge output voltage starts
looking more like a square wave than a smooth transition to zero volts.
The result is that you get small oscillations when the position error is
near zero.

The problem is that our velocity feedback fails at low position errors.
We need a more reliable velocity feedback source. One solution is to use
an encoder on the motor shaft before it goes into the gear box. This can
supply accurate velocity information even at low speeds because it is
directly measuring the velocity.
Another solution is to turn off (disconnect) the H bridge periodically
(100 Hz?) at low speeds and carefully measure the back-EMF with a high
impedance (very low load on the motor) ADC. At light loads, the brushes
lose much of their non-linearity, so you can measure back-EMF even when
it is small. This is an electronic solution when you do not have a motor
with a built-in encoder.

The turn-off-and-measure method only needs to come into play at low
error = low H-bridge drive voltage. This is left as an exercise for the
student.

I hope this helps.

Dave Wyland
+----------------------------------------------------------------------
| Silicon Valley Home Brew Robotics Club Mailing List
|    For Club info Visit:  <http://www.hbrobotics.org/>
|
| hbrobotics at wildrice.com               Send a post to the list.
| hbrobotics-join at wildrice.com	       Join the list.
| hbrobotics-digest at wildrice.com	Join the list in digest mode.
| hbrobotics-leave at wildrice.com	Leave the list.




More information about the Chchrobotics mailing list