Tune Parameters and Monitor Data in Model Running on Target Hardware
Signal Monitoring and Parameter Tuning
You can use Monitor and Tune feature (also called External mode) to tune parameters and monitor a model running on your target hardware.
You can tune model parameters and evaluate the effects of different parameter values on model results in real time. Doing so helps you find the optimal values for performance. This process is called parameter tuning.
Monitor and tune accelerates parameter tuning because you do not have to rerun the model each time you change parameters. You can also use Monitor and Tune feature to develop and validate your model using the actual data and hardware for which it is designed.
The support package supports signal monitoring and parameter tuning simulation over these communication interfaces:
Communication Interface | Description |
---|---|
TCP/IP | In Monitor and Tune simulation over TCP/IP connections, you can use the Sources blocks to change parameter values and the Sink blocks to monitor the effects of parameter tuning. |
XCP on TCP/IP | In Universal Measurement and Calibration Protocol (XCP)-based Monitor and Tune simulation over TCP/IP connections, you can use:
|
This workflow lists the tasks usually required to tune parameters with Monitor and Tune:
In the model on your host computer, click Monitor & Tune from Hardware tab.
(Optional) Place sink blocks in your model and connect them to signals. For example, use Display or Scope blocks to visualize data, or use a To File block to log signal data.
Run the model on the target hardware in Monitor and Tune feature.
(Optional) Observe signals from target hardware using Display or Scope blocks on your host computer.
Change and apply parameter values in the model on your host computer.
Find the optimal parameter values by making adjustments and observing the results.
Save the new parameter values, stop Monitor and Tune, and save the model.
Prepare a Simulink Model for Signal Monitoring and Parameter Tuning
This section explains how to prepare a Simulink® model for Signal Monitoring and Parameter Tuning.
Configure the hardware network as described in Install Support for LEGO MINDSTORMS EV3 Hardware.
Create or open a Simulink model.
Set the Stop time parameter, located in the Simulation tab of toolstrip.
The default value is
10.0
seconds. To run the model for an indefinite period, enterInf
.Configure the Model Configuration Parameters for the hardware as described in Model Configuration Parameters for the LEGO MINDSTORMS EV3 Brick. In External mode, set the Communication interface parameter based on the type of External mode simulation to run on the model.
When you set the Communication interface to an XCP-based External mode, the Logging buffer size (in bytes) parameter becomes available. For this parameter, specify the number of bytes to preallocate for the buffer in the hardware during simulation.
Monitor and Tune Your Simulink Model
This section explains how to monitor and tune your Simulink model:
Monitor and Tune Simulation over Serial, TCP/IP, or Wi-Fi Connection
XCP-Based External Mode Simulation over Serial, TCP/IP, or Wi-Fi Connection
Monitor and Tune Simulation over Serial, TCP/IP, or Wi-Fi Connection
Note
This section applies only when you set the communication interface to Serial, TCP/IP, or Wi-Fi®.
Ensure that you have placed Sink blocks in the model to monitor the simulation output.
To start the simulation, in the Simulink toolbar, click the Run button .
If the model does not contain a Sink block, the MATLAB® Command Window displays a warning message. For example:
Warning: No data has been selected for uploading. > In C:\Program Files (x86)\MATLAB\R2013a Student1\toolbox\ realtime\realtime\+realtime\extModeAutoConnect.p> extModeAutoConnect at 17 In C:\Program Files (x86)\MATLAB\R2013a Student1\toolbox\ realtime\realtime\sl_customization.p>myRunCallback at 149
You can disregard this warning or add a sink block to the model. For example, use a Display or Scope block to visualize data, or use a To File block to log signal data.
After several minutes, Simulink starts running the model on the hardware.
Change the parameter values in the model. Observe the corresponding changes in the simulation output.
Find the optimal parameter values by making adjustments and observing the results in the Sink blocks.
After you are satisfied with the results, disable External mode, and save the model.
Note
External mode increases the processing burden of the model running on the board. If the software reports an overrun, disable External mode.
XCP-Based External Mode Simulation over Serial, TCP/IP, or Wi-Fi Connection
Note
This section applies only when you set the communication interface to XCP on Serial, XCP on TCP/IP, or XCP on Wi-Fi.
Before you begin, complete the Prepare a Simulink Model for Signal Monitoring and Parameter Tuning section.
In the Simulink model, identify the signals to be logged for monitoring during simulation. Select the identified signal, open its context menu, and click the icon corresponding to Enable Data Logging.
For instructions on logging the signal using other methods, refer to View the Signal Logging Configuration. Simulink displays a logged signal indicator for each logged signal.
(Optional) Place one or more Sink blocks in the model, and then mark the signals connected to them also for logging. For example, connect Display or Scope blocks and mark the signals connected to them for logging.
To start the simulation, in the Simulink toolbar, click the Run button .
If none of the signals in the model is marked for logging, the MATLAB Command Window displays a warning message. For example:
Warning: No data has been selected for uploading. > In C:\Program Files (x86)\MATLAB\R2013a Student1\toolbox\ realtime\realtime\+realtime\extModeAutoConnect.p> extModeAutoConnect at 17 In C:\Program Files (x86)\MATLAB\R2013a Student1\toolbox\ realtime\realtime\sl_customization.p>myRunCallback at 149
You can disregard this warning or mark signals for logging. For instructions on logging the signal, see View the Signal Logging Configuration.
After several minutes, Simulink starts running the model on the hardware.
During simulation, when new simulation data becomes available in SDI, the Simulation Data Inspector button appears highlighted.
View the simulation output in Sink blocks or in SDI.
Sink blocks – To view the simulation output, double-click the Sink blocks in the model.
SDI – To view the new simulation data, perform these steps:
Click the Simulation Data Inspector button.
A new simulation run appears in the Inspect pane. The Inspect pane lists all logged signals in rows, organized by simulation run. You can expand or collapse any of the runs to view the signals in a run. For more information on signal grouping, see Configure the Simulation Data Inspector.
We recommend you use SDI rather than using Sink blocks for the following reasons:
Streaming data to SDI does not store data in memory, making more efficient use of the memory available on the hardware. Sink blocks such as Scope stores data in buffers before sending the data to the host.
Using SDI, you can stream signals from top models and reference models simultaneously. Scope blocks can only log signals from a top-level model.
Change the parameter values in the model. Observe the corresponding changes in the simulation output.
Find the optimal parameter values by making adjustments and observing the results in the Sink blocks.
After you are satisfied with the results, disable External mode, and save the model.
Note
External mode increases the processing burden of the model running on the board. If the software reports an overrun, disable External mode.
Stop Signal Monitoring and Parameter Tuning
To stop signal monitoring and parameter tuning, click the Stop button located in the Hardware tab of the toolstrip.
If the Stop time parameter is set to a specific number of seconds, External mode stops when that time elapses.