Sie sind auf Seite 1von 40

cSPACE Rapid Controller Prototyping System User Manual

Zhengzhou WinnerMotor Technology Co. Ltd


Add: No.3A, Tianxin Building, No.1300 Hanghaidonglu, Zhengzhou Economic and Technological Development Zone ZIP Code: 450016 Tel: 0371-62003180 62003190 Fax: 0371-62003160 Email: xmgatech@gmail.com Website: http://www.winnermotor.com

Content
Content..........................................................................................................................2 Introduction........................................................................................................3 Hardware Features:......................................................................................................5 Advantage of cSPACE.................................................................................................7 Software Installation of cSPACE......................................................................8 Matlab/Simulink toolbox of WM-cSPACE....................................................12 3.1 Commonly Used Blocks......................................................................................12 3.2 Hardware Interface Blocks...................................................................................13 3.3 Parameters Tuning Blocks...................................................................................15 3.4 Variables Display Blocks.....................................................................................16 3.5 System Blocks......................................................................................................17 cSPACE Graphical User Interface.................................................................18 4.1 cSPACE GUI Introduction...................................................................................18 4.2 cSPACE GUI Operating Principles......................................................................20 4.2.1 Start cSPACE GUI.....................................................................................20 4.2.2 Variable Display.........................................................................................20 4.2.3 Parameter Tunning.....................................................................................21 4.2.4 Save Data...................................................................................................22 4.2.5 Number of Variables Displayed in "WM-Read1"......................................22 4.2.6 Sample Time Setup....................................................................................23 4.2.7 X-Axis Setup..............................................................................................24 4.2.8 Y-Axis Setup..............................................................................................25 Control System Design Using cSPACE............................................................28 Six operation procedures of cSPACE........................................................................28 5.1 Example: Using PID Algorithm to Control Linear Motor Tracking Sinusoid.....29 First: Modeling and Simulation..........................................................................29 Second: Building Simulink Model file...............................................................30 Third: Click WM Model Build to Build the Simulink model.........................32 Forth: Run the Application..................................................................................32 Fifth: Variables Display and Parameter Tunning................................................33
2

Sixth: Data Processing Using MATLAB............................................................33 5.2 Example: Using PID Algorithm to Control pipe flow pressure...........................35 First: Modeling and Simulation..........................................................................37 Second: Building Simulink Model file...............................................................37 Third: Click WM Model Build to Build the Simulink model.........................39 Forth: Run the Application..................................................................................39 Fifth: Variables Display and Parameter Tunning................................................39 Sixth: Result........................................................................................................39

Introduction
Rapid Controller Prototyping (RCP) and Hardware-in-Loop (HIL) are now the typical method used by engineers to develop and test their control systems. They combine computer simulation with real-time control, and the computer simulation results can be used in real-time control by importing real input/output interfaces of a real-time target computer to the simulation application, which can greatly accelerate the development of control system. RCP and HIL have been widely used for the electrically controlled unit design in research labs. One of the most popular products of RCP and HIL is dSPACE. The dSPACE Real-time Control Environment allows easy and rapid prototyping of controllers within the MATLAB/Simulink environment and downloading of these controllers to dedicated Digital Signal Processor (DSP) based systems for implementation. It can speed up the whole ECU development process. Almost all over the world, wherever engineers are working on cars and planes, dSPACE is involved. A problem with RCP system is the cost and complexity of the control hardware. A typical commercial rapid control prototyping system is typically around $10-45,000.00 depending on the vendor. This entry level price is too expansive for many researchers to use. The Winnermotor developed a cSPACE RCP and HIL development system (cSPACE) based on TI TMS320F2812 DSP and MATLAB/Simulink, and as show in Table 1.1, it consists of a DSP control card, a real-time interface toolbox in MATLAB/Simulink and a Graphical User Interface (GUI). Its functions are similar with the dSPACE. It has powerful peripherals combined with ADC, DAC, RS232, CAN, interfaces for incremental encoders. It has functions for symbolic model development, automatic code generation, variable monitoring, and parameter tuning. With cSPACEs flexible prototyping systems, one can optimize the control designs for the real electrically controlled unit (ECU) as often as you need until they meet your requirements, all without any manual programming. Table 1.1 Three constituent parts of cSPACE DSP control card Real-time interface toolbox in MATLAB/Simulink GUI

