MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

61
cSPACE Rapid Controller Prototyping System User Zhengzhou WinnerMotor Technology Co.

description

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.

Transcript of MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

Page 1: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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: 450016Tel: 0371-62003180 62003190Fax: 0371-62003160Email: [email protected]: http:// www.winnermotor.com

Page 2: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

Content

Content...........................................................................................................................1一、 Introduction.........................................................................................................2

Hardware Features:................................................................................................4Advantage of cSPACE...........................................................................................6

二、 Software Installation of cSPACE.......................................................................7三、 Matlab/Simulink toolbox of WM-cSPACE.....................................................11

3.1 Commonly Used Blocks.................................................................................113.2 Hardware Interface Blocks.............................................................................123.3 Parameters Tuning Blocks..............................................................................143.4 Variables Display Blocks...............................................................................153.5 System Blocks................................................................................................16

四、 cSPACE Graphical User Interface..................................................................174.1 cSPACE GUI Introduction.............................................................................174.2 cSPACE GUI Operating Principles................................................................19

4.2.1 Start cSPACE GUI..............................................................................194.2.2 Variable Display..................................................................................194.2.3 Parameter Tunning..............................................................................214.2.4 Save Data............................................................................................214.2.5 Number of Variables Displayed in "WM-Read1"...............................224.2.6 Sample Time Setup.............................................................................224.2.7 X-Axis Setup.......................................................................................244.2.8 Y-Axis Setup.......................................................................................25

五、Control System Design Using cSPACE............................................................27Six operation procedures of cSPACE...................................................................275.1 Example: Using PID Algorithm to Control Linear Motor Tracking Sinusoid

......................................................................................................................................28First: Modeling and Simulation...................................................................28Second: Building Simulink Model file........................................................29Third: Click “WM Model Build” to Build the Simulink model..................31Forth: Run the Application...........................................................................31Fifth: Variables Display and Parameter Tunning.........................................32Sixth: Data Processing Using MATLAB.....................................................32

5.2 Example: Using PID Algorithm to Control pipe flow pressure.....................34First: Modeling and Simulation...................................................................36Second: Building Simulink Model file........................................................36Third: Click “WM Model Build” to Build the Simulink model..................38Forth: Run the Application...........................................................................38Fifth: Variables Display and Parameter Tunning.........................................38Sixth: Result.................................................................................................38

1

Page 3: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

一、 IntroductionRapid 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 cSPACE’s 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 cardReal-time interface toolbox in

MATLAB/SimulinkGUI

2

Page 4: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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.

3

Page 5: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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

4

Page 6: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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

5

Page 7: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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 MATLAB’s 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 DSP’s FLASH.

6

Page 8: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

二、 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 WM-cSPACE Real time interface toolbox.

Fig. 2.2 XCHGFile.exe dialog box

Click button and open the following dialog box, then select the

7

Page 9: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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 MATLAB’s work folder, and the path of “work” file is “MATLAB\R2008a\work”, so the “WMcSPACE” folder’s 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

8

Page 10: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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

9

Page 11: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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.

10

Page 12: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

三、 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.

11

Page 13: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

Fig.3.2 " Winnermotor WM-A1000" Toolbox

3.2 Hardware Interface Blocks

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

12

Page 14: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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 TMS320F2812DSP’s 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.

13

Page 15: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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

counter’s value, operating at 30MHz

“Encoder3”

Use this block when use want to use both “Encoder1” and “Encoder3”block.

“Encoder2”Output value is 32 bit

software counter’s 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.

14

Page 16: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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

15

Page 17: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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 System Blocks

Table 3.2 is description of system blocks.

Table 3.2 Description of

Model Description

WM Model BuilderBuild the simulink model to an executable file

for the TMS320F2812 DSP board

WM Model RunDownload the executable file to the DSP to

run the application

F2812 eZdspA processor preference of TMS3202812 DSP

for the model

16

Page 18: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

四、 cSPACE Graphical User Interface4.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.

17

Page 19: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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.

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 "WM-Read4" 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", "WM-Write2", ~, "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

18

1 2

3 4

Menu

Download parameters

Close

Observing variables

Tuning parameters

1 2

3 4

Page 20: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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.

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 "WM-Read4" 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

19

Page 21: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

Figure Correspondent Block Figure Correspondent Block

WM-Read1

Variable Display

WM-Read2

Variable Display

WM-Read3

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

20

Page 22: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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 click "Download" button to download these values to tune the parameters set by "WM-Write1", "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.

21

Checkboxes

Start Saving

Saved data"txt" files

MATLAB's current working directory

Page 23: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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 "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.

22

Page 24: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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).

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).

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).

23

Sample Time

Sample time setup

Don't display sample Time

Page 25: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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).

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.

24

Page 26: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

4.2.8 Y-Axis Setup

The Y-Axis value of the four figures are the value of the observing points set by "WM-Read1", "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 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).

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).

25

Y-Axis Labels Setup

Page 27: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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".

26

Y-Axis labels "txt" file

