XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf  xPC Target

  • View
    227

  • Download
    2

Embed Size (px)

Text of XPC Target Tutorial - RPIcats-fs.rpi.edu/~wenj/ECSE446S05/XPC Target Tutorial_r2.pdf  xPC...

  • xPC Target Tutorial

    Control System Design

    Feb. 15, 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.70.114

    IP: 128.113.70.196

    Student laptopsIP: 128.113.70.116

    Connect to your experiment through the network.

  • 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

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

    1. At the MATLAB prompt type:

    xpcsetup

    2. Enter appropriate data

    3. Click on Update

    4. Click on CloseSee zoom on next page.

  • 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

  • Test your xPC setup

    Test your setup with a MATLAB xPC target test suite.

    At the MATLAB prompt, enter:

    xpctest(noreboot)

    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 )

    Encoders

    D/A converters

    Data logging

    Differentiation

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

  • 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

  • PD Controller Details

    Derivative term in the feedback to avoid reference differentiation

    Controller Output Actual PositionDesired Position

    Proportional GainDerivative Gain

    Differentiation( velocity estimate )

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

    SimulationConfiguration ParametersSolver Program will halt after this timeChoose fixed step

    Your real time interrupt rate

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

    SimulationConfiguration ParametersReal-Time Workshop

    1. Click on Browse.

    2. Select xPC Target from the pop up menu.

    3. Screen should now look like this.

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

    SimulationConfiguration ParametersReal-Time WorkshopxPC Target options

    Enter size of dataLogging buffer.

  • 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: ToolsReal-Time WorkshopBuild Model

    Method 2

    Click on the Build button.

  • Execute via GUIAt the MATLAB prompt, type: xpcrctool

    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 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: ToolsHost Scope Manager

  • 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

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

    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 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') ;

    tg

    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

  • 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);

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

    xPC Target TutorialControl HardwareSoftware Architecture for Laptop (host computer)Setting up xPC TargetxPCsetup ZoomTest your xPC setupCreate Simulink Model( 2 PD controllers )Encoder DetailsD/A DetailsPD Controller DetailsConfigure for Compile (1-runtime)Configure for Compile (2-compile)Configure for Compile (3-data log)Compile and DownloadExecute via GUIMonitor Signals via GUIData Logging via GUIExecute via Command LineData Logging via Command LineParameter Tuning via Command LineExecute and Parameter Tuning via Simulink