[From Bill Powers (970306.2143 MST)]
This has been a long and interesting day. Earlier, I posted a preliminary
version of Hans Blom's MCT model, using the correct physical model of the
theodolite. The remainder of the model, however, was uncertain: it
oscillated, and I didn't know why. So I went back to scratch and re-did the
entire model. I am finally satisfied (my, that feels risky!) that the new
version is exactly correct in all particulars, and that I can explain
exactly why it behaves as it does.
For those who aren't going to follow this post in detail, I will summarize
the findings.
1. Except for the matter of the modeled disturbance, the MCT model developed
using Hans' strategy proves identical to the two-level PCT model I used --
and indeed, used in the Little Man some years ago. This was a great
surprise, because the mathematics does not reveal this fact without some
persuasion.
2. For the particular example I chose, in which there is a free-moving mass
accelerated and decelerated in angle by an applied torque, there is an
uncorrectable problem with the MCT model in its present form. Briefly, it is
that the modeled disturbance can't be calculated until after the real
disturbance has imparted an angular velocity to the mass. There is an
unavoidable one-iteration mismatch between the real and modeled
disturbances, and this means that there is an uncorrected angular velocity
in the real theodolite that does not appear in the modeled theodolite. This
mismatch persists as long as there is a nonzero disturbance, and each
attempt to correct it results in another mismatch, so the angular velocity
error is never corrected.
This problem would not be obvious in a physical system that contains
internal damping, as all of Hans' previous models of "the plant" have done,
because the velocity error would quickly die away. I chose this free-moving
mass as an example because I still suspected that slight integration errors
would be cumulative. That proved to be true, although not at all in the way
I had anticipated.
This did not show up in Hans' orginal model, because Hans used identically
the same _incorrect_ calculation for the physical theodolite and the model's
internal simulation of the theodolite. This way of treating the system left
velocity out of consideration, and this prevented the problem I have found.
As it has turned out, the critical error boils down to an uncorrectable
effect of that one-iteration delay between the modeled disturbance and the
real one: truth, it seems, is in the smallest details.
After my haste-induced mathematical "insights" of a couple of days ago, I
don't expect these brave words to be taken without a grain of salt. So I
will spend the rest of this post laying out my development of the MCT model,
after which I hope that more than one person will subject the results to as
careful a scrutiny as I have tried to apply today.
···
---------------------------------------------------------
I: THE THEODOLITE MODEL
Let us start with the model of the theodolite, under the condition that the
torques applied to it are constant except for steps that occur at intervals
of dt, defined for the duration of this development as 0.01 second.
I will briefly recap what I said in an earlier post today.
The basic differential equation of motion is
J*d2x/dt^2 = (u + d),
where x, u, and d are all functions of time. u is the torque output of the
discrete controller, and d is the value of a disturbance that has only two
values: either 0, or some constant number. J is the moment of inertia of the
theodolite.
The solution of this equation in the special case where u and d are constants is
(1) x = x0 + v0*dt + 0.5*(u+d)/J*dt^2
In this equation, dt is not an infinitesimal, but a finite duration of time.
The angle of the theodolite at the beginning of the interval is x0, and the
velocity is v0. The value of x in equation 1 is the position at the end of
the interval dt, and thus at the beginning of the next interval.
Also, we can compute the angular velocity of the theodolite at the end of
the interval. It will be
(2) v = v0 + (u+d)/J*dt
These two equations exactly describe the continuous motion of the theodolite
under the stated conditions. Under torque inputs which occur in discrete
steps, the motion will be a series of segments of parabolas.
II: THE MCT MODEL
The conditions specified by Hans are that the MCT model is to contain a
simulation of the theodolite that is an exact replica of the equations of
motion of the theodolite. This was accomplished by using equations (1) and
(2) for both the theodolite and the simulation.
I chose to start the iteration loop with the torque output initialized to
zero, and compute both the modeled xmod and vmod and the real x and v (using
the term "modeled" to mean "simulated"). The variables a and amod are dummy
variables used to represent angular acceleration. Since these are program
steps, the variable on the left is the _next_ value; the same variable if it
appears on the right is the _old_ value.
Just before each value of x or v is computed, the value of d or dmod is
found. When a disturbance appears, it will appear at the start of an
interval dt.
The first step is to calculate the new position and velocity of the real and
simulated theodolite. We apply the current output u simultaneously to the
simulation and the real theodolite:
d := make_disturbance; {returns 0 or 50}
a := (u+d)/J;
x := x + v*dt + 0.5*a*dt*dt; {real theodolite}
v := v + a*dt;
amod := (u+dmod)/J;
xmod := xmod + vmod*dt + 0.5*amod*dt*dt; {simulated theodolite}
vmod := vmod + amod*dt;
In the program, the previous values of x and v are preserved as oldx, oldv,
oldxmod, and oldvmod.
Note that in order to calculate the new values for the simulation, we must
already have an assumed value of dmod. However, in order to estimate a new
value for dmod, we must have available the values of x, v, xmod, and vmod,
the latter two of which will be known only after the second set of
calculations above is done. Thus we must do both sets of calculations before
we can make an estimate of the next simulated disturbance.
Since we know that the disturbance begins at zero, jumping to 50 only later,
we can use an initial assumed value of 0.
When the disturbance jumps to 50, we will find that it has been applied to
the real theodolite, but not yet to the simulated one, which is still using
the previous value of dmod. This is where the unavoidable one-iteration lag
of the simulated disturbance arises. The real theodolite receives a brief
impulse that the modeled one does not. As the result of this, the real
theodolite acquires an angular velocity that, as it turns out, remains
higher than that of the modeled system until the end of the disturbance.
This produces a steadily increasing departure of the real theodolite angle
from the simulated angle, for the duration of the disturbance.
After both calculations above have been done, we can estimate the next value
of the disturbance on the basis of any discrepancy between the position and
velocity of the real and simulated theodolites. It is done as follows:
We now have values for x, v, xmod, and vmod all at the same instant of time.
We can thus use the two equations for x and xmod to solve for the mismatch
between the real disturbance and the simulated one. That mismatch can then
be used to correct the simulated disturbance.
x := x + v*dt + 0.5*a*dt*dt; {real theodolite}
xmod := xmod + vmod*dt + 0.5*amod*dt*dt; {simulated theodolite}
We now have to be careful to keep track of what is a "new" value or an "old"
value. Since x and xmod are new values, obtained from the above two sets of
calculations, we must make use of the old values as they existed before the
calculations, which have been preserved as oldx, oldxmod, and so on. Using
those variables, we can write the above two program steps as equations:
x = oldx + oldv*dt + 0.5*a*dt*dt (a has not yet changed)
xmod = oldxmod + oldvmod*dt + 0.5*amod*dt*dt
Subtracting the second equation from the first, we have
(x - xmod) = (oldx - oldxmod) + (oldv - oldvmod)*dt
+ 0.5*(a - amod)*dt*dt
Substituting from the definitions of a and amod, we find that the right-hand
term reduces to
0.5*(d - dmod)*dt*dt/J
In that term we find the discrepancy we want to calculate, d - dmod, which
is the amount by which the previous value of dmod must be changed to be a
correct model of the real disturbance.
We can now solve the above equation for (d - dmod):
d - dmod := [(x - xmod) - (oldx - oldxmod) - (oldv -
oldvmod)*dt]*2*J/(dt*dt)
Adding (d - dmod) to the old value, dmod, we get the correct simulated value
of dmod for the next iteration: d. It is one iteration too late, but that is
the best that can be done.
The final step is to calculate the next value of the output, u, preliminary
to starting a new iteration. To do this, we start with the simulation
program step, but using the current values of xmod and vmod in order to
calculate the _next_ value of xmod, which we want to equal the reference
level r.
xmod(next) = xmod + vmod*dt + 0.5*a*dt*dt
Substituting r for xmod on the left allows us to solve for the next value of
amod that will make the model's xmod equal to the reference value r.
r = xmod + vmod*dt + 0.5*amod*dt*dt
and expanding amod,
r = xmod + vmod*dt + 0.5*(u + dmod)*dt*dt/J
Remember that dmod is now the estimate for the _next_ value of simulated
disturbance, already calculated.
From this we obtain the program step for calculating the next value
of u:
u := 2*J/(dt*dt)*(r - xmod - vmod*dt) - dmod
Since we now have new values for u and dmod, we can go back to the beginning
and start the calculations for the next iteration.
----------------------------------------
III: THE PCT MODEL
To clear up one mystery, we must review the PCT model. This is a two-level
model, in which the lower level controls velocity and the higher level
controls position. The error signal from the position control system is
multiplied by Gx to produce Rv, the reference level for velocity. The error
signal from the velocity control system is multiplied by Gv to create the
output torque u. The two control-system equations are
Rv :=Gx*(r - x);
u := Gv*(Rv - v);
The x and v values come from the physical theodolite, which is identical to
the model used for the MCT model above. We assume that the control systems
can sense v and x, sampling once per dt.
The MCT model calculates u this way:
u := 2*J/(dt*dt)*(r - xmod - vmod*dt) - dmod
However, when that equation is used in the MCT model, a serious malfunction
occurs. The output oscillates on alternate iterations between 80 and 0 as
long as the reference signal is changing. The reason is that the error gets
completely corrected on one iteration, leaving no error to drive the next
output, so the error jumps back up again. The cure is quite simple: omit the
2. In fact, the problem here is the same one I spoke of in the "spadeword"
paper: the gain of this system is too high; in fact it is just twice the
maximum gain for correcting the error in minimum time. Reducing the gain by
a factor of two brings the system essentially to its maximum useful
performance (the rapid oscillations disappear). So the program step actually
used in the MCT model is
u := J/(dt*dt)*(r - xmod - vmod*dt) - dmod
The way the next value of u is computed in the MCT model seems to have
little to do with the way it is computed in the PCT model. However, let's
combine the two PCT program steps into one:
u := Gv*[Gx*(r-x) - v)], or
u := Gv*Gx*(r-x) - Gv*v
Let's also multiply out the expression for the MCT model (except for dmod):
u := 2*J/(dt*dt)*(r - xmod) - 2*J/dt*vmod
From this we can compute the relationship between the coefficients in the
two expressions:
Gv*Gx = J/(dt*dt)
Gv := J/dt
From this we can deduce that
Gx := 1/dt
J is 1.0 n-m^2, and dt is 0.01, so the values of Gx and Gv required for the
PCT system to behave like the MCT system without a disturbance are
Gx = 100 and
Gv := 100.
When these values are used in the PCT model, it behaves identically to the
MCT model, including small oscillations when the reference signal suddenly
starts or stops rising.
We're comparing the MCT model controlling its internal simulation with the
PCT model controlling the actual theodolite (since it has no internal
simulation of the theodolite). When there is no disturbance, the two models
behave identically at all rates of rise of the reference signal, all the way
to the point where the slope is so high that both models show large damped
oscillations at the start of the reference signal changes (they could be
overlaid).
So the MCT model controls its _simulated_ xmod in the same way that the PCT
model controls the actual theodolite. But how do the models compare in terms
of controlling the real theodolite?
--------------------------------
With a disturbance of zero, the MCT model controls the real theodolite
exactly as the PCT model does. When a step-disturbance is introduced,
however, the MCT model fails. In the program, the disturbance is introduced
after the reference signal ramp has reached its upper limit and has become
constant. Up to the point where the disturbance begins, the traces for the
PCT model exactly match those of the MCT model. But when the disturbance
appears, the angle of the real theodolite in the MCT model starts to
increase at a constant rate that is proportional to the magnitude of the
disturbance, departing rapidly from the reference signal. This increasing
error is a perfectly linear ramp; nothing is being done to correct it. At
the end of the disturbance square-wave, the increasing angle of the real
theodolite becomes constant again, but does not return to the reference level.
The reason has been explained above: because of the one-iteration delay in
the simulated disturbance, which is unavoidable, the real theodolite gets a
one-iteration kick that the simulated theodolite does not receive. This
causes a velocity to appear in the real theodolite that does not appear in
the simulation. Given the model as it stands, this can't be cured.
The only way to cure it would be to allow the controller to observe the
angular velocity of the real theodolite as well as the angle. Two criteria
would then have to be met in estimating the next disturbance and the next
value of u, and probably the saved previous values of the variables would
have to go back two steps instead of one. Not having tried this, I don't
know what the final model would look like.
---------------------------------------------------
I hope that I have made no errors in this presentation -- I have spent about
16 hours today debugging this analysis, so at least mathematical errors
should have been eliminated. The fact that the PCT model exactly matches the
MCT model in the absence of disturbances strongly indicates that no errors
remain, and the behavior of the theodolite under the MCT model, when a
disturbance appears, seems completely explained.
I hope this presentation will lay to rest some hasty generalizations about
the PCT model. It is neither better nor worse than the MCT model in the main
respects examined here. It is, in fact, the same model, only the PCT model
controls the real theodolite while the MCT model controls an internal
simulation having the same properties as the theodolite. I am sure that a
proper elaboration on the MCT model will take care of the problem of
uncontrolled velocities, and that this will make the two models even more
similar. If this is done, we can then pass on to further items on the agenda:
1. The effects of computational inaccuracies on the two models;
2. The effects of unmodeled disturbances on the two models;
3. Finding a true measure of the complexity of the two models (which, to tip
my hand, must include ALL mathematical operations employed in making the
model work).
I'll post the source code for the final version of theo6mct.pas in the
morning. I can't do any more tonight (or, I guess, this morning).
Best,
Bill P.