Experiment 4
Experiment 4
Spring 2023
Experiment No. 4
The output of a PID controller, which is equal to the control input to the plant, is calculated in the time domain from the
feedback error as follows:
The transfer function of a PID controller is found by taking the Laplace transform of the above equation.
Increasing the proportional gain ( ) has the effect of proportionally increasing the control signal for the same level of
error. The fact that the controller will "push" harder for a given level of error tends to cause the closed-loop system to
react more quickly, but also to overshoot more. Another effect of increasing is that it tends to reduce, but not
eliminate, the steady-state error.
The addition of a derivative term to the controller ( ) adds the ability of the controller to "anticipate" error. With simple
proportional control, if is fixed, the only way that the control will increase is if the error increases. With derivative
control, the control signal can become large if the error begins sloping upward, even while the magnitude of the error
is still relatively small. This anticipation tends to add damping to the system, thereby decreasing overshoot. The addition
of a derivative term, however, has no effect on the steady-state error.
The addition of an integral term to the controller ( ) tends to help reduce steady-state error. If there is a persistent,
steady error, the integrator builds and builds, thereby increasing the control signal and driving the error down. A
drawback of the integral term, however, is that it can make the system more sluggish (and oscillatory) since when the
error signal changes sign, it may take a while for the integrator to "unwind."
The general effects of each controller parameter ( , , ) on a closed-loop system are summarized in the table
below. Note, these guidelines hold in many cases, but not all. If you truly want to know the effect of tuning the individual
gains, you will have to do more analysis, or will have to perform testing on the actual system.
CL RESPONSE RISE TIME OVERSHOOT SETTLING TIME S-S ERROR
When you are designing a PID controller for a given system, follow the steps shown below to obtain a desired response.
1. Obtain an open-loop response and determine what needs to be improved
2. Add a proportional control to improve the rise time
3. Add a derivative control to reduce the overshoot
4. Add an integral control to reduce the steady-state error
5. Adjust each of the gains , , and until you obtain a desired overall response. You can always
refer to the above table to find out which controller controls which characteristics.
Lastly, please keep in mind that you do not need to implement all three controllers (proportional, derivative, and integral)
into a single system, if not necessary. For example, if a PI controller meets the given requirements (like the above
example), then you don't need to implement a derivative controller on the system. Keep the controller as simple as
possible.
Task 1 Basics
a- Define a PID controller in MATLAB using a transfer function model directly.
b- Alternatively, use MATLAB's pid object to generate an equivalent continuous-time controller.
c- Convert the pid object to a transfer function to verify that it yields the same result as above.
The transfer function between the input force and the output displacement then becomes
Let m = 1 kg, b = 10 N s/m, k = 20 N/m and F = 1 N. Substituting these values into the above transfer function gives.
a- Plot the open-loop step response. Find the DC gain, steady state error, rise time and settling time. Mark it on the
graph.
b- From the table shown above, we see that the proportional controller ( ) reduces the rise time, increases the
overshoot, and reduces the steady-state error. The closed-loop transfer function of our unity-feedback system with a
proportional controller is the following, where is our output (equals ) and our reference is the input:
Let the proportional gain ( ) equal 300. Plot the step response. Observe the effect on system characteristics.
c- Let equal 300 as before and let equal 10. Plot the step response. Observe the effect on system
characteristics.
d- Let's reduce to 30, and let equal 70. We have reduced the proportional gain ( ) because the integral
controller also reduces the rise time and increases the overshoot as the proportional controller does (double effect).
Plot the step response. Observe the effect on system characteristics.
e- Now, let's examine PID control. Tune the parameters to get the desired response.
f- Repeat the above task using using pidtune or pidTuner.
The transfer function model for the cruise control problem is given below.
a- Find a closed-loop transfer function with a proportional control added. Use equal to 100 and a reference speed
of 10 m/s. Plot the step response. You can increase the proportional gain, , to reduce the rise time and the steady-
state error. Set equals to 5000 and observe the response. Is it realistic?
b- Let equal 600 and equal 1 and see what happens to the response. Now adjust both the proportional gain,
, and the integral gain, , to obtain the desired response. When you adjust the integral gain, , we suggest you to
start with a small value since a large can de-stabilize the response. Achieve the desired response with PI control.
c- Let equal 1, equal 1, and equal 1.Plot the step response and adjust all of , , and until you
obtain satisfactory results. Usually choosing appropriate gains requires a trial and error process. The best way to attack
this tedious process is to adjust one variable ( , , or ) at a time and observe how changing one variable
influences the system output. The characteristics of , , and are summarized above.
For a 1-rad/sec step reference, the design criteria are the following.
a- Implement a proportional controller with a gain of 100 and determine the step response Comment on the response
characteristics.
.
b- Try a PID controller with small and . Steady-state error will go to zero for a step input. However, the time it
takes to reach steady-state is far larger than the required settling time of 2 seconds. This process can be sped up by
increasing the value of . However, the large will greatly increase the overshoot. Increase in an attempt to
reduce the overshoot. In this way, tune the controller to meet the designed criteria.
The structure of the control system has the form shown in the figure below.
For a 1-radian step reference, the design criteria are the following.
b- Let's also consider the system's response to a step disturbance. In this case, we will assume a reference of zero
and look at how the system responds to the disturbance by itself. The feedback command can still be employed for
generating the closed-loop transfer function where there is still negative feedback, however, now only the plant transfer
function P(s) is in the forward path and the controller C(s) is considered to be in the feedback path.
c- Let's first try a PI controller to get rid of the steady-state error due to the disturbance. We will set = 21 and test
integral gains ranging from 100 to 500. Also, see what happened to the step disturbance response.
d- Investigate derivative gains ranging from 0.05 to 0.25. In this way, a PID controller will be designed.
where,
We want to design a feedback controller so that when the road disturbance (W) is simulated by a unit step input, the
output (X1-X2) has a settling time less than 5 seconds and an overshoot less than 5%. For example, when the bus
runs onto a 10-cm step, the bus body will oscillate within a range of +/- 5 mm and will stop oscillating within 5 seconds.
a- Represent the system in MATLAB.
b- Let's assume that we will need all three of these gains in our controller. To begin, we might start with guessing a
gain for each: =208025, =832100 and =624075. Now let's simulate the response of the system (the distance
X1-X2) to a step disturbance on the road. Play around with all three of the parameters, , , and , as we
suggested, to achieve the desired response.
More specifically, the controller will attempt to maintain the pendulum vertically upward when the cart is subjected to a
1-Nsec impulse. Under these conditions, the design criteria are:
The structure of the controller for this problem is a little different than the standard control problems you may be used
to. Since we are attempting to control the pendulum's position, which should return to the vertical after the initial
disturbance, the reference signal we are tracking should be zero. This type of situation is often referred to as a Regulator
problem. The external force applied to the cart can be considered as an impulsive disturbance. The schematic for this
problem is depicted below.
You may find it easier to analyze and design for this system if we first rearrange the schematic as follows.
The resulting transfer function for the closed-loop system from an input of force to an output of pendulum angle is
then determined to be the following.
a- Create the plant model using M = 0.5, m = 0.2, b = 0.1, I = 0.006, g = 9.8 and l = 0.3.
b- Define the controller using the pid object within MATLAB and then use the feedback command to generate the
closed-loop transfer function. Take Kp = 1, Ki = 1 and Kd = 1.
c- Examine the response of the closed-loop system to an impulse disturbance for this initial set of control gains. Is the
response stable?
d- Let's begin to modify the response by increasing the proportional gain. Increase the variable to see what effect
it has on the response. Identify the rise time, overshoot, settling time and steady state error. important characteristics
of the response. Tune the parameters to provide a satisfactory response. Justify in a step by step approach.
e- At the beginning of this page, a block diagram for the inverted pendulum system was given. The diagram was not
entirely complete. The block representing the response of the cart's position was not included because that variable
is 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 full system block diagram as shown in the
following figure.
In the above, the block is the controller designed for maintaining the pendulum vertical. The closed-loop transfer
function from an input force applied to the cart to an output of cart position is, therefore, given by the following.
where,
Generate the response of the cart's position to the same impulsive disturbance as considered above. What do you
see? Comment on the feasibility of the design if it is to be implemented on an actual physical system.
where the input is elevator deflection angle and the output is the aircraft pitch angle .
For a step reference of 0.2 radians, the design criteria are the following.
Since our reference is a step function of 0.2 radians, we can set the precompensator block equal to 0.2 to scale
a unit step input to our system. This can be accomplished from the Compensator Editor window, which can be opened
by right-clicking on the plot and then selecting Edit Compensator. Specifically, choose F from the drop-down menu in
the Compensator portion of the window and set the compensator equal to 0.2 as shown in the figure below.
To begin with, let's see how the system performs with a proportional controller set equal to 2. The
compensator can be defined in the same manner as the precompensator, just choose C from the drop-down
menu in the Compensator portion of the window instead of F. Then set the compensator equal to 2. To see the
performance of our system with this controller, move to the IOTransfer_r2y:step tab. If you have accidentally closed
this tab, you can re-open it from the Control System Designer window by clicking on the New Plot menu and
selecting New Step. In response, a new window titled New Step to plot will appear. From the Select Responses to
Plot menu, then choose IOTransfer_r2y and click the button Plot as shown below.
A window will then open with the following step response displayed.
Examination of the above shows that aside from steady-state error, the given design requirements have not been met.
The gain chosen for can be adjusted in an attempt to modify the resulting performance through the Compensator
Editor window. Instead, we will use the Control System Designer to automatically tune our proportional compensator.
In order to use this feature, go to the Tuning Methods menu of the MATLAB toolstrip and choose PID Tuning under
the Automated Tuning menu. Then select a Controller type of P and Select Loop to Tune as LoopTransfer_C as
shown in the figure below (our architecture has only one loop).
There are two options that can be chosen from the Tuning method drop-down menu, Robust response
time or Classical design formulas. The Robust response time algorithm automatically tunes the PID
parameters to balance speed of response and robustness. It can tune all parameters for any type of PID controller. It
can be used for design of plants that are stable, unstable, or integrating. However, the Classical design
formulas algorithm requires a stable or integrating plant and cannot tune the derivative filter. If you select Classical
design formulas algorithm, then in the Formula drop-down menu a range of options can be seen. These options
range from heuristic techniques, like Ziegler-Nichols, to numerical approaches that search over all possible control
gains to minimize some identified performance index. For our example, choose the Robust response
time algorithm. Then in the Design mode drop-down menu, you can choose Time or Frequency. Since our design
requirements are expressed in the time-domain, we select the Design mode as Time. Since, our rise time is expected
to be less than 2 seconds, try specifying a Response Time of 1.5 seconds. Once all of the tuning settings have been
chosen, then click the Update Compensator button. The algorithm then chooses a proportional gain of = 1.1269.
This controller meets the rise time requirement, but the settle time is much too large. You can attempt requiring a faster
response time (move the slider to the right), however, this will result in an increase in overshoot and oscillation. The
proportional controller does not provide us a sufficient degree of freedom in our tuning, we need to add integral and/or
derivative terms to our controller in order to meet the given requirements.
Integral control is often helpful in reducing steady-state error. In our case, the steady-state error requirement is already
met. For purposes of illustration, let's design a PI controller anyway. We will again use automated tuning to choose our
controller gains as we did above, only now we will select a Controller type of PI. Everything else will be left
unchanged. Clicking on the Compensator Update button then produces the following controller.
This transfer function is a PI compensator with = 0.0263 and = 1.13. The resulting closed-loop step response
is shown below.
From inspection of the above, notice that the addition of integral control helped reduce the average error in the signal
more quickly (the error changes sign around 20 seconds), but it didn't help reduce the oscillation. Let's try also adding
a derivative term to our controller.
Increasing the derivative gain in a PID controller can often help reduce overshoot. Therefore, by adding derivative
control we may be able to reduce the oscillation in the response a sufficient amount that we can then increase the other
gains to reduce the settling time. Let's test our hypothesis by changing the Controller type to PID and again click
the Update Compensator button. The generated controller is shown below.
This transfer function is a PID compensator with = 0.5241, = 1.0482, and = 0.5241. The resulting closed-
loop step response is shown below.
This response meets all of the requirements except for the settle time which at 19.7 seconds is larger than the given
requirement of 10 seconds. Reducing the Response Time requirement (moving the slider to the right) will make the
response faster, while moving the Transient Behavior slider towards Robust will help reduce the oscillation. The
resulting PID controller for the shown settings is given below.
Here we can see that moving both sliders to the right made the response faster and reduced the oscillation. However,
the settling time is still greater than the required 10 seconds. We again try increasing the required speed of response;
we have some room to spare on overshoot. The resulting PID controller for the settings shown below is the following.
This response meets all of the given requirements as summarized below.
First, we will study the response of the system shown above when a proportional controller is used. Then, derivative
and/or integral control will be added if necessary.
a- Model the closed-loop transfer function for proportional control with a proportional gain ( ) equal to 100 for a
step input of 0.25 m. Comment on the response.
b- Now, we will add a derivative term to the controller. Comment on the response. Tune PD parameters to meet all the
control objectives without the use of an integral controller.