Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows - 316
Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows - 316
Windows
Engr.Lubna Moin Dr.Vali Uddin
Abstract:This paper investigates the issue of real time simulations using MATLAB as a
tool. Real-time systems are loosely defined as the class of computer systems that interact
in a time frame defined by the external world. It is an environment where a single computer
is a host and a target. After creating a model and simulating it with simulink in normal
mode we can generate executable codes with real time workshop. Here we have used
MATLAB as an application tool which provide us the specialized tool boxes for specific
areas. The real time window target communicates with the executable program acting as a
control program and interfaces with the hardware device through the I/O port.
Here we tried to analyze a magnetic levitation system. The control goal is to suspend a
steel sphere by means of a magnetic field counteracting the force of gravity and to be able
to apply a controlled disturbance to force the sphere to follow a predetermined trajectory.
The control to be applied is the voltage, which is converted into a current via internal
circuitry in the controller located in the mechanical unit. The current passes through and
an electromagnet which creates a magnetic field in its vicinity. The sphere is placed along
the vertical axis of the electromagnet after the control system is started in the software. In
this way a approach towards real time workshop is analyzed and applied.
Key Words Magnetic levitation, PID controller, actuator, sensor, real time MATLAB
simulation.
1 Introduction
• timeliness: meet deadlines, it is required that the application has to finish certain tasks
within the time boundaries it has to respect.
• simultaneity or simultaneous processing: more than one event may happen
simultaneously, all deadlines should be met.
• predictability: the real-time system has to react to all possible events in a predictable way.
• dependability or trustworthiness: it is necessary that the real-time system environment
can rely on it.
The overall objective of this project is to levitate a metallic ball by producing a magnetic field
which counteracts the natural gravitational force. In order to achieve this goal, the following sub-
objectives need to be accomplished.
o Design and fabrication of a sensor to sense the ball’s vertical displacement (height).
o Design and implementation of a PID controller.
o Design and fabrication of an electromagnet that provides sufficient magnetic attraction to
suspend the metallic ball.
1
o Designing and fabricating the actuator (a voltage controlled current source) to regulate
current flowing into the electromagnet’s coil.
o Simulation of the controller in MATLAB using Simulink.
o Exploring MATLAB’s Magnetic Levitation Mode
3 Basic Approach
Magnetic Levitation model may be considered as a closed loop feedback control system, whose
basic block diagram is illustrated in Fig 1.
The plant’s output output is the ball’s vertical displacement which is sensed by an optical sensor.
Current produced by the sensor is converted to a proportional voltage, commonly referred to as
the ‘sensor voltage’, by means of a ‘current to voltage’ converter. The ‘setpoint’ voltage (a known
reference) is subtracted from the ‘sensor’ voltage to generate an error signal which is acted upon
by the ‘PID’ controller. The ‘actuator’ is simply a ‘voltage to current’ converter that produces
current proportional to the controller’s output voltage. Magnitude of this current decides the
magnetic field strength and, hence, the upward force with which the ferromagnetic ball is
attracted. The magnetic levitation system can be seen to comprise of the following fundamental
elements:
A. Plant
The electromagnet along with the suspended metallic ball may be collectively termed as the
‘plant’.Input to the ‘plant’ is the current flowing in the electromagnet’s coil.The plant’s output is the
vertical displacement of the suspended ball.
It is worth mentioning that is not possible to control the ‘plant’ while it operates in ‘open loop’. The
reason being its highly unstable nature.
B. Sensor
The sensor used in this project is a photovoltaic cell whose ‘short circuit’ current (Isc) varies
linearly with light intensity.As the metallic ball is attracted upwards by the electromagnet it
partially covers the sensor, bringing about a change in its surface area exposed to the light
source. This action is depicted by Fig 2.
2
The ‘current to voltage’ converter is an ‘operational amplifier’ based circuit that converts the
photovoltaic cell’s ‘short circuit’ current (Isc) to a proportional voltage (Vsensor).
D. PID Controller
The PID controller acts upon the ‘error’ signal generated by subtracting the ‘set point’ voltage (V
set point) from the ‘sensor’ voltage (Vsensor).
o ‘Proportional’ control ensures that the controller output is proportional to the amount of
‘error’.
o ‘Integral’ control takes into account the error signal’s time duration as well as magnitude
and completely eliminates steady state offset.
o ‘Derivative’ control ensures that the corrective action taken by the controller is proportional
to the rate of change of error. Hence, an early corrective action is initiated.
E. Actuator
The actuator is a ‘voltage to current converter that receives an input voltage from the ‘PID’
controller and converts it to a proportional current, which excites the electromagnet.The schematic
shown in Fig3. gives the reader an overview of the hardware details and fundamental components
of the levitation system.
The metal ball is under the influence of two opposing forces, namely, the downward gravitational
force and the upward pull of the electromagnet, as shown in Fig4. Perfect levitation is achieved
once these two forces exactly balance each other. The ball’s vertical displacement is governed
by the following electro-mechanical equation:
where:
• ‘m’ is the ball’s mass.
• ‘g’ denotes gravity.
• ‘X’ is the distance of the ball from the electromagnet.
• ‘I’ is the current flowing through the electromagnet.
• ‘k’ is a coefficient.
3
5 PID Controller
5.1.Introduction of PID Controller
The PID controller reads the error voltage generated by subtracting a predefined ‘set point’ from
the ‘measured’ variable. Corrective effort is initiated using this error voltage in three ways.
1. Proportional control ensures that the corrective action is proportional to the amount of error.
2. Integral control takes into account the time duration of the error and completely eliminates
steady state offset.
3. Derivative control ensures that the controller output is proportional to the rate of change of
error.
The mathematical equation describing a PID controller’s behaviour is as follows:
4
where:
Kp is the proportional gain
Ki is the integral gain
Kd is the derivative gain
u(n) is the controller output.
5.4Proportional term
The proportional term ensures that the controller’s output is proportional to the error signal. The
proportional term is given by:
Pout = Kp*e(t)
• Where Pout: Proportional output
Kp: Proportional Gain, a tuning parameter equal to -Rf/Rin
e(t): Error = Vsensor - Vsetpoint
5.5Integral term
To learn from the past, the error is integrated and multiplied by a constant Ki. Without the integral
term a PID controller cannot eliminate error if the process requires a non-null input to produce the
desired setpoint. The magnitude of the contribution of the integral term to the overall control
action is determined by the integral gain, Ki.
5
5.6Derivative term
To anticipate the future the first derivative of the error signal is calculated and multiplied by a
constant Kd.The derivative term is given
Vou=RfCin*dVin/dt
We implemented the controller using LM358A IC’s instead of the 741 opamp IC. LM358A was the
better option because it has an advantage of being a dual op amp IC which saves circuit space
and the number of ICs required.
The PID controller was implemented in cascaded form since all three terms must recieve the
error signal simultaneously, after which their responses are summed by means of a summer
circuit.
6
Table 1. Effect of increasing proportional, integral and derivative gains
Improving the system’s transient stability.
In order to appreciate magnetic levitation and to get a thorough insight into the fundamentals of
feedback control, it is worth exploring matlab’s ‘Magnetic Levitation Model’. This model may be
accessed by typing ‘vrmaglev’ on matlab’s command window, as is shown below. It may also be
accessed from matlab’s ‘virtual reality toolbox’.[3]
The ‘Magnetic Levitation Model’ is meant to demonstrate control problems associated with non-
linear and unstable systems. It comprises of a position sensor connected to an A/D converter, to
sense the steel ball’s vertical position. The coil is driven by a power amplifier interfaced with a
D/A converter. A pictorial representation of the model itself is given for further clarity.[3]
7
Fig 14. Block Diagram of the Levitation model.
By double clicking on the ‘scope’ one can observe how the plant’s output tracks the chosen
signal. The images that follow will further clarify this point.
8
Fig 17. The plant’s output trying to track a square wave.
By double clicking on the ‘PID block’, one can change the controller’s parameters. These
include, KP (proportional gain), KD (derivative gain) and KI (Integral gain).
The closed loop control system shown in Fig 1 was simulated in MATLAB and the results closely
analysed. The objective of this simulation was to get a better understanding of PID control and
the individual effects of ‘proportional’, ‘integral’ and ‘derivative’ terms.[4]
When Kp=1, Ki=10 and Kd=0.03, then the output would be like this and the ball will move
between two ends smoothly.
9
Fig 20output of the controller
When Kp value is increased to 5,Ki to 15 and Kd to 0.5 then there will be increase in transients
and the ball starts to fluctuate. So as we go on increasing the PID parameters value the
unstability increases. Therefore it is suggested to keep it between this limit.
The Real-Time Windows Target brings rapid prototyping and hardware-in-the-loop simulation.. It
is the most portable solution available today for rapid prototyping and hardware-in-the-loop
simulation This picture shows the basic components of the Real-Time Windows Target. [4]
10
Fig22. Real-Time Windows (rtwin) Target [1]
Parameter tuning is done interactively, by simply editing Simulink blocks and changing parameter
values. For viewing signals, the Real-Time Windows Target uses standard Simulink Scope
blocks, without any need to alter your Simulink block diagram. Signal data can also be logged to
a file or set of files for later analysis in MATLAB.
The Real-Time Windows Target is often called the "one-box rapid prototyping system," since both
Simulink and the generated code run on the same PC. A run-time interface enables you to run
generated code on the same processor that runs Windows The generated code executes in real
time, allowing Windows to execute when there are free CPU cycles. The Real-Time Windows
Target supports over 100 I/O boards, including ISA, PCI, CompactPCI, and PCMCIA. Sample
rates in excess of 10 to 20 kHz can be achieved on Pentium PCs.
The Simulink code generator included with Real-Time Workshop is packed with optimizations to
help create fast and minimal size code. The optimizations are classified either as cross-block
optimizations, or block specific optimizations. Cross-block optimizations apply to groups of blocks
or the general structure of a model. Block specific optimizations are handled locally by the object
generating code for a given block. Listing each block specific optimization here is not practical;
suffice it to say that the Target Language Compiler technology generates very tight and fast code
for each block in our model.[4]
11
Fig 23Magnetic Levitation Detailed Non linear model
The control goal of suspending a steel sphere by means of a magnetic field counteracting the
force of gravity, and to be able to apply a controlled disturbance to force the sphere to follow a
predetermined trajectory is achieved using Real time Matlab Simulink tool. In operation the
control output from the I/O board in the PC is a voltage, but the magnetic levitation unit contains
inbuilt voltage to current converter circuitry. The electromagnetic is therefore driven with a current
output source and the system avoids the problems associated with the high impedance of the
electromagnet coil and the consequent large phase difference between voltage and current.
RTWT combines the powerful functionality of MATLAB, Simulink and Real-Time Workshop and
allows users to implement any kind of control algorithm.It also suggest the value of the PID
design for proper operation.
References:
[1] On the development of a real-time digital control system using x PC-Target and a
magnetic levitation device Shiakolas,P.S.;Piyabongkarn,D.Decision and Control, 2001.
Proceedings of the 40th IEEE Conference on Volume 2, Issue , 2001 Page(s):1348 - 1353 vol.2
Digital Object Identifier10.1109/.2001.981077.
[2] Real-time adaptive control using neural generalized predictive control Haley, P.;Soloway,
D.;Gold, B. American Control Conference, 1999. Proceedings of the 1999Volume 6, Issue , 1999
Page(s):4278 - 4282 vol.6 Digital Object Identifier 10.1109/ACC.1999.786371
[4] Real Time Windows Targrt for modelling, Simulation and Implementation.User Guide
version 2. by MathWorks,Inc.
Engr.Lubna Moin, Dr. Vali Uddin
Pakistan Navy Engineering College
University of Science and Technology
Electronics and Electrical Department
PNSJauharHabibRehmatullahRoad,
Karachi, Pakistan
[email protected] , [email protected]
12