Using this system, the design of electrically controlled unit becomes efficient so that the designers can place more focus on creative solution of control algorithms or engineering problems rather than the software and hardware implementation of the control algorithms, especially the low cost of the cSPACE makes it available for most control researchers to accelerate the development of control system. The development procedures of the cSPACE are as follows: 1. Build up a simulation model of a target system, and then implement a simulation process. 2. Choose proper cSPACE I/O blocks and replace the relevant Simulink blocks in the model file. 3. Start generating code, download the code to the real-time target computer and run the target code. 4. Observe the variables and change parameters of the controller online. 5. Save the data for further analyzing.

Fig.1.1 Development procedures of the cSPACE

Hardware Features:
1. TMS320F2812 Digital Signal Processor operating at 150 MHz 2. 18 K on chip RAM 3. 128 K on chip FLASH ROM 4. 64 K words on board RAM 5. 3 system timers and 4 general timers 6. Expansion Connectors (unpopulated) 7. IEEE 1149.1 JTAG controller 8. +5, +15, -15 volt operation with supplied adapter 9. 16 channels of 12bit ADC, conversion time is 250ns, input range is (0,3V) 10. 6 channels of 16bit ADC, conversion time is 3.1us, input range is (-10,10V) 11. 4 channels of 16bit DAC, conversion time is 10us, output range is (-10,10V) 12. 2 channels of 32bit Encoder operating at 30MHz 13. 2 channels of 16 bit Encoder operating at 50MHz, or 32bit at 2MHz

14. 2 RS232 15. 3 channels of independent PWM with photoelectric isolation (PWM1/PWM2, PWM3/PWM4,PWM5/PWM6, these six Pins can also be configured as GPIO output pins) 16. 4 GPIO input pins with photoelectric isolation

Fig.1.2 DSP control card

Advantage of cSPACE
1. Using Rapid Controller Prototyping (RCP) and Hardware-in-Loop (HIL) development method, combine computer simulation with real-time control and greatly accelerate the development of control system. 2. Graphical programming with MATLAB/Simulink. MATLAB not only eliminates the need to program by hand, but also lets engineers fully MATLABs powerful computation function and toolbox and analyze and visualize data and develop algorithms with exceptionally improved productivity and creativity. 3. Powerful peripherals make the cSPACE a good control solution and data acquisition. 4. Friendly Graphical User Interface and engineers can observe the variables and change parameters of the controller online, and save the data for further analyzing 5. Low cost. This makes it available for most control researchers to accelerate the development of control system. The most important thing is that engineers can use this control card as an embedded controller for their equipment directly after downloading the generated code to the DSPs FLASH.

Software Installation of cSPACE


The MALTAB R2008a and CCS3.3 software should be installed before installing the cSPACE. The installation of cSPACE is showed as following steps. 1. Install MALTAB R2008a and CCS3.3 software (The two software and their installation guides are in the CD attached with this product.). XDS510 Emulator software should also be installed, and XDS510 Emulator software.pdf shows details about the installation. 2. Install Microsoft .NET Framework 2.0 CHS.exe software, this is a Mivrosoft .NET Framework 2.0 software.

Fig.2.1 Microsoft .NET Framework 2.0 CHS.exe installation

3. Running XCHGFile.exe software which is under the \cSPACE Installation package\5_Cspace setup pack folder to install the MATLAB/Simulink WMcSPACE Real time interface toolbox.

Fig. 2.2 XCHGFile.exe dialog box

Click

button and open the following dialog box, then select the

MATLAB installation path and click

button to fix the path.

Fig.2.3 MATLAB installation path selection dialog box 4. Copy the WMcSPACE file to the MATLABs work folder, and the path of work file is MATLAB\R2008a\work, so the WMcSPACE folders path is MATLAB\R2008a\work\WMcSPACE. Go to MATLAB File menu and select Set Path to open the Set Path dialog, then click Add Folder and select MATLAB\R2008a\work\WMcSPACE to add this path to MATLAB search path.

Fig.2.4 Set Path dialog

Fig.2.5 add folder to path 5. Go to MATLAB File menu and select Preferences to open the Preference dialog box. Select General and enable Enable toolbox path cache diagnostics, then click Update Toolbox Path Cathe to finish the toolbox installation.

Fig.2.6 Preferences dialog box


10

6. After install the WM-cSPACE Toolbox, this toolbox can be found in MATLAB/Simulink toolbox, which shows that cSPACE software is successfully installed..

