xPC Target Tutorial
Control System Design Feb. 15, 2004
For more detailed information, see the xPC target manual at: [Link]
Control Hardware
Connect to your experiment through the network.
IP: [Link] xPC target xPC target
IP: [Link] xPC target
Student laptops
IP: [Link]
Software Architecture for Laptop
(host computer)
1. Generate real time code and download to computer
Visual C++
Simulink
xPC Target Real Time Workshop
EXECUTABLE
2. Execute code and interact with real time process
MATLAB GUI xpcrctool.m
Simulink
MATLAB command line or script
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
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.
Path to VC++ on your computer
IP address of target computer
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
( 2 PD controllers )
Data logging
Encoders
D/A converters
Differentiation
Find Simulink block:
Encoder Details
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)
Find Simulink block: xPC Target\D/A\Measurement Computing\PCIM-DAS1602 16
D/A Details
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
PD Controller Details
Derivative term in the feedback to avoid reference differentiation
Proportional Gain Derivative Gain
Desired Position Controller Output Actual Position
Differentiation ( velocity estimate )
Configure for Compile (1-runtime)
On your Simulink window select: SimulationConfiguration ParametersSolver
Choose fixed step Program will halt after this time
Your real time interrupt rate
Configure for Compile (2-compile)
On your Simulink window select: SimulationConfiguration ParametersReal-Time Workshop
1. 2.
Click on Browse. Select xPC Target from the pop up menu. Screen should now look like this.
3.
Configure for Compile (3-data log)
On your Simulink window select: SimulationConfiguration ParametersReal-Time WorkshopxPC Target options
Enter size of data Logging buffer.
Compile and Download
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 1 select: ToolsReal-Time WorkshopBuild Model
Method 2 Click on the Build button.
Execute via GUI
At 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.
Monitor Signals via GUI
1. Select Host scope 2. Click Add Scope 3. Select Host 4. Select from pull down menu: ToolsHost Scope Manager 5. Click Add Signals Your Simulink diagram will pop up. You can select any signal to monitor by right clicking on the signal trace.
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
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)
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. [Link](:,1)
The variable [Link] is a time vector [Link] is a matrix of logged data
[Link](:,2) [Link](:,3)
At the MATLAB prompt: >> time = [Link]; >> outputlog = [Link]; >> response =outputlog(:,3); >> plot(time,response);
Parameter Tuning via Command Line
Each 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 P0 P1 P2 P3 P4 P5 P6 P7 = PROP. VALUE -1.000000 1024.000000 3.000000 1.000000 3.000000 1.000000 0.001000 3.000000 PARAMETER NAME Scalar P1 Scalar P2 Scalar P3 Scalar P4 Scalar P5 Scalar P6 Scalar P7 Scalar P8 BLOCK NAME PCI-QUAD04 PCI-QUAD04 PCI-QUAD04 PCI-QUAD04 PCI-QUAD04 PCI-QUAD04 PCI-QUAD04 PCI-QUAD04
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>
Execute and Parameter Tuning via Simulink
1. External Mode 2. Connect to Target
3. Run Executable 4. Click on blocks to change parameter values during real time.