Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows_316

Embed Size (px)

Citation preview

  • 8/7/2019 Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows_316

    1/12

    1

    Design and Simulation of Model Based System Using Real TimeWindows

    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 interactin a time frame defined by the external world. It is an environment where a single computeris a host and a target. After creating a model and simulating it with simulink in normalmode we can generate executable codes with real time workshop. Here we have usedMATLAB as an application tool which provide us the specialized tool boxes for specificareas. The real time window target communicates with the executable program acting as acontrol 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 asteel sphere by means of a magnetic field counteracting the force of gravity and to be ableto 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 internalcircuitry in the controller located in the mechanical unit. The current passes through andan electromagnet which creates a magnetic field in its vicinity. The sphere is placed alongthe vertical axis of the electromagnet after the control system is started in the software. Inthis way a approach towards real time workshop is analyzed and applied.

    Key Words Magnetic levitation, PID controller, actuator, sensor, real time MATLABsimulation.

    1 Introduction

    Magnetic levitation, maglev, or magnetic suspension is a method by which an object issuspended with no support other than magnetic fields. The electromagnetic force is used tocounteract the effects of the gravitational force. Magnetic levitation may be defined as theprocess 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 Real-Time System responds in a (timely) predictable way to unpredictable external stimuli arrivals. Inshort, a Real-Time System has to fulfil under extreme load conditions: [1]

    timeliness: meet deadlines, it is required that the application has to finish certain taskswithin the time boundaries it has to respect.

    simultaneity or simultaneous processing: more than one event may happensimultaneously, 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 environmentcan rely on it.

    2 Objective of the Research

    The overall objective of this project is to levitate a metallic ball by producing a magnetic fieldwhich 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 balls 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.

  • 8/7/2019 Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows_316

    2/12

    2

    o Designing and fabricating the actuator (a voltage controlled current source) to regulatecurrent flowing into the electromagnets coil.

    o Simulation of the controller in MATLAB using Simulink.o Exploring MATLABs Magnetic Levitation Mode

    3 Basic Approach

    Magnetic Levitation model may be considered as a closed loop feedback control system, whosebasic 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 asthe sensor voltage, by means of a current to voltage converter. The setpoint voltage (a knownreference) is subtracted from the sensor voltage to generate an error signal which is acted uponby the PID controller. The actuator is simply a voltage to current converter that producescurrent proportional to the controllers output voltage. Magnitude of this current decides themagnetic field strength and, hence, the upward force with which the ferromagnetic ball isattracted. The magnetic levitation system can be seen to comprise of the following fundamentalelements:

    A. Plant

    The electromagnet along with the suspended metallic ball may be collectively termed as theplant.Input to the plant is the current flowing in the electromagnets coil.The plants output is thevertical displacement of the suspended ball.It is worth mentioning that is not possible to control the plant while it operates in open loop. Thereason being its highly unstable nature.B. Sensor

    The sensor used in this project is a photovoltaic cell whose short circuit current (Isc) varieslinearly with light intensity.As the metallic ball is attracted upwards by the electromagnet itpartially covers the sensor, bringing about a change in its surface area exposed to the lightsource. This action is depicted by Fig 2.

    Fig 2. Diagram illustrating photovoltaic sensors operation

    C. Current to voltage convertor

  • 8/7/2019 Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows_316

    3/12

    3

    The current to voltage converter is an operational amplifier based circuit that converts thephotovoltaic cells short circuit current (Isc) to a proportional voltage (Vsensor).D. PID ControllerThe PID controller acts upon the error signal generated by subtracting the set point voltage (Vset point) from the sensor voltage (Vsensor).

    o Proportional control ensures that the controller output is proportional to the amount oferror.

    o Integral control takes into account the error signals time duration as well as magnitudeand completely eliminates steady state offset.

    o Derivative control ensures that the corrective action taken by the controller is proportionalto the rate of change of error. Hence, an early corrective action is initiated.

    E. ActuatorThe actuator is a voltage to current converter that receives an input voltage from the PIDcontroller and converts it to a proportional current, which excites the electromagnet.The schematicshown in Fig3. gives the reader an overview of the hardware details and fundamental componentsof the levitation system.

    fig3. System. Hardware schematic of Magnetic Ball Levitation

    4 Mathematical Model of Magnetic Levitation System

    The metal ball is under the influence of two opposing forces, namely, the downward gravitationalforce and the upward pull of the electromagnet, as shown in Fig4. Perfect levitation is achievedonce these two forces exactly balance each other. The balls vertical displacement is governedby 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

  • 8/7/2019 Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows_316

    4/12

    4

    5 PID Controller

    5.1.Introduction of PID Controller

    A proportional-integral-derivative controller (PID controller) is a generic control loop feedbackmechanism 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 acorrective action. The PID controller involves three separate parameters; the Proportional, theIntegral and Derivative values. The Proportional term produces a response that is proportional tothe error signal, the Integral term examines the set points offset over time and corrects it whenand if necessary, while the Derivative term produces an output that is proportional to the rate ofchange 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 providecontrol action in accordance with specific process requirements. The controllers behavior can bedescribed in terms of its responsiveness to the error signal, the degree to which the outputovershoots the set point and the degree of system oscillation.

    5.2.Objective of PID Controller in our researchThe 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 fromthe 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 eliminatessteady state offset.3. Derivative control ensures that the controller output is proportional to the rate of change oferror.The mathematical equation describing a PID controllers behaviour is as follows:

  • 8/7/2019 Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows_316

    5/12

    5

    where:Kp is the proportional gainKiis the integral gainKdis the derivative gain

    u(n) is the controller output.

    5.4Proportional termThe proportional term ensures that the controllers output is proportional to the error signal. Theproportional 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 integralterm a PID controller cannot eliminate error if the process requires a non-null input to produce thedesired setpoint. The magnitude of the contribution of the integral term to the overall controlaction is determined by the integral gain, Ki.

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

  • 8/7/2019 Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows_316

    6/12

    6

    5.6Derivative term

    To anticipate the future the first derivative of the error signal is calculated and multiplied by aconstant 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 thebetter option because it has an advantage of being a dual op amp IC which saves circuit spaceand the number of ICs required.The PID controller was implemented in cascaded form since all three terms must recieve theerror signal simultaneously, after which their responses are summed by means of a summercircuit.

    5.8Tunning the ControllerIndividual gains of P, I & D were adjusted using potentiometers to ensure optimum performanceof 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. Kiwas varied to reduce the steady-state errors and finally Kd was adjusted to improve unwantedovershoots and to decrease the systems settling time.

    Parameter

    Risetime

    Overshoot

    Settling time S.Serror

    Kp decrease increase Small change decrease

    Ki Decrease Increase increase eliminate

    Kd Smallchange

    decrease decrease Smallchange

  • 8/7/2019 Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows_316

    7/12

    7

    Table 1. Effect of increasing proportional, integral and derivative gainsImproving 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

    6 MATLAB Magnetic Levitation Model

    In order to appreciate magnetic levitation and to get a thorough insight into the fundamentals offeedback control, it is worth exploring matlabs Magnetic Levitation Model. This model may beaccessed by typing vrmaglev on matlabs command window, as is shown below. It may also beaccessed from matlabs 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, tosense the steel balls vertical position. The coil is driven by a power amplifier interfaced with aD/A converter. A pictorial representation of the model itself is given for further clarity.[3]

    Fig13. Matlabs Magnetic Levitation Model.

  • 8/7/2019 Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows_316

    8/12

    8

    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 chosensignal. The images that follow will further clarify this point.

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

  • 8/7/2019 Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows_316

    9/12

    9

    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. Theseinclude, KP (proportional gain), KD (derivative gain) and KI (Integral gain).

    7 Simulation of the Controller using Simulink

    The closed loop control system shown in Fig 1 was simulated in MATLAB and the results closelyanalysed. The objective of this simulation was to get a better understanding of PID control andthe individual effects of proportional, integral and derivative terms.[4]

    Fig 19: Simulinkmodel 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 movebetween two ends smoothly.

  • 8/7/2019 Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows_316

    10/12

    10

    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 transientsand the ball starts to fluctuate. So as we go on increasing the PID parameters value theunstability increases. Therefore it is suggested to keep it between this limit.

    Fig 21 output of the controller

    8 Real time window targets technique

    The Real-Time Windows Target brings rapid prototyping and hardware-in-the-loop simulation.. Itis the most portable solution available today for rapid prototyping and hardware-in-the-loopsimulation This picture shows the basic components of the Real-Time Windows Target. [4]

  • 8/7/2019 Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows_316

    11/12

    11

    Fig22. Real-Time Windows (rtwin) Target [1]

    Parameter tuning is done interactively, by simply editing Simulink blocks and changing parametervalues. For viewing signals, the Real-Time Windows Target uses standard Simulink Scopeblocks, 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 bothSimulink and the generated code run on the same PC. A run-time interface enables you to rungenerated code on the same processor that runs Windows The generated code executes in realtime, allowing Windows to execute when there are free CPU cycles. The Real-Time WindowsTarget supports over 100 I/O boards, including ISA, PCI, CompactPCI, and PCMCIA. Samplerates 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 tohelp 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 blocksor the general structure of a model. Block specific optimizations are handled locally by the objectgenerating 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 codefor each block in our model.[4]

  • 8/7/2019 Paper ID 316 Design and Simulation of Model Based System Using Real Time Windows_316

    12/12

    12

    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 theforce of gravity, and to be able to apply a controlled disturbance to force the sphere to follow apredetermined trajectory is achieved using Real time Matlab Simulink tool. In operation thecontrol output from the I/O board in the PC is a voltage, but the magnetic levitation unit containsinbuilt voltage to current converter circuitry. The electromagnetic is therefore driven with a currentoutput source and the system avoids the problems associated with the high impedance of theelectromagnet coil and the consequent large phase difference between voltage and current.RTWT combines the powerful functionality of MATLAB, Simulink and Real-Time Workshop andallows users to implement any kind of control algorithm.It also suggest the value of the PIDdesign for proper operation.

    References:

    [1] On the development of a real-time digital control system using x PC-Target and amagnetic 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.2Digital 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 , 1999Page(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 magneticlevitation device for reinforcement of control education Shiakolas,P.S.;Piyabongkarn, D.Education,IEEE Transactioson Volume 46, Issue 1, Feb 2003Page(s):79-87Digital Object Identifier10.1109/TE.2002.808268

    [4] Real Time Windows Targrt for modelling, Simulation and Implementation.User Guideversion 2. by MathWorks,Inc.

    Engr.Lubna Moin, Dr. Vali UddinPakistan Navy Engineering CollegeUniversity of Science and TechnologyElectronics and Electrical DepartmentPNSJauharHabibRehmatullahRoad,Karachi, [email protected] , [email protected]