Professional Documents
Culture Documents
SYSTEM
CONTROL
PID
ROOT LOCUS
FREQUENCY
STATE-SPACE
DIGITAL
SIMULINK
MODELING
CONTROL
Contents
Equipment needed
Purpose
ON/OFF Control
P and PI Control
Embedded Control
Equipment needed
The temperature of the light bulb is measured in this example with a TMP36
provides power to the sensor and reads the sensor output via an Analog
Input. The Arduino board is also used for generating the Digital Output that
switches the solid-state relay on and off. That is, the digital output alternately
connects and disconnects the light bulb from the AC power source (from the
wall) via the relay in order to turn the light bulb on and off. The control logic
implemented within Simulink, which is also employed for visualizing the light
Purpose
The purpose of this activity with the light bulb is to demonstrate how to
turning the light bulb on and the light bulb's temperature is decreased by
turning the light bulb off (up to environmental limits). The light bulb is a
binary system with only two states, on or off. The light bulb is either
this chatter, or smoothing the chatter, through the use of deadbands, low-
first-order systems.
need a model of our plant (the light bulb). We can simply employ logic that
turns the light bulb on when the measured temperature is lower than desired
and turns the light bulb off when the temperature is higher than desired. We,
however, would like to be able to explain the resulting behavior of our control
system (and perhaps even attempt to design the control algorithm in a more
behavior of the light bulb based on its observed response. This is sometimes
Hardware setup
limits of the temperature sensor we have chosen. You can also employ other
For our temperature sensor, we will employ the TMP36 (though many others
many Arduino starter kits that are in the market place. The datasheet for this
sensor can be found here. The temperature sensor can be attached to the
shown below. Specifically, if the sensor is oriented such that the pins are
pointed downward and the flat side of the sensor is facing you, then the
leftmost pin is the power (must be between 2.7 V and 5.5 V), the middle pin
is the signal, and the rightmost pin is ground. Power and ground for the
TMP36 are supplied from the Arduino board and the signal, which is a
The light bulb is turned on and off employing a digital output from the
comes from a standard wall outlet and the DC signal is supplied by a Digital
Output from our Arduino board. Therefore, our solid-state relay needs to be
able to handle 120-240 V on the AC side (in North America need 120 V) and
the DC side must be able to be controlled with a 5 V signal. Since our load
(the light bulb) is resistive (not inductive) and doesn't require much current,
we don't have to be very particular about the solid-state relay we employ.
control the light bulb, we need to insert the relay into the circuit (the loop)
that connects the light bulb to the wall. Therefore, we must cut into the cord
for the light bulb and wire the relay into the circuit. In doing this, make sure
that the bulb is not plugged in. You should insert the relay on the neutral wire
of the bulb's plug. The neutral wire is indicated by a white stripe or ribbing. If
you insert the relay on the live wire, then the terminals of the relay are
connected to the power supply even when the relay is off. You should also
cover the exposed terminals of the relay and never touch the terminals when
Software setup
the data from the temperature sensor, and to plot the data in real time. In
particular, we will employ the IO package from the MathWorks. For details
on how to use the IO package, refer to the following link. Later on, we
demonstrate how to embed the control logic on-board the Arduino board.
The Simulink model we will use is shown below and can be downloaded
here, where you may need to change the COM port in the IO Setup block to
match location where your Arduino board is connected. This model reads
the temperature data via an Analog Read on channel A0. This data is then
to-digital converter. This means (for the default) an Analog Input channel
1.75 V, you can get better resolution by employing the on-board 3.3 V
source for AREF instead of using the default 5 V. The data in bits is then
on information given in the datasheet for the TMP36. The model then
displays the stored data on a scope and a display and is written to the
This model commands the relay to be open (1) or closed (0) (corresponding
to the light bulb on and off, respectively) via a Digital Write on channel 9. For
starters, we will employ a step input such that the light bulb is initially off and
is turned on once. The Arduino Analog Read block, Digital Write block, IO
Setup block, and Real-Time Pacer block are all part of the IO package. The
seconds. If you try to sample too quickly, the Simulink model will run slower
than real-time, that is, it won't be able to sample at the rate specified. Since
the thermal dynamics of the light bulb are relatively slow, a sample time of
0.1 is more than sufficient. We will set the sample time within the Digital
Once the Simulink model has been created, it can then be run to collect a
set of data like that shown below. Specifically, the light bulb is initially at
light bulb is turned on (via the step input) and it is allowed to heat up. We
wait 50 seconds before turning the light bulb on in order to gather sufficient
data for estimating the ambient temperature (initial light bulb temperature).
Make sure to run the model for a sufficient amount of the time for the light
Inspection of the above response data indicates that the thermal dynamics
of the light bulb appear to be approximately first order. We will employ this
Modeling
In this experiment, we will derive a model for the thermal dynamics of the
light bulb solely based on the step response data we recorded. That is, we
will fit a model to the data without any consideration of the underlying
physics of the system. Examination of the recorded data indicates that the
thermal dynamics of the light bulb are approximately first order. Therefore,
we will fit a transfer function to the data of the form shown below, where
(1)
For our particular light bulb system, we will consider the input to be the
percent of time the light bulb is on (i.e. duty cycle), , and we will
consider the output to be the deviation of the light bulb's temperature from
linear system, the output must be linearly proportional to the input. This
estimating the parameters and because of the noise on the signal and
because of the drift in the data. The effect of the noise could be minimized
our heads by just "eye-balling" an average curve fitted to the data. The drift
the voltage, errors in the sensor, etc. We again will try to average over this
From inspection of the given step response data, the ambient temperature
degrees C. Since the input is equal to 1 (100 percent duty cycle), and the
83.5 degrees C (102 - 18.5). Recalling the definition of time constant as the
time it takes for the system response to achieve 63% of its total change, the
below for an annotated version of the step response plot where 0.63(83.5
approximately 116 seconds. Since the step input didn't occur until 50
50).
Based on the above identification of parameters, the estimated model of the
(2)
In order to get a better sense of how well our derived model fits our data, we
will apply the following MATLAB commands, where the output of our
s = tf('s');
K = 83.5; % DC gain
plot(t+50,y+To);
hold
plot(temp,'r:')
xlabel('time (sec)')
legend('model','experiment','Location','SouthEast')
Examination of the above demonstrates that our assumption of a first-order
we consider the underlying physics of the light bulb. Considering the heat
capacitance" of the light bulb, while the net rate of heat transfer depends on
the thermal conductivity of the light bulb (like the inverse of "thermal
resistance") and the difference between the bulb's temperature and the
input (will be almost a perfect step because the electrical dynamics are so
(3)
following.
(4)
Inspection of the above shows that the thermal dynamics of the light bulb
ON/OFF Control
Now that we have some intuition about the behavior of our plant and a
model, we can attempt some strategies for its control. Specifically, we will
attempt to control the temperature of the light bulb. The first approach to
control that we will attempt is a simple ON/OFF controller that turns the light
temperature (error > 0) and turns the light bulb off when the measured
temperature is greater than the desired temperature (error < 0). Below
shows our modified Simulink model with the logic of our ON/OFF controller
The control scheme shown above does not use any knowledge of the plant
model and employs feedback. The feedback loop is a little difficult to picture
because the plant is in the physical world. The figure below helps to illustrate
how the entire feedback system (the Simulink model and the physical world)
fits together.
It is instructive to take a minute and think about how you would implement
an open-loop controller for this system (no measurement of the light bulb's
The resulting temperature of our light bulb with the closed-loop ON/OFF
controller is shown below. The behavior is pretty intuitive. Initially the light
bulb is too cold causing the controller to turn the bulb on. This causes the
with the light bulb fully on. At this point, the light bulb then is turned off
because its temperature has risen above the desired level. As the bulb loses
degrees, at which point the light bulb is turned back on. This ON/OFF control
strategy then results in the light bulb flickering, being rapidly turned on and
off, and the resulting temperature chatters around the desired temperature.
temperature signal.
This resulting control is quite effective in that it keeps the light bulb's
temperature close to the desired level and was designed and implemented
that it may shorten the life of the light bulb and it may not be very energy
One approach for reducing the chatter is to add a low-pass filter on the
first-order filter with a time constant equal to 2 seconds. The filter acts on the
signal to account for the fact that a transfer function assumes zero initial
The resulting controlled behavior is shown below. Here we can see the
effect of the low pass filter to smooth the measured temperature signal. One
where a larger time constant increases the rounding (decreases the speed
discrete-time version of the filter transfer function. In this case, a larger time
average.
This approach to filtering could have been employed when we generated our
blackbox model of the plant. One drawback of using a low-pass filter in real
Aside from smoothing the noise in the temperature measurement signal, the
filter also reduced the frequency with which the light bulb was turned on and
off, thereby possibly improving the life and efficiency of the light bulb. The
drawback is that the controlled temperature does not stay as close to the
changing the time constant of the filter. The reason why the filter affects the
light bulb in this manner can be understood by considering the low-pass filter
rises above the desired level the light bulb turns off and as soon as the
temperature falls below the desired level the light bulb turns on. With a
moving average, the light bulb will not turn off when the temperature reaches
the threshold because the average has not yet crossed the threshold. The
to wait for several of the most recent measurements to cross the threshold in
With Deadband
which the light bulb turns on and off is to use a deadband. This is achieved
in the model shown below with a Relay block. The Relay block behaves like
a switch with hysteresis, that is, it has a different condition for switching
"ON" than it does for switching "OFF." In this case, the deadband is set to
+2/-2 degrees. In other words, the light bulb is turned off when the measured
temperature rises 2 degrees above desired (77 degrees in this case), and it
turns on when the temperature falls 2 degrees below desired (73 degrees in
this case). The model shown below with deadband can be downloaded here.
behavior is similar to that achieved with filtering. The frequency with which
the light bulb is turned on and off (and the resulting proximity to the desired
where the light bulb was fully on when the error was positive and fully off
would modulate the light bulb in proportion to how much temperature error
there was (and later, in proportion to the integral of the error as well). In
other words, if the light bulb was much too cool (large error), it would be
turned on brightly, but if the light bulb was only a little cool (small error), it
would only be turned on dimly. This approach, where the control effort is
ON/OFF strategies employed so far, but the dynamics of this system are
slow enough, and understandable enough, that this exercise will help us to
P Control
cannot modulate the intensity of the light bulb, it is either connected to the
Pulse-Width Modulation the input signal is a pulse train (a square wave) with
fully off, as we have here). The "intensity" of the control is then affected by
changing the percent of time that the input is "on." This percentage is called
the light bulb's temperature might look like if the period of the PWM signal
was very long. You would have a first-order step response rising to some
ambient (when off). In practice, however, the period of the PWM signal is
made small (frequency large) compared to the dynamics of the system being
controlled so that there isn't much time for the output to rise or fall.
The model given below implements a P Control strategy for our light bulb
system. The PWM signal is implemented by the Analog Write block shown.
Therefore, the input to the Analog Write block must be between 0 and 255,
cycle. The saturation block is included to capture these limits. The PWM
signal is output on the Digital Pin 9 that we have been utilizing. Those digital
pins that can generate a PWM output are indicated by the ~ symbol on the
temperature profile with this gain is shown below. The resulting profile has a
of our control system is shown below. Note that the feedback loop is written
in terms of , rather than , in order that our plant be linear with zero
initial conditions.
For this system with and the defined earlier, we have the
(5)
Examining the above, we can see that the closed-loop system has a DC
have changed, such differences don't explain the magnitude of the error
observed. The difference between the prediction and the observation is that
our model was derived for a step input of 1, that is, for a duty cycle.
Looking at the control input generated for shown below, we can see
that the light bulb operates at a duty cycle that is significantly less than
Inspection of the expression for the DC gain that we derived earlier shows
cycle, bringing it closer to the conditions for which our plant model was
will still result in a first-order type response, but it will reach steady-state
accurate and predictable model in order to set the scaling factor correctly. A
this next.
PI Control
Adding a term to our controller that is proportional to the integral of the error
(6)
indeed have zero steady-state error for a constant reference. The larger the
value of , the more quickly the steady-state error will be driven to zero.
energy to the bulb at a rate that was exactly in balance with the rate at which
heat was being lost to the environment. The control input remained constant
because the temperature error had settled at a steady value and the control
effort was proportional to the error. With integral control however, the control
effort will continue to increase until it drives the steady-state error to zero.
Since integration is a sum, it adds up the area under the error vs. time
graph. Therefore, the integral term of the controller will have the effect of
increasing the control effort as it accumulates this error (as it adds up the
area). A side-effect of the addition of the integral control is that it made our
closed-loop system second-order, such that the response may now oscillate
(overshoot). This effect is also somewhat intuitive. Let's run our system with
proportional term of the controller and the integral term of the controller (as
shown in the displays). Below is given the resulting temperature profile and
control effort for this model. Initially the error is large and it gets smaller as
the light bulb heats up. Therefore, the proportional term of the control effort
is initially large and then it decreases as the error gets smaller. The integral
portion of the control effort continues to grow even as the magnitude of the
area under the error "curve." When the light bulb's temperature reaches the
desired level, the error is zero and the proportional control effort is also zero.
The integral control effort, however, is still quite large because it has
accumulated all of the positive error since the control system was started.
This is referred to as the integrator "winding up." Therefore, the light bulb
continues to heat up for a while and overshoots its desired temperature due
to the integrator. At this point, the error is now negative and the proportional
control effort is negative. And while the integral control effort is still positive,
system is now second order, that is, why it can now have complex poles and
oscillate.
This example also illustrates a common tradeoff with adding integral control.
Its addition can help to decrease the steady-state error, but may make the
response more oscillatory and slower to settle. Modifying the control gain
will alter the balance of these two effects. Returning to our closed-loop
constant. This illustrates how increasing can help to drive the error
smaller more quickly (decreases rise time due to the larger ), but at the
Embedded Control
So far in this experiment, the logic for controlling the light bulb's temperature
communicating between the board and the host computer running Simulink.
communicate with the board in real time with ease. Therefore, we can
observe and graph the measured light bulb temperature (and control effort)
approach has two advantages. One, since the control software does not
have to run under an operating system (i.e. Windows, etc.) that has to
address many other (higher priority) tasks, the control program can run
faster and achieve faster sampling rates. The other advantage is that
device to keep your coffee warm, you could do so without needing your
device to be plugged into a host computer. Note that if you want to unplug
the Arduino board from the host computer, you will then need to provide an
alternative power source for the board. For example, the Arduino board can
be powered by a 9-V battery plugged into its power jack (7-12 Volts is
recommended). In this activity we so far have been powering the board from
In order to embed our control logic on board the Arduino, we will use the
Arduino Support Package from the MathWorks. More details can be found
here. The blockset of this support package is almost identical to those used
previously from the IO package. Specifically, the control command (light bulb
on/off) is achieved from a Digital Output block and the temperature is read
via an Analog Input block. The Arduino IO Setup block and the Real-Time
Pacer block are no longer necessary, though the model needs to be set to
automatically detect the COM port, or must be manually set to the correct
COM port. This can be done through the drop-down menu of the model
toolbar Tools > Run on Target Hardware > Options.... Also the Scope and
and can be downloaded here. This control software can be deployed to the
Arduino board by clicking on the icon in the upper righthand corner identified
by the red circle below, or by typing Ctrl+B. This automatically builds and
compiles the Simulink model into code that runs in real time on board the
industrial practice.
Published with MATLAB® 8.2
International License.