Fig.2.7 WM-cSPACE Simulink toolbox 7. When deleting this software, please delete MATLAB\R2008a\work\WMcSPACE search path in step 4, and perform step 5 again to update the change.

11

Matlab/Simulink toolbox of WM-cSPACE


The cSPACE is an easy-to-use rapid controller prototyping development system, and it is used through "Winnermotor WM-cSPACE toolbox" in Matlab/Simulink. By using the toolbox, it can generate a C-language real-time implementation of control algorithm. It can automatically compile, link, download, and execute the generated code on the control card. The peripherals including AD, DA, Encoder and IO to control the object are directly supported in the toolbox. The generated code is readable and editable with TI Code Composer Studio 3.3. WM-cSPACE Matlab/Simulink toolbox includes

Commonly_Used_Blocks, Hardware_Interface, Parameters_Tuning, System_Blocks and Variables_Display sub toolboxes.

Fig.3.1 WM-cSPACE toolbox

3.1 Commonly Used Blocks


Commonly Used Blocks is commonly used blocks which are picked out from MATLAB/Simulink toolbox, including Math Operations, Logic and Bit Operations, Signal Generator, Discrete differential and integral blocks, which will be convenient for user.

12

Fig.3.2

" Winnermotor WM-A1000" Toolbox

3.2 Hardware Interface Blocks


These blocks are interface with the corresponding peripherals on the control board.

13

Fig.3.3

WM-cSPACE /Hardware Interface Toolbox

Following blocks are original TMS320F2812 DSP peripherals blocks. User can refer these blocks MATLAB description to know about their use methods.

Fig.3.4

TI TMS320F2812DSPs original blocks in MATLAB

Following blocks is the extended AD, DA, Encoder and IO peripherals interface blocks, which integrated drive code to the real-time input/output Simulink blocks.

14

Fig.3.5

Extended blocks

The features of extended blocks are showed in Table 3.1.


Table 3.1 Features of extended blocks

Blocks

Description
16bit ADC blocks of control card, and input range is (-10,+10)V whose corresponding output range is (-32767,32767)

16bit DAC blocks of control card, and output range is (-10,+10)V whose corresponding input range is (-10,+10)

Encoder1

Output value is 32 bit counters value, operating at 30MHz

Encoder3

Use this block when use want to use both Encoder1 and Encoder3block. Encoder2 Output value is 32 bit software counters value, operating at 6MHz

Encoder4

3.3 Parameters Tuning Blocks


RTDX (Real-Time Data Exchange) is used for DSP control card to communicate with a computer when the graphical user interface is running. RTDX Sub-Toolbox includes variable display Simulink blocks and parameter tuning Simulink blocks. Following blocks are parameter tuning Simulink blocks, and they are used as Gain blocks, and the value of gain is set by graphical user interface application. The output value is equal to the input multiplied by the value of gain. Refer to 4.2.3 section for more details about parameter tuning Simulink blocks.

15

Fig.3.6

Parameter tuning Simulink blocks

3.4 Variables Display Blocks


Fig.3.7 show variable observing Simulink blocks which are used to display variables through the graphical user interface. "WM-Read1", "WM-Read2", "WM-Read3" and "WM-Read4" variable observing Simulink blocks have an input port to be wired to the observation point. After these blocks are generated executable code to the DSP, the program can send variable data to the graphical user interface application through emulator and USB cable so that user can observe the variables in a running real-time application on DSP. Refer to 4.2.2 section for more details about observing the variables.

Fig.3.7

RTDX Variables Display Blocks

16

3.5 System Blocks


System blocks include Build and Run blocks, and Build block is used to convert the simulink file to C code and build the C code in CCS3.3 to generate executable code of DSP; Run block is used to download executable code to DSP and run the code and start GUI at the same time.

Fig.3.8 Table 3.2 is description of system blocks.

System Blocks

Table 3.2 Description of Model WM Model Builder WM Model Run F2812 eZdsp Description

Build the simulink model to an executable file for the TMS320F2812 DSP board Download the executable file to the DSP to run the application A processor preference of TMS3202812 DSP for the model

17

cSPACE Graphical User Interface


4.1 cSPACE GUI Introduction
Double click "WM Model Run" block in the Simulink model and the cSPACE GUI is start automatically (Fig.4.1, refer to 5.1 section, the forth step).

