Products & Services Solutions Academia Support User Community Company

Learn more about xPC Target   

Running the Target Application

Introduction

During the build process, the xPC Target software creates a target object that represents the target application running on the target PC. The target object is defined by a set of properties and associated methods. You control the target application and computer by setting the target object properties.

For procedures to simulate your model in nonreal time, see Simulating the Model.

Control with xPC Target Explorer

This procedure assumes you have created an xPC Target boot disk and you have booted the target PC. See Booting Target PCs from Boot Floppy Disk. While the xPC Target Explorer gives you access to build and download a target application, this procedure begins with a target application already downloaded to the target PC (see xPC Target Application). For a description of how to download a prebuilt target application, see Downloading and Running Target Applications on a Target PC.

  1. In the MATLAB window, type

    xpcexplr

    The xPC Target Explorer window opens.

  2. To connect to the target PC, right-click the target PC icon for which you have downloaded the application and select Connect.

    To view the model hierarchy for the downloaded application, one of the following must be true:

    • You must be in the same folder in which you build the target application. Otherwise, xPC Target Explorer returns an error.

    • When you built the target application, you selected the Include model hierarchy on the target application check box in the xPC Target Options pane.

    If you are in the appropriate folder, a node for the target application appears in the xPC Target Hierarchy under the target PC node and displays information about the previously loaded target application.

    Note, if, in your current folder, you have a prebuilt target application that you want to download to the target PC, left-click and drag the desired target application to the target PC to which you want to download the target application.

  3. If you want to rebuild the current target application, in the xPC Target Explorer window, right-click the target application node and select Go To Simulink Model.

    The Simulink window opens for that model.

  4. To rebuild the target application, in the Simulink window and from the Tools menu, select Real-Time Workshop. From the Real-Time Workshop submenu, click Build Model.

    The xPC Target software recompiles, links, and downloads the target application to the target PC.

  5. Start the target application. For example, in the xPC Target Explorer window, select the downloaded target application.

  6. From the toolbar, click the Start Application button . The target application begins running on the target PC, and stops when it reaches the stop time.

  7. With the target application still selected in the Target Hierarchy pane of xPC Target Explorer, enter a new value for the Stop time value for the application and click Apply. For example,

    inf

  8. Again, click the Start Application button. The target application now runs until you stop it.

  9. From the toolbar, click the Stop Application button .

See also Signal Tracing with xPC Target Explorer and Signal Logging with xPC Target Explorer in the xPC Target User's Guide.

Downloading and Running Target Applications on a Target PC

This topic describes how to change folder to one that contains the prebuilt target applications (DLMs) you want to download to your target PCs and how to download and run a prebuilt target application. To view the model hierarchy, you must be in the same folder in which you build the target application. This topic assumes the following:

  1. In the xPC Target Explorer, left-click the File menu. (Note that you can also change this folder from the MATLAB window or by right-clicking the DLM node.)

  2. Select Change Host PC Current Working Directory.

    A browser is displayed.

  3. Browse to the folder that contains the prebuilt target applications you want.

  4. Click OK.

    A list of the prebuilt target applications appears, as shown.

  5. In xPC Target Explorer, check that the DLM(s) node in the xPC Target Hierarchy has the pathname of the folder that contains the prebuilt target application you want to download to the target PC.

  6. Right-click a target PC that you booted with xPC Target software, for example, TargetPC1.

  7. Select Connect.

    The target PC icon changes and the red X is removed . The target PC information changes to reflect file system and PCI device information.

  8. Left-click and drag the desired target application to the target PC to which you want to download the target application.

    xPC Target Explorer downloads the target application to the target PC. A node for the target application appears in the xPC Target Hierarchy under the target PC node.

    Alternatively, you can now drag a prebuilt target application, DLM, to a target PC icon. If a connection does not already exist, xPC Target Explorer optionally creates a connection to that target PC.

      Note   If you want to rebuild or revisit the model, click the Go to Simulink Model button. The Simulink model for the target application appears.

  9. In xPC Target Explorer, right-click the downloaded target application node. For example, xpcosc.

    The context menu appears and lists the operations you can perform on the target application.

  10. Select Start.

    xPC Target Explorer starts running the loaded target application.

  11. Stop the target application (described here) or let the target application run to the end. To stop the target application, right-click the target application node (for example, xpcosc) and select Stop from the list.

