You are on page 1of 12

Design and Simulation of Model Based System Using Real Time 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 simulation. 1 Magnetic levitation, PID controller, actuator, sensor, real time MATLAB

Introduction

Magnetic levitation, maglev, or magnetic suspension is a method by which an object is suspended with no support other than magnetic fields. The electromagnetic force is used to counteract the effects of the gravitational force. Magnetic levitation may be defined as the process of suspending a body in free space by counteracting the force of gravity acting on it. In simpler words it may be termed as the stable suspension of an object against gravity. A RealTime System responds in a (timely) predictable way to unpredictable external stimuli arrivals. In short, a Real-Time System has to fulfil under extreme load conditions: [1] 2 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. Objective of the Research

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 subobjectives need to be accomplished. o o o Design and fabrication of a sensor to sense the balls vertical displacement (height). Design and implementation of a PID controller. Design and fabrication of an electromagnet that provides sufficient magnetic attraction to suspend the metallic ball.

o o o 3

Designing and fabricating the actuator (a voltage controlled current source) to regulate current flowing into the electromagnets coil. Simulation of the controller in MATLAB using Simulink. Exploring MATLABs Magnetic Levitation Mode Basic Approach

Magnetic Levitation model may be considered as a closed loop feedback control system, whose basic block diagram is illustrated in Fig 1.

Fig 1. Block diagram of Magnetic Ball Levitation Control System

The plants output output is the balls 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 controllers 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 electromagnets coil.The plants 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.

Fig 2. Diagram illustrating photovoltaic sensors operation

C.

Current to voltage convertor

The current to voltage converter is an operational amplifier based circuit that converts the photovoltaic cells 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 signals 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.

fig3. System. Hardware schematic of Magnetic Ball Levitation

Mathematical Model of Magnetic 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 balls vertical displacement is governed by the following electro-mechanical equation: where: m is the balls 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.

fig4.Mathematical model of the Magnetic Levitation System

PID Controller

5.1.Introduction of PID Controller A proportional-integral-derivative controller (PID controller) is a generic control loop feedback mechanism widely used in industrial control systems. It attempts to correct the error between a measured process variable and a desired set point by calculating and then implementing a corrective action. The PID controller involves three separate parameters; the Proportional, the Integral and Derivative values. The Proportional term produces a response that is proportional to the error signal, the Integral term examines the set points offset over time and corrects it when and if necessary, while the Derivative term produces an output that is proportional to the rate of change of error. The sum of these three actions is collectively termed as PID control.by "tuning" the proportional, Integral and Derivative gains, the PID controller can be made to provide control action in accordance with specific process requirements. The controllers behavior can be described in terms of its responsiveness to the error signal, the degree to which the output overshoots the set point and the degree of system oscillation. 5.2.Objective of PID Controller in our research The controllers basic function is to respond to any variations in the balls vertical displacement from the electromagnet by taking necessary corrective actions.

Fig5. A typical PID control 5.3Designing 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 controllers behaviour is as follows:

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 controllers 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

fig6: Proportional amplifier

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.

Fig 7: IntegratorThe integral term is given by: Vout = 1/RinC * integral(Vin)

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

Fig 8: Differentiator circuit

5.7

Analog implementation of the PID

Fig9. PID controllers analog implementation. We implemented the controller using LM358A ICs 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. 5.8Tunning the Controller Individual gains of P, I & D were adjusted using potentiometers to ensure optimum performance of the controller. The proportional gain was precisely adjusted to achieve minimum rise time. However, increasing Kp made the transient response worse by introducing large overshoots. Ki was varied to reduce the steady-state errors and finally Kd was adjusted to improve unwanted overshoots and to decrease the systems settling time. Param Rise eter time Kp Ki Kd Over shoot Settling time S.S error

decrease increase Small change decrea se Decrease Increase increase elimina te Small decrease decrease Small change change

Table 1. Effect of increasing proportional, integral and derivative gains Improving the systems transient stability.

Fig10.Proportional gain Kp on step response of controller.

Fig11. Effect of variation of Ki on the step response of controller

MATLAB Magnetic Levitation Model

In order to appreciate magnetic levitation and to get a thorough insight into the fundamentals of feedback control, it is worth exploring matlabs Magnetic Levitation Model. This model may be accessed by typing vrmaglev on matlabs command window, as is shown below. It may also be accessed from matlabs virtual reality toolbox.[3] The Magnetic Levitation Model is meant to demonstrate control problems associated with nonlinear and unstable systems. It comprises of a position sensor connected to an A/D converter, to sense the steel balls 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]

Fig13. Matlabs Magnetic Levitation Model.

Fig 14. Block Diagram of the Levitation model.

There is provision to vary the signals frequency and amplitude as well.

Fig15. Obtained by double clicking the signal generator blockset.

By double clicking on the scope one can observe how the plants output tracks the chosen signal. The images that follow will further clarify this point.

Fig16. The plants output trying to track a sinusoidal wave.

Fig 17. The plants output trying to track a square wave.

Fig 18 The plants output trying to track a sawtooth wave.

By double clicking on the PID block, one can change the controllers parameters. include, KP (proportional gain), KD (derivative gain) and KI (Integral gain). 7 Simulation of the Controller using Simulink

These

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]

Fig 19: Simulink model of PID controller

7.1

Simulation Results

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.

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.

Fig 21 output of the controller

Real time window targets technique

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. 9 Code Generation Optimizations

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

Result and Conclusion: 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 [3] Development of a real-time digital control system with a hardware-in-the-loop magnetic levitation device for reinforcement of control education Shiakolas,P.S.;Piyabongkarn, D.Education ,IEEE Transactioson Volume 46, Issue 1, Feb 2003Page(s):79-87Digital Object Identifier 10.1109/TE.2002.808268 [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 lubna@pnec.edu.pk , V_uddin@pnec.edu.pk

12

You might also like