Fig.4.1

cSPACE Graphical User Interface

Following are characteristics of the cSPACE GUI. 1. The cSPACE GUI was developed based on MATLAB, and users will learn to use this GUI if they have some basic knowledge about MATLAB/Simulink. 2. There are as much as ten parameters that can be tuned on-line and four variables that can be observed on-line. 3. The cSPACE GUI is easy to use and there are only six operating steps (Refer to the next section.) 4. The number of tuning parameters and observing variables can be any combination for user, and the cSPACE GUI can automatically distinguish user setting. 5. Observing variables can be saved as "txt" format files in hard disk under MATLAB's current working directory, and users can further process these data through MATLAB's powerful function.

18

Menu

Observing variables Tuning parameters

Download parameters

Close

Fig.4.2

cSPACE Graphical User Interface

The elements and function of the cSPACE GUI are show as follows. 1) Variable Display: Four figures marked by "1", "2", "3" and "4" can display four different variables set by "WM-Read1", "WM-Read2", "WM-Read3" and "WMRead4" Simulink blocks in RTDX Sub-Toolbox. 2) Parameter Tunning: Users can input values in the ten number input boxes marked by "Write1", "Write1", ~,"Write10" and then click "Download" button to download these values to tune the parameters set by "WM-Write1", "WMWrite2", ~, "WM-Write10" Simulink blocks in RTDX Sub-Toolbox. 3) Save Data: Observing variables can be saved as "txt" format in hard disk under MATLAB's current working directory. 4) Menu: a) Number of variables displayed in "WM-Read1": Set the number of variables displayed in the "WM-Read1 Variable Display" figure. b) Sample Time Setup: Set the sample time of the cSPACE GUI to receive data from the DSP control card in order to make the X-Axis of four variable display figure is the same as the real time. The sample time set by user can be displayed in the X-axis label, for example, Sample Time: 0.01s. c) X-Axis Setup: Set the time scope of the X-Axis so that the figure can better display variables. d) Y-Axis Setup: Set the labels of the four figures' Y-Axis and the labels can be saved in a "txt" file automatically. When the cSPACE GUI is started next time, the labels can be imported automatically.
19

4.2 cSPACE GUI Operating Principles


4.2.1 Start cSPACE GUI After finish a Simulink model file, double click "WM Model Builder" block to build the Simulink model to an executable file for the TMS320F2812 DSP board. Then double click "WM Model Run" block in the Simulink model and the cSPACE GUI is start automatically.

Fig.4.3

cSPACE Graphical User Interface

4.2.2 Variable Display Four figures marked by "WM-Read1 Variable Display", "WM-Read2 Variable Display", "WM-Read3 Variable Display" and "WM-Read4 Variable Display" can display four different variables set by "WM-Read1", "WM-Read2", "WM-Read3" and "WMRead4" Simulink blocks in the Simulink model file. The correspondence between figures in the cSPACE GUI and the blocks in the RTDX Sub-Toolbox are showed in Table4.1.

Table 4.1 Correspondence between figures and blocks Figure Correspondent Block Figure Correspondent Block

20

WM-Read1 Variable Display WM-Read3 Variable Display

WM-Read2 Variable Display WM-Read4 Variable Display

When the number of variable observing Simulink blocks is less than four, some figures in the cSPACE GUI will display correspondent variables and the other figures will not be activated. When the cSPACE GUI is running, the data of the observing variables can be saved as "txt" format fieles in hard disk under MATLAB's current working directory. The data of the "WM-Read1", "WM-Read2", "WM-Read3" and "WM-Read4" figures are saved as in the data1ab.txt, data2ab.txt, data3ab.txt, data4ab.txt files respectively. The "txt" files are created automatically after click "Start Saving". Refer to 4.2.4 section for data saving. The scope of the Y-Axis is automatically regulated by the value of the observing variables. The value of the X-Axis is real time, for example, Fig.4.4 shows the data in latest 1.2 second. Be aware that the "Sample Time Setup" of the cSPACE GUI should be correctly set so that the value of the X-Axis can be equal to real time. Refer to 4.2.6 to set sample time, and refer to 4.2.7 to set the scope of the X-Axis.

Fig.4.4

Figure of cSPACE GUI

4.2.3 Parameter Tunning There are as much as ten parameter tunning input boxes in the cSPACE GUI, and users can input values in the input boxes marked by "Write1", "Write1", ~,"Write10" and then

