22
XPC Target Tutorial Control System Design Feb. 3, 2004 For more detailed information, see the xPC target manual at: www.mathworks.com

XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

XPC Target Tutorial

Control System Design

Feb. 3, 2004

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

www.mathworks.com

Page 2: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

Control Hardware

xPC target

xPC target

xPC target

IP: 128.113.224.???

IP: 128.113.224.104

Student laptopsIP: 128.113.224.???

Connect to your experiment through the network.

Page 3: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

Software Architecture for Host Computer (laptop)

MATLAB command line or script

1. Generate real time code and download to computer

2. Execute code and interact with real time process

Simulink

MATLAB GUI

xpcrctool.mSimulink

Visual C++

Page 4: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

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 Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

Xpcsetup Zoom

Path to VC++ on your computer

IP address of target computer

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

Page 6: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

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 Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

Create Simulink Model

Encoder

D/A converter

Controller

Data logging

Page 8: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

Encoder Details

Channel number: there are four encoder channels available.

Set direction of encoder to match your coordinate system.

position in radians = 2*pi*Turns + Angle

Number of encoder counts

xPC Target\Incremental Encoder\Computer Boards\PCI-QUAD04

Use quadrature

Find Simulink block:

Page 9: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

Controller Details

Proportional Gain

Derivative Gain

Finite Difference

Velocity Estimate

Page 10: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

D/A DetailsxPC Target\D/A\Computer Boards\PCIM-DAS1602 16Find Simulink block:

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

Desired voltage signal feeds in here

Set the range: –10 to +10 volts

Reset to initial value after termination

Initial value of D/A

Page 11: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

Configure for Compile (1-runtime)On your Simulink window select: Simulation…Simulation Parameters…Solver

Program will halt after this time

Choose fixed step

Your real time interrupt rate

Page 12: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

Configure for Compile (2-compile)

1. Click on Browse.

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

3. Screen should now look like this.

On your Simulink window select:

Simulation…Simulation Parameters…Real-Time Workshop

Page 13: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

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

Simulation…Simulation Parameters…Real-Time Workshop

1. Select xPC Target code generation options

2. Enter size of data logging buffer.

Page 14: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

Compile and Download

Method 1

Click on the Build button.

Using 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 2 select: Tools…Real-Time Workshop…Build Model

Page 15: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

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

Click play button to start real time code execution.

Log data to plot after execution.

Monitor signals during run time. Not Real Time!

Page 16: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

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 Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

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 Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

Data Logging via Command LineRegardless 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 19: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

Parameter tuningYou can change the parameters during run time by clicking on Simulink blocks.

3. Start execution of your real time code with xpcrctool (or any other method).

1. Select Simulation…External

2. Select Simulation…Connect to Target

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

5. After execution finishes, Click on Simulation…Disconnect from Target.

Page 20: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

MATLAB Scripting(1-Application Control)

1. Compile and download code using Simulink

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 21: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

MATLAB Scripting –2 Parameter Tuning

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

tg <enter>

Each parameter will have a parameter name (e.g. P1 … P14, etc.)

To see the list of parameters and associated Simulink variables:

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 22: XPC Target Tutorial2 - Rensselaer Polytechnic Institutecats-fs.rpi.edu/~wenj/ECSE4962S04/xpctarget.pdf?q=~wenj/... · 2004-02-03 · XPC Target Tutorial Control System Design Feb

MATLAB Scripting Demo

csddemoxpc.m

1. Starts real time code.

2. Tunes the gains during runtime.

3. Stops real time code.