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!

Friday, January 15, 2021

How to Build a Flying Car,II: Control Theory

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

Here you are in your flying car. You are at 10,000 feet and need to go somewhere. You have 50 thruster fans pointed down through the floor of your car and 10 more pointed back. What you need now is some way to tell all of them how much to thrust. You don't have 50 hands, and even if you did, you don't have the brainpower to use them all properly to avoid the fate of the VertiJet's test pilots.

You need control theory.

Control theory has been a substantial part of engineering since Jame Clerk Maxwell published On Governors in the Proceedings of the Royal Society in 1868. This was the day of the steam engine and the Watt governor, descended from the spinning-ball governors used in windmills, which kept the engines running at an even speed.


The Watt governor is fairly simple to understand; the speed of the engine makes the balls try to stand out by centrifugal force, and thus to pull up on a yoke that cuts off the steam supply. There is a happy medium where the supply and speed match just right and so that is the speed the engine will try to run. Setting the balls and the steam-valve right was something of an art, it was an attempt to reduce this to a science that was Maxwell's aim.

Maxwell's analysis sets the stage for another trend in control theory: it contains no less than 73 mathematical formulae and equations. And I can assure you that it is easier to read than anything published on the subject in the 20th century.

What I would like to do in the next few posts is try to give an overview of a small part of control theory, nowhere near what an engineering student would learn in the course of a degree, but enough to  give you an intuitive grasp of what is going on. Note that even this little part is usually covered using differential equations, Laplace transforms, and their maps in the complex plane; but I will strive to avoid that here.

So, here is the problem. Here is your flying car, and I have set the fans so that the thrust is exactly equal to the weight of the car. It ought to hang there motionlessly. But there is also a disturbing force, which here I have labelled "wind" and modeled with a randomly varying force. 


The wind is the wiggly orange and green lines at about 0, from two separate runs. The blue and red lines, respectively, represent the altitude of the car. As you can see, the car doesn't stay put. Whenever it gets a couple of seconds of sustained gusts, it starts moving, and its momentum is enough to keep it going even though the wind returns to an average of zero.  

So what's a flying car to do? A first attempt is to use a controller of a kind we're all familiar with: it's like the thermostat in your home. It's either on or off (or in a more sophisticated version, turns on the heat if it's too cold, and the air conditioner if it's too hot.) But full force in either case. For that reason, a controller of this kind is often referred to as a "bang-bang" controller. For heating and cooling, this actually works rather well. But for our flying car, we have a little problem:


 The scale of the wind is the same here as before. We have drawn in orange the signal for control either pushing up or pushing down. But the blue signal, the car's altitude, is engaging in sickening leaps and plunges, which are getting worse as time goes on!

What's happening, of course, is that the corrective force acting all the time the car is above its intended altitude, is pushing it so hard that by the time it gets back to zero, it's going down so fast it can't stop. For heating and cooling, the system doesn't have that kind of momentum; for flying cars, it does. And that's enough to make the control problem quite a bit more complex.

Something like this happens in airplanes under human control, as well: when it does, it's called PIO for Pilot-Induced-Oscillation. A human pilot, of course, doesn't operate by slamming the controls back and forth to the stops; we try for a proportional response to what we observe. But PIO can still occur; the base reason for it is very different from "bang-bang syndrome." 

Enlightenment lies ahead in our next episode!



Tuesday, January 12, 2021

How to Build a Flying Car

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

So we wish to design a flying car. There are a lot of people attempting to do so now, perhaps twice as many groups as were 2 years ago when the book came out, and even then there were quite a few. And there are a remarkable number of designs, so many that you might even call this a "Cambrian Explosion" of flying car types.

The key to understanding which ones will catch on is of course, understanding which ones will present the most value to whomever buys one. You may remember that in the book I had a chapter on travel theory, which I summarized in this post. The essence of it is that the flying car is most valuable when it has the least latency, i.e. lands in your own driveway (or rooftop helipad), but at the same time is as fast as possible in flight. 

This is a tough assignment technologically, but by no means impossible with current technology. On the other hand it means that autogyros, which would have been the perfect flying car for the 1930s, probably won't make it in the 2030s. (As much as I would have liked them!)

What are we left with? A compact shape, basically a lifting body, with separate lift and thrust fans. Something like the Ryan XV5 VertiJet.