21

click "Download" button to download these values to tune the parameters set by "WMWrite1", "WM-Write2", ~, "WM-Write10" Simulink blocks in RTDX Sub-Toolbox. The correspondence between parameters input boxes in the cSPACE GUI and parameter tuning Simulink blocks in the RTDX Sub-Toolbox are showed in Table4.2.
Table4.2 Correspondence between parameters input boxes and parameter tuning Simulink blocks

parameter tuning Simulink blocks

parameters input boxes

parameter tuning Simulink blocks

parameters input boxes

4.2.4 Save Data The "Save Data" element in the CSPACE GUI can save data that the variable display figures have received. In Fig.4.5, the "Read1", "Read2", "Read3" and "Read4" checkboxes correspond to the "WM-Read1", "WM-Read2", "WM-Read3" and "WM-Read4" figures. Select the checkboxes and click "Start Saving" button, then observing variables can be saved as "txt" format files in hard disk under MATLAB's current working directory. The filename of the "txt" files are "data1ab.txt", "data2ab.txt", "data3ab.txt" and "data4ab.txt" respectively. Checkboxes Start Saving Saved data "txt" files
MATLAB's current working directory

Fig.4.5 Saving Data

4.2.5 Number of Variables Displayed in "WM-Read1" In order to make a comparison for different variables, you can set the "WM-Read1 Variable Display" figure to display one to four variables, in other words, the variables of
22

"WM-Read1", "WM-Read2", "WM-Read3" and "WM-Read4" can be displayed in the "WM-Read1 Variable Display" figure. In Fig.4.6(a), choose Number of variables displayed in "WM-Read1"-"2 (Two Channels)", and "WM-Read1" and "WM-Read2" variables will be displayed in "WM-Read1 Variable Display" figure, as show in Fig.4.6(b).

(a) Display one variable

(b) Display two variables

Fig.4.6 Number of variables displayed in "WM-Read1"

4.2.6 Sample Time Setup Set the sample time of the cSPACE GUI to receive data from the DSP control card in order to make that the X-Axis of four variable display figure is the same as real time, and the unit of X-Axis is "second". The sample time is set according to the sample time of Simulink model that can generate executable code to run in DSP control card. It should also be noted that the sample time of the cSPACE GUI is twice larger than the sample time of the Simulink model. The default setting is that the sample time of Simulink model is 0.005 second, and the sample time of the cSPACE GUI is 0.01 second. In 4.2.5 section, the sample time of the cSPACE GUI is 0.01 second, and there are 120 data in each figure, so the total time of the figure is 1.2 second (120*0.01=1.2). Fig.4.7 and Fig.4.8 show the steps to set the sample time. Sample time setup

Fig.4.7 Sample time setup

Choose "Sample Time Setup"-"Set Sample Time" menu, and it will open Sample Time Setup dialog (Fig.4.8).
23

Fig.4.8 Sample time input dialog

Input sample time (0.01), then click "OK" button to apply the sample time. The sample time set by user can be displayed in the X-axis label, for example, Sample Time: 0.01s (Fig.4.9).

Sample Time

Fig.4.9 Display sample time

Choose "Sample Time Setup"-"Don't Display Sample Time" menu, and the sample time can't be displayed in the X-axis label (Fig.4.10). Don't display sample Time

Fig.4.10 Don't display sample time

4.2.7 X-Axis Setup The default scope of X-Axis is 1.2 second. It is necessary to set the time scope of the X-Axis so that the figure can better display variables at different frequency. To change the scope, choose X-Axis Setup- Set X-Axis (Fig.4.11).

24

Fig.4.11 X-Axis setup

The X-Axis setup dialog will be opened, and input the scope of X-Axis, and it will be better if the scope can be divided exactly by 1.2 or the scope is smeller than 1.2 and larger than 0.05 (Fig.4.12).

Fig.4.12 X-Axis setup dialog

Input 3.6 in the X-Axis setup dialog, the result is showed in Fig.4.13.

Fig.4.13 Setting the scope of X-Axis

