Вы находитесь на странице: 1из 22

XPC Target Tutorial

Control System Design


Feb. 3, 2004
For more detailed information, see the
xPC target manual at:
www.mathworks.com
Control Hardware
xPC target
xPC target
xPC target
IP: 128.113.224.???
IP: 128.113.224.104
Student laptops
IP: 128.113.224.???
Connect to your experiment
through the network.
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.m
Simulink
Visual C++
Setting up xPC Target
This 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 Close
See zoom on next page.
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 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.
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.
Create Simulink Model
Encoder
D/A converter
Controller
Data logging
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:
Controller Details
Proportional Gain
Derivative Gain
Finite Difference
Velocity Estimate
D/A Details
xPC Target\D/A\Computer Boards\PCIM-DAS1602 16
Find 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
Configure for Compile (1-runtime)
On your Simulink window select:
SimulationSimulation ParametersSolver
Program will halt
after this time
Choose fixed step
Your real time
interrupt rate
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:
SimulationSimulation ParametersReal-Time Workshop
Configure for Compile (3-data log)
On your Simulink window select:
SimulationSimulation ParametersReal-Time Workshop
1. Select xPC Target code
generation options
2. Enter size of data
logging buffer.
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:
ToolsReal-Time
WorkshopBuild Model
Execute via GUI
At 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!
Monitor Signals via GUI
1. 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:
ToolsHost Scope Manager
Data Logging via GUI
After the program has finished,
check the outputs box. Click
on Plot Logged Data.
The outputs correspond to
the outport blocks in your
Simulink Diagram
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:
Parameter tuning
You 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 SimulationExternal
2. Select SimulationConnect to Target
4. Click on blocks to change parameter
values during real time.
5. After execution finishes, Click on
SimulationDisconnect from Target.
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)
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
MATLAB Scripting Demo
csddemoxpc.m
1. Starts real time code.
2. Tunes the gains during
runtime.
3. Stops real time code.

Вам также может понравиться