University of Notre DameAME 30315 Pendulum Project

University of Notre dame /
Pendulum Project /
AME 30315 /
Joshua Szczudlak /
FirasFasheh

5/2/2012

For me, I am driven by two main philosophies, know more today about the world than I knew yesterday. And lessen the suffering of others. You'd be surprised how far that gets you.
- Neil deGrasse Tyson

Abstract

The purpose of this project was to design a controller that stabilizes an inverted pendulum. The first step in designing the controller was to identify the system. Through the process of system identification it was found that and Next, a transfer function was derived for the system using the governing equations of motion. This transfer function was found for an output position, in terms of an input torque, Additionally, lead and lag compensators were created to help stabilize the system. Two lead-lag compensators were designed. One controller used the assigned parameters of and a lag gain of 92. The other controller was designed for optimal performance including a half second rise time, quick settling time, and small stead-state error. These parameters were evaluated using root locus plots and the used of Simulink to predict performance.

Table of Contents

1 System

1.1 System Identification

1.1.1 Design Parameters

2 Control Design

2.1 Continuous Transfer Function

2.1.1 Hanging Pendulum

2.1.2 Inverted Pendulum

2.2 Design Parameters

2.3 Lead Control

2.3.1 Design

2.3.2 Lead Calculation

2.4 Lag Control

2.4.1 Design

2.4.2 Lag Calculation

2.5 Discrete-time Transfer Function

2.5.1 Conversion to Discrete-time

3 Controller Implementation

3.1 Controller Implementation

3.1.1 Non-dimensionalization

3.1.2 Error Calculation

3.1.3 Transfer Function Implementation

5 System Evaluation

5.1 Theoretical Modeling

5.2 Transient Evaluation

5.2.1 Rise Time Evaluation

5.2.2 Overshoot Evaluation

5.3 Steady-State Evaluation

6 System Verification

6.1 Position Verification

7 Conclusions

Appendix A: Matlab Code

Appendix B: C Code

Appendix C: Discretization of Transfer Function

Appendix D: Derivations of Transfer Function

Appendix E: Lead Compensator Calculations

Appendix F: Iterations Table

List of Tables

Table 1. Steady-state error in the controller at various desired angles.

List of Figures

Figure 1. Measured damped frequency response

Figure 2. Root locus of the hanging pendulum transfer function

Figure 3. Comparison of measured damped frequency response and derived transfer function

Figure 3. Root locus of the inverted pendulum transfer function

Figure 4. Root locus with effect of the lead compensator

Figure 5. Root locus of the transfer function with the lead-lag compensator

Figure 6. Representative Simulink block diagram

Figure 7. Response predicted by Simulink

Figure 8. Response of pendulum

Figure 9. Response of pendulum at angles of -30º to 30º

1 System

1.1 System Identification

The first step to designing a controller is to determine what sort of system you are dealing with and what parameters you need to model the system accurately. Determining the parameters to the pendulum system is fairly simple because when a step input is sent to the pendulum it responds in an easily understood sinusoidal manner. The parameters necessary for the modeling of the pendulum are , the damping ratio, , the natural frequency, and F a scale factor. A series of simple equations can be used to determine these expressions. The first equation can be used to find the damping ratio,

/ (1)

where is the logarithmic decrement, is the damping ratio of the system, and and are the distance from the steady-state value of the second and third peaks respectively. This equation can be used to determine the damping ratio of the pendulum system.

Knowledge of the period and the damping ratio allows us to find the damped natural frequency of the system.

/ (2)

where is the damped natural frequency, and is the period. Using the damped natural frequency and the damping ratio the natural frequency can be determined.

/ (3)

where is the natural frequency. A final scale factor was determined by multiplying the steady-state value by the square of the natural frequency and dividing by the value of the applied torque. Figure 1 shows the damped frequency response of the pendulum.

Figure 1.Measured damped frequency response

The parameters derived from this plot are outlined in section 1.1.1 Design Parameters.

1.1.1 Design Parameters

The design parameters were determined through the system identification process outlined above. The parameters used in the design of the pendulum controller were found by averaging data taken by testing multiple pendulums at various torques. Doing this ensured that any pendulum could be used with relative accuracy. This process yielded the following parameters: was 6.28 Hz, was 0.055, and the scale factor F was 37.2. Additional system identification plots can be found in the Matlab code in Appendix A.

2Control Design

2.1 Continuous Transfer Function

A transfer function in the continuous time domain was derived first for the hanging pendulum system. This system is then inverted for uses in the inverted pendulum system. The inverted pendulum transfer function is then discretized for use in the microcontroller.

2.1.1 Hanging Pendulum

The transfer function of the pendulum is shown in the following equation,

/ (4)

whereR is the input position error and T is the output torque. Appendix D shows the calculations necessary to obtain the transfer function for the hanging pendulum.