In Fig.4.13, the scope of X-Axis is 3.6 which is treble of 1.2, and the figure refresh form right to left, and the refresh frequency is 1.2 second. 4.2.8 Y-Axis Setup The Y-Axis value of the four figures are the value of the observing points set by "WMRead1", "WM-Read2", "WM-Read3" and "WM-Read4" Simulink blocks in the Simulink model file, and the units of these value are the same as the value of the observing points. In GUI, the labels of Y-Axis should be units of the observing points, but the observing points are different for different users, so the labels of Y-Axis are uncertain, and the default labels of Y-Axis are "Observation Point Value". Those labels can be changed by users. The method to set the Y-Axis labels is as follows. Click "Y-Axis Setup" menu, select "Y-Axis Labels Setup" to open the "Y-Axis Labels
25

Setup Dialog" (Fig.4.14).

Fig.4.14 Y-Axis labels setup dialog

Users can input different labels in the "Y-Axis Labels Setup Dialog" and click "OK" button to apply the labels (Fig4.15).

Y-Axis Labels Setup

Fig.4.15 Y-Axis Labels setup

The Y-Axis labels of the four figures can be saved in a "wm_ordinate.txt" file automatically under MATLAB's current working directory (Fig.4.16).

26

Y-Axis labels "txt" file Labels saved in "txt" file

Fig.4.16 "wm_ordinate.txt" file

When the cSPACE GUI is started next time, the labels can be imported automatically. If there is no "wm_ordinate.txt" file, the labels of the four figures will be "Observation Point Value".

27

Control System Design Using cSPACE


Six operation procedures of cSPACE
First: Start MATLAB Second: Create or copy the Simulink model file to the MATLAB's "work" directory (MATLAB/R2008a/work), and open the Simulink model file (Fig.5.1). Note: If user wants to design new control algorithm, it recommends that using a existing Simulink model file to design a new control algorithm, and it will be more efficient (the file name should be letters and numbers, and the first character can not be number).

Fig.5.1 Simulink model file Third: Double click "WM Model Build" block to build the Simulink model. After building completely, click "WM Model Run" to run the generated code and the GUI will be started automaticlly.

Fig.5.2 "WM Model Build" and "WM Model Run" blocks Forth: Input parameters in the "Parameters Tunning" input boxes, and then click "Download" button to download the parameters. Fifth: Select the variables in the "Save Data" panel to save data. Sixth: Input the "0" in all the "Parameters Tunning" input boxes, and then click "Download" button to download the parameters, which make the output to be zero. Click "Close" button to close the GUI and stop the application running in the DSP control card.

Cautions:

28

1. In the second procedure, if user wants to build another Simulink model file, please restart MATLAB or input "clear" command in the MATLAB Command Window to clear the remaining variables of last Simulink model file. 2. Please close MATLAB first before turn off power of the control box or some errors will occur. If the errors occur, user can open "Windows Task Manager" to compulsorily close the "CCS.exe" and "MATLAB.exe" process. 3. If the MATLAB can't connect target DSP board when building the Simulink model file, please close the MATLAB compulsorily, turn off power of the control box, plug and play the USB cable, and then turn on power of the control box and start MATLAB.

5.1 Example: Using PID Algorithm to Control Linear Motor Tracking Sinusoid
The linear motor used in this experiment is an ironless permanent magnet linear synchronous motor produced by the Zhengzhou WinnerMotor Technology Co. Ltd. Its characteristics are showed in Table 5.1.
Table 5.1 Characteristics of linear motor Parameter Continuous thrust Peak thrust Velocity Peak acceleration Resolution of linear encoder Input Output Value 30N 80N

1m s 60 m s 2 5 m (-10+10V) analog voltage


(-0.5+0.5m/s)

cSPACE was used to control the linear motor tracking sinusoid, and the PID parameters, the amplitude of the sinusoid can be changed online, and the reference sinusoid, linear motors position, tracking error, control voltage (four variables) can be displayed by GUI. Tour variables can be saved as txt file to the hard disk. The operation procedures are as follows: First: Modeling and Simulation The control system is a single input and single output system for linear motor. A linear motor model should be built and input to the Transfer Fcn transfer function block, and then design a PID controller and carry out simulation to obtain PID parameters (Fig.5.3).

29

Fig5.3 PID controller

The PID controller offered by MATLAB/Simulink can be used directly.


ref fdb DMC out PID

PID Controller

Fig.5.4 Simulink PID controller

Second: Building Simulink Model file The hardware architecture of driver and cSPACE control system of the linear motor is showed in Fig.5.5.
PC cSPACE Driver Linear Motor

Linear Encoder Fig.5.5 Hardware architecture of linear motor control system