See also Signal Tracing with xPC Target Explorer and Signal Logging with xPC Target Explorer within Signals and Parameters in the xPC Target User's Guide.

Manipulating Target Application Properties

This topic describes how to manipulate target application properties. It assumes that you have already downloaded the target application xpcosc to a target PC.

  1. In xPC Target Explorer, select the node of the loaded target application in which you are interested. For example, xpcosc.

    The right pane changes to the target application properties pane for the application.

  2. In this pane, you can change the following application properties:

    • Stop time

    • Sample time

    • Log mode

    See User Interaction for limitations on changing sample times.

  3. Change the Stop time parameter to 9999. Click Apply. For example,

Control with MATLAB Commands

You run your target application in real time to observe the behavior of your model with generated code.

After the xPC Target software downloads your target application to the target PC, you can run the target application. This procedure uses the Simulink model xpc_osc3.mdl as an example, and assumes you have created and downloaded the target application for that model. It also assumes that you have assigned tg to the appropriate target PC.

  1. In the MATLAB window, type any of

    +tg or tg.start or start(tg)

    The target application starts running on the target PC. In the MATLAB window, the status of the target object changes from stopped to running.

    xPC Object
    		Connected 			= Yes
    		Application 			= xpc_osc3
    		Mode 			= Real-Time Single-Tasking
    		Status 			= running

    On the target PC screen, the Execution line changes from stopped to running and the AverageTET line is periodically updated with a new value.

  2. In the MATLAB window, type

    -tg or tg.stop or stop(tg)

    The target application stops running.

    The xPC Target software allows you to change many properties and parameters without rebuilding your target application. Two of these properties are StopTime and SampleTime.

  3. Change the stop time. For example, to change the stop time to 1000 seconds, type either

    tg.StopTime = 1000	 or set(tg,'StopTime',1000)
  4. Change the sample time. For example, to change the sample time to 0.01 seconds, type either

    tg.SampleTime = 0.01 or set(tg, 'SampleTime', 0.01)

Although you can change the sample time between different runs, you can only change the sample time without rebuilding the target application under certain circumstances.

If you choose a sample time that is too small, a CPU overload can occur. If a CPU overload occurs, the target object property CPUOverload changes to detected. In that case, change the Fixed step size in the Solver node to a larger value and rebuild the model. (See User Interaction for further limitations on changing sample times.)

Control with Simulink External Mode

Control of your xPC Target application with Simulink is limited to connecting a Simulink model to a target application through external mode, and starting the target application. Using Simulink external mode is one method to tune parameters. In Simulink external mode, the model can only connect to the default target PC.

After you create and download a target application to the target PC, you can run the target application. This procedure uses the Simulink model xpc_osc2.mdl as an example (see Building and Downloading the Target Application). It assumes that you have specified the correct target PC environment on the xPC Target options node of the Real-Time Workshop parameters dialog. In particular, you must specify the target PC to which you want to connect. See the Use the default target PC check box description in xPC Target Options.

  1. In the Simulink window, and from the Simulation menu, click External.

    A check mark appears next to the menu item External, and Simulink external mode is activated. Simulink external mode connects your Simulink model to your target application as a simple graphical user interface.

  2. In the Simulink window, and from the Simulation menu, click Connect to target.

    All the current Simulink model parameters are downloaded to your target application. This downloading guarantees the consistency of the parameters between the host model and the target application.

  3. From the Simulation menu, click Start real-time code.

    The target application begins running.

  4. In the MATLAB window, type

    tg.stop or -tg

You cannot stop the target application from the Simulink window by clicking Stop real-time code from the Simulation menu.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS