The Mathematics of Range Anxiety

Late at night, the student in the apartment is awakened by a strange smell. Investigating in the darkened rooms, she sees a burst of flame engulf her roommate’s hoverboard. There is only just enough time to get everyone out of the apartment before the rooms are fully involved.

Near the end of the marathon, a camera drone suddenly begins to descend, apparently moving in for a close shot. Then it abruptly tilts and plunges, striking two runners and disrupting the finish, leaving a trail of minor injuries, angry runners, and rather pathetic-looking wreckage (Figure 1).

Figure 1. Misestimating the state of charge of a lithium-ion battery can result in tears, or worse

crashed-drone

In heavy afternoon traffic, the electric car suddenly pulls toward the left shoulder, cutting off a truck and several passing cars. Then it drifts to a stop, still partly blocking one lane. Everyone manages to avoid a collision, but traffic flow will not recover until the end of the evening commute.

Each of these scenarios has a common element: lithium. As application of lithium-ion batteries has spread across toys, tools, cars, and jetliners, system designers have had to confront a worrying problem: managing lithium-ion batteries is not easy, it is not inexpensive, and even with considerable hardware resources it remains science with more than a brush-stroke of art. Yet it is a safety-critical and mandatory task.

Non-Linear

The underlying issue rests in the nature of lithium batteries. They have the advantages of good energy storage per gram and per cubic centimeter, nearly constant voltage over a wide range of charge levels, rechargeability and—if they are properly managed—long life. These traits have made them natural choices across an astonishing array of applications.

But there is another side to this success story. The batteries’ most dramatic characteristic is that they have the ability, sometimes under seemingly reasonable conditions, to generate damaging amounts of heat. Under some conditions—which hoverboards seem to have the knack of finding—the heat can lead to explosive combustion.

Explosions, fires, and injuries provide good incentive for knowing the state of charge of a battery’s cells. But that brings us back to one of the chemistry’s big advantages: nearly constant open-circuit voltage over perhaps 80 percent of the range of charge. In fact there is no one externally-measurable quantity that can by itself provide an accurate value for the charge on a cell until the cell is very close to either over-charge or exhaustion. Thus system designers have to choose between inexpensive but possibly inaccurate charge estimations or much more complex and hardware-consuming techniques for hidden-state estimation. Given that many lithium-ion-powered systems are seriously cost-constrained, and yet the systems’ potential for havoc is not necessarily proportional to their cost, designers have some hard choices to make.

Simple or Complex

There are times when cost simply dictates the decisions on battery management. When a quadcopter sells for under $50 retail, the bill of materials cost has no headroom for expensive silicon. In these situations, the choice often goes to the lowest-cost approach to state-of-charge (SOC) estimation: measuring output voltage. In principle, the open-circuit voltage on a lithium-ion cell does decrease as the cell discharges (Figure 2). After a short initial drop, the voltage decreases, usually monotonically, but by as little as a fraction of one percent, until the cell approaches full discharge, where it begins to plunge. So by the time a simple voltage measurement detects an unambiguous drop, it is too late to safely abort the mission. Similarly on the charging cycle, the sharp increase in open-circuit voltage may be detected too late to avoid dangerous heating.

Figure 2. Lithium-ion cells maintain a nearly constant voltage over a wide range of charge.

lithium-ion_cells

That gradual ramp is measurable. But it is an unusual system in which you can frequently float the battery long enough for the voltage to stabilize and for you to make an open-circuit measurement. And over most of the range of charge, the voltage is more sensitive to load current—and perhaps other variables such as temperature, age, and charging history—than it is to state of charge. Add in unavoidable measurement noise in a system that is often running several high-current motors, and the approach becomes seriously questionable. Some sources claim that direct voltage measurement rarely delivers better than 10 to 20 percent accuracy. That is more than enough to remind you to plug the car in tonight, but not enough to assure you that you will certainly make it home from work on a partial charge.

Yet the determined engineer is not deterred by adversity. If you can’t get an accurate estimate by just measuring voltage, why not measure the sources of error too, and correct for them? Following this path, battery management systems may add temperature sensors, current sensors, and low-pass filters—adding cost and complexity, but not necessarily accuracy, unless there is some way to calibrate the algorithm to the particular battery in question.

There is an entirely different approach—coulomb counting. The idea is to think of the battery as a charge container: what goes in has to come out. And in fact lithium batteries have good charge retention characteristics, so over a short period of time this is not a bad approximation. You can measure current and calculate how much charge goes in and how much comes out of the battery, so—problem solved, right? Would that it were that simple.

For coulomb counting to work, you have to know the initial state of charge. You could of course monitor changing, and watch for the telltale upswing in open-circuit voltage as the cell approaches full charge. But then you would still have to refer to the history of the cell to know what full charge actually was at the present time. And if there is even a tiny DC offset in your current measurement, the error will accumulate over time, causing your charge estimate to drift. So you would need to reset to a known state of charge fairly frequently. And in most use scenarios, you couldn’t count on the user either to give you time for a full charge or to fully discharge the cell so that you know what the capacity really is at the moment. It does change with cell temperature and with aging.

Complex Algorithms

Some designers have looked at this situation and said to themselves, “What we have here is a system with hidden state.” If it is possible to accurately model such systems, and if the model allows prediction of the hidden state, even a noisy, unreliable prediction, from the externally measurable state, there is a known technique for estimating the hidden variables. In this case, that would mean estimating the state of charge based on such quantities as cell temperature, voltage, and current under load. That technique is the Kalman filter.

The Kalman filter—beloved of statistical-control theorists and feared by many engineers—is an iterative digital computation that will—if its assumptions are met—allow you to accurately track hidden state inside a system by repetitively sampling state variables that you can measure from the outside. An advantage of the Kalman filter is that it can work even in the presence of significant noise, both in the measurements and in your knowledge of the state of the system.  It is used widely, across a range of seemingly dissimilar applications from airborne vehicle guidance systems to sensor fusion in smart vehicles to shaft position estimation in brushless motors. And yes, it is used for estimating state of charge in lithium batteries.

The Kalman filter starts out with a model of the system it will be estimating—a model that expresses the system’s state variables at the present time—call it time t—as a linear combination of the state variables at the previous sample time, t-1, plus control input variables, plus simple Gaussian noise. One thing that makes Kalman filters a bit obscure mathematically is that, with the addition of the noise, the state variables are not scalars—they are Gaussian probability functions. This allows mathematicians to go on at great length about covariance matrices, when most of the time all you really care about is the mean of the probability distributions.

The vital importance of the model is that it creates a relationship between the variables you can measure and the ones you can’t. So it predicts the hidden internal state of the system based on its observable behavior in previous cycles. Clearly, the success of the Kalman filter in cutting through noise and uncertainty depends on the quality of the model. In our case, where we are trying to estimate the charge on each cell by measuring external voltages and currents, that means an accurate equivalent circuit for a cell is mandatory (Figure 3). The model we show here, developed by researchers at the University of Pisa, is among the simpler accurate ones. It includes some of the internal dynamics of the cell, but leaves out behaviors like hysteresis that may be significant in some applications.

Figure 3. This equivalent circuit for a cell is based on work from the University of Pisa.

equivalent_circuit

If you have been reading carefully, you may have spotted a problem at this point. This model—like many in the real world—will not give us a linear relationship between consecutive samples of the state variables. Developers resolve this by using Taylor series to produce a locally linear model, calling their handiwork an Extended Kalman filter.

But back to how it works. From the model and your previous best estimate of the state at t-1, you calculate what the state should be now, at time t. You also sample the state variables you can get at, add in Gaussian noise, and calculate—from the system model, again—what the state probably really is based on your measurements.

