Analysis and Synthesis on the Simulink Environment of Control
Total Page:16
File Type:pdf, Size:1020Kb
Int. J. Engng Ed. Vol. 21, No. 5, pp. 814±837, 2005 0949-149X/91 $3.00+0.00 Printed in Great Britain. # 2005 TEMPUS Publications. Analysis and Synthesis in the Simulink Environment of Control Laws for DC Motors: A Real-time Implementation with the Microcontroller BASIC Stamp II as a Simple Tool for an Education Control Laboratory* ANTONIO TORNAMBEÁ Dipartimento di Informatica, Sistemi e Produzione, UniversitaÁ di Roma Tor Vergata, via del Politecnico, 1, 00133 Roma, Italy. E-mail: [email protected] This paper describes a simple and cheap experimental apparatus that has been developed at UniversitaÁ di Roma Tor Vergata for educational purposes; this tool is currently used in the course ``Laboratorio d'Automatica'' (Laboratory of Automatic Control), which is offered in the first year of a three-year university programme (``Laurea'' degree) in Automatic Control. The most notable feature of this experimental apparatus is that it can be controlled in real time from Simulink; the paper reports on several experimental tests for students using this tool who are only familiar with the fundamentals of calculus, geometry, physics and computer sciences. INTRODUCTION directly apply to the DC motor a suitable input voltage whose value can be computed in real time THIS PAPER DESCRIBES a simple and cheap on the basis of measured position and of estimated experimental apparatus that has been developed at velocity through simple control laws. UniversitaÁ di Roma Tor Vergata for educational Students on the course are arranged in small purposes; this tool is presently used in the course groups (two or three students per group) and the ``Laboratorio d'Automatica'' (Laboratory of instructor provides each group with a PC Automatic Control), which is offered in the connected to the experimental apparatus, which first year of a three-year university programme constitutes a sort of simulative/experimental per- (``Laurea'' degree) in Automatic Control. The sonal desktop lab; this can be done in our institu- aim of the course is to present the basic principles tion, thanks to the low cost of the experimental of Automatic Control from a practical point of apparatus, by using the computer science labora- view, particularly before students are introduced to tory PCs, which are already available. The experi- the theory. In the first year of the ``Laurea'' degree mental set-up is already assembled by the in Automatic Control, the students are only famil- instructor, so that the students are only asked to iar with the fundamentals of calculus, geometry, control it by programming in Simulink and/or physics and computer sciences; hence, introducing directly at low level using BS2, after a set of the basics of Automatic Control theory from a simulation tests. The most notable feature of our practical point of view, using ``visual'' environ- software implementation is that the same Simulink ments such as Simulink, is almost mandatory. program used in the simulation can be used to The experimental apparatus allows the real-time control the actual experimental apparatus in real control of a DC motor, using the microcontroller time; it is sufficient to replace the Simulink block BASIC Stamp II (BS2) for real-time implementa- corresponding to the model of the DC motor with tion of the control laws; through the serial port of another Simulink block which is concerned with the PC, the BS2 communicates in real time with a real-time communication between the experimen- Simulink program; directly in Simulink, the tal set-up and the PC. student can read the state of the DC motor Several projects can be assigned to each group: encoder, which can be used for velocity estimation implementation both in Simulink and with BS2 of with a high-gain observer; the student can also a simple velocity estimation algorithm (a high-gain observer); tuning of the parameters appearing on a * Accepted 6 July 2005. simple model of the DC motor through a series of 814 Analysis and Synthesis in the Simulink Environment of Control Laws for DC Motors 815 experiments that exert different input voltages on ometers available within DS1803-010 can be set the motor; design and simulation of simple control independently, thus digitally defining two voltages laws in Simulink (proportional control law, PID (V0 and V1). The difference between these two control law, Sliding mode control); real-time voltages (V : V0 V1) is suitably amplified with implementation in Simulink of the above control the wide-band amplifier, thus generating a Æ12 V laws; real-time implementation of the same control voltage that can be directly applied to the DC laws with BS2. In this way, the students can motor, which can rotate clockwise and counter- familiarize themselves with all the phases necessary clockwise, depending on the sign of the amplified for the actual design of a real control system: 1) voltage (clockwise if V0 < V1 Á, counter- design of a dynamic model of the process to be clockwise if V0 > V1 Á, at rest if abs(V0 V1) controlled and parameter tuning/identification, 2) Á, with 2Á being the amplitude of the motor analysis and design of control laws by simulation dead-zone, assuming symmetric). The encoder tests, 3) implementation of the control law on a shaft is directly joined to the motor shaft: the prototype system, and 4) implementation on a data coming from the two channels A and B of microcontroller. the encoder can then be fed to the counters, which are connected in cascade to count from 0 up to 255 (eight bits), before resetting. The shaft position of THE EQUIPMENT USED the manually controlled potentiometer is read by the BS2 with the RCTIME instruction, and this is The experimental set-up (schematic circuit used as an analogue reference input, both for shown in Fig. 1) was realized using the following position and velocity control. equipment: one BASIC Stamp II, including the A brief description of each device is given below. NZ-1000 universal training board with the requi- The BASIC Stamp II is a hybrid microcontroller site 12V (DC) wall transformer (the BS2); the which is designed to be programmed in a version of integrated circuit DS1803-010, which comprises the BASIC programming language called two digitally controlled potentiometers, two PBASIC; version 2.5 of the PBASIC language is synchronous up/down binary counters used, with the freeware BASIC STAMP Editor 2.0 HEF40193B (four bits each), one rotary optical for programming. All the subsequent fragments of encoder ENT1J-B28-L00128, one DC motor code are written in PBASIC 2.5. IG33 (Æ12 V), one wideband amplifier WA301, The main program is simply an infinite loop one manually controlled potentiometer, and some constituted by the following sequence of resistors and capacitors. commands: reading (or, real-time acquisition The digitally controlled device DS1803-010 from Simulink) of the reference value (either and the wide-band amplifier WA301 are used to reference position or reference velocity), reading generate an analogue positive/negative voltage of the state of the encoder, possible velocity suitable for the DC motor IG33. The two counters estimation with a high-gain observer, computation HEF40193B and the encoder ENT1J-B28- (or real-time acquisition from Simulink) of the L00128 are used to digitally measure the position control input, application of the requisite voltage of the motor shaft. The manually controlled to the DC motor, and debugging for PC data potentiometer is used to generate an analogue acquisition and elaboration in real time using reference input, proportional to the position of Simulink, which receives the data from the BS2 its shaft. All these operations are controlled and with the format ``start;%d,%d,%d;end''. coordinated by the BS2, possibly with the inter- DO action of a Simulink program running on a PC GOSUB Reading ` Reading of the reference communicating with the BS2 through the serial value ports COM1/COM2. GOSUB Measure ` Reading of the encoder In particular, the BS2 can be used for the GOSUB Observer ` Velocity estimation implementation of various control and observa- GOSUB Control ` Computation of the tion/estimation algorithms, and for data exchange control law with the other devices and with the PC; for the GOSUB Potentiometer0 ` Writing the control law on Pot 0 BS2 ! PC (serial port COM1) communication, GOSUB Potentiometer1 ` Writing the serial data are transmitted using the DEBUG control law on Pot 1 instruction (or, equivalently, with a SEROUT ` The reference and measured positions instruction) on a BS2 pin dedicated to program- and the control law ming (PIN16=SOUT, which is not directly avail- ` are sent to the PC in a format suitable able on the NX-1000 board but is available for interfacing Simulink through the programming cable), whereas for the DEBUG ``start;'',DEC (serial port COM2) PC ! BS2 communication, RPosition,'','',DEC serial data are received using the SERIN instruc- MPosition,'','',DEC SControlInput,'';end'' tion on the BS2 PIN15 using a second commun- ication cable. Using appropriate commands LOOP executed with the BS2, the position of the wiper The subroutines Observer and Control are terminals of the two digitally controlled potenti- specified in the subsequent sections, according to 816 A. TornambeÁ Fig. 1. The schematic circuit of the experimental set-up. the particular assignment (see [6±8] for details on _ general control theory and digital applications). x^1 t x^2 t k1 y t x^1 t; The subroutines Reading, Measure, Potenti- x^_ t k y t x^ t; ometer0 and Potentiometer1 are specified in the 2 2 1 section where the devices and main procedures are where y t is the measured shaft position at time t, described. x^1 t and x^2 t are the estimated shaft position and velocity, respectively, at the same time t, k1 : 2 2 and k2 : , with being the high-gain (in fact, ASSIGNMENT 1: HIGH-GAIN OBSERVER the value chosen after some trials is not too high: IMPLEMENTATION IN SIMULINK 4).