Professional Documents
Culture Documents
2. Effects of fixed and unfixed (also probably unknown) sampling rate on the control system
performance.
By using a simple system, we will demonstrate the effects of use of an real-time system and
a nonreal-time system on the controller performance.
*IEEE POSE Standard (Portable Operation System Interface for Computer Environments)
** Real-time Control Systems: A Tutorial, A. Gambier
3
System to be
controlled
State measurement
sensors for feedback
Drive system
Data acquisition
system
Sensors measure the system states for feedback and produce a low amplitude electrical signal
(voltage or current). A data acquisition system (generally a data acquisition card, or input
ports of a microcontroller) receives this signal, converts it to a digital signal, and then sends to
PC-based system that runs the control algorithm designed. Information produced by the
control algorithm is sent by PC-based system (a host PC, or microprocessor unit of a
microcontroller) to data acquisition system again. Data acquisition system converts this signal
to an analog signal, and then sends it to drive system via its output ports. Main function of
the drive system is to produce drive signals proper for the plant, that is, the system to be
4
controlled. The drive system may be linear amplifier, or a power electronic system.
PMDC Motor
Linear amplifier
Quanser Q4 DAC
Remember that we have three state variables; current, velocity, and position. For a full-state
feedback, we will use a hall-effect current sensor and an encoder. The incremental encoder
can be used for both velocity and position feedback. Quanser Q4 card receives sensor
outputs, converts the analog current information to a digital one, and then sends measured
values to target PC. The target PC downloads the control algorithm from the Simulink file in
host PC, runs this code, produce the control input signal (voltage) information, and finally
sends this information back to the host PC. The host PC transmits this signal to the Quanser
card. The low-amplitude voltage at the output of the card is amplified by a linear amplifier.
This actual control input signal is then supplied to the motor.
5
Emphasis will not be upon the theory of real-time systems in this class. Instead, we will
introduce the hardware and software that we will use during the experiments. But, even so,
some important points explained below should be considered.
SYSTEMS
Real-time System
Degraded operation in a
rarely occurring peak load Soft
can be tolerated.
Timing parameters and the
priority for tasks is modified Dynamic
at run-time.
Static
System timing
parameters are known
before execution.
http://www.ece.cmu.edu/~koopman/des_s99/real_time/
6
Hard
Real-time
System
D/A
Error in output
waveform
Soft
Real-time
System
D/A
Error in execution
time
7
MATLAB/SIMULINK have a toolbox called xPC Target. This toolbox enables you to real-time
control prototyping and testing. It provides a library of drivers, a real-time kernel, and a hosttarget interface for real-time monitoring, parameter tuning, and data logging. You create a
real-time testing environment for Simulink models by connecting a host computer (a laptop),
a target computer (a desktop), and your hardware under test (PMDC motor). You connect
the host computer running xPC Target, Simulink, and a C compiler to the target computer via
a single TCP/IP communications link (an ethernet cable). You then connect the target
computer to your hardware under test and download code generated by Simulink Coder
from a Simulink model to the target computer via the communication links.
You create an xPC Target application using xPC Target with Simulink Coder to automatically
generate and compile a C/C++ code representation of a Simulink model. You then
download the target application via a LAN (Ethernet) connection from the host computer
to the target computer.
xPC Target enables you to access the target application and control it directly from the
host computer using either the xPC Target Explorer tool or the MATLAB command line. You
can download your target application, start and stop real-time test execution, change the
sample time and stop time, and modify other target application properties.
To monitor and acquire data, xPC Target includes scopes for both the host and target
computers. Scopes support several trigger modes you can use to control the acquisition,
timing, and duration of data collection. You can also display multiple signals in a single
scope and attach multiple scopes to a single model.
Signal monitoring enables you to view signal values at the current sample rate. Signal
tracing lets you capture, store, and display bursts of data, similar to the behavior of a
digital oscilloscope. Signal logging lets you acquire and store signals during the entire test
execution. You can then upload the logged data to the host computer for signal display,
analysis, or archiving.
9
Host Computer
Target Computer
Design a Simulink
model on the host PC
Host
MATLAB with
Simulink
C++
Target PC
xPC OS from Mathworks
+
Q4 HIL Board
System
Input
Output
Feedback
11
Quanser Q4 card in the Target PC provides data acquisition for feedback. Output ports of
the card is used to send the control signal calculated by the control algorithm implemented
in Simulink to the linear amplifier.
Q4 Terminal Board
From Q4 board
Analog In (A/D)
Channels
Channels
Channels
13
Finally, a linear amplifier is used to produce actual control signals to be applied the system.
14
The Q4 cards being used for data acquisition and control are very useful and very
expensive. Read the manuals for voltage limitations and proper use.
Download a supplementary document that explains in detail xPC Target setup, laptop
configuration, Q4 card, linear amplifier calibration and some additional important issues
from http://www.duzce.edu.tr/~ugurhasirci/ece893/sup/sup2.pdf .
15
The software and hardware introduced so far are not the only option to design and
implement real time control systems. These are the things available in our labs.
Of course there are some other software/hardware combinations to achieve a good real
time performance. For example dSPACE provides a very useful hardware (dSPACE data
acquisition card) and software (Real Time Interface - RTI) to implement the control
algorithms embedded in MATLAB/Simulink environment.
16
x x u
where x is the state variable and u is the control input. The control objective is to drive x to
a desired trajectory, xd. To observe the performance of the controller to be designed, an
error signal can be defined as follows:
e xd x
First consider the following simulation. This blocks simulates the system with a fixed and
known sampling rate. The desired trajectory is just a constant, 1, and the values of the
control gains are Kp=8, Kd=3, and KI=0.01.
1
Constant
PID(s)
fcn
PID Controller
MATLAB Function
1
s
Integrator
Scope
18
e(t)
0.08
0.06
0.04
0.02
0
0
20
40
60
80
100
Time
After a very short transient, the error settles to a small constant and the system is stable.
19
Now we will use the same system, same control rule, and the same values of the control
gains, but, for this time, we will also use some additional blocks to make the system a nonreal time system.
1
Constant
k1
To
PID(s)
Variable
PID Controller
Time Delay
y1
fcn
MATLAB Function
1
s
Integrator
Scope
Uniform Random
Number
Newly-added Variable Time Delay block holds the last 10 samples of the error signal and
Uniform Random Number block generates an integer ranging from 1 to 10 at each time
step. In this way, the derivative and integrator embedded in PID Controller block use the
existing value of the error signal and any random one of the last 10 sampled values of the
error signal to calculate the derivative and integral of e(t). This means that this system is not
a real time system anymore. Indeed, such a system can be used to simulate a non-real time
system.
20
Time-variation of tracking error signal for this non-real time system is shown in the
following figure.
12
15
x 10
e(t)
10
-5
0
20
40
60
80
100
Time