Labels saved in "txt" file

Page 28: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

五、Control System Design Using cSPACESix operation procedures of cSPACE

First: Start MATLABSecond: 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:

27

Page 29: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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 Value

Continuous thrust 30N

Peak thrust 80N

Velocity1

Peak acceleration60

Resolution of linear encoder 5

Input(-10,+10V) analog voltage

Output(-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 motor’s 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).

28

Page 30: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

Fig5.3 PID controller

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

PID Controller

ref

fdb

out

PID

DMC

Fig.5.4 Simulink PID controller

Second: Building Simulink Model file

The h ardware architecture of driver and cSPACE control system of the linear motor is showed in Fig.5.5.

Fig.5.5 H ardware architecture of linear motor control system

The DSP control card acquires linear motor’s 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.

cSPACE Driver Linear Motor

Linear Encoder

PC

29

Page 31: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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 Description1 Proportional coefficient, it can be changed

online in cSPACE GUI WM-Write2 parameter tunning input box

2 Derivative coefficient, it can be changed online in cSPACE GUI WM-Write2

parameter tunning input box3 Integral coefficient, it can be changed online

in cSPACE GUI WM-Write3 parameter tunning input box

4 Gain model of the amplitude of the sinusoid, it can be changed online in cSPACE GUI WM-

Write1 parameter tunning input box5 Display linear motor’s position6 Display tracking error7 Display control voltage8 Reference sinusoid generating model, the

default frequency is 2Hz, and sample time is 0.005 second.

9 P ulse equivalent setup, its value is 0.005, and the linear encoder’s resolution is 5um, so the

unit of this model’s output is millimeter.10 Acquire linear motor’s position11 16bit DA model12 Start and stop motor model13 Build the Simulink model to an executable

file for the TMS320F2812 DSP board14 Download the executable file to the DSP to

30

Page 32: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

run the application and start the cSPACE GUI

15 Display reference sinusoidThird: 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.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).

31

Page 33: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

Fig.5.8 cSPACE GUI

Fifth: Variables Display and Parameter Tunning

The GUI displays the reference sinusoid, linear motor’s 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).

Fig.5.9 Variables data files

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).

32

Import data to Workspace

Saved data"txt" files

MATLAB's current working directory

Page 34: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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 motor’s 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).

0 2000 4000 6000 8000 10000 12000 14000 16000 18000-10

-5

0

5

10

15

20

Fig.5.12 Reference sinusoid and linear motor’s position

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

33

Page 35: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

Fig.5.13 Reference sinusoid and linear motor’s 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.

0 2000 4000 6000 8000 10000 12000 14000 16000 18000-10

-5

0

5

10

15

20

Fig.5.14 Linear motor’s tracking result under different PID parameters

5.2 Example: Using PID Algorithm to Control pipe flow pressure

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

34

P=0.5I=0 D=0

P=0.7I=0 D=0

P=0.8I=0 D=0

P=1I=0 D=0

P=1I=0.02D=0

Reference sinusoid

Linear motor’s position

Error

Page 36: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

图 5.15 A1000 process control instrumentation

The water flow direction is showed in Fig.5.16.

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.

35

Water flow

Page 37: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

Table 5.3 Characteristics of pressure sensor and speed controller

Number Code Equipment cSPACE block UseageOriginal signal

1 PT101pressure transducer

Sensor Output

block

pressure sensor

4~20mA

2 U101(P101)speed

controllerWM-DAC2

Speed regulation

2~10V

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.

PID Controller

ref

fdb

out

PID

DMC

Fig.5.18 Simulink PID controller

Second: Building Simulink Model file

The h ardware architecture of driver and cSPACE control system of the pipe flow pressure is showed in Fig.5.19.

Fig.5.19 H ardware 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.

cSPACE Driver Pump

Pressure sensor

PC

36

Page 38: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

Control signal was amplified by driver to drive the pump to track reference pressure. 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 Description

WM-Write1

Gain model of the reference pressure, it can be changed online in cSPACE GUI WM-

Write1 parameter tunning input box(Scope: 0~100KPa, default: 18)

WM-Write2Derivative coefficient, it can be changed

online in cSPACE GUI WM-Write2 parameter tunning input box (default: 0.5)

WM-Write4

Integral coefficient, it can be changed online in cSPACE GUI WM-Write3

parameter tunning input box(default: 0.021)

WM-Write3 Gain model of the amplitude of the sinusoid, it can be changed online in cSPACE GUI

37

Page 39: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

WM-Write1 parameter tunning input box (default: 0)

WM-Read1 Display reference pressure

WM-Read2 Display pressure

WM-Read3 Display tracking error

WM-Read4 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.

38

Page 40: MATLAB and DSP Based Rapid Controller Pro to Typing System User Manual

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).

0 20 40 60 80 1000

5

10

15

20

Time (s)

Pre

ssur

e (K

Pa)

Fig.5.23 Experiment result of pipe flow pressure control

39

P=0.5I=0.02

P=0.5I=0.021