
Open-loop Representation
Closed-loop response with no compensation
Closed-loop response with compensation
What happens to the cart's position?
The transfer function of the plant for this problem is given below:


The design criteria (with the pendulum receiving a 1N impulse force from the cart) are:
M = .5; m = 0.2; b = 0.1; i = 0.006; g = 9.8; l = 0.3; q = (M+m)*(i+m*l^2)-(m*l)^2; %simplifies input num = [m*l/q 0 0]; den = [1 b*(i+m*l^2)/q -(M+m)*m*g*l/q -b*m*g*l/q 0]; pendulum = tf(num,den)
We will now design an inverted pendulum controller for an impulse force using Nyquist diagrams (we cannot use Bode plots because the system is unstable in open loop). Let's begin by looking at the block diagram for this system:

The best way to use MATLAB to solve this problem is to first change the schematic to something that can be modeled much more easily. Rearranging the picture, you can get the following new schematic:

Now we can begin our design. First, we will look at the poles and zeros of this function:
x = roots(num) y = roots(den) x = 0 0 y = 0 -5.6041 5.5651 -0.1428As you already know, we have a pole-zero cancellation at the origin, as well as one positive, real pole in the right-half plane. This means that we will need one anti-clockwise encirclement of -1 in order to have a stable closed-loop system (Z = P + N; P = 1, N = -1). The following m-file will be very useful for designing our controller.
function[ ] = pend()
%define TF
num = [4.5455 0 0];
den = [1.0000 0.1818 -31.1818 -4.4545 0];
pendulum = tf(num,den);
figure(1)
%ask user for controller
numc = input('numc?.........');
denc = input('denc?.........');
k = input('K?............');
%view compensated system bode
contr = k*tf(numc,denc);
loop = contr*pendulum;
bode(loop)
%view compensated system nyquist
figure(2)
subplot (2,1,1)
nyquist(loop)
%view compensated CL system impulse response
subplot(2,1,2)
sys_cl = feedback(pendulum,contr);
impulse(sys_cl)
With this m-file we will now view the uncompensated system's Nyquist
diagram by setting the controller numerator, denominator and gain equal to
one. Enter pend at the command prompt, and enter 1 for numc,
denc, and K. You should see the following plots in your screen:
numc?.........1 denc?.........1 K?............1


Note: The phase portion of the Bode plot shown in your version of MATLAB may differ from the Bode plot in the tutorials by 360 degrees. Shifting the phase by 360 degrees does not change the relationship between the Bode plot and the dynamic response of the system.
The system is unstable in closed loop (no encirclements of -1). Our first step will be to add an integrator to cancel the extra zero at the origin (we will then have two poles and two zeros at the origin). Use the pend command again.
numc?.........1 denc?.........[1 0] K?............1


numc?.........[1 1] denc?.........[1 0] K?............1


numc?.........conv([1 1],[1 1]) denc?.........[1 0] K?............1


numc?.........conv([1 1],[1 1]) denc?.........[1 0] K?............10


If we try different combinations of poles and gains, we can get a very reasonable response. (Enter the command axis([0 5 -0.05 0.1]) after the pend command.)
numc?.........conv([1 1.1],[1 5]) denc?.........[1 0] K?............10


At the beginning on this solution page, the block diagram for this problem was given. The diagram was not entirely complete. The block representing the the position was left out because that variable was not being controlled. It is interesting though, to see what is happening to the cart's position when the controller for the pendulum's angle is in place. To see this we need to consider the actual system block diagram:

Rearranging a little bit, you get the following block diagram:

The feedback loop represents the controller we have designed for the pendulum. The transfer function from the cart's position to the impulse force, with the frequency response feedback controller which we designed, is given as follows:



For more about the Laplace transform please refer to the inverted pendulum modeling page.
Now, create a new m-file and run it in the command window:
M = .5; m = 0.2; b = 0.1; i = 0.006; g = 9.8; l = 0.3; q = (M+m)*(i+m*l^2)-(m*l)^2; %simplifies input num1 = [m*l/q 0 0]; den1 = [1 b*(i+m*l^2)/q -(M+m)*m*g*l/q -b*m*g*l/q 0]; G1 = tf(num1,den1); num2 = [(i+m*l^2)/q 0 -m*g*l/q]; den2 = den1; G2 = tf(num2,den2); k = 10; numc = conv([1 1.1],[1 5]); denc = [1 0]; contr = tf(k*numc,denc); sys_cl = feedback(1,contr*G1)*G2; sys_cl = minreal(sys_cl); t=0:0.01:100; impulse(sys_cl,t)

The minreal command tells MATLAB to cancel out all common poles and zeros in the closed loop transfer function; this gives the impulse function better numerical properties. As you can see, the cart moves in the negative direction and stabilizes at about -0.18 meters. This design might work pretty well for the actual controller, assuming that the cart had that much room to move. Keep in mind that this was pure luck. We were not trying to design to stabilize the cart's position, and the fact that we have is a fortunate side effect.
