Saturday, January 16, 2021

How to Build a Flying Car,III: Phase Space

 How to Build a Flying Car: an occasional series of posts that examine various points of interest.

We finished the last post looking at a controller that didn't work: a bang-bang that simply always ran the motor as hard as possible in a direction towards the goal state. We hinted that it might be possible with a controller that had a more proportional response: turning on the motor to a degree proportional to the distance from the goal. 

This is, after all, exactly what the Watt spinning-ball steam engine governor did. And that worked pretty well!

But that would be to make a subtle mistake. To understand why, we need a tool that is basically just another way of looking at the process. What we are going to do is plot the above graph again, but instead of plotting the altitude against time, we are going to plot it against vertical speed. Physicists call such a chart a phase space, and there is a good reason why this is a good name, but we will ignore it for the moment.

So here is the very same run as above, but plotted in the phase space. The vertical axis is exactly the same, but instead of plotting time running left to right, we plot whatever the vertical speed happens to be on the horizontal axis:


(The system is moving counterclockwise, i.e. getting further and further from the origin. This is bad!)

Note several things: all the segments are parts of parabolas. Segments in the top half are uniform acceleration downwards, and segments in the bottom half are uniform acceleration upward (plus a bit of random "wind".)

Every trace crosses the y-axis at right angles every time. See if you can figure out why this has to be the case for the y-axis, but not for the x-axis.

But the most important point is slightly subtle: the points where the controller switches acceleration don't lie on the x-axis! They're on a line that slopes ever so slightly down to the left and up to the right.

This is due to lag in the controller. Like Wiley Coyote walking in the air a few steps before he realizes he's walked over a cliff, the controller runs a little bit across the axis before it realizes it needs to switch. It's this lag that makes each parabolic segment a little bigger than the previous one, with the unfortunate consequence of wandering off to infinity.

It is NOT the bang-bang nature of control that causes this instability; it's the lag. To investigate this, let's use a proportional controller. The only difference in the phase space view is that the cycles will be circles rather than almond-shaped:


Phase space map for a proportional controller with zero lag.

If you get the lag to be exactly zero, then the system will plot out an exact circle in the phase space, neither expanding nor contracting. Here's a plot of a system with some lag and with as close as I could tune it to none:

Note that the lagged run does suffer from increasing oscillations and will ultimately run away.

By now the solution should be obvious: mathematically induce some negative lag. How do we do this?



It is simplicity itself if you are thinking in phase spaces. Instead of making the control response proportional to the distance above the zero line, make it proportional to the distance above this tilted line instead. Then, in the phase space, the track of the system will tend to spiral into the center. In practice, if you get the slope of the line and the constant of proportionality right, it really works incredibly well. 

Here's a run with the same scale of wind as the above but with the control parameters tuned just right.



 And just to show off, here, on the same scale, is the phase space track of the same run:

Maxwell Smart couldn't have done better.

How did I find those optimal values for the line tilt and proportionality constant? Brute force. I simply ran a lot of cases and measured the standard deviation of the result, picking the smallest. It helps to visualize the result as a valley in parameter space:


... which may help you in designing systems and knowing what results to expect. Note that the surface is wrinkly due to the random "wind."

A couple of other notes: if you read the control theory literature, typically they put the system position, which they call "error," on the x-axis and velocity on the y-axis, and the system moves clockwise. I used the scheme here because we are actually interested in a vertical parameter, and the same variable is on the vertical axis in time-series charts.

In standard control theory distance from the goal state is called "error" and the proportional signal is proportional to that. What we called velocity is called "derivative," as it is the derivative of the error function (and the system is often not a moving object with a speed). So the formulation here is called a proportional-derivative or P-D controller.

Finally, the derivative term, or the slope of the line in our formulation, acts as a force against the motion that increases with speed; in other words it acts like friction (in fancy parlance, "damping"). The reason that Watt's governor worked so well was because it had enough real friction to create a converging phase space!

Next up: Optimal Control!

No comments:

Post a Comment