Now you have two versions of the current state: one based on the best estimate of the previous state, and one based on the current measurements. You combine them, using a set of weighting coefficients collectively called the Kalman gain, to produce a new best estimate for the state in time t. Finally, you update the Kalman coefficients based on the difference between the estimated and measured values, putting less weight on inputs that appear to be error-prone. And then you go back to the beginning and repeat the process for the next sample time.

This iterative procedure gives a mathematically optimal result for some classes of systems. It has issues with non-Gaussian noise, since the math depends on a linear combination of probability functions still being a Gaussian distribution. It can’t work if the measured variables are insufficient to predict the hidden state—for instance if over a wide range the lithium cell shows absolutely no change in voltage or current due to state of charge. And it involves a lot of multiplying and adding on each cycle, ideally in floating point. This is not a job for a low-cost microcontroller.

For these and other reasons—a guy has to have a thesis topic, after all—a number of other approaches have been tried to turn a time-series of voltage and current samples into an accurate estimate of the state of charge. Neural networks have been trained on files of measured data, which in retrospect can include fairly accurate data on the actual charge on the cell—once you fully discharge it, you know what the initial state of charge really had been. Normally this training would be done on pre-collected data, since the computations involved in training a neural network would be beyond the range of most on-board processors and memory systems. So the battery on which the network was trained may or may not closely resemble the actual battery in the system. If the resemblance is slight, there will be tears.

Perhaps inevitably, fuzzy logic has also been tried. But at the moment, the Kalman approach seems the most promising.

The Whole Problem

Estimating the charge on each cell is not the end of battery management. We still have to use that data to control charging, to protect weak cells, to spot potentially hazardous states, and to report accurately on the state of the whole battery. These tasks require not only estimating the state of charge of each cell, but controlling individual cell charging currents and discharge conditions, potentially switching cells and shunts in and out of the battery circuit during operation.

In a $50,000 vehicle this level of sophistication is affordable. In a $50 toy drone, it may be impossible. Yet an error in managing the toy is potentially as catastrophic as an error with the car. That remains an interesting problem for designers.


CATEGORIES : All, System Management/ AUTHOR : Ron Wilson

10 comments to “The Mathematics of Range Anxiety”

You can leave a reply or Trackback this post.
  1. Thanks Ron for a very interesting article. I wonder if Amazon have considered this implication in their drone delivery plans !!
    Regards
    George

  2. Hi Ron,

    Are you suggesting FPGAs can better implement Kalman filtering than microcontrollers? If yes, would you explain how?

    Regards,
    Nitish

    • Ron Wilson says: -#2

      Nitish:
      I didn’t mean to suggest there was anything magical about FPGAs in this regard. Kalman filters can involve a lot of matrix computations–nothing a microcontroller with adequate memory can’t handle. But FPGAs tend to be very rich in hardware multiply-accumulate units, and can implement data-driven architectures efficiently. So they, like DSPs, GPUs, or purpose-built ASICs, can achieve quite high computation rates on matrix operations. With Kalman filters, that translates directly into higher possible sampling rates at lower latency.
      ron

  3. It must be that internal chemistry and state of charge are strongly coupled. How costly would it be to add a sensor and output that information?

  4. If extended Kalman filter has good performance in estimating future, is it possible to consider that a tandem connection of extended Kalman filters has higher performance? If not, what is its reason ?

  5. this article is very sinificant,it provides a new idea to a unsteady system for me. Kalman filter is widely used, material chemistry research is also important to solve battery question.

  6. Thanks for this article.

    We NiMetalHydride boys add an ‘unbalanced’ string of cells to the situation after a few years of operation of our cars, and wonder why we are stranded with a ”Hybrid System Fail.
    ccdisce.

  7. Hello Ron;

    A very interesting approach…
    I am very interested to see what your answer would be to Nitish’s question regarding FPGA’s would be.

    Regards,
    Marlon Kasprzyk

  8. Are you suggesting FPGAs can better implement filtering

Write a Reply or Comment

Your email address will not be published.