The DSP control card acquires linear motors position signal and was subtracted by the reference sinusoid to obtain position error, and the position error was processed by the PID controller. Control signal was amplified by driver to drive the linear motor to track reference sinusoid. According to above workflow, the Simulink model file was built for PID controller in Fig.5.6.

30

Fig.5.6 Simulink model file for PID controller

The Simulink blocks are described in Table 5.4.


Table 5.1 Model description of Fig.5.4 Model number 1

5 6 7 8

Description Proportional coefficient, it can be changed online in cSPACE GUI WM-Write2 parameter tunning input box Derivative coefficient, it can be changed online in cSPACE GUI WM-Write2 parameter tunning input box Integral coefficient, it can be changed online in cSPACE GUI WM-Write3 parameter tunning input box Gain model of the amplitude of the sinusoid, it can be changed online in cSPACE GUI WMWrite1 parameter tunning input box Display linear motors position Display tracking error Display control voltage Reference sinusoid generating model, the default frequency is 2Hz, and sample time is 0.005 second. Pulse equivalent setup, its value is 0.005, and the linear encoders resolution is 5um, so the
unit of this models output is millimeter. Acquire linear motors position 16bit DA model Start and stop motor model

10 11 12 13 14

Build the Simulink model to an executable file for the TMS320F2812 DSP board Download the executable file to the DSP to
31

run the application and start the cSPACE GUI Display reference sinusoid Third: Click WM Model Build to Build the Simulink model
15

Double click "WM Model Build" block to build the Simulink model and generate the executable code. The build procedure is completed when the Build compete hit message is displayed in MATLAB Command Window (Fig.5.7).

Fig.5.7 Build compete hit message

Forth: Run the Application


After building completely, click "WM Model Run" to run the generated code and the GUI

will be started automaticlly (Fig.5.8).

Fig.5.8 cSPACE GUI

32

Fifth: Variables Display and Parameter Tunning The GUI displays the reference sinusoid, linear motors position, tracking error, control voltage (four variables) sequentially. Four variables can be saved as txt file to the hard disk. "Write1" is used to set the amplitude of the sinusoid, "Write2", "Write3" and "Write4" are used to set the "P", "I" and "D" parameters of the PID controller respectively. Sixth: Data Processing Using MATLAB Import the "txt" format data to MATLAB Workspace, and the data can be display through figure. Under the current directory of MATLAB (Fig.5.9), right click over the "txt" file and select "Import" to open "Import Wizard" (Fig.5.10).

MATLAB's current working directory

Saved data "txt" files

Fig.5.9 Variables data files

Import data to Workspace

Fig.5.10 Import data to MATLAB Workspace

Click "Finish" to import the data to the MATLAB Workspace in Fig.5.10, and the data is in the Workspace (Fig.5.11).

33

Fig.5.11 Import data to MATLAB Workspace

Select "data1" (

), and click

button, and then the data will be display

through figure (Fig.5.12). The green curve is linear motors position, while the blue curve is reference sinusoid. The unit of Y-Axis is millimeter, while the unit of X-Axis is number of data, and the time span of these data is 0.01second (Refer to 4.2.6 for details).
20

15

10

-5

-10

2000

4000

6000

8000

10000

12000

14000

16000

18000

Fig.5.12 Reference sinusoid and linear motors position

Use the figure tool to reduce the scope of X-Axis so that the figure can be better observation.

34

Reference sinusoid

Linear motors position


Error

Fig.5.13 Reference sinusoid and linear motors position

The tracking result of linear motor changed according to the parameters of PID controller. Fig.5.14 shows the different tracking result under different PID parameters. 20 P=1 P=1 P=0.8 I=0 I=0.02 P=0.7 I=0 15 D=0 D=0 I=0 P=0.5 D=0 D=0 I=0
10

D=0

-5

-10

2000

4000

6000

8000

10000

12000

14000

16000

18000

Fig.5.14 Linear motors tracking result under different PID parameters

5.2 Example: Using PID Algorithm to Control pipe flow pressure


WinnerMotors three-tank process control instrumentation A1000 was used to do the experiment, and the instrumentation is showed in Fig.5.15.

35

5.15 A1000 process control instrumentation

The water flow direction is showed in Fig.5.16.

Water flow

Fig.5.16 Water flow direction

Water was pumped from V4 tank by P101 pump, flow through JV11 manually operated valve into V1 tank, and flow back to V4 tank through JV31 to make a water loop. The pipe flow pressure is tested by PT102 sensor. PID algorithm was used to control pipe flow pressure. Speed controller U101 was used to control the P101 pump. The characteristics of the pressure sensor and the speed controller U101 are showed in Table
5.3.

36

Table 5.3 Characteristics of pressure sensor and speed controller Number 1 2 Code PT101 U101(P101) Equipment cSPACE block Sensor Output block WM-DAC2

Useage pressure sensor Speed regulation

Original signal
420mA 210V

pressure
transducer

speed controller The operation procedures are as follows: First: Modeling and Simulation

The control system of pipe flow pressure is a single input and single output system. A pipe flow pressure and pipe flow model should be built and input to the Transfer Fcn transfer function block, and then design a PID controller and carry out simulation to obtain PID parameters (Fig.5.17).

Fig5.17 PID controller

The PID controller offered by MATLAB/Simulink can be used directly.


ref fdb DMC out PID

PID Controller

Fig.5.18 Simulink PID controller

Second: Building Simulink Model file The hardware architecture of driver and cSPACE control system of the pipe flow pressure is showed in Fig.5.19.
PC cSPACE Driver Pump

Pressure sensor Fig.5.19 Hardware architecture of pipe flow pressure control system

The DSP control card acquires pressure signal and was subtracted by the reference pressure to obtain pressure error, and the pressure error was processed by the PID controller. Control signal was amplified by driver to drive the pump to track reference pressure.
37

According to above workflow, the Simulink model file was built for PID controller in Fig.5.20. The file is also provided by Winnermotor, and it is at "MATLAB\R2008a\work\ process control" directory (e1_pressure_pt101.mdl).

Fig.5.20 Simulink model file for PID controller

The parameters tunning and variables display blocks are described in Table 5.4.
Table 5.4 Parameter tunning and variables display blocks Blocks WM-Write1

Description
Gain model of the reference pressure, it can be changed online in cSPACE GUI WMWrite1 parameter tunning input box (Scope: 0100KPa, default: 18)

WM-Write2

WM-Write4

WM-Write3

(default: 0.021) Gain model of the amplitude of the sinusoid, it

Derivative coefficient, it can be changed online in cSPACE GUI WM-Write2 parameter tunning input box (default: 0.5) Integral coefficient, it can be changed online in cSPACE GUI WM-Write3 parameter tunning input box

can be changed online in cSPACE GUI WM-Write1 parameter tunning input box
(default: 0)

38

WM-Read1 WM-Read2 WM-Read3 WM-Read4

Display reference pressure Display pressure Display tracking error Display control voltage

Third: Click WM Model Build to Build the Simulink model Double click "WM Model Build" block to build the Simulink model and generate the executable code. The build procedure is completed when the Build compete hit message is displayed in MATLAB Command Window (Fig.5.21).

Fig.5.21 Build compete hit message

Forth: Run the Application


After building completely, click "WM Model Run" to run the generated code and the

GUI will be started automaticlly.

Fifth: Variables Display and Parameter Tunning The GUI displays the reference pressure, controlled pressure, tracking error, control voltage (four variables) sequentially. Four variables can be saved as txt file to the hard disk. "Write1" is used to set the reference pressure, "Write2", "Write3" and "Write4" are used to set the "P", "I" and "D" parameters of the PID controller respectively. Sixth: Result The reference pressure was 18KPa, and the "P", "I" and "D" parameters of the PID controller were 0.5, 0.02 and 0 respectively. The experiment result is showed in Fig.5.22, from "WM-Read1 Variable Display" figure, the controlled pressure didn't reach the reference pressure
and the error was larger than 1.5KPa.

39

Fig.5.22 Pressure control cSPACE GUI

Fig.5.23 shows the experiment result. The green curve is controlled pressure, while the blue curve is reference pressure. The unit of Y-Axis is KPa, while the unit of X-Axis is real time. Change the "I" parameters of the PID controller online, when the value was 0.021, the controlled pressure was equal to the reference pressure on the whole (Fig.5.23).
20

P=0.5 I=0.02
15 Pressure (KPa)

P=0.5 I=0.021

10

20

40 Time (s)

60

80

100

Fig.5.23 Experiment result of pipe flow pressure control

40

Das könnte Ihnen auch gefallen