Friday, January 25, 2019

Correcting the steady state error in LQR

So in the previous post I had posted on the state feedback control of a single phase UPS with the state feedback gain designed using Linear Quadratic Regulator (LQR). There were positives and negatives. The positive was that you didn't need synchronous transformation - the control was applied in stationary reference frame. The negative was that there was a steady state error. The main cause for the steady state error was the choice of reference for the inductor current. The reference for inductor current was assumed to be equal to the load current, but this neglects the current drawn by the filter capacitor.

The straightforward way to solve the steady state error issue would be to try to generate a more accurate reference for the inductor current. So, the equation for inductor current would be:

if = Iload + icap

To estimate the filter capacitor current icap, the reference output voltage which is the desired voltage across the filter capacitor can be used:

if = iload + Cf d vo_ref/dt

This can be done and has been done by many many researchers in the past. I too have tried to implement the above. The only tricky part is the d/dt. In control, you do not want to perform differential - never ever. For the simple reason that d/dt magnifies any noise that may be present in the system. So we find ways of generating the signal without d/dt.

Anyway, I have always been thinking - do we need to do this? We know there is an error. So, let's first analyze this error and figure out what it looks like. Assuming the desired reference output voltage is perfectly sinusoidal, this was the tracking performance we saw from the last post.



Next, let's plot the error.



The error between the desired reference output voltage and the actual output voltage is a sinusoidal waveform. Sinusoidal waveforms are nice - periodic, nice shape etc. Most importantly, a sinusoidal waveform is an indication that the reason for the error lies mainly with the choice of the magnitude. Why? If the error was let's say a constant, this would mean the reference and the actual waveforms will be criss-crossing each other. Because, the error is defined as v_ref - v_actual. If the error was some other weird shape, it means it is difficult to predict how the actual voltage tracks the reference. But with a sinusoidal waveform such as the one above, the reference always has a larger magnitude and the actual voltage will differ only by magnitude and not by phase angle. Try drawing some waveforms and check it out for yourself.

So, the next part - the solution. A sinusoidal waveform is nice because it can be defined by several parameters - peak, RMS, frequency etc. The frequency of the sinusoidal waveform will be the same as the system frequency. Well, this might be worth a check. But peak and RMS are related. And RMS is very convenient to calculate.

RMS = Integral ( sqrt(err*err/T) )

Here, T is the time period of the waveform and is also the time interval of integration. Now, there a few ways of doing the above integration. Some (and this includes me before) prefer to do a moving window integration. So, they collect some number of samples - 100, 1000 etc and keep moving the waveform across this window. And they calculate the sum of squares over this window (or array of values). This works. But quite inefficient from the perspective of implementation, if you were to implement in a DSP or FPGA.  You need an array of 1000 elements - not very nice.

A simpler way of doing this integration is to declare a timer for the time period T. Start the sum with 0. And add squares to this sum until the time period expires. At this point, use the sum to calculate RMS and reset the sum and also reset the time period. This is convenient to do using a DSP or FPGA. The result of this is:



And as you can see the RMS has been added to the waveform. It updates every 0.01 seconds. The larger this time period is, the better for accuracy of calculation of the RMS. But is bad for the performance of the controller as the RMS value will be of the previous state until the time interval expires.

So, now what of it? If we know the RMS value (or incidentally the peak value), we can now scale up the reference voltage by that value. The reason, we know this error is going to appear anyway. So, if vref if what we want and verr is the error we get, by manipulating vref to be:

vref' = vref + verr

And applying vref' to the state feedback, the error verr that will anyway result, will now produce a v_actual that is almost equal to v_ref. Check this out:




And you see the difference. After 0.01s, the peak error (RMS*1.414) is added to the desired reference. The result, the actual voltage now catches up with the desired reference that we wanted to begin with. And you see, the tracking is almost perfect, the error is close to zero - tough to see the waveforms apart.

The true test will come when the reference has harmonics - let's add a 5th harmonic component to the desired voltage output.


The tracking is way better than the first 0.01s when the raw state feedback was working. The errors are mainly at the parts where the d/dt of the desired voltage is very high. It is important to note at this point that a controller cannot overcome the design constraints of a system (in this case an inverter). Therefore the maximum d/dt that an inverter can achieve is limited by the choice of dc bus voltage, filter inductor and filter capacitor. So, are those errors the result of our control design or just the way the inverter is and whatever may be the answer, what do we do about it? This will be a future post.

For now, the state feedback controller has achieved both targets - very close tracking with negligible error and also hassle free control implementation - no synchronous transformations etc. Any waveform can be tracked - pure sinusoid or with harmonics.

No comments:

Post a Comment