Inverted Pendulum

Team: Reed Cao, Robert Herkenham, Ryan Meredith, and Stan Smith

 

 

 

 

 

Final Results

Controller Sampling Period

One of the most interesting results of this project is the effect that the PID controller sampling rate has on the quality of control on the pendulum. By using a Matlab script to iterate through many controller sampling rates, we were able to plot the simulation length for a given set of controller parameters against the sampling period of the controller, and in effect, have a measure of how stable the system is over a range of sampling periods.

Contrary to expectation, the level of control doesn't simply become better with increasing sampling rate. Instead, there is an optimum sampling rate for a given set of PID controller parameters somewhere in the middle of the range provided on the GUI. For example, as shown in Fig. 1, the optimum sampling period occurs near 0.0057 s.

Insert response graph Here

Fig. 1: System simulation length as a function of controller sampling rate with initial angle of 3.5 rad

Furthermore, this sampling rate appears to be independent of the initial angle of the pendulum as shown by the following graph. Although the initial angle of the pendulum varies only slightly from the previous graph, the simulation is very sensitive to the initial angle of the pendulum around this point, shown by the shorter simulation lengths in Fig. 2. No sampling rate is able to produce a simulation greater than one second at an initial angles of 3.6 rad and greater for this particular set of gains of the PID controller.

Insert response graph Here

Fig. 2: System simulation length as a function of controller sampling rate with initial angle of 3.55 rad

At sampling periods greater than the optimum value, the pendulum begins to oscillate with an increasing arc until the cart is unable to correct the pendulum angle within the distance limitation. If there were no limit on the distance that the cart could move, it seems apparent that eventually the cart would no longer be able to keep up with the increasing arc, and the pendulum would become horizontal, ending the simulation.

Smaller sampling periods are less ideal from the constraints placed on how far the cart is allowed to move from its starting position. At sampling periods smaller than the optimum value, the pendulum angle slowly becomes stable, but the cart begins to drift to the left until it hits the distance limit. By looking at the position graph of our GUI, this becomes apparent from the movement of the cart. At the optimum sampling rate, however, the cart reaches very steady oscillation. The following three graphs show the described behavior.

Insert response graph Here

Fig. 3: 0.005727 s sampling period sampling cart oscillations

Insert response graph Here

Fig. 4: 0.01 s sampling period increasing cart oscillations

Insert response graph Here

Fig. 5: 0.001 s sampling period cart drift

In addition, the PID controller parameters can be tuned to optimize the simulation for a particular sampling rate. If, for example, a controller is only able to sample a system at a relatively low frequency, the controller parameters may be chosen to optimize the stability of the pendulum for that rate. The following graph shows the system stability for the controller parameters which optimize the system for the lowest sampling frequency our team could find. Unfortunately, the simulation is only able to last about 60 s, but the sampling period is a relatively large 0.1624 s. By varying the simulation of the parameters, other sampling periods may be optimized.

Insert response graph Here

Fig. 6: Optimization for highest sampling period

Pole-Zero Plot

By using the residue function in Matlab, we were able to plot the pole-zero plot of the compensator formula of our PID controller and see how changing the simulation parameters effected the results.

In general, as the integral gain of the controller increases, the zeros of the plot gain larger imaginary components. Changing the proportional and derivative gains tend to move the zeros horizontally, but the relation to their magnitudes and the locations of the holes is not intuitive. Due to the nature of the compensator formula, one pole of the system will always be at z = 1. The other pole moves depending upon the values of N and Ts in such a way that the controller will be unstable (a pole will move outside the unit circle in the ROC) if Ts > 2*(1/N). As the value of the filter coefficient increases in relation to the sampling period of the controller, the second pole will become more negative. This is reasonable because only N and Ts appear in a denominator of the compensator equation. If the controller is not stable, it will try to apply an unbounded force to the system in order to correct a bounded error. In other words, the controller is overcompensating, and the system will surely not be stable.

An example of an unstable controller is shown in Fig. 7 with the second pole located at z = -1.25. Initially the cart moves to the left to correctly move the pendulum upright. At time 0.19 s, however, the controller shows its instability by moving to the right causing the error of the pendulum angle to increase. This shows that the derivative filter is unstable which creates a controller output which is not always dependent on the pendulum error and could result in an unbounded controller output despite the input being bounded.

Insert response graph Here

Fig. 7: Pole-Zero Plot depicting unstable controller and inverted pendulum movement

Controller LCCDE Equation

The LCCDE of the controller was obtained by analyzing its Z-transform. We accomplished this by using the residue function in order to simplify the Z-transform into a single fraction with a second order numerator and denominator. From this, we can obtain a second order LCCDE equation of the form:

A*y[n] + B*y[n-1] + C*y[n-2] = D*x[n] + E*x[n-1] + F*x[n-2]

Where y[n] is the output force of the controller is applied to the cart and x[n] is the input error to the controller. By inspection, we can see that this equation indicates that the controller is indeed causal, meaning that this controller is possible to implement in real life.

This LCCDE results from the transfer function H(z) of the controller:

 D*z^2 + E*z + F
---------------------
 A*z^2 + B*z + C

Therefore, roots of the numerator are zeros of the system and roots for the denominator are poles of the system. The coefficient A is always equal to 1 which is the same as the first pole of the controller. B is always equal to the second pole, and the sum of A, B, and C is 0 since we always have a pole at z=1. The values of B and C are dependent on N and Ts which is reasonable as described in the pole-zero analysis in the previous section.

D is dependent only on the proportional gain, derivative gain, and filter coefficient while E and F are dependent on all system parameters.

Future Possibilities

This project could be expanded in the future by allowing the user to implement his own transfer function within the Matlab GUI. This could be accomplished by having the user input desired poles and zeros of the controller compensator formula and generating the resulting transfer function. The user could then see how well the equation controls the inverted pendulum in a simulation.