Figure 2 is the root locus plot of the hanging pendulum system.

Figure 2.Root locus of the hanging pendulum transfer function

Figure 3 shows the measured response of the hanging pendulum system and the hanging pendulum transfer function after it has been subject to a step input. The similarity between the two helps to verify the accuracy of the model as well as the accuracy of the values obtained from the system identification.

Figure 3.Comparison of measured damped frequency response and derived transfer function

2.1.2 Inverted Pendulum

After obtaining the transfer function for the hanging pendulum the transfer function for the inverted system is almost trivial. The difference is in a sign difference in the equations of motion. This transfer function is shown in the following equation,

/ (5)

The only difference between the two transfer functions is that the pendulum responds to the force of gravity. When the hanging pendulum is displaced in the positive direction, the gravitational force opposes it. However, in the inverted pendulum system the gravitational force works with displacement. This difference causes the sign change on the term.

Figure 3 is the root locus of the invert pendulum transfer function.


Figure 3.Root locus of the inverted pendulum transfer function

Of interest to us at this point is the location of the poles because these will help to determine many of the characteristics of our lead and lag controllers. These poles are at 5.93 and -6.62.

2.2 Design Parameters

The design of the controller is dictated mostly by the desired response characteristics. Therefore before we can begin to design the controller, it is useful to specify a few parameters. The parameters are:

(1)Rise time of 0.5 seconds or less

(2)Damping ratio of 0.32

(3)Lag gain of 92

These parameters will be used as a guide to the design of a lead and lag compensator.

2.3 Lead Control

Lead compensator is a fairly easy and effective means to approximate Proportional-Derivative, PD,control. The idea behind PD control is that the control system should reflect the derivative of the error of the system. Quite simply how large the control input should be should depend upon whether the error is increasing or decreasing. The lead compensator provides phase lead. This shifts the poles to the left, which enhances the stability and performance of the system.

2.3.1 Design

The lead compensator is of the form

/ (6)

where is the location of the lead zero and is the location of the lead pole.

The angle to the compensator pole must be

/ (7)

because points on the root locus satisfy , we can use the angles from the two poles and one zero to the desired point to compute what the angle from the compensator pole must be.

2.3.2 Lead Calculation

Calculations for the lead controller are done using the Matlab function pole_locashown in Appendix E. This function takes the location of the transfer function poles as well as a desired zero and outputs a minimum lead pole location. A large part of the lead design is dictated by the assigned damping ratio value. This is because,

/ (8)

where is given by the root locus plot. A small amount of control over the lead design is exercised in the placement of the lead zero. This zero was placed as close as possible to the plant pole in order to mitigate any adverse effects the zero would have on the response of the system. Using a zero at -7 a pole of -8.5 is needed to meet the minimum design specifications. The gain needed to obtain the correct damping ratio was then . However this design did not seem optimal. To optimize the design it was decided that the lead pole needed to be moved farther left in order to increase its effect on the root locus. The actual placement of the pole was found through an iterative process. This process and comments on response can be found in Appendix F. The final design of the lead compensator is shown in Equation 9.

/ (9)

The root locus of the plant transfer function with the effects of the lead compensator is shown in Figure 4.

Figure 4.Root locus with effect of the lead compensator

2.4 Lag Control

The downside to PD control and thus lead compensation is that it tends to offset from the target value. To account for this an additional lag compensator is needed. A lag compensator approximates Proportional-Integral,PI,[F1]control to reduce the steady-state error.

2.4.1 Design

A lag compensator is of the same form as the lead compensator. See Equation 6. The pole and zero of the lag compensator should be close together so as not to cause the poles to shift right, which could cause instability or slow convergence. Additionally, since their purpose is to affect the low frequency range they should be near zero.

2.4.2 Lag Calculation

The lag compensator was designed to be a balance between rise time effects and stability issues. The closer the lag compensator values were to zero the less effect they had on stability. However, if these values were too close to zero, they negatively affected rise time. The placement of the lag zero, and thus the lag pole, was also determined through an iterative process. A lag zero was chosen and then a lag pole was calculated using the lag gain ratio. The final design of the lag compensator is shown in Equation 10.

/ (10)

The root locus of the transfer function with the lead-lag compensator is show in Figure 5. The point shown corresponds to the optimal gain value used.

Figure 5.Root locus of the transfer function with the lead-lag compensator

2.5 Discrete-time Transfer Function

Up to this point the entire controller design has been in continuous-time. However, the microcontroller only works in discrete-time. Therefore the controller must be converted from continuous-time to discrete-time.

2.5.1Conversion to Discrete-time

The Tustin method allows us to switch from continuous time to discrete time by substituting in the following equation for ,

/ (7)

where is the integration step size. The Matlab c2d command can be used to make this substitution. For completeness hand substitutions for a single lead-lag controller were also done. Appendix C shows these substitutions.