The main trouble with the VertiJet was simple: both of them crashed, killing experienced test pilots. Sheesh.

The bottom line is that it is quite difficult to fly a thrust-supported aircraft. The difference between 1961 and today is twofold: we have electric motors for thruster fans with much faster response time to control; and we have computers and electronics that make the best they had then look like stone knives and bearskins.

So technologically, the way to optimal flying cars today lies through control theory. 

Excitement lies ahead in our next episode!


Monday, December 7, 2020

The Third Wave (covid)

 So in my previous post on the subject, I noted that the small third waves in the various states were not large or coordinated enough to make another big bump in the graph. They have now begun to do so, but there are a couple of factors in play that make it seem perhaps more significant than it really is. 

The first one is fairly straightforward: the expected number of deaths goes up this time of year every year. To see the second one, let's look a bit more closely at the CDC mortality statistics:

(This is from the same CDC page I've been using all along.) So far I have been looking only at all-cause mortality, compared to average, since that finesses a lot of issues about whether covid was a major factor in any given death. 

But a closer look shows an interesting phenomenon I hadn't noticed before. Since April the non-covid deaths ran well above normal, contributing to both peaks, if you accept the CDC's classification. But since the September minimum (and using the same classifications), non-covid mortality dropped back into the normal range. 

As a result, while covid deaths are increasing (and that's all you will see, out of context, in the alarmist press), total all-cause mortality is still basically tracking average, seasonally increasing, rates.

And it still looks like that if nothing fundamental changes, your chance of dying next year is 1.1% instead of the normal 1%. Of course, if all goes well, you will be able to drop that back down to 1% by taking a vaccine. 




Wednesday, November 25, 2020

Ammonia, the fuel of the future: a refrain

 A couple of years back I did a post here about a post I had done at Foresight about a decade or so back.


Ammonia (NH3)


The basic idea is that ammonia is a close to ideal fuel for a near-nanotech chemical technology, in that it carries hydrogen which can be oxidized in a fuel cell (producing nothing but water), and the rest is merely nitrogen, which is already the majority component of air.

One of the key reasons for revisiting something like this is to check up on your prowess as a technological forecaster. My recent post here was to point out some recent advance that seemed to bring us closer to the ability to use ammonia as envisioned. So when I saw another reference in the technical literature, I thought to look around and see how far the efforts had got. 

Imagine my surprise when I discovered a substantial literature, conferences, and companies at the point of viable commercialization. Rather than talk about that myself, I will refer you to the Ammonia Energy Association's review of ammonia for fuel cells. Rummage around the site for much more information.

A little brief background: the hydrogen from the ammonia molecule is what fuels the cell and generates electricity. In the most common standard type of fuel cell, the PEM (proton exchange membrane), ammonia itself poisons the chemistry and has to be separated into nitrogen and hydrogen ahead of time. There has been substantial progress in separation devices. 

But even more important, at a best guess, is the fact that there are other kinds of fuel cell than the (acid-chemistry) PEM, but which are not poisoned by ammonia and can be fed it directly, without a separate separation phase. These include alkaline-chemistry fuel cells, and solid oxide fuel cells (SOFCs). These have come a long way in the past decade. The state of the art is that SOFCs are efficient enough for small stationary power units (1-10 kW range) but still too heavy for transportation, although approaching something that might be usable on a ship or locomotive fairly soon.

Your flying car, not so soon. But we're probably only talking another decade.

For a futurist, this is close enough to qualify as a win. In my previous post, I pointed out that "Ammonia, the Fuel of the Future" scanned with a classic American tune, "Columbia, the Gem of the Ocean." To celebrate, I sat down and penned out a couple of full verses. You may now sing them with your friends in full glee:

Ammonia, the fuel of the future!
your vector of useful energy
for your house, for your car, your computer,
for airplanes; even for the ships at sea.
It's a liquid you pour into a fuel tank,
Yet ammonia's entirely carbon free;
From the good old days of Bosch and Haber,
We understand the right chemistry.

Understand the right chemistry!
Understand the right chemistry!
From the good old days of Bosch and Haber,
We understand the right chemistry.

Ammonia, the fuel of the future!
With power for you and for me;
'Tis silent and couldn't be smoother;
when piped into an SOFC.
Do not thermalize your potential;
We know how to handle NH3 --
No need for Carnot and his limits
to generate electricity!

Generating electricity!
Generating electricity!
Ammonia, the fuel of the future,
generating electricity!

... and there you have it!


Monday, November 16, 2020

One more look at COVID numbers

 Given that my fit of a lognormal to excess deaths in my previous post worked so well, 


I thought I would revisit the stats and see how things were going two months later and whether I might need to add a third wave to the fit.

The actual national numbers don't appear to support that, so I thought perhaps I would take the state-by-state data (from the CDC) and see if there were separate patterns that made up the whole curve. I still couldn't see much in the way of a third wave, but this illuminated the first and second waves quite a bit:

Each trace is a single state (plus DC and PR with NYC separated out) of the absolute number by which all-cause mortality exceeded the high end of the expected range. Note that you would not even see the normal winter flu mortality peak in such a graph: the "expected" number goes up along with the actual deaths.


It's the orange line on this graph. It cycles between 50 to 60 thousand deaths per week over the course of a normal year. Note in particular that it's going up now, as people are not outside as much and not getting as much Vitamin D. Also note that the total number of people dying from any cause whatsoever is flattening and they will soon cross.

The major thing to note in the first graph is that the states making up the bulk of the first wave are different than the states making up the second wave. To a rough approximation, each state only gets one wave. States that didn't participate in the April or August waves are now getting their own waves, incoherently, so there's no distinct third wave but a statistical mush.

Here's the same graph again, but instead of absolute numbers we have the percentage over expected deaths for the particular state:

Now the vertical scale is percent. New York got up to 6 times the expected death rate in April, but nowhere got much more than 50% in August, and the average in the statistical mush is getting back down to zero, with a spread of 10-20%.

Note that that's not quite normal: normal is that the TOP of the spread is zero, as on the left-hand side of the graph a month before the pandemic hit. But remember the average American has a roughly 1% chance of dying in a given year; now he has a 1.1% chance of dying next year. Unless the vaccines work out, of course.





Friday, September 11, 2020

Eleven days in May, revisited

 Well, it's 9/11/2020, so a young man's thoughts flit lightly towards major disasters. A few months (!) back I wrote a post attempting to put the mortality of COVID in perspective, and here we sit; perhaps a longer perspective is now possible.

In the meantime the CDC has released data indicating that the vast majority of Covid deaths had major co-morbidity factors, which bolsters the interpretation that it best be looked at as essentially an acceleration of your remaining days in this vale of tears.

Rather than try to guess how many people actually died of, rather than with, COVID, I simply took the number of people who died of any cause, and compared that to the average non-Covid numbers. You can these stats at the CDC website here.

It now looks like this: 

The initial spike got a longer tail, and there was a second wave, and of course there will be a tail from the second wave you can't see yet due to reporting lag. 

Back in May I wrote that the overall effect of the pandemic had been to reduce everyone's life expectancy by 11 days. What does it look like now?

The low curves are the number of days we were losing per week, the upper ones are cumulative, and the two curves represent the differences from average and statistically significant figures. The "real" number should be between them.

So we lost eleven days in May (actually mostly April), then it slacked off some, and then picked up a bit for the second wave, and is going down again. As of right now we are losing about a day of life expectancy a week, but that is declining. The total amount of life expectancy we've lost so far is closing in on a month.

By the way, remember that average American life expectancy has been improving throughout history. How far would you have to go back to have a life expectancy one month shorter? About to 2010, it turns out. And this decade has been one of abnormally slow life expectancy growth; over the 20th century we typically gained 2 or 3 months a year.

Well, that's one way to look at it, but what's gone is gone. How much more life expectancy can you expect to lose?

To predict the remainder of the loss I fit a curve to the excess deaths. A lognormal curve fits the spikes quite well, as you can see:
The heavy blue curve is actual excess deaths, the orange is a lognormal fit to the first spike, and we add a second lognormal to it for the green, total, curve.  Note that these are in thousands of excess deaths in the US on a weekly basis. You need to compare them to an average 55,000 deaths per week or nearly 3 million a year. 

The total area under the green curve from current date on is just 14,000 deaths, which works out to be 43 hours of life expectancy loss.

 You can all relax now.