Real-Time Workshop    

Parameter Tuning and Monitoring

You can change program parameters from the host and monitor data with Scope blocks while the program executes using Simulink external mode. You can also monitor program outputs using the StethoScope data analysis tool.

Using Simulink external mode or StethoScope allows you to change model parameters in your program, and to analyze the results of these changes, in real time.

External Mode

Simulink external mode provides a mechanism to download new parameter values to the executing program and to monitor signals in your model. In this mode, the external link MEX-file sends a vector of new parameter values to the real-time program via the network connection. These new parameter values are sent to the program whenever you make a parameter change without requiring a new code generation or build iteration.

You can use the BlockIOSignals code generation option to monitor signals in VxWorks. See Interfacing Parameters and Signals for further information and example code.

The real-time program (executing on the VxWorks target) runs a low priority task that communicates with the external link MEX-file and accepts the new parameters as they are passed into the program.

Communication between Simulink and the real-time program is accomplished using the sockets network API. This implementation requires an Ethernet network that supports TCP/IP. See External Mode for more information on external mode.

Changes to the block diagram structure (for example, adding or removing blocks) require generation of model and execution of the build process.

Configuring VxWorks to Use Sockets

If you want to use Simulink external mode with your VxWorks program, you must configure your VxWorks kernel to support sockets by including the INCLUDE_NET_INIT, INCLUDE_NET_SHOW, and INCLUDE_NETWORK options in your VxWorks image. For more information on configuring your kernel, see the VxWorks Programmer's Guide.

Before using external mode, you must ensure that VxWorks can properly respond to your host over the network. You can test this by using the host command

Configuring Simulink to Use Sockets

Simulink external mode uses a MEX-file to communicate with the VxWorks system. The MEX-file is

where * is a host-dependent MEX-file extension. See External Mode for more information.

To use external mode with VxWorks, specify ext_comm as the MEX-file for external interface in the External Target Interface dialog box (accessed from the External Mode Control Panel). In the MEX-file arguments field you must specify the name of the VxWorks target system and, optionally, the verbosity and TCP port number. Verbosity can be 0 (the default) or 1 if extra information is desired. The TCP port number ranges from 256 to 65535 (the default is 17725). If there is a conflict with other software using TCP port 17725, you can change the port that you use by editing the third argument of the MEX-file for external interface on the External Target Interface dialog box. The format for the MEX-file arguments field is

For example, this picture shows the External Target Interface dialog box configured for a target system called halebopp with default verbosity and the port assigned to 18000.

StethoScope

With StethoScope, you can access the output of any block in the model (in the real-time program) and display this data on a host. Signals are installed in StethoScope by the real-time program using the BlockIOSignals data structure (See Interfacing Parameters and Signals for information on BlockIOSignals), or interactively from the WindSh while the real-time program is running. To use StethoScope interactively, see the StethoScope User's Manual.

To use StethoScope you must specify certain options with the build command. See Code Generation Options for information on these options.

Run-Time Structure

The real-time program executes on the VxWorks target while Simulink and StethoScope execute on the same or different host workstations. Simulink and StethoScope require tasks on the VxWorks target to handle communication.

This diagram illustrates the structure of a VxWorks application using Simulink external mode and StethoScope.

Figure 12-2: The Run-Time Structure

The program creates VxWorks tasks to run on the real-time system: one communicates with Simulink, the others execute the model. StethoScope creates its own tasks to collect data.

Host Processes

There are two processes running on the host side that communicate with the real-time program:

VxWorks Tasks

You can run the real-time program in either singletasking or multitasking mode. The code for both modes is located in

Real-Time Workshop compiles and links rt_main.c with the model code during the build process.

Singletasking.   By default, the model is run as one task, tSingleRate. This may actually provide the best performance (highest base sample rate) depending on the model.

The tSingleRate task runs at the base rate of the model and executes all necessary code for the slower sample rates. Execution of the tSingleRate task is normally blocked by a call to the VxWorks semTake routine. When a clock interrupt occurs, the interrupt service routine calls the semGive routine, which causes the semTake call to return. Once enabled, the tSingleRate task executes the model code for one time step. The loop then waits at the top by again calling semTake. For more information about the semTake and semGive routines, refer to the VxWorks Reference Manual. By default, it runs at a relatively high priority (30), which allows it to execute without interruption from background system activity.

Multitasking.   Optionally, the model can run as multiple tasks, one for each sample rate in the model:

Supporting Tasks..   If you select external mode and/or StethoScope during the build process, these tasks will also be created:


  Run-Time Architecture Overview Implementation Overview