3 Controller Implementation

3.1 Controller Implementation

The controller is implemented in discrete-time using the substitution described above. Additional steps are described below.

3.1.1 Non-dimensionalization

All terms relevant to the control system are non-dimensionalized. This was done for two reasons. (1) It allows for units to be taken in to account at the end of the program and (2) It allows for easier debugging because all important parameters have to be between 0 and 1. Because we had no real sense of what sorts of values we should expect from the torque at various positions, it is much easier to catch an error this way.

3.1.2Error Calculation

The error is calculated by subtracting the current position from the desired position and then multiplying by a scale factor which includes the gain. This value is then divided by the approximate maximum position which non-dimensionalized the error.

/ (8)

where is the error in the current system, and is the gain.

3.1.3 Transfer Function Implementation

The transfer function is implemented by solving for the output value, the torque. This torque is a function of the current error in the system, the previous loop’s error value, the error two loops previous, the previous loop’s torque, and the torque two loops previous all scaled by coefficients obtained from the discrete transfer function. For example the implemented transfer function looked something like this,

/ (9)

where and are the coefficients obtained from the discrete transfer function, is the error in the system, is the output torque and prevand prev2 denote the previous and twice previous values, respectively. Additionally, a code needed to be implemented that kept the applied torque between -400 and 400. This restriction was caused by supplied PWM.

5 System Evaluation

When the program was run the following errors were displayed:

“filename.c: In function `main':

filename.c:65: warning: unused variable `i'

C:\usr\bin\..\lib\gcc-lib\m6811-elf\3.3.6-m68hc1x-20060122\..\

..\..\..\m6811elf\bin\ld.exe:ldscripts/m68hc11elfb.xbn:264:

warning: memory region eeprom not declared”

The first warning, “unused variable” comes from a counter that was occasionally used to stall the program while evaluating system performance. Neither warning affects the programming of the controller.

5.1 Theoretical Modeling

A theoretical model of the controller was implemented using the Simulink block diagram shown in Figure 4.

Figure 6. Representative Simulink block diagram

The response of the system is compared against the results presented in Simulink to get a more thorough understanding of system performance. Figure 7 shows the response predicted by Simulink.

Figure 7.Response predicted by Simulink

5.2 Transient Evaluation

The transient response was evaluated by looking at the rise time and the overshoot. Figure 8 shows the response of the pendulum.

Figure 8.Response of pendulum

5.2.1 Rise Time Evaluation

Simulink predicts about a 0.2 s rise time. The pendulum itself has a rise time of approximately 0.6 s. Although these values differ, the pendulum almost perfectly meets the designed for rise time of 0.5 s. This difference in rise time is mostly likely attributed to neglected values in the derivation of the transfer function. Slipping of the pendulum arm at the point of contact of the motor is not considered. The elasticity of the pendulum is also not considered. Both of these factors could contribute to a longer rise time.

5.2.2 Overshoot Evaluation

Simulink predicts an overshoot of about 45%. The actual pendulum, however, has an overshoot of nearly 150%. Part of this error can be attributed to the fact that the microcontroller can only take values for torque within the 400/-400 range. The overshoot could be further exasperated by the fact that the microcontroller only takes integer values for input torque. A more precise system that takes decimal inputs could decrease this error. The errors are compounded by the discretized controller system. The torque is computed by using the previous two error and torque values. If these values are themselves in error then the torque could overcompensate and therefore increase the overshoot value.

5.3 Steady-State Evaluation

To evaluate the steady-state response of the system a program is run and swept through a variety of angles. The approximate errors at these angles are tabulated in Table 1. This table shows that as the displacement increases, the error increases. This result is most likely due to the small angle approximation made during the derivation of the transfer function. Additionally, the error seems greatest when the desired value is negative. This error is most likely caused because of the way the motor applies the torque. More than likely the motor has a certain direction that it prefers to apply a torque. This direction would have a stronger and more constant value than the ‘reverse’ direction. This is probably what is causing the greater error on the negative displacement side.

Table 1.Steady-state error in the controller at various desired angles.

Desired Angle [] / Error [] / Desired Angle [] / Error []
-30 / -1.5 / 0 / 1
-20 / -1.5 / 10 / 0.5
-10 / -1 / 20 / 0
0 / 1 / 30 / 1

Figure 9 shows the response of the system as it is being swept through the various angles. It’s interesting to note that although there is a small amount of steady-state error associated with the system, the rise times and overshoots stayed relatively constant. Additionally, the settling time of the system can be computed from Figure 9. Simulink predicts a settling time of about 6 s. The actual pendulum settles in about 4 s. This lowering of the settling time of the actual pendulum could be attributed to the increase in overshoot, by overshooting so much the controller requests additional torque from the motor. This additional torque acts to quickly forces the pendulum to its steady-state value.