Discrete state-space
Controllability and Observability
Control design via pole placement
Reference input
Observer design
In this digital control version of the inverted pendulum problem, we are going to use the state-space method to design the digital controller. If you refer to the Inverted Pendulum Modeling page, the state-space equations were derived as
M | mass of the cart | 0.5 kg |
m | mass of the pendulum | 0.5 kg |
b | friction of the cart | 0.1 N/m/sec |
l | length to pendulum center of mass | 0.3 m |
I | inertia of the pendulum | 0.006 kg*m^2 |
u | step force applied to the cart | |
x | cart position coordinate | |
phi | pendulum angle from vertical | |
Output are the cart displacement (x in meters) and the pendulum deflection angle (phi in radians).
The design requirements are
Assuming that the closed-loop bandwidth frequencies are around 1 rad/sec for both the cart and the pendulum, let the sampling time be 1/100 sec/sample. Now we are ready to use c2dm. Enter the following commands to an m-file.
Running this m-file in the Matlab command window gives you the following four matrices.
F = 1.0000 0.0100 0.0001 0.0000 0 0.9982 0.0267 0.0001 0 0.0000 1.0016 0.0100 0 -0.0045 0.3119 1.0016 G = 0.0001 0.0182 0.0002 0.0454 H = 1 0 0 0 0 0 1 0 J = 0 0
Now we have obtained the discrete state-space model of the form
must have the rank of n. The rank of the matrix is the number of independent rows (or columns). In the same token, for the system to be completely state observable, the observability matrix
must also have the rank of n.
Since our controllability matrix and observability matrix are '4x4', the rank of both matrices must be 4. The function rank can give you the rank of each matrix. In an new m-file, enter the following commands and run it in the command window.
Controllability = 4 Observability = 4
This proves that our discrete system is both completely state controllable and completely state observable.
The next step is to assume that all four state are measurable, and find the control matrix (K). If you refer to the continuous Inverted Pendulum: State-Space page, the Linear Quadratic Regulator (LQR) method was used to find the control matrix (K). In this digital version, we will use the same LQR method. This method allows you to find the optimal control matrix that results in some balance between system errors and control effort. Please consult your control textbook for details. To use this LQR method, we need to find three parameters: Performance index matrix (R), state-cost matrix (Q), and weighting factors. For simplicity, we will choose the performance index matrix equals 1 (R=1), and the state-cost matrix (Q) equals to H' x H. The weighting factors will be chosen by trial and errors. The state-cost matrix (Q) has the following structure
Q = 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
The element in the 1,1 position will be used to weight the cart's position and the element in the 3,3 position will be used to weight the pendulum's angle. The weighting factors for the cart's position and the pendulum's angle will be chosen individually.
Now we are ready to find the control matrix (K) and see the response of the system. Enter the following commands to an new m-file and run it in the Matlab command window. You should see the following step response.
The curve in green represents the pendulum's angle, in radians, and the curve in blue represents the cart's position in meters. The pendulum's and cart's overshoot appear fine, but their settling times need improvement and the cart's rise time needs to be decreased. Also the cart has, in fact, moved in the opposite direction. For now, we will concentrate on improving the settling times and the rise times, and fix the steady-state error later.
Let's increase the weighting factors (x and y) and see if both the settling and rise times decrease. Go back to your m-file and change the x and y to x=5000 and y=100. Running this m-file in the command window gives you the following new step response.
From this plot, we see that all design requirements are satisfied except the steady-state error of the cart position (x). We can easily correct this by introducing a feedforwarding scaling factor (Nbar).
Unfortunately, we can not use our user-defined function rscale to find Nbar. But certainly we can find it from trial and errors. After several trials, the Nbar equals to -61.55 provided the satisfactory response. Try the following m-file and obtain the step response shown below.
Notice that the steady-state error of the cart's position have been eliminated. Now we have designed the system that satisfies all design requirements.
A basic schematic of the plant-observer system is shown below.
To design the observer, first, we need to find the L matrix. To find the L matrix, we need to find the poles of the system without the observer (the poles of F-G*K). Copy the following commands to an new m-file and run it in the Matlab command window.
In the command window, you should see
poles = 0.9156+0.0729i 0.9156-0.0729i 0.9535+0.0079i 0.9535-0.0079i
We want to place observer poles so that the observer works a lot faster than the system without the observer. Let's place the observer poles far left of above poles, say, at [-0.3 -0.31 -0.32 -0.33]. These poles can be changed later, if necessary. We will use the Matlab function place to find the L matrix. Enter the following commands to an new m-file and run it.
You should see the following L matrix in the command window.
L = 2.6310 -0.0105 172.8146 -1.3468 -0.0129 2.6304 -2.2954 173.2787
Now we will obtain the overall system response including the observer. Once again, create an new m-file and copy the following code.
After running this m-file, you should get the following step response.
As you noticed, this response is about the same as before, and all of the design requirements have been satisfied.
Tutorials