[Hans Blom, 970226]
(Bill Powers (970225.0530 MST))
To Bill and any other interested programmers. Right now I have no
time to write a program, but I'll provide the few formulas that need
to be implemented and a description of how they are derived. Bill,
being the programming buff that you are, I expect you to be able to
get the program right within half an hour, given yours as the basis:
only a few things need to be changed. Others may need more time ;-).
The following derivation of the controller would be pretty familiar
by now, if you have followed the discussions so far. The differential
equation of the theodolite example (itself an approximation, or what
MCT calls a model!) is
J * d2x(t)/dt2 = u(t) + d(t)
We first derive the equivalent difference equation form. We have,
after all, to implement computer code. We therefore introduce the
(temporary!) variables acceleration a(t) and velocity v(t)
a(t) = d2x(t)/dt2 and v(t) = dx(t)/dt
The equation then becomes
J * a(t) = u(t) + d(t)
Now we approximate a(t) as
a(t) = dv(t)/dt = [v(t) - v(t-dt)]/dt
so we get
J * [v(t) - v(t-dt)]/dt = u(t) + d(t)
Next, we approximate v(t) as
v(t) = dx(t)/dt = [x(t) - x(t-dt)]/dt
and we get
J * [[x(t)-x(t-dt)]/dt - [x(t-dt)-x(t-2dt)]/dt]/dt = u(t) + d(t)
Defining K as J/dt^2 lets us get rid of all the multiplier-dt's:
K * [x(t) - 2x(t-dt) + x(t-2dt)] = u(t) + d(t)
In the term between square brackets one can recognize the discrete-
time approximation of a second derivative. It is, however, centered
around t-dt, so we can do slightly better if we center around t and
use the formula
K * [x(t+dt) - 2x(t) + x(t-dt)] = u(t) + d(t)
which we will therefore use (this is not essential). Thus far, we've
only translated a differential equation into a difference equation.
Nothing new, just a preliminary step.
Rewriting the last expression, we obtain the "prediction equation"
x(t+dt) = 2x(t) - x(t-dt) + u(t)/K + d(t)/K
At time instant t, we know everything but the lefthand side (which is
only a prediction so far, not yet an observation) and the disturbance
d(t). Because d(t) is unknown, we cannot really predict yet; we need
an assumption about the value of d(t). Let's make a naive start and
see what happens if we assume d(t) to be zero always. That would be
good enough only if there were no significant disturbances. We then
get the prediction
xpre(t+dt) = 2x(t) - x(t-dt) + u(t)/K
where xpre(t) is the predicted value of x(t). Specifying the control
goal
xpre(t+dt) = r(t+dt)
we substitute and get
r(t+dt) = 2x(t) - x(t-dt) + u(t)/K
and, solving for u(t), we get
u(t) = K * [r(t+dt) - 2x(t) + x(t-dt)]
Let's plug this in into the prediction equation and see what we get:
x(t+dt) = r(t+dt) + d(t)/K
That is, there is good control only if d(t)/K is small with respect
to r(t). In the case that Bill specified, this is far from true, I
guess.
What to do? In order to be able to compute a prediction, we need some
expression/model for d(t). We now drop the assumption that d(t)=0 for
all t and take the simplest model possible (except for the assumption
that d(t)=0), a zero order hold, which assumes that d(t)=constant and
can be described as
d(t) = d(t-dt)
Now d(t) is not known either, of course, but we can estimate it. That
is done as follows. Assuming some estimate d(t-dt) -- whose initial
value we take to be zero -- and using the zero order hold equation
and thus the previous value of d, we get the prediction
xpre(t+dt) = 2x(t) - x(t-dt) + u(t)/K + d(t-dt)/K
This prediction will be incorrect, because at time t+dt we will
actually observe
x(t+dt) = 2x(t) - x(t-dt) + u(t)/K + d(t)/K
But by taking the "error correction" difference we obtain
xpre(t+dt) - x(t+dt) = d(t)/K - d(t-dt)/K
from which we can, once x(t+dt) has been observed, compute an
estimate d(t) as
d(t) = d(t-dt) + K * [xpre(t+dt) - x(t+dt)]
and it will be this value that we will use in the following iteration
as d(t-dt). At this point we _can_ compute an action u(t) from
xpre(t+dt) = 2x(t) - x(t-dt) + u(t)/K + d(t-dt)/K
because all terms on the righthand side are now known (or available
as estimates), if we combine this expression with the control goal
xpre (t+dt) = r(t+dt)
Thus the control law will be
u(t) = K * [r(t+dt) - 2x(t) + x(t-dt)] - d(t-dt)
How good will this zero-order-hold based controller be? Well, plug
this equation into the model. We get
x(t+dt) - r(t+dt) = [d(t) - d(t-dt)]/K
That is, control will be perfect as long as d(t) = d(t-dt) -- which
Bill was so nice to provide most of the time with his square wave
disturbance! -- and it will only be bad at those time instants (and
only there!) where the disturbance makes large jumps.
I did not take limitations in u(t) into account. I assume that they
do not cause difficulties and that their effect will be intuitively
obvious: the specified reference cannot be reached in a single step.
I expect that the only complaint left will be that this controller is
_too_ good to mimick a human ;-). Maybe. Maybe not. That requires a
different test.
If y'all don't get around to rewriting the above into a program, I
will, but that may take some days.
Greetings,
Hans