Transcript
Page 1: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

xPC Target Tutorial

Control System Design

Feb. 15, 2004

For more detailed information, see the xPC target manual at:

www.mathworks.com

Page 2: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Control Hardware

xPC target

xPC target

xPC target

IP: 128.113.70.114

IP: 128.113.70.196

Student laptopsIP: 128.113.70.116

Connect to your experiment through the network.

Page 3: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Software Architecture for Laptop (host computer)

1. Generate real time code and download to computer

Visual C++

xPC Target

Real Time Workshop

Simulink EXECUTABLE

2. Execute code and interact with real time process

MATLAB command line or script

MATLAB GUI

xpcrctool.mSimulink

Page 4: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Setting up xPC TargetThis GUI configures your computer to communicate with the xPC target computer.

1. At the MATLAB prompt type:

xpcsetup <enter>

2. Enter appropriate data

3. Click on Update

4. Click on CloseSee zoom on next page.

Page 5: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

xPCsetup ZoomChange all settings to match the values shown below, except for the CompilerPath and TcpIpTargetAddress. The compiler path should contain the path to visual C++ on your computer. Use the TcpIpTargetAddress assigned to the box controlling your hardware.

IP address of target computer

Path to VC++ on your computer

Page 6: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Test your xPC setup

• Test your setup with a MATLAB xPC target test suite.

At the MATLAB prompt, enter:

xpctest(‘noreboot’) <enter>

• It is important to include the ‘noreboot’ option or the computer will lock up.

• All is good if there are no errors reported.

Page 7: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Create Simulink Model( 2 PD controllers )

Encoders

D/A converters

Data logging

Differentiation

Page 8: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Encoder DetailsFind Simulink block:xPC Target\Incremental Encoder\Measurement Computing\PCI-QUAD04

Channel number: There are four encoder channels available.

Count four times per complete cycle of the quadrature signal.

position in radians = 2*pi*Count / (1024*4)

Page 9: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

D/A DetailsFind Simulink block:xPC Target\D/A\Measurement Computing\PCIM-DAS1602 16

Channel number: There are 2 D/A channels available. Channels 1 and 2 are connected to motor amplifiers.

Set the range for both channels: –10 to +10 volts Reset to initial value after termination

Initial value of D/A

Desired voltage signals feed in here

Page 10: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

PD Controller Details

• Derivative term in the feedback to avoid reference differentiation

Controller Output Actual PositionDesired Position

Proportional GainDerivative Gain

Differentiation( velocity estimate )

Page 11: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Configure for Compile (1-runtime)On your Simulink window select:

Simulation…Configuration Parameters…Solver Program will halt after this timeChoose fixed step

Your real time interrupt rate

Page 12: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Configure for Compile (2-compile)On your Simulink window select:

Simulation…Configuration Parameters…Real-Time Workshop

1. Click on Browse.

2. Select “xPC Target” from the pop up menu.

3. Screen should now look like this.

Page 13: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Configure for Compile (3-data log)On your Simulink window select:

Simulation…Configuration Parameters…Real-Time Workshop…xPC Target options

Enter size of dataLogging buffer.

Page 14: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Compile and DownloadUsing either method 1 or method 2 will cause MATLAB to compile your Simulink Model and download the real time code to the target PC.Method 1 select: Tools…Real-Time Workshop…Build Model

Method 2

Click on the Build button.

Page 15: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Execute via GUIAt the MATLAB prompt, type: xpcrctool <enter>

Click play button to start real time code execution.

Monitor signals during run time. Not Real Time!

Log data to plot after execution.

Page 16: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Monitor Signals via GUI1. Select “Host scope”

2. Click “Add Scope”

5. Click “Add Signals”

3. Select “Host”

Your Simulink diagram will pop up. You can select any signal to monitor by right clicking on the signal trace.

4. Select from pull down menu: Tools…Host Scope Manager

Page 17: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Data Logging via GUIAfter the program has finished, check the outputs box. Click on Plot Logged Data.

The outputs correspond to the outport blocks in your Simulink Diagram

Page 18: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Execute via Command Line

>> start(tg): start execution of real time code>> stop(tg): stop execution of real time code

If you already have a compiled application, you can load it with:

load(XPCOBJ, APPNAME)

Page 19: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Data Logging via Command Line

Regardless of how you execute the real time code, the logged data will be available from the MATLAB command line after the code has finished.

The variable tg.timelog is a time vector

tg.outputlog is a matrix of logged data

tg.outputlog(:,1)

tg.outputlog(:,2)

tg.outputlog(:,3)

>> time = tg.timelog;>> outputlog = tg.outputlog;>> response =outputlog(:,3);>> plot(time,response);

At the MATLAB prompt:

Page 20: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Parameter Tuning via Command LineEach parameter will have a parameter name (e.g. P1 … P14, etc.)

To see the list of parameters and associated Simulink variables:

set(tg,'ShowParameters','on') ; <enter>

tg <enter>

Parameters = PROP. VALUE PARAMETER NAME BLOCK NAME

P0 -1.000000 Scalar P1 PCI-QUAD04

P1 1024.000000 Scalar P2 PCI-QUAD04

P2 3.000000 Scalar P3 PCI-QUAD04

P3 1.000000 Scalar P4 PCI-QUAD04

P4 3.000000 Scalar P5 PCI-QUAD04

P5 1.000000 Scalar P6 PCI-QUAD04

P6 0.001000 Scalar P7 PCI-QUAD04

P7 3.000000 Scalar P8 PCI-QUAD04

Page 21: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Parameter Tuning via Command Line

To change the value of a parameter:

setparam(tg, parameter number, new value);

e.g. If we want P3 = 10 we write

setparam(tg, 3, 10); <enter>

Page 22: XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf · xPC Target Tutorial Control System ... • Test your setup with a MATLAB xPC target test suite

Execute and Parameter Tuning via Simulink1. External Mode 2. Connect to Target

3. Run Executable

4. Click on blocks to change parameter values during real time.