Tune Parameters and Monitor Data in a Model Running on NXT Brick

About External Mode

This topic explains how the External mode feature enables you to tune parameters and monitor data in a model running on your target hardware.

For example, in a model, if you select Simulation > Mode > External and then select Simulation > Run, Simulink® software embeds lightweight client/server code in your model and then runs your model on the target hardware. If you tune parameters in the model on your host computer, External mode updates the corresponding parameter values in the model running on the target hardware. You can use sink blocks, such as Display or Scope blocks, to monitor data from the model running on the target hardware. External mode sends data from the sink blocks on the target hardware to the corresponding sink blocks on your host computer, where you can view or log the data.

External mode accelerates parameter tuning. When you develop an algorithm, you must typically try a range of parameter values in order to find the optimal settings. Without External mode, you must re-run the model on the target hardware to evaluate the effects of each change. With External mode, you can adjust parameter values, monitor data, and evaluate the results until you find the optimal value, without re-running the model.

External mode increases the processing burden of the model running on the NXT brick. If the model running on the hardware reports an overrun, you can disable External mode or fix the issue as described in Detect and Fix Task Overruns on NXT Brick.

Run Your Simulink Model in External Mode

Before running your model in External mode, set up a Bluetooth® connection between the NXT hardware and your Windows® computer, as described in Set Up A Bluetooth Connection

  1. On the model toolbar, set Simulation mode to External.

  2. Set the Simulation stop time parameter, located to the left of Simulation mode on the model toolbar. The default value is 10.0 seconds. To run the model for an indefinite period, enter inf.

  3. Click the Run button.

    If your 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.

    After several minutes, Simulink starts running your model on the board.

  4. While the model is running in External mode, you can change parameter values in the model on your host computer and observe the corresponding changes in the model running on the hardware.

    If your model contains blocks from the Simulink Sinks block library, the sink blocks in the model on your host computer display the values generated by the model running on the hardware.

    Note:   External mode has low priority on the NXT brick. Under heavy loads, External mode sends data to the host computer less frequently.

    Note:   If you have the Embedded Coder® or Simulink Coder™ products, you can use External mode with a model that contains Model blocks (uses the "Model reference").

Stop External Mode

To stop the model running in External mode, click the Stop button located on the model toolbar.

If the Simulation stop time parameter is set to a specific number of seconds, External mode stops when that time elapses.

When you are finished using External mode, set Simulation mode back to Normal.

Set COM Port Number Manually

By default, Run on Target Hardware automatically gets the COM port number of the NXT brick when you use External mode. However, you have the option of setting the COM port number manually.

  1. In Windows, locate the NXT brick under Control Panel > Hardware and Sound > Devices and Printers.

    The NXT brick uses the name you assigned to it during the firmware update process. By default, that name is "NXT". If you changed that name during the firmware update, the Windows device label shows that new name.

  2. Right-click the NTX brick and select Properties.

  3. In the Properties dialog box, select the Hardware tab and make a note of the COM port number.

  4. In your model, select the Tools > Run on Target Hardware > Options menu item.

  5. In the Run on Target Hardware pane that opens, change the Set host COM port parameter to Manually.

  6. In the COM port number parameter, enter the COM port number you noted earlier.

Was this topic helpful?